mmu.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. #ifdef CONFIG_PPC_RADIX_MMU
  115. MMU_FTR_TYPE_RADIX |
  116. #endif
  117. 0,
  118. };
  119. static inline bool early_mmu_has_feature(unsigned long feature)
  120. {
  121. return !!(MMU_FTRS_POSSIBLE & cur_cpu_spec->mmu_features & feature);
  122. }
  123. #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
  124. #include <linux/jump_label.h>
  125. #define NUM_MMU_FTR_KEYS 32
  126. extern struct static_key_true mmu_feature_keys[NUM_MMU_FTR_KEYS];
  127. extern void mmu_feature_keys_init(void);
  128. static __always_inline bool mmu_has_feature(unsigned long feature)
  129. {
  130. int i;
  131. #ifndef __clang__ /* clang can't cope with this */
  132. BUILD_BUG_ON(!__builtin_constant_p(feature));
  133. #endif
  134. #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
  135. if (!static_key_initialized) {
  136. printk("Warning! mmu_has_feature() used prior to jump label init!\n");
  137. dump_stack();
  138. return early_mmu_has_feature(feature);
  139. }
  140. #endif
  141. if (!(MMU_FTRS_POSSIBLE & feature))
  142. return false;
  143. i = __builtin_ctzl(feature);
  144. return static_branch_likely(&mmu_feature_keys[i]);
  145. }
  146. static inline void mmu_clear_feature(unsigned long feature)
  147. {
  148. int i;
  149. i = __builtin_ctzl(feature);
  150. cur_cpu_spec->mmu_features &= ~feature;
  151. static_branch_disable(&mmu_feature_keys[i]);
  152. }
  153. #else
  154. static inline void mmu_feature_keys_init(void)
  155. {
  156. }
  157. static inline bool mmu_has_feature(unsigned long feature)
  158. {
  159. return early_mmu_has_feature(feature);
  160. }
  161. static inline void mmu_clear_feature(unsigned long feature)
  162. {
  163. cur_cpu_spec->mmu_features &= ~feature;
  164. }
  165. #endif /* CONFIG_JUMP_LABEL */
  166. extern unsigned int __start___mmu_ftr_fixup, __stop___mmu_ftr_fixup;
  167. #ifdef CONFIG_PPC64
  168. /* This is our real memory area size on ppc64 server, on embedded, we
  169. * make it match the size our of bolted TLB area
  170. */
  171. extern u64 ppc64_rma_size;
  172. /* Cleanup function used by kexec */
  173. extern void mmu_cleanup_all(void);
  174. extern void radix__mmu_cleanup_all(void);
  175. /* Functions for creating and updating partition table on POWER9 */
  176. extern void mmu_partition_table_init(void);
  177. extern void mmu_partition_table_set_entry(unsigned int lpid, unsigned long dw0,
  178. unsigned long dw1);
  179. #endif /* CONFIG_PPC64 */
  180. struct mm_struct;
  181. #ifdef CONFIG_DEBUG_VM
  182. extern void assert_pte_locked(struct mm_struct *mm, unsigned long addr);
  183. #else /* CONFIG_DEBUG_VM */
  184. static inline void assert_pte_locked(struct mm_struct *mm, unsigned long addr)
  185. {
  186. }
  187. #endif /* !CONFIG_DEBUG_VM */
  188. #ifdef CONFIG_PPC_RADIX_MMU
  189. static inline bool radix_enabled(void)
  190. {
  191. return mmu_has_feature(MMU_FTR_TYPE_RADIX);
  192. }
  193. static inline bool early_radix_enabled(void)
  194. {
  195. return early_mmu_has_feature(MMU_FTR_TYPE_RADIX);
  196. }
  197. #else
  198. static inline bool radix_enabled(void)
  199. {
  200. return false;
  201. }
  202. static inline bool early_radix_enabled(void)
  203. {
  204. return false;
  205. }
  206. #endif
  207. #endif /* !__ASSEMBLY__ */
  208. /* The kernel use the constants below to index in the page sizes array.
  209. * The use of fixed constants for this purpose is better for performances
  210. * of the low level hash refill handlers.
  211. *
  212. * A non supported page size has a "shift" field set to 0
  213. *
  214. * Any new page size being implemented can get a new entry in here. Whether
  215. * the kernel will use it or not is a different matter though. The actual page
  216. * size used by hugetlbfs is not defined here and may be made variable
  217. *
  218. * Note: This array ended up being a false good idea as it's growing to the
  219. * point where I wonder if we should replace it with something different,
  220. * to think about, feedback welcome. --BenH.
  221. */
  222. /* These are #defines as they have to be used in assembly */
  223. #define MMU_PAGE_4K 0
  224. #define MMU_PAGE_16K 1
  225. #define MMU_PAGE_64K 2
  226. #define MMU_PAGE_64K_AP 3 /* "Admixed pages" (hash64 only) */
  227. #define MMU_PAGE_256K 4
  228. #define MMU_PAGE_512K 5
  229. #define MMU_PAGE_1M 6
  230. #define MMU_PAGE_2M 7
  231. #define MMU_PAGE_4M 8
  232. #define MMU_PAGE_8M 9
  233. #define MMU_PAGE_16M 10
  234. #define MMU_PAGE_64M 11
  235. #define MMU_PAGE_256M 12
  236. #define MMU_PAGE_1G 13
  237. #define MMU_PAGE_16G 14
  238. #define MMU_PAGE_64G 15
  239. /* N.B. we need to change the type of hpte_page_sizes if this gets to be > 16 */
  240. #define MMU_PAGE_COUNT 16
  241. #ifdef CONFIG_PPC_BOOK3S_64
  242. #include <asm/book3s/64/mmu.h>
  243. #else /* CONFIG_PPC_BOOK3S_64 */
  244. #ifndef __ASSEMBLY__
  245. /* MMU initialization */
  246. extern void early_init_mmu(void);
  247. extern void early_init_mmu_secondary(void);
  248. extern void setup_initial_memory_limit(phys_addr_t first_memblock_base,
  249. phys_addr_t first_memblock_size);
  250. static inline void mmu_early_init_devtree(void) { }
  251. #endif /* __ASSEMBLY__ */
  252. #endif
  253. #if defined(CONFIG_PPC_STD_MMU_32)
  254. /* 32-bit classic hash table MMU */
  255. #include <asm/book3s/32/mmu-hash.h>
  256. #elif defined(CONFIG_40x)
  257. /* 40x-style software loaded TLB */
  258. # include <asm/mmu-40x.h>
  259. #elif defined(CONFIG_44x)
  260. /* 44x-style software loaded TLB */
  261. # include <asm/mmu-44x.h>
  262. #elif defined(CONFIG_PPC_BOOK3E_MMU)
  263. /* Freescale Book-E software loaded TLB or Book-3e (ISA 2.06+) MMU */
  264. # include <asm/mmu-book3e.h>
  265. #elif defined (CONFIG_PPC_8xx)
  266. /* Motorola/Freescale 8xx software loaded TLB */
  267. # include <asm/mmu-8xx.h>
  268. #endif
  269. #endif /* __KERNEL__ */
  270. #endif /* _ASM_POWERPC_MMU_H_ */