pgtable.h 11 KB

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