Linux-PM Archive mirror
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang@amd.com>
To: "Yuan, Perry" <Perry.Yuan@amd.com>
Cc: "rafael.j.wysocki@intel.com" <rafael.j.wysocki@intel.com>,
	"Limonciello, Mario" <Mario.Limonciello@amd.com>,
	"viresh.kumar@linaro.org" <viresh.kumar@linaro.org>,
	"Shenoy, Gautham Ranjal" <gautham.shenoy@amd.com>,
	"Petkov, Borislav" <Borislav.Petkov@amd.com>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>,
	"Huang, Shimmer" <Shimmer.Huang@amd.com>,
	"oleksandr@natalenko.name" <oleksandr@natalenko.name>,
	"Du, Xiaojian" <Xiaojian.Du@amd.com>,
	"Meng, Li (Jassmine)" <Li.Meng@amd.com>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v10 8/8] cpufreq: amd-pstate: Add quirk for the pstate CPPC capabilities missing
Date: Mon, 15 Apr 2024 23:16:20 +0800	[thread overview]
Message-ID: <Zh1ExGtyhGOsduOs@amd.com> (raw)
In-Reply-To: <31afd5ae23f8b1d7c6a2f0efe593a368dee61224.1711335714.git.perry.yuan@amd.com>

On Mon, Mar 25, 2024 at 11:03:28AM +0800, Yuan, Perry wrote:
> Add quirks table to get CPPC capabilities issue fixed by providing
> correct perf or frequency values while driver loading.
> 
> If CPPC capabilities are not defined in the ACPI tables or wrongly
> defined by platform firmware, it needs to use quick to get those
> issues fixed with correct workaround values to make pstate driver
> can be loaded even though there are CPPC capabilities errors.
> 
> The workaround will match the broken BIOS which lack of CPPC capabilities
> nominal_freq and lowest_freq definition in the ACPI table.
> 
> $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/lowest_freq
> 0
> $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/nominal_freq
> 0
> 
> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
> Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> Tested-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
> Signed-off-by: Perry Yuan <perry.yuan@amd.com>
> ---
>  drivers/cpufreq/amd-pstate.c | 53 ++++++++++++++++++++++++++++++++++--
>  include/linux/amd-pstate.h   |  6 ++++
>  2 files changed, 57 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index ec049b62b366..59a2db225d98 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -67,6 +67,7 @@ static struct cpufreq_driver amd_pstate_epp_driver;
>  static int cppc_state = AMD_PSTATE_UNDEFINED;
>  static bool cppc_enabled;
>  static bool amd_pstate_prefcore = true;
> +static struct quirk_entry *quirks;

If we set quirks as global pointer, while the amd-pstate is uninstalling,
should we free the quirks as well?

Thanks,
Ray

>  
>  /*
>   * AMD Energy Preference Performance (EPP)
> @@ -111,6 +112,41 @@ static unsigned int epp_values[] = {
>  
>  typedef int (*cppc_mode_transition_fn)(int);
>  
> +static struct quirk_entry quirk_amd_7k62 = {
> +	.nominal_freq = 2600,
> +	.lowest_freq = 550,
> +};
> +
> +static int __init dmi_matched_7k62_bios_bug(const struct dmi_system_id *dmi)
> +{
> +	/**
> +	 * match the broken bios for family 17h processor support CPPC V2
> +	 * broken BIOS lack of nominal_freq and lowest_freq capabilities
> +	 * definition in ACPI tables
> +	 */
> +	if (boot_cpu_has(X86_FEATURE_ZEN2)) {
> +		quirks = dmi->driver_data;
> +		pr_info("Overriding nominal and lowest frequencies for %s\n", dmi->ident);
> +		return 1;
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct dmi_system_id amd_pstate_quirks_table[] __initconst = {
> +	{
> +		.callback = dmi_matched_7k62_bios_bug,
> +		.ident = "AMD EPYC 7K62",
> +		.matches = {
> +			DMI_MATCH(DMI_BIOS_VERSION, "5.14"),
> +			DMI_MATCH(DMI_BIOS_RELEASE, "12/12/2019"),
> +		},
> +		.driver_data = &quirk_amd_7k62,
> +	},
> +	{}
> +};
> +MODULE_DEVICE_TABLE(dmi, amd_pstate_quirks_table);
> +
>  static inline int get_mode_idx_from_str(const char *str, size_t size)
>  {
>  	int i;
> @@ -812,8 +848,16 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
>  	if (ret)
>  		return ret;
>  
> -	min_freq = cppc_perf.lowest_freq * 1000;
> -	nominal_freq = cppc_perf.nominal_freq * 1000;
> +	if (quirks && quirks->lowest_freq)
> +		min_freq = quirks->lowest_freq * 1000;
> +	else
> +		min_freq = cppc_perf.lowest_freq * 1000;
> +
> +	if (quirks && quirks->nominal_freq)
> +		nominal_freq = quirks->nominal_freq * 1000;
> +	else
> +		nominal_freq = cppc_perf.nominal_freq * 1000;
> +
>  	nominal_perf = READ_ONCE(cpudata->nominal_perf);
>  
>  	highest_perf = READ_ONCE(cpudata->highest_perf);
> @@ -1662,6 +1706,11 @@ static int __init amd_pstate_init(void)
>  	if (cpufreq_get_current_driver())
>  		return -EEXIST;
>  
> +	quirks = NULL;
> +
> +	/* check if this machine need CPPC quirks */
> +	dmi_check_system(amd_pstate_quirks_table);
> +
>  	switch (cppc_state) {
>  	case AMD_PSTATE_UNDEFINED:
>  		/* Disable on the following configs by default:
> diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
> index ab7e82533718..6b832153a126 100644
> --- a/include/linux/amd-pstate.h
> +++ b/include/linux/amd-pstate.h
> @@ -128,4 +128,10 @@ static const char * const amd_pstate_mode_string[] = {
>  	[AMD_PSTATE_GUIDED]      = "guided",
>  	NULL,
>  };
> +
> +struct quirk_entry {
> +	u32 nominal_freq;
> +	u32 lowest_freq;
> +};
> +
>  #endif /* _LINUX_AMD_PSTATE_H */
> -- 
> 2.34.1
> 

  reply	other threads:[~2024-04-15 15:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25  3:03 [PATCH v10 0/8] AMD Pstate Fixes And Enhancements Perry Yuan
2024-03-25  3:03 ` [PATCH v10 1/8] cpufreq: amd-pstate: Document *_limit_* fields in struct amd_cpudata Perry Yuan
2024-04-15  1:37   ` Huang Rui
2024-04-18  9:17     ` Yuan, Perry
2024-03-25  3:03 ` [PATCH v10 2/8] cpufreq: amd-pstate: Document the units for freq variables in amd_cpudata Perry Yuan
2024-04-15  1:38   ` Huang Rui
2024-03-25  3:03 ` [PATCH v10 3/8] cpufreq: amd-pstate: Unify computation of {max,min,nominal,lowest_nonlinear}_freq Perry Yuan
2024-04-15 14:54   ` Huang Rui
2024-04-18  9:15     ` Yuan, Perry
2024-03-25  3:03 ` [PATCH v10 4/8] cpufreq: amd-pstate: Remove amd_get_{min,max,nominal,lowest_nonlinear}_freq() Perry Yuan
2024-04-15 14:56   ` Huang Rui
2024-03-25  3:03 ` [PATCH v10 5/8] cpufreq: amd-pstate: Bail out if min/max/nominal_freq is 0 Perry Yuan
2024-04-15 14:59   ` Huang Rui
2024-04-18  9:12     ` Yuan, Perry
2024-03-25  3:03 ` [PATCH v10 6/8] cpufreq: amd-pstate: get transition delay and latency value from ACPI tables Perry Yuan
2024-04-15 15:01   ` Huang Rui
2024-03-25  3:03 ` [PATCH v10 7/8] cppc_acpi: print error message if CPPC is unsupported Perry Yuan
2024-04-15 15:04   ` Huang Rui
2024-03-25  3:03 ` [PATCH v10 8/8] cpufreq: amd-pstate: Add quirk for the pstate CPPC capabilities missing Perry Yuan
2024-04-15 15:16   ` Huang Rui [this message]
2024-04-22  9:50     ` Yuan, Perry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zh1ExGtyhGOsduOs@amd.com \
    --to=ray.huang@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Borislav.Petkov@amd.com \
    --cc=Li.Meng@amd.com \
    --cc=Mario.Limonciello@amd.com \
    --cc=Perry.Yuan@amd.com \
    --cc=Shimmer.Huang@amd.com \
    --cc=Xiaojian.Du@amd.com \
    --cc=gautham.shenoy@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=oleksandr@natalenko.name \
    --cc=rafael.j.wysocki@intel.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).