Skip to contentSkip to conversation

ACPI: platform: Fix SMB0001 enumeration on Kontron devices

PATCH Superseded Andy Shevchenko 3 participants 11 messages Jun 26, 2023 – Jun 29, 2023

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover ACPI: platform: Fix SMB0001 enumeration on Kontron devices

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, add a flag and count the resources of the forbiden device. If the count is non-zero, the device must be skipped.

Changelog v3:
- provided completely rewritten solution (Rafael)
- due to above, added two new patches
- due to above, dropped tags from patch 3

Andy Shevchenko (4):
ACPI: bus: Constify acpi_companion_match() returned value
ACPI: bus: Introduce acpi_match_acpi_device() helper
ACPI: platform: Ignore SMB0001 only when it has resources
ACPI: platform: Move SMB0001 HID to the header and reuse

 drivers/acpi/acpi_platform.c  | 31 +++++++++++++++++++++++++++----
 drivers/acpi/bus.c            | 21 ++++++++++++++-------
 drivers/acpi/device_sysfs.c   |  2 +-
 drivers/acpi/internal.h       |  2 +-
 drivers/i2c/busses/i2c-scmi.c |  3 ---
 include/acpi/acpi_drivers.h   |  2 ++
 include/linux/acpi.h          |  9 +++++++++
 7 files changed, 54 insertions(+), 16 deletions(-)
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw

PATCH v3 1/4 ACPI: bus: Constify acpi_companion_match() returned value

acpi_companion_match() doesn't alter the contents of the passed parameter, so we don't expect that returned value can be altered either. So constify it.

---
 drivers/acpi/bus.c          | 6 +++---
 drivers/acpi/device_sysfs.c | 2 +-
 drivers/acpi/internal.h     | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/acpi/bus.c +3 -3
index e3e0bd0c5a50..20cdfb37da79 100644
@@ -682,7 +682,7 @@ bool acpi_device_is_first_physical_node(struct acpi_device *adev,
  * resources available from it but they will be matched normally using functions
  * provided by their bus types (and analogously for their modalias).
  */
-struct acpi_device *acpi_companion_match(const struct device *dev)
+const struct acpi_device *acpi_companion_match(const struct device *dev)
 {
 	struct acpi_device *adev;
 
@@ -706,7 +706,7 @@ struct acpi_device *acpi_companion_match(const struct device *dev)
  * identifiers and a _DSD object with the "compatible" property, use that
  * property to match against the given list of identifiers.
  */
-static bool acpi_of_match_device(struct acpi_device *adev,
+static bool acpi_of_match_device(const struct acpi_device *adev,
 				 const struct of_device_id *of_match_table,
 				 const struct of_device_id **of_id)
 {
@@ -808,7 +808,7 @@ static bool __acpi_match_device_cls(const struct acpi_device_id *id,
 	return true;
 }
 
-static bool __acpi_match_device(struct acpi_device *device,
+static bool __acpi_match_device(const struct acpi_device *device,
 				const struct acpi_device_id *acpi_ids,
 				const struct of_device_id *of_ids,
 				const struct acpi_device_id **acpi_id,
drivers/acpi/device_sysfs.c +1 -1
index 0fbfbaa8d8e3..b9bbf0746199 100644
@@ -283,7 +283,7 @@ int acpi_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env
 }
 EXPORT_SYMBOL_GPL(acpi_device_uevent_modalias);
 
-static int __acpi_device_modalias(struct acpi_device *adev, char *buf, int size)
+static int __acpi_device_modalias(const struct acpi_device *adev, char *buf, int size)
 {
 	int len, count;
 
drivers/acpi/internal.h +1 -1
index 50dcb35c9965..f4148dc50b9c 100644
@@ -121,7 +121,7 @@ int acpi_bus_register_early_device(int type);
 /* --------------------------------------------------------------------------
                      Device Matching and Notification
    -------------------------------------------------------------------------- */
-struct acpi_device *acpi_companion_match(const struct device *dev);
+const struct acpi_device *acpi_companion_match(const struct device *dev);
 int __acpi_device_uevent_modalias(const struct acpi_device *adev,
 				  struct kobj_uevent_env *env);
 
Signature · 1 line
2.40.0.1.gaa8946217a0b
#2 lore raw

Re: [PATCH v3 1/4] ACPI: bus: Constify acpi_companion_match() returned value

Quoted 6 lines · Andy Shevchenko

acpi_companion_match() doesn't alter the contents of the passed parameter, so we don't expect that returned value can be altered either. So constify it.

This makes sense even without the rest of the series, so I can queue it up right away if you want me to do that.

Quoted 66 lines
---
 drivers/acpi/bus.c          | 6 +++---
 drivers/acpi/device_sysfs.c | 2 +-
 drivers/acpi/internal.h     | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/acpi/bus.c +3 -3
index e3e0bd0c5a50..20cdfb37da79 100644
@@ -682,7 +682,7 @@ bool acpi_device_is_first_physical_node(struct acpi_device *adev,
  * resources available from it but they will be matched normally using functions
  * provided by their bus types (and analogously for their modalias).
  */
-struct acpi_device *acpi_companion_match(const struct device *dev)
+const struct acpi_device *acpi_companion_match(const struct device *dev)
 {
        struct acpi_device *adev;
 
@@ -706,7 +706,7 @@ struct acpi_device *acpi_companion_match(const struct device *dev)
  * identifiers and a _DSD object with the "compatible" property, use that
  * property to match against the given list of identifiers.
  */
-static bool acpi_of_match_device(struct acpi_device *adev,
+static bool acpi_of_match_device(const struct acpi_device *adev,
                                 const struct of_device_id *of_match_table,
                                 const struct of_device_id **of_id)
 {
@@ -808,7 +808,7 @@ static bool __acpi_match_device_cls(const struct acpi_device_id *id,
        return true;
 }
 
-static bool __acpi_match_device(struct acpi_device *device,
+static bool __acpi_match_device(const struct acpi_device *device,
                                const struct acpi_device_id *acpi_ids,
                                const struct of_device_id *of_ids,
                                const struct acpi_device_id **acpi_id,
drivers/acpi/device_sysfs.c +1 -1
index 0fbfbaa8d8e3..b9bbf0746199 100644
@@ -283,7 +283,7 @@ int acpi_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env
 }
 EXPORT_SYMBOL_GPL(acpi_device_uevent_modalias);
 
-static int __acpi_device_modalias(struct acpi_device *adev, char *buf, int size)
+static int __acpi_device_modalias(const struct acpi_device *adev, char *buf, int size)
 {
        int len, count;
 
drivers/acpi/internal.h +1 -2
index 50dcb35c9965..f4148dc50b9c 100644
@@ -121,7 +121,7 @@ int acpi_bus_register_early_device(int type);
 /* --------------------------------------------------------------------------
                      Device Matching and Notification
    -------------------------------------------------------------------------- */
-struct acpi_device *acpi_companion_match(const struct device *dev);
+const struct acpi_device *acpi_companion_match(const struct device *dev);
 int __acpi_device_uevent_modalias(const struct acpi_device *adev,
                                  struct kobj_uevent_env *env);
 
--

2.40.0.1.gaa8946217a0b

#3 lore raw

Re: [PATCH v3 1/4] ACPI: bus: Constify acpi_companion_match() returned value

Quoted 11 lines · Rafael J. Wysocki
Quoted 6 lines · Andy Shevchenko

acpi_companion_match() doesn't alter the contents of the passed parameter, so we don't expect that returned value can be altered either. So constify it.

This makes sense even without the rest of the series, so I can queue it up right away if you want me to do that.

Please, go ahead and thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v3 1/4] ACPI: bus: Constify acpi_companion_match() returned value

Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines · Andy Shevchenko

acpi_companion_match() doesn't alter the contents of the passed parameter, so we don't expect that returned value can be altered either. So constify it.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

This makes sense even without the rest of the series, so I can queue it up right away if you want me to do that.

Please, go ahead and thank you!

Done, thanks!

maintainer Reviewed-by on v3 1/4
#5 lore raw

Re: [PATCH v3 1/4] ACPI: bus: Constify acpi_companion_match() returned value

In reply to Andy Shevchenko

Hi Andy,

Quoted 5 lines · Andy Shevchenko

acpi_companion_match() doesn't alter the contents of the passed parameter, so we don't expect that returned value can be altered either. So constify it.

I guess I'm late for adding my

here.

Andi

#6 lore raw

PATCH v3 2/4 ACPI: bus: Introduce acpi_match_acpi_device() helper

In reply to Andy Shevchenko

In some cases we can't have a physical node associated with the ACPI device. Yet we want to match it against ID table and get respective driver data. Introduce the helper for that.

---
 drivers/acpi/bus.c   | 15 +++++++++++----
 include/linux/acpi.h |  9 +++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)
drivers/acpi/bus.c +11 -4
index 20cdfb37da79..ee88bfb60ac2 100644
@@ -850,6 +850,16 @@ static bool __acpi_match_device(const struct acpi_device *device,
 	return true;
 }
 
+const struct acpi_device_id *acpi_match_acpi_device(const struct acpi_device_id *ids,
+						    const struct acpi_device *adev)
+{
+	const struct acpi_device_id *id = NULL;
+
+	__acpi_match_device(adev, ids, NULL, &id, NULL);
+	return id;
+}
+EXPORT_SYMBOL_GPL(acpi_match_acpi_device);
+
 /**
  * acpi_match_device - Match a struct device against a given list of ACPI IDs
  * @ids: Array of struct acpi_device_id object to match against.
@@ -864,10 +874,7 @@ static bool __acpi_match_device(const struct acpi_device *device,
 const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
 					       const struct device *dev)
 {
-	const struct acpi_device_id *id = NULL;
-
-	__acpi_match_device(acpi_companion_match(dev), ids, NULL, &id, NULL);
-	return id;
+	return acpi_match_acpi_device(ids, acpi_companion_match(dev));
 }
 EXPORT_SYMBOL_GPL(acpi_match_device);
 
include/linux/acpi.h +9 -0
index 640f1c07c894..641dc4843987 100644
@@ -707,6 +707,9 @@ extern int acpi_nvs_register(__u64 start, __u64 size);
 extern int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *),
 				    void *data);
 
+const struct acpi_device_id *acpi_match_acpi_device(const struct acpi_device_id *ids,
+						    const struct acpi_device *adev);
+
 const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
 					       const struct device *dev);
 
@@ -922,6 +925,12 @@ static inline int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *),
 
 struct acpi_device_id;
 
+static inline const struct acpi_device_id *acpi_match_acpi_device(
+	const struct acpi_device_id *ids, const struct acpi_device *adev)
+{
+	return NULL;
+}
+
 static inline const struct acpi_device_id *acpi_match_device(
 	const struct acpi_device_id *ids, const struct device *dev)
 {
Signature · 1 line
2.40.0.1.gaa8946217a0b
#7 lore raw

Re: [PATCH v3 2/4] ACPI: bus: Introduce acpi_match_acpi_device() helper

Quoted 4 lines · Andy Shevchenko

In some cases we can't have a physical node associated with the ACPI device. Yet we want to match it against ID table and get respective driver data. Introduce the helper for that.

I think that the problem is really to find a struct acpi_device_id in a given list matching a given struct acpi_device.

Quoted 13 lines
---
 drivers/acpi/bus.c   | 15 +++++++++++----
 include/linux/acpi.h |  9 +++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)
drivers/acpi/bus.c +0 -0
index 20cdfb37da79..ee88bfb60ac2 100644
@@ -850,6 +850,16 @@ static bool __acpi_match_device(const struct acpi_device *device,
        return true;
 }

drivers/acpi/bus.c static bool __acpi_match_device(const struct acpi_device *device, · line 861

Quoted 10 lines
drivers/acpi/bus.c +9 -0
 
+const struct acpi_device_id *acpi_match_acpi_device(const struct acpi_device_id *ids,
+                                                   const struct acpi_device *adev)
+{
+       const struct acpi_device_id *id = NULL;
+
+       __acpi_match_device(adev, ids, NULL, &id, NULL);
+       return id;
+}
+EXPORT_SYMBOL_GPL(acpi_match_acpi_device);

This is fine, but it requires a kerneldoc comment (as an exported function).

Of course, the code in scan.c can use it even if it is not exported.

Quoted 46 lines
drivers/acpi/bus.c +2 -4
+
 /**
  * acpi_match_device - Match a struct device against a given list of ACPI IDs
  * @ids: Array of struct acpi_device_id object to match against.
@@ -864,10 +874,7 @@ static bool __acpi_match_device(const struct acpi_device *device,
 const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
                                               const struct device *dev)
 {
-       const struct acpi_device_id *id = NULL;
-
-       __acpi_match_device(acpi_companion_match(dev), ids, NULL, &id, NULL);
-       return id;
+       return acpi_match_acpi_device(ids, acpi_companion_match(dev));
 }
 EXPORT_SYMBOL_GPL(acpi_match_device);
 
include/linux/acpi.h +9 -1
index 640f1c07c894..641dc4843987 100644
@@ -707,6 +707,9 @@ extern int acpi_nvs_register(__u64 start, __u64 size);
 extern int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *),
                                    void *data);
 
+const struct acpi_device_id *acpi_match_acpi_device(const struct acpi_device_id *ids,
+                                                   const struct acpi_device *adev);
+
 const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
                                               const struct device *dev);
 
@@ -922,6 +925,12 @@ static inline int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *),
 
 struct acpi_device_id;
 
+static inline const struct acpi_device_id *acpi_match_acpi_device(
+       const struct acpi_device_id *ids, const struct acpi_device *adev)
+{
+       return NULL;
+}
+
 static inline const struct acpi_device_id *acpi_match_device(
        const struct acpi_device_id *ids, const struct device *dev)
 {
--

2.40.0.1.gaa8946217a0b

#8 lore raw

PATCH v3 3/4 ACPI: platform: Ignore SMB0001 only when it has resources

In reply to Andy Shevchenko

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

To resolve the situation, add a flag to driver data to allow devices with no resources in _CRS to be enumerated via platform bus.

---
 drivers/acpi/acpi_platform.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
drivers/acpi/acpi_platform.c +27 -4
index fe00a5783f53..ee6ea1ee8396 100644
@@ -9,6 +9,7 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/bits.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
@@ -19,13 +20,16 @@
 
 #include "internal.h"
 
+/* Exclude devices that have no _CRS resources provided */
+#define ACPI_ALLOW_WO_RESOURCES		BIT(0)
+
 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 */
+	{"SMB0001",  ACPI_ALLOW_WO_RESOURCES},	/* 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 unsigned int acpi_platform_resource_count(struct acpi_resource *ares, void *data)
+{
+	int *count = data;
+
+	(*count)++;
+
+	return AE_OK;
+}
+
 /**
  * acpi_create_platform_device - Create platform device for ACPI device node
  * @adev: ACPI device node to create a platform device for.
@@ -100,17 +113,27 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
 	struct acpi_device *parent = acpi_dev_parent(adev);
 	struct platform_device *pdev = NULL;
 	struct platform_device_info pdevinfo;
+	const struct acpi_device_id *match;
 	struct resource_entry *rentry;
 	struct list_head resource_list;
 	struct resource *resources = NULL;
-	int count;
+	int count = 0;
 
 	/* If the ACPI node already has a physical device attached, skip it. */
 	if (adev->physical_node_count)
 		return NULL;
 
-	if (!acpi_match_device_ids(adev, forbidden_id_list))
-		return ERR_PTR(-EINVAL);
+	match = acpi_match_acpi_device(forbidden_id_list, adev);
+	if (match) {
+		if (match->driver_data & ACPI_ALLOW_WO_RESOURCES) {
+			acpi_walk_resources(adev->handle, METHOD_NAME__CRS,
+					    acpi_platform_resource_count, &count);
+			if (count > 0)
+				return ERR_PTR(-EINVAL);
+		} else {
+			return ERR_PTR(-EINVAL);
+		}
+	}
 
 	INIT_LIST_HEAD(&resource_list);
 	count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
Signature · 1 line
2.40.0.1.gaa8946217a0b
maintainer Reviewed-by on v3 3/4
#9 lore raw

Re: [PATCH v3 3/4] ACPI: platform: Ignore SMB0001 only when it has resources

Hi Andy,

Quoted 11 lines · Andy Shevchenko

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

To resolve the situation, add a flag to driver data to allow devices with no resources in _CRS to be enumerated via platform bus.

Andi

#10 lore raw

PATCH v3 4/4 ACPI: platform: Move SMB0001 HID to the header and reuse

In reply to 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.

---
 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 ee6ea1ee8396..b5e32257fa3e 100644
@@ -29,7 +29,7 @@ static const struct acpi_device_id forbidden_id_list[] = {
 	{"PNP0000",  0},	/* PIC */
 	{"PNP0100",  0},	/* Timer */
 	{"PNP0200",  0},	/* AT DMA Controller */
-	{"SMB0001",  ACPI_ALLOW_WO_RESOURCES},	/* ACPI SMBUS virtual device */
+	{ACPI_SMBUS_MS_HID,  ACPI_ALLOW_WO_RESOURCES},	/* 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