13 #include <linux/device.h>
14 #include <linux/module.h>
15 #include <linux/errno.h>
16 #include <linux/slab.h>
18 #include <linux/string.h>
21 #include "power/power.h"
24 static struct kset *system_kset;
26 #define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr)
32 #define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr)
41 kset_get(&bus->
p->subsys);
47 static void bus_put(
struct bus_type *bus)
50 kset_put(&bus->
p->subsys);
66 const char *buf,
size_t count)
73 ret = drv_attr->
store(drv_priv->
driver, buf, count);
77 static const struct sysfs_ops driver_sysfs_ops = {
78 .show = drv_attr_show,
79 .store = drv_attr_store,
82 static void driver_release(
struct kobject *kobj)
86 pr_debug(
"driver: '%s': %s\n", kobject_name(kobj), __func__);
91 .sysfs_ops = &driver_sysfs_ops,
92 .release = driver_release,
106 ret = bus_attr->
show(subsys_priv->
bus, buf);
111 const char *buf,
size_t count)
118 ret = bus_attr->
store(subsys_priv->
bus, buf, count);
122 static const struct sysfs_ops bus_sysfs_ops = {
123 .show = bus_attr_show,
124 .store = bus_attr_store,
149 .sysfs_ops = &bus_sysfs_ops,
156 if (ktype == &bus_ktype)
162 .filter = bus_uevent_filter,
165 static struct kset *bus_kset;
168 #ifdef CONFIG_HOTPLUG
171 const char *buf,
size_t count)
178 if (dev && dev->
driver == drv) {
183 device_unlock(dev->
parent);
198 const char *buf,
size_t count)
205 if (dev && dev->
driver ==
NULL && driver_match_device(drv, dev)) {
212 device_unlock(dev->
parent);
217 }
else if (err == 0) {
230 return sprintf(buf,
"%d\n", bus->
p->drivers_autoprobe);
234 const char *buf,
size_t count)
237 bus->
p->drivers_autoprobe = 0;
239 bus->
p->drivers_autoprobe = 1;
244 const char *buf,
size_t count)
251 if (bus_rescan_devices_helper(dev,
NULL) != 0)
300 (start ? &start->
p->knode_bus :
NULL));
301 while ((dev = next_device(&i)) && !error)
302 error =
fn(dev, data);
324 struct device *start,
void *data,
334 (start ? &start->
p->knode_bus :
NULL));
335 while ((dev = next_device(&i)))
343 static int match_name(
struct device *dev,
void *data)
361 struct device *start,
const char *name)
388 dev = next_device(&i);
397 while ((dev = next_device(&i))) {
450 start ? &start->
p->knode_bus :
NULL);
451 while ((drv = next_driver(&i)) && !error)
452 error =
fn(drv, data);
458 static int device_add_attrs(
struct bus_type *bus,
struct device *dev)
477 static void device_remove_attrs(
struct bus_type *bus,
struct device *dev)
502 error = device_add_attrs(bus, dev);
510 &dev->
bus->p->subsys.kobj,
"subsystem");
520 device_remove_attrs(bus, dev);
541 if (bus->
p->drivers_autoprobe) {
580 device_remove_attrs(dev->
bus, dev);
584 pr_debug(
"bus: '%s': remove device %s\n",
585 dev->
bus->name, dev_name(dev));
610 static void driver_remove_attrs(
struct bus_type *bus,
621 #ifdef CONFIG_HOTPLUG
647 show_drivers_autoprobe, store_drivers_autoprobe);
649 static int add_probe_files(
struct bus_type *bus)
664 static void remove_probe_files(
struct bus_type *bus)
670 static inline int add_bind_files(
struct device_driver *drv) {
return 0; }
671 static inline void remove_bind_files(
struct device_driver *drv) {}
672 static inline int add_probe_files(
struct bus_type *bus) {
return 0; }
673 static inline void remove_probe_files(
struct bus_type *bus) {}
677 const char *buf,
size_t count)
697 bus = bus_get(drv->
bus);
711 priv->
kobj.kset = bus->
p->drivers_kset;
717 if (drv->
bus->p->drivers_autoprobe) {
728 __func__, drv->
name);
730 error = driver_add_attrs(bus, drv);
734 __func__, drv->
name);
738 error = add_bind_files(drv);
742 __func__, drv->
name);
771 remove_bind_files(drv);
772 driver_remove_attrs(drv->
bus, drv);
793 device_unlock(dev->
parent);
795 return ret < 0 ? ret : 0;
828 device_unlock(dev->
parent);
830 return bus_rescan_devices_helper(dev,
NULL);
844 struct bus_type *find_bus(
char *name)
847 return k ? to_bus(k) :
NULL;
857 static int bus_add_attrs(
struct bus_type *bus)
877 static void bus_remove_attrs(
struct bus_type *bus)
887 static void klist_devices_get(
struct klist_node *n)
895 static void klist_devices_put(
struct klist_node *n)
904 const char *buf,
size_t count)
941 priv->
subsys.kobj.kset = bus_kset;
942 priv->
subsys.kobj.ktype = &bus_ktype;
951 goto bus_uevent_fail;
957 goto bus_devices_fail;
964 goto bus_drivers_fail;
972 retval = add_probe_files(bus);
974 goto bus_probe_files_fail;
976 retval = bus_add_attrs(bus);
984 remove_probe_files(bus);
985 bus_probe_files_fail:
1012 bus_remove_attrs(bus);
1013 remove_probe_files(bus);
1037 return &bus->
p->subsys;
1043 return &bus->
p->klist_devices;
1055 int (*compare)(
const struct device *a,
1067 if (compare(a, b) <= 0) {
1068 list_move_tail(&a->
p->knode_bus.n_node,
1069 &b->
p->knode_bus.n_node);
1073 list_move_tail(&a->
p->knode_bus.n_node, list);
1077 int (*compare)(
const struct device *a,
1085 struct klist *device_klist;
1089 spin_lock(&device_klist->
k_lock);
1094 device_insertion_sort_klist(dev, &sorted_devices, compare);
1096 list_splice(&sorted_devices, &device_klist->
k_list);
1097 spin_unlock(&device_klist->
k_lock);
1119 start_knode = &start->
p->knode_bus;
1172 if (!sif || !sif->
subsys)
1175 subsys = bus_get(sif->
subsys);
1199 if (!sif || !sif->
subsys)
1205 list_del_init(&sif->
node);
1218 static void system_root_device_release(
struct device *dev)
1260 dev->
kobj.parent = &system_kset->
kobj;
1262 dev->
release = system_root_device_release;