* [PATCH 0/3] uevents handler for macio & of_platform @ 2006-12-17 16:51 Sylvain Munaut 2006-12-17 16:51 ` [PATCH 1/2] macintosh: tidy up uevent handler by using add_uevent_var Sylvain Munaut 2006-12-17 23:04 ` [PATCH 0/3] uevents handler for macio & of_platform Arnd Bergmann 0 siblings, 2 replies; 5+ messages in thread From: Sylvain Munaut @ 2006-12-17 16:51 UTC (permalink / raw) To: Paul Mackerras; +Cc: Linux PPC Devel Hi Paul, Hi Ben, and Hi everyone ;) This couple of patch is a rework of the uevent handler in macio and of_platform. For macio, it was present but not using the latest helper that makes the code more readable. The of_platform one is new (no uevent support in of_platform before) but is basically the same code as the macio one. The of_platform one has been tested on Efika and enable module autoloading by udev. The macio patch is not tested. However, being based on the same code as the of_platform handler I would excpect it to be fine. Sylvain PS: The previous one I sent a few weeks back were buggy, theses are new ones ;) ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] macintosh: tidy up uevent handler by using add_uevent_var 2006-12-17 16:51 [PATCH 0/3] uevents handler for macio & of_platform Sylvain Munaut @ 2006-12-17 16:51 ` Sylvain Munaut 2006-12-17 16:51 ` [PATCH 2/2] powerpc: Add support for uevent to of_platform Sylvain Munaut 2006-12-17 23:04 ` [PATCH 0/3] uevents handler for macio & of_platform Arnd Bergmann 1 sibling, 1 reply; 5+ messages in thread From: Sylvain Munaut @ 2006-12-17 16:51 UTC (permalink / raw) To: Paul Mackerras; +Cc: Sylvain Munaut, Linux PPC Devel This add_uevent_var helper is specifically there for that task and that makes the code more readable. Signed-off-by: Sylvain Munaut <tnt@246tNt.com> --- drivers/macintosh/macio_asic.c | 92 +++++++++++++++------------------------- 1 files changed, 34 insertions(+), 58 deletions(-) diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c index d562160..3d83d6c 100644 --- a/drivers/macintosh/macio_asic.c +++ b/drivers/macintosh/macio_asic.c @@ -139,11 +139,12 @@ static int macio_uevent(struct device *d { struct macio_dev * macio_dev; struct of_device * of; - char *scratch; - const char *compat, *compat2; + const char *compat; + char *compat2; + char compat_buf[128]; /* need to be size of 'compatible' */ int i = 0; - int length, cplen, cplen2, seen = 0; + int length = 0, cplen, sl, seen = 0; if (!dev) return -ENODEV; @@ -155,75 +156,50 @@ static int macio_uevent(struct device *d 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)) + if (add_uevent_var(envp, num_envp, &i, + buffer, buffer_size, &length, + "OF_NAME=%s", of->node->name)) 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)) + if (add_uevent_var(envp, num_envp, &i, + buffer, buffer_size, &length, + "OF_TYPE=%s", of->node->type)) 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)) + 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; - scratch += length; - length = strlen (compat) + 1; - compat += length; - cplen -= length; + + sl = strlen (compat) + 1; + compat += sl; + compat2 += sl; + cplen -= sl; seen++; + compat2[-1] = 'C'; } + compat2[seen?-1:0] = 0; - 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)) + if (add_uevent_var(envp, num_envp, &i, + buffer, buffer_size, &length, + "OF_COMPATIBLE_N=%d", seen)) 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; - } + if (add_uevent_var(envp, num_envp, &i, + buffer, buffer_size, &length, + "MODALIAS=of:N%sT%sC%s", + of->node->name, of->node->type, + compat_buf)) + return -ENOMEM; envp[i] = NULL; @@ -235,7 +211,7 @@ extern struct device_attribute macio_dev struct bus_type macio_bus_type = { .name = "macio", .match = macio_bus_match, - .uevent = macio_uevent, + .uevent = macio_uevent, .probe = macio_device_probe, .remove = macio_device_remove, .shutdown = macio_device_shutdown, -- 1.4.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] powerpc: Add support for uevent to of_platform 2006-12-17 16:51 ` [PATCH 1/2] macintosh: tidy up uevent handler by using add_uevent_var Sylvain Munaut @ 2006-12-17 16:51 ` Sylvain Munaut 0 siblings, 0 replies; 5+ messages in thread From: Sylvain Munaut @ 2006-12-17 16:51 UTC (permalink / raw) To: Paul Mackerras; +Cc: Sylvain Munaut, Linux PPC Devel This adds a proper uevent handler to the of_platform bus. This allows autoloading of modules (or at least should ;). It's _heavily_ based on the macio counterpart. Signed-off-by: Sylvain Munaut <tnt@246tNt.com> --- arch/powerpc/kernel/of_platform.c | 70 +++++++++++++++++++++++++++++++++++++ 1 files changed, 70 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/kernel/of_platform.c b/arch/powerpc/kernel/of_platform.c index 3002ea3..30ae365 100644 --- a/arch/powerpc/kernel/of_platform.c +++ b/arch/powerpc/kernel/of_platform.c @@ -73,6 +73,75 @@ static int of_platform_bus_match(struct return of_match_device(matches, of_dev) != NULL; } +static int of_platform_uevent(struct device *dev, char **envp, int num_envp, + char *buffer, int buffer_size) +{ + struct of_device *of; + const char *compat; + char *compat2; + char compat_buf[128]; /* need to be size of 'compatible' */ + + int i = 0; + int length = 0, cplen, sl, seen = 0; + + if (!dev) + return -ENODEV; + + of = to_of_device(dev); + if (!of) + return -ENODEV; + + /* stuff we want to pass to /sbin/hotplug */ + if (add_uevent_var(envp, num_envp, &i, + buffer, buffer_size, &length, + "OF_NAME=%s", of->node->name)) + return -ENOMEM; + + if (add_uevent_var(envp, num_envp, &i, + buffer, buffer_size, &length, + "OF_TYPE=%s", of->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(of->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", + of->node->name, of->node->type, + compat_buf)) + return -ENOMEM; + + envp[i] = NULL; + + return 0; +} + static int of_platform_device_probe(struct device *dev) { int error = -ENODEV; @@ -132,6 +201,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_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] 5+ messages in thread
* Re: [PATCH 0/3] uevents handler for macio & of_platform 2006-12-17 16:51 [PATCH 0/3] uevents handler for macio & of_platform Sylvain Munaut 2006-12-17 16:51 ` [PATCH 1/2] macintosh: tidy up uevent handler by using add_uevent_var Sylvain Munaut @ 2006-12-17 23:04 ` Arnd Bergmann 2006-12-18 7:16 ` Sylvain Munaut 1 sibling, 1 reply; 5+ messages in thread From: Arnd Bergmann @ 2006-12-17 23:04 UTC (permalink / raw) To: linuxppc-dev; +Cc: Paul Mackerras On Sunday 17 December 2006 17:51, Sylvain Munaut wrote: > The of_platform one has been tested on Efika and enable module > autoloading by udev. The macio patch is not tested. However, > being based on the same code as the of_platform handler I would > excpect it to be fine. Would it be possible to have only a single copy of that code, for all of_device probes? I guess the same code also will be used on ibmebus and the ps3platform bus eventually. Arnd <>< ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] uevents handler for macio & of_platform 2006-12-17 23:04 ` [PATCH 0/3] uevents handler for macio & of_platform Arnd Bergmann @ 2006-12-18 7:16 ` Sylvain Munaut 0 siblings, 0 replies; 5+ messages in thread From: Sylvain Munaut @ 2006-12-18 7:16 UTC (permalink / raw) To: Arnd Bergmann; +Cc: linuxppc-dev, Paul Mackerras Arnd Bergmann wrote: > On Sunday 17 December 2006 17:51, Sylvain Munaut wrote: > >> The of_platform one has been tested on Efika and enable module >> autoloading by udev. The macio patch is not tested. However, >> being based on the same code as the of_platform handler I would >> excpect it to be fine. >> > > Would it be possible to have only a single copy of that code, > for all of_device probes? I guess the same code also will be > used on ibmebus and the ps3platform bus eventually. > Mmmh. Yes actually, I could put that code in of_device.c and export it, then in each bus, you would only need a small stub to handle the conversion to of_device * and call the common code. I'll do that and resend. Sylvain ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-12-18 7:18 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-12-17 16:51 [PATCH 0/3] uevents handler for macio & of_platform Sylvain Munaut 2006-12-17 16:51 ` [PATCH 1/2] macintosh: tidy up uevent handler by using add_uevent_var Sylvain Munaut 2006-12-17 16:51 ` [PATCH 2/2] powerpc: Add support for uevent to of_platform Sylvain Munaut 2006-12-17 23:04 ` [PATCH 0/3] uevents handler for macio & of_platform Arnd Bergmann 2006-12-18 7:16 ` 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).