aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/bus.c')
-rw-r--r--drivers/base/bus.c182
1 files changed, 0 insertions, 182 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index aa27f76d28cd..1b05c1399e37 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -18,7 +18,6 @@
18#include "power/power.h" 18#include "power/power.h"
19 19
20#define to_dev(node) container_of(node, struct device, bus_list) 20#define to_dev(node) container_of(node, struct device, bus_list)
21#define to_drv(node) container_of(node, struct device_driver, kobj.entry)
22 21
23#define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr) 22#define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr)
24#define to_bus(obj) container_of(obj, struct bus_type, subsys.kset.kobj) 23#define to_bus(obj) container_of(obj, struct bus_type, subsys.kset.kobj)
@@ -243,181 +242,6 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
243 return ret; 242 return ret;
244} 243}
245 244
246/**
247 * device_bind_driver - bind a driver to one device.
248 * @dev: device.
249 *
250 * Allow manual attachment of a driver to a device.
251 * Caller must have already set @dev->driver.
252 *
253 * Note that this does not modify the bus reference count
254 * nor take the bus's rwsem. Please verify those are accounted
255 * for before calling this. (It is ok to call with no other effort
256 * from a driver's probe() method.)
257 */
258
259void device_bind_driver(struct device * dev)
260{
261 pr_debug("bound device '%s' to driver '%s'\n",
262 dev->bus_id, dev->driver->name);
263 list_add_tail(&dev->driver_list, &dev->driver->devices);
264 sysfs_create_link(&dev->driver->kobj, &dev->kobj,
265 kobject_name(&dev->kobj));
266 sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver");
267}
268
269
270/**
271 * driver_probe_device - attempt to bind device & driver.
272 * @drv: driver.
273 * @dev: device.
274 *
275 * First, we call the bus's match function, if one present, which
276 * should compare the device IDs the driver supports with the
277 * device IDs of the device. Note we don't do this ourselves
278 * because we don't know the format of the ID structures, nor what
279 * is to be considered a match and what is not.
280 *
281 * If we find a match, we call @drv->probe(@dev) if it exists, and
282 * call device_bind_driver() above.
283 */
284int driver_probe_device(struct device_driver * drv, struct device * dev)
285{
286 int error = 0;
287
288 if (drv->bus->match && !drv->bus->match(dev, drv))
289 return -ENODEV;
290
291 down(&dev->sem);
292 dev->driver = drv;
293 if (drv->probe) {
294 error = drv->probe(dev);
295 if (error) {
296 dev->driver = NULL;
297 up(&dev->sem);
298 return error;
299 }
300 }
301 up(&dev->sem);
302 device_bind_driver(dev);
303 return 0;
304}
305
306
307/**
308 * device_attach - try to attach device to a driver.
309 * @dev: device.
310 *
311 * Walk the list of drivers that the bus has and call
312 * driver_probe_device() for each pair. If a compatible
313 * pair is found, break out and return.
314 */
315int device_attach(struct device * dev)
316{
317 struct bus_type * bus = dev->bus;
318 struct list_head * entry;
319 int error;
320
321 if (dev->driver) {
322 device_bind_driver(dev);
323 return 1;
324 }
325
326 if (bus->match) {
327 list_for_each(entry, &bus->drivers.list) {
328 struct device_driver * drv = to_drv(entry);
329 error = driver_probe_device(drv, dev);
330 if (!error)
331 /* success, driver matched */
332 return 1;
333 if (error != -ENODEV && error != -ENXIO)
334 /* driver matched but the probe failed */
335 printk(KERN_WARNING
336 "%s: probe of %s failed with error %d\n",
337 drv->name, dev->bus_id, error);
338 }
339 }
340
341 return 0;
342}
343
344
345/**
346 * driver_attach - try to bind driver to devices.
347 * @drv: driver.
348 *
349 * Walk the list of devices that the bus has on it and try to
350 * match the driver with each one. If driver_probe_device()
351 * returns 0 and the @dev->driver is set, we've found a
352 * compatible pair.
353 *
354 * Note that we ignore the -ENODEV error from driver_probe_device(),
355 * since it's perfectly valid for a driver not to bind to any devices.
356 */
357void driver_attach(struct device_driver * drv)
358{
359 struct bus_type * bus = drv->bus;
360 struct list_head * entry;
361 int error;
362
363 if (!bus->match)
364 return;
365
366 list_for_each(entry, &bus->devices.list) {
367 struct device * dev = container_of(entry, struct device, bus_list);
368 if (!dev->driver) {
369 error = driver_probe_device(drv, dev);
370 if (error && (error != -ENODEV))
371 /* driver matched but the probe failed */
372 printk(KERN_WARNING
373 "%s: probe of %s failed with error %d\n",
374 drv->name, dev->bus_id, error);
375 }
376 }
377}
378
379
380/**
381 * device_release_driver - manually detach device from driver.
382 * @dev: device.
383 *
384 * Manually detach device from driver.
385 * Note that this is called without incrementing the bus
386 * reference count nor taking the bus's rwsem. Be sure that
387 * those are accounted for before calling this function.
388 */
389
390void device_release_driver(struct device * dev)
391{
392 struct device_driver * drv;
393
394 down(&dev->sem);
395 drv = dev->driver;
396 if (drv) {
397 sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
398 sysfs_remove_link(&dev->kobj, "driver");
399 list_del_init(&dev->driver_list);
400 if (drv->remove)
401 drv->remove(dev);
402 dev->driver = NULL;
403 }
404 up(&dev->sem);
405}
406
407
408/**
409 * driver_detach - detach driver from all devices it controls.
410 * @drv: driver.
411 */
412
413static void driver_detach(struct device_driver * drv)
414{
415 while (!list_empty(&drv->devices)) {
416 struct device * dev = container_of(drv->devices.next, struct device, driver_list);
417 device_release_driver(dev);
418 }
419}
420
421static int device_add_attrs(struct bus_type * bus, struct device * dev) 245static int device_add_attrs(struct bus_type * bus, struct device * dev)
422{ 246{
423 int error = 0; 247 int error = 0;
@@ -757,12 +581,6 @@ int __init buses_init(void)
757EXPORT_SYMBOL_GPL(bus_for_each_dev); 581EXPORT_SYMBOL_GPL(bus_for_each_dev);
758EXPORT_SYMBOL_GPL(bus_for_each_drv); 582EXPORT_SYMBOL_GPL(bus_for_each_drv);
759 583
760EXPORT_SYMBOL_GPL(driver_probe_device);
761EXPORT_SYMBOL_GPL(device_bind_driver);
762EXPORT_SYMBOL_GPL(device_release_driver);
763EXPORT_SYMBOL_GPL(device_attach);
764EXPORT_SYMBOL_GPL(driver_attach);
765
766EXPORT_SYMBOL_GPL(bus_add_device); 584EXPORT_SYMBOL_GPL(bus_add_device);
767EXPORT_SYMBOL_GPL(bus_remove_device); 585EXPORT_SYMBOL_GPL(bus_remove_device);
768EXPORT_SYMBOL_GPL(bus_register); 586EXPORT_SYMBOL_GPL(bus_register);