Lines Matching refs:bus

40 static struct bus_type *bus_get(struct bus_type *bus)  in bus_get()  argument
42 if (bus) { in bus_get()
43 kset_get(&bus->p->subsys); in bus_get()
44 return bus; in bus_get()
49 static void bus_put(struct bus_type *bus) in bus_put() argument
51 if (bus) in bus_put()
52 kset_put(&bus->p->subsys); in bus_put()
108 ret = bus_attr->show(subsys_priv->bus, buf); in bus_attr_show()
120 ret = bus_attr->store(subsys_priv->bus, buf, count); in bus_attr_store()
129 int bus_create_file(struct bus_type *bus, struct bus_attribute *attr) in bus_create_file() argument
132 if (bus_get(bus)) { in bus_create_file()
133 error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr); in bus_create_file()
134 bus_put(bus); in bus_create_file()
141 void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr) in bus_remove_file() argument
143 if (bus_get(bus)) { in bus_remove_file()
144 sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); in bus_remove_file()
145 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()
198 bus_put(bus); in unbind_store()
211 struct bus_type *bus = bus_get(drv->bus); in bind_store() local
215 dev = bus_find_device_by_name(bus, NULL, buf); in bind_store()
234 bus_put(bus); in bind_store()
239 static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) in show_drivers_autoprobe() argument
241 return sprintf(buf, "%d\n", bus->p->drivers_autoprobe); in show_drivers_autoprobe()
244 static ssize_t store_drivers_autoprobe(struct bus_type *bus, in store_drivers_autoprobe() argument
248 bus->p->drivers_autoprobe = 0; in store_drivers_autoprobe()
250 bus->p->drivers_autoprobe = 1; in store_drivers_autoprobe()
254 static ssize_t store_drivers_probe(struct bus_type *bus, in store_drivers_probe() argument
260 dev = bus_find_device_by_name(bus, NULL, buf); in store_drivers_probe()
301 int bus_for_each_dev(struct bus_type *bus, struct device *start, in bus_for_each_dev() argument
308 if (!bus || !bus->p) in bus_for_each_dev()
311 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_for_each_dev()
335 struct device *bus_find_device(struct bus_type *bus, in bus_find_device() argument
342 if (!bus || !bus->p) in bus_find_device()
345 klist_iter_init_node(&bus->p->klist_devices, &i, in bus_find_device()
372 struct device *bus_find_device_by_name(struct bus_type *bus, in bus_find_device_by_name() argument
375 return bus_find_device(bus, start, (void *)name, match_name); in bus_find_device_by_name()
451 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, in bus_for_each_drv() argument
458 if (!bus) in bus_for_each_drv()
461 klist_iter_init_node(&bus->p->klist_drivers, &i, in bus_for_each_drv()
470 static int device_add_attrs(struct bus_type *bus, struct device *dev) in device_add_attrs() argument
475 if (!bus->dev_attrs) in device_add_attrs()
478 for (i = 0; bus->dev_attrs[i].attr.name; i++) { in device_add_attrs()
479 error = device_create_file(dev, &bus->dev_attrs[i]); in device_add_attrs()
482 device_remove_file(dev, &bus->dev_attrs[i]); in device_add_attrs()
489 static void device_remove_attrs(struct bus_type *bus, struct device *dev) in device_remove_attrs() argument
493 if (bus->dev_attrs) { in device_remove_attrs()
494 for (i = 0; bus->dev_attrs[i].attr.name; i++) in device_remove_attrs()
495 device_remove_file(dev, &bus->dev_attrs[i]); in device_remove_attrs()
509 struct bus_type *bus = bus_get(dev->bus); in bus_add_device() local
512 if (bus) { in bus_add_device()
513 pr_debug("bus: '%s': add device %s\n", bus->name, dev_name(dev)); in bus_add_device()
514 error = device_add_attrs(bus, dev); in bus_add_device()
517 error = device_add_groups(dev, bus->dev_groups); in bus_add_device()
520 error = sysfs_create_link(&bus->p->devices_kset->kobj, in bus_add_device()
525 &dev->bus->p->subsys.kobj, "subsystem"); in bus_add_device()
528 klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices); in bus_add_device()
533 sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); in bus_add_device()
535 device_remove_groups(dev, bus->dev_groups); in bus_add_device()
537 device_remove_attrs(bus, dev); in bus_add_device()
539 bus_put(dev->bus); in bus_add_device()
551 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()
560 mutex_lock(&bus->p->mutex); in bus_probe_device()
561 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_probe_device()
564 mutex_unlock(&bus->p->mutex); in bus_probe_device()
579 struct bus_type *bus = dev->bus; in bus_remove_device() local
582 if (!bus) in bus_remove_device()
585 mutex_lock(&bus->p->mutex); in bus_remove_device()
586 list_for_each_entry(sif, &bus->p->interfaces, node) in bus_remove_device()
589 mutex_unlock(&bus->p->mutex); in bus_remove_device()
592 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, in bus_remove_device()
594 device_remove_attrs(dev->bus, dev); in bus_remove_device()
595 device_remove_groups(dev, dev->bus->dev_groups); in bus_remove_device()
600 dev->bus->name, dev_name(dev)); in bus_remove_device()
602 bus_put(dev->bus); in bus_remove_device()
628 static int add_probe_files(struct bus_type *bus) in add_probe_files() argument
632 retval = bus_create_file(bus, &bus_attr_drivers_probe); in add_probe_files()
636 retval = bus_create_file(bus, &bus_attr_drivers_autoprobe); in add_probe_files()
638 bus_remove_file(bus, &bus_attr_drivers_probe); in add_probe_files()
643 static void remove_probe_files(struct bus_type *bus) in remove_probe_files() argument
645 bus_remove_file(bus, &bus_attr_drivers_autoprobe); in remove_probe_files()
646 bus_remove_file(bus, &bus_attr_drivers_probe); in remove_probe_files()
668 drv->bus->name, drv->name, ret); in driver_attach_async()
677 struct bus_type *bus; in bus_add_driver() local
681 bus = bus_get(drv->bus); in bus_add_driver()
682 if (!bus) in bus_add_driver()
685 pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); in bus_add_driver()
695 priv->kobj.kset = bus->p->drivers_kset; in bus_add_driver()
701 klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); in bus_add_driver()
702 if (drv->bus->p->drivers_autoprobe) { in bus_add_driver()
705 drv->bus->name, drv->name); in bus_add_driver()
720 error = driver_add_groups(drv, bus->drv_groups); in bus_add_driver()
743 bus_put(bus); in bus_add_driver()
757 if (!drv->bus) in bus_remove_driver()
762 driver_remove_groups(drv, drv->bus->drv_groups); in bus_remove_driver()
765 pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); in bus_remove_driver()
769 bus_put(drv->bus); in bus_remove_driver()
796 int bus_rescan_devices(struct bus_type *bus) in bus_rescan_devices() argument
798 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); in bus_rescan_devices()
841 static int bus_add_groups(struct bus_type *bus, in bus_add_groups() argument
844 return sysfs_create_groups(&bus->p->subsys.kobj, groups); in bus_add_groups()
847 static void bus_remove_groups(struct bus_type *bus, in bus_remove_groups() argument
850 sysfs_remove_groups(&bus->p->subsys.kobj, groups); in bus_remove_groups()
869 static ssize_t bus_uevent_store(struct bus_type *bus, in bus_uevent_store() argument
875 kobject_uevent(&bus->p->subsys.kobj, action); in bus_uevent_store()
888 int bus_register(struct bus_type *bus) in bus_register() argument
892 struct lock_class_key *key = &bus->lock_key; in bus_register()
898 priv->bus = bus; in bus_register()
899 bus->p = priv; in bus_register()
903 retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name); in bus_register()
915 retval = bus_create_file(bus, &bus_attr_uevent); in bus_register()
938 retval = add_probe_files(bus); in bus_register()
942 retval = bus_add_groups(bus, bus->bus_groups); in bus_register()
946 pr_debug("bus: '%s': registered\n", bus->name); in bus_register()
950 remove_probe_files(bus); in bus_register()
952 kset_unregister(bus->p->drivers_kset); in bus_register()
954 kset_unregister(bus->p->devices_kset); in bus_register()
956 bus_remove_file(bus, &bus_attr_uevent); in bus_register()
958 kset_unregister(&bus->p->subsys); in bus_register()
960 kfree(bus->p); in bus_register()
961 bus->p = NULL; in bus_register()
973 void bus_unregister(struct bus_type *bus) in bus_unregister() argument
975 pr_debug("bus: '%s': unregistering\n", bus->name); in bus_unregister()
976 if (bus->dev_root) in bus_unregister()
977 device_unregister(bus->dev_root); in bus_unregister()
978 bus_remove_groups(bus, bus->bus_groups); in bus_unregister()
979 remove_probe_files(bus); in bus_unregister()
980 kset_unregister(bus->p->drivers_kset); in bus_unregister()
981 kset_unregister(bus->p->devices_kset); in bus_unregister()
982 bus_remove_file(bus, &bus_attr_uevent); in bus_unregister()
983 kset_unregister(&bus->p->subsys); in bus_unregister()
987 int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_register_notifier() argument
989 return blocking_notifier_chain_register(&bus->p->bus_notifier, nb); in bus_register_notifier()
993 int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) in bus_unregister_notifier() argument
995 return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb); in bus_unregister_notifier()
999 struct kset *bus_get_kset(struct bus_type *bus) in bus_get_kset() argument
1001 return &bus->p->subsys; in bus_get_kset()
1005 struct klist *bus_get_device_klist(struct bus_type *bus) in bus_get_device_klist() argument
1007 return &bus->p->klist_devices; in bus_get_device_klist()
1040 void bus_sort_breadthfirst(struct bus_type *bus, in bus_sort_breadthfirst() argument
1051 device_klist = bus_get_device_klist(bus); in bus_sort_breadthfirst()