Skip to contentSkip to conversation

ACPI: platform: Ignore SMB0001 only when it has resources

PATCH In review Andy Shevchenko 3 participants 10 messages Jun 21, 2023 – Jun 26, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 ACPI: platform: Ignore SMB0001 only when it has resources

After switching i2c-scmi driver to be a plaform one, it stopped being enumerated on number of Kontron platforms, because it's listed in the forbidden_id_list.

To resolve the situation, split the list to generic one and another that holds devices that has to be skipped if and only if they have bogus resources attached (_CRS method returns some).

---
v2: added tags (Andi, Michael), fixed spelling (Andi)

 drivers/acpi/acpi_platform.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/acpi/acpi_platform.c +25 -2
index fe00a5783f53..089a98bd18bf 100644
@@ -19,13 +19,17 @@
 
 #include "internal.h"
 
+static const struct acpi_device_id forbidden_id_with_resourses[] = {
+	{"SMB0001",  0},	/* ACPI SMBUS virtual device */
+	{ }
+};
+
 static const struct acpi_device_id forbidden_id_list[] = {
 	{"ACPI0009", 0},	/* IOxAPIC */
 	{"ACPI000A", 0},	/* IOAPIC */
 	{"PNP0000",  0},	/* PIC */
 	{"PNP0100",  0},	/* Timer */
 	{"PNP0200",  0},	/* AT DMA Controller */
-	{"SMB0001",  0},	/* ACPI SMBUS virtual device */
 	{ }
 };
 
@@ -83,6 +87,15 @@ static void acpi_platform_fill_resource(struct acpi_device *adev,
 		dest->parent = pci_find_resource(to_pci_dev(parent), dest);
 }
 
+static int acpi_platform_resource_count(struct acpi_resource *ares, void *data)
+{
+	int *count = data;
+
+	*count = *count + 1;
+
+	return 1;
+}
+
 /**
  * acpi_create_platform_device - Create platform device for ACPI device node
  * @adev: ACPI device node to create a platform device for.
@@ -103,7 +116,8 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
 	struct resource_entry *rentry;
 	struct list_head resource_list;
 	struct resource *resources = NULL;
-	int count;
+	int count = 0;
+	int ret;
 
 	/* If the ACPI node already has a physical device attached, skip it. */
 	if (adev->physical_node_count)
@@ -113,6 +127,15 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
 		return ERR_PTR(-EINVAL);
 
 	INIT_LIST_HEAD(&resource_list);
+	ret = acpi_dev_get_resources(adev, &resource_list, acpi_platform_resource_count, &count);
+	if (ret < 0)
+		return ERR_PTR(ret);
+
+	acpi_dev_free_resource_list(&resource_list);
+
+	if (count > 0 && !acpi_match_device_ids(adev, forbidden_id_with_resourses))
+		return ERR_PTR(-EINVAL);
+
 	count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
 	if (count < 0)
 		return NULL;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw

PATCH v2 2/2 ACPI: platform: Move SMB0001 HID to the header and reuse

There are at least two places in the kernel that are using the SMB0001 HID. Make it to be available via acpi_drivers.h header file. While at it, replace hard coded one with a definition.

---
v2: added tag (Andi)

 drivers/acpi/acpi_platform.c  | 2 +-
 drivers/i2c/busses/i2c-scmi.c | 3 ---
 include/acpi/acpi_drivers.h   | 2 ++
 3 files changed, 3 insertions(+), 4 deletions(-)
drivers/acpi/acpi_platform.c +1 -1
index 089a98bd18bf..e86f76ee3473 100644
@@ -20,7 +20,7 @@
 #include "internal.h"
 
 static const struct acpi_device_id forbidden_id_with_resourses[] = {
-	{"SMB0001",  0},	/* ACPI SMBUS virtual device */
+	{ACPI_SMBUS_MS_HID,  0},	/* ACPI SMBUS virtual device */
 	{ }
 };
 
drivers/i2c/busses/i2c-scmi.c +0 -3
index 104570292241..421735acfa14 100644
@@ -13,9 +13,6 @@
 #include <linux/i2c.h>
 #include <linux/acpi.h>
 
-/* SMBUS HID definition as supported by Microsoft Windows */
-#define ACPI_SMBUS_MS_HID		"SMB0001"
-
 struct smbus_methods_t {
 	char *mt_info;
 	char *mt_sbr;
include/acpi/acpi_drivers.h +2 -0
index 8372b0e7fd15..b14d165632e7 100644
@@ -27,6 +27,8 @@
 #define ACPI_BAY_HID			"LNXIOBAY"
 #define ACPI_DOCK_HID			"LNXDOCK"
 #define ACPI_ECDT_HID			"LNXEC"
+/* SMBUS HID definition as supported by Microsoft Windows */
+#define ACPI_SMBUS_MS_HID		"SMB0001"
 /* Quirk for broken IBM BIOSes */
 #define ACPI_SMBUS_IBM_HID		"SMBUSIBM"
 
Signature · 1 line
2.40.0.1.gaa8946217a0b
Acked-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] ACPI: platform: Move SMB0001 HID to the header and reuse

Quoted 8 lines · Andy Shevchenko

There are at least two places in the kernel that are using the SMB0001 HID. Make it to be available via acpi_drivers.h header file. While at it, replace hard coded one with a definition.

#3 lore raw
In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

After switching i2c-scmi driver to be a plaform one, it stopped

"platform"

Quoted 5 lines

being enumerated on number of Kontron platforms, because it's listed in the forbidden_id_list.

To resolve the situation, split the list to generic one and another that holds devices that has to be skipped if and only

"have"

Quoted 19 lines

if they have bogus resources attached (_CRS method returns some).

---
v2: added tags (Andi, Michael), fixed spelling (Andi)

 drivers/acpi/acpi_platform.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/acpi/acpi_platform.c +0 -0
index fe00a5783f53..089a98bd18bf 100644

drivers/acpi/acpi_platform.c line 22

Quoted 4 lines
drivers/acpi/acpi_platform.c +1 -0
@@ -19,13 +19,17 @@
 
 #include "internal.h"
 
+static const struct acpi_device_id forbidden_id_with_resourses[] = {

I don't quite like this name and the driver_data field could be used to indicate the need to check the resources.

Quoted 15 lines
drivers/acpi/acpi_platform.c +4 -1
+       {"SMB0001",  0},        /* ACPI SMBUS virtual device */
+       { }
+};
+
 static const struct acpi_device_id forbidden_id_list[] = {
        {"ACPI0009", 0},        /* IOxAPIC */
        {"ACPI000A", 0},        /* IOAPIC */
        {"PNP0000",  0},        /* PIC */
        {"PNP0100",  0},        /* Timer */
        {"PNP0200",  0},        /* AT DMA Controller */
-       {"SMB0001",  0},        /* ACPI SMBUS virtual device */
        { }
 };
 

drivers/acpi/acpi_platform.c static void acpi_platform_fill_resource(struct acpi_device *adev, · line 94

Quoted 8 lines
drivers/acpi/acpi_platform.c +5 -0
@@ -83,6 +87,15 @@ static void acpi_platform_fill_resource(struct acpi_device *adev,
                dest->parent = pci_find_resource(to_pci_dev(parent), dest);
 }
 
+static int acpi_platform_resource_count(struct acpi_resource *ares, void *data)
+{
+       int *count = data;
+
+       *count = *count + 1;

Why not (*count)++?

Quoted 18 lines
drivers/acpi/acpi_platform.c +6 -1
+
+       return 1;
+}
+
 /**
  * acpi_create_platform_device - Create platform device for ACPI device node
  * @adev: ACPI device node to create a platform device for.
@@ -103,7 +116,8 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
        struct resource_entry *rentry;
        struct list_head resource_list;
        struct resource *resources = NULL;
-       int count;
+       int count = 0;
+       int ret;
 
        /* If the ACPI node already has a physical device attached, skip it. */
        if (adev->physical_node_count)

drivers/acpi/acpi_platform.c struct platform_device *acpi_create_platform_device(struct acpi_device *adev, · line 132

Quoted 6 lines
drivers/acpi/acpi_platform.c +3 -0
@@ -113,6 +127,15 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
                return ERR_PTR(-EINVAL);
 
        INIT_LIST_HEAD(&resource_list);
+       ret = acpi_dev_get_resources(adev, &resource_list, acpi_platform_resource_count, &count);
+       if (ret < 0)
+               return ERR_PTR(ret);

Why not use acpi_walk_resources() directly here?

Also, this extra resources walk is only needed if the resources check is needed to decide whether or not to skip the device, so what's the benefit of doing it for every device that's not skipped?

Quoted 10 lines
drivers/acpi/acpi_platform.c +6 -1
+
+       acpi_dev_free_resource_list(&resource_list);
+
+       if (count > 0 && !acpi_match_device_ids(adev, forbidden_id_with_resourses))
+               return ERR_PTR(-EINVAL);
+
        count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
        if (count < 0)
                return NULL;
--
#4 lore raw
Quoted 7 lines · Rafael J. Wysocki
Quoted 2 lines · Andy Shevchenko

After switching i2c-scmi driver to be a plaform one, it stopped

"platform"

Quoted 9 lines
Quoted 5 lines

being enumerated on number of Kontron platforms, because it's listed in the forbidden_id_list.

To resolve the situation, split the list to generic one and another that holds devices that has to be skipped if and only

"have"

Quoted 1 line

if they have bogus resources attached (_CRS method returns some).

Thanks for the typo fixes!

...

Quoted 4 lines
Quoted 1 line

+static const struct acpi_device_id forbidden_id_with_resourses[] = {

I don't quite like this name and the driver_data field could be used to indicate the need to check the resources.

Okay, something like

/* Check if the device has resources provided by _CRS method */
#define ACPI_PLATFORM_CHECK_RES BIT(0)

?

Quoted 3 lines
Quoted 3 lines
drivers/acpi/acpi_platform.c +3 -0
+       {"SMB0001",  0},        /* ACPI SMBUS virtual device */
+       { }
+};

...

Quoted 7 lines

drivers/acpi/acpi_platform.c static void acpi_platform_fill_resource(struct acpi_device *adev, · line 94

Quoted 5 lines
drivers/acpi/acpi_platform.c +5 -0
+static int acpi_platform_resource_count(struct acpi_resource *ares, void *data)
+{
+       int *count = data;
+
+       *count = *count + 1;

Why not (*count)++?

Can be that way, I just copied'n'pasted from the existing code.

Quoted 2 lines
Quoted 2 lines
drivers/acpi/acpi_platform.c +2 -0
+       return 1;
+}

...

Quoted 6 lines

drivers/acpi/acpi_platform.c struct platform_device *acpi_create_platform_device(struct acpi_device *adev, · line 132

Quoted 4 lines
        INIT_LIST_HEAD(&resource_list);
drivers/acpi/acpi_platform.c +3 -0
+       ret = acpi_dev_get_resources(adev, &resource_list, acpi_platform_resource_count, &count);
+       if (ret < 0)
+               return ERR_PTR(ret);

Why not use acpi_walk_resources() directly here?

Can be done that way. Again, I just used a template (existing code in kernel) for similar functionality.

Quoted 3 lines

Also, this extra resources walk is only needed if the resources check is needed to decide whether or not to skip the device, so what's the benefit of doing it for every device that's not skipped?

Ah, indeed. Makes sense to have done it conditionally.

Quoted 1 line
Quoted 1 line

+ acpi_dev_free_resource_list(&resource_list);

...

Thank you for the review!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 28 lines · Andy Shevchenko
Quoted 7 lines · Rafael J. Wysocki
Quoted 2 lines · Andy Shevchenko

After switching i2c-scmi driver to be a plaform one, it stopped

"platform"

Quoted 9 lines
Quoted 5 lines

being enumerated on number of Kontron platforms, because it's listed in the forbidden_id_list.

To resolve the situation, split the list to generic one and another that holds devices that has to be skipped if and only

"have"

Quoted 1 line

if they have bogus resources attached (_CRS method returns some).

Thanks for the typo fixes!

...

Quoted 4 lines
Quoted 1 line

+static const struct acpi_device_id forbidden_id_with_resourses[] = {

I don't quite like this name and the driver_data field could be used to indicate the need to check the resources.

Quoted 6 lines

Okay, something like

/* Check if the device has resources provided by _CRS method */
#define ACPI_PLATFORM_CHECK_RES BIT(0)

?

Could be, but this is specific to forbidden_ids_list[]. Maybe ACPI_ALLOW_WO_RESOURCES or similar.

Quoted 14 lines
Quoted 3 lines
Quoted 3 lines
drivers/acpi/acpi_platform.c +3 -0
+       {"SMB0001",  0},        /* ACPI SMBUS virtual device */
+       { }
+};

...

Quoted 7 lines

drivers/acpi/acpi_platform.c static void acpi_platform_fill_resource(struct acpi_device *adev, · line 94

Quoted 5 lines
drivers/acpi/acpi_platform.c +5 -0
+static int acpi_platform_resource_count(struct acpi_resource *ares, void *data)
+{
+       int *count = data;
+
+       *count = *count + 1;

Why not (*count)++?

Quoted 4 lines

Can be that way, I just copied'n'pasted from the existing code.

Quoted 2 lines
Quoted 2 lines
drivers/acpi/acpi_platform.c +2 -0
+       return 1;
+}

BTW, this doesn't need to increment the count even. It could just terminate the walk on the first valid resource found and tell the caller to return true in that case.

#6 lore raw
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki

On Wed, Jun 21, 2023 at 5:16 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 7 lines
Quoted 4 lines

/* Check if the device has resources provided by _CRS method */
#define ACPI_PLATFORM_CHECK_RES BIT(0)

?

Could be, but this is specific to forbidden_ids_list[]. Maybe ACPI_ALLOW_WO_RESOURCES or similar.

Got it, will do this way.

...

Quoted 3 lines

BTW, this doesn't need to increment the count even. It could just terminate the walk on the first valid resource found and tell the caller to return true in that case.

Indeed, thank you for the hint!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki

On Wed, Jun 21, 2023 at 5:16 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 5 lines
Quoted 3 lines

BTW, this doesn't need to increment the count even. It could just terminate the walk on the first valid resource found and tell the caller to return true in that case.

Indeed, thank you for the hint!

Actually it's doesn't matter if we count them or not, we still must use the context of the call to set up a flag or whatever. With the current code in mind I prefer to count resources and compare that to be non-zero. This will help to read and understand code better.

That said, I will go with (*counter)++;

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki

On Wed, Jun 21, 2023 at 5:16 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

BTW, this doesn't need to increment the count even. It could just terminate the walk on the first valid resource found and tell the caller to return true in that case.

Indeed, thank you for the hint!

Actually it's doesn't matter if we count them or not, we still must use the context of the call to set up a flag or whatever.

No, it is sufficient to pass a pointer to a bool variable.

Quoted 2 lines

With the current code in mind I prefer to count resources and compare that to be non-zero. This will help to read and understand code better.

I'm not sure. The condition is "if there is at least one valid resource, skip the device". Counting them all will make casual readers wonder why IMO.

#9 lore raw
Quoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki

On Wed, Jun 21, 2023 at 5:16 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

BTW, this doesn't need to increment the count even. It could just terminate the walk on the first valid resource found and tell the caller to return true in that case.

Indeed, thank you for the hint!

Actually it's doesn't matter if we count them or not, we still must use the context of the call to set up a flag or whatever.

Quoted 8 lines

No, it is sufficient to pass a pointer to a bool variable.

Quoted 2 lines

With the current code in mind I prefer to count resources and compare that to be non-zero. This will help to read and understand code better.

I'm not sure. The condition is "if there is at least one valid resource, skip the device". Counting them all will make casual readers wonder why IMO.

Okay, Can you check v3 for the rest and I can send a v4 if nothing else there?

Signature · 2 lines
With Best Regards,
Andy Shevchenko