mcf_pgtable.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _MCF_PGTABLE_H
  3. #define _MCF_PGTABLE_H
  4. #include <asm/mcfmmu.h>
  5. #include <asm/page.h>
  6. /*
  7. * MMUDR bits, in proper place. We write these directly into the MMUDR
  8. * after masking from the pte.
  9. */
  10. #define CF_PAGE_LOCKED MMUDR_LK /* 0x00000002 */
  11. #define CF_PAGE_EXEC MMUDR_X /* 0x00000004 */
  12. #define CF_PAGE_WRITABLE MMUDR_W /* 0x00000008 */
  13. #define CF_PAGE_READABLE MMUDR_R /* 0x00000010 */
  14. #define CF_PAGE_SYSTEM MMUDR_SP /* 0x00000020 */
  15. #define CF_PAGE_COPYBACK MMUDR_CM_CCB /* 0x00000040 */
  16. #define CF_PAGE_NOCACHE MMUDR_CM_NCP /* 0x00000080 */
  17. #define CF_CACHEMASK (~MMUDR_CM_CCB)
  18. #define CF_PAGE_MMUDR_MASK 0x000000fe
  19. #define _PAGE_NOCACHE030 CF_PAGE_NOCACHE
  20. /*
  21. * MMUTR bits, need shifting down.
  22. */
  23. #define CF_PAGE_MMUTR_MASK 0x00000c00
  24. #define CF_PAGE_MMUTR_SHIFT 10
  25. #define CF_PAGE_VALID (MMUTR_V << CF_PAGE_MMUTR_SHIFT)
  26. #define CF_PAGE_SHARED (MMUTR_SG << CF_PAGE_MMUTR_SHIFT)
  27. /*
  28. * Fake bits, not implemented in CF, will get masked out before
  29. * hitting hardware.
  30. */
  31. #define CF_PAGE_DIRTY 0x00000001
  32. #define CF_PAGE_ACCESSED 0x00001000
  33. #define _PAGE_CACHE040 0x020 /* 68040 cache mode, cachable, copyback */
  34. #define _PAGE_NOCACHE_S 0x040 /* 68040 no-cache mode, serialized */
  35. #define _PAGE_NOCACHE 0x060 /* 68040 cache mode, non-serialized */
  36. #define _PAGE_CACHE040W 0x000 /* 68040 cache mode, cachable, write-through */
  37. #define _DESCTYPE_MASK 0x003
  38. #define _CACHEMASK040 (~0x060)
  39. #define _PAGE_GLOBAL040 0x400 /* 68040 global bit, used for kva descs */
  40. /* We borrow bit 7 to store the exclusive marker in swap PTEs. */
  41. #define _PAGE_SWP_EXCLUSIVE CF_PAGE_NOCACHE
  42. /*
  43. * Externally used page protection values.
  44. */
  45. #define _PAGE_PRESENT (CF_PAGE_VALID)
  46. #define _PAGE_ACCESSED (CF_PAGE_ACCESSED)
  47. #define _PAGE_DIRTY (CF_PAGE_DIRTY)
  48. #define _PAGE_READWRITE (CF_PAGE_READABLE \
  49. | CF_PAGE_WRITABLE \
  50. | CF_PAGE_SYSTEM \
  51. | CF_PAGE_SHARED)
  52. /*
  53. * Compound page protection values.
  54. */
  55. #define PAGE_NONE __pgprot(CF_PAGE_VALID \
  56. | CF_PAGE_ACCESSED)
  57. #define PAGE_SHARED __pgprot(CF_PAGE_VALID \
  58. | CF_PAGE_ACCESSED \
  59. | CF_PAGE_SHARED)
  60. #define PAGE_INIT __pgprot(CF_PAGE_VALID \
  61. | CF_PAGE_READABLE \
  62. | CF_PAGE_WRITABLE \
  63. | CF_PAGE_EXEC \
  64. | CF_PAGE_SYSTEM)
  65. #define PAGE_KERNEL __pgprot(CF_PAGE_VALID \
  66. | CF_PAGE_ACCESSED \
  67. | CF_PAGE_READABLE \
  68. | CF_PAGE_WRITABLE \
  69. | CF_PAGE_EXEC \
  70. | CF_PAGE_SYSTEM \
  71. | CF_PAGE_SHARED)
  72. #define PAGE_COPY __pgprot(CF_PAGE_VALID \
  73. | CF_PAGE_ACCESSED \
  74. | CF_PAGE_READABLE \
  75. | CF_PAGE_DIRTY)
  76. #define PTE_MASK PAGE_MASK
  77. #define CF_PAGE_CHG_MASK (PTE_MASK | CF_PAGE_ACCESSED | CF_PAGE_DIRTY)
  78. #ifndef __ASSEMBLY__
  79. #define pmd_pgtable(pmd) pfn_to_virt(pmd_val(pmd) >> PAGE_SHIFT)
  80. /*
  81. * Conversion functions: convert a page and protection to a page entry,
  82. * and a page entry and page directory to the page they refer to.
  83. */
  84. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  85. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  86. {
  87. pte_val(pte) = (pte_val(pte) & CF_PAGE_CHG_MASK) | pgprot_val(newprot);
  88. return pte;
  89. }
  90. #define pmd_set(pmdp, ptep) do {} while (0)
  91. static inline void pgd_set(pgd_t *pgdp, pmd_t *pmdp)
  92. {
  93. pgd_val(*pgdp) = virt_to_phys(pmdp);
  94. }
  95. #define __pte_page(pte) ((void *) (pte_val(pte) & PAGE_MASK))
  96. #define pmd_page_vaddr(pmd) ((unsigned long) (pmd_val(pmd)))
  97. static inline int pte_none(pte_t pte)
  98. {
  99. return !pte_val(pte);
  100. }
  101. static inline int pte_present(pte_t pte)
  102. {
  103. return pte_val(pte) & CF_PAGE_VALID;
  104. }
  105. static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
  106. pte_t *ptep)
  107. {
  108. pte_val(*ptep) = 0;
  109. }
  110. #define pte_page(pte) virt_to_page(__pte_page(pte))
  111. static inline int pmd_none2(pmd_t *pmd) { return !pmd_val(*pmd); }
  112. #define pmd_none(pmd) pmd_none2(&(pmd))
  113. static inline int pmd_bad2(pmd_t *pmd) { return 0; }
  114. #define pmd_bad(pmd) pmd_bad2(&(pmd))
  115. #define pmd_present(pmd) (!pmd_none2(&(pmd)))
  116. static inline void pmd_clear(pmd_t *pmdp) { pmd_val(*pmdp) = 0; }
  117. #define pte_ERROR(e) \
  118. printk(KERN_ERR "%s:%d: bad pte %08lx.\n", \
  119. __FILE__, __LINE__, pte_val(e))
  120. #define pgd_ERROR(e) \
  121. printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \
  122. __FILE__, __LINE__, pgd_val(e))
  123. /*
  124. * The following only work if pte_present() is true.
  125. * Undefined behaviour if not...
  126. * [we have the full set here even if they don't change from m68k]
  127. */
  128. static inline int pte_read(pte_t pte)
  129. {
  130. return pte_val(pte) & CF_PAGE_READABLE;
  131. }
  132. static inline int pte_write(pte_t pte)
  133. {
  134. return pte_val(pte) & CF_PAGE_WRITABLE;
  135. }
  136. static inline int pte_exec(pte_t pte)
  137. {
  138. return pte_val(pte) & CF_PAGE_EXEC;
  139. }
  140. static inline int pte_dirty(pte_t pte)
  141. {
  142. return pte_val(pte) & CF_PAGE_DIRTY;
  143. }
  144. static inline int pte_young(pte_t pte)
  145. {
  146. return pte_val(pte) & CF_PAGE_ACCESSED;
  147. }
  148. static inline pte_t pte_wrprotect(pte_t pte)
  149. {
  150. pte_val(pte) &= ~CF_PAGE_WRITABLE;
  151. return pte;
  152. }
  153. static inline pte_t pte_rdprotect(pte_t pte)
  154. {
  155. pte_val(pte) &= ~CF_PAGE_READABLE;
  156. return pte;
  157. }
  158. static inline pte_t pte_exprotect(pte_t pte)
  159. {
  160. pte_val(pte) &= ~CF_PAGE_EXEC;
  161. return pte;
  162. }
  163. static inline pte_t pte_mkclean(pte_t pte)
  164. {
  165. pte_val(pte) &= ~CF_PAGE_DIRTY;
  166. return pte;
  167. }
  168. static inline pte_t pte_mkold(pte_t pte)
  169. {
  170. pte_val(pte) &= ~CF_PAGE_ACCESSED;
  171. return pte;
  172. }
  173. static inline pte_t pte_mkwrite_novma(pte_t pte)
  174. {
  175. pte_val(pte) |= CF_PAGE_WRITABLE;
  176. return pte;
  177. }
  178. static inline pte_t pte_mkread(pte_t pte)
  179. {
  180. pte_val(pte) |= CF_PAGE_READABLE;
  181. return pte;
  182. }
  183. static inline pte_t pte_mkexec(pte_t pte)
  184. {
  185. pte_val(pte) |= CF_PAGE_EXEC;
  186. return pte;
  187. }
  188. static inline pte_t pte_mkdirty(pte_t pte)
  189. {
  190. pte_val(pte) |= CF_PAGE_DIRTY;
  191. return pte;
  192. }
  193. static inline pte_t pte_mkyoung(pte_t pte)
  194. {
  195. pte_val(pte) |= CF_PAGE_ACCESSED;
  196. return pte;
  197. }
  198. static inline pte_t pte_mknocache(pte_t pte)
  199. {
  200. pte_val(pte) |= 0x80 | (pte_val(pte) & ~0x40);
  201. return pte;
  202. }
  203. static inline pte_t pte_mkcache(pte_t pte)
  204. {
  205. pte_val(pte) &= ~CF_PAGE_NOCACHE;
  206. return pte;
  207. }
  208. #define swapper_pg_dir kernel_pg_dir
  209. extern pgd_t kernel_pg_dir[PTRS_PER_PGD];
  210. /*
  211. * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
  212. * are !pte_none() && !pte_present().
  213. *
  214. * Format of swap PTEs:
  215. *
  216. * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  217. * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  218. * <------------------ offset -------------> 0 0 0 E <-- type --->
  219. *
  220. * E is the exclusive marker that is not stored in swap entries.
  221. */
  222. #define __swp_type(x) ((x).val & 0x7f)
  223. #define __swp_offset(x) ((x).val >> 11)
  224. #define __swp_entry(typ, off) ((swp_entry_t) { ((typ) & 0x7f) | \
  225. (off << 11) })
  226. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  227. #define __swp_entry_to_pte(x) (__pte((x).val))
  228. static inline int pte_swp_exclusive(pte_t pte)
  229. {
  230. return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
  231. }
  232. static inline pte_t pte_swp_mkexclusive(pte_t pte)
  233. {
  234. pte_val(pte) |= _PAGE_SWP_EXCLUSIVE;
  235. return pte;
  236. }
  237. static inline pte_t pte_swp_clear_exclusive(pte_t pte)
  238. {
  239. pte_val(pte) &= ~_PAGE_SWP_EXCLUSIVE;
  240. return pte;
  241. }
  242. #define PFN_PTE_SHIFT PAGE_SHIFT
  243. #define pmd_pfn(pmd) (pmd_val(pmd) >> PAGE_SHIFT)
  244. #define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
  245. #define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
  246. #define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT)
  247. #endif /* !__ASSEMBLY__ */
  248. #endif /* _MCF_PGTABLE_H */