Lines Matching full:bus
3 * bus.c - bus driver management
41 static struct bus_type *bus_get(struct bus_type *bus) in bus_get() argument
43 if (bus) { in bus_get()
44 kset_get(&bus->p->subsys); in bus_get()
45 return bus; in bus_get()
50 static void bus_put(struct bus_type *bus) in bus_put() argument
52 if (bus) in bus_put()
53 kset_put(&bus->p->subsys); in bus_put()
109 ret = bus_attr->show(subsys_priv->bus, buf); in bus_attr_show()
121 ret = bus_attr->store(subsys_priv->bus, buf, count); in bus_attr_store()
130 int bus_create_file(struct bus_type *bus, struct bus_attribute *attr) in bus_create_file() argument
133 if (bus_get(bus)) { in bus_create_file()
134 error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr); in bus_create_file()
135 bus_put(bus); in bus_create_file()
142 void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr) in bus_remove_file() argument
144 if (bus_get(bus)) { in bus_remove_file()
145 sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); in bus_remove_file()
146 bus_put(bus); in bus_remove_file()
154 struct bus_type *bus = priv->bus; in bus_release() local
157 bus->p = NULL; in bus_release()
184 struct bus_type *bus = bus_get(drv->bus); in unbind_store() local
188 dev = bus_find_device_by_name(bus, NULL, buf); in unbind_store()
194 bus_put(bus); in unbind_store()
207 struct bus_type *bus = bus_get(drv->bus); in bind_store() local
211 dev = bus_find_device_by_name(bus, NULL, buf); in bind_store()
224 bus_put(bus); in bind_store()
229 static ssize_t drivers_autoprobe_show(struct bus_type *bus, char *buf) in drivers_autoprobe_show() argument
231 return sprintf(buf, "%d\n", bus->p->drivers_autoprobe); in drivers_autoprobe_show()
234 static ssize_t drivers_autoprobe_store(struct bus_type *bus, in drivers_autoprobe_store() argument
238 bus->p->drivers_autoprobe = 0; in drivers_autoprobe_store()
240 bus->p->drivers_autoprobe = 1; in drivers_autoprobe_store()
244 static ssize_t drivers_probe_store(struct bus_type *bus, in drivers_probe_store() argument
250 dev = bus_find_device_by_name(bus, NULL, buf); in drivers_probe_store()
274 * @bus: bus type.
279 * Iterate over @bus's list of devices, and call @fn for each,
291 int bus_for_each_dev(struct bus_type *bus, struct device *start, in bus_for_each_dev() argument
298 if (!bus || !bus->p) in bus_for_each_dev()
301 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_for_each_dev()
312 * @bus: bus type
325 struct device *bus_find_device(struct bus_type *bus, in bus_find_device() argument
332 if (!bus || !bus->p) in bus_find_device()
335 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_find_device()
400 * @bus: bus we're dealing with.
406 * We iterate over each driver that belongs to @bus, and call
417 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, in bus_for_each_drv() argument
424 if (!bus) in bus_for_each_drv()
427 klist_iter_init_node(&bus->p->klist_drivers, &i, in bus_for_each_drv()
437 * bus_add_device - add device to bus
440 * - Add device's bus attributes.
441 * - Create links to device's bus.
442 * - Add the device to its bus's list of devices.
446 struct bus_type *bus = bus_get(dev->bus); in bus_add_device() local
449 if (bus) { in bus_add_device()
450 pr_debug("bus: '%s': add device %s\n", bus->name, dev_name(dev)); in bus_add_device()
451 error = device_add_groups(dev, bus->dev_groups); in bus_add_device()
454 error = sysfs_create_link(&bus->p->devices_kset->kobj, in bus_add_device()
459 &dev->bus->p->subsys.kobj, "subsystem"); in bus_add_device()
462 klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices); in bus_add_device()
467 sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); in bus_add_device()
469 device_remove_groups(dev, bus->dev_groups); in bus_add_device()
471 bus_put(dev->bus); in bus_add_device()
479 * - Automatically probe for a driver if the bus allows it.
483 struct bus_type *bus = dev->bus; in bus_probe_device() local
486 if (!bus) in bus_probe_device()
489 if (bus->p->drivers_autoprobe) in bus_probe_device()
492 mutex_lock(&bus->p->mutex); in bus_probe_device()
493 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_probe_device()
496 mutex_unlock(&bus->p->mutex); in bus_probe_device()
500 * bus_remove_device - remove device from bus
504 * - Remove symlink from bus' directory.
505 * - Delete device from bus's list.
511 struct bus_type *bus = dev->bus; in bus_remove_device() local
514 if (!bus) in bus_remove_device()
517 mutex_lock(&bus->p->mutex); in bus_remove_device()
518 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_remove_device()
521 mutex_unlock(&bus->p->mutex); in bus_remove_device()
524 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, in bus_remove_device()
526 device_remove_groups(dev, dev->bus->dev_groups); in bus_remove_device()
530 pr_debug("bus: '%s': remove device %s\n", in bus_remove_device()
531 dev->bus->name, dev_name(dev)); in bus_remove_device()
533 bus_put(dev->bus); in bus_remove_device()
558 static int add_probe_files(struct bus_type *bus) in add_probe_files() argument
562 retval = bus_create_file(bus, &bus_attr_drivers_probe); in add_probe_files()
566 retval = bus_create_file(bus, &bus_attr_drivers_autoprobe); in add_probe_files()
568 bus_remove_file(bus, &bus_attr_drivers_probe); in add_probe_files()
573 static void remove_probe_files(struct bus_type *bus) in remove_probe_files() argument
575 bus_remove_file(bus, &bus_attr_drivers_autoprobe); in remove_probe_files()
576 bus_remove_file(bus, &bus_attr_drivers_probe); in remove_probe_files()
590 * bus_add_driver - Add a driver to the bus.
595 struct bus_type *bus; in bus_add_driver() local
599 bus = bus_get(drv->bus); in bus_add_driver()
600 if (!bus) in bus_add_driver()
603 pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); in bus_add_driver()
613 priv->kobj.kset = bus->p->drivers_kset; in bus_add_driver()
619 klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); in bus_add_driver()
620 if (drv->bus->p->drivers_autoprobe) { in bus_add_driver()
632 error = driver_add_groups(drv, bus->drv_groups); in bus_add_driver()
655 bus_put(bus); in bus_add_driver()
660 * bus_remove_driver - delete driver from bus's knowledge.
664 * it from its bus's list of drivers. Finally, we drop the reference
665 * to the bus we took in bus_add_driver().
669 if (!drv->bus) in bus_remove_driver()
674 driver_remove_groups(drv, drv->bus->drv_groups); in bus_remove_driver()
677 pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); in bus_remove_driver()
681 bus_put(drv->bus); in bus_remove_driver()
691 if (dev->parent && dev->bus->need_parent_lock) in bus_rescan_devices_helper()
694 if (dev->parent && dev->bus->need_parent_lock) in bus_rescan_devices_helper()
701 * bus_rescan_devices - rescan devices on the bus for possible drivers
702 * @bus: the bus to scan.
704 * This function will look for devices on the bus with no driver
708 int bus_rescan_devices(struct bus_type *bus) in bus_rescan_devices() argument
710 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); in bus_rescan_devices()
732 * find_bus - locate bus by name.
733 * @name: name of bus.
736 * find a bus by name. Return bus if found.
738 * Note that kset_find_obj increments bus' reference count.
748 static int bus_add_groups(struct bus_type *bus, in bus_add_groups() argument
751 return sysfs_create_groups(&bus->p->subsys.kobj, groups); in bus_add_groups()
754 static void bus_remove_groups(struct bus_type *bus, in bus_remove_groups() argument
757 sysfs_remove_groups(&bus->p->subsys.kobj, groups); in bus_remove_groups()
776 static ssize_t bus_uevent_store(struct bus_type *bus, in bus_uevent_store() argument
781 rc = kobject_synth_uevent(&bus->p->subsys.kobj, buf, count); in bus_uevent_store()
795 * @bus: bus to register
797 * Once we have that, we register the bus with the kobject
801 int bus_register(struct bus_type *bus) in bus_register() argument
805 struct lock_class_key *key = &bus->lock_key; in bus_register()
811 priv->bus = bus; in bus_register()
812 bus->p = priv; in bus_register()
816 retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name); in bus_register()
828 retval = bus_create_file(bus, &bus_attr_uevent); in bus_register()
851 retval = add_probe_files(bus); in bus_register()
855 retval = bus_add_groups(bus, bus->bus_groups); in bus_register()
859 pr_debug("bus: '%s': registered\n", bus->name); in bus_register()
863 remove_probe_files(bus); in bus_register()
865 kset_unregister(bus->p->drivers_kset); in bus_register()
867 kset_unregister(bus->p->devices_kset); in bus_register()
869 bus_remove_file(bus, &bus_attr_uevent); in bus_register()
871 kset_unregister(&bus->p->subsys); in bus_register()
873 kfree(bus->p); in bus_register()
874 bus->p = NULL; in bus_register()
880 * bus_unregister - remove a bus from the system
881 * @bus: bus.
883 * Unregister the child subsystems and the bus itself.
886 void bus_unregister(struct bus_type *bus) in bus_unregister() argument
888 pr_debug("bus: '%s': unregistering\n", bus->name); in bus_unregister()
889 if (bus->dev_root) in bus_unregister()
890 device_unregister(bus->dev_root); in bus_unregister()
891 bus_remove_groups(bus, bus->bus_groups); in bus_unregister()
892 remove_probe_files(bus); in bus_unregister()
893 kset_unregister(bus->p->drivers_kset); in bus_unregister()
894 kset_unregister(bus->p->devices_kset); in bus_unregister()
895 bus_remove_file(bus, &bus_attr_uevent); in bus_unregister()
896 kset_unregister(&bus->p->subsys); in bus_unregister()
900 int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_register_notifier() argument
902 return blocking_notifier_chain_register(&bus->p->bus_notifier, nb); in bus_register_notifier()
906 int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_unregister_notifier() argument
908 return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb); in bus_unregister_notifier()
912 struct kset *bus_get_kset(struct bus_type *bus) in bus_get_kset() argument
914 return &bus->p->subsys; in bus_get_kset()
918 struct klist *bus_get_device_klist(struct bus_type *bus) in bus_get_device_klist() argument
920 return &bus->p->klist_devices; in bus_get_device_klist()
951 void bus_sort_breadthfirst(struct bus_type *bus, in bus_sort_breadthfirst() argument
961 device_klist = bus_get_device_klist(bus); in bus_sort_breadthfirst()
1189 bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); in buses_init()