diff mbox series

[v3,09/14] platform/x86: hfi: add power management callback

Message ID 20241015213645.1476-10-mario.limonciello@amd.com
State Superseded
Headers show
Series Add support for AMD hardware feedback interface | expand

Commit Message

Mario Limonciello Oct. 15, 2024, 9:36 p.m. UTC
From: Perry Yuan <Perry.Yuan@amd.com>

Introduces power management callbacks for the `amd_hfi` driver.
Specifically, the `suspend` and `resume` callbacks have been added
to handle the necessary operations during system low power states
and wake-up.

Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v2->v3:
 * Whitespace (Ilpo)
---
 drivers/platform/x86/amd/hfi/hfi.c | 33 ++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Gautham R. Shenoy Oct. 17, 2024, 6 a.m. UTC | #1
On Tue, Oct 15, 2024 at 04:36:40PM -0500, Mario Limonciello wrote:
> From: Perry Yuan <Perry.Yuan@amd.com>
> 
> Introduces power management callbacks for the `amd_hfi` driver.
> Specifically, the `suspend` and `resume` callbacks have been added
> to handle the necessary operations during system low power states
> and wake-up.
> 
> Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
> Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> v2->v3:
>  * Whitespace (Ilpo)
> ---
>  drivers/platform/x86/amd/hfi/hfi.c | 33 ++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> index d971ec1124af..79963c423d35 100644
> --- a/drivers/platform/x86/amd/hfi/hfi.c
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -392,6 +392,38 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
>  	return ret;
>  }
>  
> +static int amd_hfi_pm_resume(struct device *dev)
> +{
> +	int ret, cpu;
> +
> +	for_each_present_cpu(cpu) {

Shouldn't this be for_each_online_cpu() in light of the hotplug
notifier callbacks implemented in Patch 8?

> +		ret = amd_hfi_set_state(cpu, true);
> +		if (ret < 0) {
> +			dev_err(dev, "failed to enable workload class config: %d\n", ret);
> +			return ret;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static int amd_hfi_pm_suspend(struct device *dev)
> +{
> +	int ret, cpu;
> +
> +	for_each_present_cpu(cpu) {

Ditto..

> +		ret = amd_hfi_set_state(cpu, false);
> +		if (ret < 0) {
> +			dev_err(dev, "failed to disable workload class config: %d\n", ret);
> +			return ret;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static DEFINE_SIMPLE_DEV_PM_OPS(amd_hfi_pm_ops, amd_hfi_pm_suspend, amd_hfi_pm_resume);
> +
>  static const struct acpi_device_id amd_hfi_platform_match[] = {
>  	{ "AMDI0104", 0},
>  	{ }
> @@ -438,6 +470,7 @@ static struct platform_driver amd_hfi_driver = {
>  	.driver = {
>  		.name = AMD_HFI_DRIVER,
>  		.owner = THIS_MODULE,
> +		.pm = &amd_hfi_pm_ops,
>  		.acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
>  	},
>  	.probe = amd_hfi_probe,
> -- 
> 2.43.0

--
Thanks and Regards
gautham.
Mario Limonciello Oct. 17, 2024, 7:27 p.m. UTC | #2
On 10/17/2024 01:00, Gautham R. Shenoy wrote:
> On Tue, Oct 15, 2024 at 04:36:40PM -0500, Mario Limonciello wrote:
>> From: Perry Yuan <Perry.Yuan@amd.com>
>>
>> Introduces power management callbacks for the `amd_hfi` driver.
>> Specifically, the `suspend` and `resume` callbacks have been added
>> to handle the necessary operations during system low power states
>> and wake-up.
>>
>> Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
>> Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>> ---
>> v2->v3:
>>   * Whitespace (Ilpo)
>> ---
>>   drivers/platform/x86/amd/hfi/hfi.c | 33 ++++++++++++++++++++++++++++++
>>   1 file changed, 33 insertions(+)
>>
>> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
>> index d971ec1124af..79963c423d35 100644
>> --- a/drivers/platform/x86/amd/hfi/hfi.c
>> +++ b/drivers/platform/x86/amd/hfi/hfi.c
>> @@ -392,6 +392,38 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
>>   	return ret;
>>   }
>>   
>> +static int amd_hfi_pm_resume(struct device *dev)
>> +{
>> +	int ret, cpu;
>> +
>> +	for_each_present_cpu(cpu) {
> 
> Shouldn't this be for_each_online_cpu() in light of the hotplug
> notifier callbacks implemented in Patch 8?

Thx, will fix.

> 
>> +		ret = amd_hfi_set_state(cpu, true);
>> +		if (ret < 0) {
>> +			dev_err(dev, "failed to enable workload class config: %d\n", ret);
>> +			return ret;
>> +		}
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +static int amd_hfi_pm_suspend(struct device *dev)
>> +{
>> +	int ret, cpu;
>> +
>> +	for_each_present_cpu(cpu) {
> 
> Ditto..
> 
>> +		ret = amd_hfi_set_state(cpu, false);
>> +		if (ret < 0) {
>> +			dev_err(dev, "failed to disable workload class config: %d\n", ret);
>> +			return ret;
>> +		}
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +static DEFINE_SIMPLE_DEV_PM_OPS(amd_hfi_pm_ops, amd_hfi_pm_suspend, amd_hfi_pm_resume);
>> +
>>   static const struct acpi_device_id amd_hfi_platform_match[] = {
>>   	{ "AMDI0104", 0},
>>   	{ }
>> @@ -438,6 +470,7 @@ static struct platform_driver amd_hfi_driver = {
>>   	.driver = {
>>   		.name = AMD_HFI_DRIVER,
>>   		.owner = THIS_MODULE,
>> +		.pm = &amd_hfi_pm_ops,
>>   		.acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
>>   	},
>>   	.probe = amd_hfi_probe,
>> -- 
>> 2.43.0
> 
> --
> Thanks and Regards
> gautham.
diff mbox series

Patch

diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
index d971ec1124af..79963c423d35 100644
--- a/drivers/platform/x86/amd/hfi/hfi.c
+++ b/drivers/platform/x86/amd/hfi/hfi.c
@@ -392,6 +392,38 @@  static int amd_hfi_metadata_parser(struct platform_device *pdev,
 	return ret;
 }
 
+static int amd_hfi_pm_resume(struct device *dev)
+{
+	int ret, cpu;
+
+	for_each_present_cpu(cpu) {
+		ret = amd_hfi_set_state(cpu, true);
+		if (ret < 0) {
+			dev_err(dev, "failed to enable workload class config: %d\n", ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int amd_hfi_pm_suspend(struct device *dev)
+{
+	int ret, cpu;
+
+	for_each_present_cpu(cpu) {
+		ret = amd_hfi_set_state(cpu, false);
+		if (ret < 0) {
+			dev_err(dev, "failed to disable workload class config: %d\n", ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(amd_hfi_pm_ops, amd_hfi_pm_suspend, amd_hfi_pm_resume);
+
 static const struct acpi_device_id amd_hfi_platform_match[] = {
 	{ "AMDI0104", 0},
 	{ }
@@ -438,6 +470,7 @@  static struct platform_driver amd_hfi_driver = {
 	.driver = {
 		.name = AMD_HFI_DRIVER,
 		.owner = THIS_MODULE,
+		.pm = &amd_hfi_pm_ops,
 		.acpi_match_table = ACPI_PTR(amd_hfi_platform_match),
 	},
 	.probe = amd_hfi_probe,