Skip to content

Commit d79c3c8

Browse files
rjingarjwrdegoede
authored andcommitted
platform/x86/intel/pmc: Move common code to core.c
Functions like mtl_set_device_d3() and mtl_punit_pmt_init() were added for Meteor Lake. To be able to use them in Arrow Lake and future platforms, move them to core.c. Also, to support different guids, add guid argument in pmc_core_punit_pmt_init() and to support different PCI function numbers, add func arg in pmc_core_ssram_init(). Signed-off-by: Rajvi Jingar <rajvi.jingar@linux.intel.com> Link: https://lore.kernel.org/r/20231219042216.2592029-5-rajvi.jingar@linux.intel.com Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent d873f38 commit d79c3c8

File tree

4 files changed

+60
-57
lines changed

4 files changed

+60
-57
lines changed

drivers/platform/x86/intel/pmc/core.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,51 @@ int get_primary_reg_base(struct pmc *pmc)
11061106
return 0;
11071107
}
11081108

1109+
void pmc_core_punit_pmt_init(struct pmc_dev *pmcdev, u32 guid)
1110+
{
1111+
struct telem_endpoint *ep;
1112+
struct pci_dev *pcidev;
1113+
1114+
pcidev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(10, 0));
1115+
if (!pcidev) {
1116+
dev_err(&pmcdev->pdev->dev, "PUNIT PMT device not found.");
1117+
return;
1118+
}
1119+
1120+
ep = pmt_telem_find_and_register_endpoint(pcidev, guid, 0);
1121+
pci_dev_put(pcidev);
1122+
if (IS_ERR(ep)) {
1123+
dev_err(&pmcdev->pdev->dev,
1124+
"pmc_core: couldn't get DMU telem endpoint %ld",
1125+
PTR_ERR(ep));
1126+
return;
1127+
}
1128+
1129+
pmcdev->punit_ep = ep;
1130+
1131+
pmcdev->has_die_c6 = true;
1132+
pmcdev->die_c6_offset = MTL_PMT_DMU_DIE_C6_OFFSET;
1133+
}
1134+
1135+
void pmc_core_set_device_d3(unsigned int device)
1136+
{
1137+
struct pci_dev *pcidev;
1138+
1139+
pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
1140+
if (pcidev) {
1141+
if (!device_trylock(&pcidev->dev)) {
1142+
pci_dev_put(pcidev);
1143+
return;
1144+
}
1145+
if (!pcidev->dev.driver) {
1146+
dev_info(&pcidev->dev, "Setting to D3hot\n");
1147+
pci_set_power_state(pcidev, PCI_D3hot);
1148+
}
1149+
device_unlock(&pcidev->dev);
1150+
pci_dev_put(pcidev);
1151+
}
1152+
}
1153+
11091154
static bool pmc_core_is_pson_residency_enabled(struct pmc_dev *pmcdev)
11101155
{
11111156
struct platform_device *pdev = pmcdev->pdev;

drivers/platform/x86/intel/pmc/core.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ enum ppfear_regs {
268268
#define MTL_SOCM_PPFEAR_NUM_ENTRIES 8
269269
#define MTL_IOE_PPFEAR_NUM_ENTRIES 10
270270

271+
/* Die C6 from PUNIT telemetry */
272+
#define MTL_PMT_DMU_DIE_C6_OFFSET 15
273+
#define MTL_PMT_DMU_GUID 0x1A067102
274+
271275
extern const char *pmc_lpm_modes[];
272276

273277
struct pmc_bit_map {
@@ -504,8 +508,10 @@ extern int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value);
504508
int pmc_core_resume_common(struct pmc_dev *pmcdev);
505509
int get_primary_reg_base(struct pmc *pmc);
506510
extern void pmc_core_get_low_power_modes(struct pmc_dev *pmcdev);
511+
extern void pmc_core_punit_pmt_init(struct pmc_dev *pmcdev, u32 guid);
512+
extern void pmc_core_set_device_d3(unsigned int device);
507513

508-
extern int pmc_core_ssram_init(struct pmc_dev *pmcdev);
514+
extern int pmc_core_ssram_init(struct pmc_dev *pmcdev, int func);
509515

510516
int spt_core_init(struct pmc_dev *pmcdev);
511517
int cnp_core_init(struct pmc_dev *pmcdev);

drivers/platform/x86/intel/pmc/core_ssram.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ pmc_core_ssram_get_pmc(struct pmc_dev *pmcdev, int pmc_idx, u32 offset)
290290
return pmc_core_pmc_add(pmcdev, pwrm_base, map, pmc_idx);
291291
}
292292

293-
int pmc_core_ssram_init(struct pmc_dev *pmcdev)
293+
int pmc_core_ssram_init(struct pmc_dev *pmcdev, int func)
294294
{
295295
struct pci_dev *pcidev;
296296
int ret;
297297

298-
pcidev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(20, 2));
298+
pcidev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(20, func));
299299
if (!pcidev)
300300
return -ENODEV;
301301

drivers/platform/x86/intel/pmc/mtl.c

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
#define IOEM_LPM_REQ_GUID 0x4357464
1818
#define IOEP_LPM_REQ_GUID 0x5077612
1919

20-
/* Die C6 from PUNIT telemetry */
21-
#define MTL_PMT_DMU_DIE_C6_OFFSET 15
22-
#define MTL_PMT_DMU_GUID 0x1A067102
23-
2420
static const u8 MTL_LPM_REG_INDEX[] = {0, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20};
2521

2622
/*
@@ -973,63 +969,18 @@ static struct pmc_info mtl_pmc_info_list[] = {
973969
{}
974970
};
975971

976-
static void mtl_punit_pmt_init(struct pmc_dev *pmcdev)
977-
{
978-
struct telem_endpoint *ep;
979-
struct pci_dev *pcidev;
980-
981-
pcidev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(10, 0));
982-
if (!pcidev) {
983-
dev_err(&pmcdev->pdev->dev, "PUNIT PMT device not found.\n");
984-
return;
985-
}
986-
987-
ep = pmt_telem_find_and_register_endpoint(pcidev, MTL_PMT_DMU_GUID, 0);
988-
pci_dev_put(pcidev);
989-
if (IS_ERR(ep)) {
990-
dev_err(&pmcdev->pdev->dev,
991-
"pmc_core: couldn't get DMU telem endpoint, %ld\n",
992-
PTR_ERR(ep));
993-
return;
994-
}
995-
996-
pmcdev->punit_ep = ep;
997-
998-
pmcdev->has_die_c6 = true;
999-
pmcdev->die_c6_offset = MTL_PMT_DMU_DIE_C6_OFFSET;
1000-
}
1001-
1002972
#define MTL_GNA_PCI_DEV 0x7e4c
1003973
#define MTL_IPU_PCI_DEV 0x7d19
1004974
#define MTL_VPU_PCI_DEV 0x7d1d
1005-
static void mtl_set_device_d3(unsigned int device)
1006-
{
1007-
struct pci_dev *pcidev;
1008-
1009-
pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
1010-
if (pcidev) {
1011-
if (!device_trylock(&pcidev->dev)) {
1012-
pci_dev_put(pcidev);
1013-
return;
1014-
}
1015-
if (!pcidev->dev.driver) {
1016-
dev_info(&pcidev->dev, "Setting to D3hot\n");
1017-
pci_set_power_state(pcidev, PCI_D3hot);
1018-
}
1019-
device_unlock(&pcidev->dev);
1020-
pci_dev_put(pcidev);
1021-
}
1022-
}
1023-
1024975
/*
1025976
* Set power state of select devices that do not have drivers to D3
1026977
* so that they do not block Package C entry.
1027978
*/
1028979
static void mtl_d3_fixup(void)
1029980
{
1030-
mtl_set_device_d3(MTL_GNA_PCI_DEV);
1031-
mtl_set_device_d3(MTL_IPU_PCI_DEV);
1032-
mtl_set_device_d3(MTL_VPU_PCI_DEV);
981+
pmc_core_set_device_d3(MTL_GNA_PCI_DEV);
982+
pmc_core_set_device_d3(MTL_IPU_PCI_DEV);
983+
pmc_core_set_device_d3(MTL_VPU_PCI_DEV);
1033984
}
1034985

1035986
static int mtl_resume(struct pmc_dev *pmcdev)
@@ -1042,6 +993,7 @@ int mtl_core_init(struct pmc_dev *pmcdev)
1042993
{
1043994
struct pmc *pmc = pmcdev->pmcs[PMC_IDX_SOC];
1044995
int ret;
996+
int func = 2;
1045997

1046998
mtl_d3_fixup();
1047999

@@ -1052,7 +1004,7 @@ int mtl_core_init(struct pmc_dev *pmcdev)
10521004
* If ssram init fails use legacy method to at least get the
10531005
* primary PMC
10541006
*/
1055-
ret = pmc_core_ssram_init(pmcdev);
1007+
ret = pmc_core_ssram_init(pmcdev, func);
10561008
if (ret) {
10571009
dev_warn(&pmcdev->pdev->dev,
10581010
"ssram init failed, %d, using legacy init\n", ret);
@@ -1063,7 +1015,7 @@ int mtl_core_init(struct pmc_dev *pmcdev)
10631015
}
10641016

10651017
pmc_core_get_low_power_modes(pmcdev);
1066-
mtl_punit_pmt_init(pmcdev);
1018+
pmc_core_punit_pmt_init(pmcdev, MTL_PMT_DMU_GUID);
10671019

10681020
/* Due to a hardware limitation, the GBE LTR blocks PC10
10691021
* when a cable is attached. Tell the PMC to ignore it.

0 commit comments

Comments
 (0)