pgtable.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 0
  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_FILE 0 /* when !present: nonlinear file
  68. mapping */
  69. #define _PAGE_BIT_PRESENT 1 /* Valid: page is valid */
  70. #define _PAGE_BIT_GLOBAL 2 /* Global */
  71. #define _PAGE_BIT_LARGE 3 /* Large */
  72. #define _PAGE_BIT_EXEC 4 /* Execute */
  73. #define _PAGE_BIT_WRITE 5 /* Write */
  74. #define _PAGE_BIT_READ 6 /* Read */
  75. #define _PAGE_BIT_NONCACHABLE 7 /* Non cachable */
  76. #define _PAGE_BIT_ACCESSED 8 /* software: page referenced */
  77. #define _PAGE_BIT_PROTNONE 9 /* software: if not present */
  78. #define _PAGE_DIRTY (1UL << _PAGE_BIT_DIRTY)
  79. #define _PAGE_FILE (1UL << _PAGE_BIT_FILE)
  80. #define _PAGE_PRESENT (1UL << _PAGE_BIT_PRESENT)
  81. #define _PAGE_GLOBAL (1UL << _PAGE_BIT_GLOBAL)
  82. #define _PAGE_LARGE (1UL << _PAGE_BIT_LARGE)
  83. #define _PAGE_EXEC (1UL << _PAGE_BIT_EXEC)
  84. #define _PAGE_WRITE (1UL << _PAGE_BIT_WRITE)
  85. #define _PAGE_READ (1UL << _PAGE_BIT_READ)
  86. #define _PAGE_NONCACHABLE (1UL << _PAGE_BIT_NONCACHABLE)
  87. #define _PAGE_ACCESSED (1UL << _PAGE_BIT_ACCESSED)
  88. #define _PAGE_PROTNONE (1UL << _PAGE_BIT_PROTNONE)
  89. #define _PAGE_TABLE \
  90. ( _PAGE_PRESENT | _PAGE_WRITE | _PAGE_READ | _PAGE_ACCESSED \
  91. | _PAGE_DIRTY )
  92. #define _KERNPG_TABLE \
  93. ( _PAGE_PRESENT | _PAGE_WRITE | _PAGE_READ | _PAGE_ACCESSED \
  94. | _PAGE_DIRTY )
  95. #define _PAGE_CHG_MASK \
  96. ( PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY )
  97. #ifdef CONFIG_MMU
  98. #define PAGE_NONE \
  99. __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
  100. #define PAGE_SHARED \
  101. __pgprot(_PAGE_PRESENT | _PAGE_WRITE | _PAGE_READ | _PAGE_ACCESSED)
  102. #define PAGE_SHARED_EXEC \
  103. __pgprot(_PAGE_PRESENT | _PAGE_EXEC | _PAGE_WRITE | _PAGE_READ \
  104. | _PAGE_ACCESSED)
  105. #define PAGE_COPY \
  106. __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_ACCESSED)
  107. #define PAGE_COPY_EXEC \
  108. __pgprot(_PAGE_PRESENT | _PAGE_EXEC | _PAGE_READ | _PAGE_ACCESSED)
  109. #define PAGE_READONLY \
  110. __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_ACCESSED)
  111. #define PAGE_READONLY_EXEC \
  112. __pgprot(_PAGE_PRESENT | _PAGE_EXEC | _PAGE_READ | _PAGE_ACCESSED)
  113. #define __PAGE_KERNEL \
  114. ( _PAGE_PRESENT | _PAGE_EXEC | _PAGE_WRITE | _PAGE_READ | _PAGE_DIRTY \
  115. | _PAGE_ACCESSED )
  116. #define __PAGE_KERNEL_RO ( __PAGE_KERNEL & ~_PAGE_WRITE )
  117. #define __PAGE_KERNEL_NOCACHE ( __PAGE_KERNEL | _PAGE_NONCACHABLE)
  118. #define MAKE_GLOBAL(x) __pgprot((x) | _PAGE_GLOBAL)
  119. #define PAGE_KERNEL MAKE_GLOBAL(__PAGE_KERNEL)
  120. #define PAGE_KERNEL_RO MAKE_GLOBAL(__PAGE_KERNEL_RO)
  121. #define PAGE_KERNEL_NOCACHE MAKE_GLOBAL(__PAGE_KERNEL_NOCACHE)
  122. #else
  123. #define PAGE_NONE __pgprot(0)
  124. #define PAGE_SHARED __pgprot(0)
  125. #define PAGE_SHARED_EXEC __pgprot(0)
  126. #define PAGE_COPY __pgprot(0)
  127. #define PAGE_COPY_EXEC __pgprot(0)
  128. #define PAGE_READONLY __pgprot(0)
  129. #define PAGE_READONLY_EXEC __pgprot(0)
  130. #define PAGE_KERNEL __pgprot(0)
  131. #define PAGE_KERNEL_RO __pgprot(0)
  132. #define PAGE_KERNEL_NOCACHE __pgprot(0)
  133. #endif /* CONFIG_MMU */
  134. /* xwr */
  135. #define __P000 PAGE_NONE
  136. #define __P001 PAGE_READONLY
  137. #define __P010 PAGE_COPY
  138. #define __P011 PAGE_COPY
  139. #define __P100 PAGE_READONLY_EXEC
  140. #define __P101 PAGE_READONLY_EXEC
  141. #define __P110 PAGE_COPY_EXEC
  142. #define __P111 PAGE_COPY_EXEC
  143. #define __S000 PAGE_NONE
  144. #define __S001 PAGE_READONLY
  145. #define __S010 PAGE_SHARED
  146. #define __S011 PAGE_SHARED
  147. #define __S100 PAGE_READONLY_EXEC
  148. #define __S101 PAGE_READONLY_EXEC
  149. #define __S110 PAGE_SHARED_EXEC
  150. #define __S111 PAGE_SHARED_EXEC
  151. /* page table for 0-4MB for everybody */
  152. #define pte_present(x) (pte_val(x) & (_PAGE_PRESENT | _PAGE_PROTNONE))
  153. #define pte_clear(mm,addr,xp) do { set_pte_at(mm, addr, xp, __pte(0)); } while (0)
  154. #define pmd_none(x) (!pmd_val(x))
  155. #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
  156. #define pmd_clear(xp) do { set_pmd(xp, __pmd(0)); } while (0)
  157. #define pmd_bad(x) ((pmd_val(x) & ~PAGE_MASK) != _KERNPG_TABLE)
  158. #define pages_to_mb(x) ((x) >> (20 - PAGE_SHIFT))
  159. /*
  160. * The following only work if pte_present() is true.
  161. * Undefined behaviour if not..
  162. */
  163. static inline int pte_dirty(pte_t pte)
  164. {
  165. return pte_val(pte) & _PAGE_DIRTY;
  166. }
  167. static inline int pte_young(pte_t pte)
  168. {
  169. return pte_val(pte) & _PAGE_ACCESSED;
  170. }
  171. static inline int pte_write(pte_t pte)
  172. {
  173. return pte_val(pte) & _PAGE_WRITE;
  174. }
  175. /*
  176. * The following only works if pte_present() is not true.
  177. */
  178. static inline int pte_file(pte_t pte)
  179. {
  180. return pte_val(pte) & _PAGE_FILE;
  181. }
  182. static inline int pte_special(pte_t pte)
  183. {
  184. return 0;
  185. }
  186. static inline pte_t pte_mkclean(pte_t pte)
  187. {
  188. pte_val(pte) &= ~_PAGE_DIRTY;
  189. return pte;
  190. }
  191. static inline pte_t pte_mkold(pte_t pte)
  192. {
  193. pte_val(pte) &= ~_PAGE_ACCESSED;
  194. return pte;
  195. }
  196. static inline pte_t pte_wrprotect(pte_t pte)
  197. {
  198. pte_val(pte) &= ~_PAGE_WRITE;
  199. return pte;
  200. }
  201. static inline pte_t pte_mkdirty(pte_t pte)
  202. {
  203. pte_val(pte) |= _PAGE_DIRTY;
  204. return pte;
  205. }
  206. static inline pte_t pte_mkyoung(pte_t pte)
  207. {
  208. pte_val(pte) |= _PAGE_ACCESSED;
  209. return pte;
  210. }
  211. static inline pte_t pte_mkwrite(pte_t pte)
  212. {
  213. pte_val(pte) |= _PAGE_WRITE;
  214. return pte;
  215. }
  216. static inline pte_t pte_mkspecial(pte_t pte)
  217. {
  218. return pte;
  219. }
  220. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
  221. {
  222. return test_and_clear_bit(_PAGE_BIT_ACCESSED, ptep);
  223. }
  224. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  225. {
  226. clear_bit(_PAGE_BIT_WRITE, ptep);
  227. }
  228. /*
  229. * Macro and implementation to make a page protection as uncachable.
  230. */
  231. static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  232. {
  233. unsigned long prot = pgprot_val(_prot);
  234. prot |= _PAGE_NONCACHABLE;
  235. return __pgprot(prot);
  236. }
  237. #define pgprot_writecombine(prot) pgprot_noncached(prot)
  238. /*
  239. * Conversion functions: convert a page and protection to a page entry,
  240. * and a page entry and page directory to the page they refer to.
  241. */
  242. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), pgprot)
  243. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  244. {
  245. set_pte(&pte, __pte((pte_val(pte) & _PAGE_CHG_MASK) \
  246. | pgprot_val(newprot)));
  247. return pte;
  248. }
  249. /*
  250. * Conversion functions: convert a page and protection to a page entry,
  251. * and a page entry and page directory to the page they refer to.
  252. */
  253. static inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
  254. {
  255. pmd_val(*pmdp) = (((unsigned long) ptep) & PAGE_MASK);
  256. }
  257. #define pmd_page_vaddr(pmd) \
  258. ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
  259. #ifndef CONFIG_DISCONTIGMEM
  260. #define pmd_page(pmd) (mem_map + ((pmd_val(pmd) >> PAGE_SHIFT) - PFN_BASE))
  261. #endif /* !CONFIG_DISCONTIGMEM */
  262. /* to find an entry in a page-table-directory. */
  263. #define pgd_index(address) \
  264. (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
  265. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  266. /* to find an entry in a kernel page-table-directory */
  267. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  268. #define pmd_index(address) \
  269. (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
  270. #define pte_index(address) \
  271. (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  272. #define pte_offset_kernel(dir, address) \
  273. ((pte_t *)pmd_page_vaddr(*(dir)) + pte_index(address))
  274. #define pte_offset_map(dir, address) \
  275. ((pte_t *)page_address(pmd_page(*(dir))) + pte_index(address))
  276. #define pte_unmap(pte) do { } while (0)
  277. /* Encode and de-code a swap entry */
  278. #define __swp_type(x) (((x).val >> 2) & 0x1f)
  279. #define __swp_offset(x) ((x).val >> 10)
  280. #define __swp_entry(type, offset) \
  281. ((swp_entry_t) { ((type) << 2) | ((offset) << 10) })
  282. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  283. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  284. #endif /* !__ASSEMBLY__ */
  285. /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  286. #define kern_addr_valid(addr) (1)
  287. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  288. remap_pfn_range(vma, vaddr, pfn, size, prot)
  289. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  290. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  291. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  292. #define __HAVE_ARCH_PTE_SAME
  293. #include <asm-generic/pgtable.h>
  294. #endif /* __KERNEL__ */
  295. #endif /* _ASM_M32R_PGTABLE_H */