pgtable.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. #ifndef _ASM_M32R_PGTABLE_H
  2. #define _ASM_M32R_PGTABLE_H
  3. #include <asm-generic/4level-fixup.h>
  4. #ifdef __KERNEL__
  5. /*
  6. * The Linux memory management assumes a three-level page table setup. On
  7. * the M32R, we use that, but "fold" the mid level into the top-level page
  8. * table, so that we physically have the same two-level page table as the
  9. * M32R mmu expects.
  10. *
  11. * This file contains the functions and defines necessary to modify and use
  12. * the M32R page table tree.
  13. */
  14. /* CAUTION!: If you change macro definitions in this file, you might have to
  15. * change arch/m32r/mmu.S manually.
  16. */
  17. #ifndef __ASSEMBLY__
  18. #include <linux/config.h>
  19. #include <linux/threads.h>
  20. #include <asm/processor.h>
  21. #include <asm/addrspace.h>
  22. #include <asm/bitops.h>
  23. #include <asm/page.h>
  24. extern pgd_t swapper_pg_dir[1024];
  25. extern void paging_init(void);
  26. /*
  27. * ZERO_PAGE is a global shared page that is always zero: used
  28. * for zero-mapped memory areas etc..
  29. */
  30. extern unsigned long empty_zero_page[1024];
  31. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  32. #endif /* !__ASSEMBLY__ */
  33. #ifndef __ASSEMBLY__
  34. #include <asm/pgtable-2level.h>
  35. #endif
  36. #define pgtable_cache_init() do { } while (0)
  37. #define PMD_SIZE (1UL << PMD_SHIFT)
  38. #define PMD_MASK (~(PMD_SIZE - 1))
  39. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  40. #define PGDIR_MASK (~(PGDIR_SIZE - 1))
  41. #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
  42. #define FIRST_USER_ADDRESS 0
  43. #ifndef __ASSEMBLY__
  44. /* Just any arbitrary offset to the start of the vmalloc VM area: the
  45. * current 8MB value just means that there will be a 8MB "hole" after the
  46. * physical memory until the kernel virtual memory starts. That means that
  47. * any out-of-bounds memory accesses will hopefully be caught.
  48. * The vmalloc() routines leaves a hole of 4kB between each vmalloced
  49. * area for the same reason. ;)
  50. */
  51. #define VMALLOC_START KSEG2
  52. #define VMALLOC_END KSEG3
  53. /*
  54. * M32R TLB format
  55. *
  56. * [0] [1:19] [20:23] [24:31]
  57. * +-----------------------+----+-------------+
  58. * | VPN |0000| ASID |
  59. * +-----------------------+----+-------------+
  60. * +-+---------------------+----+-+---+-+-+-+-+
  61. * |0 PPN |0000|N|AC |L|G|V| |
  62. * +-+---------------------+----+-+---+-+-+-+-+
  63. * RWX
  64. */
  65. #define _PAGE_BIT_DIRTY 0 /* software: page changed */
  66. #define _PAGE_BIT_FILE 0 /* when !present: nonlinear file
  67. mapping */
  68. #define _PAGE_BIT_PRESENT 1 /* Valid: page is valid */
  69. #define _PAGE_BIT_GLOBAL 2 /* Global */
  70. #define _PAGE_BIT_LARGE 3 /* Large */
  71. #define _PAGE_BIT_EXEC 4 /* Execute */
  72. #define _PAGE_BIT_WRITE 5 /* Write */
  73. #define _PAGE_BIT_READ 6 /* Read */
  74. #define _PAGE_BIT_NONCACHABLE 7 /* Non cachable */
  75. #define _PAGE_BIT_ACCESSED 8 /* software: page referenced */
  76. #define _PAGE_BIT_PROTNONE 9 /* software: if not present */
  77. #define _PAGE_DIRTY (1UL << _PAGE_BIT_DIRTY)
  78. #define _PAGE_FILE (1UL << _PAGE_BIT_FILE)
  79. #define _PAGE_PRESENT (1UL << _PAGE_BIT_PRESENT)
  80. #define _PAGE_GLOBAL (1UL << _PAGE_BIT_GLOBAL)
  81. #define _PAGE_LARGE (1UL << _PAGE_BIT_LARGE)
  82. #define _PAGE_EXEC (1UL << _PAGE_BIT_EXEC)
  83. #define _PAGE_WRITE (1UL << _PAGE_BIT_WRITE)
  84. #define _PAGE_READ (1UL << _PAGE_BIT_READ)
  85. #define _PAGE_NONCACHABLE (1UL << _PAGE_BIT_NONCACHABLE)
  86. #define _PAGE_ACCESSED (1UL << _PAGE_BIT_ACCESSED)
  87. #define _PAGE_PROTNONE (1UL << _PAGE_BIT_PROTNONE)
  88. #define _PAGE_TABLE \
  89. ( _PAGE_PRESENT | _PAGE_WRITE | _PAGE_READ | _PAGE_ACCESSED \
  90. | _PAGE_DIRTY )
  91. #define _KERNPG_TABLE \
  92. ( _PAGE_PRESENT | _PAGE_WRITE | _PAGE_READ | _PAGE_ACCESSED \
  93. | _PAGE_DIRTY )
  94. #define _PAGE_CHG_MASK \
  95. ( PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY )
  96. #ifdef CONFIG_MMU
  97. #define PAGE_NONE \
  98. __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
  99. #define PAGE_SHARED \
  100. __pgprot(_PAGE_PRESENT | _PAGE_WRITE | _PAGE_READ | _PAGE_ACCESSED)
  101. #define PAGE_SHARED_EXEC \
  102. __pgprot(_PAGE_PRESENT | _PAGE_EXEC | _PAGE_WRITE | _PAGE_READ \
  103. | _PAGE_ACCESSED)
  104. #define PAGE_COPY \
  105. __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_ACCESSED)
  106. #define PAGE_COPY_EXEC \
  107. __pgprot(_PAGE_PRESENT | _PAGE_EXEC | _PAGE_READ | _PAGE_ACCESSED)
  108. #define PAGE_READONLY \
  109. __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_ACCESSED)
  110. #define PAGE_READONLY_EXEC \
  111. __pgprot(_PAGE_PRESENT | _PAGE_EXEC | _PAGE_READ | _PAGE_ACCESSED)
  112. #define __PAGE_KERNEL \
  113. ( _PAGE_PRESENT | _PAGE_EXEC | _PAGE_WRITE | _PAGE_READ | _PAGE_DIRTY \
  114. | _PAGE_ACCESSED )
  115. #define __PAGE_KERNEL_RO ( __PAGE_KERNEL & ~_PAGE_WRITE )
  116. #define __PAGE_KERNEL_NOCACHE ( __PAGE_KERNEL | _PAGE_NONCACHABLE)
  117. #define MAKE_GLOBAL(x) __pgprot((x) | _PAGE_GLOBAL)
  118. #define PAGE_KERNEL MAKE_GLOBAL(__PAGE_KERNEL)
  119. #define PAGE_KERNEL_RO MAKE_GLOBAL(__PAGE_KERNEL_RO)
  120. #define PAGE_KERNEL_NOCACHE MAKE_GLOBAL(__PAGE_KERNEL_NOCACHE)
  121. #else
  122. #define PAGE_NONE __pgprot(0)
  123. #define PAGE_SHARED __pgprot(0)
  124. #define PAGE_SHARED_EXEC __pgprot(0)
  125. #define PAGE_COPY __pgprot(0)
  126. #define PAGE_COPY_EXEC __pgprot(0)
  127. #define PAGE_READONLY __pgprot(0)
  128. #define PAGE_READONLY_EXEC __pgprot(0)
  129. #define PAGE_KERNEL __pgprot(0)
  130. #define PAGE_KERNEL_RO __pgprot(0)
  131. #define PAGE_KERNEL_NOCACHE __pgprot(0)
  132. #endif /* CONFIG_MMU */
  133. /* xwr */
  134. #define __P000 PAGE_NONE
  135. #define __P001 PAGE_READONLY
  136. #define __P010 PAGE_COPY
  137. #define __P011 PAGE_COPY
  138. #define __P100 PAGE_READONLY_EXEC
  139. #define __P101 PAGE_READONLY_EXEC
  140. #define __P110 PAGE_COPY_EXEC
  141. #define __P111 PAGE_COPY_EXEC
  142. #define __S000 PAGE_NONE
  143. #define __S001 PAGE_READONLY
  144. #define __S010 PAGE_SHARED
  145. #define __S011 PAGE_SHARED
  146. #define __S100 PAGE_READONLY_EXEC
  147. #define __S101 PAGE_READONLY_EXEC
  148. #define __S110 PAGE_SHARED_EXEC
  149. #define __S111 PAGE_SHARED_EXEC
  150. /* page table for 0-4MB for everybody */
  151. #define pte_present(x) (pte_val(x) & (_PAGE_PRESENT | _PAGE_PROTNONE))
  152. #define pte_clear(mm,addr,xp) do { set_pte_at(mm, addr, xp, __pte(0)); } while (0)
  153. #define pmd_none(x) (!pmd_val(x))
  154. #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
  155. #define pmd_clear(xp) do { set_pmd(xp, __pmd(0)); } while (0)
  156. #define pmd_bad(x) ((pmd_val(x) & ~PAGE_MASK) != _KERNPG_TABLE)
  157. #define pages_to_mb(x) ((x) >> (20 - PAGE_SHIFT))
  158. /*
  159. * The following only work if pte_present() is true.
  160. * Undefined behaviour if not..
  161. */
  162. static inline int pte_read(pte_t pte)
  163. {
  164. return pte_val(pte) & _PAGE_READ;
  165. }
  166. static inline int pte_exec(pte_t pte)
  167. {
  168. return pte_val(pte) & _PAGE_EXEC;
  169. }
  170. static inline int pte_dirty(pte_t pte)
  171. {
  172. return pte_val(pte) & _PAGE_DIRTY;
  173. }
  174. static inline int pte_young(pte_t pte)
  175. {
  176. return pte_val(pte) & _PAGE_ACCESSED;
  177. }
  178. static inline int pte_write(pte_t pte)
  179. {
  180. return pte_val(pte) & _PAGE_WRITE;
  181. }
  182. /*
  183. * The following only works if pte_present() is not true.
  184. */
  185. static inline int pte_file(pte_t pte)
  186. {
  187. return pte_val(pte) & _PAGE_FILE;
  188. }
  189. static inline pte_t pte_rdprotect(pte_t pte)
  190. {
  191. pte_val(pte) &= ~_PAGE_READ;
  192. return pte;
  193. }
  194. static inline pte_t pte_exprotect(pte_t pte)
  195. {
  196. pte_val(pte) &= ~_PAGE_EXEC;
  197. return pte;
  198. }
  199. static inline pte_t pte_mkclean(pte_t pte)
  200. {
  201. pte_val(pte) &= ~_PAGE_DIRTY;
  202. return pte;
  203. }
  204. static inline pte_t pte_mkold(pte_t pte)
  205. {
  206. pte_val(pte) &= ~_PAGE_ACCESSED;
  207. return pte;
  208. }
  209. static inline pte_t pte_wrprotect(pte_t pte)
  210. {
  211. pte_val(pte) &= ~_PAGE_WRITE;
  212. return pte;
  213. }
  214. static inline pte_t pte_mkread(pte_t pte)
  215. {
  216. pte_val(pte) |= _PAGE_READ;
  217. return pte;
  218. }
  219. static inline pte_t pte_mkexec(pte_t pte)
  220. {
  221. pte_val(pte) |= _PAGE_EXEC;
  222. return pte;
  223. }
  224. static inline pte_t pte_mkdirty(pte_t pte)
  225. {
  226. pte_val(pte) |= _PAGE_DIRTY;
  227. return pte;
  228. }
  229. static inline pte_t pte_mkyoung(pte_t pte)
  230. {
  231. pte_val(pte) |= _PAGE_ACCESSED;
  232. return pte;
  233. }
  234. static inline pte_t pte_mkwrite(pte_t pte)
  235. {
  236. pte_val(pte) |= _PAGE_WRITE;
  237. return pte;
  238. }
  239. static inline int ptep_test_and_clear_dirty(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
  240. {
  241. return test_and_clear_bit(_PAGE_BIT_DIRTY, ptep);
  242. }
  243. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
  244. {
  245. return test_and_clear_bit(_PAGE_BIT_ACCESSED, ptep);
  246. }
  247. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  248. {
  249. clear_bit(_PAGE_BIT_WRITE, ptep);
  250. }
  251. /*
  252. * Macro and implementation to make a page protection as uncachable.
  253. */
  254. static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  255. {
  256. unsigned long prot = pgprot_val(_prot);
  257. prot |= _PAGE_NONCACHABLE;
  258. return __pgprot(prot);
  259. }
  260. #define pgprot_writecombine(prot) pgprot_noncached(prot)
  261. /*
  262. * Conversion functions: convert a page and protection to a page entry,
  263. * and a page entry and page directory to the page they refer to.
  264. */
  265. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), pgprot)
  266. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  267. {
  268. set_pte(&pte, __pte((pte_val(pte) & _PAGE_CHG_MASK) \
  269. | pgprot_val(newprot)));
  270. return pte;
  271. }
  272. #define page_pte(page) page_pte_prot(page, __pgprot(0))
  273. /*
  274. * Conversion functions: convert a page and protection to a page entry,
  275. * and a page entry and page directory to the page they refer to.
  276. */
  277. static inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
  278. {
  279. pmd_val(*pmdp) = (((unsigned long) ptep) & PAGE_MASK);
  280. }
  281. #define pmd_page_kernel(pmd) \
  282. ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
  283. #ifndef CONFIG_DISCONTIGMEM
  284. #define pmd_page(pmd) (mem_map + ((pmd_val(pmd) >> PAGE_SHIFT) - PFN_BASE))
  285. #endif /* !CONFIG_DISCONTIGMEM */
  286. /* to find an entry in a page-table-directory. */
  287. #define pgd_index(address) \
  288. (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
  289. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  290. /* to find an entry in a kernel page-table-directory */
  291. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  292. #define pmd_index(address) \
  293. (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
  294. #define pte_index(address) \
  295. (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  296. #define pte_offset_kernel(dir, address) \
  297. ((pte_t *)pmd_page_kernel(*(dir)) + pte_index(address))
  298. #define pte_offset_map(dir, address) \
  299. ((pte_t *)page_address(pmd_page(*(dir))) + pte_index(address))
  300. #define pte_offset_map_nested(dir, address) pte_offset_map(dir, address)
  301. #define pte_unmap(pte) do { } while (0)
  302. #define pte_unmap_nested(pte) do { } while (0)
  303. /* Encode and de-code a swap entry */
  304. #define __swp_type(x) (((x).val >> 2) & 0x3f)
  305. #define __swp_offset(x) ((x).val >> 10)
  306. #define __swp_entry(type, offset) \
  307. ((swp_entry_t) { ((type) << 2) | ((offset) << 10) })
  308. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  309. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  310. #endif /* !__ASSEMBLY__ */
  311. /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  312. #define kern_addr_valid(addr) (1)
  313. #define io_remap_page_range(vma, vaddr, paddr, size, prot) \
  314. remap_pfn_range(vma, vaddr, (paddr) >> PAGE_SHIFT, size, prot)
  315. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  316. remap_pfn_range(vma, vaddr, pfn, size, prot)
  317. #define MK_IOSPACE_PFN(space, pfn) (pfn)
  318. #define GET_IOSPACE(pfn) 0
  319. #define GET_PFN(pfn) (pfn)
  320. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  321. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
  322. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  323. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  324. #define __HAVE_ARCH_PTE_SAME
  325. #include <asm-generic/pgtable.h>
  326. #endif /* __KERNEL__ */
  327. #endif /* _ASM_M32R_PGTABLE_H */