Lines Matching full:bus
3 * bus.c - bus driver management
12 #include <linux/device/bus.h>
42 static struct bus_type *bus_get(struct bus_type *bus) in bus_get() argument
44 if (bus) { in bus_get()
45 kset_get(&bus->p->subsys); in bus_get()
46 return bus; in bus_get()
51 static void bus_put(struct bus_type *bus) in bus_put() argument
53 if (bus) in bus_put()
54 kset_put(&bus->p->subsys); in bus_put()
110 ret = bus_attr->show(subsys_priv->bus, buf); in bus_attr_show()
122 ret = bus_attr->store(subsys_priv->bus, buf, count); in bus_attr_store()
131 int bus_create_file(struct bus_type *bus, struct bus_attribute *attr) in bus_create_file() argument
134 if (bus_get(bus)) { in bus_create_file()
135 error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr); in bus_create_file()
136 bus_put(bus); in bus_create_file()
143 void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr) in bus_remove_file() argument
145 if (bus_get(bus)) { in bus_remove_file()
146 sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); in bus_remove_file()
147 bus_put(bus); in bus_remove_file()
155 struct bus_type *bus = priv->bus; in bus_release() local
158 bus->p = NULL; in bus_release()
185 struct bus_type *bus = bus_get(drv->bus); in unbind_store() local
189 dev = bus_find_device_by_name(bus, NULL, buf); in unbind_store()
195 bus_put(bus); in unbind_store()
208 struct bus_type *bus = bus_get(drv->bus); in bind_store() local
212 dev = bus_find_device_by_name(bus, NULL, buf); in bind_store()
225 bus_put(bus); in bind_store()
230 static ssize_t drivers_autoprobe_show(struct bus_type *bus, char *buf) in drivers_autoprobe_show() argument
232 return sysfs_emit(buf, "%d\n", bus->p->drivers_autoprobe); in drivers_autoprobe_show()
235 static ssize_t drivers_autoprobe_store(struct bus_type *bus, in drivers_autoprobe_store() argument
239 bus->p->drivers_autoprobe = 0; in drivers_autoprobe_store()
241 bus->p->drivers_autoprobe = 1; in drivers_autoprobe_store()
245 static ssize_t drivers_probe_store(struct bus_type *bus, in drivers_probe_store() argument
251 dev = bus_find_device_by_name(bus, NULL, buf); in drivers_probe_store()
275 * @bus: bus type.
280 * Iterate over @bus's list of devices, and call @fn for each,
292 int bus_for_each_dev(struct bus_type *bus, struct device *start, in bus_for_each_dev() argument
299 if (!bus || !bus->p) in bus_for_each_dev()
302 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_for_each_dev()
313 * @bus: bus type
326 struct device *bus_find_device(struct bus_type *bus, in bus_find_device() argument
333 if (!bus || !bus->p) in bus_find_device()
336 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_find_device()
401 * @bus: bus we're dealing with.
407 * We iterate over each driver that belongs to @bus, and call
418 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, in bus_for_each_drv() argument
425 if (!bus) in bus_for_each_drv()
428 klist_iter_init_node(&bus->p->klist_drivers, &i, in bus_for_each_drv()
438 * bus_add_device - add device to bus
441 * - Add device's bus attributes.
442 * - Create links to device's bus.
443 * - Add the device to its bus's list of devices.
447 struct bus_type *bus = bus_get(dev->bus); in bus_add_device() local
450 if (bus) { in bus_add_device()
451 pr_debug("bus: '%s': add device %s\n", bus->name, dev_name(dev)); in bus_add_device()
452 error = device_add_groups(dev, bus->dev_groups); in bus_add_device()
455 error = sysfs_create_link(&bus->p->devices_kset->kobj, in bus_add_device()
460 &dev->bus->p->subsys.kobj, "subsystem"); in bus_add_device()
463 klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices); in bus_add_device()
468 sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); in bus_add_device()
470 device_remove_groups(dev, bus->dev_groups); in bus_add_device()
472 bus_put(dev->bus); in bus_add_device()
480 * - Automatically probe for a driver if the bus allows it.
484 struct bus_type *bus = dev->bus; in bus_probe_device() local
487 if (!bus) in bus_probe_device()
490 if (bus->p->drivers_autoprobe) in bus_probe_device()
493 mutex_lock(&bus->p->mutex); in bus_probe_device()
494 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_probe_device()
497 mutex_unlock(&bus->p->mutex); in bus_probe_device()
501 * bus_remove_device - remove device from bus
505 * - Remove symlink from bus' directory.
506 * - Delete device from bus's list.
512 struct bus_type *bus = dev->bus; in bus_remove_device() local
515 if (!bus) in bus_remove_device()
518 mutex_lock(&bus->p->mutex); in bus_remove_device()
519 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_remove_device()
522 mutex_unlock(&bus->p->mutex); in bus_remove_device()
525 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, in bus_remove_device()
527 device_remove_groups(dev, dev->bus->dev_groups); in bus_remove_device()
531 pr_debug("bus: '%s': remove device %s\n", in bus_remove_device()
532 dev->bus->name, dev_name(dev)); in bus_remove_device()
534 bus_put(dev->bus); in bus_remove_device()
559 static int add_probe_files(struct bus_type *bus) in add_probe_files() argument
563 retval = bus_create_file(bus, &bus_attr_drivers_probe); in add_probe_files()
567 retval = bus_create_file(bus, &bus_attr_drivers_autoprobe); in add_probe_files()
569 bus_remove_file(bus, &bus_attr_drivers_probe); in add_probe_files()
574 static void remove_probe_files(struct bus_type *bus) in remove_probe_files() argument
576 bus_remove_file(bus, &bus_attr_drivers_autoprobe); in remove_probe_files()
577 bus_remove_file(bus, &bus_attr_drivers_probe); in remove_probe_files()
591 * bus_add_driver - Add a driver to the bus.
596 struct bus_type *bus; in bus_add_driver() local
600 bus = bus_get(drv->bus); in bus_add_driver()
601 if (!bus) in bus_add_driver()
604 pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); in bus_add_driver()
614 priv->kobj.kset = bus->p->drivers_kset; in bus_add_driver()
620 klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); in bus_add_driver()
621 if (drv->bus->p->drivers_autoprobe) { in bus_add_driver()
633 error = driver_add_groups(drv, bus->drv_groups); in bus_add_driver()
656 bus_put(bus); in bus_add_driver()
661 * bus_remove_driver - delete driver from bus's knowledge.
665 * it from its bus's list of drivers. Finally, we drop the reference
666 * to the bus we took in bus_add_driver().
670 if (!drv->bus) in bus_remove_driver()
675 driver_remove_groups(drv, drv->bus->drv_groups); in bus_remove_driver()
678 pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); in bus_remove_driver()
682 bus_put(drv->bus); in bus_remove_driver()
692 if (dev->parent && dev->bus->need_parent_lock) in bus_rescan_devices_helper()
695 if (dev->parent && dev->bus->need_parent_lock) in bus_rescan_devices_helper()
702 * bus_rescan_devices - rescan devices on the bus for possible drivers
703 * @bus: the bus to scan.
705 * This function will look for devices on the bus with no driver
709 int bus_rescan_devices(struct bus_type *bus) in bus_rescan_devices() argument
711 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); in bus_rescan_devices()
733 * find_bus - locate bus by name.
734 * @name: name of bus.
737 * find a bus by name. Return bus if found.
739 * Note that kset_find_obj increments bus' reference count.
749 static int bus_add_groups(struct bus_type *bus, in bus_add_groups() argument
752 return sysfs_create_groups(&bus->p->subsys.kobj, groups); in bus_add_groups()
755 static void bus_remove_groups(struct bus_type *bus, in bus_remove_groups() argument
758 sysfs_remove_groups(&bus->p->subsys.kobj, groups); in bus_remove_groups()
777 static ssize_t bus_uevent_store(struct bus_type *bus, in bus_uevent_store() argument
782 rc = kobject_synth_uevent(&bus->p->subsys.kobj, buf, count); in bus_uevent_store()
796 * @bus: bus to register
798 * Once we have that, we register the bus with the kobject
802 int bus_register(struct bus_type *bus) in bus_register() argument
806 struct lock_class_key *key = &bus->lock_key; in bus_register()
812 priv->bus = bus; in bus_register()
813 bus->p = priv; in bus_register()
817 retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name); in bus_register()
829 retval = bus_create_file(bus, &bus_attr_uevent); in bus_register()
852 retval = add_probe_files(bus); in bus_register()
856 retval = bus_add_groups(bus, bus->bus_groups); in bus_register()
860 pr_debug("bus: '%s': registered\n", bus->name); in bus_register()
864 remove_probe_files(bus); in bus_register()
866 kset_unregister(bus->p->drivers_kset); in bus_register()
868 kset_unregister(bus->p->devices_kset); in bus_register()
870 bus_remove_file(bus, &bus_attr_uevent); in bus_register()
872 kset_unregister(&bus->p->subsys); in bus_register()
874 kfree(bus->p); in bus_register()
875 bus->p = NULL; in bus_register()
881 * bus_unregister - remove a bus from the system
882 * @bus: bus.
884 * Unregister the child subsystems and the bus itself.
887 void bus_unregister(struct bus_type *bus) in bus_unregister() argument
889 pr_debug("bus: '%s': unregistering\n", bus->name); in bus_unregister()
890 if (bus->dev_root) in bus_unregister()
891 device_unregister(bus->dev_root); in bus_unregister()
892 bus_remove_groups(bus, bus->bus_groups); in bus_unregister()
893 remove_probe_files(bus); in bus_unregister()
894 kset_unregister(bus->p->drivers_kset); in bus_unregister()
895 kset_unregister(bus->p->devices_kset); in bus_unregister()
896 bus_remove_file(bus, &bus_attr_uevent); in bus_unregister()
897 kset_unregister(&bus->p->subsys); in bus_unregister()
901 int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_register_notifier() argument
903 return blocking_notifier_chain_register(&bus->p->bus_notifier, nb); in bus_register_notifier()
907 int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_unregister_notifier() argument
909 return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb); in bus_unregister_notifier()
913 struct kset *bus_get_kset(struct bus_type *bus) in bus_get_kset() argument
915 return &bus->p->subsys; in bus_get_kset()
919 struct klist *bus_get_device_klist(struct bus_type *bus) in bus_get_device_klist() argument
921 return &bus->p->klist_devices; in bus_get_device_klist()
952 void bus_sort_breadthfirst(struct bus_type *bus, in bus_sort_breadthfirst() argument
962 device_klist = bus_get_device_klist(bus); in bus_sort_breadthfirst()
1190 bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); in buses_init()