Skip to contentSkip to conversation

ACPI: add module autoloading support for ACPI enumerated devices

PATCH In review Zhang Rui 4 participants 7 messages Oct 14, 2013 – Oct 21, 2013

Subsystems (4)
lore
Share & tools
lore

Zhang Rui

author
#0 lore raw

PATCH 1/3 ACPI: add module autoloading support for ACPI enumerated devices

An ACPI enumerated device may have its compatible id strings.

To support the compatible ACPI ids (acpi_device->pnp.ids), we introduced acpi_driver_match_device() to match the driver->acpi_match_table and acpi_device->pnp.ids.

For those drivers, MODULE_DEVICE_TABLE(acpi, xxx) is used to exports the driver module alias in the format of "acpi:device_compatible_ids".
But in the mean time, the current code does not export the ACPI compatible strings as part of the module_alias for the ACPI enumerated devices, which will break the module autoloading.

Take the following piece of code for example,

static const struct acpi_device_id xxx_acpi_match[] = {
        { "INTABCD", 0 },
        { }
};

MODULE_DEVICE_TABLE(acpi, xxx_acpi_match);

If this piece of code is used in a platform driver for
an ACPI enumerated platform device, the platform driver module_alias is "acpi:INTABCD", but the uevent attribute of its platform device node is "platform:INTABCD:00" (PREFIX:pdev->name).
If this piece of code is used in an i2c driver for an ACPI enumerated i2c device, the i2c driver module_alias is "acpi:INTABCD", but the uevent of its i2c device node is "i2c:INTABCD:00" (PREFIX:client->name).

The reason why the module autoloading is not broken for now is that the uevent file of the ACPI device node is "acpi:INTABCD".
Thus it is the ACPI device node creation that loads the platform/i2c driver.

So this is a problem that will affect us the day when the ACPI bus is removed from device model.

This patch introduces a new function to exporting ACPI ids as the module_alias, for the ACPI enumerate devices.

For any drivers using MODULE_DEVICE_TALBE(acpi, blabla), the uevent file of its associated device must be fixed by invoking this function.

---
 drivers/acpi/scan.c  |   24 ++++++++++++++++++++++++
 include/linux/acpi.h |    8 ++++++++
 2 files changed, 32 insertions(+)
drivers/acpi/scan.c +24 -0
index 407ad13..db6f879 100644
@@ -111,6 +111,30 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
 	return len;
 }
 
+int acpi_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct acpi_device *acpi_dev;
+	int result;
+	int len;
+
+	result = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev);
+	if (result)
+		return result;
+
+	if (list_empty(&acpi_dev->pnp.ids))
+		return 0;
+
+	if (add_uevent_var(env, "MODALIAS="))
+		return -ENOMEM;
+	len = create_modalias(acpi_dev, &env->buf[env->buflen - 1],
+				sizeof(env->buf) - env->buflen);
+	if (len >= (sizeof(env->buf) - env->buflen))
+		return -ENOMEM;
+	env->buflen += len;
+	return 0;
+}
+EXPORT_SYMBOL(acpi_device_uevent_modalias);
+
 static ssize_t
 acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) {
 	struct acpi_device *acpi_dev = to_acpi_device(dev);
include/linux/acpi.h +8 -0
index a5db4ae..117fa26 100644
@@ -401,6 +401,8 @@ static inline bool acpi_driver_match_device(struct device *dev,
 	return !!acpi_match_device(drv->acpi_match_table, dev);
 }
 
+int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *);
+
 #define ACPI_PTR(_ptr)	(_ptr)
 
 #else	/* !CONFIG_ACPI */
@@ -471,6 +473,12 @@ static inline bool acpi_driver_match_device(struct device *dev,
 	return false;
 }
 
+static inline int acpi_device_uevent_modalias(struct device *dev,
+				struct kobj_uevent_env *env)
+{
+	return -ENODEV;
+}
+
 #define ACPI_PTR(_ptr)	(NULL)
 
 #endif	/* !CONFIG_ACPI */
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 2/3 Platform: fix module autoloading for ACPI enumerated devices

---
 drivers/base/platform.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/base/platform.c +4 -0
index 4f8bef3..80d2250 100644
@@ -690,6 +690,10 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
 	if (rc != -ENODEV)
 		return rc;
 
+	rc = acpi_device_uevent_modalias(dev, env);
+	if (rc != -ENODEV)
+		return rc;
+
 	add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
 			pdev->name);
 	return 0;
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH 3/3 I2C: fix module autoloading for ACPI enumerated devices

In reply to Zhang Rui
---
 drivers/i2c/i2c-core.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/i2c/i2c-core.c +5 -0
index 3be58f8..d75b679 100644
@@ -104,6 +104,11 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv)
 static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
 	struct i2c_client	*client = to_i2c_client(dev);
+	int rc;
+
+	rc = acpi_device_uevent_modalias(dev, env);
+	if (rc != -ENODEV)
+		return rc;
 
 	if (add_uevent_var(env, "MODALIAS=%s%s",
 			   I2C_MODULE_PREFIX, client->name))
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/3
#3 lore raw
In reply to Zhang Rui
Quoted 32 lines · Zhang Rui

An ACPI enumerated device may have its compatible id strings.

To support the compatible ACPI ids (acpi_device->pnp.ids), we introduced acpi_driver_match_device() to match the driver->acpi_match_table and acpi_device->pnp.ids.

For those drivers, MODULE_DEVICE_TABLE(acpi, xxx) is used to exports the driver module alias in the format of "acpi:device_compatible_ids".
But in the mean time, the current code does not export the ACPI compatible strings as part of the module_alias for the ACPI enumerated devices, which will break the module autoloading.

Take the following piece of code for example,

static const struct acpi_device_id xxx_acpi_match[] = {
        { "INTABCD", 0 },
        { }
};

MODULE_DEVICE_TABLE(acpi, xxx_acpi_match);

If this piece of code is used in a platform driver for
an ACPI enumerated platform device, the platform driver module_alias is "acpi:INTABCD", but the uevent attribute of its platform device node is "platform:INTABCD:00" (PREFIX:pdev->name).
If this piece of code is used in an i2c driver for an ACPI enumerated i2c device, the i2c driver module_alias is "acpi:INTABCD", but the uevent of its i2c device node is "i2c:INTABCD:00" (PREFIX:client->name).

The reason why the module autoloading is not broken for now is that the uevent file of the ACPI device node is "acpi:INTABCD".
Thus it is the ACPI device node creation that loads the platform/i2c driver.

Quoted 7 lines

So this is a problem that will affect us the day when the ACPI bus is removed from device model.

This patch introduces a new function to exporting ACPI ids as the module_alias, for the ACPI enumerate devices.

For any drivers using MODULE_DEVICE_TALBE(acpi, blabla), the uevent file

^ TABLE?

Quoted 3 lines

of its associated device must be fixed by invoking this function.

Makes sense. There is one comment below but other than that, you can add my,

For the three patches.

I wonder if we should do the same for SPI bus as well?

Quoted 26 lines
---
 drivers/acpi/scan.c  |   24 ++++++++++++++++++++++++
 include/linux/acpi.h |    8 ++++++++
 2 files changed, 32 insertions(+)
drivers/acpi/scan.c +13 -0
index 407ad13..db6f879 100644
@@ -111,6 +111,30 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
 	return len;
 }
 
+int acpi_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct acpi_device *acpi_dev;
+	int result;
+	int len;
+
+	result = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev);
+	if (result)
+		return result;
+
+	if (list_empty(&acpi_dev->pnp.ids))
+		return 0;
+

drivers/acpi/scan.c static int create_modalias(struct acpi_device *acpi_dev, char *modalias, · line 136

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+	if (add_uevent_var(env, "MODALIAS="))
+		return -ENOMEM;
+	len = create_modalias(acpi_dev, &env->buf[env->buflen - 1],
+				sizeof(env->buf) - env->buflen);
+	if (len >= (sizeof(env->buf) - env->buflen))
+		return -ENOMEM;
+	env->buflen += len;
+	return 0;
+}
+EXPORT_SYMBOL(acpi_device_uevent_modalias);

_GPL?

author
#4 lore raw
Quoted 42 lines · Mika Westerberg
Quoted 32 lines · Zhang Rui

An ACPI enumerated device may have its compatible id strings.

To support the compatible ACPI ids (acpi_device->pnp.ids), we introduced acpi_driver_match_device() to match the driver->acpi_match_table and acpi_device->pnp.ids.

For those drivers, MODULE_DEVICE_TABLE(acpi, xxx) is used to exports the driver module alias in the format of "acpi:device_compatible_ids".
But in the mean time, the current code does not export the ACPI compatible strings as part of the module_alias for the ACPI enumerated devices, which will break the module autoloading.

Take the following piece of code for example,

static const struct acpi_device_id xxx_acpi_match[] = {
        { "INTABCD", 0 },
        { }
};

MODULE_DEVICE_TABLE(acpi, xxx_acpi_match);

If this piece of code is used in a platform driver for
an ACPI enumerated platform device, the platform driver module_alias is "acpi:INTABCD", but the uevent attribute of its platform device node is "platform:INTABCD:00" (PREFIX:pdev->name).
If this piece of code is used in an i2c driver for an ACPI enumerated i2c device, the i2c driver module_alias is "acpi:INTABCD", but the uevent of its i2c device node is "i2c:INTABCD:00" (PREFIX:client->name).

The reason why the module autoloading is not broken for now is that the uevent file of the ACPI device node is "acpi:INTABCD".
Thus it is the ACPI device node creation that loads the platform/i2c driver.

Quoted 7 lines

So this is a problem that will affect us the day when the ACPI bus is removed from device model.

This patch introduces a new function to exporting ACPI ids as the module_alias, for the ACPI enumerate devices.

For any drivers using MODULE_DEVICE_TALBE(acpi, blabla), the uevent file

^ TABLE?

Quoted 9 lines
Quoted 3 lines

of its associated device must be fixed by invoking this function.

Makes sense. There is one comment below but other than that, you can add my,

Thanks for reviewing.

Quoted 4 lines

For the three patches.

I wonder if we should do the same for SPI bus as well?

yes, you are right.
Actually, I should check for buses that supports acpi_driver_match_device() and fix them all. Will add it in next version.

thanks,
rui

Quoted 38 lines
Quoted 26 lines
---
 drivers/acpi/scan.c  |   24 ++++++++++++++++++++++++
 include/linux/acpi.h |    8 ++++++++
 2 files changed, 32 insertions(+)
drivers/acpi/scan.c +13 -0
index 407ad13..db6f879 100644
@@ -111,6 +111,30 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
 	return len;
 }
 
+int acpi_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct acpi_device *acpi_dev;
+	int result;
+	int len;
+
+	result = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev);
+	if (result)
+		return result;
+
+	if (list_empty(&acpi_dev->pnp.ids))
+		return 0;
+

drivers/acpi/scan.c static int create_modalias(struct acpi_device *acpi_dev, char *modalias, · line 136

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+	if (add_uevent_var(env, "MODALIAS="))
+		return -ENOMEM;
+	len = create_modalias(acpi_dev, &env->buf[env->buflen - 1],
+				sizeof(env->buf) - env->buflen);
+	if (len >= (sizeof(env->buf) - env->buflen))
+		return -ENOMEM;
+	env->buflen += len;
+	return 0;
+}
+EXPORT_SYMBOL(acpi_device_uevent_modalias);

_GPL?

#5 lore raw

Hi

Quoted 10 lines · Zhang Rui
Quoted 4 lines · Mika Westerberg

For the three patches.

I wonder if we should do the same for SPI bus as well?

yes, you are right.
Actually, I should check for buses that supports acpi_driver_match_device() and fix them all. Will add it in next version.

You could have my pre- "Tested-by: Jarkko Nikula <[email protected]>".

With your set I see bunch of failing modprobe calls from udev for i2c:INTABCD:xy and platform:INTDCBA:xy modaliases gone.

Signature · 1 line
Jarkko
#6 lore raw
In reply to Zhang Rui
Quoted 68 lines · Zhang Rui

An ACPI enumerated device may have its compatible id strings.

To support the compatible ACPI ids (acpi_device->pnp.ids), we introduced acpi_driver_match_device() to match the driver->acpi_match_table and acpi_device->pnp.ids.

For those drivers, MODULE_DEVICE_TABLE(acpi, xxx) is used to exports the driver module alias in the format of "acpi:device_compatible_ids".
But in the mean time, the current code does not export the ACPI compatible strings as part of the module_alias for the ACPI enumerated devices, which will break the module autoloading.

Take the following piece of code for example,

static const struct acpi_device_id xxx_acpi_match[] = {
        { "INTABCD", 0 },
        { }
};

MODULE_DEVICE_TABLE(acpi, xxx_acpi_match);

If this piece of code is used in a platform driver for
an ACPI enumerated platform device, the platform driver module_alias is "acpi:INTABCD", but the uevent attribute of its platform device node is "platform:INTABCD:00" (PREFIX:pdev->name).
If this piece of code is used in an i2c driver for an ACPI enumerated i2c device, the i2c driver module_alias is "acpi:INTABCD", but the uevent of its i2c device node is "i2c:INTABCD:00" (PREFIX:client->name).

The reason why the module autoloading is not broken for now is that the uevent file of the ACPI device node is "acpi:INTABCD".
Thus it is the ACPI device node creation that loads the platform/i2c driver.

So this is a problem that will affect us the day when the ACPI bus is removed from device model.

This patch introduces a new function to exporting ACPI ids as the module_alias, for the ACPI enumerate devices.

For any drivers using MODULE_DEVICE_TALBE(acpi, blabla), the uevent file of its associated device must be fixed by invoking this function.

---
 drivers/acpi/scan.c  |   24 ++++++++++++++++++++++++
 include/linux/acpi.h |    8 ++++++++
 2 files changed, 32 insertions(+)
drivers/acpi/scan.c +13 -0
index 407ad13..db6f879 100644
@@ -111,6 +111,30 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
 	return len;
 }
 
+int acpi_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct acpi_device *acpi_dev;
+	int result;
+	int len;
+
+	result = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev);
+	if (result)
+		return result;
+
+	if (list_empty(&acpi_dev->pnp.ids))
+		return 0;
+

drivers/acpi/scan.c static int create_modalias(struct acpi_device *acpi_dev, char *modalias, · line 136

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+	if (add_uevent_var(env, "MODALIAS="))
+		return -ENOMEM;
+	len = create_modalias(acpi_dev, &env->buf[env->buflen - 1],
+				sizeof(env->buf) - env->buflen);
+	if (len >= (sizeof(env->buf) - env->buflen))
+		return -ENOMEM;
+	env->buflen += len;
+	return 0;
+}
+EXPORT_SYMBOL(acpi_device_uevent_modalias);

Looks like this function shares a lot with the existing acpi_device_uevent, so perhaps worth making some resue of the exising code? e.g. seperate the common code into a function and then have the two functions call it.

-Aaron

Quoted 31 lines
drivers/acpi/scan.c +1 -0
+
 static ssize_t
 acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) {
 	struct acpi_device *acpi_dev = to_acpi_device(dev);
include/linux/acpi.h +8 -0
index a5db4ae..117fa26 100644
@@ -401,6 +401,8 @@ static inline bool acpi_driver_match_device(struct device *dev,
 	return !!acpi_match_device(drv->acpi_match_table, dev);
 }
 
+int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *);
+
 #define ACPI_PTR(_ptr)	(_ptr)
 
 #else	/* !CONFIG_ACPI */
@@ -471,6 +473,12 @@ static inline bool acpi_driver_match_device(struct device *dev,
 	return false;
 }
 
+static inline int acpi_device_uevent_modalias(struct device *dev,
+				struct kobj_uevent_env *env)
+{
+	return -ENODEV;
+}
+
 #define ACPI_PTR(_ptr)	(NULL)
 
 #endif	/* !CONFIG_ACPI */