Skip to content

Commit 267fc71

Browse files
gkammelaandy-shev
authored andcommitted
platform/x86: intel_pmc_core: Make pmc_core_lpm_display() generic for platforms that support sub-states
Currently pmc_core_lpm_display() uses an array of the struct pointers, i.e. tgl_lpm_maps for Tiger Lake directly to iterate through and to get the number of (live) status registers which is hard coded and can not be re-used for the future platforms that support sub-states. To maintain readability, make pmc_core_lpm_display() generic, so that it can be re-used for future platforms. Cc: Chen Zhou <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: David E. Box <[email protected]> Suggested-by: Andy Shevchenko <[email protected]> Signed-off-by: Gayatri Kammela <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]>
1 parent 9945a24 commit 267fc71

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

drivers/platform/x86/intel_pmc_core.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/module.h>
2121
#include <linux/pci.h>
2222
#include <linux/platform_device.h>
23+
#include <linux/slab.h>
2324
#include <linux/suspend.h>
2425
#include <linux/uaccess.h>
2526

@@ -639,20 +640,35 @@ static void pmc_core_slps0_display(struct pmc_dev *pmcdev, struct device *dev,
639640
}
640641
}
641642

643+
static int pmc_core_lpm_get_arr_size(const struct pmc_bit_map **maps)
644+
{
645+
int idx;
646+
647+
for (idx = 0; maps[idx]; idx++)
648+
;/* Nothing */
649+
650+
return idx;
651+
}
652+
642653
static void pmc_core_lpm_display(struct pmc_dev *pmcdev, struct device *dev,
643654
struct seq_file *s, u32 offset,
644655
const char *str,
645656
const struct pmc_bit_map **maps)
646657
{
647-
u32 lpm_regs[ARRAY_SIZE(tgl_lpm_maps)-1];
648-
int index, idx, len = 32, bit_mask;
658+
int index, idx, len = 32, bit_mask, arr_size;
659+
u32 *lpm_regs;
660+
661+
arr_size = pmc_core_lpm_get_arr_size(maps);
662+
lpm_regs = kmalloc_array(arr_size, sizeof(*lpm_regs), GFP_KERNEL);
663+
if (!lpm_regs)
664+
return;
649665

650-
for (index = 0; tgl_lpm_maps[index]; index++) {
666+
for (index = 0; index < arr_size; index++) {
651667
lpm_regs[index] = pmc_core_reg_read(pmcdev, offset);
652668
offset += 4;
653669
}
654670

655-
for (idx = 0; maps[idx]; idx++) {
671+
for (idx = 0; idx < arr_size; idx++) {
656672
if (dev)
657673
dev_dbg(dev, "\nLPM_%s_%d:\t0x%x\n", str, idx,
658674
lpm_regs[idx]);
@@ -671,6 +687,8 @@ static void pmc_core_lpm_display(struct pmc_dev *pmcdev, struct device *dev,
671687
lpm_regs[idx] & bit_mask ? 1 : 0);
672688
}
673689
}
690+
691+
kfree(lpm_regs);
674692
}
675693

676694
#if IS_ENABLED(CONFIG_DEBUG_FS)

0 commit comments

Comments
 (0)