Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * bus.c - bus driver management |
| 3 | * |
| 4 | * Copyright (c) 2002-3 Patrick Mochel |
| 5 | * Copyright (c) 2002-3 Open Source Development Labs |
| 6 | * |
| 7 | * This file is released under the GPLv2 |
| 8 | * |
| 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/device.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/string.h> |
| 16 | #include "base.h" |
| 17 | #include "power/power.h" |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr) |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 20 | #define to_bus(obj) container_of(obj, struct bus_type_private, subsys.kobj) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * sysfs bindings for drivers |
| 24 | */ |
| 25 | |
| 26 | #define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr) |
| 27 | #define to_driver(obj) container_of(obj, struct device_driver, kobj) |
| 28 | |
| 29 | |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 30 | static int __must_check bus_rescan_devices_helper(struct device *dev, |
| 31 | void *data); |
| 32 | |
Greg Kroah-Hartman | 5901d01 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 33 | static struct bus_type *bus_get(struct bus_type *bus) |
| 34 | { |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 35 | if (bus) { |
| 36 | kset_get(&bus->p->subsys); |
| 37 | return bus; |
| 38 | } |
| 39 | return NULL; |
Greg Kroah-Hartman | 5901d01 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 42 | static void bus_put(struct bus_type *bus) |
| 43 | { |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 44 | if (bus) |
| 45 | kset_put(&bus->p->subsys); |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | static ssize_t |
| 49 | drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) |
| 50 | { |
| 51 | struct driver_attribute * drv_attr = to_drv_attr(attr); |
| 52 | struct device_driver * drv = to_driver(kobj); |
Dmitry Torokhov | 4a0c20b | 2005-04-29 01:23:47 -0500 | [diff] [blame] | 53 | ssize_t ret = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | if (drv_attr->show) |
| 56 | ret = drv_attr->show(drv, buf); |
| 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | static ssize_t |
| 61 | drv_attr_store(struct kobject * kobj, struct attribute * attr, |
| 62 | const char * buf, size_t count) |
| 63 | { |
| 64 | struct driver_attribute * drv_attr = to_drv_attr(attr); |
| 65 | struct device_driver * drv = to_driver(kobj); |
Dmitry Torokhov | 4a0c20b | 2005-04-29 01:23:47 -0500 | [diff] [blame] | 66 | ssize_t ret = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | if (drv_attr->store) |
| 69 | ret = drv_attr->store(drv, buf, count); |
| 70 | return ret; |
| 71 | } |
| 72 | |
| 73 | static struct sysfs_ops driver_sysfs_ops = { |
| 74 | .show = drv_attr_show, |
| 75 | .store = drv_attr_store, |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | static void driver_release(struct kobject * kobj) |
| 80 | { |
Greg Kroah-Hartman | 74e9f5f | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 81 | /* |
| 82 | * Yes this is an empty release function, it is this way because struct |
| 83 | * device is always a static object, not a dynamic one. Yes, this is |
| 84 | * not nice and bad, but remember, drivers are code, reference counted |
| 85 | * by the module count, not a device, which is really data. And yes, |
| 86 | * in the future I do want to have all drivers be created dynamically, |
| 87 | * and am working toward that goal, but it will take a bit longer... |
| 88 | * |
| 89 | * But do not let this example give _anyone_ the idea that they can |
| 90 | * create a release function without any code in it at all, to do that |
| 91 | * is almost always wrong. If you have any questions about this, |
| 92 | * please send an email to <greg@kroah.com> |
| 93 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Greg Kroah-Hartman | a1148fb | 2007-10-11 10:47:49 -0600 | [diff] [blame] | 96 | static struct kobj_type driver_ktype = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | .sysfs_ops = &driver_sysfs_ops, |
| 98 | .release = driver_release, |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | /* |
| 103 | * sysfs bindings for buses |
| 104 | */ |
| 105 | |
| 106 | |
| 107 | static ssize_t |
| 108 | bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) |
| 109 | { |
| 110 | struct bus_attribute * bus_attr = to_bus_attr(attr); |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 111 | struct bus_type_private *bus_priv = to_bus(kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | ssize_t ret = 0; |
| 113 | |
| 114 | if (bus_attr->show) |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 115 | ret = bus_attr->show(bus_priv->bus, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | static ssize_t |
| 120 | bus_attr_store(struct kobject * kobj, struct attribute * attr, |
| 121 | const char * buf, size_t count) |
| 122 | { |
| 123 | struct bus_attribute * bus_attr = to_bus_attr(attr); |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 124 | struct bus_type_private *bus_priv = to_bus(kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | ssize_t ret = 0; |
| 126 | |
| 127 | if (bus_attr->store) |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 128 | ret = bus_attr->store(bus_priv->bus, buf, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | static struct sysfs_ops bus_sysfs_ops = { |
| 133 | .show = bus_attr_show, |
| 134 | .store = bus_attr_store, |
| 135 | }; |
| 136 | |
| 137 | int bus_create_file(struct bus_type * bus, struct bus_attribute * attr) |
| 138 | { |
| 139 | int error; |
Greg Kroah-Hartman | 5901d01 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 140 | if (bus_get(bus)) { |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 141 | error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr); |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 142 | bus_put(bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } else |
| 144 | error = -EINVAL; |
| 145 | return error; |
| 146 | } |
| 147 | |
| 148 | void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr) |
| 149 | { |
Greg Kroah-Hartman | 5901d01 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 150 | if (bus_get(bus)) { |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 151 | sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 152 | bus_put(bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
Kay Sievers | 80f03e3 | 2007-05-26 11:21:36 +0200 | [diff] [blame] | 156 | static struct kobj_type bus_ktype = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | .sysfs_ops = &bus_sysfs_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
Kay Sievers | 80f03e3 | 2007-05-26 11:21:36 +0200 | [diff] [blame] | 160 | static int bus_uevent_filter(struct kset *kset, struct kobject *kobj) |
| 161 | { |
| 162 | struct kobj_type *ktype = get_ktype(kobj); |
| 163 | |
| 164 | if (ktype == &bus_ktype) |
| 165 | return 1; |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static struct kset_uevent_ops bus_uevent_ops = { |
| 170 | .filter = bus_uevent_filter, |
| 171 | }; |
| 172 | |
Greg Kroah-Hartman | 59a5483 | 2007-10-29 23:22:26 -0500 | [diff] [blame] | 173 | static struct kset *bus_kset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Russell King | 2139bdd | 2006-02-07 12:58:20 -0800 | [diff] [blame] | 176 | #ifdef CONFIG_HOTPLUG |
Alan Stern | 2b08c8d | 2005-11-23 15:43:50 -0800 | [diff] [blame] | 177 | /* Manually detach a device from its associated driver. */ |
Greg Kroah-Hartman | 151ef38 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 178 | static int driver_helper(struct device *dev, void *data) |
| 179 | { |
| 180 | const char *name = data; |
| 181 | |
| 182 | if (strcmp(name, dev->bus_id) == 0) |
| 183 | return 1; |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static ssize_t driver_unbind(struct device_driver *drv, |
| 188 | const char *buf, size_t count) |
| 189 | { |
Greg Kroah-Hartman | 5901d01 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 190 | struct bus_type *bus = bus_get(drv->bus); |
Greg Kroah-Hartman | 151ef38 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 191 | struct device *dev; |
| 192 | int err = -ENODEV; |
| 193 | |
| 194 | dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); |
Alan Stern | 2b08c8d | 2005-11-23 15:43:50 -0800 | [diff] [blame] | 195 | if (dev && dev->driver == drv) { |
Alan Stern | bf74ad5 | 2005-11-17 16:54:12 -0500 | [diff] [blame] | 196 | if (dev->parent) /* Needed for USB */ |
| 197 | down(&dev->parent->sem); |
Greg Kroah-Hartman | 151ef38 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 198 | device_release_driver(dev); |
Alan Stern | bf74ad5 | 2005-11-17 16:54:12 -0500 | [diff] [blame] | 199 | if (dev->parent) |
| 200 | up(&dev->parent->sem); |
Greg Kroah-Hartman | 151ef38 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 201 | err = count; |
| 202 | } |
Alan Stern | 2b08c8d | 2005-11-23 15:43:50 -0800 | [diff] [blame] | 203 | put_device(dev); |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 204 | bus_put(bus); |
Alan Stern | 2b08c8d | 2005-11-23 15:43:50 -0800 | [diff] [blame] | 205 | return err; |
Greg Kroah-Hartman | 151ef38 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 206 | } |
| 207 | static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); |
| 208 | |
Greg Kroah-Hartman | afdce75 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 209 | /* |
| 210 | * Manually attach a device to a driver. |
| 211 | * Note: the driver must want to bind to the device, |
| 212 | * it is not possible to override the driver's id table. |
| 213 | */ |
| 214 | static ssize_t driver_bind(struct device_driver *drv, |
| 215 | const char *buf, size_t count) |
| 216 | { |
Greg Kroah-Hartman | 5901d01 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 217 | struct bus_type *bus = bus_get(drv->bus); |
Greg Kroah-Hartman | afdce75 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 218 | struct device *dev; |
| 219 | int err = -ENODEV; |
| 220 | |
| 221 | dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); |
Alan Stern | 2b08c8d | 2005-11-23 15:43:50 -0800 | [diff] [blame] | 222 | if (dev && dev->driver == NULL) { |
Alan Stern | bf74ad5 | 2005-11-17 16:54:12 -0500 | [diff] [blame] | 223 | if (dev->parent) /* Needed for USB */ |
| 224 | down(&dev->parent->sem); |
Greg Kroah-Hartman | afdce75 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 225 | down(&dev->sem); |
| 226 | err = driver_probe_device(drv, dev); |
| 227 | up(&dev->sem); |
Alan Stern | bf74ad5 | 2005-11-17 16:54:12 -0500 | [diff] [blame] | 228 | if (dev->parent) |
| 229 | up(&dev->parent->sem); |
Ryan Wilson | 3722540 | 2006-03-22 16:26:25 -0500 | [diff] [blame] | 230 | |
| 231 | if (err > 0) /* success */ |
| 232 | err = count; |
| 233 | else if (err == 0) /* driver didn't accept device */ |
| 234 | err = -ENODEV; |
Greg Kroah-Hartman | afdce75 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 235 | } |
Alan Stern | 2b08c8d | 2005-11-23 15:43:50 -0800 | [diff] [blame] | 236 | put_device(dev); |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 237 | bus_put(bus); |
Alan Stern | 2b08c8d | 2005-11-23 15:43:50 -0800 | [diff] [blame] | 238 | return err; |
Greg Kroah-Hartman | afdce75 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 239 | } |
| 240 | static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); |
| 241 | |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 242 | static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) |
| 243 | { |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 244 | return sprintf(buf, "%d\n", bus->p->drivers_autoprobe); |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static ssize_t store_drivers_autoprobe(struct bus_type *bus, |
| 248 | const char *buf, size_t count) |
| 249 | { |
| 250 | if (buf[0] == '0') |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 251 | bus->p->drivers_autoprobe = 0; |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 252 | else |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 253 | bus->p->drivers_autoprobe = 1; |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 254 | return count; |
| 255 | } |
| 256 | |
| 257 | static ssize_t store_drivers_probe(struct bus_type *bus, |
| 258 | const char *buf, size_t count) |
| 259 | { |
| 260 | struct device *dev; |
| 261 | |
| 262 | dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); |
| 263 | if (!dev) |
| 264 | return -ENODEV; |
| 265 | if (bus_rescan_devices_helper(dev, NULL) != 0) |
| 266 | return -EINVAL; |
| 267 | return count; |
| 268 | } |
Russell King | 2139bdd | 2006-02-07 12:58:20 -0800 | [diff] [blame] | 269 | #endif |
Greg Kroah-Hartman | 151ef38 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 270 | |
mochel@digitalimplant.org | 465c7a3 | 2005-03-21 11:49:14 -0800 | [diff] [blame] | 271 | static struct device * next_device(struct klist_iter * i) |
| 272 | { |
| 273 | struct klist_node * n = klist_next(i); |
| 274 | return n ? container_of(n, struct device, knode_bus) : NULL; |
| 275 | } |
| 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /** |
| 278 | * bus_for_each_dev - device iterator. |
| 279 | * @bus: bus type. |
| 280 | * @start: device to start iterating from. |
| 281 | * @data: data for the callback. |
| 282 | * @fn: function to be called for each device. |
| 283 | * |
| 284 | * Iterate over @bus's list of devices, and call @fn for each, |
| 285 | * passing it @data. If @start is not NULL, we use that device to |
| 286 | * begin iterating from. |
| 287 | * |
| 288 | * We check the return of @fn each time. If it returns anything |
| 289 | * other than 0, we break out and return that value. |
| 290 | * |
| 291 | * NOTE: The device that returns a non-zero value is not retained |
| 292 | * in any way, nor is its refcount incremented. If the caller needs |
| 293 | * to retain this data, it should do, and increment the reference |
| 294 | * count in the supplied callback. |
| 295 | */ |
| 296 | |
| 297 | int bus_for_each_dev(struct bus_type * bus, struct device * start, |
| 298 | void * data, int (*fn)(struct device *, void *)) |
| 299 | { |
mochel@digitalimplant.org | 465c7a3 | 2005-03-21 11:49:14 -0800 | [diff] [blame] | 300 | struct klist_iter i; |
| 301 | struct device * dev; |
| 302 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
mochel@digitalimplant.org | 465c7a3 | 2005-03-21 11:49:14 -0800 | [diff] [blame] | 304 | if (!bus) |
| 305 | return -EINVAL; |
| 306 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 307 | klist_iter_init_node(&bus->p->klist_devices, &i, |
mochel@digitalimplant.org | 465c7a3 | 2005-03-21 11:49:14 -0800 | [diff] [blame] | 308 | (start ? &start->knode_bus : NULL)); |
| 309 | while ((dev = next_device(&i)) && !error) |
| 310 | error = fn(dev, data); |
| 311 | klist_iter_exit(&i); |
| 312 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Cornelia Huck | 0edb586 | 2005-06-22 16:59:51 +0200 | [diff] [blame] | 315 | /** |
| 316 | * bus_find_device - device iterator for locating a particular device. |
| 317 | * @bus: bus type |
| 318 | * @start: Device to begin with |
| 319 | * @data: Data to pass to match function |
| 320 | * @match: Callback function to check device |
| 321 | * |
| 322 | * This is similar to the bus_for_each_dev() function above, but it |
| 323 | * returns a reference to a device that is 'found' for later use, as |
| 324 | * determined by the @match callback. |
| 325 | * |
| 326 | * The callback should return 0 if the device doesn't match and non-zero |
| 327 | * if it does. If the callback returns non-zero, this function will |
| 328 | * return to the caller and not iterate over any more devices. |
| 329 | */ |
| 330 | struct device * bus_find_device(struct bus_type *bus, |
| 331 | struct device *start, void *data, |
| 332 | int (*match)(struct device *, void *)) |
| 333 | { |
| 334 | struct klist_iter i; |
| 335 | struct device *dev; |
| 336 | |
| 337 | if (!bus) |
| 338 | return NULL; |
| 339 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 340 | klist_iter_init_node(&bus->p->klist_devices, &i, |
Cornelia Huck | 0edb586 | 2005-06-22 16:59:51 +0200 | [diff] [blame] | 341 | (start ? &start->knode_bus : NULL)); |
| 342 | while ((dev = next_device(&i))) |
| 343 | if (match(dev, data) && get_device(dev)) |
| 344 | break; |
| 345 | klist_iter_exit(&i); |
| 346 | return dev; |
| 347 | } |
mochel@digitalimplant.org | 38fdac3 | 2005-03-21 12:00:18 -0800 | [diff] [blame] | 348 | |
| 349 | |
| 350 | static struct device_driver * next_driver(struct klist_iter * i) |
| 351 | { |
| 352 | struct klist_node * n = klist_next(i); |
| 353 | return n ? container_of(n, struct device_driver, knode_bus) : NULL; |
| 354 | } |
| 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | /** |
| 357 | * bus_for_each_drv - driver iterator |
| 358 | * @bus: bus we're dealing with. |
| 359 | * @start: driver to start iterating on. |
| 360 | * @data: data to pass to the callback. |
| 361 | * @fn: function to call for each driver. |
| 362 | * |
| 363 | * This is nearly identical to the device iterator above. |
| 364 | * We iterate over each driver that belongs to @bus, and call |
| 365 | * @fn for each. If @fn returns anything but 0, we break out |
| 366 | * and return it. If @start is not NULL, we use it as the head |
| 367 | * of the list. |
| 368 | * |
| 369 | * NOTE: we don't return the driver that returns a non-zero |
| 370 | * value, nor do we leave the reference count incremented for that |
| 371 | * driver. If the caller needs to know that info, it must set it |
| 372 | * in the callback. It must also be sure to increment the refcount |
| 373 | * so it doesn't disappear before returning to the caller. |
| 374 | */ |
| 375 | |
| 376 | int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, |
| 377 | void * data, int (*fn)(struct device_driver *, void *)) |
| 378 | { |
mochel@digitalimplant.org | 38fdac3 | 2005-03-21 12:00:18 -0800 | [diff] [blame] | 379 | struct klist_iter i; |
| 380 | struct device_driver * drv; |
| 381 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
mochel@digitalimplant.org | 38fdac3 | 2005-03-21 12:00:18 -0800 | [diff] [blame] | 383 | if (!bus) |
| 384 | return -EINVAL; |
| 385 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 386 | klist_iter_init_node(&bus->p->klist_drivers, &i, |
mochel@digitalimplant.org | 38fdac3 | 2005-03-21 12:00:18 -0800 | [diff] [blame] | 387 | start ? &start->knode_bus : NULL); |
| 388 | while ((drv = next_driver(&i)) && !error) |
| 389 | error = fn(drv, data); |
| 390 | klist_iter_exit(&i); |
| 391 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Andrew Morton | 4aca67e | 2007-02-13 22:39:26 -0800 | [diff] [blame] | 394 | static int device_add_attrs(struct bus_type *bus, struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
| 396 | int error = 0; |
| 397 | int i; |
| 398 | |
Andrew Morton | 4aca67e | 2007-02-13 22:39:26 -0800 | [diff] [blame] | 399 | if (!bus->dev_attrs) |
| 400 | return 0; |
| 401 | |
| 402 | for (i = 0; attr_name(bus->dev_attrs[i]); i++) { |
| 403 | error = device_create_file(dev,&bus->dev_attrs[i]); |
| 404 | if (error) { |
| 405 | while (--i >= 0) |
| 406 | device_remove_file(dev, &bus->dev_attrs[i]); |
| 407 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | static void device_remove_attrs(struct bus_type * bus, struct device * dev) |
| 414 | { |
| 415 | int i; |
| 416 | |
| 417 | if (bus->dev_attrs) { |
| 418 | for (i = 0; attr_name(bus->dev_attrs[i]); i++) |
| 419 | device_remove_file(dev,&bus->dev_attrs[i]); |
| 420 | } |
| 421 | } |
| 422 | |
Kay Sievers | b9cafc7 | 2006-09-14 11:23:28 +0200 | [diff] [blame] | 423 | #ifdef CONFIG_SYSFS_DEPRECATED |
| 424 | static int make_deprecated_bus_links(struct device *dev) |
| 425 | { |
| 426 | return sysfs_create_link(&dev->kobj, |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 427 | &dev->bus->p->subsys.kobj, "bus"); |
Kay Sievers | b9cafc7 | 2006-09-14 11:23:28 +0200 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void remove_deprecated_bus_links(struct device *dev) |
| 431 | { |
| 432 | sysfs_remove_link(&dev->kobj, "bus"); |
| 433 | } |
| 434 | #else |
| 435 | static inline int make_deprecated_bus_links(struct device *dev) { return 0; } |
| 436 | static inline void remove_deprecated_bus_links(struct device *dev) { } |
| 437 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | /** |
| 440 | * bus_add_device - add device to bus |
| 441 | * @dev: device being added |
| 442 | * |
| 443 | * - Add the device to its bus's list of devices. |
Kay Sievers | 53877d0 | 2006-04-04 20:42:26 +0200 | [diff] [blame] | 444 | * - Create link to device's bus. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | */ |
| 446 | int bus_add_device(struct device * dev) |
| 447 | { |
Greg Kroah-Hartman | 5901d01 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 448 | struct bus_type * bus = bus_get(dev->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | int error = 0; |
| 450 | |
| 451 | if (bus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); |
Greg Kroah-Hartman | d377e85 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 453 | error = device_add_attrs(bus, dev); |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 454 | if (error) |
Cornelia Huck | 513e733 | 2006-09-22 11:37:08 +0200 | [diff] [blame] | 455 | goto out_put; |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 456 | error = sysfs_create_link(&bus->p->devices_kset->kobj, |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 457 | &dev->kobj, dev->bus_id); |
| 458 | if (error) |
Cornelia Huck | 513e733 | 2006-09-22 11:37:08 +0200 | [diff] [blame] | 459 | goto out_id; |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 460 | error = sysfs_create_link(&dev->kobj, |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 461 | &dev->bus->p->subsys.kobj, "subsystem"); |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 462 | if (error) |
Cornelia Huck | 513e733 | 2006-09-22 11:37:08 +0200 | [diff] [blame] | 463 | goto out_subsys; |
Kay Sievers | b9cafc7 | 2006-09-14 11:23:28 +0200 | [diff] [blame] | 464 | error = make_deprecated_bus_links(dev); |
Cornelia Huck | 513e733 | 2006-09-22 11:37:08 +0200 | [diff] [blame] | 465 | if (error) |
| 466 | goto out_deprecated; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
Cornelia Huck | 513e733 | 2006-09-22 11:37:08 +0200 | [diff] [blame] | 468 | return 0; |
| 469 | |
| 470 | out_deprecated: |
| 471 | sysfs_remove_link(&dev->kobj, "subsystem"); |
| 472 | out_subsys: |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 473 | sysfs_remove_link(&bus->p->devices_kset->kobj, dev->bus_id); |
Cornelia Huck | 513e733 | 2006-09-22 11:37:08 +0200 | [diff] [blame] | 474 | out_id: |
| 475 | device_remove_attrs(bus, dev); |
| 476 | out_put: |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 477 | bus_put(dev->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return error; |
| 479 | } |
| 480 | |
| 481 | /** |
Kay Sievers | 53877d0 | 2006-04-04 20:42:26 +0200 | [diff] [blame] | 482 | * bus_attach_device - add device to bus |
| 483 | * @dev: device tried to attach to a driver |
| 484 | * |
Alan Stern | f2eaae1 | 2006-09-18 16:22:34 -0400 | [diff] [blame] | 485 | * - Add device to bus's list of devices. |
Kay Sievers | 53877d0 | 2006-04-04 20:42:26 +0200 | [diff] [blame] | 486 | * - Try to attach to driver. |
| 487 | */ |
Cornelia Huck | c6a4669 | 2007-02-05 16:15:26 -0800 | [diff] [blame] | 488 | void bus_attach_device(struct device * dev) |
Kay Sievers | 53877d0 | 2006-04-04 20:42:26 +0200 | [diff] [blame] | 489 | { |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 490 | struct bus_type *bus = dev->bus; |
| 491 | int ret = 0; |
Kay Sievers | 53877d0 | 2006-04-04 20:42:26 +0200 | [diff] [blame] | 492 | |
| 493 | if (bus) { |
Alan Stern | f2eaae1 | 2006-09-18 16:22:34 -0400 | [diff] [blame] | 494 | dev->is_registered = 1; |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 495 | if (bus->p->drivers_autoprobe) |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 496 | ret = device_attach(dev); |
Cornelia Huck | c6a4669 | 2007-02-05 16:15:26 -0800 | [diff] [blame] | 497 | WARN_ON(ret < 0); |
| 498 | if (ret >= 0) |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 499 | klist_add_tail(&dev->knode_bus, &bus->p->klist_devices); |
Cornelia Huck | c6a4669 | 2007-02-05 16:15:26 -0800 | [diff] [blame] | 500 | else |
Alan Stern | f2eaae1 | 2006-09-18 16:22:34 -0400 | [diff] [blame] | 501 | dev->is_registered = 0; |
Kay Sievers | 53877d0 | 2006-04-04 20:42:26 +0200 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
| 505 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | * bus_remove_device - remove device from bus |
| 507 | * @dev: device to be removed |
| 508 | * |
| 509 | * - Remove symlink from bus's directory. |
| 510 | * - Delete device from bus's list. |
| 511 | * - Detach from its driver. |
| 512 | * - Drop reference taken in bus_add_device(). |
| 513 | */ |
| 514 | void bus_remove_device(struct device * dev) |
| 515 | { |
| 516 | if (dev->bus) { |
Kay Sievers | b9d9c82 | 2006-06-15 15:31:56 +0200 | [diff] [blame] | 517 | sysfs_remove_link(&dev->kobj, "subsystem"); |
Kay Sievers | b9cafc7 | 2006-09-14 11:23:28 +0200 | [diff] [blame] | 518 | remove_deprecated_bus_links(dev); |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 519 | sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev->bus_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | device_remove_attrs(dev->bus, dev); |
Alan Stern | f70fa62 | 2006-10-05 17:03:24 -0400 | [diff] [blame] | 521 | if (dev->is_registered) { |
| 522 | dev->is_registered = 0; |
| 523 | klist_del(&dev->knode_bus); |
| 524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); |
| 526 | device_release_driver(dev); |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 527 | bus_put(dev->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv) |
| 532 | { |
| 533 | int error = 0; |
| 534 | int i; |
| 535 | |
| 536 | if (bus->drv_attrs) { |
| 537 | for (i = 0; attr_name(bus->drv_attrs[i]); i++) { |
| 538 | error = driver_create_file(drv, &bus->drv_attrs[i]); |
| 539 | if (error) |
| 540 | goto Err; |
| 541 | } |
| 542 | } |
| 543 | Done: |
| 544 | return error; |
| 545 | Err: |
| 546 | while (--i >= 0) |
| 547 | driver_remove_file(drv, &bus->drv_attrs[i]); |
| 548 | goto Done; |
| 549 | } |
| 550 | |
| 551 | |
| 552 | static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv) |
| 553 | { |
| 554 | int i; |
| 555 | |
| 556 | if (bus->drv_attrs) { |
| 557 | for (i = 0; attr_name(bus->drv_attrs[i]); i++) |
| 558 | driver_remove_file(drv, &bus->drv_attrs[i]); |
| 559 | } |
| 560 | } |
| 561 | |
Greg Kroah-Hartman | 874c624 | 2005-12-13 15:17:34 -0800 | [diff] [blame] | 562 | #ifdef CONFIG_HOTPLUG |
| 563 | /* |
| 564 | * Thanks to drivers making their tables __devinit, we can't allow manual |
| 565 | * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled. |
| 566 | */ |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 567 | static int __must_check add_bind_files(struct device_driver *drv) |
Greg Kroah-Hartman | 874c624 | 2005-12-13 15:17:34 -0800 | [diff] [blame] | 568 | { |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 569 | int ret; |
| 570 | |
| 571 | ret = driver_create_file(drv, &driver_attr_unbind); |
| 572 | if (ret == 0) { |
| 573 | ret = driver_create_file(drv, &driver_attr_bind); |
| 574 | if (ret) |
| 575 | driver_remove_file(drv, &driver_attr_unbind); |
| 576 | } |
| 577 | return ret; |
Greg Kroah-Hartman | 874c624 | 2005-12-13 15:17:34 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static void remove_bind_files(struct device_driver *drv) |
| 581 | { |
| 582 | driver_remove_file(drv, &driver_attr_bind); |
| 583 | driver_remove_file(drv, &driver_attr_unbind); |
| 584 | } |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 585 | |
Kay Sievers | 8380770 | 2007-07-30 02:28:56 +0200 | [diff] [blame] | 586 | static BUS_ATTR(drivers_probe, S_IWUSR, NULL, store_drivers_probe); |
| 587 | static BUS_ATTR(drivers_autoprobe, S_IWUSR | S_IRUGO, |
| 588 | show_drivers_autoprobe, store_drivers_autoprobe); |
| 589 | |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 590 | static int add_probe_files(struct bus_type *bus) |
| 591 | { |
| 592 | int retval; |
| 593 | |
Kay Sievers | 8380770 | 2007-07-30 02:28:56 +0200 | [diff] [blame] | 594 | retval = bus_create_file(bus, &bus_attr_drivers_probe); |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 595 | if (retval) |
| 596 | goto out; |
| 597 | |
Kay Sievers | 8380770 | 2007-07-30 02:28:56 +0200 | [diff] [blame] | 598 | retval = bus_create_file(bus, &bus_attr_drivers_autoprobe); |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 599 | if (retval) |
Kay Sievers | 8380770 | 2007-07-30 02:28:56 +0200 | [diff] [blame] | 600 | bus_remove_file(bus, &bus_attr_drivers_probe); |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 601 | out: |
| 602 | return retval; |
| 603 | } |
| 604 | |
| 605 | static void remove_probe_files(struct bus_type *bus) |
| 606 | { |
Kay Sievers | 8380770 | 2007-07-30 02:28:56 +0200 | [diff] [blame] | 607 | bus_remove_file(bus, &bus_attr_drivers_autoprobe); |
| 608 | bus_remove_file(bus, &bus_attr_drivers_probe); |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 609 | } |
Greg Kroah-Hartman | 874c624 | 2005-12-13 15:17:34 -0800 | [diff] [blame] | 610 | #else |
Yoichi Yuasa | 35acfdd | 2006-07-15 01:30:11 +0900 | [diff] [blame] | 611 | static inline int add_bind_files(struct device_driver *drv) { return 0; } |
Greg Kroah-Hartman | 874c624 | 2005-12-13 15:17:34 -0800 | [diff] [blame] | 612 | static inline void remove_bind_files(struct device_driver *drv) {} |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 613 | static inline int add_probe_files(struct bus_type *bus) { return 0; } |
| 614 | static inline void remove_probe_files(struct bus_type *bus) {} |
Greg Kroah-Hartman | 874c624 | 2005-12-13 15:17:34 -0800 | [diff] [blame] | 615 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Kay Sievers | 7ac1cf4 | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 617 | static ssize_t driver_uevent_store(struct device_driver *drv, |
| 618 | const char *buf, size_t count) |
| 619 | { |
| 620 | enum kobject_action action; |
| 621 | |
| 622 | if (kobject_action_type(buf, count, &action) == 0) |
| 623 | kobject_uevent(&drv->kobj, action); |
| 624 | return count; |
| 625 | } |
| 626 | static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store); |
| 627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | /** |
| 629 | * bus_add_driver - Add a driver to the bus. |
| 630 | * @drv: driver. |
| 631 | * |
| 632 | */ |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 633 | int bus_add_driver(struct device_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
Greg Kroah-Hartman | 5901d01 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 635 | struct bus_type * bus = bus_get(drv->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | int error = 0; |
| 637 | |
Jeff Garzik | d9fd4d3b3 | 2006-10-04 07:48:03 -0400 | [diff] [blame] | 638 | if (!bus) |
Greg Kroah-Hartman | 4f6e194 | 2007-04-20 11:29:52 -0700 | [diff] [blame] | 639 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
Jeff Garzik | d9fd4d3b3 | 2006-10-04 07:48:03 -0400 | [diff] [blame] | 641 | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); |
| 642 | error = kobject_set_name(&drv->kobj, "%s", drv->name); |
| 643 | if (error) |
| 644 | goto out_put_bus; |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 645 | drv->kobj.kset = bus->p->drivers_kset; |
Greg Kroah-Hartman | 3514fac | 2007-10-16 10:11:44 -0600 | [diff] [blame] | 646 | drv->kobj.ktype = &driver_ktype; |
Cornelia Huck | dc0afa8 | 2007-07-09 11:39:18 -0700 | [diff] [blame] | 647 | error = kobject_register(&drv->kobj); |
| 648 | if (error) |
Jeff Garzik | d9fd4d3b3 | 2006-10-04 07:48:03 -0400 | [diff] [blame] | 649 | goto out_put_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 651 | if (drv->bus->p->drivers_autoprobe) { |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 652 | error = driver_attach(drv); |
| 653 | if (error) |
| 654 | goto out_unregister; |
| 655 | } |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 656 | klist_add_tail(&drv->knode_bus, &bus->p->klist_drivers); |
Jeff Garzik | d9fd4d3b3 | 2006-10-04 07:48:03 -0400 | [diff] [blame] | 657 | module_add_driver(drv->owner, drv); |
| 658 | |
Kay Sievers | 7ac1cf4 | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 659 | error = driver_create_file(drv, &driver_attr_uevent); |
| 660 | if (error) { |
| 661 | printk(KERN_ERR "%s: uevent attr (%s) failed\n", |
| 662 | __FUNCTION__, drv->name); |
| 663 | } |
Jeff Garzik | d9fd4d3b3 | 2006-10-04 07:48:03 -0400 | [diff] [blame] | 664 | error = driver_add_attrs(bus, drv); |
| 665 | if (error) { |
| 666 | /* How the hell do we get out of this pickle? Give up */ |
| 667 | printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", |
| 668 | __FUNCTION__, drv->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
Jeff Garzik | d9fd4d3b3 | 2006-10-04 07:48:03 -0400 | [diff] [blame] | 670 | error = add_bind_files(drv); |
| 671 | if (error) { |
| 672 | /* Ditto */ |
| 673 | printk(KERN_ERR "%s: add_bind_files(%s) failed\n", |
| 674 | __FUNCTION__, drv->name); |
| 675 | } |
| 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | return error; |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 678 | out_unregister: |
| 679 | kobject_unregister(&drv->kobj); |
| 680 | out_put_bus: |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 681 | bus_put(bus); |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 682 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | /** |
| 686 | * bus_remove_driver - delete driver from bus's knowledge. |
| 687 | * @drv: driver. |
| 688 | * |
| 689 | * Detach the driver from the devices it controls, and remove |
| 690 | * it from its bus's list of drivers. Finally, we drop the reference |
| 691 | * to the bus we took in bus_add_driver(). |
| 692 | */ |
| 693 | |
| 694 | void bus_remove_driver(struct device_driver * drv) |
| 695 | { |
Jeff Garzik | d9fd4d3b3 | 2006-10-04 07:48:03 -0400 | [diff] [blame] | 696 | if (!drv->bus) |
| 697 | return; |
| 698 | |
| 699 | remove_bind_files(drv); |
| 700 | driver_remove_attrs(drv->bus, drv); |
Kay Sievers | 7ac1cf4 | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 701 | driver_remove_file(drv, &driver_attr_uevent); |
Jeff Garzik | d9fd4d3b3 | 2006-10-04 07:48:03 -0400 | [diff] [blame] | 702 | klist_remove(&drv->knode_bus); |
| 703 | pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); |
| 704 | driver_detach(drv); |
| 705 | module_remove_driver(drv); |
| 706 | kobject_unregister(&drv->kobj); |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 707 | bus_put(drv->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | |
| 711 | /* Helper for bus_rescan_devices's iter */ |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 712 | static int __must_check bus_rescan_devices_helper(struct device *dev, |
| 713 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 715 | int ret = 0; |
| 716 | |
Alan Stern | bf74ad5 | 2005-11-17 16:54:12 -0500 | [diff] [blame] | 717 | if (!dev->driver) { |
| 718 | if (dev->parent) /* Needed for USB */ |
| 719 | down(&dev->parent->sem); |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 720 | ret = device_attach(dev); |
Alan Stern | bf74ad5 | 2005-11-17 16:54:12 -0500 | [diff] [blame] | 721 | if (dev->parent) |
| 722 | up(&dev->parent->sem); |
| 723 | } |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 724 | return ret < 0 ? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | /** |
Greg Kroah-Hartman | 23d3d60 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 728 | * bus_rescan_devices - rescan devices on the bus for possible drivers |
| 729 | * @bus: the bus to scan. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | * |
Greg Kroah-Hartman | 23d3d60 | 2005-06-22 16:09:05 -0700 | [diff] [blame] | 731 | * This function will look for devices on the bus with no driver |
| 732 | * attached and rescan it against existing drivers to see if it matches |
| 733 | * any by calling device_attach() for the unbound devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | */ |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 735 | int bus_rescan_devices(struct bus_type * bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | { |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 737 | return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Moore, Eric | e935d5d | 2006-03-14 09:18:18 -0700 | [diff] [blame] | 740 | /** |
| 741 | * device_reprobe - remove driver for a device and probe for a new driver |
| 742 | * @dev: the device to reprobe |
| 743 | * |
| 744 | * This function detaches the attached driver (if any) for the given |
| 745 | * device and restarts the driver probing process. It is intended |
| 746 | * to use if probing criteria changed during a devices lifetime and |
| 747 | * driver attachment should change accordingly. |
| 748 | */ |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 749 | int device_reprobe(struct device *dev) |
Moore, Eric | e935d5d | 2006-03-14 09:18:18 -0700 | [diff] [blame] | 750 | { |
| 751 | if (dev->driver) { |
| 752 | if (dev->parent) /* Needed for USB */ |
| 753 | down(&dev->parent->sem); |
| 754 | device_release_driver(dev); |
| 755 | if (dev->parent) |
| 756 | up(&dev->parent->sem); |
| 757 | } |
Andrew Morton | f86db39 | 2006-08-14 22:43:20 -0700 | [diff] [blame] | 758 | return bus_rescan_devices_helper(dev, NULL); |
Moore, Eric | e935d5d | 2006-03-14 09:18:18 -0700 | [diff] [blame] | 759 | } |
| 760 | EXPORT_SYMBOL_GPL(device_reprobe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | /** |
| 763 | * find_bus - locate bus by name. |
| 764 | * @name: name of bus. |
| 765 | * |
| 766 | * Call kset_find_obj() to iterate over list of buses to |
| 767 | * find a bus by name. Return bus if found. |
| 768 | * |
| 769 | * Note that kset_find_obj increments bus' reference count. |
| 770 | */ |
Adrian Bunk | 7e4ef08 | 2006-06-26 22:26:56 +0200 | [diff] [blame] | 771 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | struct bus_type * find_bus(char * name) |
| 773 | { |
Greg Kroah-Hartman | 59a5483 | 2007-10-29 23:22:26 -0500 | [diff] [blame] | 774 | struct kobject * k = kset_find_obj(bus_kset, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | return k ? to_bus(k) : NULL; |
| 776 | } |
Adrian Bunk | 7e4ef08 | 2006-06-26 22:26:56 +0200 | [diff] [blame] | 777 | #endif /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
| 779 | |
| 780 | /** |
| 781 | * bus_add_attrs - Add default attributes for this bus. |
| 782 | * @bus: Bus that has just been registered. |
| 783 | */ |
| 784 | |
| 785 | static int bus_add_attrs(struct bus_type * bus) |
| 786 | { |
| 787 | int error = 0; |
| 788 | int i; |
| 789 | |
| 790 | if (bus->bus_attrs) { |
| 791 | for (i = 0; attr_name(bus->bus_attrs[i]); i++) { |
Cornelia Huck | dc0afa8 | 2007-07-09 11:39:18 -0700 | [diff] [blame] | 792 | error = bus_create_file(bus,&bus->bus_attrs[i]); |
| 793 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | goto Err; |
| 795 | } |
| 796 | } |
| 797 | Done: |
| 798 | return error; |
| 799 | Err: |
| 800 | while (--i >= 0) |
| 801 | bus_remove_file(bus,&bus->bus_attrs[i]); |
| 802 | goto Done; |
| 803 | } |
| 804 | |
| 805 | static void bus_remove_attrs(struct bus_type * bus) |
| 806 | { |
| 807 | int i; |
| 808 | |
| 809 | if (bus->bus_attrs) { |
| 810 | for (i = 0; attr_name(bus->bus_attrs[i]); i++) |
| 811 | bus_remove_file(bus,&bus->bus_attrs[i]); |
| 812 | } |
| 813 | } |
| 814 | |
James Bottomley | 34bb61f | 2005-09-06 16:56:51 -0700 | [diff] [blame] | 815 | static void klist_devices_get(struct klist_node *n) |
| 816 | { |
| 817 | struct device *dev = container_of(n, struct device, knode_bus); |
| 818 | |
| 819 | get_device(dev); |
| 820 | } |
| 821 | |
| 822 | static void klist_devices_put(struct klist_node *n) |
| 823 | { |
| 824 | struct device *dev = container_of(n, struct device, knode_bus); |
| 825 | |
| 826 | put_device(dev); |
| 827 | } |
| 828 | |
Kay Sievers | 7ac1cf4 | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 829 | static ssize_t bus_uevent_store(struct bus_type *bus, |
| 830 | const char *buf, size_t count) |
| 831 | { |
| 832 | enum kobject_action action; |
| 833 | |
| 834 | if (kobject_action_type(buf, count, &action) == 0) |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 835 | kobject_uevent(&bus->p->subsys.kobj, action); |
Kay Sievers | 7ac1cf4 | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 836 | return count; |
| 837 | } |
| 838 | static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store); |
| 839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | /** |
| 841 | * bus_register - register a bus with the system. |
| 842 | * @bus: bus. |
| 843 | * |
| 844 | * Once we have that, we registered the bus with the kobject |
| 845 | * infrastructure, then register the children subsystems it has: |
| 846 | * the devices and drivers that belong to the bus. |
| 847 | */ |
| 848 | int bus_register(struct bus_type * bus) |
| 849 | { |
| 850 | int retval; |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 851 | struct bus_type_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 853 | priv = kzalloc(sizeof(struct bus_type_private), GFP_KERNEL); |
| 854 | if (!priv) |
| 855 | return -ENOMEM; |
Benjamin Herrenschmidt | 116af37 | 2006-10-25 13:44:59 +1000 | [diff] [blame] | 856 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 857 | priv->bus = bus; |
| 858 | bus->p = priv; |
| 859 | |
| 860 | BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier); |
| 861 | |
| 862 | retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | if (retval) |
| 864 | goto out; |
| 865 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 866 | priv->subsys.kobj.kset = bus_kset; |
| 867 | priv->subsys.kobj.ktype = &bus_ktype; |
| 868 | priv->drivers_autoprobe = 1; |
Greg Kroah-Hartman | d6b05b8 | 2007-09-12 15:06:57 -0700 | [diff] [blame] | 869 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 870 | retval = kset_register(&priv->subsys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | if (retval) |
| 872 | goto out; |
| 873 | |
Kay Sievers | 7ac1cf4 | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 874 | retval = bus_create_file(bus, &bus_attr_uevent); |
| 875 | if (retval) |
| 876 | goto bus_uevent_fail; |
| 877 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 878 | priv->devices_kset = kset_create_and_add("devices", NULL, |
| 879 | &priv->subsys.kobj); |
| 880 | if (!priv->devices_kset) { |
Greg Kroah-Hartman | 3d89959 | 2007-11-01 13:31:26 -0700 | [diff] [blame] | 881 | retval = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | goto bus_devices_fail; |
Greg Kroah-Hartman | 3d89959 | 2007-11-01 13:31:26 -0700 | [diff] [blame] | 883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 885 | priv->drivers_kset = kset_create_and_add("drivers", NULL, |
| 886 | &priv->subsys.kobj); |
| 887 | if (!priv->drivers_kset) { |
Greg Kroah-Hartman | 6dcec25 | 2007-11-01 13:31:26 -0700 | [diff] [blame] | 888 | retval = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | goto bus_drivers_fail; |
Greg Kroah-Hartman | 6dcec25 | 2007-11-01 13:31:26 -0700 | [diff] [blame] | 890 | } |
mochel@digitalimplant.org | 465c7a3 | 2005-03-21 11:49:14 -0800 | [diff] [blame] | 891 | |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 892 | klist_init(&priv->klist_devices, klist_devices_get, klist_devices_put); |
| 893 | klist_init(&priv->klist_drivers, NULL, NULL); |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 894 | |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 895 | retval = add_probe_files(bus); |
| 896 | if (retval) |
| 897 | goto bus_probe_files_fail; |
| 898 | |
Cornelia Huck | 1bb6881 | 2006-09-22 11:37:04 +0200 | [diff] [blame] | 899 | retval = bus_add_attrs(bus); |
| 900 | if (retval) |
| 901 | goto bus_attrs_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
| 903 | pr_debug("bus type '%s' registered\n", bus->name); |
| 904 | return 0; |
| 905 | |
Cornelia Huck | 1bb6881 | 2006-09-22 11:37:04 +0200 | [diff] [blame] | 906 | bus_attrs_fail: |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 907 | remove_probe_files(bus); |
| 908 | bus_probe_files_fail: |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 909 | kset_unregister(bus->p->drivers_kset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | bus_drivers_fail: |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 911 | kset_unregister(bus->p->devices_kset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | bus_devices_fail: |
Kay Sievers | 7ac1cf4 | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 913 | bus_remove_file(bus, &bus_attr_uevent); |
| 914 | bus_uevent_fail: |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 915 | kset_unregister(&bus->p->subsys); |
| 916 | kfree(bus->p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | out: |
| 918 | return retval; |
| 919 | } |
| 920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | /** |
| 922 | * bus_unregister - remove a bus from the system |
| 923 | * @bus: bus. |
| 924 | * |
| 925 | * Unregister the child subsystems and the bus itself. |
Greg Kroah-Hartman | fc1ede5 | 2007-09-13 02:53:13 -0700 | [diff] [blame] | 926 | * Finally, we call bus_put() to release the refcount |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | */ |
| 928 | void bus_unregister(struct bus_type * bus) |
| 929 | { |
| 930 | pr_debug("bus %s: unregistering\n", bus->name); |
| 931 | bus_remove_attrs(bus); |
Kay Sievers | b8c5cec | 2007-02-16 17:33:36 +0100 | [diff] [blame] | 932 | remove_probe_files(bus); |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 933 | kset_unregister(bus->p->drivers_kset); |
| 934 | kset_unregister(bus->p->devices_kset); |
Kay Sievers | 7ac1cf4 | 2007-08-12 20:43:55 +0200 | [diff] [blame] | 935 | bus_remove_file(bus, &bus_attr_uevent); |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 936 | kset_unregister(&bus->p->subsys); |
| 937 | kfree(bus->p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Benjamin Herrenschmidt | 116af37 | 2006-10-25 13:44:59 +1000 | [diff] [blame] | 940 | int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) |
| 941 | { |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 942 | return blocking_notifier_chain_register(&bus->p->bus_notifier, nb); |
Benjamin Herrenschmidt | 116af37 | 2006-10-25 13:44:59 +1000 | [diff] [blame] | 943 | } |
| 944 | EXPORT_SYMBOL_GPL(bus_register_notifier); |
| 945 | |
| 946 | int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) |
| 947 | { |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 948 | return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb); |
Benjamin Herrenschmidt | 116af37 | 2006-10-25 13:44:59 +1000 | [diff] [blame] | 949 | } |
| 950 | EXPORT_SYMBOL_GPL(bus_unregister_notifier); |
| 951 | |
Greg Kroah-Hartman | 0fed80f | 2007-11-01 19:41:16 -0700 | [diff] [blame] | 952 | struct kset *bus_get_kset(struct bus_type *bus) |
| 953 | { |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 954 | return &bus->p->subsys; |
Greg Kroah-Hartman | 0fed80f | 2007-11-01 19:41:16 -0700 | [diff] [blame] | 955 | } |
| 956 | EXPORT_SYMBOL_GPL(bus_get_kset); |
| 957 | |
Greg Kroah-Hartman | b249072 | 2007-11-01 19:41:16 -0700 | [diff] [blame] | 958 | struct klist *bus_get_device_klist(struct bus_type *bus) |
| 959 | { |
Greg Kroah-Hartman | c6f7e72 | 2007-11-01 19:41:16 -0700 | [diff] [blame^] | 960 | return &bus->p->klist_devices; |
Greg Kroah-Hartman | b249072 | 2007-11-01 19:41:16 -0700 | [diff] [blame] | 961 | } |
| 962 | EXPORT_SYMBOL_GPL(bus_get_device_klist); |
| 963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | int __init buses_init(void) |
| 965 | { |
Greg Kroah-Hartman | 59a5483 | 2007-10-29 23:22:26 -0500 | [diff] [blame] | 966 | bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); |
| 967 | if (!bus_kset) |
| 968 | return -ENOMEM; |
| 969 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | |
| 973 | EXPORT_SYMBOL_GPL(bus_for_each_dev); |
Cornelia Huck | 0edb586 | 2005-06-22 16:59:51 +0200 | [diff] [blame] | 974 | EXPORT_SYMBOL_GPL(bus_find_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | EXPORT_SYMBOL_GPL(bus_for_each_drv); |
| 976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | EXPORT_SYMBOL_GPL(bus_register); |
| 978 | EXPORT_SYMBOL_GPL(bus_unregister); |
| 979 | EXPORT_SYMBOL_GPL(bus_rescan_devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
| 981 | EXPORT_SYMBOL_GPL(bus_create_file); |
| 982 | EXPORT_SYMBOL_GPL(bus_remove_file); |