[PATCH 0/3] uevents handler for macio & of_platform

STALE7219d

Revision v1 of 2 in this series.

7 messages, 2 authors, 2006-12-18 · open the first message on its own page

[PATCH 0/3] uevents handler for macio & of_platform

From: Sylvain Munaut <hidden>
Date: 2006-12-18 22:48:08

Hi everyone,

Same goal as the previous version : provide uvent handler where needed.

This version place the core of the code in of_device.c and then
each bus type just need a small stub and call the generic function.

Again, of_platform hook tested on the efika.
I hope this one is the good take ;)

        Sylvain

[PATCH 2/4] macintosh: Use the new of_device common uevent handler

From: Sylvain Munaut <hidden>
Date: 2006-12-18 22:48:07

The generation of the uevent is now common to all bus using
of_device.

Signed-off-by: Sylvain Munaut <redacted>
---
 drivers/macintosh/macio_asic.c |   81 ----------------------------------------
 1 files changed, 1 insertions(+), 80 deletions(-)
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index d562160..767ad00 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -139,11 +139,6 @@ static int macio_uevent(struct device *d
 {
 	struct macio_dev * macio_dev;
 	struct of_device * of;
-	char *scratch;
-	const char *compat, *compat2;
-
-	int i = 0;
-	int length, cplen, cplen2, seen = 0;
 
 	if (!dev)
 		return -ENODEV;
@@ -153,81 +148,7 @@ static int macio_uevent(struct device *d
 		return -ENODEV;
 
 	of = &macio_dev->ofdev;
-
-	/* stuff we want to pass to /sbin/hotplug */
-	envp[i++] = scratch = buffer;
-	length = scnprintf (scratch, buffer_size, "OF_NAME=%s", of->node->name);
-	++length;
-	buffer_size -= length;
-	if ((buffer_size <= 0) || (i >= num_envp))
-		return -ENOMEM;
-	scratch += length;
-
-	envp[i++] = scratch;
-	length = scnprintf (scratch, buffer_size, "OF_TYPE=%s", of->node->type);
-	++length;
-	buffer_size -= length;
-	if ((buffer_size <= 0) || (i >= num_envp))
-		return -ENOMEM;
-	scratch += length;
-
-        /* Since the compatible field can contain pretty much anything
-         * it's not really legal to split it out with commas. We split it
-         * up using a number of environment variables instead. */
-
-	compat = get_property(of->node, "compatible", &cplen);
-	compat2 = compat;
-	cplen2= cplen;
-	while (compat && cplen > 0) {
-                envp[i++] = scratch;
-		length = scnprintf (scratch, buffer_size,
-		                     "OF_COMPATIBLE_%d=%s", seen, compat);
-		++length;
-		buffer_size -= length;
-		if ((buffer_size <= 0) || (i >= num_envp))
-			return -ENOMEM;
-		scratch += length;
-		length = strlen (compat) + 1;
-		compat += length;
-		cplen -= length;
-		seen++;
-	}
-
-	envp[i++] = scratch;
-	length = scnprintf (scratch, buffer_size, "OF_COMPATIBLE_N=%d", seen);
-	++length;
-	buffer_size -= length;
-	if ((buffer_size <= 0) || (i >= num_envp))
-		return -ENOMEM;
-	scratch += length;
-
-	envp[i++] = scratch;
-	length = scnprintf (scratch, buffer_size, "MODALIAS=of:N%sT%s",
-			of->node->name, of->node->type);
-	/* overwrite '\0' */
-	buffer_size -= length;
-	if ((buffer_size <= 0) || (i >= num_envp))
-		return -ENOMEM;
-	scratch += length;
-
-	if (!compat2) {
-		compat2 = "";
-		cplen2 = 1;
-	}
-	while (cplen2 > 0) {
-		length = snprintf (scratch, buffer_size, "C%s", compat2);
-		buffer_size -= length;
-		if (buffer_size <= 0)
-			return -ENOMEM;
-		scratch += length;
-		length = strlen (compat2) + 1;
-		compat2 += length;
-		cplen2 -= length;
-	}
-
-	envp[i] = NULL;
-
-	return 0;
+	return of_device_uevent(of, envp, num_envp, buffer, buffer_size);
 }
 
 extern struct device_attribute macio_dev_attrs[];
-- 
1.4.2

[PATCH 3/4] powerpc: Add uevent handler for of_platform_bus

From: Sylvain Munaut <hidden>
Date: 2006-12-18 22:48:07

Adding this handler allow userspace to properly handle the module
autoloading. The generation of the uevent itself is now common to
all bus using of_device, so not much code here.

Signed-off-by: Sylvain Munaut <redacted>
---
 arch/powerpc/kernel/of_platform.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/arch/powerpc/kernel/of_platform.c b/arch/powerpc/kernel/of_platform.c
index 3002ea3..ce40dd5 100644
--- a/arch/powerpc/kernel/of_platform.c
+++ b/arch/powerpc/kernel/of_platform.c
@@ -73,6 +73,18 @@ static int of_platform_bus_match(struct 
 	return of_match_device(matches, of_dev) != NULL;
 }
 
+static int of_platform_device_uevent(struct device *dev,
+		char **envp, int num_envp, char *buffer, int buffer_size)
+{
+	struct of_device *of;
+
+	if (!dev)
+		return -ENODEV;
+
+	of = to_of_device(dev);
+	return of_device_uevent(of, envp, num_envp, buffer, buffer_size);
+}
+
 static int of_platform_device_probe(struct device *dev)
 {
 	int error = -ENODEV;
@@ -132,6 +144,7 @@ static int of_platform_device_resume(str
 struct bus_type of_platform_bus_type = {
        .name	= "of_platform",
        .match	= of_platform_bus_match,
+       .uevent	= of_platform_device_uevent,
        .probe	= of_platform_device_probe,
        .remove	= of_platform_device_remove,
        .suspend	= of_platform_device_suspend,
-- 
1.4.2

[PATCH 1/4] powerpc: Add a unified uevent handler for bus based on of_device

From: Sylvain Munaut <hidden>
Date: 2006-12-18 22:48:08

This common uevent handler allow the several bus types based on
of_device to generate the uevent properly and avoiding
code duplication.

Signed-off-by: Sylvain Munaut <redacted>
---
 arch/powerpc/kernel/of_device.c |   63 +++++++++++++++++++++++++++++++++++++++
 include/asm-powerpc/of_device.h |    3 ++
 2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c
index e921514..a7e3a5f 100644
--- a/arch/powerpc/kernel/of_device.c
+++ b/arch/powerpc/kernel/of_device.c
@@ -120,6 +120,68 @@ void of_device_unregister(struct of_devi
 }
 
 
+int of_device_uevent(struct of_device *ofdev,
+		char **envp, int num_envp, char *buffer, int buffer_size)
+{
+	const char *compat;
+	char *compat2;
+	char compat_buf[128];   /* need to be size of 'compatible' */
+	int i = 0, length = 0, seen = 0, cplen, sl;
+
+	if (!ofdev)
+		return -ENODEV;
+
+	if (add_uevent_var(envp, num_envp, &i,
+			   buffer, buffer_size, &length,
+			   "OF_NAME=%s", ofdev->node->name))
+		return -ENOMEM;
+
+	if (add_uevent_var(envp, num_envp, &i,
+			   buffer, buffer_size, &length,
+			   "OF_TYPE=%s", ofdev->node->type))
+		return -ENOMEM;
+
+        /* Since the compatible field can contain pretty much anything
+         * it's not really legal to split it out with commas. We split it
+         * up using a number of environment variables instead. */
+
+	compat = get_property(ofdev->node, "compatible", &cplen);
+	compat2 = compat_buf;
+	if (compat)
+		memcpy(compat2, compat, cplen);
+	while (compat && *compat && cplen > 0) {
+		if (add_uevent_var(envp, num_envp, &i,
+				   buffer, buffer_size, &length,
+				   "OF_COMPATIBLE_%d=%s", seen, compat))
+			return -ENOMEM;
+
+		sl = strlen (compat) + 1;
+		compat += sl;
+		compat2 += sl;
+		cplen -= sl;
+		seen++;
+		compat2[-1] = 'C'; 
+	}
+	compat2[seen?-1:0] = 0;
+
+	if (add_uevent_var(envp, num_envp, &i,
+			   buffer, buffer_size, &length,
+			   "OF_COMPATIBLE_N=%d", seen))
+		return -ENOMEM;
+
+	if (add_uevent_var(envp, num_envp, &i,
+			   buffer, buffer_size, &length,
+			   "MODALIAS=of:N%sT%sC%s",
+			   ofdev->node->name, ofdev->node->type,
+			   compat_buf))
+		return -ENOMEM;
+
+	envp[i] = NULL;
+
+	return 0;
+}
+
+
 EXPORT_SYMBOL(of_match_node);
 EXPORT_SYMBOL(of_match_device);
 EXPORT_SYMBOL(of_device_register);
@@ -127,3 +189,4 @@ EXPORT_SYMBOL(of_device_unregister);
 EXPORT_SYMBOL(of_dev_get);
 EXPORT_SYMBOL(of_dev_put);
 EXPORT_SYMBOL(of_release_dev);
+EXPORT_SYMBOL(of_device_uevent);
diff --git a/include/asm-powerpc/of_device.h b/include/asm-powerpc/of_device.h
index a889b20..caf0619 100644
--- a/include/asm-powerpc/of_device.h
+++ b/include/asm-powerpc/of_device.h
@@ -32,5 +32,8 @@ extern int of_device_register(struct of_
 extern void of_device_unregister(struct of_device *ofdev);
 extern void of_release_dev(struct device *dev);
 
+extern int of_device_uevent(struct of_device *ofdev,
+	char **envp, int num_envp, char *buffer, int buffer_size);
+
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_OF_DEVICE_H */
-- 
1.4.2

[PATCH 4/4] powerpc: Add uevent handler for ibmebus

From: Sylvain Munaut <hidden>
Date: 2006-12-18 22:48:13

Adding this handler allow userspace to properly handle the module
autoloading. The generation of the uevent itself is now common to
all bus using of_device, so not much code here.

Signed-off-by: Sylvain Munaut <redacted>
---
 arch/powerpc/kernel/ibmebus.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
index 82bd2f1..5a42100 100644
--- a/arch/powerpc/kernel/ibmebus.c
+++ b/arch/powerpc/kernel/ibmebus.c
@@ -361,9 +361,27 @@ static int ibmebus_bus_match(struct devi
 	return 0;
 }
 
+static int ibmebus_bus_uevent(struct device *dev,
+		char **envp, int num_envp, char *buffer, int buffer_size)
+{
+	struct ibmebus_dev *ebus_dev;
+	struct of_device *of;
+
+	if (!dev)
+		return -ENODEV;
+
+	ebus_dev = to_ibmebus_dev(dev);
+	if (!ebus_dev)
+		return -ENODEV;
+
+	of = &ebus_dev->ofdev;
+	return of_device_uevent(of, envp, num_envp, buffer, buffer_size);
+}
+
 struct bus_type ibmebus_bus_type = {
 	.name = "ibmebus",
 	.match = ibmebus_bus_match,
+	.uevent = ibmebus_bus_uevent,
 };
 EXPORT_SYMBOL(ibmebus_bus_type);
 
-- 
1.4.2

Re: [PATCH 4/4] powerpc: Add uevent handler for ibmebus

From: Arnd Bergmann <arnd@arndb.de>
Date: 2006-12-18 23:03:45

T24gTW9uZGF5IDE4IERlY2VtYmVyIDIwMDYgMjM6NDYsIFN5bHZhaW4gTXVuYXV0IHdyb3RlOgo+
ICugoKCgoKCgc3RydWN0IGlibWVidXNfZGV2ICplYnVzX2RldjsKPiAroKCgoKCgoHN0cnVjdCBv
Zl9kZXZpY2UgKm9mOwo+ICsKPiAroKCgoKCgoGlmICghZGV2KQo+ICugoKCgoKCgoKCgoKCgoKBy
ZXR1cm4gLUVOT0RFVjsKPiArCj4gK6CgoKCgoKBlYnVzX2RldiA9IHRvX2libWVidXNfZGV2KGRl
dik7Cj4gK6CgoKCgoKBpZiAoIWVidXNfZGV2KQo+ICugoKCgoKCgoKCgoKCgoKByZXR1cm4gLUVO
T0RFVjsKPiArCj4gK6CgoKCgoKBvZiA9ICZlYnVzX2Rldi0+b2ZkZXY7CgpUaGlzIGNhbiBiZSBz
aG9ydGVuZWQgdG8gCgoJb2YgPSB0b19vZl9kZXZpY2UoZGV2KTsKCldpdGggdGhhdCBjb2RlIGlu
IHBsYWNlLCB0aGlzIGZ1bmN0aW9uIGlzIGlkZW50aWNhbCB0byB0aG9zZQpmb3IgbWFjaW8gYW5k
IG9mX3BsYXRmb3JtX2RldmljZSwgYW5kIHlvdSBjYW4gY29sbGFwc2UgdGhlbQphbGwgaW50byBv
Zl9kZXZpY2VfdWV2ZW50LgoKCUFybmQgPD48Cg==

Re: [PATCH 4/4] powerpc: Add uevent handler for ibmebus

From: Sylvain Munaut <hidden>
Date: 2006-12-18 23:10:55

Arnd Bergmann wrote:
On Monday 18 December 2006 23:46, Sylvain Munaut wrote:
  
quoted
+       struct ibmebus_dev *ebus_dev;
+       struct of_device *of;
+
+       if (!dev)
+               return -ENODEV;
+
+       ebus_dev = to_ibmebus_dev(dev);
+       if (!ebus_dev)
+               return -ENODEV;
+
+       of = &ebus_dev->ofdev;
    
This can be shortened to 

	of = to_of_device(dev);

With that code in place, this function is identical to those
for macio and of_platform_device, and you can collapse them
all into of_device_uevent.

	Arnd <><
  
Right, damn I missed that. Not too used to the whole "to_..." stuff.
I'll wait a little in case someone has other comments, and I'll resubmit
in a single patch (unless you really want me to separate in 4 patch, 2
of those
being one liners ...)


    Sylvain
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help