Skip to content

Commit c977b98

Browse files
spandruvadaandy-shev
authored andcommitted
platform/x86: intel_pmc_core: Make the driver PCH family agnostic
Although this driver did pretty good job in abstracting PCH specific interfaces, but still there are some loose ends. For example SLP_S0 counter (for reading SLP_S0 residency), PM config offset (for checking permissions to read XRAM) and PPFEAR offset (for reading IP status) is still hardcoded for a specific family of PCH. This change extended the struct pmc_reg_map to allow per family configuration of offsets and bits. No functional change is expected with this change. This change allows seamless additions to new PCH and create a baseline for other platform specific extensions. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
1 parent 2cf7bde commit c977b98

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

‎drivers/platform/x86/intel_pmc_core.c‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ static const struct pmc_reg_map spt_reg_map = {
110110
.pfear_sts = spt_pfear_map,
111111
.mphy_sts = spt_mphy_map,
112112
.pll_sts = spt_pll_map,
113+
.slp_s0_offset = SPT_PMC_SLP_S0_RES_COUNTER_OFFSET,
114+
.ltr_ignore_offset = SPT_PMC_LTR_IGNORE_OFFSET,
115+
.regmap_length = SPT_PMC_MMIO_REG_LEN,
116+
.ppfear0_offset = SPT_PMC_XRAM_PPFEAR0A,
117+
.ppfear_buckets = SPT_PPFEAR_NUM_ENTRIES,
118+
.pm_cfg_offset = SPT_PMC_PM_CFG_OFFSET,
119+
.pm_read_disable_bit = SPT_PMC_READ_DISABLE_BIT,
113120
};
114121

115122
static const struct pci_device_id pmc_pci_ids[] = {
@@ -157,12 +164,13 @@ static inline u32 pmc_core_adjust_slp_s0_step(u32 value)
157164
int intel_pmc_slp_s0_counter_read(u32 *data)
158165
{
159166
struct pmc_dev *pmcdev = &pmc;
167+
const struct pmc_reg_map *map = pmcdev->map;
160168
u32 value;
161169

162170
if (!pmcdev->has_slp_s0_res)
163171
return -EACCES;
164172

165-
value = pmc_core_reg_read(pmcdev, SPT_PMC_SLP_S0_RES_COUNTER_OFFSET);
173+
value = pmc_core_reg_read(pmcdev, map->slp_s0_offset);
166174
*data = pmc_core_adjust_slp_s0_step(value);
167175

168176
return 0;
@@ -172,9 +180,10 @@ EXPORT_SYMBOL_GPL(intel_pmc_slp_s0_counter_read);
172180
static int pmc_core_dev_state_get(void *data, u64 *val)
173181
{
174182
struct pmc_dev *pmcdev = data;
183+
const struct pmc_reg_map *map = pmcdev->map;
175184
u32 value;
176185

177-
value = pmc_core_reg_read(pmcdev, SPT_PMC_SLP_S0_RES_COUNTER_OFFSET);
186+
value = pmc_core_reg_read(pmcdev, map->slp_s0_offset);
178187
*val = pmc_core_adjust_slp_s0_step(value);
179188

180189
return 0;
@@ -187,8 +196,8 @@ static int pmc_core_check_read_lock_bit(void)
187196
struct pmc_dev *pmcdev = &pmc;
188197
u32 value;
189198

190-
value = pmc_core_reg_read(pmcdev, SPT_PMC_PM_CFG_OFFSET);
191-
return value & BIT(SPT_PMC_READ_DISABLE_BIT);
199+
value = pmc_core_reg_read(pmcdev, pmcdev->map->pm_cfg_offset);
200+
return value & BIT(pmcdev->map->pm_read_disable_bit);
192201
}
193202

194203
#if IS_ENABLED(CONFIG_DEBUG_FS)
@@ -204,12 +213,13 @@ static int pmc_core_ppfear_sts_show(struct seq_file *s, void *unused)
204213
{
205214
struct pmc_dev *pmcdev = s->private;
206215
const struct pmc_bit_map *map = pmcdev->map->pfear_sts;
207-
u8 pf_regs[NUM_ENTRIES];
216+
u8 pf_regs[PPFEAR_MAX_NUM_ENTRIES];
208217
int index, iter;
209218

210-
iter = SPT_PMC_XRAM_PPFEAR0A;
219+
iter = pmcdev->map->ppfear0_offset;
211220

212-
for (index = 0; index < NUM_ENTRIES; index++, iter++)
221+
for (index = 0; index < pmcdev->map->ppfear_buckets &&
222+
index < PPFEAR_MAX_NUM_ENTRIES; index++, iter++)
213223
pf_regs[index] = pmc_core_reg_read_byte(pmcdev, iter);
214224

215225
for (index = 0; map[index].name; index++)
@@ -376,6 +386,7 @@ static ssize_t pmc_core_ltr_ignore_write(struct file *file, const char __user
376386
*userbuf, size_t count, loff_t *ppos)
377387
{
378388
struct pmc_dev *pmcdev = &pmc;
389+
const struct pmc_reg_map *map = pmcdev->map;
379390
u32 val, buf_size, fd;
380391
int err = 0;
381392

@@ -392,9 +403,9 @@ static ssize_t pmc_core_ltr_ignore_write(struct file *file, const char __user
392403
goto out_unlock;
393404
}
394405

395-
fd = pmc_core_reg_read(pmcdev, SPT_PMC_LTR_IGNORE_OFFSET);
406+
fd = pmc_core_reg_read(pmcdev, map->ltr_ignore_offset);
396407
fd |= (1U << val);
397-
pmc_core_reg_write(pmcdev, SPT_PMC_LTR_IGNORE_OFFSET, fd);
408+
pmc_core_reg_write(pmcdev, map->ltr_ignore_offset, fd);
398409

399410
out_unlock:
400411
mutex_unlock(&pmcdev->lock);
@@ -530,8 +541,8 @@ static int pmc_core_probe(struct pci_dev *dev, const struct pci_device_id *id)
530541
}
531542

532543
mutex_init(&pmcdev->lock);
533-
pmcdev->pmc_xram_read_bit = pmc_core_check_read_lock_bit();
534544
pmcdev->map = map;
545+
pmcdev->pmc_xram_read_bit = pmc_core_check_read_lock_bit();
535546

536547
err = pmc_core_dbgfs_register(pmcdev);
537548
if (err < 0)

‎drivers/platform/x86/intel_pmc_core.h‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
#define SPT_PMC_SLP_S0_RES_COUNTER_STEP 0x64
3939
#define PMC_BASE_ADDR_MASK ~(SPT_PMC_MMIO_REG_LEN - 1)
4040
#define MTPMC_MASK 0xffff0000
41-
#define NUM_ENTRIES 5
41+
#define PPFEAR_MAX_NUM_ENTRIES 5
42+
#define SPT_PPFEAR_NUM_ENTRIES 5
4243
#define SPT_PMC_READ_DISABLE_BIT 0x16
4344
#define SPT_PMC_MSG_FULL_STS_BIT 0x18
4445
#define NUM_RETRIES 100
@@ -126,10 +127,37 @@ struct pmc_bit_map {
126127
u32 bit_mask;
127128
};
128129

130+
/**
131+
* struct pmc_reg_map - Structure used to define parameter unique to a
132+
PCH family
133+
* @pfear_sts: Maps name of IP block to PPFEAR* bit
134+
* @mphy_sts: Maps name of MPHY lane to MPHY status lane status bit
135+
* @pll_sts: Maps name of PLL to corresponding bit status
136+
* @slp_s0_offset: PWRMBASE offset to read SLP_S0 residency
137+
* @ltr_ignore_offset: PWRMBASE offset to read/write LTR ignore bit
138+
* @base_address: Base address of PWRMBASE defined in BIOS writer guide
139+
* @regmap_length: Length of memory to map from PWRMBASE address to access
140+
* @ppfear0_offset: PWRMBASE offset to to read PPFEAR*
141+
* @ppfear_buckets: Number of 8 bits blocks to read all IP blocks from
142+
* PPFEAR
143+
* @pm_cfg_offset: PWRMBASE offset to PM_CFG register
144+
* @pm_read_disable_bit: Bit index to read PMC_READ_DISABLE
145+
*
146+
* Each PCH has unique set of register offsets and bit indexes. This structure
147+
* captures them to have a common implementation.
148+
*/
129149
struct pmc_reg_map {
130150
const struct pmc_bit_map *pfear_sts;
131151
const struct pmc_bit_map *mphy_sts;
132152
const struct pmc_bit_map *pll_sts;
153+
const u32 slp_s0_offset;
154+
const u32 ltr_ignore_offset;
155+
const u32 base_address;
156+
const int regmap_length;
157+
const u32 ppfear0_offset;
158+
const int ppfear_buckets;
159+
const u32 pm_cfg_offset;
160+
const int pm_read_disable_bit;
133161
};
134162

135163
/**

0 commit comments

Comments
 (0)