mmu.h 9.4 KB

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