pgtable.h 9.7 KB

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