Lines Matching full:bus

2  * bus.c - bus driver management
39 static struct bus_type *bus_get(struct bus_type *bus) in bus_get() argument
41 if (bus) { in bus_get()
42 kset_get(&bus->p->subsys); in bus_get()
43 return bus; in bus_get()
48 static void bus_put(struct bus_type *bus) in bus_put() argument
50 if (bus) in bus_put()
51 kset_put(&bus->p->subsys); in bus_put()
107 ret = bus_attr->show(subsys_priv->bus, buf); in bus_attr_show()
119 ret = bus_attr->store(subsys_priv->bus, buf, count); in bus_attr_store()
128 int bus_create_file(struct bus_type *bus, struct bus_attribute *attr) in bus_create_file() argument
131 if (bus_get(bus)) { in bus_create_file()
132 error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr); in bus_create_file()
133 bus_put(bus); in bus_create_file()
140 void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr) in bus_remove_file() argument
142 if (bus_get(bus)) { in bus_remove_file()
143 sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); in bus_remove_file()
144 bus_put(bus); in bus_remove_file()
174 struct bus_type *bus = bus_get(drv->bus); in driver_unbind() local
178 dev = bus_find_device_by_name(bus, NULL, buf); in driver_unbind()
188 bus_put(bus); in driver_unbind()
201 struct bus_type *bus = bus_get(drv->bus); in driver_bind() local
205 dev = bus_find_device_by_name(bus, NULL, buf); in driver_bind()
224 bus_put(bus); in driver_bind()
229 static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) in show_drivers_autoprobe() argument
231 return sprintf(buf, "%d\n", bus->p->drivers_autoprobe); in show_drivers_autoprobe()
234 static ssize_t store_drivers_autoprobe(struct bus_type *bus, in store_drivers_autoprobe() argument
238 bus->p->drivers_autoprobe = 0; in store_drivers_autoprobe()
240 bus->p->drivers_autoprobe = 1; in store_drivers_autoprobe()
244 static ssize_t store_drivers_probe(struct bus_type *bus, in store_drivers_probe() argument
249 dev = bus_find_device_by_name(bus, NULL, buf); in store_drivers_probe()
273 * @bus: bus type.
278 * Iterate over @bus's list of devices, and call @fn for each,
290 int bus_for_each_dev(struct bus_type *bus, struct device *start, in bus_for_each_dev() argument
297 if (!bus) in bus_for_each_dev()
300 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_for_each_dev()
311 * @bus: bus type
324 struct device *bus_find_device(struct bus_type *bus, in bus_find_device() argument
331 if (!bus) in bus_find_device()
334 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_find_device()
353 * @bus: bus type
361 struct device *bus_find_device_by_name(struct bus_type *bus, in bus_find_device_by_name() argument
364 return bus_find_device(bus, start, (void *)name, match_name); in bus_find_device_by_name()
423 * @bus: bus we're dealing with.
429 * We iterate over each driver that belongs to @bus, and call
440 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, in bus_for_each_drv() argument
447 if (!bus) in bus_for_each_drv()
450 klist_iter_init_node(&bus->p->klist_drivers, &i, in bus_for_each_drv()
459 static int device_add_attrs(struct bus_type *bus, struct device *dev) in device_add_attrs() argument
464 if (!bus->dev_attrs) in device_add_attrs()
467 for (i = 0; attr_name(bus->dev_attrs[i]); i++) { in device_add_attrs()
468 error = device_create_file(dev, &bus->dev_attrs[i]); in device_add_attrs()
471 device_remove_file(dev, &bus->dev_attrs[i]); in device_add_attrs()
478 static void device_remove_attrs(struct bus_type *bus, struct device *dev) in device_remove_attrs() argument
482 if (bus->dev_attrs) { in device_remove_attrs()
483 for (i = 0; attr_name(bus->dev_attrs[i]); i++) in device_remove_attrs()
484 device_remove_file(dev, &bus->dev_attrs[i]); in device_remove_attrs()
489 * bus_add_device - add device to bus
492 * - Add device's bus attributes.
493 * - Create links to device's bus.
494 * - Add the device to its bus's list of devices.
498 struct bus_type *bus = bus_get(dev->bus); in bus_add_device() local
501 if (bus) { in bus_add_device()
502 pr_debug("bus: '%s': add device %s\n", bus->name, dev_name(dev)); in bus_add_device()
503 error = device_add_attrs(bus, dev); in bus_add_device()
506 error = sysfs_create_link(&bus->p->devices_kset->kobj, in bus_add_device()
511 &dev->bus->p->subsys.kobj, "subsystem"); in bus_add_device()
514 klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices); in bus_add_device()
519 sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); in bus_add_device()
521 device_remove_attrs(bus, dev); in bus_add_device()
523 bus_put(dev->bus); in bus_add_device()
531 * - Automatically probe for a driver if the bus allows it.
535 struct bus_type *bus = dev->bus; in bus_probe_device() local
539 if (!bus) in bus_probe_device()
542 if (bus->p->drivers_autoprobe) { in bus_probe_device()
547 mutex_lock(&bus->p->mutex); in bus_probe_device()
548 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_probe_device()
551 mutex_unlock(&bus->p->mutex); in bus_probe_device()
555 * bus_remove_device - remove device from bus
559 * - Remove symlink from bus' directory.
560 * - Delete device from bus's list.
566 struct bus_type *bus = dev->bus; in bus_remove_device() local
569 if (!bus) in bus_remove_device()
572 mutex_lock(&bus->p->mutex); in bus_remove_device()
573 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_remove_device()
576 mutex_unlock(&bus->p->mutex); in bus_remove_device()
579 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, in bus_remove_device()
581 device_remove_attrs(dev->bus, dev); in bus_remove_device()
585 pr_debug("bus: '%s': remove device %s\n", in bus_remove_device()
586 dev->bus->name, dev_name(dev)); in bus_remove_device()
588 bus_put(dev->bus); in bus_remove_device()
591 static int driver_add_attrs(struct bus_type *bus, struct device_driver *drv) in driver_add_attrs() argument
596 if (bus->drv_attrs) { in driver_add_attrs()
597 for (i = 0; attr_name(bus->drv_attrs[i]); i++) { in driver_add_attrs()
598 error = driver_create_file(drv, &bus->drv_attrs[i]); in driver_add_attrs()
607 driver_remove_file(drv, &bus->drv_attrs[i]); in driver_add_attrs()
611 static void driver_remove_attrs(struct bus_type *bus, in driver_remove_attrs() argument
616 if (bus->drv_attrs) { in driver_remove_attrs()
617 for (i = 0; attr_name(bus->drv_attrs[i]); i++) in driver_remove_attrs()
618 driver_remove_file(drv, &bus->drv_attrs[i]); in driver_remove_attrs()
650 static int add_probe_files(struct bus_type *bus) in add_probe_files() argument
654 retval = bus_create_file(bus, &bus_attr_drivers_probe); in add_probe_files()
658 retval = bus_create_file(bus, &bus_attr_drivers_autoprobe); in add_probe_files()
660 bus_remove_file(bus, &bus_attr_drivers_probe); in add_probe_files()
665 static void remove_probe_files(struct bus_type *bus) in remove_probe_files() argument
667 bus_remove_file(bus, &bus_attr_drivers_autoprobe); in remove_probe_files()
668 bus_remove_file(bus, &bus_attr_drivers_probe); in remove_probe_files()
673 static inline int add_probe_files(struct bus_type *bus) { return 0; } in add_probe_files() argument
674 static inline void remove_probe_files(struct bus_type *bus) {} in remove_probe_files() argument
689 * bus_add_driver - Add a driver to the bus.
694 struct bus_type *bus; in bus_add_driver() local
698 bus = bus_get(drv->bus); in bus_add_driver()
699 if (!bus) in bus_add_driver()
702 pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); in bus_add_driver()
712 priv->kobj.kset = bus->p->drivers_kset; in bus_add_driver()
718 if (drv->bus->p->drivers_autoprobe) { in bus_add_driver()
723 klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); in bus_add_driver()
731 error = driver_add_attrs(bus, drv); in bus_add_driver()
755 bus_put(bus); in bus_add_driver()
760 * bus_remove_driver - delete driver from bus's knowledge.
764 * it from its bus's list of drivers. Finally, we drop the reference
765 * to the bus we took in bus_add_driver().
769 if (!drv->bus) in bus_remove_driver()
774 driver_remove_attrs(drv->bus, drv); in bus_remove_driver()
777 pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); in bus_remove_driver()
781 bus_put(drv->bus); in bus_remove_driver()
801 * bus_rescan_devices - rescan devices on the bus for possible drivers
802 * @bus: the bus to scan.
804 * This function will look for devices on the bus with no driver
808 int bus_rescan_devices(struct bus_type *bus) in bus_rescan_devices() argument
810 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); in bus_rescan_devices()
837 * find_bus - locate bus by name.
838 * @name: name of bus.
841 * find a bus by name. Return bus if found.
843 * Note that kset_find_obj increments bus' reference count.
855 * bus_add_attrs - Add default attributes for this bus.
856 * @bus: Bus that has just been registered.
859 static int bus_add_attrs(struct bus_type *bus) in bus_add_attrs() argument
864 if (bus->bus_attrs) { in bus_add_attrs()
865 for (i = 0; attr_name(bus->bus_attrs[i]); i++) { in bus_add_attrs()
866 error = bus_create_file(bus, &bus->bus_attrs[i]); in bus_add_attrs()
875 bus_remove_file(bus, &bus->bus_attrs[i]); in bus_add_attrs()
879 static void bus_remove_attrs(struct bus_type *bus) in bus_remove_attrs() argument
883 if (bus->bus_attrs) { in bus_remove_attrs()
884 for (i = 0; attr_name(bus->bus_attrs[i]); i++) in bus_remove_attrs()
885 bus_remove_file(bus, &bus->bus_attrs[i]); in bus_remove_attrs()
905 static ssize_t bus_uevent_store(struct bus_type *bus, in bus_uevent_store() argument
911 kobject_uevent(&bus->p->subsys.kobj, action); in bus_uevent_store()
918 * @bus: bus to register
921 * Once we have that, we register the bus with the kobject
925 int __bus_register(struct bus_type *bus, struct lock_class_key *key) in __bus_register() argument
934 priv->bus = bus; in __bus_register()
935 bus->p = priv; in __bus_register()
939 retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name); in __bus_register()
951 retval = bus_create_file(bus, &bus_attr_uevent); in __bus_register()
974 retval = add_probe_files(bus); in __bus_register()
978 retval = bus_add_attrs(bus); in __bus_register()
982 pr_debug("bus: '%s': registered\n", bus->name); in __bus_register()
986 remove_probe_files(bus); in __bus_register()
988 kset_unregister(bus->p->drivers_kset); in __bus_register()
990 kset_unregister(bus->p->devices_kset); in __bus_register()
992 bus_remove_file(bus, &bus_attr_uevent); in __bus_register()
994 kset_unregister(&bus->p->subsys); in __bus_register()
996 kfree(bus->p); in __bus_register()
997 bus->p = NULL; in __bus_register()
1003 * bus_unregister - remove a bus from the system
1004 * @bus: bus.
1006 * Unregister the child subsystems and the bus itself.
1009 void bus_unregister(struct bus_type *bus) in bus_unregister() argument
1011 pr_debug("bus: '%s': unregistering\n", bus->name); in bus_unregister()
1012 if (bus->dev_root) in bus_unregister()
1013 device_unregister(bus->dev_root); in bus_unregister()
1014 bus_remove_attrs(bus); in bus_unregister()
1015 remove_probe_files(bus); in bus_unregister()
1016 kset_unregister(bus->p->drivers_kset); in bus_unregister()
1017 kset_unregister(bus->p->devices_kset); in bus_unregister()
1018 bus_remove_file(bus, &bus_attr_uevent); in bus_unregister()
1019 kset_unregister(&bus->p->subsys); in bus_unregister()
1020 kfree(bus->p); in bus_unregister()
1021 bus->p = NULL; in bus_unregister()
1025 int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_register_notifier() argument
1027 return blocking_notifier_chain_register(&bus->p->bus_notifier, nb); in bus_register_notifier()
1031 int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_unregister_notifier() argument
1033 return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb); in bus_unregister_notifier()
1037 struct kset *bus_get_kset(struct bus_type *bus) in bus_get_kset() argument
1039 return &bus->p->subsys; in bus_get_kset()
1043 struct klist *bus_get_device_klist(struct bus_type *bus) in bus_get_device_klist() argument
1045 return &bus->p->klist_devices; in bus_get_device_klist()
1078 void bus_sort_breadthfirst(struct bus_type *bus, in bus_sort_breadthfirst() argument
1089 device_klist = bus_get_device_klist(bus); in bus_sort_breadthfirst()
1284 bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); in buses_init()