diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 15:20:36 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 15:20:36 -0700 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/base |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/base')
28 files changed, 5835 insertions, 0 deletions
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig new file mode 100644 index 00000000000..934149c1512 --- /dev/null +++ b/drivers/base/Kconfig @@ -0,0 +1,40 @@ +menu "Generic Driver Options" + +config STANDALONE + bool "Select only drivers that don't need compile-time external firmware" if EXPERIMENTAL + default y + help + Select this option if you don't have magic firmware for drivers that + need it. + + If unsure, say Y. + +config PREVENT_FIRMWARE_BUILD + bool "Prevent firmware from being built" + default y + help + Say yes to avoid building firmware. Firmware is usually shipped + with the driver, and only when updating the firmware a rebuild + should be made. + If unsure say Y here. + +config FW_LOADER + tristate "Hotplug firmware loading support" + select HOTPLUG + ---help--- + This option is provided for the case where no in-kernel-tree modules + require hotplug firmware loading support, but a module built outside + the kernel tree does. + +config DEBUG_DRIVER + bool "Driver Core verbose debug messages" + depends on DEBUG_KERNEL + help + Say Y here if you want the Driver core to produce a bunch of + debug messages to the system log. Select this if you are having a + problem with the driver core and want to see more of what is + going on. + + If you are unsure about this, say N here. + +endmenu diff --git a/drivers/base/Makefile b/drivers/base/Makefile new file mode 100644 index 00000000000..6662b545e0a --- /dev/null +++ b/drivers/base/Makefile @@ -0,0 +1,14 @@ +# Makefile for the Linux device tree + +obj-y := core.o sys.o interface.o bus.o \ + driver.o class.o class_simple.o platform.o \ + cpu.o firmware.o init.o map.o dmapool.o \ + attribute_container.o transport_class.o +obj-y += power/ +obj-$(CONFIG_FW_LOADER) += firmware_class.o +obj-$(CONFIG_NUMA) += node.o + +ifeq ($(CONFIG_DEBUG_DRIVER),y) +EXTRA_CFLAGS += -DDEBUG +endif + diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c new file mode 100644 index 00000000000..ec615d854be --- /dev/null +++ b/drivers/base/attribute_container.c @@ -0,0 +1,376 @@ +/* + * attribute_container.c - implementation of a simple container for classes + * + * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com> + * + * This file is licensed under GPLv2 + * + * The basic idea here is to enable a device to be attached to an + * aritrary numer of classes without having to allocate storage for them. + * Instead, the contained classes select the devices they need to attach + * to via a matching function. + */ + +#include <linux/attribute_container.h> +#include <linux/init.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/list.h> +#include <linux/module.h> + +/* This is a private structure used to tie the classdev and the + * container .. it should never be visible outside this file */ +struct internal_container { + struct list_head node; + struct attribute_container *cont; + struct class_device classdev; +}; + +/** + * attribute_container_classdev_to_container - given a classdev, return the container + * + * @classdev: the class device created by attribute_container_add_device. + * + * Returns the container associated with this classdev. + */ +struct attribute_container * +attribute_container_classdev_to_container(struct class_device *classdev) +{ + struct internal_container *ic = + container_of(classdev, struct internal_container, classdev); + return ic->cont; +} +EXPORT_SYMBOL_GPL(attribute_container_classdev_to_container); + +static struct list_head attribute_container_list; + +static DECLARE_MUTEX(attribute_container_mutex); + +/** + * attribute_container_register - register an attribute container + * + * @cont: The container to register. This must be allocated by the + * callee and should also be zeroed by it. + */ +int +attribute_container_register(struct attribute_container *cont) +{ + INIT_LIST_HEAD(&cont->node); + INIT_LIST_HEAD(&cont->containers); + + down(&attribute_container_mutex); + list_add_tail(&cont->node, &attribute_container_list); + up(&attribute_container_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(attribute_container_register); + +/** + * attribute_container_unregister - remove a container registration + * + * @cont: previously registered container to remove + */ +int +attribute_container_unregister(struct attribute_container *cont) +{ + int retval = -EBUSY; + down(&attribute_container_mutex); + if (!list_empty(&cont->containers)) + goto out; + retval = 0; + list_del(&cont->node); + out: + up(&attribute_container_mutex); + return retval; + +} +EXPORT_SYMBOL_GPL(attribute_container_unregister); + +/* private function used as class release */ +static void attribute_container_release(struct class_device *classdev) +{ + struct internal_container *ic + = container_of(classdev, struct internal_container, classdev); + struct device *dev = classdev->dev; + + kfree(ic); + put_device(dev); +} + +/** + * attribute_container_add_device - see if any container is interested in dev + * + * @dev: device to add attributes to + * @fn: function to trigger addition of class device. + * + * This function allocates storage for the class device(s) to be + * attached to dev (one for each matching attribute_container). If no + * fn is provided, the code will simply register the class device via + * class_device_add. If a function is provided, it is expected to add + * the class device at the appropriate time. One of the things that + * might be necessary is to allocate and initialise the classdev and + * then add it a later time. To do this, call this routine for + * allocation and initialisation and then use + * attribute_container_device_trigger() to call class_device_add() on + * it. Note: after this, the class device contains a reference to dev + * which is not relinquished until the release of the classdev. + */ +void +attribute_container_add_device(struct device *dev, + int (*fn)(struct attribute_container *, + struct device *, + struct class_device *)) +{ + struct attribute_container *cont; + + down(&attribute_container_mutex); + list_for_each_entry(cont, &attribute_container_list, node) { + struct internal_container *ic; + + if (attribute_container_no_classdevs(cont)) + continue; + + if (!cont->match(cont, dev)) + continue; + ic = kmalloc(sizeof(struct internal_container), GFP_KERNEL); + if (!ic) { + dev_printk(KERN_ERR, dev, "failed to allocate class container\n"); + continue; + } + memset(ic, 0, sizeof(struct internal_container)); + INIT_LIST_HEAD(&ic->node); + ic->cont = cont; + class_device_initialize(&ic->classdev); + ic->classdev.dev = get_device(dev); + ic->classdev.class = cont->class; + cont->class->release = attribute_container_release; + strcpy(ic->classdev.class_id, dev->bus_id); + if (fn) + fn(cont, dev, &ic->classdev); + else + attribute_container_add_class_device(&ic->classdev); + list_add_tail(&ic->node, &cont->containers); + } + up(&attribute_container_mutex); +} + +/** + * attribute_container_remove_device - make device eligible for removal. + * + * @dev: The generic device + * @fn: A function to call to remove the device + * + * This routine triggers device removal. If fn is NULL, then it is + * simply done via class_device_unregister (note that if something + * still has a reference to the classdev, then the memory occupied + * will not be freed until the classdev is released). If you want a + * two phase release: remove from visibility and then delete the + * device, then you should use this routine with a fn that calls + * class_device_del() and then use + * attribute_container_device_trigger() to do the final put on the + * classdev. + */ +void +attribute_container_remove_device(struct device *dev, + void (*fn)(struct attribute_container *, + struct device *, + struct class_device *)) +{ + struct attribute_container *cont; + + down(&attribute_container_mutex); + list_for_each_entry(cont, &attribute_container_list, node) { + struct internal_container *ic, *tmp; + + if (attribute_container_no_classdevs(cont)) + continue; + + if (!cont->match(cont, dev)) + continue; + list_for_each_entry_safe(ic, tmp, &cont->containers, node) { + if (dev != ic->classdev.dev) + continue; + list_del(&ic->node); + if (fn) + fn(cont, dev, &ic->classdev); + else { + attribute_container_remove_attrs(&ic->classdev); + class_device_unregister(&ic->classdev); + } + } + } + up(&attribute_container_mutex); +} +EXPORT_SYMBOL_GPL(attribute_container_remove_device); + +/** + * attribute_container_device_trigger - execute a trigger for each matching classdev + * + * @dev: The generic device to run the trigger for + * @fn the function to execute for each classdev. + * + * This funcion is for executing a trigger when you need to know both + * the container and the classdev. If you only care about the + * container, then use attribute_container_trigger() instead. + */ +void +attribute_container_device_trigger(struct device *dev, + int (*fn)(struct attribute_container *, + struct device *, + struct class_device *)) +{ + struct attribute_container *cont; + + down(&attribute_container_mutex); + list_for_each_entry(cont, &attribute_container_list, node) { + struct internal_container *ic, *tmp; + + if (!cont->match(cont, dev)) + continue; + + list_for_each_entry_safe(ic, tmp, &cont->containers, node) { + if (dev == ic->classdev.dev) + fn(cont, dev, &ic->classdev); + } + } + up(&attribute_container_mutex); +} +EXPORT_SYMBOL_GPL(attribute_container_device_trigger); + +/** + * attribute_container_trigger - trigger a function for each matching container + * + * @dev: The generic device to activate the trigger for + * @fn: the function to trigger + * + * This routine triggers a function that only needs to know the + * matching containers (not the classdev) associated with a device. + * It is more lightweight than attribute_container_device_trigger, so + * should be used in preference unless the triggering function + * actually needs to know the classdev. + */ +void +attribute_container_trigger(struct device *dev, + int (*fn)(struct attribute_container *, + struct device *)) +{ + struct attribute_container *cont; + + down(&attribute_container_mutex); + list_for_each_entry(cont, &attribute_container_list, node) { + if (cont->match(cont, dev)) + fn(cont, dev); + } + up(&attribute_container_mutex); +} +EXPORT_SYMBOL_GPL(attribute_container_trigger); + +/** + * attribute_container_add_attrs - add attributes + * + * @classdev: The class device + * + * This simply creates all the class device sysfs files from the + * attributes listed in the container + */ +int +attribute_container_add_attrs(struct class_device *classdev) +{ + struct attribute_container *cont = + attribute_container_classdev_to_container(classdev); + struct class_device_attribute **attrs = cont->attrs; + int i, error; + + if (!attrs) + return 0; + + for (i = 0; attrs[i]; i++) { + error = class_device_create_file(classdev, attrs[i]); + if (error) + return error; + } + + return 0; +} +EXPORT_SYMBOL_GPL(attribute_container_add_attrs); + +/** + * attribute_container_add_class_device - same function as class_device_add + * + * @classdev: the class device to add + * + * This performs essentially the same function as class_device_add except for + * attribute containers, namely add the classdev to the system and then + * create the attribute files + */ +int +attribute_container_add_class_device(struct class_device *classdev) +{ + int error = class_device_add(classdev); + if (error) + return error; + return attribute_container_add_attrs(classdev); +} +EXPORT_SYMBOL_GPL(attribute_container_add_class_device); + +/** + * attribute_container_add_class_device_adapter - simple adapter for triggers + * + * This function is identical to attribute_container_add_class_device except + * that it is designed to be called from the triggers + */ +int +attribute_container_add_class_device_adapter(struct attribute_container *cont, + struct device *dev, + struct class_device *classdev) +{ + return attribute_container_add_class_device(classdev); +} +EXPORT_SYMBOL_GPL(attribute_container_add_class_device_adapter); + +/** + * attribute_container_remove_attrs - remove any attribute files + * + * @classdev: The class device to remove the files from + * + */ +void +attribute_container_remove_attrs(struct class_device *classdev) +{ + struct attribute_container *cont = + attribute_container_classdev_to_container(classdev); + struct class_device_attribute **attrs = cont->attrs; + int i; + + if (!attrs) + return; + + for (i = 0; attrs[i]; i++) + class_device_remove_file(classdev, attrs[i]); +} +EXPORT_SYMBOL_GPL(attribute_container_remove_attrs); + +/** + * attribute_container_class_device_del - equivalent of class_device_del + * + * @classdev: the class device + * + * This function simply removes all the attribute files and then calls + * class_device_del. + */ +void +attribute_container_class_device_del(struct class_device *classdev) +{ + attribute_container_remove_attrs(classdev); + class_device_del(classdev); +} +EXPORT_SYMBOL_GPL(attribute_container_class_device_del); + +int __init +attribute_container_init(void) +{ + INIT_LIST_HEAD(&attribute_container_list); + return 0; +} diff --git a/drivers/base/base.h b/drivers/base/base.h new file mode 100644 index 00000000000..8d1e8bd4863 --- /dev/null +++ b/drivers/base/base.h @@ -0,0 +1,18 @@ +extern int bus_add_device(struct device * dev); +extern void bus_remove_device(struct device * dev); + +extern int bus_add_driver(struct device_driver *); +extern void bus_remove_driver(struct device_driver *); + +static inline struct class_device *to_class_dev(struct kobject *obj) +{ + return container_of(obj, struct class_device, kobj); +} + +static inline +struct class_device_attribute *to_class_dev_attr(struct attribute *_attr) +{ + return container_of(_attr, struct class_device_attribute, attr); +} + + diff --git a/drivers/base/bus.c b/drivers/base/bus.c new file mode 100644 index 00000000000..f4fa27315fb --- /dev/null +++ b/drivers/base/bus.c @@ -0,0 +1,770 @@ +/* + * bus.c - bus driver management + * + * Copyright (c) 2002-3 Patrick Mochel + * Copyright (c) 2002-3 Open Source Development Labs + * + * This file is released under the GPLv2 + * + */ + +#include <linux/config.h> +#include <linux/device.h> +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <linux/string.h> +#include "base.h" +#include "power/power.h" + +#define to_dev(node) container_of(node, struct device, bus_list) +#define to_drv(node) container_of(node, struct device_driver, kobj.entry) + +#define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr) +#define to_bus(obj) container_of(obj, struct bus_type, subsys.kset.kobj) + +/* + * sysfs bindings for drivers + */ + +#define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr) +#define to_driver(obj) container_of(obj, struct device_driver, kobj) + + +static ssize_t +drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) +{ + struct driver_attribute * drv_attr = to_drv_attr(attr); + struct device_driver * drv = to_driver(kobj); + ssize_t ret = 0; + + if (drv_attr->show) + ret = drv_attr->show(drv, buf); + return ret; +} + +static ssize_t +drv_attr_store(struct kobject * kobj, struct attribute * attr, + const char * buf, size_t count) +{ + struct driver_attribute * drv_attr = to_drv_attr(attr); + struct device_driver * drv = to_driver(kobj); + ssize_t ret = 0; + + if (drv_attr->store) + ret = drv_attr->store(drv, buf, count); + return ret; +} + +static struct sysfs_ops driver_sysfs_ops = { + .show = drv_attr_show, + .store = drv_attr_store, +}; + + +static void driver_release(struct kobject * kobj) +{ + struct device_driver * drv = to_driver(kobj); + complete(&drv->unloaded); +} + +static struct kobj_type ktype_driver = { + .sysfs_ops = &driver_sysfs_ops, + .release = driver_release, +}; + + +/* + * sysfs bindings for buses + */ + + +static ssize_t +bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) +{ + struct bus_attribute * bus_attr = to_bus_attr(attr); + struct bus_type * bus = to_bus(kobj); + ssize_t ret = 0; + + if (bus_attr->show) + ret = bus_attr->show(bus, buf); + return ret; +} + +static ssize_t +bus_attr_store(struct kobject * kobj, struct attribute * attr, + const char * buf, size_t count) +{ + struct bus_attribute * bus_attr = to_bus_attr(attr); + struct bus_type * bus = to_bus(kobj); + ssize_t ret = 0; + + if (bus_attr->store) + ret = bus_attr->store(bus, buf, count); + return ret; +} + +static struct sysfs_ops bus_sysfs_ops = { + .show = bus_attr_show, + .store = bus_attr_store, +}; + +int bus_create_file(struct bus_type * bus, struct bus_attribute * attr) +{ + int error; + if (get_bus(bus)) { + error = sysfs_create_file(&bus->subsys.kset.kobj, &attr->attr); + put_bus(bus); + } else + error = -EINVAL; + return error; +} + +void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr) +{ + if (get_bus(bus)) { + sysfs_remove_file(&bus->subsys.kset.kobj, &attr->attr); + put_bus(bus); + } +} + +static struct kobj_type ktype_bus = { + .sysfs_ops = &bus_sysfs_ops, + +}; + +decl_subsys(bus, &ktype_bus, NULL); + +static int __bus_for_each_dev(struct bus_type *bus, struct device *start, + void *data, int (*fn)(struct device *, void *)) +{ + struct list_head *head; + struct device *dev; + int error = 0; + + if (!(bus = get_bus(bus))) + return -EINVAL; + + head = &bus->devices.list; + dev = list_prepare_entry(start, head, bus_list); + list_for_each_entry_continue(dev, head, bus_list) { + get_device(dev); + error = fn(dev, data); + put_device(dev); + if (error) + break; + } + put_bus(bus); + return error; +} + +static int __bus_for_each_drv(struct bus_type *bus, struct device_driver *start, + void * data, int (*fn)(struct device_driver *, void *)) +{ + struct list_head *head; + struct device_driver *drv; + int error = 0; + + if (!(bus = get_bus(bus))) + return -EINVAL; + + head = &bus->drivers.list; + drv = list_prepare_entry(start, head, kobj.entry); + list_for_each_entry_continue(drv, head, kobj.entry) { + get_driver(drv); + error = fn(drv, data); + put_driver(drv); + if (error) + break; + } + put_bus(bus); + return error; +} + +/** + * bus_for_each_dev - device iterator. + * @bus: bus type. + * @start: device to start iterating from. + * @data: data for the callback. + * @fn: function to be called for each device. + * + * Iterate over @bus's list of devices, and call @fn for each, + * passing it @data. If @start is not NULL, we use that device to + * begin iterating from. + * + * We check the return of @fn each time. If it returns anything + * other than 0, we break out and return that value. + * + * NOTE: The device that returns a non-zero value is not retained + * in any way, nor is its refcount incremented. If the caller needs + * to retain this data, it should do, and increment the reference + * count in the supplied callback. + */ + +int bus_for_each_dev(struct bus_type * bus, struct device * start, + void * data, int (*fn)(struct device *, void *)) +{ + int ret; + + down_read(&bus->subsys.rwsem); + ret = __bus_for_each_dev(bus, start, data, fn); + up_read(&bus->subsys.rwsem); + return ret; +} + +/** + * bus_for_each_drv - driver iterator + * @bus: bus we're dealing with. + * @start: driver to start iterating on. + * @data: data to pass to the callback. + * @fn: function to call for each driver. + * + * This is nearly identical to the device iterator above. + * We iterate over each driver that belongs to @bus, and call + * @fn for each. If @fn returns anything but 0, we break out + * and return it. If @start is not NULL, we use it as the head + * of the list. + * + * NOTE: we don't return the driver that returns a non-zero + * value, nor do we leave the reference count incremented for that + * driver. If the caller needs to know that info, it must set it + * in the callback. It must also be sure to increment the refcount + * so it doesn't disappear before returning to the caller. + */ + +int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, + void * data, int (*fn)(struct device_driver *, void *)) +{ + int ret; + + down_read(&bus->subsys.rwsem); + ret = __bus_for_each_drv(bus, start, data, fn); + up_read(&bus->subsys.rwsem); + return ret; +} + +/** + * device_bind_driver - bind a driver to one device. + * @dev: device. + * + * Allow manual attachment of a driver to a device. + * Caller must have already set @dev->driver. + * + * Note that this does not modify the bus reference count + * nor take the bus's rwsem. Please verify those are accounted + * for before calling this. (It is ok to call with no other effort + * from a driver's probe() method.) + */ + +void device_bind_driver(struct device * dev) +{ + pr_debug("bound device '%s' to driver '%s'\n", + dev->bus_id, dev->driver->name); + list_add_tail(&dev->driver_list, &dev->driver->devices); + sysfs_create_link(&dev->driver->kobj, &dev->kobj, + kobject_name(&dev->kobj)); + sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); +} + + +/** + * driver_probe_device - attempt to bind device & driver. + * @drv: driver. + * @dev: device. + * + * First, we call the bus's match function, if one present, which + * should compare the device IDs the driver supports with the + * device IDs of the device. Note we don't do this ourselves + * because we don't know the format of the ID structures, nor what + * is to be considered a match and what is not. + * + * If we find a match, we call @drv->probe(@dev) if it exists, and + * call device_bind_driver() above. + */ +int driver_probe_device(struct device_driver * drv, struct device * dev) +{ + if (drv->bus->match && !drv->bus->match(dev, drv)) + return -ENODEV; + + dev->driver = drv; + if (drv->probe) { + int error = drv->probe(dev); + if (error) { + dev->driver = NULL; + return error; + } + } + + device_bind_driver(dev); + return 0; +} + + +/** + * device_attach - try to attach device to a driver. + * @dev: device. + * + * Walk the list of drivers that the bus has and call + * driver_probe_device() for each pair. If a compatible + * pair is found, break out and return. + */ +int device_attach(struct device * dev) +{ + struct bus_type * bus = dev->bus; + struct list_head * entry; + int error; + + if (dev->driver) { + device_bind_driver(dev); + return 1; + } + + if (bus->match) { + list_for_each(entry, &bus->drivers.list) { + struct device_driver * drv = to_drv(entry); + error = driver_probe_device(drv, dev); + if (!error) + /* success, driver matched */ + return 1; + if (error != -ENODEV && error != -ENXIO) + /* driver matched but the probe failed */ + printk(KERN_WARNING + "%s: probe of %s failed with error %d\n", + drv->name, dev->bus_id, error); + } + } + + return 0; +} + + +/** + * driver_attach - try to bind driver to devices. + * @drv: driver. + * + * Walk the list of devices that the bus has on it and try to + * match the driver with each one. If driver_probe_device() + * returns 0 and the @dev->driver is set, we've found a + * compatible pair. + * + * Note that we ignore the -ENODEV error from driver_probe_device(), + * since it's perfectly valid for a driver not to bind to any devices. + */ +void driver_attach(struct device_driver * drv) +{ + struct bus_type * bus = drv->bus; + struct list_head * entry; + int error; + + if (!bus->match) + return; + + list_for_each(entry, &bus->devices.list) { + struct device * dev = container_of(entry, struct device, bus_list); + if (!dev->driver) { + error = driver_probe_device(drv, dev); + if (error && (error != -ENODEV)) + /* driver matched but the probe failed */ + printk(KERN_WARNING + "%s: probe of %s failed with error %d\n", + drv->name, dev->bus_id, error); + } + } +} + + +/** + * device_release_driver - manually detach device from driver. + * @dev: device. + * + * Manually detach device from driver. + * Note that this is called without incrementing the bus + * reference count nor taking the bus's rwsem. Be sure that + * those are accounted for before calling this function. + */ + +void device_release_driver(struct device * dev) +{ + struct device_driver * drv = dev->driver; + if (drv) { + sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj)); + sysfs_remove_link(&dev->kobj, "driver"); + list_del_init(&dev->driver_list); + device_detach_shutdown(dev); + if (drv->remove) + drv->remove(dev); + dev->driver = NULL; + } +} + + +/** + * driver_detach - detach driver from all devices it controls. + * @drv: driver. + */ + +static void driver_detach(struct device_driver * drv) +{ + struct list_head * entry, * next; + list_for_each_safe(entry, next, &drv->devices) { + struct device * dev = container_of(entry, struct device, driver_list); + device_release_driver(dev); + } +} + +static int device_add_attrs(struct bus_type * bus, struct device * dev) +{ + int error = 0; + int i; + + if (bus->dev_attrs) { + for (i = 0; attr_name(bus->dev_attrs[i]); i++) { + error = device_create_file(dev,&bus->dev_attrs[i]); + if (error) + goto Err; + } + } + Done: + return error; + Err: + while (--i >= 0) + device_remove_file(dev,&bus->dev_attrs[i]); + goto Done; +} + + +static void device_remove_attrs(struct bus_type * bus, struct device * dev) +{ + int i; + + if (bus->dev_attrs) { + for (i = 0; attr_name(bus->dev_attrs[i]); i++) + device_remove_file(dev,&bus->dev_attrs[i]); + } +} + + +/** + * bus_add_device - add device to bus + * @dev: device being added + * + * - Add the device to its bus's list of devices. + * - Try to attach to driver. + * - Create link to device's physical location. + */ +int bus_add_device(struct device * dev) +{ + struct bus_type |