Skip to contentSkip to conversation

crosslink ACPI and "real" device nodes

PATCH In review David Brownell 3 participants 15 messages Feb 23, 2008 – Mar 8, 2008 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crosslink ACPI and "real" device nodes

Add cross-links between ACPI device and "real" devices in sysfs, exposing otherwise-hidden interrelationships between the various device nodes for ACPI stuff. As a representative example, one hardware device is exposed as two logical devices (PNP and ACPI):

.../pnp0/00:06/ .../LNXSYSTM:00/device:00/PNP0A03:00/device:15/PNP0B00:00/

The PNP device gets a "firmware_node" link pointing to the ACPI device, and is what a Linux device driver binds to. The ACPI device has instead a "physical_node" link pointing back to the PNP device. Other firmware frameworks, like OpenFirmware, could do the same thing to couple their firmware tables to the rest of the system.

(Based on a patch from Zhang Rui. This version is modified to not depend on the patch makig ACPI initialize driver model wakeup flags.)

---
Another extract from the "teach ACPI how to use driver model wakeup flags" patch series. The linkage helps sort out confusion about which devices are wakeup-capable, among other things, and can help when interpreting /proc/acpi/wakeup contents.

 drivers/acpi/glue.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/acpi/glue.c +20 -0
@@ -142,6 +142,7 @@ EXPORT_SYMBOL(acpi_get_physical_device);
 
 static int acpi_bind_one(struct device *dev, acpi_handle handle)
 {
+	struct acpi_device *acpi_dev;
 	acpi_status status;
 
 	if (dev->archdata.acpi_handle) {
@@ -157,6 +158,16 @@ static int acpi_bind_one(struct device *
 	}
 	dev->archdata.acpi_handle = handle;
 
+	status = acpi_bus_get_device(handle, &acpi_dev);
+	if (!ACPI_FAILURE(status)) {
+		int ret;
+
+		ret = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
+				"firmware_node");
+		ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
+				"physical_node");
+	}
+
 	return 0;
 }
 
@@ -165,8 +176,17 @@ static int acpi_unbind_one(struct device
 	if (!dev->archdata.acpi_handle)
 		return 0;
 	if (dev == acpi_get_physical_device(dev->archdata.acpi_handle)) {
+		struct acpi_device *acpi_dev;
+
 		/* acpi_get_physical_device increase refcnt by one */
 		put_device(dev);
+
+		if (!acpi_bus_get_device(dev->archdata.acpi_handle,
+					&acpi_dev)) {
+			sysfs_remove_link(&dev->kobj, "firmware_node");
+			sysfs_remove_link(&acpi_dev->dev.kobj, "physical_node");
+		}
+
 		acpi_detach_data(dev->archdata.acpi_handle,
 				 acpi_glue_data_handler);
 		dev->archdata.acpi_handle = NULL;
#1 lore raw
Quoted 47 lines · David Brownell

Add cross-links between ACPI device and "real" devices in sysfs, exposing otherwise-hidden interrelationships between the various device nodes for ACPI stuff. As a representative example, one hardware device is exposed as two logical devices (PNP and ACPI):

.../pnp0/00:06/ .../LNXSYSTM:00/device:00/PNP0A03:00/device:15/PNP0B00:00/

The PNP device gets a "firmware_node" link pointing to the ACPI device,
and is what a Linux device driver binds to. The ACPI device has instead
a "physical_node" link pointing back to the PNP device. Other firmware
frameworks, like OpenFirmware, could do the same thing to couple their firmware tables to the rest of the system.

(Based on a patch from Zhang Rui. This version is modified to not depend on the patch makig ACPI initialize driver model wakeup flags.)

---
Another extract from the "teach ACPI how to use driver model wakeup flags" patch series. The linkage helps sort out confusion about which devices are wakeup-capable, among other things, and can help when interpreting /proc/acpi/wakeup contents.

 drivers/acpi/glue.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

--- g26.orig/drivers/acpi/glue.c 2008-02-22 20:39:19.000000000
-0800
+++ g26/drivers/acpi/glue.c 2008-02-22 20:46:40.000000000 -0800

drivers/acpi/glue.c +2 -0
@@ -142,6 +142,7 @@ EXPORT_SYMBOL(acpi_get_physical_device);
 
 static int acpi_bind_one(struct device *dev, acpi_handle handle)
 {
+       struct acpi_device *acpi_dev;
        acpi_status status;
 
        if (dev->archdata.acpi_handle) {
@@ -157,6 +158,16 @@ static int acpi_bind_one(struct device *
        }
        dev->archdata.acpi_handle = handle;
 
+       status = acpi_bus_get_device(handle, &acpi_dev);

drivers/acpi/glue.c static int acpi_bind_one(struct device * · line 171

Quoted 10 lines
drivers/acpi/glue.c +8 -0
+       if (!ACPI_FAILURE(status)) {
+               int ret;
+
+               ret = sysfs_create_link(&dev->kobj,
 &acpi_dev->dev.kobj,
+                               "firmware_node");
+               ret = sysfs_create_link(&acpi_dev->dev.kobj,
 &dev->kobj,
+                               "physical_node");
+       }

ret is not needed here...

Quoted 26 lines
drivers/acpi/glue.c +9 -0
        return 0;
 }
@@ -165,8 +176,17 @@ static int acpi_unbind_one(struct device
        if (!dev->archdata.acpi_handle)
                return 0;
        if (dev ==
 acpi_get_physical_device(dev->archdata.acpi_handle)) {
+               struct acpi_device *acpi_dev;
+
                /* acpi_get_physical_device increase refcnt by one */
                put_device(dev);
+
+               if (!acpi_bus_get_device(dev->archdata.acpi_handle,
+                                       &acpi_dev)) {
+                       sysfs_remove_link(&dev->kobj,
 "firmware_node");
+                       sysfs_remove_link(&acpi_dev->dev.kobj,
 "physical_node");
+               }
+
                acpi_detach_data(dev->archdata.acpi_handle,
                                 acpi_glue_data_handler);
                dev->archdata.acpi_handle = NULL;
#2 lore raw
In reply to David Brownell
Quoted 47 lines · David Brownell

Add cross-links between ACPI device and "real" devices in sysfs, exposing otherwise-hidden interrelationships between the various device nodes for ACPI stuff. As a representative example, one hardware device is exposed as two logical devices (PNP and ACPI):

.../pnp0/00:06/ .../LNXSYSTM:00/device:00/PNP0A03:00/device:15/PNP0B00:00/

The PNP device gets a "firmware_node" link pointing to the ACPI device,
and is what a Linux device driver binds to. The ACPI device has instead
a "physical_node" link pointing back to the PNP device. Other firmware
frameworks, like OpenFirmware, could do the same thing to couple their firmware tables to the rest of the system.

(Based on a patch from Zhang Rui. This version is modified to not depend on the patch makig ACPI initialize driver model wakeup flags.)

---
Another extract from the "teach ACPI how to use driver model wakeup flags" patch series. The linkage helps sort out confusion about which devices are wakeup-capable, among other things, and can help when interpreting /proc/acpi/wakeup contents.

 drivers/acpi/glue.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

--- g26.orig/drivers/acpi/glue.c 2008-02-22 20:39:19.000000000
-0800
+++ g26/drivers/acpi/glue.c 2008-02-22 20:46:40.000000000 -0800

drivers/acpi/glue.c +2 -0
@@ -142,6 +142,7 @@ EXPORT_SYMBOL(acpi_get_physical_device);
 
 static int acpi_bind_one(struct device *dev, acpi_handle handle)
 {
+       struct acpi_device *acpi_dev;
        acpi_status status;
 
        if (dev->archdata.acpi_handle) {
@@ -157,6 +158,16 @@ static int acpi_bind_one(struct device *
        }
        dev->archdata.acpi_handle = handle;
 
+       status = acpi_bus_get_device(handle, &acpi_dev);

drivers/acpi/glue.c static int acpi_bind_one(struct device * · line 171

Quoted 10 lines
drivers/acpi/glue.c +8 -0
+       if (!ACPI_FAILURE(status)) {
+               int ret;
+
+               ret = sysfs_create_link(&dev->kobj,
 &acpi_dev->dev.kobj,
+                               "firmware_node");
+               ret = sysfs_create_link(&acpi_dev->dev.kobj,
 &dev->kobj,
+                               "physical_node");
+       }

ret is not needed here...

Quoted 26 lines
drivers/acpi/glue.c +9 -0
        return 0;
 }
@@ -165,8 +176,17 @@ static int acpi_unbind_one(struct device
        if (!dev->archdata.acpi_handle)
                return 0;
        if (dev ==
 acpi_get_physical_device(dev->archdata.acpi_handle)) {
+               struct acpi_device *acpi_dev;
+
                /* acpi_get_physical_device increase refcnt by one */
                put_device(dev);
+
+               if (!acpi_bus_get_device(dev->archdata.acpi_handle,
+                                       &acpi_dev)) {
+                       sysfs_remove_link(&dev->kobj,
 "firmware_node");
+                       sysfs_remove_link(&acpi_dev->dev.kobj,
 "physical_node");
+               }
+
                acpi_detach_data(dev->archdata.acpi_handle,
                                 acpi_glue_data_handler);
                dev->archdata.acpi_handle = NULL;
#3 lore raw
Quoted 10 lines · Rui
Quoted 8 lines

+       if (!ACPI_FAILURE(status)) {
+               int ret;
+
+               ret = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
+                               "firmware_node");
+               ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
+                               "physical_node");
+       }

ret is not needed here...

But what compiler warnings do you see when you omit it? :)

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 8 lines · David Brownell
Quoted 4 lines · Rui

drivers/acpi/glue.c static int acpi_bind_one(struct device *

Quoted 4 lines
drivers/acpi/glue.c +4 -0
+       if (!ACPI_FAILURE(status)) {
+               int ret;
+
+               ret = sysfs_create_link(&dev->kobj,

&acpi_dev->dev.kobj,

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                               "firmware_node");
+               ret = sysfs_create_link(&acpi_dev->dev.kobj,
Quoted 7 lines

&dev->kobj,

Quoted 4 lines

drivers/acpi/glue.c static int acpi_bind_one(struct device * · line 169

Quoted 2 lines
drivers/acpi/glue.c +2 -0
+                               "physical_node");
+       }

ret is not needed here...

But what compiler warnings do you see when you omit it? :)

I tried but NO warnings at all

thanks,
rui

#5 lore raw
In reply to David Brownell
Quoted 8 lines · David Brownell
Quoted 4 lines · Rui

drivers/acpi/glue.c static int acpi_bind_one(struct device *

Quoted 4 lines
drivers/acpi/glue.c +4 -0
+       if (!ACPI_FAILURE(status)) {
+               int ret;
+
+               ret = sysfs_create_link(&dev->kobj,

&acpi_dev->dev.kobj,

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                               "firmware_node");
+               ret = sysfs_create_link(&acpi_dev->dev.kobj,
Quoted 7 lines

&dev->kobj,

Quoted 4 lines

drivers/acpi/glue.c static int acpi_bind_one(struct device * · line 169

Quoted 2 lines
drivers/acpi/glue.c +2 -0
+                               "physical_node");
+       }

ret is not needed here...

But what compiler warnings do you see when you omit it? :)

I tried but NO warnings at all

thanks,
rui

#6 lore raw
Quoted 12 lines · Rui
Quoted 10 lines · David Brownell
Quoted 9 lines · Rui
Quoted 8 lines
drivers/acpi/glue.c +8 -0
+       if (!ACPI_FAILURE(status)) {
+               int ret;
+
+               ret = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
+                               "firmware_node");
+               ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
+                               "physical_node");
+       }
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

ret is not needed here...

But what compiler warnings do you see when you omit it? :)

I tried but NO warnings at all

Really??? In <linux/sysfs.h> I found:

int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,

                                   const char *name);

Perhaps you disabled those warnings. (And FWIW, I don't see any reasonable way to handle such faults, so ignoring them is thus the right "solution".)

#7 lore raw
In reply to Zhang, Rui
Quoted 12 lines · Rui
Quoted 10 lines · David Brownell
Quoted 9 lines · Rui
Quoted 8 lines
drivers/acpi/glue.c +8 -0
+       if (!ACPI_FAILURE(status)) {
+               int ret;
+
+               ret = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
+                               "firmware_node");
+               ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
+                               "physical_node");
+       }
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

ret is not needed here...

But what compiler warnings do you see when you omit it? :)

I tried but NO warnings at all

Really??? In <linux/sysfs.h> I found:

int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,

                                   const char *name);

Perhaps you disabled those warnings. (And FWIW, I don't see any reasonable way to handle such faults, so ignoring them is thus the right "solution".)

#8 lore raw
Quoted 6 lines · David Brownell

int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,

                                   const char *name);

Perhaps you disabled those warnings. (And FWIW, I don't see any reasonable way to handle such faults, so ignoring them is thus the right "solution".)

You issue a printk warning the user, and try to continue.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#9 lore raw
In reply to David Brownell
Quoted 6 lines · David Brownell

int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,

                                   const char *name);

Perhaps you disabled those warnings. (And FWIW, I don't see any reasonable way to handle such faults, so ignoring them is thus the right "solution".)

You issue a printk warning the user, and try to continue.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#10 lore raw
Quoted 9 lines · Henrique de Moraes Holschuh
Quoted 6 lines · David Brownell

int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,

                                   const char *name);

Perhaps you disabled those warnings. (And FWIW, I don't see any reasonable way to handle such faults, so ignoring them is thus the right "solution".)

You issue a printk warning the user, and try to continue.

That's not "handling" in any useful sense though. There's no question about "try" to continue, by the way ... from inside the kernel this information is completely non-essential.

- Dave

#11 lore raw
In reply to Henrique de Moraes Holschuh
Quoted 9 lines · Henrique de Moraes Holschuh
Quoted 6 lines · David Brownell

int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,

                                   const char *name);

Perhaps you disabled those warnings. (And FWIW, I don't see any reasonable way to handle such faults, so ignoring them is thus the right "solution".)

You issue a printk warning the user, and try to continue.

That's not "handling" in any useful sense though. There's no question about "try" to continue, by the way ... from inside the kernel this information is completely non-essential.

- Dave

#12 lore raw
Quoted 9 lines · David Brownell
Quoted 8 lines · Henrique de Moraes Holschuh
Quoted 6 lines · David Brownell

int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,

                                   const char *name);

Perhaps you disabled those warnings. (And FWIW, I don't see any reasonable way to handle such faults, so ignoring them is thus the right "solution".)

Quoted 5 lines
Quoted 1 line

You issue a printk warning the user, and try to continue.

That's not "handling" in any useful sense though. There's no question about "try" to continue, by the way ... from inside the kernel this information is completely non-essential.

Here's a version with pr_debug() to report those case. Against git-current.

======== CUT HERE
From: David Brownell <[email protected]>

Add cross-links between ACPI device and "real" devices in sysfs, exposing otherwise-hidden interrelationships between the various device nodes which ACPI creates. As a representative example one hardware device is exposed as two logical devices (PNP and ACPI):

.../pnp0/00:06/ .../LNXSYSTM:00/device:00/PNP0A03:00/device:15/PNP0B00:00/

The PNP device gets a "firmware_node" link pointing to the ACPI device. The ACPI device has a "physical_node" link pointing to the PNP device.

Linux drivers currently bind only to the "physical" device nodes.

Other device trees provided by firmware tables could be exported using the same scheme; these names aren't ACPI-specific.

(Based on a patch from Zhang Rui. This version is modified to not depend on the patch teaching ACPI about driver model wakeup flags.)

---
Change from previous version: if creating the link fails, a pr_debug level message is emitted.

 drivers/acpi/glue.c |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
drivers/acpi/glue.c +27 -0
@@ -142,6 +142,7 @@ EXPORT_SYMBOL(acpi_get_physical_device);
 
 static int acpi_bind_one(struct device *dev, acpi_handle handle)
 {
+	struct acpi_device *acpi_dev;
 	acpi_status status;
 
 	if (dev->archdata.acpi_handle) {
@@ -157,6 +158,23 @@ static int acpi_bind_one(struct device *
 	}
 	dev->archdata.acpi_handle = handle;
 
+	status = acpi_bus_get_device(handle, &acpi_dev);
+	if (!ACPI_FAILURE(status)) {
+		int ret;
+
+		ret = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
+				"firmware_node");
+		if (ret != 0)
+			pr_debug(PREFIX "Can't create %s link for %s\n",
+				"firmware_node", dev->bus_id);
+
+		ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
+				"physical_node");
+		if (ret != 0)
+			pr_debug(PREFIX "Can't create %s link for %s\n",
+				"physical_node", acpi_dev->dev.bus_id);
+	}
+
 	return 0;
 }
 
@@ -165,8 +183,17 @@ static int acpi_unbind_one(struct device
 	if (!dev->archdata.acpi_handle)
 		return 0;
 	if (dev == acpi_get_physical_device(dev->archdata.acpi_handle)) {
+		struct acpi_device *acpi_dev;
+
 		/* acpi_get_physical_device increase refcnt by one */
 		put_device(dev);
+
+		if (!acpi_bus_get_device(dev->archdata.acpi_handle,
+					&acpi_dev)) {
+			sysfs_remove_link(&dev->kobj, "firmware_node");
+			sysfs_remove_link(&acpi_dev->dev.kobj, "physical_node");
+		}
+
 		acpi_detach_data(dev->archdata.acpi_handle,
 				 acpi_glue_data_handler);
 		dev->archdata.acpi_handle = NULL;
#13 lore raw
In reply to David Brownell
Quoted 9 lines · David Brownell
Quoted 8 lines · Henrique de Moraes Holschuh
Quoted 6 lines · David Brownell

int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,

                                   const char *name);

Perhaps you disabled those warnings. (And FWIW, I don't see any reasonable way to handle such faults, so ignoring them is thus the right "solution".)

Quoted 5 lines
Quoted 1 line

You issue a printk warning the user, and try to continue.

That's not "handling" in any useful sense though. There's no question about "try" to continue, by the way ... from inside the kernel this information is completely non-essential.

Here's a version with pr_debug() to report those case. Against git-current.

======== CUT HERE
From: David Brownell <[email protected]>

Add cross-links between ACPI device and "real" devices in sysfs, exposing otherwise-hidden interrelationships between the various device nodes which ACPI creates. As a representative example one hardware device is exposed as two logical devices (PNP and ACPI):

.../pnp0/00:06/ .../LNXSYSTM:00/device:00/PNP0A03:00/device:15/PNP0B00:00/

The PNP device gets a "firmware_node" link pointing to the ACPI device. The ACPI device has a "physical_node" link pointing to the PNP device.

Linux drivers currently bind only to the "physical" device nodes.

Other device trees provided by firmware tables could be exported using the same scheme; these names aren't ACPI-specific.

(Based on a patch from Zhang Rui. This version is modified to not depend on the patch teaching ACPI about driver model wakeup flags.)

---
Change from previous version: if creating the link fails, a pr_debug level message is emitted.

 drivers/acpi/glue.c |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
drivers/acpi/glue.c +27 -0
@@ -142,6 +142,7 @@ EXPORT_SYMBOL(acpi_get_physical_device);
 
 static int acpi_bind_one(struct device *dev, acpi_handle handle)
 {
+	struct acpi_device *acpi_dev;
 	acpi_status status;
 
 	if (dev->archdata.acpi_handle) {
@@ -157,6 +158,23 @@ static int acpi_bind_one(struct device *
 	}
 	dev->archdata.acpi_handle = handle;
 
+	status = acpi_bus_get_device(handle, &acpi_dev);
+	if (!ACPI_FAILURE(status)) {
+		int ret;
+
+		ret = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
+				"firmware_node");
+		if (ret != 0)
+			pr_debug(PREFIX "Can't create %s link for %s\n",
+				"firmware_node", dev->bus_id);
+
+		ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
+				"physical_node");
+		if (ret != 0)
+			pr_debug(PREFIX "Can't create %s link for %s\n",
+				"physical_node", acpi_dev->dev.bus_id);
+	}
+
 	return 0;
 }
 
@@ -165,8 +183,17 @@ static int acpi_unbind_one(struct device
 	if (!dev->archdata.acpi_handle)
 		return 0;
 	if (dev == acpi_get_physical_device(dev->archdata.acpi_handle)) {
+		struct acpi_device *acpi_dev;
+
 		/* acpi_get_physical_device increase refcnt by one */
 		put_device(dev);
+
+		if (!acpi_bus_get_device(dev->archdata.acpi_handle,
+					&acpi_dev)) {
+			sysfs_remove_link(&dev->kobj, "firmware_node");
+			sysfs_remove_link(&acpi_dev->dev.kobj, "physical_node");
+		}
+
 		acpi_detach_data(dev->archdata.acpi_handle,
 				 acpi_glue_data_handler);
 		dev->archdata.acpi_handle = NULL;
#14 lore raw
In reply to Zhang, Rui
Quoted 10 lines · Rui
Quoted 8 lines

+       if (!ACPI_FAILURE(status)) {
+               int ret;
+
+               ret = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
+                               "firmware_node");
+               ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
+                               "physical_node");
+       }

ret is not needed here...

But what compiler warnings do you see when you omit it? :)