* [PATCH 0/3] uevents handler for macio & of_platform
@ 2006-12-18 22:46 Sylvain Munaut
2006-12-18 22:46 ` [PATCH 1/4] powerpc: Add a unified uevent handler for bus based on of_device Sylvain Munaut
0 siblings, 1 reply; 7+ messages in thread
From: Sylvain Munaut @ 2006-12-18 22:46 UTC (permalink / raw)
To: Paul Mackerras; +Cc: Arnd Bergmann, Linux PPC Devel
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] powerpc: Add a unified uevent handler for bus based on of_device
2006-12-18 22:46 [PATCH 0/3] uevents handler for macio & of_platform Sylvain Munaut
@ 2006-12-18 22:46 ` Sylvain Munaut
2006-12-18 22:46 ` [PATCH 2/4] macintosh: Use the new of_device common uevent handler Sylvain Munaut
0 siblings, 1 reply; 7+ messages in thread
From: Sylvain Munaut @ 2006-12-18 22:46 UTC (permalink / raw)
To: Paul Mackerras; +Cc: Sylvain Munaut, Arnd Bergmann, Linux PPC Devel
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 <tnt@246tNt.com>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] macintosh: Use the new of_device common uevent handler
2006-12-18 22:46 ` [PATCH 1/4] powerpc: Add a unified uevent handler for bus based on of_device Sylvain Munaut
@ 2006-12-18 22:46 ` Sylvain Munaut
2006-12-18 22:46 ` [PATCH 3/4] powerpc: Add uevent handler for of_platform_bus Sylvain Munaut
0 siblings, 1 reply; 7+ messages in thread
From: Sylvain Munaut @ 2006-12-18 22:46 UTC (permalink / raw)
To: Paul Mackerras; +Cc: Sylvain Munaut, Arnd Bergmann, Linux PPC Devel
The generation of the uevent is now common to all bus using
of_device.
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] powerpc: Add uevent handler for of_platform_bus
2006-12-18 22:46 ` [PATCH 2/4] macintosh: Use the new of_device common uevent handler Sylvain Munaut
@ 2006-12-18 22:46 ` Sylvain Munaut
2006-12-18 22:46 ` [PATCH 4/4] powerpc: Add uevent handler for ibmebus Sylvain Munaut
0 siblings, 1 reply; 7+ messages in thread
From: Sylvain Munaut @ 2006-12-18 22:46 UTC (permalink / raw)
To: Paul Mackerras; +Cc: Sylvain Munaut, Arnd Bergmann, Linux PPC Devel
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 <tnt@246tNt.com>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] powerpc: Add uevent handler for ibmebus
2006-12-18 22:46 ` [PATCH 3/4] powerpc: Add uevent handler for of_platform_bus Sylvain Munaut
@ 2006-12-18 22:46 ` Sylvain Munaut
2006-12-18 23:03 ` Arnd Bergmann
0 siblings, 1 reply; 7+ messages in thread
From: Sylvain Munaut @ 2006-12-18 22:46 UTC (permalink / raw)
To: Paul Mackerras; +Cc: Sylvain Munaut, Arnd Bergmann, Linux PPC Devel
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 <tnt@246tNt.com>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 4/4] powerpc: Add uevent handler for ibmebus
2006-12-18 22:46 ` [PATCH 4/4] powerpc: Add uevent handler for ibmebus Sylvain Munaut
@ 2006-12-18 23:03 ` Arnd Bergmann
2006-12-18 23:09 ` Sylvain Munaut
0 siblings, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2006-12-18 23:03 UTC (permalink / raw)
To: Sylvain Munaut; +Cc: Paul Mackerras, Linux PPC Devel
T24gTW9uZGF5IDE4IERlY2VtYmVyIDIwMDYgMjM6NDYsIFN5bHZhaW4gTXVuYXV0IHdyb3RlOgo+
ICugoKCgoKCgc3RydWN0IGlibWVidXNfZGV2ICplYnVzX2RldjsKPiAroKCgoKCgoHN0cnVjdCBv
Zl9kZXZpY2UgKm9mOwo+ICsKPiAroKCgoKCgoGlmICghZGV2KQo+ICugoKCgoKCgoKCgoKCgoKBy
ZXR1cm4gLUVOT0RFVjsKPiArCj4gK6CgoKCgoKBlYnVzX2RldiA9IHRvX2libWVidXNfZGV2KGRl
dik7Cj4gK6CgoKCgoKBpZiAoIWVidXNfZGV2KQo+ICugoKCgoKCgoKCgoKCgoKByZXR1cm4gLUVO
T0RFVjsKPiArCj4gK6CgoKCgoKBvZiA9ICZlYnVzX2Rldi0+b2ZkZXY7CgpUaGlzIGNhbiBiZSBz
aG9ydGVuZWQgdG8gCgoJb2YgPSB0b19vZl9kZXZpY2UoZGV2KTsKCldpdGggdGhhdCBjb2RlIGlu
IHBsYWNlLCB0aGlzIGZ1bmN0aW9uIGlzIGlkZW50aWNhbCB0byB0aG9zZQpmb3IgbWFjaW8gYW5k
IG9mX3BsYXRmb3JtX2RldmljZSwgYW5kIHlvdSBjYW4gY29sbGFwc2UgdGhlbQphbGwgaW50byBv
Zl9kZXZpY2VfdWV2ZW50LgoKCUFybmQgPD48Cg==
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 4/4] powerpc: Add uevent handler for ibmebus
2006-12-18 23:03 ` Arnd Bergmann
@ 2006-12-18 23:09 ` Sylvain Munaut
0 siblings, 0 replies; 7+ messages in thread
From: Sylvain Munaut @ 2006-12-18 23:09 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Paul Mackerras, Linux PPC Devel
Arnd Bergmann wrote:
> On Monday 18 December 2006 23:46, Sylvain Munaut wrote:
>
>> + 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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-12-18 23:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-18 22:46 [PATCH 0/3] uevents handler for macio & of_platform Sylvain Munaut
2006-12-18 22:46 ` [PATCH 1/4] powerpc: Add a unified uevent handler for bus based on of_device Sylvain Munaut
2006-12-18 22:46 ` [PATCH 2/4] macintosh: Use the new of_device common uevent handler Sylvain Munaut
2006-12-18 22:46 ` [PATCH 3/4] powerpc: Add uevent handler for of_platform_bus Sylvain Munaut
2006-12-18 22:46 ` [PATCH 4/4] powerpc: Add uevent handler for ibmebus Sylvain Munaut
2006-12-18 23:03 ` Arnd Bergmann
2006-12-18 23:09 ` Sylvain Munaut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).