Lines Matching refs:dev
77 struct device *dev; in deferred_probe_work_func() local
94 typeof(*dev->p), deferred_probe); in deferred_probe_work_func()
95 dev = private->device; in deferred_probe_work_func()
98 get_device(dev); in deferred_probe_work_func()
100 kfree(dev->p->deferred_probe_reason); in deferred_probe_work_func()
101 dev->p->deferred_probe_reason = NULL; in deferred_probe_work_func()
115 device_pm_move_to_tail(dev); in deferred_probe_work_func()
117 dev_dbg(dev, "Retrying from deferred list\n"); in deferred_probe_work_func()
118 bus_probe_device(dev); in deferred_probe_work_func()
121 put_device(dev); in deferred_probe_work_func()
127 void driver_deferred_probe_add(struct device *dev) in driver_deferred_probe_add() argument
130 if (list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_add()
131 dev_dbg(dev, "Added to deferred list\n"); in driver_deferred_probe_add()
132 list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list); in driver_deferred_probe_add()
137 void driver_deferred_probe_del(struct device *dev) in driver_deferred_probe_del() argument
140 if (!list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_del()
141 dev_dbg(dev, "Removed from deferred list\n"); in driver_deferred_probe_del()
142 list_del_init(&dev->p->deferred_probe); in driver_deferred_probe_del()
143 kfree(dev->p->deferred_probe_reason); in driver_deferred_probe_del()
144 dev->p->deferred_probe_reason = NULL; in driver_deferred_probe_del()
220 void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf) in device_set_deferred_probe_reason() argument
222 const char *drv = dev_driver_string(dev); in device_set_deferred_probe_reason()
226 kfree(dev->p->deferred_probe_reason); in device_set_deferred_probe_reason()
227 dev->p->deferred_probe_reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf); in device_set_deferred_probe_reason()
277 int driver_deferred_probe_check_state(struct device *dev) in driver_deferred_probe_check_state() argument
280 dev_warn(dev, "ignoring dependency for device, assuming no driver\n"); in driver_deferred_probe_check_state()
285 dev_warn(dev, "deferred probe timeout, ignoring dependency\n"); in driver_deferred_probe_check_state()
355 bool device_is_bound(struct device *dev) in device_is_bound() argument
357 return dev->p && klist_node_attached(&dev->p->knode_driver); in device_is_bound()
360 static void driver_bound(struct device *dev) in driver_bound() argument
362 if (device_is_bound(dev)) { in driver_bound()
364 __func__, kobject_name(&dev->kobj)); in driver_bound()
368 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name, in driver_bound()
369 __func__, dev_name(dev)); in driver_bound()
371 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); in driver_bound()
372 device_links_driver_bound(dev); in driver_bound()
374 device_pm_check_callbacks(dev); in driver_bound()
380 driver_deferred_probe_del(dev); in driver_bound()
383 if (dev->bus) in driver_bound()
384 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_bound()
385 BUS_NOTIFY_BOUND_DRIVER, dev); in driver_bound()
387 kobject_uevent(&dev->kobj, KOBJ_BIND); in driver_bound()
390 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr, in coredump_store() argument
393 device_lock(dev); in coredump_store()
394 dev->driver->coredump(dev); in coredump_store()
395 device_unlock(dev); in coredump_store()
401 static int driver_sysfs_add(struct device *dev) in driver_sysfs_add() argument
405 if (dev->bus) in driver_sysfs_add()
406 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_sysfs_add()
407 BUS_NOTIFY_BIND_DRIVER, dev); in driver_sysfs_add()
409 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, in driver_sysfs_add()
410 kobject_name(&dev->kobj)); in driver_sysfs_add()
414 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj, in driver_sysfs_add()
419 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump || in driver_sysfs_add()
420 !device_create_file(dev, &dev_attr_coredump)) in driver_sysfs_add()
423 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_add()
426 sysfs_remove_link(&dev->driver->p->kobj, in driver_sysfs_add()
427 kobject_name(&dev->kobj)); in driver_sysfs_add()
433 static void driver_sysfs_remove(struct device *dev) in driver_sysfs_remove() argument
435 struct device_driver *drv = dev->driver; in driver_sysfs_remove()
439 device_remove_file(dev, &dev_attr_coredump); in driver_sysfs_remove()
440 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj)); in driver_sysfs_remove()
441 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_remove()
458 int device_bind_driver(struct device *dev) in device_bind_driver() argument
462 ret = driver_sysfs_add(dev); in device_bind_driver()
464 driver_bound(dev); in device_bind_driver()
465 else if (dev->bus) in device_bind_driver()
466 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in device_bind_driver()
467 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in device_bind_driver()
475 static void driver_deferred_probe_add_trigger(struct device *dev, in driver_deferred_probe_add_trigger() argument
478 driver_deferred_probe_add(dev); in driver_deferred_probe_add_trigger()
484 static ssize_t state_synced_show(struct device *dev, in state_synced_show() argument
489 device_lock(dev); in state_synced_show()
490 val = dev->state_synced; in state_synced_show()
491 device_unlock(dev); in state_synced_show()
497 static int really_probe(struct device *dev, struct device_driver *drv) in really_probe() argument
510 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); in really_probe()
511 driver_deferred_probe_add(dev); in really_probe()
515 ret = device_links_check_suppliers(dev); in really_probe()
517 driver_deferred_probe_add_trigger(dev, local_trigger_count); in really_probe()
523 drv->bus->name, __func__, drv->name, dev_name(dev)); in really_probe()
524 if (!list_empty(&dev->devres_head)) { in really_probe()
525 dev_crit(dev, "Resources present before probing\n"); in really_probe()
531 dev->driver = drv; in really_probe()
534 ret = pinctrl_bind_pins(dev); in really_probe()
538 if (dev->bus->dma_configure) { in really_probe()
539 ret = dev->bus->dma_configure(dev); in really_probe()
544 ret = driver_sysfs_add(dev); in really_probe()
547 __func__, dev_name(dev)); in really_probe()
551 if (dev->pm_domain && dev->pm_domain->activate) { in really_probe()
552 ret = dev->pm_domain->activate(dev); in really_probe()
557 if (dev->bus->probe) { in really_probe()
558 ret = dev->bus->probe(dev); in really_probe()
562 ret = drv->probe(dev); in really_probe()
567 ret = device_add_groups(dev, drv->dev_groups); in really_probe()
569 dev_err(dev, "device_add_groups() failed\n"); in really_probe()
573 if (dev_has_sync_state(dev)) { in really_probe()
574 ret = device_create_file(dev, &dev_attr_state_synced); in really_probe()
576 dev_err(dev, "state_synced sysfs add failed\n"); in really_probe()
584 device_remove_file(dev, &dev_attr_state_synced); in really_probe()
585 device_remove_groups(dev, drv->dev_groups); in really_probe()
587 if (dev->bus->remove) in really_probe()
588 dev->bus->remove(dev); in really_probe()
590 drv->remove(dev); in really_probe()
592 devres_release_all(dev); in really_probe()
593 arch_teardown_dma_ops(dev); in really_probe()
594 kfree(dev->dma_range_map); in really_probe()
595 dev->dma_range_map = NULL; in really_probe()
596 driver_sysfs_remove(dev); in really_probe()
597 dev->driver = NULL; in really_probe()
598 dev_set_drvdata(dev, NULL); in really_probe()
599 if (dev->pm_domain && dev->pm_domain->dismiss) in really_probe()
600 dev->pm_domain->dismiss(dev); in really_probe()
601 pm_runtime_reinit(dev); in really_probe()
606 pinctrl_init_done(dev); in really_probe()
608 if (dev->pm_domain && dev->pm_domain->sync) in really_probe()
609 dev->pm_domain->sync(dev); in really_probe()
611 driver_bound(dev); in really_probe()
614 drv->bus->name, __func__, dev_name(dev), drv->name); in really_probe()
618 device_remove_groups(dev, drv->dev_groups); in really_probe()
620 if (dev->bus->remove) in really_probe()
621 dev->bus->remove(dev); in really_probe()
623 drv->remove(dev); in really_probe()
625 if (dev->bus) in really_probe()
626 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in really_probe()
627 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in really_probe()
629 device_links_no_driver(dev); in really_probe()
630 devres_release_all(dev); in really_probe()
631 arch_teardown_dma_ops(dev); in really_probe()
632 kfree(dev->dma_range_map); in really_probe()
633 dev->dma_range_map = NULL; in really_probe()
634 driver_sysfs_remove(dev); in really_probe()
635 dev->driver = NULL; in really_probe()
636 dev_set_drvdata(dev, NULL); in really_probe()
637 if (dev->pm_domain && dev->pm_domain->dismiss) in really_probe()
638 dev->pm_domain->dismiss(dev); in really_probe()
639 pm_runtime_reinit(dev); in really_probe()
640 dev_pm_set_driver_flags(dev, 0); in really_probe()
645 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); in really_probe()
646 driver_deferred_probe_add_trigger(dev, local_trigger_count); in really_probe()
651 drv->name, dev_name(dev), ret); in really_probe()
656 drv->name, dev_name(dev), ret); in really_probe()
672 static int really_probe_debug(struct device *dev, struct device_driver *drv) in really_probe_debug() argument
678 ret = really_probe(dev, drv); in really_probe_debug()
681 dev_name(dev), ret, ktime_us_delta(rettime, calltime)); in really_probe_debug()
729 int driver_probe_device(struct device_driver *drv, struct device *dev) in driver_probe_device() argument
733 if (!device_is_registered(dev)) in driver_probe_device()
737 drv->bus->name, __func__, dev_name(dev), drv->name); in driver_probe_device()
739 pm_runtime_get_suppliers(dev); in driver_probe_device()
740 if (dev->parent) in driver_probe_device()
741 pm_runtime_get_sync(dev->parent); in driver_probe_device()
743 pm_runtime_barrier(dev); in driver_probe_device()
745 ret = really_probe_debug(dev, drv); in driver_probe_device()
747 ret = really_probe(dev, drv); in driver_probe_device()
748 pm_request_idle(dev); in driver_probe_device()
750 if (dev->parent) in driver_probe_device()
751 pm_runtime_put(dev->parent); in driver_probe_device()
753 pm_runtime_put_suppliers(dev); in driver_probe_device()
794 struct device *dev; member
829 struct device *dev = data->dev; in __device_attach_driver() local
833 ret = driver_match_device(drv, dev); in __device_attach_driver()
838 dev_dbg(dev, "Device match requests probe deferral\n"); in __device_attach_driver()
839 driver_deferred_probe_add(dev); in __device_attach_driver()
846 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __device_attach_driver()
858 return driver_probe_device(drv, dev); in __device_attach_driver()
863 struct device *dev = _dev; in __device_attach_async_helper() local
865 .dev = dev, in __device_attach_async_helper()
870 device_lock(dev); in __device_attach_async_helper()
878 if (dev->p->dead || dev->driver) in __device_attach_async_helper()
881 if (dev->parent) in __device_attach_async_helper()
882 pm_runtime_get_sync(dev->parent); in __device_attach_async_helper()
884 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver); in __device_attach_async_helper()
885 dev_dbg(dev, "async probe completed\n"); in __device_attach_async_helper()
887 pm_request_idle(dev); in __device_attach_async_helper()
889 if (dev->parent) in __device_attach_async_helper()
890 pm_runtime_put(dev->parent); in __device_attach_async_helper()
892 device_unlock(dev); in __device_attach_async_helper()
894 put_device(dev); in __device_attach_async_helper()
897 static int __device_attach(struct device *dev, bool allow_async) in __device_attach() argument
902 device_lock(dev); in __device_attach()
903 if (dev->p->dead) { in __device_attach()
905 } else if (dev->driver) { in __device_attach()
906 if (device_is_bound(dev)) { in __device_attach()
910 ret = device_bind_driver(dev); in __device_attach()
914 dev->driver = NULL; in __device_attach()
919 .dev = dev, in __device_attach()
924 if (dev->parent) in __device_attach()
925 pm_runtime_get_sync(dev->parent); in __device_attach()
927 ret = bus_for_each_drv(dev->bus, NULL, &data, in __device_attach()
937 dev_dbg(dev, "scheduling asynchronous probe\n"); in __device_attach()
938 get_device(dev); in __device_attach()
941 pm_request_idle(dev); in __device_attach()
944 if (dev->parent) in __device_attach()
945 pm_runtime_put(dev->parent); in __device_attach()
948 device_unlock(dev); in __device_attach()
950 async_schedule_dev(__device_attach_async_helper, dev); in __device_attach()
968 int device_attach(struct device *dev) in device_attach() argument
970 return __device_attach(dev, false); in device_attach()
974 void device_initial_probe(struct device *dev) in device_initial_probe() argument
976 __device_attach(dev, true); in device_initial_probe()
988 static void __device_driver_lock(struct device *dev, struct device *parent) in __device_driver_lock() argument
990 if (parent && dev->bus->need_parent_lock) in __device_driver_lock()
992 device_lock(dev); in __device_driver_lock()
1004 static void __device_driver_unlock(struct device *dev, struct device *parent) in __device_driver_unlock() argument
1006 device_unlock(dev); in __device_driver_unlock()
1007 if (parent && dev->bus->need_parent_lock) in __device_driver_unlock()
1019 int device_driver_attach(struct device_driver *drv, struct device *dev) in device_driver_attach() argument
1023 __device_driver_lock(dev, dev->parent); in device_driver_attach()
1029 if (!dev->p->dead && !dev->driver) in device_driver_attach()
1030 ret = driver_probe_device(drv, dev); in device_driver_attach()
1032 __device_driver_unlock(dev, dev->parent); in device_driver_attach()
1039 struct device *dev = _dev; in __driver_attach_async_helper() local
1043 __device_driver_lock(dev, dev->parent); in __driver_attach_async_helper()
1045 drv = dev->p->async_driver; in __driver_attach_async_helper()
1051 if (!dev->p->dead && !dev->driver) in __driver_attach_async_helper()
1052 ret = driver_probe_device(drv, dev); in __driver_attach_async_helper()
1054 __device_driver_unlock(dev, dev->parent); in __driver_attach_async_helper()
1056 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); in __driver_attach_async_helper()
1058 put_device(dev); in __driver_attach_async_helper()
1061 static int __driver_attach(struct device *dev, void *data) in __driver_attach() argument
1077 ret = driver_match_device(drv, dev); in __driver_attach()
1082 dev_dbg(dev, "Device match requests probe deferral\n"); in __driver_attach()
1083 driver_deferred_probe_add(dev); in __driver_attach()
1090 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __driver_attach()
1102 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name); in __driver_attach()
1103 device_lock(dev); in __driver_attach()
1104 if (!dev->driver) { in __driver_attach()
1105 get_device(dev); in __driver_attach()
1106 dev->p->async_driver = drv; in __driver_attach()
1109 device_unlock(dev); in __driver_attach()
1111 async_schedule_dev(__driver_attach_async_helper, dev); in __driver_attach()
1115 device_driver_attach(drv, dev); in __driver_attach()
1139 static void __device_release_driver(struct device *dev, struct device *parent) in __device_release_driver() argument
1143 drv = dev->driver; in __device_release_driver()
1145 pm_runtime_get_sync(dev); in __device_release_driver()
1147 while (device_links_busy(dev)) { in __device_release_driver()
1148 __device_driver_unlock(dev, parent); in __device_release_driver()
1150 device_links_unbind_consumers(dev); in __device_release_driver()
1152 __device_driver_lock(dev, parent); in __device_release_driver()
1158 if (dev->driver != drv) { in __device_release_driver()
1159 pm_runtime_put(dev); in __device_release_driver()
1164 driver_sysfs_remove(dev); in __device_release_driver()
1166 if (dev->bus) in __device_release_driver()
1167 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1169 dev); in __device_release_driver()
1171 pm_runtime_put_sync(dev); in __device_release_driver()
1173 device_remove_file(dev, &dev_attr_state_synced); in __device_release_driver()
1174 device_remove_groups(dev, drv->dev_groups); in __device_release_driver()
1176 if (dev->bus && dev->bus->remove) in __device_release_driver()
1177 dev->bus->remove(dev); in __device_release_driver()
1179 drv->remove(dev); in __device_release_driver()
1181 device_links_driver_cleanup(dev); in __device_release_driver()
1183 devres_release_all(dev); in __device_release_driver()
1184 arch_teardown_dma_ops(dev); in __device_release_driver()
1185 kfree(dev->dma_range_map); in __device_release_driver()
1186 dev->dma_range_map = NULL; in __device_release_driver()
1187 dev->driver = NULL; in __device_release_driver()
1188 dev_set_drvdata(dev, NULL); in __device_release_driver()
1189 if (dev->pm_domain && dev->pm_domain->dismiss) in __device_release_driver()
1190 dev->pm_domain->dismiss(dev); in __device_release_driver()
1191 pm_runtime_reinit(dev); in __device_release_driver()
1192 dev_pm_set_driver_flags(dev, 0); in __device_release_driver()
1194 klist_remove(&dev->p->knode_driver); in __device_release_driver()
1195 device_pm_check_callbacks(dev); in __device_release_driver()
1196 if (dev->bus) in __device_release_driver()
1197 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1199 dev); in __device_release_driver()
1201 kobject_uevent(&dev->kobj, KOBJ_UNBIND); in __device_release_driver()
1205 void device_release_driver_internal(struct device *dev, in device_release_driver_internal() argument
1209 __device_driver_lock(dev, parent); in device_release_driver_internal()
1211 if (!drv || drv == dev->driver) in device_release_driver_internal()
1212 __device_release_driver(dev, parent); in device_release_driver_internal()
1214 __device_driver_unlock(dev, parent); in device_release_driver_internal()
1228 void device_release_driver(struct device *dev) in device_release_driver() argument
1235 device_release_driver_internal(dev, NULL, NULL); in device_release_driver()
1246 void device_driver_detach(struct device *dev) in device_driver_detach() argument
1248 device_release_driver_internal(dev, NULL, dev->parent); in device_driver_detach()
1258 struct device *dev; in driver_detach() local
1272 dev = dev_prv->device; in driver_detach()
1273 get_device(dev); in driver_detach()
1275 device_release_driver_internal(dev, drv, dev->parent); in driver_detach()
1276 put_device(dev); in driver_detach()