From: Sylvain Munaut <tnt@246tNt.com>
To: Paul Mackerras <paulus@samba.org>
Cc: Sylvain Munaut <tnt@246tNt.com>, Arnd Bergmann <arnd@arndb.de>,
Linux PPC Devel <linuxppc-dev@ozlabs.org>
Subject: [PATCH 1/4] powerpc: Add a unified uevent handler for bus based on of_device
Date: Mon, 18 Dec 2006 23:46:36 +0100 [thread overview]
Message-ID: <1166482000535-git-send-email-tnt@246tNt.com> (raw)
In-Reply-To: <1166481999359-git-send-email-tnt@246tNt.com>
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
next prev parent reply other threads:[~2006-12-18 22:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-18 22:46 [PATCH 0/3] uevents handler for macio & of_platform Sylvain Munaut
2006-12-18 22:46 ` Sylvain Munaut [this message]
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
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=1166482000535-git-send-email-tnt@246tNt.com \
--to=tnt@246tnt.com \
--cc=arnd@arndb.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.