diff mbox series

platform/x86/amd/hsmp: Check HSMP support on AMD family of processors

Message ID 20240603081512.142909-1-suma.hegde@amd.com (mailing list archive)
State Accepted, archived
Delegated to: Hans de Goede
Headers show
Series platform/x86/amd/hsmp: Check HSMP support on AMD family of processors | expand

Commit Message

Suma Hegde June 3, 2024, 8:15 a.m. UTC
HSMP interface is supported only on few x86 processors from AMD.
Accessing HSMP registers on rest of the platforms might cause
unexpected behaviour. So add a check.

Also unavailability of this interface on rest of the processors
is not an error. Hence, use pr_info() instead of the pr_err() to
log the message.

Signed-off-by: Suma Hegde <suma.hegde@amd.com>
Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
---
This patch addresses review comments from Mario Limonciello for 
"Check HSMP support on AMD family of processors" patch at
<https://lore.kernel.org/platform-driver-x86/20240423091434.2063246-2-suma.hegde@amd.com/>
Please ignore the patch "platform/x86/amd/hsmp: Split the ACPI and non-ACPI code" in the above series.
<https://lore.kernel.org/platform-driver-x86/20240423091434.2063246-3-suma.hegde@amd.com/>

We are working on addressing Hans comments on sysfs patch "Remove devm_* call for sysfs and use dev_groups"
<https://lore.kernel.org/platform-driver-x86/20240410121746.1955500-1-suma.hegde@amd.com/>

 drivers/platform/x86/amd/hsmp.c | 50 ++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 7 deletions(-)

Comments

Hans de Goede June 3, 2024, 9:58 a.m. UTC | #1
Hi,

On 6/3/24 10:15 AM, Suma Hegde wrote:
> HSMP interface is supported only on few x86 processors from AMD.
> Accessing HSMP registers on rest of the platforms might cause
> unexpected behaviour. So add a check.
> 
> Also unavailability of this interface on rest of the processors
> is not an error. Hence, use pr_info() instead of the pr_err() to
> log the message.
> 
> Signed-off-by: Suma Hegde <suma.hegde@amd.com>
> Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

I will include this patch in my next fixes pull-req to Linus
for the current kernel development cycle.

Regards,

Hans


> ---
> This patch addresses review comments from Mario Limonciello for 
> "Check HSMP support on AMD family of processors" patch at
> <https://lore.kernel.org/platform-driver-x86/20240423091434.2063246-2-suma.hegde@amd.com/>
> Please ignore the patch "platform/x86/amd/hsmp: Split the ACPI and non-ACPI code" in the above series.
> <https://lore.kernel.org/platform-driver-x86/20240423091434.2063246-3-suma.hegde@amd.com/>
> 
> We are working on addressing Hans comments on sysfs patch "Remove devm_* call for sysfs and use dev_groups"
> <https://lore.kernel.org/platform-driver-x86/20240410121746.1955500-1-suma.hegde@amd.com/>
> 
>  drivers/platform/x86/amd/hsmp.c | 50 ++++++++++++++++++++++++++++-----
>  1 file changed, 43 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/hsmp.c b/drivers/platform/x86/amd/hsmp.c
> index d84ea66eecc6..8fcf38eed7f0 100644
> --- a/drivers/platform/x86/amd/hsmp.c
> +++ b/drivers/platform/x86/amd/hsmp.c
> @@ -907,16 +907,44 @@ static int hsmp_plat_dev_register(void)
>  	return ret;
>  }
>  
> +/*
> + * This check is only needed for backward compatibility of previous platforms.
> + * All new platforms are expected to support ACPI based probing.
> + */
> +static bool legacy_hsmp_support(void)
> +{
> +	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
> +		return false;
> +
> +	switch (boot_cpu_data.x86) {
> +	case 0x19:
> +		switch (boot_cpu_data.x86_model) {
> +		case 0x00 ... 0x1F:
> +		case 0x30 ... 0x3F:
> +		case 0x90 ... 0x9F:
> +		case 0xA0 ... 0xAF:
> +			return true;
> +		default:
> +			return false;
> +		}
> +	case 0x1A:
> +		switch (boot_cpu_data.x86_model) {
> +		case 0x00 ... 0x1F:
> +			return true;
> +		default:
> +			return false;
> +		}
> +	default:
> +		return false;
> +	}
> +
> +	return false;
> +}
> +
>  static int __init hsmp_plt_init(void)
>  {
>  	int ret = -ENODEV;
>  
> -	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD || boot_cpu_data.x86 < 0x19) {
> -		pr_err("HSMP is not supported on Family:%x model:%x\n",
> -		       boot_cpu_data.x86, boot_cpu_data.x86_model);
> -		return ret;
> -	}
> -
>  	/*
>  	 * amd_nb_num() returns number of SMN/DF interfaces present in the system
>  	 * if we have N SMN/DF interfaces that ideally means N sockets
> @@ -930,7 +958,15 @@ static int __init hsmp_plt_init(void)
>  		return ret;
>  
>  	if (!plat_dev.is_acpi_device) {
> -		ret = hsmp_plat_dev_register();
> +		if (legacy_hsmp_support()) {
> +			/* Not ACPI device, but supports HSMP, register a plat_dev */
> +			ret = hsmp_plat_dev_register();
> +		} else {
> +			/* Not ACPI, Does not support HSMP */
> +			pr_info("HSMP is not supported on Family:%x model:%x\n",
> +				boot_cpu_data.x86, boot_cpu_data.x86_model);
> +			ret = -ENODEV;
> +		}
>  		if (ret)
>  			platform_driver_unregister(&amd_hsmp_driver);
>  	}
diff mbox series

Patch

diff --git a/drivers/platform/x86/amd/hsmp.c b/drivers/platform/x86/amd/hsmp.c
index d84ea66eecc6..8fcf38eed7f0 100644
--- a/drivers/platform/x86/amd/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp.c
@@ -907,16 +907,44 @@  static int hsmp_plat_dev_register(void)
 	return ret;
 }
 
+/*
+ * This check is only needed for backward compatibility of previous platforms.
+ * All new platforms are expected to support ACPI based probing.
+ */
+static bool legacy_hsmp_support(void)
+{
+	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
+		return false;
+
+	switch (boot_cpu_data.x86) {
+	case 0x19:
+		switch (boot_cpu_data.x86_model) {
+		case 0x00 ... 0x1F:
+		case 0x30 ... 0x3F:
+		case 0x90 ... 0x9F:
+		case 0xA0 ... 0xAF:
+			return true;
+		default:
+			return false;
+		}
+	case 0x1A:
+		switch (boot_cpu_data.x86_model) {
+		case 0x00 ... 0x1F:
+			return true;
+		default:
+			return false;
+		}
+	default:
+		return false;
+	}
+
+	return false;
+}
+
 static int __init hsmp_plt_init(void)
 {
 	int ret = -ENODEV;
 
-	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD || boot_cpu_data.x86 < 0x19) {
-		pr_err("HSMP is not supported on Family:%x model:%x\n",
-		       boot_cpu_data.x86, boot_cpu_data.x86_model);
-		return ret;
-	}
-
 	/*
 	 * amd_nb_num() returns number of SMN/DF interfaces present in the system
 	 * if we have N SMN/DF interfaces that ideally means N sockets
@@ -930,7 +958,15 @@  static int __init hsmp_plt_init(void)
 		return ret;
 
 	if (!plat_dev.is_acpi_device) {
-		ret = hsmp_plat_dev_register();
+		if (legacy_hsmp_support()) {
+			/* Not ACPI device, but supports HSMP, register a plat_dev */
+			ret = hsmp_plat_dev_register();
+		} else {
+			/* Not ACPI, Does not support HSMP */
+			pr_info("HSMP is not supported on Family:%x model:%x\n",
+				boot_cpu_data.x86, boot_cpu_data.x86_model);
+			ret = -ENODEV;
+		}
 		if (ret)
 			platform_driver_unregister(&amd_hsmp_driver);
 	}