mmu.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #ifndef _ASM_POWERPC_MMU_H_
  2. #define _ASM_POWERPC_MMU_H_
  3. #ifdef __KERNEL__
  4. #include <linux/types.h>
  5. #include <asm/asm-compat.h>
  6. #include <asm/feature-fixups.h>
  7. /*
  8. * MMU features bit definitions
  9. */
  10. /*
  11. * MMU families
  12. */
  13. #define MMU_FTR_HPTE_TABLE ASM_CONST(0x00000001)
  14. #define MMU_FTR_TYPE_8xx ASM_CONST(0x00000002)
  15. #define MMU_FTR_TYPE_40x ASM_CONST(0x00000004)
  16. #define MMU_FTR_TYPE_44x ASM_CONST(0x00000008)
  17. #define MMU_FTR_TYPE_FSL_E ASM_CONST(0x00000010)
  18. #define MMU_FTR_TYPE_47x ASM_CONST(0x00000020)
  19. /* Radix page table supported and enabled */
  20. #define MMU_FTR_TYPE_RADIX ASM_CONST(0x00000040)
  21. /*
  22. * Individual features below.
  23. */
  24. /*
  25. * Kernel read only support.
  26. * We added the ppp value 0b110 in ISA 2.04.
  27. */
  28. #define MMU_FTR_KERNEL_RO ASM_CONST(0x00004000)
  29. /*
  30. * We need to clear top 16bits of va (from the remaining 64 bits )in
  31. * tlbie* instructions
  32. */
  33. #define MMU_FTR_TLBIE_CROP_VA ASM_CONST(0x00008000)
  34. /* Enable use of high BAT registers */
  35. #define MMU_FTR_USE_HIGH_BATS ASM_CONST(0x00010000)
  36. /* Enable >32-bit physical addresses on 32-bit processor, only used
  37. * by CONFIG_6xx currently as BookE supports that from day 1
  38. */
  39. #define MMU_FTR_BIG_PHYS ASM_CONST(0x00020000)
  40. /* Enable use of broadcast TLB invalidations. We don't always set it
  41. * on processors that support it due to other constraints with the
  42. * use of such invalidations
  43. */
  44. #define MMU_FTR_USE_TLBIVAX_BCAST ASM_CONST(0x00040000)
  45. /* Enable use of tlbilx invalidate instructions.
  46. */
  47. #define MMU_FTR_USE_TLBILX ASM_CONST(0x00080000)
  48. /* This indicates that the processor cannot handle multiple outstanding
  49. * broadcast tlbivax or tlbsync. This makes the code use a spinlock
  50. * around such invalidate forms.
  51. */
  52. #define MMU_FTR_LOCK_BCAST_INVAL ASM_CONST(0x00100000)
  53. /* This indicates that the processor doesn't handle way selection
  54. * properly and needs SW to track and update the LRU state. This
  55. * is specific to an errata on e300c2/c3/c4 class parts
  56. */
  57. #define MMU_FTR_NEED_DTLB_SW_LRU ASM_CONST(0x00200000)
  58. /* Enable use of TLB reservation. Processor should support tlbsrx.
  59. * instruction and MAS0[WQ].
  60. */
  61. #define MMU_FTR_USE_TLBRSRV ASM_CONST(0x00800000)
  62. /* Use paired MAS registers (MAS7||MAS3, etc.)
  63. */
  64. #define MMU_FTR_USE_PAIRED_MAS ASM_CONST(0x01000000)
  65. /* Doesn't support the B bit (1T segment) in SLBIE
  66. */
  67. #define MMU_FTR_NO_SLBIE_B ASM_CONST(0x02000000)
  68. /* Support 16M large pages
  69. */
  70. #define MMU_FTR_16M_PAGE ASM_CONST(0x04000000)
  71. /* Supports TLBIEL variant
  72. */
  73. #define MMU_FTR_TLBIEL ASM_CONST(0x08000000)
  74. /* Supports tlbies w/o locking
  75. */
  76. #define MMU_FTR_LOCKLESS_TLBIE ASM_CONST(0x10000000)
  77. /* Large pages can be marked CI
  78. */
  79. #define MMU_FTR_CI_LARGE_PAGE ASM_CONST(0x20000000)
  80. /* 1T segments available
  81. */
  82. #define MMU_FTR_1T_SEGMENT ASM_CONST(0x40000000)
  83. /* MMU feature bit sets for various CPUs */
  84. #define MMU_FTRS_DEFAULT_HPTE_ARCH_V2 \
  85. MMU_FTR_HPTE_TABLE | MMU_FTR_PPCAS_ARCH_V2
  86. #define MMU_FTRS_POWER4 MMU_FTRS_DEFAULT_HPTE_ARCH_V2
  87. #define MMU_FTRS_PPC970 MMU_FTRS_POWER4 | MMU_FTR_TLBIE_CROP_VA
  88. #define MMU_FTRS_POWER5 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE
  89. #define MMU_FTRS_POWER6 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO
  90. #define MMU_FTRS_POWER7 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO
  91. #define MMU_FTRS_POWER8 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO
  92. #define MMU_FTRS_POWER9 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_KERNEL_RO
  93. #define MMU_FTRS_CELL MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \
  94. MMU_FTR_CI_LARGE_PAGE
  95. #define MMU_FTRS_PA6T MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \
  96. MMU_FTR_CI_LARGE_PAGE | MMU_FTR_NO_SLBIE_B
  97. #ifndef __ASSEMBLY__
  98. #include <linux/bug.h>
  99. #include <asm/cputable.h>
  100. #ifdef CONFIG_PPC_FSL_BOOK3E
  101. #include <asm/percpu.h>
  102. DECLARE_PER_CPU(int, next_tlbcam_idx);
  103. #endif
  104. enum {
  105. MMU_FTRS_POSSIBLE = MMU_FTR_HPTE_TABLE | MMU_FTR_TYPE_8xx |
  106. MMU_FTR_TYPE_40x | MMU_FTR_TYPE_44x | MMU_FTR_TYPE_FSL_E |
  107. MMU_FTR_TYPE_47x | MMU_FTR_USE_HIGH_BATS | MMU_FTR_BIG_PHYS |
  108. MMU_FTR_USE_TLBIVAX_BCAST | MMU_FTR_USE_TLBILX |
  109. MMU_FTR_LOCK_BCAST_INVAL | MMU_FTR_NEED_DTLB_SW_LRU |
  110. MMU_FTR_USE_TLBRSRV | MMU_FTR_USE_PAIRED_MAS |
  111. MMU_FTR_NO_SLBIE_B | MMU_FTR_16M_PAGE | MMU_FTR_TLBIEL |
  112. MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE |
  113. MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA |
  114. MMU_FTR_KERNEL_RO |
  115. #ifdef CONFIG_PPC_RADIX_MMU
  116. MMU_FTR_TYPE_RADIX |
  117. #endif
  118. 0,
  119. };
  120. static inline bool early_mmu_has_feature(unsigned long feature)
  121. {
  122. return !!(MMU_FTRS_POSSIBLE & cur_cpu_spec->mmu_features & feature);
  123. }
  124. #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
  125. #include <linux/jump_label.h>
  126. #define NUM_MMU_FTR_KEYS 32
  127. extern struct static_key_true mmu_feature_keys[NUM_MMU_FTR_KEYS];
  128. extern void mmu_feature_keys_init(void);
  129. static __always_inline bool mmu_has_feature(unsigned long feature)
  130. {
  131. int i;
  132. #ifndef __clang__ /* clang can't cope with this */
  133. BUILD_BUG_ON(!__builtin_constant_p(feature));
  134. #endif
  135. #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
  136. if (!static_key_initialized) {
  137. printk("Warning! mmu_has_feature() used prior to jump label init!\n");
  138. dump_stack();
  139. return early_mmu_has_feature(feature);
  140. }
  141. #endif
  142. if (!(MMU_FTRS_POSSIBLE & feature))
  143. return false;
  144. i = __builtin_ctzl(feature);
  145. return static_branch_likely(&mmu_feature_keys[i]);
  146. }
  147. static inline void mmu_clear_feature(unsigned long feature)
  148. {
  149. int i;
  150. i = __builtin_ctzl(feature);
  151. cur_cpu_spec->mmu_features &= ~feature;
  152. static_branch_disable(&mmu_feature_keys[i]);
  153. }
  154. #else
  155. static inline void mmu_feature_keys_init(void)
  156. {
  157. }
  158. static inline bool mmu_has_feature(unsigned long feature)
  159. {
  160. return early_mmu_has_feature(feature);
  161. }
  162. static inline void mmu_clear_feature(unsigned long feature)
  163. {
  164. cur_cpu_spec->mmu_features &= ~feature;
  165. }
  166. #endif /* CONFIG_JUMP_LABEL */
  167. extern unsigned int __start___mmu_ftr_fixup, __stop___mmu_ftr_fixup;
  168. #ifdef CONFIG_PPC64
  169. /* This is our real memory area size on ppc64 server, on embedded, we
  170. * make it match the size our of bolted TLB area
  171. */
  172. extern u64 ppc64_rma_size;
  173. /* Cleanup function used by kexec */
  174. extern void mmu_cleanup_all(void);
  175. extern void radix__mmu_cleanup_all(void);
  176. #endif /* CONFIG_PPC64 */
  177. struct mm_struct;
  178. #ifdef CONFIG_DEBUG_VM
  179. extern void assert_pte_locked(struct mm_struct *mm, unsigned long addr);
  180. #else /* CONFIG_DEBUG_VM */
  181. static inline void assert_pte_locked(struct mm_struct *mm, unsigned long addr)
  182. {
  183. }
  184. #endif /* !CONFIG_DEBUG_VM */
  185. #ifdef CONFIG_PPC_RADIX_MMU
  186. static inline bool radix_enabled(void)
  187. {
  188. return mmu_has_feature(MMU_FTR_TYPE_RADIX);
  189. }
  190. static inline bool early_radix_enabled(void)
  191. {
  192. return early_mmu_has_feature(MMU_FTR_TYPE_RADIX);
  193. }
  194. #else
  195. static inline bool radix_enabled(void)
  196. {
  197. return false;
  198. }
  199. static inline bool early_radix_enabled(void)
  200. {
  201. return false;
  202. }
  203. #endif
  204. #endif /* !__ASSEMBLY__ */
  205. /* The kernel use the constants below to index in the page sizes array.
  206. * The use of fixed constants for this purpose is better for performances
  207. * of the low level hash refill handlers.
  208. *
  209. * A non supported page size has a "shift" field set to 0
  210. *
  211. * Any new page size being implemented can get a new entry in here. Whether
  212. * the kernel will use it or not is a different matter though. The actual page
  213. * size used by hugetlbfs is not defined here and may be made variable
  214. *
  215. * Note: This array ended up being a false good idea as it's growing to the
  216. * point where I wonder if we should replace it with something different,
  217. * to think about, feedback welcome. --BenH.
  218. */
  219. /* These are #defines as they have to be used in assembly */
  220. #define MMU_PAGE_4K 0
  221. #define MMU_PAGE_16K 1
  222. #define MMU_PAGE_64K 2
  223. #define MMU_PAGE_64K_AP 3 /* "Admixed pages" (hash64 only) */
  224. #define MMU_PAGE_256K 4
  225. #define MMU_PAGE_1M 5
  226. #define MMU_PAGE_2M 6
  227. #define MMU_PAGE_4M 7
  228. #define MMU_PAGE_8M 8
  229. #define MMU_PAGE_16M 9
  230. #define MMU_PAGE_64M 10
  231. #define MMU_PAGE_256M 11
  232. #define MMU_PAGE_1G 12
  233. #define MMU_PAGE_16G 13
  234. #define MMU_PAGE_64G 14
  235. /* N.B. we need to change the type of hpte_page_sizes if this gets to be > 16 */
  236. #define MMU_PAGE_COUNT 15
  237. #ifdef CONFIG_PPC_BOOK3S_64
  238. #include <asm/book3s/64/mmu.h>
  239. #else /* CONFIG_PPC_BOOK3S_64 */
  240. #ifndef __ASSEMBLY__
  241. /* MMU initialization */
  242. extern void early_init_mmu(void);
  243. extern void early_init_mmu_secondary(void);
  244. extern void setup_initial_memory_limit(phys_addr_t first_memblock_base,
  245. phys_addr_t first_memblock_size);
  246. static inline void mmu_early_init_devtree(void) { }
  247. #endif /* __ASSEMBLY__ */
  248. #endif
  249. #if defined(CONFIG_PPC_STD_MMU_32)
  250. /* 32-bit classic hash table MMU */
  251. #include <asm/book3s/32/mmu-hash.h>
  252. #elif defined(CONFIG_40x)
  253. /* 40x-style software loaded TLB */
  254. # include <asm/mmu-40x.h>
  255. #elif defined(CONFIG_44x)
  256. /* 44x-style software loaded TLB */
  257. # include <asm/mmu-44x.h>
  258. #elif defined(CONFIG_PPC_BOOK3E_MMU)
  259. /* Freescale Book-E software loaded TLB or Book-3e (ISA 2.06+) MMU */
  260. # include <asm/mmu-book3e.h>
  261. #elif defined (CONFIG_PPC_8xx)
  262. /* Motorola/Freescale 8xx software loaded TLB */
  263. # include <asm/mmu-8xx.h>
  264. #endif
  265. #endif /* __KERNEL__ */
  266. #endif /* _ASM_POWERPC_MMU_H_ */