Unverified Commit ac6bef0d authored by Xi Pardee's avatar Xi Pardee Committed by Ilpo Järvinen
Browse files

platform/x86:intel/pmc: Create generic_core_init() for all platforms



Create a generic_core_init() function for all architectures to reduce
duplicate code in each architecture file. Create an info structure
to catch the variations between each architecture and pass it to the
generic init function.

Convert all architectures to call the generic core init function.

Signed-off-by: default avatarXi Pardee <xi.pardee@linux.intel.com>
Link: https://lore.kernel.org/r/20250207225615.401235-4-xi.pardee@linux.intel.com


Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
parent 78eaf4d1
Loading
Loading
Loading
Loading
+7 −14
Original line number Diff line number Diff line
@@ -311,20 +311,13 @@ const struct pmc_reg_map adl_reg_map = {
	.pson_residency_counter_step = TGL_PSON_RES_COUNTER_STEP,
};

static struct pmc_dev_info adl_pmc_dev = {
	.map = &adl_reg_map,
	.suspend = cnl_suspend,
	.resume = cnl_resume,
};

int adl_core_init(struct pmc_dev *pmcdev)
{
	struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
	int ret;

	pmcdev->suspend = cnl_suspend;
	pmcdev->resume = cnl_resume;

	pmc->map = &adl_reg_map;
	ret = get_primary_reg_base(pmc);
	if (ret)
		return ret;

	pmc_core_get_low_power_modes(pmcdev);

	return 0;
	return generic_core_init(pmcdev, &adl_pmc_dev);
}
+10 −33
Original line number Diff line number Diff line
@@ -691,40 +691,17 @@ static int arl_resume(struct pmc_dev *pmcdev)
	return cnl_resume(pmcdev);
}

static struct pmc_dev_info arl_pmc_dev = {
	.pci_func = 0,
	.dmu_guid = ARL_PMT_DMU_GUID,
	.regmap_list = arl_pmc_info_list,
	.map = &arl_socs_reg_map,
	.suspend = cnl_suspend,
	.resume = arl_resume,
};

int arl_core_init(struct pmc_dev *pmcdev)
{
	struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
	int ret;
	int func = 0;
	bool ssram_init = true;

	arl_d3_fixup();
	pmcdev->suspend = cnl_suspend;
	pmcdev->resume = arl_resume;
	pmcdev->regmap_list = arl_pmc_info_list;

	/*
	 * If ssram init fails use legacy method to at least get the
	 * primary PMC
	 */
	ret = pmc_core_ssram_init(pmcdev, func);
	if (ret) {
		ssram_init = false;
		pmc->map = &arl_socs_reg_map;

		ret = get_primary_reg_base(pmc);
		if (ret)
			return ret;
	}

	pmc_core_get_low_power_modes(pmcdev);
	pmc_core_punit_pmt_init(pmcdev, ARL_PMT_DMU_GUID);

	if (ssram_init)	{
		ret = pmc_core_ssram_get_lpm_reqs(pmcdev);
		if (ret)
			return ret;
	}

	return 0;
	return generic_core_init(pmcdev, &arl_pmc_dev);
}
+7 −14
Original line number Diff line number Diff line
@@ -274,20 +274,13 @@ int cnl_resume(struct pmc_dev *pmcdev)
	return pmc_core_resume_common(pmcdev);
}

static struct pmc_dev_info cnp_pmc_dev = {
	.map = &cnp_reg_map,
	.suspend = cnl_suspend,
	.resume = cnl_resume,
};

int cnp_core_init(struct pmc_dev *pmcdev)
{
	struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
	int ret;

	pmcdev->suspend = cnl_suspend;
	pmcdev->resume = cnl_resume;

	pmc->map = &cnp_reg_map;
	ret = get_primary_reg_base(pmc);
	if (ret)
		return ret;

	pmc_core_get_low_power_modes(pmcdev);

	return 0;
	return generic_core_init(pmcdev, &cnp_pmc_dev);
}
+42 −0
Original line number Diff line number Diff line
@@ -1345,6 +1345,48 @@ static void pmc_core_dbgfs_register(struct pmc_dev *pmcdev)
	}
}

/*
 * When supported, ssram init is used to achieve all available PMCs.
 * If ssram init fails, this function uses legacy method to at least get the
 * primary PMC.
 */
int generic_core_init(struct pmc_dev *pmcdev, struct pmc_dev_info *pmc_dev_info)
{
	struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
	bool ssram;
	int ret;

	pmcdev->suspend = pmc_dev_info->suspend;
	pmcdev->resume = pmc_dev_info->resume;

	ssram = pmc_dev_info->regmap_list != NULL;
	if (ssram) {
		pmcdev->regmap_list = pmc_dev_info->regmap_list;
		ret = pmc_core_ssram_init(pmcdev, pmc_dev_info->pci_func);
		if (ret) {
			dev_warn(&pmcdev->pdev->dev,
				 "ssram init failed, %d, using legacy init\n", ret);
			ssram = false;
		}
	}

	if (!ssram) {
		pmc->map = pmc_dev_info->map;
		ret = get_primary_reg_base(pmc);
		if (ret)
			return ret;
	}

	pmc_core_get_low_power_modes(pmcdev);
	if (pmc_dev_info->dmu_guid)
		pmc_core_punit_pmt_init(pmcdev, pmc_dev_info->dmu_guid);

	if (ssram)
		return pmc_core_ssram_get_lpm_reqs(pmcdev);

	return 0;
}

static const struct x86_cpu_id intel_pmc_core_ids[] = {
	X86_MATCH_VFM(INTEL_SKYLAKE_L,		spt_core_init),
	X86_MATCH_VFM(INTEL_SKYLAKE,		spt_core_init),
+22 −0
Original line number Diff line number Diff line
@@ -435,6 +435,27 @@ enum pmc_index {
	PMC_IDX_MAX
};

/**
 * struct pmc_dev_info - Structure to keep PMC device info
 * @pci_func:		Function number of the primary PMC
 * @dmu_guid:		Die Management Unit GUID
 * @regmap_list:	Pointer to a list of pmc_info structure that could be
 *			available for the platform. When set, this field implies
 *			SSRAM support.
 * @map:		Pointer to a pmc_reg_map struct that contains platform
 *			specific attributes of the primary PMC
 * @suspend:		Function to perform platform specific suspend
 * @resume:		Function to perform platform specific resume
 */
struct pmc_dev_info {
	u8 pci_func;
	u32 dmu_guid;
	struct pmc_info *regmap_list;
	const struct pmc_reg_map *map;
	void (*suspend)(struct pmc_dev *pmcdev);
	int (*resume)(struct pmc_dev *pmcdev);
};

extern const struct pmc_bit_map msr_map[];
extern const struct pmc_bit_map spt_pll_map[];
extern const struct pmc_bit_map spt_mphy_map[];
@@ -591,6 +612,7 @@ extern void pmc_core_set_device_d3(unsigned int device);

extern int pmc_core_ssram_init(struct pmc_dev *pmcdev, int func);

int generic_core_init(struct pmc_dev *pmcdev, struct pmc_dev_info *pmc_dev_info);
int spt_core_init(struct pmc_dev *pmcdev);
int cnp_core_init(struct pmc_dev *pmcdev);
int icl_core_init(struct pmc_dev *pmcdev);
Loading