Lines Matching +full:fixed +full:- +full:links

1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/base/core.c - core driver model code (device registration, etc)
5 * Copyright (c) 2002-3 Patrick Mochel
6 * Copyright (c) 2002-3 Open Source Development Labs
7 * Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de>
16 #include <linux/dma-map-ops.h> /* for dma_default_coherent */
40 /* Device links support. */
51 * __fwnode_link_add - Create a link between two fwnode_handles.
65 * Attempts to create duplicate links between the same pair of fwnode handles
73 list_for_each_entry(link, &sup->consumers, s_hook) in __fwnode_link_add()
74 if (link->consumer == con) { in __fwnode_link_add()
75 link->flags |= flags; in __fwnode_link_add()
81 return -ENOMEM; in __fwnode_link_add()
83 link->supplier = sup; in __fwnode_link_add()
84 INIT_LIST_HEAD(&link->s_hook); in __fwnode_link_add()
85 link->consumer = con; in __fwnode_link_add()
86 INIT_LIST_HEAD(&link->c_hook); in __fwnode_link_add()
87 link->flags = flags; in __fwnode_link_add()
89 list_add(&link->s_hook, &sup->consumers); in __fwnode_link_add()
90 list_add(&link->c_hook, &con->suppliers); in __fwnode_link_add()
106 * __fwnode_link_del - Delete a link between two fwnode_handles.
114 link->consumer, link->supplier); in __fwnode_link_del()
115 list_del(&link->s_hook); in __fwnode_link_del()
116 list_del(&link->c_hook); in __fwnode_link_del()
121 * __fwnode_link_cycle - Mark a fwnode link as being part of a cycle.
129 link->consumer, link->supplier); in __fwnode_link_cycle()
130 link->flags |= FWLINK_FLAG_CYCLE; in __fwnode_link_cycle()
134 * fwnode_links_purge_suppliers - Delete all supplier links of fwnode_handle.
135 * @fwnode: fwnode whose supplier links need to be deleted
137 * Deletes all supplier links connecting directly to @fwnode.
145 list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) in fwnode_links_purge_suppliers()
150 * fwnode_links_purge_consumers - Delete all consumer links of fwnode_handle.
151 * @fwnode: fwnode whose consumer links need to be deleted
153 * Deletes all consumer links connecting directly to @fwnode.
161 list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) in fwnode_links_purge_consumers()
166 * fwnode_links_purge - Delete all links connected to a fwnode_handle.
167 * @fwnode: fwnode whose links needs to be deleted
169 * Deletes all links connecting directly to a fwnode.
181 /* Don't purge consumer links of an added child */ in fw_devlink_purge_absent_suppliers()
182 if (fwnode->dev) in fw_devlink_purge_absent_suppliers()
185 fwnode->flags |= FWNODE_FLAG_NOT_DEVICE; in fw_devlink_purge_absent_suppliers()
194 * __fwnode_links_move_consumers - Move consumer from @from to @to fwnode_handle
198 * Move all consumer links from @from fwnode to @to fwnode.
205 list_for_each_entry_safe(link, tmp, &from->consumers, s_hook) { in __fwnode_links_move_consumers()
206 __fwnode_link_add(link->consumer, to, link->flags); in __fwnode_links_move_consumers()
212 * __fw_devlink_pickup_dangling_consumers - Pick up dangling consumers
218 * MANAGED device links to this device, so leave @fwnode and its descendant's
219 * fwnode links alone.
228 if (fwnode->dev && fwnode->dev->bus) in __fw_devlink_pickup_dangling_consumers()
231 fwnode->flags |= FWNODE_FLAG_NOT_DEVICE; in __fw_devlink_pickup_dangling_consumers()
273 list_del_rcu(&link->s_node); in device_link_remove_from_lists()
274 list_del_rcu(&link->c_node); in device_link_remove_from_lists()
279 while (target->parent) { in device_is_ancestor()
280 target = target->parent; in device_is_ancestor()
296 * device_is_dependent - Check if one device depends on another one
320 list_for_each_entry(link, &dev->links.consumers, s_node) { in device_is_dependent()
321 if (device_link_flag_is_sync_state_only(link->flags)) in device_is_dependent()
324 if (link->consumer == target) in device_is_dependent()
327 ret = device_is_dependent(link->consumer, target); in device_is_dependent()
338 switch (supplier->links.status) { in device_link_init_status()
340 switch (consumer->links.status) { in device_link_init_status()
349 link->status = DL_STATE_CONSUMER_PROBE; in device_link_init_status()
352 link->status = DL_STATE_DORMANT; in device_link_init_status()
357 switch (consumer->links.status) { in device_link_init_status()
359 link->status = DL_STATE_CONSUMER_PROBE; in device_link_init_status()
362 link->status = DL_STATE_ACTIVE; in device_link_init_status()
365 link->status = DL_STATE_AVAILABLE; in device_link_init_status()
370 link->status = DL_STATE_SUPPLIER_UNBIND; in device_link_init_status()
373 link->status = DL_STATE_DORMANT; in device_link_init_status()
393 list_for_each_entry(link, &dev->links.consumers, s_node) { in device_reorder_to_tail()
394 if (device_link_flag_is_sync_state_only(link->flags)) in device_reorder_to_tail()
396 device_reorder_to_tail(link->consumer, NULL); in device_reorder_to_tail()
403 * device_pm_move_to_tail - Move set of devices to the end of device lists
429 switch (to_devlink(dev)->status) { in status_show()
463 if (link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER) in auto_remove_on_show()
465 else if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) in auto_remove_on_show()
479 return sysfs_emit(buf, "%d\n", !!(link->flags & DL_FLAG_PM_RUNTIME)); in runtime_pm_show()
489 !!(link->flags & DL_FLAG_SYNC_STATE_ONLY)); in sync_state_only_show()
514 * PM-runtime usage counter to remove the reference taken by in device_link_release_fn()
517 if (link->supplier_preactivated) in device_link_release_fn()
518 pm_runtime_put_noidle(link->supplier); in device_link_release_fn()
520 pm_request_idle(link->supplier); in device_link_release_fn()
522 put_device(link->consumer); in device_link_release_fn()
523 put_device(link->supplier); in device_link_release_fn()
531 INIT_WORK(&link->rm_work, device_link_release_fn); in devlink_dev_release()
538 queue_work(device_link_wq, &link->rm_work); in devlink_dev_release()
542 * device_link_wait_removal - Wait for ongoing devlink removal jobs to terminate
566 struct device *sup = link->supplier; in devlink_add_symlinks()
567 struct device *con = link->consumer; in devlink_add_symlinks()
569 ret = sysfs_create_link(&link->link_dev.kobj, &sup->kobj, "supplier"); in devlink_add_symlinks()
573 ret = sysfs_create_link(&link->link_dev.kobj, &con->kobj, "consumer"); in devlink_add_symlinks()
579 ret = -ENOMEM; in devlink_add_symlinks()
583 ret = sysfs_create_link(&sup->kobj, &link->link_dev.kobj, buf_con); in devlink_add_symlinks()
589 ret = -ENOMEM; in devlink_add_symlinks()
593 ret = sysfs_create_link(&con->kobj, &link->link_dev.kobj, buf_sup); in devlink_add_symlinks()
600 sysfs_remove_link(&sup->kobj, buf_con); in devlink_add_symlinks()
602 sysfs_remove_link(&link->link_dev.kobj, "consumer"); in devlink_add_symlinks()
604 sysfs_remove_link(&link->link_dev.kobj, "supplier"); in devlink_add_symlinks()
613 struct device *sup = link->supplier; in devlink_remove_symlinks()
614 struct device *con = link->consumer; in devlink_remove_symlinks()
616 sysfs_remove_link(&link->link_dev.kobj, "consumer"); in devlink_remove_symlinks()
617 sysfs_remove_link(&link->link_dev.kobj, "supplier"); in devlink_remove_symlinks()
623 sysfs_remove_link(&con->kobj, buf_sup); in devlink_remove_symlinks()
629 sysfs_remove_link(&sup->kobj, buf_con); in devlink_remove_symlinks()
670 * device_link_add - Create a link between two devices.
682 * be forced into the active meta state and reference-counted upon the creation
719 * A side effect of the link creation is re-ordering of dpm_list and the
760 * reverse (non-SYNC_STATE_ONLY) dependency between the consumer and in device_link_add()
773 * SYNC_STATE_ONLY links are useless once a consumer device has probed. in device_link_add()
777 consumer->links.status != DL_DEV_NO_DRIVER && in device_link_add()
778 consumer->links.status != DL_DEV_PROBING) { in device_link_add()
791 list_for_each_entry(link, &supplier->links.consumers, s_node) { in device_link_add()
792 if (link->consumer != consumer) in device_link_add()
795 if (link->flags & DL_FLAG_INFERRED && in device_link_add()
797 link->flags &= ~DL_FLAG_INFERRED; in device_link_add()
800 if (!(link->flags & DL_FLAG_PM_RUNTIME)) { in device_link_add()
802 link->flags |= DL_FLAG_PM_RUNTIME; in device_link_add()
805 refcount_inc(&link->rpm_active); in device_link_add()
809 kref_get(&link->kref); in device_link_add()
810 if (link->flags & DL_FLAG_SYNC_STATE_ONLY && in device_link_add()
811 !(link->flags & DL_FLAG_STATELESS)) { in device_link_add()
812 link->flags |= DL_FLAG_STATELESS; in device_link_add()
815 link->flags |= DL_FLAG_STATELESS; in device_link_add()
826 if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) { in device_link_add()
827 link->flags &= ~DL_FLAG_AUTOREMOVE_CONSUMER; in device_link_add()
828 link->flags |= DL_FLAG_AUTOREMOVE_SUPPLIER; in device_link_add()
831 link->flags &= ~(DL_FLAG_AUTOREMOVE_CONSUMER | in device_link_add()
834 if (!(link->flags & DL_FLAG_MANAGED)) { in device_link_add()
835 kref_get(&link->kref); in device_link_add()
836 link->flags |= DL_FLAG_MANAGED; in device_link_add()
839 if (link->flags & DL_FLAG_SYNC_STATE_ONLY && in device_link_add()
841 link->flags &= ~DL_FLAG_SYNC_STATE_ONLY; in device_link_add()
852 refcount_set(&link->rpm_active, 1); in device_link_add()
855 link->supplier = supplier; in device_link_add()
856 INIT_LIST_HEAD(&link->s_node); in device_link_add()
858 link->consumer = consumer; in device_link_add()
859 INIT_LIST_HEAD(&link->c_node); in device_link_add()
860 link->flags = flags; in device_link_add()
861 kref_init(&link->kref); in device_link_add()
863 link->link_dev.class = &devlink_class; in device_link_add()
864 device_set_pm_not_required(&link->link_dev); in device_link_add()
865 dev_set_name(&link->link_dev, "%s:%s--%s:%s", in device_link_add()
868 if (device_register(&link->link_dev)) { in device_link_add()
869 put_device(&link->link_dev); in device_link_add()
876 refcount_inc(&link->rpm_active); in device_link_add()
883 link->status = DL_STATE_NONE; in device_link_add()
891 if (link->status == DL_STATE_CONSUMER_PROBE && in device_link_add()
895 list_add_tail_rcu(&link->s_node, &supplier->links.consumers); in device_link_add()
896 list_add_tail_rcu(&link->c_node, &consumer->links.suppliers); in device_link_add()
932 dev_dbg(link->consumer, "Dropping the link to %s\n", in __device_link_del()
933 dev_name(link->supplier)); in __device_link_del()
938 device_unregister(&link->link_dev); in __device_link_del()
943 if (link->flags & DL_FLAG_STATELESS) in device_link_put_kref()
944 kref_put(&link->kref, __device_link_del); in device_link_put_kref()
945 else if (!device_is_registered(link->consumer)) in device_link_put_kref()
946 __device_link_del(&link->kref); in device_link_put_kref()
952 * device_link_del - Delete a stateless link between two devices.
957 * Care is required for hotplugged devices: Their links are purged on removal
969 * device_link_remove - Delete a stateless link between two devices.
985 list_for_each_entry(link, &supplier->links.consumers, s_node) { in device_link_remove()
986 if (link->consumer == consumer) { in device_link_remove()
1000 list_for_each_entry(link, &dev->links.suppliers, c_node) { in device_links_missing_supplier()
1001 if (link->status != DL_STATE_CONSUMER_PROBE) in device_links_missing_supplier()
1004 if (link->supplier->links.status == DL_DEV_DRIVER_BOUND) { in device_links_missing_supplier()
1005 WRITE_ONCE(link->status, DL_STATE_AVAILABLE); in device_links_missing_supplier()
1007 WARN_ON(!(link->flags & DL_FLAG_SYNC_STATE_ONLY)); in device_links_missing_supplier()
1008 WRITE_ONCE(link->status, DL_STATE_DORMANT); in device_links_missing_supplier()
1015 return (fw_devlink_best_effort && dev->can_match) || in dev_is_best_effort()
1016 (dev->fwnode && (dev->fwnode->flags & FWNODE_FLAG_BEST_EFFORT)); in dev_is_best_effort()
1027 list_for_each_entry(link, &fwnode->suppliers, c_hook) in fwnode_links_check_suppliers()
1028 if (!(link->flags & in fwnode_links_check_suppliers()
1030 return link->supplier; in fwnode_links_check_suppliers()
1036 * device_links_check_suppliers - Check presence of supplier drivers.
1039 * Check links from this device to any suppliers. Walk the list of the device's
1040 * links to suppliers and see if all of them are available. If not, simply
1041 * return -EPROBE_DEFER.
1045 * that function checks the device's links to consumers. This means we need to
1049 * Links without the DL_FLAG_MANAGED flag set are ignored.
1062 sup_fw = fwnode_links_check_suppliers(dev->fwnode); in device_links_check_suppliers()
1065 fwnode_ret = -EAGAIN; in device_links_check_suppliers()
1067 return dev_err_probe(dev, -EPROBE_DEFER, in device_links_check_suppliers()
1074 list_for_each_entry(link, &dev->links.suppliers, c_node) { in device_links_check_suppliers()
1075 if (!(link->flags & DL_FLAG_MANAGED)) in device_links_check_suppliers()
1078 if (link->status != DL_STATE_AVAILABLE && in device_links_check_suppliers()
1079 !(link->flags & DL_FLAG_SYNC_STATE_ONLY)) { in device_links_check_suppliers()
1082 link->flags & DL_FLAG_INFERRED && in device_links_check_suppliers()
1083 !link->supplier->can_match) { in device_links_check_suppliers()
1084 ret = -EAGAIN; in device_links_check_suppliers()
1089 ret = dev_err_probe(dev, -EPROBE_DEFER, in device_links_check_suppliers()
1090 "supplier %s not ready\n", dev_name(link->supplier)); in device_links_check_suppliers()
1093 WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE); in device_links_check_suppliers()
1095 dev->links.status = DL_DEV_PROBING; in device_links_check_suppliers()
1103 * __device_links_queue_sync_state - Queue a device for sync_state() callback
1107 * Queues a device for a sync_state() callback when the device links write lock
1108 * isn't held. This allows the sync_state() execution flow to use device links
1127 if (dev->state_synced) in __device_links_queue_sync_state()
1130 list_for_each_entry(link, &dev->links.consumers, s_node) { in __device_links_queue_sync_state()
1131 if (!(link->flags & DL_FLAG_MANAGED)) in __device_links_queue_sync_state()
1133 if (link->status != DL_STATE_ACTIVE) in __device_links_queue_sync_state()
1142 dev->state_synced = true; in __device_links_queue_sync_state()
1144 if (WARN_ON(!list_empty(&dev->links.defer_sync))) in __device_links_queue_sync_state()
1148 list_add_tail(&dev->links.defer_sync, list); in __device_links_queue_sync_state()
1152 * device_links_flush_sync_list - Call sync_state() on a list of devices
1166 list_for_each_entry_safe(dev, tmp, list, links.defer_sync) { in device_links_flush_sync_list()
1167 list_del_init(&dev->links.defer_sync); in device_links_flush_sync_list()
1198 defer_sync_state_count--; in device_links_supplier_sync_state_resume()
1202 list_for_each_entry_safe(dev, tmp, &deferred_sync, links.defer_sync) { in device_links_supplier_sync_state_resume()
1207 list_del_init(&dev->links.defer_sync); in device_links_supplier_sync_state_resume()
1225 if (list_empty(&sup->links.defer_sync) && dev_has_sync_state(sup)) in __device_links_supplier_defer_sync()
1226 list_add_tail(&sup->links.defer_sync, &deferred_sync); in __device_links_supplier_defer_sync()
1231 link->flags &= ~DL_FLAG_MANAGED; in device_link_drop_managed()
1232 WRITE_ONCE(link->status, DL_STATE_NONE); in device_link_drop_managed()
1233 kref_put(&link->kref, __device_link_del); in device_link_drop_managed()
1244 val = !!fwnode_links_check_suppliers(dev->fwnode); in waiting_for_supplier_show()
1251 * device_links_force_bind - Prepares device to be force bound
1260 * supplier device links and checks if the supplier is bound. If it is, then
1262 * is dropped. Links without the DL_FLAG_MANAGED flag set are ignored.
1270 list_for_each_entry_safe(link, ln, &dev->links.suppliers, c_node) { in device_links_force_bind()
1271 if (!(link->flags & DL_FLAG_MANAGED)) in device_links_force_bind()
1274 if (link->status != DL_STATE_AVAILABLE) { in device_links_force_bind()
1278 WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE); in device_links_force_bind()
1280 dev->links.status = DL_DEV_PROBING; in device_links_force_bind()
1286 * device_links_driver_bound - Update device links after probing its driver.
1287 * @dev: Device to update the links for.
1289 * The probe has been successful, so update links from this device to any
1292 * Also change the status of @dev's links to suppliers to "active".
1294 * Links without the DL_FLAG_MANAGED flag set are ignored.
1303 * the device links it needs to or make new device links as it needs in device_links_driver_bound()
1304 * them. So, fw_devlink no longer needs to create device links to any in device_links_driver_bound()
1315 if (dev->fwnode && dev->fwnode->dev == dev) { in device_links_driver_bound()
1318 fwnode_links_purge_suppliers(dev->fwnode); in device_links_driver_bound()
1322 fwnode_for_each_available_child_node(dev->fwnode, child) in device_links_driver_bound()
1324 dev->fwnode); in device_links_driver_bound()
1331 list_for_each_entry(link, &dev->links.consumers, s_node) { in device_links_driver_bound()
1332 if (!(link->flags & DL_FLAG_MANAGED)) in device_links_driver_bound()
1336 * Links created during consumer probe may be in the "consumer in device_links_driver_bound()
1341 if (link->status == DL_STATE_CONSUMER_PROBE || in device_links_driver_bound()
1342 link->status == DL_STATE_ACTIVE) in device_links_driver_bound()
1345 WARN_ON(link->status != DL_STATE_DORMANT); in device_links_driver_bound()
1346 WRITE_ONCE(link->status, DL_STATE_AVAILABLE); in device_links_driver_bound()
1348 if (link->flags & DL_FLAG_AUTOPROBE_CONSUMER) in device_links_driver_bound()
1349 driver_deferred_probe_add(link->consumer); in device_links_driver_bound()
1357 list_for_each_entry_safe(link, ln, &dev->links.suppliers, c_node) { in device_links_driver_bound()
1360 if (!(link->flags & DL_FLAG_MANAGED)) in device_links_driver_bound()
1363 supplier = link->supplier; in device_links_driver_bound()
1364 if (link->flags & DL_FLAG_SYNC_STATE_ONLY) { in device_links_driver_bound()
1372 link->flags & DL_FLAG_INFERRED && in device_links_driver_bound()
1373 link->status != DL_STATE_CONSUMER_PROBE && in device_links_driver_bound()
1374 !link->supplier->can_match) { in device_links_driver_bound()
1377 * links to suppliers that don't have a driver. If the in device_links_driver_bound()
1384 WARN_ON(link->status != DL_STATE_CONSUMER_PROBE); in device_links_driver_bound()
1385 WRITE_ONCE(link->status, DL_STATE_ACTIVE); in device_links_driver_bound()
1400 dev->links.status = DL_DEV_DRIVER_BOUND; in device_links_driver_bound()
1408 * __device_links_no_driver - Update links of a device without a driver.
1411 * Delete all non-persistent links from this device to any suppliers.
1413 * Persistent links stay around, but their status is changed to "available",
1417 * Links without the DL_FLAG_MANAGED flag set are ignored.
1423 list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers, c_node) { in __device_links_no_driver()
1424 if (!(link->flags & DL_FLAG_MANAGED)) in __device_links_no_driver()
1427 if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) { in __device_links_no_driver()
1432 if (link->status != DL_STATE_CONSUMER_PROBE && in __device_links_no_driver()
1433 link->status != DL_STATE_ACTIVE) in __device_links_no_driver()
1436 if (link->supplier->links.status == DL_DEV_DRIVER_BOUND) { in __device_links_no_driver()
1437 WRITE_ONCE(link->status, DL_STATE_AVAILABLE); in __device_links_no_driver()
1439 WARN_ON(!(link->flags & DL_FLAG_SYNC_STATE_ONLY)); in __device_links_no_driver()
1440 WRITE_ONCE(link->status, DL_STATE_DORMANT); in __device_links_no_driver()
1444 dev->links.status = DL_DEV_NO_DRIVER; in __device_links_no_driver()
1448 * device_links_no_driver - Update links after failing driver probe.
1451 * Clean up leftover links to consumers for @dev and invoke
1452 * %__device_links_no_driver() to update links to suppliers for it as
1455 * Links without the DL_FLAG_MANAGED flag set are ignored.
1463 list_for_each_entry(link, &dev->links.consumers, s_node) { in device_links_no_driver()
1464 if (!(link->flags & DL_FLAG_MANAGED)) in device_links_no_driver()
1474 if (link->status == DL_STATE_CONSUMER_PROBE || in device_links_no_driver()
1475 link->status == DL_STATE_ACTIVE) in device_links_no_driver()
1476 WRITE_ONCE(link->status, DL_STATE_DORMANT); in device_links_no_driver()
1485 * device_links_driver_cleanup - Update links after driver removal.
1488 * Update links to consumers for @dev by changing their status to "dormant" and
1489 * invoke %__device_links_no_driver() to update links to suppliers for it as
1492 * Links without the DL_FLAG_MANAGED flag set are ignored.
1500 list_for_each_entry_safe(link, ln, &dev->links.consumers, s_node) { in device_links_driver_cleanup()
1501 if (!(link->flags & DL_FLAG_MANAGED)) in device_links_driver_cleanup()
1504 WARN_ON(link->flags & DL_FLAG_AUTOREMOVE_CONSUMER); in device_links_driver_cleanup()
1505 WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND); in device_links_driver_cleanup()
1508 * autoremove the links between this @dev and its consumer in device_links_driver_cleanup()
1512 if (link->status == DL_STATE_SUPPLIER_UNBIND && in device_links_driver_cleanup()
1513 link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER) in device_links_driver_cleanup()
1516 WRITE_ONCE(link->status, DL_STATE_DORMANT); in device_links_driver_cleanup()
1519 list_del_init(&dev->links.defer_sync); in device_links_driver_cleanup()
1526 * device_links_busy - Check if there are any busy links to consumers.
1537 * Links without the DL_FLAG_MANAGED flag set are ignored.
1546 list_for_each_entry(link, &dev->links.consumers, s_node) { in device_links_busy()
1547 if (!(link->flags & DL_FLAG_MANAGED)) in device_links_busy()
1550 if (link->status == DL_STATE_CONSUMER_PROBE in device_links_busy()
1551 || link->status == DL_STATE_ACTIVE) { in device_links_busy()
1555 WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND); in device_links_busy()
1558 dev->links.status = DL_DEV_UNBINDING; in device_links_busy()
1565 * device_links_unbind_consumers - Force unbind consumers of the given device.
1568 * Walk the list of links to consumers for @dev and if any of them is in the
1574 * driver to unbind and start over (the consumer will not re-probe as we have
1577 * Links without the DL_FLAG_MANAGED flag set are ignored.
1586 list_for_each_entry(link, &dev->links.consumers, s_node) { in device_links_unbind_consumers()
1589 if (!(link->flags & DL_FLAG_MANAGED) || in device_links_unbind_consumers()
1590 link->flags & DL_FLAG_SYNC_STATE_ONLY) in device_links_unbind_consumers()
1593 status = link->status; in device_links_unbind_consumers()
1600 WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND); in device_links_unbind_consumers()
1602 struct device *consumer = link->consumer; in device_links_unbind_consumers()
1609 consumer->parent); in device_links_unbind_consumers()
1619 * device_links_purge - Delete existing links to other devices.
1626 if (dev->class == &devlink_class) in device_links_purge()
1630 * Delete all of the remaining links from this device to any other in device_links_purge()
1635 list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers, c_node) { in device_links_purge()
1636 WARN_ON(link->status == DL_STATE_ACTIVE); in device_links_purge()
1637 __device_link_del(&link->kref); in device_links_purge()
1640 list_for_each_entry_safe_reverse(link, ln, &dev->links.consumers, s_node) { in device_links_purge()
1641 WARN_ON(link->status != DL_STATE_DORMANT && in device_links_purge()
1642 link->status != DL_STATE_NONE); in device_links_purge()
1643 __device_link_del(&link->kref); in device_links_purge()
1660 return -EINVAL; in fw_devlink_setup()
1694 return -EINVAL; in fw_devlink_sync_state_setup()
1703 return -EINVAL; in fw_devlink_sync_state_setup()
1727 if (fwnode->flags & FWNODE_FLAG_LINKS_ADDED) in fw_devlink_parse_fwnode()
1731 fwnode->flags |= FWNODE_FLAG_LINKS_ADDED; in fw_devlink_parse_fwnode()
1746 if (!(link->flags & DL_FLAG_INFERRED)) in fw_devlink_relax_link()
1749 if (device_link_flag_is_sync_state_only(link->flags)) in fw_devlink_relax_link()
1753 link->flags = DL_FLAG_MANAGED | FW_DEVLINK_FLAGS_PERMISSIVE; in fw_devlink_relax_link()
1754 dev_dbg(link->consumer, "Relaxing link with %s\n", in fw_devlink_relax_link()
1755 dev_name(link->supplier)); in fw_devlink_relax_link()
1762 if (!link->supplier->can_match) in fw_devlink_no_driver()
1780 struct device *sup = link->supplier; in fw_devlink_dev_sync_state()
1782 if (!(link->flags & DL_FLAG_MANAGED) || in fw_devlink_dev_sync_state()
1783 link->status == DL_STATE_ACTIVE || sup->state_synced || in fw_devlink_dev_sync_state()
1789 dev_name(link->consumer)); in fw_devlink_dev_sync_state()
1793 if (!list_empty(&sup->links.defer_sync)) in fw_devlink_dev_sync_state()
1797 sup->state_synced = true; in fw_devlink_dev_sync_state()
1799 list_add_tail(&sup->links.defer_sync, data); in fw_devlink_dev_sync_state()
1816 * wait_for_init_devices_probe - Try to probe any device needed for init
1879 list_for_each_entry(link, &dev->links.consumers, s_node) in fw_devlink_unblock_consumers()
1884 #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
1891 if (!(fwnode->flags & FWNODE_FLAG_INITIALIZED)) in fwnode_init_without_drv()
1895 ret = !dev || dev->links.status == DL_DEV_NO_DRIVER; in fwnode_init_without_drv()
1916 * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child
1945 * fwnode_get_next_parent_dev - Find device of closest ancestor fwnode
1973 * __fw_devlink_relax_cycles - Relax and mark dependency cycles.
1981 * and @con. When such dependency cycles are found, convert all device links
1982 * created solely by fw_devlink into SYNC_STATE_ONLY device links. Also, mark
1983 * all fwnode links in the cycle with FWLINK_FLAG_CYCLE so that when they are
1985 * SYNC_STATE_ONLY device links. This is the equivalent of doing
2007 if (sup_handle->flags & FWNODE_FLAG_VISITED) in __fw_devlink_relax_cycles()
2010 sup_handle->flags |= FWNODE_FLAG_VISITED; in __fw_devlink_relax_cycles()
2016 pr_debug("----- cycle: start -----\n"); in __fw_devlink_relax_cycles()
2026 if (sup_dev && sup_dev->links.status == DL_DEV_DRIVER_BOUND && in __fw_devlink_relax_cycles()
2027 con->links.status == DL_DEV_NO_DRIVER) { in __fw_devlink_relax_cycles()
2032 list_for_each_entry(link, &sup_handle->suppliers, c_hook) { in __fw_devlink_relax_cycles()
2033 if (link->flags & FWLINK_FLAG_IGNORE) in __fw_devlink_relax_cycles()
2036 if (__fw_devlink_relax_cycles(con, link->supplier)) { in __fw_devlink_relax_cycles()
2047 par_dev = get_device(sup_dev->parent); in __fw_devlink_relax_cycles()
2051 if (par_dev && __fw_devlink_relax_cycles(con, par_dev->fwnode)) { in __fw_devlink_relax_cycles()
2053 par_dev->fwnode); in __fw_devlink_relax_cycles()
2060 list_for_each_entry(dev_link, &sup_dev->links.suppliers, c_node) { in __fw_devlink_relax_cycles()
2065 if (device_link_flag_is_sync_state_only(dev_link->flags) && in __fw_devlink_relax_cycles()
2066 !(dev_link->flags & DL_FLAG_CYCLE)) in __fw_devlink_relax_cycles()
2070 dev_link->supplier->fwnode)) { in __fw_devlink_relax_cycles()
2072 dev_link->supplier->fwnode); in __fw_devlink_relax_cycles()
2074 dev_link->flags |= DL_FLAG_CYCLE; in __fw_devlink_relax_cycles()
2080 sup_handle->flags &= ~FWNODE_FLAG_VISITED; in __fw_devlink_relax_cycles()
2087 * fw_devlink_create_devlink - Create a device link from a consumer to fwnode
2096 * fwnode links can sometimes cause the supplier device to never be created.
2102 * -EINVAL if the device link cannot be created as expected
2103 * -EAGAIN if the device link cannot be created right now, but it may be
2114 if (link->flags & FWLINK_FLAG_IGNORE) in fw_devlink_create_devlink()
2117 if (con->fwnode == link->consumer) in fw_devlink_create_devlink()
2118 flags = fw_devlink_get_flags(link->flags); in fw_devlink_create_devlink()
2134 * When such a flag is set, we can't create device links where P is the in fw_devlink_create_devlink()
2137 if (sup_handle->flags & FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD && in fw_devlink_create_devlink()
2138 fwnode_is_ancestor_of(sup_handle, con->fwnode)) in fw_devlink_create_devlink()
2139 return -EINVAL; in fw_devlink_create_devlink()
2142 * SYNC_STATE_ONLY device links don't block probing and supports cycles. in fw_devlink_create_devlink()
2154 flags = fw_devlink_get_flags(link->flags); in fw_devlink_create_devlink()
2155 pr_debug("----- cycle: end -----\n"); in fw_devlink_create_devlink()
2156 dev_info(con, "Fixed dependency cycle(s) with %pfwf\n", in fw_devlink_create_devlink()
2162 if (sup_handle->flags & FWNODE_FLAG_NOT_DEVICE) in fw_devlink_create_devlink()
2173 if (sup_dev->links.status == DL_DEV_NO_DRIVER && in fw_devlink_create_devlink()
2174 sup_handle->flags & FWNODE_FLAG_INITIALIZED) { in fw_devlink_create_devlink()
2176 "Not linking %pfwf - dev might never probe\n", in fw_devlink_create_devlink()
2178 ret = -EINVAL; in fw_devlink_create_devlink()
2185 ret = -EINVAL; in fw_devlink_create_devlink()
2197 dev_dbg(con, "Not linking %pfwf - might never become dev\n", in fw_devlink_create_devlink()
2199 return -EINVAL; in fw_devlink_create_devlink()
2202 ret = -EAGAIN; in fw_devlink_create_devlink()
2209 * __fw_devlink_link_to_consumers - Create device links to consumers of a device
2213 * links between the consumer device and @dev (supplier).
2221 * Once device links are created from the real consumer to @dev (supplier), the
2222 * fwnode links are deleted.
2226 struct fwnode_handle *fwnode = dev->fwnode; in __fw_devlink_link_to_consumers()
2229 list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) { in __fw_devlink_link_to_consumers()
2234 con_dev = get_dev_from_fwnode(link->consumer); in __fw_devlink_link_to_consumers()
2246 con_dev = fwnode_get_next_parent_dev(link->consumer); in __fw_devlink_link_to_consumers()
2250 * consumer-supplier link from the parent to its child in __fw_devlink_link_to_consumers()
2254 fwnode_is_ancestor_of(con_dev->fwnode, fwnode)) { in __fw_devlink_link_to_consumers()
2267 if (!own_link || ret == -EAGAIN) in __fw_devlink_link_to_consumers()
2275 * __fw_devlink_link_to_suppliers - Create device links to suppliers of a device
2277 * @fwnode: Root of the fwnode tree that is used to create device links
2280 * @fwnode and creates device links between @dev (consumer) and all the
2283 * The function creates normal (non-SYNC_STATE_ONLY) device links between @dev
2284 * and the real suppliers of @dev. Once these device links are created, the
2285 * fwnode links are deleted.
2290 * driver core. So, this function creates SYNC_STATE_ONLY device links between
2293 * their device links. The fwnode links that correspond to the child devices
2294 * aren't delete because they are needed later to create the device links
2300 bool own_link = (dev->fwnode == fwnode); in __fw_devlink_link_to_suppliers()
2304 list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) { in __fw_devlink_link_to_suppliers()
2306 struct fwnode_handle *sup = link->supplier; in __fw_devlink_link_to_suppliers()
2309 if (!own_link || ret == -EAGAIN) in __fw_devlink_link_to_suppliers()
2316 * Make "proxy" SYNC_STATE_ONLY device links to represent the needs of in __fw_devlink_link_to_suppliers()
2327 struct fwnode_handle *fwnode = dev->fwnode; in fw_devlink_link_device()
2340 /* Device links support end. */
2375 return !(dev->type == &part_type); in device_is_not_partition()
2399 * dev_driver_string - Return a device's driver name, if at all possible
2411 /* dev->driver can change to NULL underneath us because of unbinding, in dev_driver_string()
2412 * so be careful about accessing it. dev->bus and dev->class should in dev_driver_string()
2415 drv = READ_ONCE(dev->driver); in dev_driver_string()
2416 return drv ? drv->name : dev_bus_name(dev); in dev_driver_string()
2427 ssize_t ret = -EIO; in dev_attr_show()
2429 if (dev_attr->show) in dev_attr_show()
2430 ret = dev_attr->show(dev, dev_attr, buf); in dev_attr_show()
2433 dev_attr->show); in dev_attr_show()
2443 ssize_t ret = -EIO; in dev_attr_store()
2445 if (dev_attr->store) in dev_attr_store()
2446 ret = dev_attr->store(dev, dev_attr, buf, count); in dev_attr_store()
2468 *(unsigned long *)(ea->var) = new; in device_store_ulong()
2479 return sysfs_emit(buf, "%lx\n", *(unsigned long *)(ea->var)); in device_show_ulong()
2496 return -EINVAL; in device_store_int()
2497 *(int *)(ea->var) = new; in device_store_int()
2509 return sysfs_emit(buf, "%d\n", *(int *)(ea->var)); in device_show_int()
2518 if (kstrtobool(buf, ea->var) < 0) in device_store_bool()
2519 return -EINVAL; in device_store_bool()
2530 return sysfs_emit(buf, "%d\n", *(bool *)(ea->var)); in device_show_bool()
2539 return sysfs_emit(buf, "%s\n", (char *)ea->var); in device_show_string()
2544 * device_release - free device structure.
2554 struct device_private *p = dev->p; in device_release()
2567 kfree(dev->dma_range_map); in device_release()
2569 if (dev->release) in device_release()
2570 dev->release(dev); in device_release()
2571 else if (dev->type && dev->type->release) in device_release()
2572 dev->type->release(dev); in device_release()
2573 else if (dev->class && dev->class->dev_release) in device_release()
2574 dev->class->dev_release(dev); in device_release()
2576 …does not have a release() function, it is broken and must be fixed. See Documentation/core-api/kob… in device_release()
2586 if (dev->class && dev->class->namespace) in device_namespace()
2587 ns = dev->class->namespace(dev); in device_namespace()
2596 if (dev->class && dev->class->get_ownership) in device_get_ownership()
2597 dev->class->get_ownership(dev, uid, gid); in device_get_ownership()
2614 if (dev->bus) in dev_uevent_filter()
2616 if (dev->class) in dev_uevent_filter()
2626 if (dev->bus) in dev_uevent_name()
2627 return dev->bus->name; in dev_uevent_name()
2628 if (dev->class) in dev_uevent_name()
2629 return dev->class->name; in dev_uevent_name()
2639 if (MAJOR(dev->devt)) { in dev_uevent()
2646 add_uevent_var(env, "MAJOR=%u", MAJOR(dev->devt)); in dev_uevent()
2647 add_uevent_var(env, "MINOR=%u", MINOR(dev->devt)); in dev_uevent()
2661 if (dev->type && dev->type->name) in dev_uevent()
2662 add_uevent_var(env, "DEVTYPE=%s", dev->type->name); in dev_uevent()
2664 if (dev->driver) in dev_uevent()
2665 add_uevent_var(env, "DRIVER=%s", dev->driver->name); in dev_uevent()
2671 if (dev->bus && dev->bus->uevent) { in dev_uevent()
2672 retval = dev->bus->uevent(dev, env); in dev_uevent()
2679 if (dev->class && dev->class->dev_uevent) { in dev_uevent()
2680 retval = dev->class->dev_uevent(dev, env); in dev_uevent()
2688 if (dev->type && dev->type->uevent) { in dev_uevent()
2689 retval = dev->type->uevent(dev, env); in dev_uevent()
2716 top_kobj = &dev->kobj; in uevent_show()
2717 while (!top_kobj->kset && top_kobj->parent) in uevent_show()
2718 top_kobj = top_kobj->parent; in uevent_show()
2719 if (!top_kobj->kset) in uevent_show()
2722 kset = top_kobj->kset; in uevent_show()
2723 if (!kset->uevent_ops || !kset->uevent_ops->uevent) in uevent_show()
2727 if (kset->uevent_ops && kset->uevent_ops->filter) in uevent_show()
2728 if (!kset->uevent_ops->filter(&dev->kobj)) in uevent_show()
2733 return -ENOMEM; in uevent_show()
2738 retval = kset->uevent_ops->uevent(&dev->kobj, env); in uevent_show()
2744 for (i = 0; i < env->envp_idx; i++) in uevent_show()
2745 len += sysfs_emit_at(buf, len, "%s\n", env->envp[i]); in uevent_show()
2756 rc = kobject_synth_uevent(&dev->kobj, buf, count); in uevent_store()
2773 val = !dev->offline; in online_show()
2803 switch (dev->removable) { in removable_show()
2808 loc = "fixed"; in removable_show()
2819 return sysfs_create_groups(&dev->kobj, groups); in device_add_groups()
2826 sysfs_remove_groups(&dev->kobj, groups); in device_remove_groups()
2838 const struct attribute_group *group = devres->group; in devm_attr_group_remove()
2841 sysfs_remove_group(&dev->kobj, group); in devm_attr_group_remove()
2845 * devm_device_add_group - given a device, create a managed attribute group
2862 return -ENOMEM; in devm_device_add_group()
2864 error = sysfs_create_group(&dev->kobj, grp); in devm_device_add_group()
2870 devres->group = grp; in devm_device_add_group()
2878 const struct class *class = dev->class; in device_add_attrs()
2879 const struct device_type *type = dev->type; in device_add_attrs()
2883 error = device_add_groups(dev, class->dev_groups); in device_add_attrs()
2889 error = device_add_groups(dev, type->groups); in device_add_attrs()
2894 error = device_add_groups(dev, dev->groups); in device_add_attrs()
2898 if (device_supports_offline(dev) && !dev->offline_disabled) { in device_add_attrs()
2904 if (fw_devlink_flags && !fw_devlink_is_permissive() && dev->fwnode) { in device_add_attrs()
2932 device_remove_groups(dev, dev->groups); in device_add_attrs()
2935 device_remove_groups(dev, type->groups); in device_add_attrs()
2938 device_remove_groups(dev, class->dev_groups); in device_add_attrs()
2945 const struct class *class = dev->class; in device_remove_attrs()
2946 const struct device_type *type = dev->type; in device_remove_attrs()
2948 if (dev->physical_location) { in device_remove_attrs()
2950 kfree(dev->physical_location); in device_remove_attrs()
2956 device_remove_groups(dev, dev->groups); in device_remove_attrs()
2959 device_remove_groups(dev, type->groups); in device_remove_attrs()
2962 device_remove_groups(dev, class->dev_groups); in device_remove_attrs()
2968 return print_dev_t(buf, dev->devt); in dev_show()
2976 * devices_kset_move_before - Move device in the devices_kset's list.
2986 spin_lock(&devices_kset->list_lock); in devices_kset_move_before()
2987 list_move_tail(&deva->kobj.entry, &devb->kobj.entry); in devices_kset_move_before()
2988 spin_unlock(&devices_kset->list_lock); in devices_kset_move_before()
2992 * devices_kset_move_after - Move device in the devices_kset's list.
3002 spin_lock(&devices_kset->list_lock); in devices_kset_move_after()
3003 list_move(&deva->kobj.entry, &devb->kobj.entry); in devices_kset_move_after()
3004 spin_unlock(&devices_kset->list_lock); in devices_kset_move_after()
3008 * devices_kset_move_last - move the device to the end of devices_kset's list.
3016 spin_lock(&devices_kset->list_lock); in devices_kset_move_last()
3017 list_move_tail(&dev->kobj.entry, &devices_kset->list); in devices_kset_move_last()
3018 spin_unlock(&devices_kset->list_lock); in devices_kset_move_last()
3022 * device_create_file - create sysfs attribute file for device.
3032 WARN(((attr->attr.mode & S_IWUGO) && !attr->store), in device_create_file()
3034 attr->attr.name); in device_create_file()
3035 WARN(((attr->attr.mode & S_IRUGO) && !attr->show), in device_create_file()
3037 attr->attr.name); in device_create_file()
3038 error = sysfs_create_file(&dev->kobj, &attr->attr); in device_create_file()
3046 * device_remove_file - remove sysfs attribute file.
3054 sysfs_remove_file(&dev->kobj, &attr->attr); in device_remove_file()
3059 * device_remove_file_self - remove sysfs attribute file from its own method.
3069 return sysfs_remove_file_self(&dev->kobj, &attr->attr); in device_remove_file_self()
3076 * device_create_bin_file - create sysfs binary attribute file for device.
3083 int error = -EINVAL; in device_create_bin_file()
3085 error = sysfs_create_bin_file(&dev->kobj, attr); in device_create_bin_file()
3091 * device_remove_bin_file - remove sysfs binary attribute file
3099 sysfs_remove_bin_file(&dev->kobj, attr); in device_remove_bin_file()
3106 struct device *dev = p->device; in klist_children_get()
3114 struct device *dev = p->device; in klist_children_put()
3120 * device_initialize - init device structure.
3141 dev->kobj.kset = devices_kset; in device_initialize()
3142 kobject_init(&dev->kobj, &device_ktype); in device_initialize()
3143 INIT_LIST_HEAD(&dev->dma_pools); in device_initialize()
3144 mutex_init(&dev->mutex); in device_initialize()
3145 lockdep_set_novalidate_class(&dev->mutex); in device_initialize()
3146 spin_lock_init(&dev->devres_lock); in device_initialize()
3147 INIT_LIST_HEAD(&dev->devres_head); in device_initialize()
3150 INIT_LIST_HEAD(&dev->links.consumers); in device_initialize()
3151 INIT_LIST_HEAD(&dev->links.suppliers); in device_initialize()
3152 INIT_LIST_HEAD(&dev->links.defer_sync); in device_initialize()
3153 dev->links.status = DL_DEV_NO_DRIVER; in device_initialize()
3157 dev->dma_coherent = dma_default_coherent; in device_initialize()
3169 &devices_kset->kobj); in virtual_device_parent()
3191 return dir->class->ns_type; in class_dir_child_ns_type()
3208 return ERR_PTR(-ENOMEM); in class_dir_create_and_add()
3210 dir->class = sp->class; in class_dir_create_and_add()
3211 kobject_init(&dir->kobj, &class_dir_ktype); in class_dir_create_and_add()
3213 dir->kobj.kset = &sp->glue_dirs; in class_dir_create_and_add()
3215 retval = kobject_add(&dir->kobj, parent_kobj, "%s", sp->class->name); in class_dir_create_and_add()
3217 kobject_put(&dir->kobj); in class_dir_create_and_add()
3220 return &dir->kobj; in class_dir_create_and_add()
3228 struct subsys_private *sp = class_to_subsys(dev->class); in get_device_parent()
3237 * Class-devices with a non class-device as parent, live in get_device_parent()
3242 else if (parent->class && !dev->class->ns_type) { in get_device_parent()
3244 return &parent->kobj; in get_device_parent()
3246 parent_kobj = &parent->kobj; in get_device_parent()
3251 /* find our class-directory at the parent and reference it */ in get_device_parent()
3252 spin_lock(&sp->glue_dirs.list_lock); in get_device_parent()
3253 list_for_each_entry(k, &sp->glue_dirs.list, entry) in get_device_parent()
3254 if (k->parent == parent_kobj) { in get_device_parent()
3258 spin_unlock(&sp->glue_dirs.list_lock); in get_device_parent()
3265 /* or create a new class-directory at the parent device */ in get_device_parent()
3274 if (!parent && dev->bus) { in get_device_parent()
3275 struct device *dev_root = bus_get_dev_root(dev->bus); in get_device_parent()
3278 kobj = &dev_root->kobj; in get_device_parent()
3285 return &parent->kobj; in get_device_parent()
3295 if (!kobj || !dev->class) in live_in_glue_dir()
3298 sp = class_to_subsys(dev->class); in live_in_glue_dir()
3302 if (kobj->kset == &sp->glue_dirs) in live_in_glue_dir()
3313 return dev->kobj.parent; in get_glue_dir()
3317 * kobject_has_children - Returns whether a kobject has children.
3328 WARN_ON_ONCE(kref_read(&kobj->kref) == 0); in kobject_has_children()
3330 return kobj->sd && kobj->sd->dir.subdirs; in kobject_has_children()
3373 * sysfs_remove_dir() // glue_dir->sd=NULL in cleanup_glue_dir()
3374 * sysfs_put() // free glue_dir->sd in cleanup_glue_dir()
3386 * and sysfs_put(). This result in glue_dir->sd is freed. in cleanup_glue_dir()
3395 ref = kref_read(&glue_dir->kref); in cleanup_glue_dir()
3396 if (!kobject_has_children(glue_dir) && !--ref) in cleanup_glue_dir()
3409 error = sysfs_create_link(&dev->kobj, of_node_kobj(of_node), "of_node"); in device_add_class_symlinks()
3415 sp = class_to_subsys(dev->class); in device_add_class_symlinks()
3419 error = sysfs_create_link(&dev->kobj, &sp->subsys.kobj, "subsystem"); in device_add_class_symlinks()
3423 if (dev->parent && device_is_not_partition(dev)) { in device_add_class_symlinks()
3424 error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, in device_add_class_symlinks()
3431 error = sysfs_create_link(&sp->subsys.kobj, &dev->kobj, dev_name(dev)); in device_add_class_symlinks()
3437 sysfs_remove_link(&dev->kobj, "device"); in device_add_class_symlinks()
3439 sysfs_remove_link(&dev->kobj, "subsystem"); in device_add_class_symlinks()
3441 sysfs_remove_link(&dev->kobj, "of_node"); in device_add_class_symlinks()
3449 struct subsys_private *sp = class_to_subsys(dev->class); in device_remove_class_symlinks()
3452 sysfs_remove_link(&dev->kobj, "of_node"); in device_remove_class_symlinks()
3457 if (dev->parent && device_is_not_partition(dev)) in device_remove_class_symlinks()
3458 sysfs_remove_link(&dev->kobj, "device"); in device_remove_class_symlinks()
3459 sysfs_remove_link(&dev->kobj, "subsystem"); in device_remove_class_symlinks()
3460 sysfs_delete_link(&sp->subsys.kobj, &dev->kobj, dev_name(dev)); in device_remove_class_symlinks()
3465 * dev_set_name - set a device name
3475 err = kobject_set_name_vargs(&dev->kobj, fmt, vargs); in dev_set_name()
3497 format_dev_t(devt_str, dev->devt); in device_create_sys_dev_entry()
3498 error = sysfs_create_link(kobj, &dev->kobj, devt_str); in device_create_sys_dev_entry()
3510 format_dev_t(devt_str, dev->devt); in device_remove_sys_dev_entry()
3517 dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL); in device_private_init()
3518 if (!dev->p) in device_private_init()
3519 return -ENOMEM; in device_private_init()
3520 dev->p->device = dev; in device_private_init()
3521 klist_init(&dev->p->klist_children, klist_children_get, in device_private_init()
3523 INIT_LIST_HEAD(&dev->p->deferred_probe); in device_private_init()
3528 * device_add - add device to device hierarchy.
3560 int error = -EINVAL; in device_add()
3567 if (!dev->p) { in device_add()
3578 if (dev->init_name) { in device_add()
3579 error = dev_set_name(dev, "%s", dev->init_name); in device_add()
3580 dev->init_name = NULL; in device_add()
3586 else if (dev->bus && dev->bus->dev_name) in device_add()
3587 error = dev_set_name(dev, "%s%u", dev->bus->dev_name, dev->id); in device_add()
3589 error = -EINVAL; in device_add()
3595 parent = get_device(dev->parent); in device_add()
3602 dev->kobj.parent = kobj; in device_add()
3610 error = kobject_add(&dev->kobj, dev->kobj.parent, NULL); in device_add()
3637 if (MAJOR(dev->devt)) { in device_add()
3653 kobject_uevent(&dev->kobj, KOBJ_ADD); in device_add()
3667 if (dev->fwnode && !dev->fwnode->dev) { in device_add()
3668 dev->fwnode->dev = dev; in device_add()
3679 if (dev->fwnode && fw_devlink_drv_reg_done && !dev->can_match) in device_add()
3683 klist_add_tail(&dev->p->knode_parent, in device_add()
3684 &parent->p->klist_children); in device_add()
3686 sp = class_to_subsys(dev->class); in device_add()
3688 mutex_lock(&sp->mutex); in device_add()
3690 klist_add_tail(&dev->p->knode_class, &sp->klist_devices); in device_add()
3693 list_for_each_entry(class_intf, &sp->interfaces, node) in device_add()
3694 if (class_intf->add_dev) in device_add()
3695 class_intf->add_dev(dev); in device_add()
3696 mutex_unlock(&sp->mutex); in device_add()
3703 if (MAJOR(dev->devt)) in device_add()
3709 dev->driver = NULL; in device_add()
3719 kobject_uevent(&dev->kobj, KOBJ_REMOVE); in device_add()
3721 kobject_del(&dev->kobj); in device_add()
3727 kfree(dev->p); in device_add()
3728 dev->p = NULL; in device_add()
3734 * device_register - register a device with the system.
3737 * This happens in two clean steps - initialize the device
3759 * get_device - increment reference count for device.
3768 return dev ? kobj_to_dev(kobject_get(&dev->kobj)) : NULL; in get_device()
3773 * put_device - decrement reference count.
3780 kobject_put(&dev->kobj); in put_device()
3795 if (dev->p->dead) in kill_device()
3797 dev->p->dead = true; in kill_device()
3803 * device_del - delete device from system.
3818 struct device *parent = dev->parent; in device_del()
3827 if (dev->fwnode && dev->fwnode->dev == dev) in device_del()
3828 dev->fwnode->dev = NULL; in device_del()
3838 klist_del(&dev->p->knode_parent); in device_del()
3839 if (MAJOR(dev->devt)) { in device_del()
3845 sp = class_to_subsys(dev->class); in device_del()
3849 mutex_lock(&sp->mutex); in device_del()
3851 list_for_each_entry(class_intf, &sp->interfaces, node) in device_del()
3852 if (class_intf->remove_dev) in device_del()
3853 class_intf->remove_dev(dev); in device_del()
3855 klist_del(&dev->p->knode_class); in device_del()
3856 mutex_unlock(&sp->mutex); in device_del()
3879 kobject_uevent(&dev->kobj, KOBJ_REMOVE); in device_del()
3881 kobject_del(&dev->kobj); in device_del()
3889 * device_unregister - unregister device from system.
3915 dev = p->device; in prev_device()
3928 dev = p->device; in next_device()
3934 * device_get_devnode - path of device node file
3942 * Non-default names may need to allocate a memory to compose
3955 if (dev->type && dev->type->devnode) in device_get_devnode()
3956 *tmp = dev->type->devnode(dev, mode, uid, gid); in device_get_devnode()
3961 if (dev->class && dev->class->devnode) in device_get_devnode()
3962 *tmp = dev->class->devnode(dev, mode); in device_get_devnode()
3978 * device_for_each_child - device child iterator.
3996 if (!parent || !parent->p) in device_for_each_child()
3999 klist_iter_init(&parent->p->klist_children, &i); in device_for_each_child()
4008 * device_for_each_child_reverse - device child iterator in reversed order.
4026 if (!parent || !parent->p) in device_for_each_child_reverse()
4029 klist_iter_init(&parent->p->klist_children, &i); in device_for_each_child_reverse()
4038 * device_for_each_child_reverse_from - device child iterator in reversed order.
4060 if (!parent->p) in device_for_each_child_reverse_from()
4063 klist_iter_init_node(&parent->p->klist_children, &i, in device_for_each_child_reverse_from()
4064 (from ? &from->p->knode_parent : NULL)); in device_for_each_child_reverse_from()
4073 * device_find_child - device iterator for locating a particular device.
4082 * The callback should return 0 if the device doesn't match and non-zero
4083 * if it does. If the callback returns non-zero and a reference to the
4095 if (!parent || !parent->p) in device_find_child()
4098 klist_iter_init(&parent->p->klist_children, &i); in device_find_child()
4108 * device_find_child_by_name - device iterator for locating a child device.
4126 klist_iter_init(&parent->p->klist_children, &i); in device_find_child_by_name()
4141 * device_find_any_child - device iterator for locating a child device, if any.
4159 return -ENOMEM; in devices_init()
4183 return -ENOMEM; in devices_init()
4194 return device_supports_offline(dev) && !dev->offline ? -EBUSY : 0; in device_check_offline()
4198 * device_offline - Prepare the device for hot-removal.
4202 * the device for a subsequent hot-removal. If that succeeds, the device must
4212 if (dev->offline_disabled) in device_offline()
4213 return -EPERM; in device_offline()
4221 if (dev->offline) { in device_offline()
4224 ret = dev->bus->offline(dev); in device_offline()
4226 kobject_uevent(&dev->kobj, KOBJ_OFFLINE); in device_offline()
4227 dev->offline = true; in device_offline()
4237 * device_online - Put the device back online after successful device_offline().
4252 if (dev->offline) { in device_online()
4253 ret = dev->bus->online(dev); in device_online()
4255 kobject_uevent(&dev->kobj, KOBJ_ONLINE); in device_online()
4256 dev->offline = false; in device_online()
4283 * __root_device_register - allocate and register a root device
4307 int err = -ENOMEM; in __root_device_register()
4313 err = dev_set_name(&root->dev, "%s", name); in __root_device_register()
4319 root->dev.release = root_device_release; in __root_device_register()
4321 err = device_register(&root->dev); in __root_device_register()
4323 put_device(&root->dev); in __root_device_register()
4329 struct module_kobject *mk = &owner->mkobj; in __root_device_register()
4331 err = sysfs_create_link(&root->dev.kobj, &mk->kobj, "module"); in __root_device_register()
4333 device_unregister(&root->dev); in __root_device_register()
4336 root->owner = owner; in __root_device_register()
4340 return &root->dev; in __root_device_register()
4345 * root_device_unregister - unregister and free a root device
4355 if (root->owner) in root_device_unregister()
4356 sysfs_remove_link(&root->dev.kobj, "module"); in root_device_unregister()
4376 int retval = -ENODEV; in device_create_groups_vargs()
4383 retval = -ENOMEM; in device_create_groups_vargs()
4388 dev->devt = devt; in device_create_groups_vargs()
4389 dev->class = class; in device_create_groups_vargs()
4390 dev->parent = parent; in device_create_groups_vargs()
4391 dev->groups = groups; in device_create_groups_vargs()
4392 dev->release = device_create_release; in device_create_groups_vargs()
4395 retval = kobject_set_name_vargs(&dev->kobj, fmt, args); in device_create_groups_vargs()
4411 * device_create - creates a device and registers it with sysfs
4446 * device_create_with_groups - creates a device and registers it with sysfs
4451 * @groups: NULL-terminated list of attribute groups to be created
4487 * device_destroy - removes a device that was created with device_create()
4507 * device_rename - renames a device
4530 * renamed it -- then you get events for the same DEVPATH, before you even see
4533 * other things than (driver-core wise very simple) network devices.
4537 * symlinks -- but never rename kernel devices later, it's a complete mess. We
4544 struct kobject *kobj = &dev->kobj; in device_rename()
4551 return -EINVAL; in device_rename()
4557 error = -ENOMEM; in device_rename()
4561 if (dev->class) { in device_rename()
4562 sp = class_to_subsys(dev->class); in device_rename()
4565 error = -EINVAL; in device_rename()
4569 error = sysfs_rename_link_ns(&sp->subsys.kobj, kobj, old_device_name, in device_rename()
4580 sysfs_rename_link_ns(&sp->subsys.kobj, kobj, new_name, in device_rename()
4599 sysfs_remove_link(&dev->kobj, "device"); in device_move_class_links()
4601 error = sysfs_create_link(&dev->kobj, &new_parent->kobj, in device_move_class_links()
4607 * device_move - moves a device to a new parent
4621 return -EINVAL; in device_move()
4634 error = kobject_move(&dev->kobj, new_parent_kobj); in device_move()
4640 old_parent = dev->parent; in device_move()
4641 dev->parent = new_parent; in device_move()
4643 klist_remove(&dev->p->knode_parent); in device_move()
4645 klist_add_tail(&dev->p->knode_parent, in device_move()
4646 &new_parent->p->klist_children); in device_move()
4650 if (dev->class) { in device_move()
4655 if (!kobject_move(&dev->kobj, &old_parent->kobj)) { in device_move()
4657 klist_remove(&dev->p->knode_parent); in device_move()
4658 dev->parent = old_parent; in device_move()
4660 klist_add_tail(&dev->p->knode_parent, in device_move()
4661 &old_parent->p->klist_children); in device_move()
4698 struct kobject *kobj = &dev->kobj; in device_attrs_change_owner()
4699 const struct class *class = dev->class; in device_attrs_change_owner()
4700 const struct device_type *type = dev->type; in device_attrs_change_owner()
4708 error = sysfs_groups_change_owner(kobj, class->dev_groups, kuid, in device_attrs_change_owner()
4719 error = sysfs_groups_change_owner(kobj, type->groups, kuid, in device_attrs_change_owner()
4726 error = sysfs_groups_change_owner(kobj, dev->groups, kuid, kgid); in device_attrs_change_owner()
4730 if (device_supports_offline(dev) && !dev->offline_disabled) { in device_attrs_change_owner()
4742 * device_change_owner - change the owner of an existing device.
4756 struct kobject *kobj = &dev->kobj; in device_change_owner()
4761 return -EINVAL; in device_change_owner()
4800 sp = class_to_subsys(dev->class); in device_change_owner()
4802 error = -EINVAL; in device_change_owner()
4805 error = sysfs_link_change_owner(&sp->subsys.kobj, &dev->kobj, dev_name(dev), kuid, kgid); in device_change_owner()
4815 * device_shutdown - call ->shutdown() on each device to shutdown.
4826 spin_lock(&devices_kset->list_lock); in device_shutdown()
4832 while (!list_empty(&devices_kset->list)) { in device_shutdown()
4833 dev = list_entry(devices_kset->list.prev, struct device, in device_shutdown()
4841 parent = get_device(dev->parent); in device_shutdown()
4845 * event that dev->*->shutdown() doesn't remove it. in device_shutdown()
4847 list_del_init(&dev->kobj.entry); in device_shutdown()
4848 spin_unlock(&devices_kset->list_lock); in device_shutdown()
4859 if (dev->class && dev->class->shutdown_pre) { in device_shutdown()
4862 dev->class->shutdown_pre(dev); in device_shutdown()
4864 if (dev->bus && dev->bus->shutdown) { in device_shutdown()
4867 dev->bus->shutdown(dev); in device_shutdown()
4868 } else if (dev->driver && dev->driver->shutdown) { in device_shutdown()
4871 dev->driver->shutdown(dev); in device_shutdown()
4881 spin_lock(&devices_kset->list_lock); in device_shutdown()
4883 spin_unlock(&devices_kset->list_lock); in device_shutdown()
4898 if (dev->class) in set_dev_info()
4899 subsys = dev->class->name; in set_dev_info()
4900 else if (dev->bus) in set_dev_info()
4901 subsys = dev->bus->name; in set_dev_info()
4905 strscpy(dev_info->subsystem, subsys); in set_dev_info()
4914 if (MAJOR(dev->devt)) { in set_dev_info()
4922 snprintf(dev_info->device, sizeof(dev_info->device), in set_dev_info()
4923 "%c%u:%u", c, MAJOR(dev->devt), MINOR(dev->devt)); in set_dev_info()
4927 snprintf(dev_info->device, sizeof(dev_info->device), in set_dev_info()
4928 "n%u", net->ifindex); in set_dev_info()
4930 snprintf(dev_info->device, sizeof(dev_info->device), in set_dev_info()
4965 dev_printk_emit(level[1] - '0', dev, "%s %s: %pV", in __dev_printk()
5016 * dev_err_probe - probe error check and log helper
5019 * @fmt: printf-style format string
5024 * -EPROBE_DEFER and propagate error upwards.
5025 * In case of -EPROBE_DEFER it sets also defer probe reason, which can be
5029 * if (err != -EPROBE_DEFER)
5040 * known to never be -EPROBE_DEFER.
5043 * instead of "-35") and the fact that the error code is returned which allows
5058 case -EPROBE_DEFER: in dev_err_probe()
5063 case -ENOMEM: in dev_err_probe()
5065 * We don't print anything on -ENOMEM, there is already enough in dev_err_probe()
5083 return fwnode && !IS_ERR(fwnode->secondary); in fwnode_is_primary()
5087 * set_primary_fwnode - Change the primary firmware node of a given device.
5095 * - primary --> secondary --> -ENODEV
5096 * - primary --> NULL
5097 * - secondary --> -ENODEV
5098 * - NULL
5102 struct device *parent = dev->parent; in set_primary_fwnode()
5103 struct fwnode_handle *fn = dev->fwnode; in set_primary_fwnode()
5107 fn = fn->secondary; in set_primary_fwnode()
5110 WARN_ON(fwnode->secondary); in set_primary_fwnode()
5111 fwnode->secondary = fn; in set_primary_fwnode()
5113 dev->fwnode = fwnode; in set_primary_fwnode()
5116 dev->fwnode = fn->secondary; in set_primary_fwnode()
5118 /* Skip nullifying fn->secondary if the primary is shared */ in set_primary_fwnode()
5119 if (parent && fn == parent->fwnode) in set_primary_fwnode()
5122 /* Set fn->secondary = NULL, so fn remains the primary fwnode */ in set_primary_fwnode()
5123 fn->secondary = NULL; in set_primary_fwnode()
5125 dev->fwnode = NULL; in set_primary_fwnode()
5132 * set_secondary_fwnode - Change the secondary firmware node of a given device.
5143 fwnode->secondary = ERR_PTR(-ENODEV); in set_secondary_fwnode()
5145 if (fwnode_is_primary(dev->fwnode)) in set_secondary_fwnode()
5146 dev->fwnode->secondary = fwnode; in set_secondary_fwnode()
5148 dev->fwnode = fwnode; in set_secondary_fwnode()
5153 * device_set_of_node_from_dev - reuse device-tree node of another device
5154 * @dev: device whose device-tree node is being set
5155 * @dev2: device whose device-tree node is being reused
5157 * Takes another reference to the new device-tree node after first dropping
5162 of_node_put(dev->of_node); in device_set_of_node_from_dev()
5163 dev->of_node = of_node_get(dev2->of_node); in device_set_of_node_from_dev()
5164 dev->of_node_reused = true; in device_set_of_node_from_dev()
5170 dev->fwnode = fwnode; in device_set_node()
5171 dev->of_node = to_of_node(fwnode); in device_set_node()
5183 return dev->of_node == np; in device_match_of_node()
5195 return dev->devt == *(dev_t *)pdevt; in device_match_devt()