libattr: remove libattr because it is clashing with udev/attr and is not used by...
[openembedded.git] / recipes / linux / linux-efika-2.6.20 / 0015-powerpc-Add-a-unified-uevent-handler-for-bus-based-on-of_device.txt
blob6de1fd28f8006b7a96248653c084d56b8ab909b9
1 From 90dc591d4c897c7a49191888c1e4d413cc08b8b7 Mon Sep 17 00:00:00 2001
2 From: Sylvain Munaut <tnt@246tNt.com>
3 Date: Sat, 23 Dec 2006 23:08:56 +0100
4 Subject: [PATCH] [PATCH] powerpc: Add a unified uevent handler for bus based on of_device
6 This common uevent handler allow the several bus types based on
7 of_device to generate the uevent properly and avoiding
8 code duplication.
10 This handlers take a struct device as argument and can therefore
11 be used as the uevent call directly if no special treatment is
12 needed for the bus.
14 Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
15 ---
16  arch/powerpc/kernel/of_device.c |   66 +++++++++++++++++++++++++++++++++++++++
17  include/asm-powerpc/of_device.h |    3 ++
18  2 files changed, 69 insertions(+), 0 deletions(-)
20 diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c
21 index e921514..ac024ad 100644
22 --- a/arch/powerpc/kernel/of_device.c
23 +++ b/arch/powerpc/kernel/of_device.c
24 @@ -120,6 +120,71 @@ void of_device_unregister(struct of_device *ofdev)
25  }
28 +int of_device_uevent(struct device *dev,
29 +               char **envp, int num_envp, char *buffer, int buffer_size)
31 +       struct of_device *ofdev;
32 +       const char *compat;
33 +       char *compat2;
34 +       char compat_buf[128];   /* need to be size of 'compatible' */
35 +       int i = 0, length = 0, seen = 0, cplen, sl;
37 +       if (!dev)
38 +               return -ENODEV;
40 +       ofdev = to_of_device(dev);
42 +       if (add_uevent_var(envp, num_envp, &i,
43 +                          buffer, buffer_size, &length,
44 +                          "OF_NAME=%s", ofdev->node->name))
45 +               return -ENOMEM;
47 +       if (add_uevent_var(envp, num_envp, &i,
48 +                          buffer, buffer_size, &length,
49 +                          "OF_TYPE=%s", ofdev->node->type))
50 +               return -ENOMEM;
52 +        /* Since the compatible field can contain pretty much anything
53 +         * it's not really legal to split it out with commas. We split it
54 +         * up using a number of environment variables instead. */
56 +       compat = get_property(ofdev->node, "compatible", &cplen);
57 +       compat2 = compat_buf;
58 +       if (compat)
59 +               memcpy(compat2, compat, cplen);
60 +       while (compat && *compat && cplen > 0) {
61 +               if (add_uevent_var(envp, num_envp, &i,
62 +                                  buffer, buffer_size, &length,
63 +                                  "OF_COMPATIBLE_%d=%s", seen, compat))
64 +                       return -ENOMEM;
66 +               sl = strlen (compat) + 1;
67 +               compat += sl;
68 +               compat2 += sl;
69 +               cplen -= sl;
70 +               seen++;
71 +               compat2[-1] = 'C'; 
72 +       }
73 +       compat2[seen?-1:0] = 0;
75 +       if (add_uevent_var(envp, num_envp, &i,
76 +                          buffer, buffer_size, &length,
77 +                          "OF_COMPATIBLE_N=%d", seen))
78 +               return -ENOMEM;
80 +       if (add_uevent_var(envp, num_envp, &i,
81 +                          buffer, buffer_size, &length,
82 +                          "MODALIAS=of:N%sT%sC%s",
83 +                          ofdev->node->name, ofdev->node->type,
84 +                          compat_buf))
85 +               return -ENOMEM;
87 +       envp[i] = NULL;
89 +       return 0;
93  EXPORT_SYMBOL(of_match_node);
94  EXPORT_SYMBOL(of_match_device);
95  EXPORT_SYMBOL(of_device_register);
96 @@ -127,3 +192,4 @@ EXPORT_SYMBOL(of_device_unregister);
97  EXPORT_SYMBOL(of_dev_get);
98  EXPORT_SYMBOL(of_dev_put);
99  EXPORT_SYMBOL(of_release_dev);
100 +EXPORT_SYMBOL(of_device_uevent);
101 diff --git a/include/asm-powerpc/of_device.h b/include/asm-powerpc/of_device.h
102 index a889b20..4f1aabe 100644
103 --- a/include/asm-powerpc/of_device.h
104 +++ b/include/asm-powerpc/of_device.h
105 @@ -32,5 +32,8 @@ extern int of_device_register(struct of_device *ofdev);
106  extern void of_device_unregister(struct of_device *ofdev);
107  extern void of_release_dev(struct device *dev);
109 +extern int of_device_uevent(struct device *dev,
110 +       char **envp, int num_envp, char *buffer, int buffer_size);
112  #endif /* __KERNEL__ */
113  #endif /* _ASM_POWERPC_OF_DEVICE_H */
114 -- 
115 1.4.4.2