0001
0002 #ifndef _ASM_POWERPC_MMU_H_
0003 #define _ASM_POWERPC_MMU_H_
0004 #ifdef __KERNEL__
0005
0006 #include <linux/types.h>
0007
0008 #include <asm/asm-const.h>
0009
0010
0011
0012
0013
0014
0015
0016
0017 #define MMU_FTR_HPTE_TABLE ASM_CONST(0x00000001)
0018 #define MMU_FTR_TYPE_8xx ASM_CONST(0x00000002)
0019 #define MMU_FTR_TYPE_40x ASM_CONST(0x00000004)
0020 #define MMU_FTR_TYPE_44x ASM_CONST(0x00000008)
0021 #define MMU_FTR_TYPE_FSL_E ASM_CONST(0x00000010)
0022 #define MMU_FTR_TYPE_47x ASM_CONST(0x00000020)
0023
0024
0025 #define MMU_FTR_TYPE_RADIX ASM_CONST(0x00000040)
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #define MMU_FTR_BOOK3S_KUAP ASM_CONST(0x00000200)
0037
0038
0039
0040
0041
0042
0043 #define MMU_FTR_BOOK3S_KUEP ASM_CONST(0x00000400)
0044
0045
0046
0047
0048 #define MMU_FTR_PKEY ASM_CONST(0x00000800)
0049
0050
0051 #define MMU_FTR_GTSE ASM_CONST(0x00001000)
0052
0053
0054
0055
0056 #define MMU_FTR_68_BIT_VA ASM_CONST(0x00002000)
0057
0058
0059
0060
0061 #define MMU_FTR_KERNEL_RO ASM_CONST(0x00004000)
0062
0063
0064
0065
0066
0067 #define MMU_FTR_TLBIE_CROP_VA ASM_CONST(0x00008000)
0068
0069
0070 #define MMU_FTR_USE_HIGH_BATS ASM_CONST(0x00010000)
0071
0072
0073
0074
0075 #define MMU_FTR_BIG_PHYS ASM_CONST(0x00020000)
0076
0077
0078
0079
0080
0081 #define MMU_FTR_USE_TLBIVAX_BCAST ASM_CONST(0x00040000)
0082
0083
0084
0085 #define MMU_FTR_USE_TLBILX ASM_CONST(0x00080000)
0086
0087
0088
0089
0090
0091 #define MMU_FTR_LOCK_BCAST_INVAL ASM_CONST(0x00100000)
0092
0093
0094
0095
0096
0097 #define MMU_FTR_NEED_DTLB_SW_LRU ASM_CONST(0x00200000)
0098
0099
0100
0101 #define MMU_FTR_NO_SLBIE_B ASM_CONST(0x02000000)
0102
0103
0104
0105 #define MMU_FTR_16M_PAGE ASM_CONST(0x04000000)
0106
0107
0108
0109 #define MMU_FTR_TLBIEL ASM_CONST(0x08000000)
0110
0111
0112
0113 #define MMU_FTR_LOCKLESS_TLBIE ASM_CONST(0x10000000)
0114
0115
0116
0117 #define MMU_FTR_CI_LARGE_PAGE ASM_CONST(0x20000000)
0118
0119
0120
0121 #define MMU_FTR_1T_SEGMENT ASM_CONST(0x40000000)
0122
0123
0124 #define MMU_FTRS_DEFAULT_HPTE_ARCH_V2 (MMU_FTR_HPTE_TABLE | MMU_FTR_TLBIEL | MMU_FTR_16M_PAGE)
0125 #define MMU_FTRS_POWER MMU_FTRS_DEFAULT_HPTE_ARCH_V2
0126 #define MMU_FTRS_PPC970 MMU_FTRS_POWER | MMU_FTR_TLBIE_CROP_VA
0127 #define MMU_FTRS_POWER5 MMU_FTRS_POWER | MMU_FTR_LOCKLESS_TLBIE
0128 #define MMU_FTRS_POWER6 MMU_FTRS_POWER5 | MMU_FTR_KERNEL_RO | MMU_FTR_68_BIT_VA
0129 #define MMU_FTRS_POWER7 MMU_FTRS_POWER6
0130 #define MMU_FTRS_POWER8 MMU_FTRS_POWER6
0131 #define MMU_FTRS_POWER9 MMU_FTRS_POWER6
0132 #define MMU_FTRS_POWER10 MMU_FTRS_POWER6
0133 #define MMU_FTRS_CELL MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \
0134 MMU_FTR_CI_LARGE_PAGE
0135 #define MMU_FTRS_PA6T MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \
0136 MMU_FTR_CI_LARGE_PAGE | MMU_FTR_NO_SLBIE_B
0137 #ifndef __ASSEMBLY__
0138 #include <linux/bug.h>
0139 #include <asm/cputable.h>
0140 #include <asm/page.h>
0141
0142 typedef pte_t *pgtable_t;
0143
0144 #ifdef CONFIG_PPC_FSL_BOOK3E
0145 #include <asm/percpu.h>
0146 DECLARE_PER_CPU(int, next_tlbcam_idx);
0147 #endif
0148
0149 enum {
0150 MMU_FTRS_POSSIBLE =
0151 #if defined(CONFIG_PPC_BOOK3S_604)
0152 MMU_FTR_HPTE_TABLE |
0153 #endif
0154 #ifdef CONFIG_PPC_8xx
0155 MMU_FTR_TYPE_8xx |
0156 #endif
0157 #ifdef CONFIG_40x
0158 MMU_FTR_TYPE_40x |
0159 #endif
0160 #ifdef CONFIG_PPC_47x
0161 MMU_FTR_TYPE_47x | MMU_FTR_USE_TLBIVAX_BCAST | MMU_FTR_LOCK_BCAST_INVAL |
0162 #elif defined(CONFIG_44x)
0163 MMU_FTR_TYPE_44x |
0164 #endif
0165 #ifdef CONFIG_E500
0166 MMU_FTR_TYPE_FSL_E | MMU_FTR_BIG_PHYS | MMU_FTR_USE_TLBILX |
0167 #endif
0168 #ifdef CONFIG_PPC_BOOK3S_32
0169 MMU_FTR_USE_HIGH_BATS |
0170 #endif
0171 #ifdef CONFIG_PPC_83xx
0172 MMU_FTR_NEED_DTLB_SW_LRU |
0173 #endif
0174 #ifdef CONFIG_PPC_BOOK3S_64
0175 MMU_FTR_KERNEL_RO |
0176 #ifdef CONFIG_PPC_64S_HASH_MMU
0177 MMU_FTR_NO_SLBIE_B | MMU_FTR_16M_PAGE | MMU_FTR_TLBIEL |
0178 MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE |
0179 MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA |
0180 MMU_FTR_68_BIT_VA | MMU_FTR_HPTE_TABLE |
0181 #endif
0182 #ifdef CONFIG_PPC_RADIX_MMU
0183 MMU_FTR_TYPE_RADIX |
0184 MMU_FTR_GTSE |
0185 #endif
0186 #endif
0187 #ifdef CONFIG_PPC_KUAP
0188 MMU_FTR_BOOK3S_KUAP |
0189 #endif
0190 #ifdef CONFIG_PPC_MEM_KEYS
0191 MMU_FTR_PKEY |
0192 #endif
0193 #ifdef CONFIG_PPC_KUEP
0194 MMU_FTR_BOOK3S_KUEP |
0195 #endif
0196
0197 0,
0198 };
0199
0200 #if defined(CONFIG_PPC_BOOK3S_604) && !defined(CONFIG_PPC_BOOK3S_603)
0201 #define MMU_FTRS_ALWAYS MMU_FTR_HPTE_TABLE
0202 #endif
0203 #ifdef CONFIG_PPC_8xx
0204 #define MMU_FTRS_ALWAYS MMU_FTR_TYPE_8xx
0205 #endif
0206 #ifdef CONFIG_40x
0207 #define MMU_FTRS_ALWAYS MMU_FTR_TYPE_40x
0208 #endif
0209 #ifdef CONFIG_PPC_47x
0210 #define MMU_FTRS_ALWAYS MMU_FTR_TYPE_47x
0211 #elif defined(CONFIG_44x)
0212 #define MMU_FTRS_ALWAYS MMU_FTR_TYPE_44x
0213 #endif
0214 #ifdef CONFIG_E500
0215 #define MMU_FTRS_ALWAYS MMU_FTR_TYPE_FSL_E
0216 #endif
0217
0218
0219 #if defined(CONFIG_PPC_RADIX_MMU) && !defined(CONFIG_PPC_64S_HASH_MMU)
0220 #define MMU_FTRS_ALWAYS MMU_FTR_TYPE_RADIX
0221 #elif !defined(CONFIG_PPC_RADIX_MMU) && defined(CONFIG_PPC_64S_HASH_MMU)
0222 #define MMU_FTRS_ALWAYS MMU_FTR_HPTE_TABLE
0223 #endif
0224
0225 #ifndef MMU_FTRS_ALWAYS
0226 #define MMU_FTRS_ALWAYS 0
0227 #endif
0228
0229 static __always_inline bool early_mmu_has_feature(unsigned long feature)
0230 {
0231 if (MMU_FTRS_ALWAYS & feature)
0232 return true;
0233
0234 return !!(MMU_FTRS_POSSIBLE & cur_cpu_spec->mmu_features & feature);
0235 }
0236
0237 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
0238 #include <linux/jump_label.h>
0239
0240 #define NUM_MMU_FTR_KEYS 32
0241
0242 extern struct static_key_true mmu_feature_keys[NUM_MMU_FTR_KEYS];
0243
0244 extern void mmu_feature_keys_init(void);
0245
0246 static __always_inline bool mmu_has_feature(unsigned long feature)
0247 {
0248 int i;
0249
0250 #ifndef __clang__
0251 BUILD_BUG_ON(!__builtin_constant_p(feature));
0252 #endif
0253
0254 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
0255 if (!static_key_initialized) {
0256 printk("Warning! mmu_has_feature() used prior to jump label init!\n");
0257 dump_stack();
0258 return early_mmu_has_feature(feature);
0259 }
0260 #endif
0261
0262 if (MMU_FTRS_ALWAYS & feature)
0263 return true;
0264
0265 if (!(MMU_FTRS_POSSIBLE & feature))
0266 return false;
0267
0268 i = __builtin_ctzl(feature);
0269 return static_branch_likely(&mmu_feature_keys[i]);
0270 }
0271
0272 static inline void mmu_clear_feature(unsigned long feature)
0273 {
0274 int i;
0275
0276 i = __builtin_ctzl(feature);
0277 cur_cpu_spec->mmu_features &= ~feature;
0278 static_branch_disable(&mmu_feature_keys[i]);
0279 }
0280 #else
0281
0282 static inline void mmu_feature_keys_init(void)
0283 {
0284
0285 }
0286
0287 static __always_inline bool mmu_has_feature(unsigned long feature)
0288 {
0289 return early_mmu_has_feature(feature);
0290 }
0291
0292 static inline void mmu_clear_feature(unsigned long feature)
0293 {
0294 cur_cpu_spec->mmu_features &= ~feature;
0295 }
0296 #endif
0297
0298 extern unsigned int __start___mmu_ftr_fixup, __stop___mmu_ftr_fixup;
0299
0300 #ifdef CONFIG_PPC64
0301
0302
0303
0304 extern u64 ppc64_rma_size;
0305
0306
0307 extern void mmu_cleanup_all(void);
0308 extern void radix__mmu_cleanup_all(void);
0309
0310
0311 extern void mmu_partition_table_init(void);
0312 extern void mmu_partition_table_set_entry(unsigned int lpid, unsigned long dw0,
0313 unsigned long dw1, bool flush);
0314 #endif
0315
0316 struct mm_struct;
0317 #ifdef CONFIG_DEBUG_VM
0318 extern void assert_pte_locked(struct mm_struct *mm, unsigned long addr);
0319 #else
0320 static inline void assert_pte_locked(struct mm_struct *mm, unsigned long addr)
0321 {
0322 }
0323 #endif
0324
0325 static __always_inline bool radix_enabled(void)
0326 {
0327 return mmu_has_feature(MMU_FTR_TYPE_RADIX);
0328 }
0329
0330 static __always_inline bool early_radix_enabled(void)
0331 {
0332 return early_mmu_has_feature(MMU_FTR_TYPE_RADIX);
0333 }
0334
0335 #ifdef CONFIG_STRICT_KERNEL_RWX
0336 static inline bool strict_kernel_rwx_enabled(void)
0337 {
0338 return rodata_enabled;
0339 }
0340 #else
0341 static inline bool strict_kernel_rwx_enabled(void)
0342 {
0343 return false;
0344 }
0345 #endif
0346
0347 static inline bool strict_module_rwx_enabled(void)
0348 {
0349 return IS_ENABLED(CONFIG_STRICT_MODULE_RWX) && strict_kernel_rwx_enabled();
0350 }
0351 #endif
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369 #define MMU_PAGE_4K 0
0370 #define MMU_PAGE_16K 1
0371 #define MMU_PAGE_64K 2
0372 #define MMU_PAGE_64K_AP 3
0373 #define MMU_PAGE_256K 4
0374 #define MMU_PAGE_512K 5
0375 #define MMU_PAGE_1M 6
0376 #define MMU_PAGE_2M 7
0377 #define MMU_PAGE_4M 8
0378 #define MMU_PAGE_8M 9
0379 #define MMU_PAGE_16M 10
0380 #define MMU_PAGE_64M 11
0381 #define MMU_PAGE_256M 12
0382 #define MMU_PAGE_1G 13
0383 #define MMU_PAGE_16G 14
0384 #define MMU_PAGE_64G 15
0385
0386
0387
0388
0389
0390 #define MMU_PAGE_COUNT 16
0391
0392 #ifdef CONFIG_PPC_BOOK3S_64
0393 #include <asm/book3s/64/mmu.h>
0394 #else
0395
0396 #ifndef __ASSEMBLY__
0397
0398 extern void early_init_mmu(void);
0399 extern void early_init_mmu_secondary(void);
0400 extern void setup_initial_memory_limit(phys_addr_t first_memblock_base,
0401 phys_addr_t first_memblock_size);
0402 static inline void mmu_early_init_devtree(void) { }
0403
0404 static inline void pkey_early_init_devtree(void) {}
0405
0406 extern void *abatron_pteptrs[2];
0407 #endif
0408 #endif
0409
0410 #if defined(CONFIG_PPC_BOOK3S_32)
0411
0412 #include <asm/book3s/32/mmu-hash.h>
0413 #elif defined(CONFIG_PPC_MMU_NOHASH)
0414 #include <asm/nohash/mmu.h>
0415 #endif
0416
0417 #endif
0418 #endif