mmu.h 9.4 KB

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