0001
0002
0003
0004
0005
0006
0007 #ifndef __MIPS_ASM_MIPS_CPS_H__
0008 # error Please include asm/mips-cps.h rather than asm/mips-cm.h
0009 #endif
0010
0011 #ifndef __MIPS_ASM_MIPS_CM_H__
0012 #define __MIPS_ASM_MIPS_CM_H__
0013
0014 #include <linux/bitfield.h>
0015 #include <linux/bitops.h>
0016 #include <linux/errno.h>
0017
0018
0019 extern void __iomem *mips_gcr_base;
0020
0021
0022 extern void __iomem *mips_cm_l2sync_base;
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 extern phys_addr_t __mips_cm_phys_base(void);
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 extern int mips_cm_is64;
0049
0050
0051
0052
0053 #ifdef CONFIG_MIPS_CM
0054 extern void mips_cm_error_report(void);
0055 #else
0056 static inline void mips_cm_error_report(void) {}
0057 #endif
0058
0059
0060
0061
0062
0063
0064
0065 #ifdef CONFIG_MIPS_CM
0066 extern int mips_cm_probe(void);
0067 #else
0068 static inline int mips_cm_probe(void)
0069 {
0070 return -ENODEV;
0071 }
0072 #endif
0073
0074
0075
0076
0077
0078
0079 static inline bool mips_cm_present(void)
0080 {
0081 #ifdef CONFIG_MIPS_CM
0082 return mips_gcr_base != NULL;
0083 #else
0084 return false;
0085 #endif
0086 }
0087
0088
0089
0090
0091
0092
0093 static inline bool mips_cm_has_l2sync(void)
0094 {
0095 #ifdef CONFIG_MIPS_CM
0096 return mips_cm_l2sync_base != NULL;
0097 #else
0098 return false;
0099 #endif
0100 }
0101
0102
0103 #define MIPS_CM_GCB_OFS 0x0000
0104 #define MIPS_CM_CLCB_OFS 0x2000
0105 #define MIPS_CM_COCB_OFS 0x4000
0106 #define MIPS_CM_GDB_OFS 0x6000
0107
0108
0109 #define MIPS_CM_GCR_SIZE 0x8000
0110
0111
0112 #define MIPS_CM_L2SYNC_SIZE 0x1000
0113
0114 #define GCR_ACCESSOR_RO(sz, off, name) \
0115 CPS_ACCESSOR_RO(gcr, sz, MIPS_CM_GCB_OFS + off, name) \
0116 CPS_ACCESSOR_RO(gcr, sz, MIPS_CM_COCB_OFS + off, redir_##name)
0117
0118 #define GCR_ACCESSOR_RW(sz, off, name) \
0119 CPS_ACCESSOR_RW(gcr, sz, MIPS_CM_GCB_OFS + off, name) \
0120 CPS_ACCESSOR_RW(gcr, sz, MIPS_CM_COCB_OFS + off, redir_##name)
0121
0122 #define GCR_CX_ACCESSOR_RO(sz, off, name) \
0123 CPS_ACCESSOR_RO(gcr, sz, MIPS_CM_CLCB_OFS + off, cl_##name) \
0124 CPS_ACCESSOR_RO(gcr, sz, MIPS_CM_COCB_OFS + off, co_##name)
0125
0126 #define GCR_CX_ACCESSOR_RW(sz, off, name) \
0127 CPS_ACCESSOR_RW(gcr, sz, MIPS_CM_CLCB_OFS + off, cl_##name) \
0128 CPS_ACCESSOR_RW(gcr, sz, MIPS_CM_COCB_OFS + off, co_##name)
0129
0130
0131 GCR_ACCESSOR_RO(64, 0x000, config)
0132 #define CM_GCR_CONFIG_CLUSTER_COH_CAPABLE BIT_ULL(43)
0133 #define CM_GCR_CONFIG_CLUSTER_ID GENMASK_ULL(39, 32)
0134 #define CM_GCR_CONFIG_NUM_CLUSTERS GENMASK(29, 23)
0135 #define CM_GCR_CONFIG_NUMIOCU GENMASK(15, 8)
0136 #define CM_GCR_CONFIG_PCORES GENMASK(7, 0)
0137
0138
0139 GCR_ACCESSOR_RW(64, 0x008, base)
0140 #define CM_GCR_BASE_GCRBASE GENMASK_ULL(47, 15)
0141 #define CM_GCR_BASE_CMDEFTGT GENMASK(1, 0)
0142 #define CM_GCR_BASE_CMDEFTGT_MEM 0
0143 #define CM_GCR_BASE_CMDEFTGT_RESERVED 1
0144 #define CM_GCR_BASE_CMDEFTGT_IOCU0 2
0145 #define CM_GCR_BASE_CMDEFTGT_IOCU1 3
0146
0147
0148 GCR_ACCESSOR_RW(32, 0x020, access)
0149 #define CM_GCR_ACCESS_ACCESSEN GENMASK(7, 0)
0150
0151
0152 GCR_ACCESSOR_RO(32, 0x030, rev)
0153 #define CM_GCR_REV_MAJOR GENMASK(15, 8)
0154 #define CM_GCR_REV_MINOR GENMASK(7, 0)
0155
0156 #define CM_ENCODE_REV(major, minor) \
0157 (FIELD_PREP(CM_GCR_REV_MAJOR, major) | \
0158 FIELD_PREP(CM_GCR_REV_MINOR, minor))
0159
0160 #define CM_REV_CM2 CM_ENCODE_REV(6, 0)
0161 #define CM_REV_CM2_5 CM_ENCODE_REV(7, 0)
0162 #define CM_REV_CM3 CM_ENCODE_REV(8, 0)
0163 #define CM_REV_CM3_5 CM_ENCODE_REV(9, 0)
0164
0165
0166 GCR_ACCESSOR_RW(32, 0x038, err_control)
0167 #define CM_GCR_ERR_CONTROL_L2_ECC_EN BIT(1)
0168 #define CM_GCR_ERR_CONTROL_L2_ECC_SUPPORT BIT(0)
0169
0170
0171 GCR_ACCESSOR_RW(64, 0x040, error_mask)
0172
0173
0174 GCR_ACCESSOR_RW(64, 0x048, error_cause)
0175 #define CM_GCR_ERROR_CAUSE_ERRTYPE GENMASK(31, 27)
0176 #define CM3_GCR_ERROR_CAUSE_ERRTYPE GENMASK_ULL(63, 58)
0177 #define CM_GCR_ERROR_CAUSE_ERRINFO GENMASK(26, 0)
0178
0179
0180 GCR_ACCESSOR_RW(64, 0x050, error_addr)
0181
0182
0183 GCR_ACCESSOR_RW(64, 0x058, error_mult)
0184 #define CM_GCR_ERROR_MULT_ERR2ND GENMASK(4, 0)
0185
0186
0187 GCR_ACCESSOR_RW(64, 0x070, l2_only_sync_base)
0188 #define CM_GCR_L2_ONLY_SYNC_BASE_SYNCBASE GENMASK(31, 12)
0189 #define CM_GCR_L2_ONLY_SYNC_BASE_SYNCEN BIT(0)
0190
0191
0192 GCR_ACCESSOR_RW(64, 0x080, gic_base)
0193 #define CM_GCR_GIC_BASE_GICBASE GENMASK(31, 17)
0194 #define CM_GCR_GIC_BASE_GICEN BIT(0)
0195
0196
0197 GCR_ACCESSOR_RW(64, 0x088, cpc_base)
0198 #define CM_GCR_CPC_BASE_CPCBASE GENMASK(31, 15)
0199 #define CM_GCR_CPC_BASE_CPCEN BIT(0)
0200
0201
0202 GCR_ACCESSOR_RW(64, 0x090, reg0_base)
0203 GCR_ACCESSOR_RW(64, 0x0a0, reg1_base)
0204 GCR_ACCESSOR_RW(64, 0x0b0, reg2_base)
0205 GCR_ACCESSOR_RW(64, 0x0c0, reg3_base)
0206 #define CM_GCR_REGn_BASE_BASEADDR GENMASK(31, 16)
0207
0208
0209 GCR_ACCESSOR_RW(64, 0x098, reg0_mask)
0210 GCR_ACCESSOR_RW(64, 0x0a8, reg1_mask)
0211 GCR_ACCESSOR_RW(64, 0x0b8, reg2_mask)
0212 GCR_ACCESSOR_RW(64, 0x0c8, reg3_mask)
0213 #define CM_GCR_REGn_MASK_ADDRMASK GENMASK(31, 16)
0214 #define CM_GCR_REGn_MASK_CCAOVR GENMASK(7, 5)
0215 #define CM_GCR_REGn_MASK_CCAOVREN BIT(4)
0216 #define CM_GCR_REGn_MASK_DROPL2 BIT(2)
0217 #define CM_GCR_REGn_MASK_CMTGT GENMASK(1, 0)
0218 #define CM_GCR_REGn_MASK_CMTGT_DISABLED 0x0
0219 #define CM_GCR_REGn_MASK_CMTGT_MEM 0x1
0220 #define CM_GCR_REGn_MASK_CMTGT_IOCU0 0x2
0221 #define CM_GCR_REGn_MASK_CMTGT_IOCU1 0x3
0222
0223
0224 GCR_ACCESSOR_RO(32, 0x0d0, gic_status)
0225 #define CM_GCR_GIC_STATUS_EX BIT(0)
0226
0227
0228 GCR_ACCESSOR_RO(32, 0x0f0, cpc_status)
0229 #define CM_GCR_CPC_STATUS_EX BIT(0)
0230
0231
0232 GCR_ACCESSOR_RW(32, 0x130, l2_config)
0233 #define CM_GCR_L2_CONFIG_BYPASS BIT(20)
0234 #define CM_GCR_L2_CONFIG_SET_SIZE GENMASK(15, 12)
0235 #define CM_GCR_L2_CONFIG_LINE_SIZE GENMASK(11, 8)
0236 #define CM_GCR_L2_CONFIG_ASSOC GENMASK(7, 0)
0237
0238
0239 GCR_ACCESSOR_RO(32, 0x150, sys_config2)
0240 #define CM_GCR_SYS_CONFIG2_MAXVPW GENMASK(3, 0)
0241
0242
0243 GCR_ACCESSOR_RW(32, 0x300, l2_pft_control)
0244 #define CM_GCR_L2_PFT_CONTROL_PAGEMASK GENMASK(31, 12)
0245 #define CM_GCR_L2_PFT_CONTROL_PFTEN BIT(8)
0246 #define CM_GCR_L2_PFT_CONTROL_NPFT GENMASK(7, 0)
0247
0248
0249 GCR_ACCESSOR_RW(32, 0x308, l2_pft_control_b)
0250 #define CM_GCR_L2_PFT_CONTROL_B_CEN BIT(8)
0251 #define CM_GCR_L2_PFT_CONTROL_B_PORTID GENMASK(7, 0)
0252
0253
0254 GCR_ACCESSOR_RW(32, 0x620, l2sm_cop)
0255 #define CM_GCR_L2SM_COP_PRESENT BIT(31)
0256 #define CM_GCR_L2SM_COP_RESULT GENMASK(8, 6)
0257 #define CM_GCR_L2SM_COP_RESULT_DONTCARE 0
0258 #define CM_GCR_L2SM_COP_RESULT_DONE_OK 1
0259 #define CM_GCR_L2SM_COP_RESULT_DONE_ERROR 2
0260 #define CM_GCR_L2SM_COP_RESULT_ABORT_OK 3
0261 #define CM_GCR_L2SM_COP_RESULT_ABORT_ERROR 4
0262 #define CM_GCR_L2SM_COP_RUNNING BIT(5)
0263 #define CM_GCR_L2SM_COP_TYPE GENMASK(4, 2)
0264 #define CM_GCR_L2SM_COP_TYPE_IDX_WBINV 0
0265 #define CM_GCR_L2SM_COP_TYPE_IDX_STORETAG 1
0266 #define CM_GCR_L2SM_COP_TYPE_IDX_STORETAGDATA 2
0267 #define CM_GCR_L2SM_COP_TYPE_HIT_INV 4
0268 #define CM_GCR_L2SM_COP_TYPE_HIT_WBINV 5
0269 #define CM_GCR_L2SM_COP_TYPE_HIT_WB 6
0270 #define CM_GCR_L2SM_COP_TYPE_FETCHLOCK 7
0271 #define CM_GCR_L2SM_COP_CMD GENMASK(1, 0)
0272 #define CM_GCR_L2SM_COP_CMD_START 1
0273 #define CM_GCR_L2SM_COP_CMD_ABORT 3
0274
0275
0276 GCR_ACCESSOR_RW(64, 0x628, l2sm_tag_addr_cop)
0277 #define CM_GCR_L2SM_TAG_ADDR_COP_NUM_LINES GENMASK_ULL(63, 48)
0278 #define CM_GCR_L2SM_TAG_ADDR_COP_START_TAG GENMASK_ULL(47, 6)
0279
0280
0281 GCR_ACCESSOR_RW(64, 0x680, bev_base)
0282
0283
0284 GCR_CX_ACCESSOR_RW(32, 0x000, reset_release)
0285
0286
0287 GCR_CX_ACCESSOR_RW(32, 0x008, coherence)
0288 #define CM_GCR_Cx_COHERENCE_COHDOMAINEN GENMASK(7, 0)
0289 #define CM3_GCR_Cx_COHERENCE_COHEN BIT(0)
0290
0291
0292 GCR_CX_ACCESSOR_RO(32, 0x010, config)
0293 #define CM_GCR_Cx_CONFIG_IOCUTYPE GENMASK(11, 10)
0294 #define CM_GCR_Cx_CONFIG_PVPE GENMASK(9, 0)
0295
0296
0297 GCR_CX_ACCESSOR_RW(32, 0x018, other)
0298 #define CM_GCR_Cx_OTHER_CORENUM GENMASK(31, 16)
0299 #define CM_GCR_Cx_OTHER_CLUSTER_EN BIT(31)
0300 #define CM_GCR_Cx_OTHER_GIC_EN BIT(30)
0301 #define CM_GCR_Cx_OTHER_BLOCK GENMASK(25, 24)
0302 #define CM_GCR_Cx_OTHER_BLOCK_LOCAL 0
0303 #define CM_GCR_Cx_OTHER_BLOCK_GLOBAL 1
0304 #define CM_GCR_Cx_OTHER_BLOCK_USER 2
0305 #define CM_GCR_Cx_OTHER_BLOCK_GLOBAL_HIGH 3
0306 #define CM_GCR_Cx_OTHER_CLUSTER GENMASK(21, 16)
0307 #define CM3_GCR_Cx_OTHER_CORE GENMASK(13, 8)
0308 #define CM_GCR_Cx_OTHER_CORE_CM 32
0309 #define CM3_GCR_Cx_OTHER_VP GENMASK(2, 0)
0310
0311
0312 GCR_CX_ACCESSOR_RW(32, 0x020, reset_base)
0313 #define CM_GCR_Cx_RESET_BASE_BEVEXCBASE GENMASK(31, 12)
0314
0315
0316 GCR_CX_ACCESSOR_RO(32, 0x028, id)
0317 #define CM_GCR_Cx_ID_CLUSTER GENMASK(15, 8)
0318 #define CM_GCR_Cx_ID_CORE GENMASK(7, 0)
0319
0320
0321 GCR_CX_ACCESSOR_RW(32, 0x030, reset_ext_base)
0322 #define CM_GCR_Cx_RESET_EXT_BASE_EVARESET BIT(31)
0323 #define CM_GCR_Cx_RESET_EXT_BASE_UEB BIT(30)
0324 #define CM_GCR_Cx_RESET_EXT_BASE_BEVEXCMASK GENMASK(27, 20)
0325 #define CM_GCR_Cx_RESET_EXT_BASE_BEVEXCPA GENMASK(7, 1)
0326 #define CM_GCR_Cx_RESET_EXT_BASE_PRESENT BIT(0)
0327
0328
0329
0330
0331
0332
0333
0334 static inline int mips_cm_l2sync(void)
0335 {
0336 if (!mips_cm_has_l2sync())
0337 return -ENODEV;
0338
0339 writel(0, mips_cm_l2sync_base);
0340 return 0;
0341 }
0342
0343
0344
0345
0346
0347
0348
0349 static inline int mips_cm_revision(void)
0350 {
0351 if (!mips_cm_present())
0352 return 0;
0353
0354 return read_gcr_rev();
0355 }
0356
0357
0358
0359
0360
0361
0362
0363 static inline unsigned int mips_cm_max_vp_width(void)
0364 {
0365 extern int smp_num_siblings;
0366
0367 if (mips_cm_revision() >= CM_REV_CM3)
0368 return FIELD_GET(CM_GCR_SYS_CONFIG2_MAXVPW,
0369 read_gcr_sys_config2());
0370
0371 if (mips_cm_present()) {
0372
0373
0374
0375
0376
0377 return FIELD_GET(CM_GCR_Cx_CONFIG_PVPE, read_gcr_cl_config()) + 1;
0378 }
0379
0380 if (IS_ENABLED(CONFIG_SMP))
0381 return smp_num_siblings;
0382
0383 return 1;
0384 }
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396 static inline unsigned int mips_cm_vp_id(unsigned int cpu)
0397 {
0398 unsigned int core = cpu_core(&cpu_data[cpu]);
0399 unsigned int vp = cpu_vpe_id(&cpu_data[cpu]);
0400
0401 return (core * mips_cm_max_vp_width()) + vp;
0402 }
0403
0404 #ifdef CONFIG_MIPS_CM
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424 extern void mips_cm_lock_other(unsigned int cluster, unsigned int core,
0425 unsigned int vp, unsigned int block);
0426
0427
0428
0429
0430
0431
0432
0433 extern void mips_cm_unlock_other(void);
0434
0435 #else
0436
0437 static inline void mips_cm_lock_other(unsigned int cluster, unsigned int core,
0438 unsigned int vp, unsigned int block) { }
0439 static inline void mips_cm_unlock_other(void) { }
0440
0441 #endif
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452 static inline void mips_cm_lock_other_cpu(unsigned int cpu, unsigned int block)
0453 {
0454 struct cpuinfo_mips *d = &cpu_data[cpu];
0455
0456 mips_cm_lock_other(cpu_cluster(d), cpu_core(d), cpu_vpe_id(d), block);
0457 }
0458
0459 #endif