0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef PMC_CORE_H
0013 #define PMC_CORE_H
0014
0015 #include <linux/bits.h>
0016
0017 #define PMC_BASE_ADDR_DEFAULT 0xFE000000
0018
0019
0020 #define SPT_PMC_PCI_DEVICE_ID 0x9d21
0021 #define SPT_PMC_BASE_ADDR_OFFSET 0x48
0022 #define SPT_PMC_SLP_S0_RES_COUNTER_OFFSET 0x13c
0023 #define SPT_PMC_PM_CFG_OFFSET 0x18
0024 #define SPT_PMC_PM_STS_OFFSET 0x1c
0025 #define SPT_PMC_MTPMC_OFFSET 0x20
0026 #define SPT_PMC_MFPMC_OFFSET 0x38
0027 #define SPT_PMC_LTR_IGNORE_OFFSET 0x30C
0028 #define SPT_PMC_VRIC1_OFFSET 0x31c
0029 #define SPT_PMC_MPHY_CORE_STS_0 0x1143
0030 #define SPT_PMC_MPHY_CORE_STS_1 0x1142
0031 #define SPT_PMC_MPHY_COM_STS_0 0x1155
0032 #define SPT_PMC_MMIO_REG_LEN 0x1000
0033 #define SPT_PMC_SLP_S0_RES_COUNTER_STEP 0x68
0034 #define PMC_BASE_ADDR_MASK ~(SPT_PMC_MMIO_REG_LEN - 1)
0035 #define MTPMC_MASK 0xffff0000
0036 #define PPFEAR_MAX_NUM_ENTRIES 12
0037 #define SPT_PPFEAR_NUM_ENTRIES 5
0038 #define SPT_PMC_READ_DISABLE_BIT 0x16
0039 #define SPT_PMC_MSG_FULL_STS_BIT 0x18
0040 #define NUM_RETRIES 100
0041 #define SPT_NUM_IP_IGN_ALLOWED 17
0042
0043 #define SPT_PMC_LTR_CUR_PLT 0x350
0044 #define SPT_PMC_LTR_CUR_ASLT 0x354
0045 #define SPT_PMC_LTR_SPA 0x360
0046 #define SPT_PMC_LTR_SPB 0x364
0047 #define SPT_PMC_LTR_SATA 0x368
0048 #define SPT_PMC_LTR_GBE 0x36C
0049 #define SPT_PMC_LTR_XHCI 0x370
0050 #define SPT_PMC_LTR_RESERVED 0x374
0051 #define SPT_PMC_LTR_ME 0x378
0052 #define SPT_PMC_LTR_EVA 0x37C
0053 #define SPT_PMC_LTR_SPC 0x380
0054 #define SPT_PMC_LTR_AZ 0x384
0055 #define SPT_PMC_LTR_LPSS 0x38C
0056 #define SPT_PMC_LTR_CAM 0x390
0057 #define SPT_PMC_LTR_SPD 0x394
0058 #define SPT_PMC_LTR_SPE 0x398
0059 #define SPT_PMC_LTR_ESPI 0x39C
0060 #define SPT_PMC_LTR_SCC 0x3A0
0061 #define SPT_PMC_LTR_ISH 0x3A4
0062
0063
0064 enum ppfear_regs {
0065 SPT_PMC_XRAM_PPFEAR0A = 0x590,
0066 SPT_PMC_XRAM_PPFEAR0B,
0067 SPT_PMC_XRAM_PPFEAR0C,
0068 SPT_PMC_XRAM_PPFEAR0D,
0069 SPT_PMC_XRAM_PPFEAR1A,
0070 };
0071
0072 #define SPT_PMC_BIT_PMC BIT(0)
0073 #define SPT_PMC_BIT_OPI BIT(1)
0074 #define SPT_PMC_BIT_SPI BIT(2)
0075 #define SPT_PMC_BIT_XHCI BIT(3)
0076 #define SPT_PMC_BIT_SPA BIT(4)
0077 #define SPT_PMC_BIT_SPB BIT(5)
0078 #define SPT_PMC_BIT_SPC BIT(6)
0079 #define SPT_PMC_BIT_GBE BIT(7)
0080
0081 #define SPT_PMC_BIT_SATA BIT(0)
0082 #define SPT_PMC_BIT_HDA_PGD0 BIT(1)
0083 #define SPT_PMC_BIT_HDA_PGD1 BIT(2)
0084 #define SPT_PMC_BIT_HDA_PGD2 BIT(3)
0085 #define SPT_PMC_BIT_HDA_PGD3 BIT(4)
0086 #define SPT_PMC_BIT_RSVD_0B BIT(5)
0087 #define SPT_PMC_BIT_LPSS BIT(6)
0088 #define SPT_PMC_BIT_LPC BIT(7)
0089
0090 #define SPT_PMC_BIT_SMB BIT(0)
0091 #define SPT_PMC_BIT_ISH BIT(1)
0092 #define SPT_PMC_BIT_P2SB BIT(2)
0093 #define SPT_PMC_BIT_DFX BIT(3)
0094 #define SPT_PMC_BIT_SCC BIT(4)
0095 #define SPT_PMC_BIT_RSVD_0C BIT(5)
0096 #define SPT_PMC_BIT_FUSE BIT(6)
0097 #define SPT_PMC_BIT_CAMREA BIT(7)
0098
0099 #define SPT_PMC_BIT_RSVD_0D BIT(0)
0100 #define SPT_PMC_BIT_USB3_OTG BIT(1)
0101 #define SPT_PMC_BIT_EXI BIT(2)
0102 #define SPT_PMC_BIT_CSE BIT(3)
0103 #define SPT_PMC_BIT_CSME_KVM BIT(4)
0104 #define SPT_PMC_BIT_CSME_PMT BIT(5)
0105 #define SPT_PMC_BIT_CSME_CLINK BIT(6)
0106 #define SPT_PMC_BIT_CSME_PTIO BIT(7)
0107
0108 #define SPT_PMC_BIT_CSME_USBR BIT(0)
0109 #define SPT_PMC_BIT_CSME_SUSRAM BIT(1)
0110 #define SPT_PMC_BIT_CSME_SMT BIT(2)
0111 #define SPT_PMC_BIT_RSVD_1A BIT(3)
0112 #define SPT_PMC_BIT_CSME_SMS2 BIT(4)
0113 #define SPT_PMC_BIT_CSME_SMS1 BIT(5)
0114 #define SPT_PMC_BIT_CSME_RTC BIT(6)
0115 #define SPT_PMC_BIT_CSME_PSF BIT(7)
0116
0117 #define SPT_PMC_BIT_MPHY_LANE0 BIT(0)
0118 #define SPT_PMC_BIT_MPHY_LANE1 BIT(1)
0119 #define SPT_PMC_BIT_MPHY_LANE2 BIT(2)
0120 #define SPT_PMC_BIT_MPHY_LANE3 BIT(3)
0121 #define SPT_PMC_BIT_MPHY_LANE4 BIT(4)
0122 #define SPT_PMC_BIT_MPHY_LANE5 BIT(5)
0123 #define SPT_PMC_BIT_MPHY_LANE6 BIT(6)
0124 #define SPT_PMC_BIT_MPHY_LANE7 BIT(7)
0125
0126 #define SPT_PMC_BIT_MPHY_LANE8 BIT(0)
0127 #define SPT_PMC_BIT_MPHY_LANE9 BIT(1)
0128 #define SPT_PMC_BIT_MPHY_LANE10 BIT(2)
0129 #define SPT_PMC_BIT_MPHY_LANE11 BIT(3)
0130 #define SPT_PMC_BIT_MPHY_LANE12 BIT(4)
0131 #define SPT_PMC_BIT_MPHY_LANE13 BIT(5)
0132 #define SPT_PMC_BIT_MPHY_LANE14 BIT(6)
0133 #define SPT_PMC_BIT_MPHY_LANE15 BIT(7)
0134
0135 #define SPT_PMC_BIT_MPHY_CMN_LANE0 BIT(0)
0136 #define SPT_PMC_BIT_MPHY_CMN_LANE1 BIT(1)
0137 #define SPT_PMC_BIT_MPHY_CMN_LANE2 BIT(2)
0138 #define SPT_PMC_BIT_MPHY_CMN_LANE3 BIT(3)
0139
0140 #define SPT_PMC_VRIC1_SLPS0LVEN BIT(13)
0141 #define SPT_PMC_VRIC1_XTALSDQDIS BIT(22)
0142
0143
0144 #define CNP_PMC_SLPS0_DBG_OFFSET 0x10B4
0145 #define CNP_PMC_PM_CFG_OFFSET 0x1818
0146 #define CNP_PMC_SLP_S0_RES_COUNTER_OFFSET 0x193C
0147 #define CNP_PMC_LTR_IGNORE_OFFSET 0x1B0C
0148
0149 #define CNP_PMC_HOST_PPFEAR0A 0x1D90
0150
0151 #define CNP_PMC_LATCH_SLPS0_EVENTS BIT(31)
0152
0153 #define CNP_PMC_MMIO_REG_LEN 0x2000
0154 #define CNP_PPFEAR_NUM_ENTRIES 8
0155 #define CNP_PMC_READ_DISABLE_BIT 22
0156 #define CNP_NUM_IP_IGN_ALLOWED 19
0157 #define CNP_PMC_LTR_CUR_PLT 0x1B50
0158 #define CNP_PMC_LTR_CUR_ASLT 0x1B54
0159 #define CNP_PMC_LTR_SPA 0x1B60
0160 #define CNP_PMC_LTR_SPB 0x1B64
0161 #define CNP_PMC_LTR_SATA 0x1B68
0162 #define CNP_PMC_LTR_GBE 0x1B6C
0163 #define CNP_PMC_LTR_XHCI 0x1B70
0164 #define CNP_PMC_LTR_RESERVED 0x1B74
0165 #define CNP_PMC_LTR_ME 0x1B78
0166 #define CNP_PMC_LTR_EVA 0x1B7C
0167 #define CNP_PMC_LTR_SPC 0x1B80
0168 #define CNP_PMC_LTR_AZ 0x1B84
0169 #define CNP_PMC_LTR_LPSS 0x1B8C
0170 #define CNP_PMC_LTR_CAM 0x1B90
0171 #define CNP_PMC_LTR_SPD 0x1B94
0172 #define CNP_PMC_LTR_SPE 0x1B98
0173 #define CNP_PMC_LTR_ESPI 0x1B9C
0174 #define CNP_PMC_LTR_SCC 0x1BA0
0175 #define CNP_PMC_LTR_ISH 0x1BA4
0176 #define CNP_PMC_LTR_CNV 0x1BF0
0177 #define CNP_PMC_LTR_EMMC 0x1BF4
0178 #define CNP_PMC_LTR_UFSX2 0x1BF8
0179
0180 #define LTR_DECODED_VAL GENMASK(9, 0)
0181 #define LTR_DECODED_SCALE GENMASK(12, 10)
0182 #define LTR_REQ_SNOOP BIT(15)
0183 #define LTR_REQ_NONSNOOP BIT(31)
0184
0185 #define ICL_PPFEAR_NUM_ENTRIES 9
0186 #define ICL_NUM_IP_IGN_ALLOWED 20
0187 #define ICL_PMC_LTR_WIGIG 0x1BFC
0188 #define ICL_PMC_SLP_S0_RES_COUNTER_STEP 0x64
0189
0190 #define LPM_MAX_NUM_MODES 8
0191 #define LPM_DEFAULT_PRI { 7, 6, 2, 5, 4, 1, 3, 0 }
0192
0193 #define GET_X2_COUNTER(v) ((v) >> 1)
0194 #define LPM_STS_LATCH_MODE BIT(31)
0195
0196 #define TGL_PMC_SLP_S0_RES_COUNTER_STEP 0x7A
0197 #define TGL_PMC_LTR_THC0 0x1C04
0198 #define TGL_PMC_LTR_THC1 0x1C08
0199 #define TGL_NUM_IP_IGN_ALLOWED 23
0200 #define TGL_PMC_LPM_RES_COUNTER_STEP_X2 61
0201
0202 #define ADL_PMC_LTR_SPF 0x1C00
0203 #define ADL_NUM_IP_IGN_ALLOWED 23
0204 #define ADL_PMC_SLP_S0_RES_COUNTER_OFFSET 0x1098
0205
0206
0207
0208
0209 #define TGL_LPM_STS_LATCH_EN_OFFSET 0x1C34
0210 #define TGL_LPM_EN_OFFSET 0x1C78
0211 #define TGL_LPM_RESIDENCY_OFFSET 0x1C80
0212
0213
0214 #define TGL_LPM_STATUS_OFFSET 0x1C3C
0215 #define TGL_LPM_LIVE_STATUS_OFFSET 0x1C5C
0216 #define TGL_LPM_PRI_OFFSET 0x1C7C
0217 #define TGL_LPM_NUM_MAPS 6
0218
0219
0220 #define ETR3_OFFSET 0x1048
0221 #define ETR3_CF9GR BIT(20)
0222 #define ETR3_CF9LOCK BIT(31)
0223
0224
0225 #define ETR3_CLEAR_LPM_EVENTS BIT(28)
0226
0227
0228 #define ADL_LPM_EN_OFFSET 0x179C
0229 #define ADL_LPM_RESIDENCY_OFFSET 0x17A4
0230 #define ADL_LPM_NUM_MODES 2
0231 #define ADL_LPM_NUM_MAPS 14
0232
0233
0234 #define ADL_LPM_STATUS_OFFSET 0x170C
0235 #define ADL_LPM_PRI_OFFSET 0x17A0
0236 #define ADL_LPM_STATUS_LATCH_EN_OFFSET 0x1704
0237 #define ADL_LPM_LIVE_STATUS_OFFSET 0x1764
0238
0239 static const char *pmc_lpm_modes[] = {
0240 "S0i2.0",
0241 "S0i2.1",
0242 "S0i2.2",
0243 "S0i3.0",
0244 "S0i3.1",
0245 "S0i3.2",
0246 "S0i3.3",
0247 "S0i3.4",
0248 NULL
0249 };
0250
0251 struct pmc_bit_map {
0252 const char *name;
0253 u32 bit_mask;
0254 };
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277 struct pmc_reg_map {
0278 const struct pmc_bit_map **pfear_sts;
0279 const struct pmc_bit_map *mphy_sts;
0280 const struct pmc_bit_map *pll_sts;
0281 const struct pmc_bit_map **slps0_dbg_maps;
0282 const struct pmc_bit_map *ltr_show_sts;
0283 const struct pmc_bit_map *msr_sts;
0284 const struct pmc_bit_map **lpm_sts;
0285 const u32 slp_s0_offset;
0286 const int slp_s0_res_counter_step;
0287 const u32 ltr_ignore_offset;
0288 const int regmap_length;
0289 const u32 ppfear0_offset;
0290 const int ppfear_buckets;
0291 const u32 pm_cfg_offset;
0292 const int pm_read_disable_bit;
0293 const u32 slps0_dbg_offset;
0294 const u32 ltr_ignore_max;
0295 const u32 pm_vric1_offset;
0296
0297 const int lpm_num_maps;
0298 const int lpm_num_modes;
0299 const int lpm_res_counter_step_x2;
0300 const u32 lpm_sts_latch_en_offset;
0301 const u32 lpm_en_offset;
0302 const u32 lpm_priority_offset;
0303 const u32 lpm_residency_offset;
0304 const u32 lpm_status_offset;
0305 const u32 lpm_live_status_offset;
0306 const u32 etr3_offset;
0307 };
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328 struct pmc_dev {
0329 u32 base_addr;
0330 void __iomem *regbase;
0331 const struct pmc_reg_map *map;
0332 struct dentry *dbgfs_dir;
0333 int pmc_xram_read_bit;
0334 struct mutex lock;
0335
0336 bool check_counters;
0337 u64 pc10_counter;
0338 u64 s0ix_counter;
0339 int num_lpm_modes;
0340 int lpm_en_modes[LPM_MAX_NUM_MODES];
0341 u32 *lpm_req_regs;
0342 };
0343
0344 #define pmc_for_each_mode(i, mode, pmcdev) \
0345 for (i = 0, mode = pmcdev->lpm_en_modes[i]; \
0346 i < pmcdev->num_lpm_modes; \
0347 i++, mode = pmcdev->lpm_en_modes[i])
0348
0349 #define DEFINE_PMC_CORE_ATTR_WRITE(__name) \
0350 static int __name ## _open(struct inode *inode, struct file *file) \
0351 { \
0352 return single_open(file, __name ## _show, inode->i_private); \
0353 } \
0354 \
0355 static const struct file_operations __name ## _fops = { \
0356 .owner = THIS_MODULE, \
0357 .open = __name ## _open, \
0358 .read = seq_read, \
0359 .write = __name ## _write, \
0360 .release = single_release, \
0361 }
0362
0363 #endif