Lines Matching refs:bus
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()
153 struct bus_type *bus = priv->bus; in bus_release() local
156 bus->p = NULL; in bus_release()
183 struct bus_type *bus = bus_get(drv->bus); in unbind_store() local
187 dev = bus_find_device_by_name(bus, NULL, buf); in unbind_store()
197 bus_put(bus); in unbind_store()
210 struct bus_type *bus = bus_get(drv->bus); in bind_store() local
214 dev = bus_find_device_by_name(bus, NULL, buf); in bind_store()
233 bus_put(bus); in bind_store()
238 static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) in show_drivers_autoprobe() argument
240 return sprintf(buf, "%d\n", bus->p->drivers_autoprobe); in show_drivers_autoprobe()
243 static ssize_t store_drivers_autoprobe(struct bus_type *bus, in store_drivers_autoprobe() argument
247 bus->p->drivers_autoprobe = 0; in store_drivers_autoprobe()
249 bus->p->drivers_autoprobe = 1; in store_drivers_autoprobe()
253 static ssize_t store_drivers_probe(struct bus_type *bus, in store_drivers_probe() argument
259 dev = bus_find_device_by_name(bus, NULL, buf); in store_drivers_probe()
300 int bus_for_each_dev(struct bus_type *bus, struct device *start, in bus_for_each_dev() argument
307 if (!bus || !bus->p) in bus_for_each_dev()
310 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_for_each_dev()
334 struct device *bus_find_device(struct bus_type *bus, in bus_find_device() argument
341 if (!bus || !bus->p) in bus_find_device()
344 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_find_device()
371 struct device *bus_find_device_by_name(struct bus_type *bus, in bus_find_device_by_name() argument
374 return bus_find_device(bus, start, (void *)name, match_name); in bus_find_device_by_name()
450 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, in bus_for_each_drv() argument
457 if (!bus) in bus_for_each_drv()
460 klist_iter_init_node(&bus->p->klist_drivers, &i, in bus_for_each_drv()
469 static int device_add_attrs(struct bus_type *bus, struct device *dev) in device_add_attrs() argument
474 if (!bus->dev_attrs) in device_add_attrs()
477 for (i = 0; bus->dev_attrs[i].attr.name; i++) { in device_add_attrs()
478 error = device_create_file(dev, &bus->dev_attrs[i]); in device_add_attrs()
481 device_remove_file(dev, &bus->dev_attrs[i]); in device_add_attrs()
488 static void device_remove_attrs(struct bus_type *bus, struct device *dev) in device_remove_attrs() argument
492 if (bus->dev_attrs) { in device_remove_attrs()
493 for (i = 0; bus->dev_attrs[i].attr.name; i++) in device_remove_attrs()
494 device_remove_file(dev, &bus->dev_attrs[i]); in device_remove_attrs()
508 struct bus_type *bus = bus_get(dev->bus); in bus_add_device() local
511 if (bus) { in bus_add_device()
512 pr_debug("bus: '%s': add device %s\n", bus->name, dev_name(dev)); in bus_add_device()
513 error = device_add_attrs(bus, dev); in bus_add_device()
516 error = device_add_groups(dev, bus->dev_groups); in bus_add_device()
519 error = sysfs_create_link(&bus->p->devices_kset->kobj, in bus_add_device()
524 &dev->bus->p->subsys.kobj, "subsystem"); in bus_add_device()
527 klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices); in bus_add_device()
532 sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); in bus_add_device()
534 device_remove_groups(dev, bus->dev_groups); in bus_add_device()
536 device_remove_attrs(bus, dev); in bus_add_device()
538 bus_put(dev->bus); in bus_add_device()
550 struct bus_type *bus = dev->bus; in bus_probe_device() local
554 if (!bus) in bus_probe_device()
557 if (bus->p->drivers_autoprobe) { in bus_probe_device()
562 mutex_lock(&bus->p->mutex); in bus_probe_device()
563 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_probe_device()
566 mutex_unlock(&bus->p->mutex); in bus_probe_device()
581 struct bus_type *bus = dev->bus; in bus_remove_device() local
584 if (!bus) in bus_remove_device()
587 mutex_lock(&bus->p->mutex); in bus_remove_device()
588 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_remove_device()
591 mutex_unlock(&bus->p->mutex); in bus_remove_device()
594 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, in bus_remove_device()
596 device_remove_attrs(dev->bus, dev); in bus_remove_device()
597 device_remove_groups(dev, dev->bus->dev_groups); in bus_remove_device()
602 dev->bus->name, dev_name(dev)); in bus_remove_device()
604 bus_put(dev->bus); in bus_remove_device()
630 static int add_probe_files(struct bus_type *bus) in add_probe_files() argument
634 retval = bus_create_file(bus, &bus_attr_drivers_probe); in add_probe_files()
638 retval = bus_create_file(bus, &bus_attr_drivers_autoprobe); in add_probe_files()
640 bus_remove_file(bus, &bus_attr_drivers_probe); in add_probe_files()
645 static void remove_probe_files(struct bus_type *bus) in remove_probe_files() argument
647 bus_remove_file(bus, &bus_attr_drivers_autoprobe); in remove_probe_files()
648 bus_remove_file(bus, &bus_attr_drivers_probe); in remove_probe_files()
668 struct bus_type *bus; in bus_add_driver() local
672 bus = bus_get(drv->bus); in bus_add_driver()
673 if (!bus) in bus_add_driver()
676 pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); in bus_add_driver()
686 priv->kobj.kset = bus->p->drivers_kset; in bus_add_driver()
692 klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); in bus_add_driver()
693 if (drv->bus->p->drivers_autoprobe) { in bus_add_driver()
705 error = driver_add_groups(drv, bus->drv_groups); in bus_add_driver()
728 bus_put(bus); in bus_add_driver()
742 if (!drv->bus) in bus_remove_driver()
747 driver_remove_groups(drv, drv->bus->drv_groups); in bus_remove_driver()
750 pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); in bus_remove_driver()
754 bus_put(drv->bus); in bus_remove_driver()
781 int bus_rescan_devices(struct bus_type *bus) in bus_rescan_devices() argument
783 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); in bus_rescan_devices()
826 static int bus_add_groups(struct bus_type *bus, in bus_add_groups() argument
829 return sysfs_create_groups(&bus->p->subsys.kobj, groups); in bus_add_groups()
832 static void bus_remove_groups(struct bus_type *bus, in bus_remove_groups() argument
835 sysfs_remove_groups(&bus->p->subsys.kobj, groups); in bus_remove_groups()
854 static ssize_t bus_uevent_store(struct bus_type *bus, in bus_uevent_store() argument
860 kobject_uevent(&bus->p->subsys.kobj, action); in bus_uevent_store()
873 int bus_register(struct bus_type *bus) in bus_register() argument
877 struct lock_class_key *key = &bus->lock_key; in bus_register()
883 priv->bus = bus; in bus_register()
884 bus->p = priv; in bus_register()
888 retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name); in bus_register()
900 retval = bus_create_file(bus, &bus_attr_uevent); in bus_register()
923 retval = add_probe_files(bus); in bus_register()
927 retval = bus_add_groups(bus, bus->bus_groups); in bus_register()
931 pr_debug("bus: '%s': registered\n", bus->name); in bus_register()
935 remove_probe_files(bus); in bus_register()
937 kset_unregister(bus->p->drivers_kset); in bus_register()
939 kset_unregister(bus->p->devices_kset); in bus_register()
941 bus_remove_file(bus, &bus_attr_uevent); in bus_register()
943 kset_unregister(&bus->p->subsys); in bus_register()
945 kfree(bus->p); in bus_register()
946 bus->p = NULL; in bus_register()
958 void bus_unregister(struct bus_type *bus) in bus_unregister() argument
960 pr_debug("bus: '%s': unregistering\n", bus->name); in bus_unregister()
961 if (bus->dev_root) in bus_unregister()
962 device_unregister(bus->dev_root); in bus_unregister()
963 bus_remove_groups(bus, bus->bus_groups); in bus_unregister()
964 remove_probe_files(bus); in bus_unregister()
965 kset_unregister(bus->p->drivers_kset); in bus_unregister()
966 kset_unregister(bus->p->devices_kset); in bus_unregister()
967 bus_remove_file(bus, &bus_attr_uevent); in bus_unregister()
968 kset_unregister(&bus->p->subsys); in bus_unregister()
972 int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_register_notifier() argument
974 return blocking_notifier_chain_register(&bus->p->bus_notifier, nb); in bus_register_notifier()
978 int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_unregister_notifier() argument
980 return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb); in bus_unregister_notifier()
984 struct kset *bus_get_kset(struct bus_type *bus) in bus_get_kset() argument
986 return &bus->p->subsys; in bus_get_kset()
990 struct klist *bus_get_device_klist(struct bus_type *bus) in bus_get_device_klist() argument
992 return &bus->p->klist_devices; in bus_get_device_klist()
1025 void bus_sort_breadthfirst(struct bus_type *bus, in bus_sort_breadthfirst() argument
1036 device_klist = bus_get_device_klist(bus); in bus_sort_breadthfirst()