Skip to contentSkip to conversation

uevents handler for macio & of_platform

PATCH New Sylvain Munaut 2 participants 7 messages Dec 18, 2006

Subsystems (2)
lore
Share & tools
lore
#2 lore raw

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

In reply to Sylvain Munaut

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

---
 drivers/macintosh/macio_asic.c |   81 ----------------------------------------
 1 files changed, 1 insertions(+), 80 deletions(-)
drivers/macintosh/macio_asic.c +1 -80
index d562160..767ad00 100644
@@ -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[];
Signature · 1 line
1.4.2
#3 lore raw

PATCH 3/4 powerpc: Add uevent handler for of_platform_bus

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.

---
 arch/powerpc/kernel/of_platform.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
arch/powerpc/kernel/of_platform.c +13 -0
index 3002ea3..ce40dd5 100644
@@ -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,
Signature · 1 line
1.4.2
#0 lore raw

cover uevents handler for macio & of_platform

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

#1 lore raw

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

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

---
 arch/powerpc/kernel/of_device.c |   63 +++++++++++++++++++++++++++++++++++++++
 include/asm-powerpc/of_device.h |    3 ++
 2 files changed, 66 insertions(+), 0 deletions(-)
arch/powerpc/kernel/of_device.c +63 -0
index e921514..a7e3a5f 100644
@@ -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);
include/asm-powerpc/of_device.h +3 -0
index a889b20..caf0619 100644
@@ -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 */
Signature · 1 line
1.4.2
#4 lore raw

PATCH 4/4 powerpc: Add uevent handler for ibmebus

In reply to Sylvain Munaut

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.

---
 arch/powerpc/kernel/ibmebus.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
arch/powerpc/kernel/ibmebus.c +18 -0
index 82bd2f1..5a42100 100644
@@ -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);
 
Signature · 1 line
1.4.2
#5 lore raw

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

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

#6 lore raw

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

Quoted 17 lines · Arnd Bergmann

arch/powerpc/kernel/ibmebus.c static int ibmebus_bus_match(struct devi · line 377

Quoted 12 lines · Sylvain Munaut
arch/powerpc/kernel/ibmebus.c +11 -0
+       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

Quoted 8 lines
	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