pte-common.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* Included from asm/pgtable-*.h only ! */
  2. /*
  3. * Some bits are only used on some cpu families... Make sure that all
  4. * the undefined gets a sensible default
  5. */
  6. #ifndef _PAGE_HASHPTE
  7. #define _PAGE_HASHPTE 0
  8. #endif
  9. #ifndef _PAGE_SHARED
  10. #define _PAGE_SHARED 0
  11. #endif
  12. #ifndef _PAGE_HWWRITE
  13. #define _PAGE_HWWRITE 0
  14. #endif
  15. #ifndef _PAGE_EXEC
  16. #define _PAGE_EXEC 0
  17. #endif
  18. #ifndef _PAGE_ENDIAN
  19. #define _PAGE_ENDIAN 0
  20. #endif
  21. #ifndef _PAGE_COHERENT
  22. #define _PAGE_COHERENT 0
  23. #endif
  24. #ifndef _PAGE_WRITETHRU
  25. #define _PAGE_WRITETHRU 0
  26. #endif
  27. #ifndef _PAGE_4K_PFN
  28. #define _PAGE_4K_PFN 0
  29. #endif
  30. #ifndef _PAGE_SAO
  31. #define _PAGE_SAO 0
  32. #endif
  33. #ifndef _PAGE_PSIZE
  34. #define _PAGE_PSIZE 0
  35. #endif
  36. /* _PAGE_RO and _PAGE_RW shall not be defined at the same time */
  37. #ifndef _PAGE_RO
  38. #define _PAGE_RO 0
  39. #else
  40. #define _PAGE_RW 0
  41. #endif
  42. #ifndef _PAGE_PTE
  43. #define _PAGE_PTE 0
  44. #endif
  45. #ifndef _PMD_PRESENT_MASK
  46. #define _PMD_PRESENT_MASK _PMD_PRESENT
  47. #endif
  48. #ifndef _PMD_SIZE
  49. #define _PMD_SIZE 0
  50. #define PMD_PAGE_SIZE(pmd) bad_call_to_PMD_PAGE_SIZE()
  51. #endif
  52. #ifndef _PAGE_KERNEL_RO
  53. #define _PAGE_KERNEL_RO (_PAGE_RO)
  54. #endif
  55. #ifndef _PAGE_KERNEL_ROX
  56. #define _PAGE_KERNEL_ROX (_PAGE_EXEC | _PAGE_RO)
  57. #endif
  58. #ifndef _PAGE_KERNEL_RW
  59. #define _PAGE_KERNEL_RW (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE)
  60. #endif
  61. #ifndef _PAGE_KERNEL_RWX
  62. #define _PAGE_KERNEL_RWX (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE | _PAGE_EXEC)
  63. #endif
  64. #ifndef _PAGE_HPTEFLAGS
  65. #define _PAGE_HPTEFLAGS _PAGE_HASHPTE
  66. #endif
  67. #ifndef _PTE_NONE_MASK
  68. #define _PTE_NONE_MASK _PAGE_HPTEFLAGS
  69. #endif
  70. /* Make sure we get a link error if PMD_PAGE_SIZE is ever called on a
  71. * kernel without large page PMD support
  72. */
  73. #ifndef __ASSEMBLY__
  74. extern unsigned long bad_call_to_PMD_PAGE_SIZE(void);
  75. /*
  76. * Don't just check for any non zero bits in __PAGE_USER, since for book3e
  77. * and PTE_64BIT, PAGE_KERNEL_X contains _PAGE_BAP_SR which is also in
  78. * _PAGE_USER. Need to explicitly match _PAGE_BAP_UR bit in that case too.
  79. */
  80. static inline bool pte_user(pte_t pte)
  81. {
  82. return (pte_val(pte) & _PAGE_USER) == _PAGE_USER;
  83. }
  84. #endif /* __ASSEMBLY__ */
  85. /* Location of the PFN in the PTE. Most 32-bit platforms use the same
  86. * as _PAGE_SHIFT here (ie, naturally aligned).
  87. * Platform who don't just pre-define the value so we don't override it here
  88. */
  89. #ifndef PTE_RPN_SHIFT
  90. #define PTE_RPN_SHIFT (PAGE_SHIFT)
  91. #endif
  92. /* The mask covered by the RPN must be a ULL on 32-bit platforms with
  93. * 64-bit PTEs
  94. */
  95. #if defined(CONFIG_PPC32) && defined(CONFIG_PTE_64BIT)
  96. #define PTE_RPN_MASK (~((1ULL<<PTE_RPN_SHIFT)-1))
  97. #else
  98. #define PTE_RPN_MASK (~((1UL<<PTE_RPN_SHIFT)-1))
  99. #endif
  100. /* _PAGE_CHG_MASK masks of bits that are to be preserved across
  101. * pgprot changes
  102. */
  103. #define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
  104. _PAGE_ACCESSED | _PAGE_SPECIAL)
  105. /* Mask of bits returned by pte_pgprot() */
  106. #define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \
  107. _PAGE_WRITETHRU | _PAGE_ENDIAN | _PAGE_4K_PFN | \
  108. _PAGE_USER | _PAGE_ACCESSED | _PAGE_RO | \
  109. _PAGE_RW | _PAGE_HWWRITE | _PAGE_DIRTY | _PAGE_EXEC)
  110. /*
  111. * We define 2 sets of base prot bits, one for basic pages (ie,
  112. * cacheable kernel and user pages) and one for non cacheable
  113. * pages. We always set _PAGE_COHERENT when SMP is enabled or
  114. * the processor might need it for DMA coherency.
  115. */
  116. #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
  117. #if defined(CONFIG_SMP) || defined(CONFIG_PPC_STD_MMU) || \
  118. defined(CONFIG_PPC_E500MC)
  119. #define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT)
  120. #else
  121. #define _PAGE_BASE (_PAGE_BASE_NC)
  122. #endif
  123. /* Permission masks used to generate the __P and __S table,
  124. *
  125. * Note:__pgprot is defined in arch/powerpc/include/asm/page.h
  126. *
  127. * Write permissions imply read permissions for now (we could make write-only
  128. * pages on BookE but we don't bother for now). Execute permission control is
  129. * possible on platforms that define _PAGE_EXEC
  130. *
  131. * Note due to the way vm flags are laid out, the bits are XWR
  132. */
  133. #define PAGE_NONE __pgprot(_PAGE_BASE)
  134. #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
  135. #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | \
  136. _PAGE_EXEC)
  137. #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
  138. #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
  139. _PAGE_EXEC)
  140. #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO)
  141. #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RO | \
  142. _PAGE_EXEC)
  143. #define __P000 PAGE_NONE
  144. #define __P001 PAGE_READONLY
  145. #define __P010 PAGE_COPY
  146. #define __P011 PAGE_COPY
  147. #define __P100 PAGE_READONLY_X
  148. #define __P101 PAGE_READONLY_X
  149. #define __P110 PAGE_COPY_X
  150. #define __P111 PAGE_COPY_X
  151. #define __S000 PAGE_NONE
  152. #define __S001 PAGE_READONLY
  153. #define __S010 PAGE_SHARED
  154. #define __S011 PAGE_SHARED
  155. #define __S100 PAGE_READONLY_X
  156. #define __S101 PAGE_READONLY_X
  157. #define __S110 PAGE_SHARED_X
  158. #define __S111 PAGE_SHARED_X
  159. /* Permission masks used for kernel mappings */
  160. #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
  161. #define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
  162. _PAGE_NO_CACHE)
  163. #define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
  164. _PAGE_NO_CACHE | _PAGE_GUARDED)
  165. #define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX)
  166. #define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
  167. #define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
  168. /* Protection used for kernel text. We want the debuggers to be able to
  169. * set breakpoints anywhere, so don't write protect the kernel text
  170. * on platforms where such control is possible.
  171. */
  172. #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\
  173. defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE)
  174. #define PAGE_KERNEL_TEXT PAGE_KERNEL_X
  175. #else
  176. #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX
  177. #endif
  178. /* Make modules code happy. We don't set RO yet */
  179. #define PAGE_KERNEL_EXEC PAGE_KERNEL_X
  180. /* Advertise special mapping type for AGP */
  181. #define PAGE_AGP (PAGE_KERNEL_NC)
  182. #define HAVE_PAGE_AGP
  183. /* Advertise support for _PAGE_SPECIAL */
  184. #define __HAVE_ARCH_PTE_SPECIAL
  185. #ifndef _PAGE_READ
  186. /* if not defined, we should not find _PAGE_WRITE too */
  187. #define _PAGE_READ 0
  188. #define _PAGE_WRITE _PAGE_RW
  189. #endif
  190. #ifndef H_PAGE_4K_PFN
  191. #define H_PAGE_4K_PFN 0
  192. #endif