From: Sylvain Munaut <tnt@246tNt.com>
To: Paul Mackerras <paulus@samba.org>
Cc: Sylvain Munaut <tnt@246tNt.com>,
Linux PPC Devel <linuxppc-dev@ozlabs.org>
Subject: [PATCH 2/2] powerpc: Add support for uevent to of_platform
Date: Sun, 17 Dec 2006 17:51:17 +0100 [thread overview]
Message-ID: <11663742803872-git-send-email-tnt@246tNt.com> (raw)
In-Reply-To: <1166374279262-git-send-email-tnt@246tNt.com>
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
next prev parent reply other threads:[~2006-12-17 16:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Sylvain Munaut [this message]
2006-12-17 23:04 ` [PATCH 0/3] uevents handler for macio & of_platform Arnd Bergmann
2006-12-18 7:16 ` Sylvain Munaut
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11663742803872-git-send-email-tnt@246tNt.com \
--to=tnt@246tnt.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).