Skip to contentSkip to conversation

platform/x86: thinkpad_acpi: Fix incorrect use of platform profile on AMD platforms

PATCH In review Mark Pearson 2 participants 5 messages Jan 21, 2022 – Jan 26, 2022 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: thinkpad_acpi: Fix incorrect use of platform profile on AMD platforms

Lenovo AMD based platforms have been offering platform_profiles but they are not working correctly. This is because the mode we are using on the Intel platforms (MMC) is not available on the AMD platforms.

This commit adds checking of the functional capabilities returned by the BIOS to confirm if MMC is supported or not. Profiles will not be available if the platform is not MMC capable.

I'm investigating and working on an alternative for AMD platforms but that is still work-in-progress.

---
 drivers/platform/x86/thinkpad_acpi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/platform/x86/thinkpad_acpi.c +13 -0
index 9c632df734bb..42a04e44135b 100644
@@ -10026,6 +10026,9 @@ static struct ibm_struct proxsensor_driver_data = {
 #define DYTC_CMD_MMC_GET      8 /* To get current MMC function and mode */
 #define DYTC_CMD_RESET    0x1ff /* To reset back to default */
 
+#define DYTC_CMD_FUNC_CAP     3 /* To get DYTC capabilities */
+#define DYTC_FC_MMC           27 /* MMC Mode supported */
+
 #define DYTC_GET_FUNCTION_BIT 8  /* Bits  8-11 - function setting */
 #define DYTC_GET_MODE_BIT     12 /* Bits 12-15 - mode setting */
 
@@ -10253,6 +10256,16 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 	if (dytc_version >= 5) {
 		dbg_printk(TPACPI_DBG_INIT,
 				"DYTC version %d: thermal mode available\n", dytc_version);
+
+		/* Check what capabilities are supported. Currently MMC is needed */
+		err = dytc_command(DYTC_CMD_FUNC_CAP, &output);
+		if (err)
+			return err;
+		if (!test_bit(DYTC_FC_MMC, (void *)&output)) {
+			dbg_printk(TPACPI_DBG_INIT, " DYTC MMC mode not supported\n");
+			return 0;
+		}
+
 		/*
 		 * Check if MMC_GET functionality available
 		 * Version > 6 and return success from MMC_GET command
Signature · 1 line
2.34.1
#1 lore raw

Hi Mark,

Quoted 31 lines · Mark Pearson

Lenovo AMD based platforms have been offering platform_profiles but they are not working correctly. This is because the mode we are using on the Intel platforms (MMC) is not available on the AMD platforms.

This commit adds checking of the functional capabilities returned by the BIOS to confirm if MMC is supported or not. Profiles will not be available if the platform is not MMC capable.

I'm investigating and working on an alternative for AMD platforms but that is still work-in-progress.

---
 drivers/platform/x86/thinkpad_acpi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/platform/x86/thinkpad_acpi.c +3 -0
index 9c632df734bb..42a04e44135b 100644
@@ -10026,6 +10026,9 @@ static struct ibm_struct proxsensor_driver_data = {
 #define DYTC_CMD_MMC_GET      8 /* To get current MMC function and mode */
 #define DYTC_CMD_RESET    0x1ff /* To reset back to default */
 
+#define DYTC_CMD_FUNC_CAP     3 /* To get DYTC capabilities */
+#define DYTC_FC_MMC           27 /* MMC Mode supported */
+
 #define DYTC_GET_FUNCTION_BIT 8  /* Bits  8-11 - function setting */
 #define DYTC_GET_MODE_BIT     12 /* Bits 12-15 - mode setting */
 

drivers/platform/x86/thinkpad_acpi.c static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) · line 10258

Quoted 3 lines
drivers/platform/x86/thinkpad_acpi.c +0 -0
@@ -10253,6 +10256,16 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
 	if (dytc_version >= 5) {
 		dbg_printk(TPACPI_DBG_INIT,
 				"DYTC version %d: thermal mode available\n", dytc_version);

This code has been refactored and this will not apply as is:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/thinkpad_acpi.c?id=0b0d2fba4f3302b601c429c9286e66b3af2d29cb
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/thinkpad_acpi.c?id=798682e236893a20e5674de02ede474373dd342d

Please rebase on top of 5.17-rc1

drivers/platform/x86/thinkpad_acpi.c static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) · line 10266

Quoted 8 lines
drivers/platform/x86/thinkpad_acpi.c +8 -0
+
+		/* Check what capabilities are supported. Currently MMC is needed */
+		err = dytc_command(DYTC_CMD_FUNC_CAP, &output);
+		if (err)
+			return err;
+		if (!test_bit(DYTC_FC_MMC, (void *)&output)) {
+			dbg_printk(TPACPI_DBG_INIT, " DYTC MMC mode not supported\n");
+			return 0;

This should be return -ENODEV;

Regards,

Hans

Quoted 6 lines
drivers/platform/x86/thinkpad_acpi.c +2 -0
+		}
+
 		/*
 		 * Check if MMC_GET functionality available
 		 * Version > 6 and return success from MMC_GET command
#2 lore raw
Quoted 39 lines · Hans de Goede

Hi Mark,

Quoted 31 lines · Mark Pearson

Lenovo AMD based platforms have been offering platform_profiles but they are not working correctly. This is because the mode we are using on the Intel platforms (MMC) is not available on the AMD platforms.

This commit adds checking of the functional capabilities returned by the BIOS to confirm if MMC is supported or not. Profiles will not be available if the platform is not MMC capable.

I'm investigating and working on an alternative for AMD platforms but that is still work-in-progress.

---
  drivers/platform/x86/thinkpad_acpi.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
drivers/platform/x86/thinkpad_acpi.c +3 -0
index 9c632df734bb..42a04e44135b 100644
@@ -10026,6 +10026,9 @@ static struct ibm_struct proxsensor_driver_data = {
  #define DYTC_CMD_MMC_GET      8 /* To get current MMC function and mode */
  #define DYTC_CMD_RESET    0x1ff /* To reset back to default */
 
+#define DYTC_CMD_FUNC_CAP     3 /* To get DYTC capabilities */
+#define DYTC_FC_MMC           27 /* MMC Mode supported */
+
  #define DYTC_GET_FUNCTION_BIT 8  /* Bits  8-11 - function setting */
  #define DYTC_GET_MODE_BIT     12 /* Bits 12-15 - mode setting */
 

drivers/platform/x86/thinkpad_acpi.c static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) · line 10258

Quoted 3 lines
drivers/platform/x86/thinkpad_acpi.c +0 -0
@@ -10253,6 +10256,16 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm)
  	if (dytc_version >= 5) {
  		dbg_printk(TPACPI_DBG_INIT,
  				"DYTC version %d: thermal mode available\n", dytc_version);

This code has been refactored and this will not apply as is:

Quoted 4 lines

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/thinkpad_acpi.c?id=0b0d2fba4f3302b601c429c9286e66b3af2d29cb
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/thinkpad_acpi.c?id=798682e236893a20e5674de02ede474373dd342d

Please rebase on top of 5.17-rc1

My apologies - I thought I was on the latest. Will rebase

Quoted 10 lines

drivers/platform/x86/thinkpad_acpi.c static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) · line 10266

Quoted 9 lines
drivers/platform/x86/thinkpad_acpi.c +8 -0
+
+		/* Check what capabilities are supported. Currently MMC is needed */
+		err = dytc_command(DYTC_CMD_FUNC_CAP, &output);
+		if (err)
+			return err;
+		if (!test_bit(DYTC_FC_MMC, (void *)&output)) {
+			dbg_printk(TPACPI_DBG_INIT, " DYTC MMC mode not supported\n");
+			return 0;

This should be return -ENODEV;

I'll double check, but I don't think we want an error here as we want to continue on, it's just the feature is not supported so 0 is OK?

Thanks

Mark

#3 lore raw

Hi,

Quoted 39 lines · Mark Pearson
Quoted 37 lines · Hans de Goede

Hi Mark,

Quoted 26 lines · Mark Pearson

Lenovo AMD based platforms have been offering platform_profiles but they are not working correctly. This is because the mode we are using on the Intel platforms (MMC) is not available on the AMD platforms.

This commit adds checking of the functional capabilities returned by the BIOS to confirm if MMC is supported or not. Profiles will not be available if the platform is not MMC capable.

I'm investigating and working on an alternative for AMD platforms but that is still work-in-progress.

---
  drivers/platform/x86/thinkpad_acpi.c | 13 +++++++++++++

  1 file changed, 13 insertions(+)
drivers/platform/x86/thinkpad_acpi.c +0 -0
index 9c632df734bb..42a04e44135b 100644
@@ -10026,6 +10026,9 @@ static struct ibm_struct proxsensor_driver_data = {
   #define DYTC_CMD_MMC_GET      8 /* To get current MMC function and mode */
   #define DYTC_CMD_RESET    0x1ff /* To reset back to default */

  +#define DYTC_CMD_FUNC_CAP     3 /* To get DYTC capabilities */

drivers/platform/x86/thinkpad_acpi.c +2 -0
+#define DYTC_FC_MMC           27 /* MMC Mode supported */
+
Quoted 6 lines

  #define DYTC_GET_FUNCTION_BIT 8  /* Bits  8-11 - function setting */ #define DYTC_GET_MODE_BIT     12 /* Bits 12-15 - mode setting */
  @@ -10253,6 +10256,16 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) if (dytc_version >= 5) {
          dbg_printk(TPACPI_DBG_INIT,
                  "DYTC version %d: thermal mode available\n", dytc_version);

This code has been refactored and this will not apply as is:

Quoted 5 lines
Quoted 4 lines

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/thinkpad_acpi.c?id=0b0d2fba4f3302b601c429c9286e66b3af2d29cb
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/thinkpad_acpi.c?id=798682e236893a20e5674de02ede474373dd342d

Please rebase on top of 5.17-rc1

My apologies - I thought I was on the latest. Will rebase

No problem.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

+
+        /* Check what capabilities are supported. Currently MMC is needed */ +        err = dytc_command(DYTC_CMD_FUNC_CAP, &output);
+        if (err)
+            return err;
+        if (!test_bit(DYTC_FC_MMC, (void *)&output)) {
+            dbg_printk(TPACPI_DBG_INIT, " DYTC MMC mode not supported\n"); +            return 0;

Quoted 3 lines
Quoted 1 line

This should be return -ENODEV;

I'll double check, but I don't think we want an error here as we want to continue on, it's just the feature is not supported so 0 is OK?

-ENODEV is treated as "feature not supported" and will not cause any errors be printed and probing will continue normally with an -ENODEV error.

Where as 0 will still cause the corresponding exit function to get called on module unload, causing platform_profile_remove() to get called even though we never registered the platform_profile handler. So -ENODEV is better.

Regards,

Hans

#4 lore raw
Quoted 62 lines · Hans de Goede

Hi,

Quoted 39 lines · Mark Pearson
Quoted 37 lines · Hans de Goede

Hi Mark,

Quoted 26 lines · Mark Pearson

Lenovo AMD based platforms have been offering platform_profiles but they are not working correctly. This is because the mode we are using on the Intel platforms (MMC) is not available on the AMD platforms.

This commit adds checking of the functional capabilities returned by the BIOS to confirm if MMC is supported or not. Profiles will not be available if the platform is not MMC capable.

I'm investigating and working on an alternative for AMD platforms but that is still work-in-progress.

---
  drivers/platform/x86/thinkpad_acpi.c | 13 +++++++++++++

  1 file changed, 13 insertions(+)
drivers/platform/x86/thinkpad_acpi.c +0 -0
index 9c632df734bb..42a04e44135b 100644
@@ -10026,6 +10026,9 @@ static struct ibm_struct proxsensor_driver_data = {
   #define DYTC_CMD_MMC_GET      8 /* To get current MMC function and mode */
   #define DYTC_CMD_RESET    0x1ff /* To reset back to default */

  +#define DYTC_CMD_FUNC_CAP     3 /* To get DYTC capabilities */

drivers/platform/x86/thinkpad_acpi.c +2 -0
+#define DYTC_FC_MMC           27 /* MMC Mode supported */
+
Quoted 6 lines

  #define DYTC_GET_FUNCTION_BIT 8  /* Bits  8-11 - function setting */ #define DYTC_GET_MODE_BIT     12 /* Bits 12-15 - mode setting */
  @@ -10253,6 +10256,16 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) if (dytc_version >= 5) {
          dbg_printk(TPACPI_DBG_INIT,
                  "DYTC version %d: thermal mode available\n", dytc_version);

This code has been refactored and this will not apply as is:

Quoted 3 lines
Quoted 2 lines

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/thinkpad_acpi.c?id=0b0d2fba4f3302b601c429c9286e66b3af2d29cb>>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/platform/x86/thinkpad_acpi.c?id=798682e236893a20e5674de02ede474373dd342d>>>>
Please rebase on top of 5.17-rc1

My apologies - I thought I was on the latest. Will rebase

No problem.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

+
+        /* Check what capabilities are supported. Currently MMC is needed */ +        err = dytc_command(DYTC_CMD_FUNC_CAP, &output);
+        if (err)
+            return err;
+        if (!test_bit(DYTC_FC_MMC, (void *)&output)) {
+            dbg_printk(TPACPI_DBG_INIT, " DYTC MMC mode not supported\n"); +            return 0;

Quoted 3 lines
Quoted 1 line

This should be return -ENODEV;

I'll double check, but I don't think we want an error here as we want to continue on, it's just the feature is not supported so 0 is OK?

Quoted 9 lines

-ENODEV is treated as "feature not supported" and will not cause any errors be printed and probing will continue normally with an -ENODEV error.

Where as 0 will still cause the corresponding exit function to get called on module unload, causing platform_profile_remove() to get called even though we never registered the platform_profile handler. So -ENODEV is better.

Ah - my bad. I'll correct that.
Thanks!
Mark