aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/macintosh
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2005-07-06 15:45:09 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-06 15:55:20 -0400
commit184f6eb8c46afc2a4aa6cb7c51ebc423c36d9c9d (patch)
treee32c7dac4947a252f6e17e62db37ca0e4d5fdf9c /drivers/macintosh
parentb5bf5b6786ccfc9e0c8801291f463d92c8e0b423 (diff)
[PATCH] openfirmware: implement hotplug for macio devices
This adds the hotplug routine for generating hotplug events when devices are seen on the macio bus. It uses the attributed created by the sysfs nodes to generate the hotplug environment vars for userspace. Since the characters allowed inside the 'compatible' field are NUL terminated, they are exported as individual OF_COMPATIBLE_# variables, with OF_COMPATIBLE_N maintaining a count of how many there are. In order for hotplug to work with macio devices, patches to module-init-tools and hotplug must be applied. Those patches are available at: ftp://ftp.suse.com/pub/people/jeffm/linux/macio-hotplug/ Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r--drivers/macintosh/macio_asic.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 7fa369cfcceb..1ee003346923 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -126,11 +126,82 @@ static int macio_device_resume(struct device * dev)
126 return 0; 126 return 0;
127} 127}
128 128
129static int macio_hotplug (struct device *dev, char **envp, int num_envp,
130 char *buffer, int buffer_size)
131{
132 struct macio_dev * macio_dev;
133 struct of_device * of;
134 char *scratch, *compat;
135 int i = 0;
136 int length = 0;
137 int cplen, seen = 0;
138
139 if (!dev)
140 return -ENODEV;
141
142 macio_dev = to_macio_device(dev);
143 if (!macio_dev)
144 return -ENODEV;
145
146 of = &macio_dev->ofdev;
147 scratch = buffer;
148
149 /* stuff we want to pass to /sbin/hotplug */
150 envp[i++] = scratch;
151 length += scnprintf (scratch, buffer_size - length, "OF_NAME=%s",
152 of->node->name);
153 if ((buffer_size - length <= 0) || (i >= num_envp))
154 return -ENOMEM;
155 ++length;
156 scratch += length;
157
158 envp[i++] = scratch;
159 length += scnprintf (scratch, buffer_size - length, "OF_TYPE=%s",
160 of->node->type);
161 if ((buffer_size - length <= 0) || (i >= num_envp))
162 return -ENOMEM;
163 ++length;
164 scratch += length;
165
166 /* Since the compatible field can contain pretty much anything
167 * it's not really legal to split it out with commas. We split it
168 * up using a number of environment variables instead. */
169
170 compat = (char *) get_property(of->node, "compatible", &cplen);
171 while (compat && cplen > 0) {
172 int l;
173 envp[i++] = scratch;
174 length += scnprintf (scratch, buffer_size - length,
175 "OF_COMPATIBLE_%d=%s", seen, compat);
176 if ((buffer_size - length <= 0) || (i >= num_envp))
177 return -ENOMEM;
178 length++;
179 scratch += length;
180 l = strlen (compat) + 1;
181 compat += l;
182 cplen -= l;
183 seen++;
184 }
185
186 envp[i++] = scratch;
187 length += scnprintf (scratch, buffer_size - length,
188 "OF_COMPATIBLE_N=%d", seen);
189 if ((buffer_size - length <= 0) || (i >= num_envp))
190 return -ENOMEM;
191 ++length;
192 scratch += length;
193
194 envp[i] = NULL;
195
196 return 0;
197}
198
129extern struct device_attribute macio_dev_attrs[]; 199extern struct device_attribute macio_dev_attrs[];
130 200
131struct bus_type macio_bus_type = { 201struct bus_type macio_bus_type = {
132 .name = "macio", 202 .name = "macio",
133 .match = macio_bus_match, 203 .match = macio_bus_match,
204 .hotplug = macio_hotplug,
134 .suspend = macio_device_suspend, 205 .suspend = macio_device_suspend,
135 .resume = macio_device_resume, 206 .resume = macio_device_resume,
136 .dev_attrs = macio_dev_attrs, 207 .dev_attrs = macio_dev_attrs,