Lines Matching defs:link
49 * __fwnode_link_add - Create a link between two fwnode_handles.
50 * @con: Consumer end of the link.
51 * @sup: Supplier end of the link.
53 * Create a fwnode link between fwnode handles @con and @sup. The fwnode link
57 * The driver core will use the fwnode link to create a device link between the
59 * driver core will automatically delete the fwnode link between @con and @sup
68 struct fwnode_link *link;
70 list_for_each_entry(link, &sup->consumers, s_hook)
71 if (link->consumer == con) {
72 link->flags |= flags;
76 link = kzalloc(sizeof(*link), GFP_KERNEL);
77 if (!link)
80 link->supplier = sup;
81 INIT_LIST_HEAD(&link->s_hook);
82 link->consumer = con;
83 INIT_LIST_HEAD(&link->c_hook);
84 link->flags = flags;
86 list_add(&link->s_hook, &sup->consumers);
87 list_add(&link->c_hook, &con->suppliers);
105 * __fwnode_link_del - Delete a link between two fwnode_handles.
106 * @link: the fwnode_link to be deleted
110 static void __fwnode_link_del(struct fwnode_link *link)
112 pr_debug("%pfwf Dropping the fwnode link to %pfwf\n",
113 link->consumer, link->supplier);
114 list_del(&link->s_hook);
115 list_del(&link->c_hook);
116 kfree(link);
120 * __fwnode_link_cycle - Mark a fwnode link as being part of a cycle.
121 * @link: the fwnode_link to be marked
125 static void __fwnode_link_cycle(struct fwnode_link *link)
127 pr_debug("%pfwf: Relaxing link with %pfwf\n",
128 link->consumer, link->supplier);
129 link->flags |= FWLINK_FLAG_CYCLE;
140 struct fwnode_link *link, *tmp;
143 list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook)
144 __fwnode_link_del(link);
156 struct fwnode_link *link, *tmp;
159 list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook)
160 __fwnode_link_del(link);
202 struct fwnode_link *link, *tmp;
204 list_for_each_entry_safe(link, tmp, &from->consumers, s_hook) {
205 __fwnode_link_add(link->consumer, to, link->flags);
206 __fwnode_link_del(link);
270 static void device_link_remove_from_lists(struct device_link *link)
272 list_del_rcu(&link->s_node);
273 list_del_rcu(&link->c_node);
304 struct device_link *link;
319 list_for_each_entry(link, &dev->links.consumers, s_node) {
320 if (device_link_flag_is_sync_state_only(link->flags))
323 if (link->consumer == target)
326 ret = device_is_dependent(link->consumer, target);
333 static void device_link_init_status(struct device_link *link,
342 * A consumer driver can create a link to a supplier
348 link->status = DL_STATE_CONSUMER_PROBE;
351 link->status = DL_STATE_DORMANT;
358 link->status = DL_STATE_CONSUMER_PROBE;
361 link->status = DL_STATE_ACTIVE;
364 link->status = DL_STATE_AVAILABLE;
369 link->status = DL_STATE_SUPPLIER_UNBIND;
372 link->status = DL_STATE_DORMANT;
379 struct device_link *link;
392 list_for_each_entry(link, &dev->links.consumers, s_node) {
393 if (device_link_flag_is_sync_state_only(link->flags))
395 device_reorder_to_tail(link->consumer, NULL);
459 struct device_link *link = to_devlink(dev);
462 if (link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER)
464 else if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER)
476 struct device_link *link = to_devlink(dev);
478 return sysfs_emit(buf, "%d\n", !!(link->flags & DL_FLAG_PM_RUNTIME));
485 struct device_link *link = to_devlink(dev);
488 !!(link->flags & DL_FLAG_SYNC_STATE_ONLY));
503 struct device_link *link = container_of(work, struct device_link, rm_work);
505 /* Ensure that all references to the link object have been dropped. */
508 pm_runtime_release_supplier(link);
510 * If supplier_preactivated is set, the link has been dropped between
516 if (link->supplier_preactivated)
517 pm_runtime_put_noidle(link->supplier);
519 pm_request_idle(link->supplier);
521 put_device(link->consumer);
522 put_device(link->supplier);
523 kfree(link);
528 struct device_link *link = to_devlink(dev);
530 INIT_WORK(&link->rm_work, device_link_release_fn);
537 queue_work(system_long_wq, &link->rm_work);
550 struct device_link *link = to_devlink(dev);
551 struct device *sup = link->supplier;
552 struct device *con = link->consumer;
563 ret = sysfs_create_link(&link->link_dev.kobj, &sup->kobj, "supplier");
567 ret = sysfs_create_link(&link->link_dev.kobj, &con->kobj, "consumer");
572 ret = sysfs_create_link(&sup->kobj, &link->link_dev.kobj, buf);
577 ret = sysfs_create_link(&con->kobj, &link->link_dev.kobj, buf);
587 sysfs_remove_link(&link->link_dev.kobj, "consumer");
589 sysfs_remove_link(&link->link_dev.kobj, "supplier");
597 struct device_link *link = to_devlink(dev);
599 struct device *sup = link->supplier;
600 struct device *con = link->consumer;
603 sysfs_remove_link(&link->link_dev.kobj, "consumer");
604 sysfs_remove_link(&link->link_dev.kobj, "supplier");
612 WARN(1, "Unable to properly free device link symlinks!\n");
658 * device_link_add - Create a link between two devices.
659 * @consumer: Consumer end of the link.
660 * @supplier: Supplier end of the link.
663 * The caller is responsible for the proper synchronization of the link creation
665 * runtime PM framework to take the link into account. Second, if the
668 * of the link. If DL_FLAG_PM_RUNTIME is not set, DL_FLAG_RPM_ACTIVE will be
672 * expected to release the link returned by it directly with the help of either
676 * management of the link over to the driver core entirely and its return value
677 * can only be used to check whether or not the link is present. In that case,
678 * the DL_FLAG_AUTOREMOVE_CONSUMER and DL_FLAG_AUTOREMOVE_SUPPLIER device link
679 * flags can be used to indicate to the driver core when the link can be safely
681 * that the link is not going to be used (by the given caller of this function)
683 * device, so the link can be deleted at that point. If none of them is set,
684 * the link will be maintained until one of the devices pointed to by it (either
689 * managed device link is being added), the DL_FLAG_AUTOPROBE_CONSUMER flag can
696 * However, if a device link between the given @consumer and @supplier pair
697 * exists already when this function is called for them, the existing link will
698 * be returned regardless of its current type and status (the link's flags may
700 * the link as though it has just been created, so (in particular) if
701 * DL_FLAG_STATELESS was passed in @flags, the link needs to be released
704 * A side effect of the link creation is re-ordering of dpm_list and the
716 struct device_link *link;
746 * the supplier already in the graph, return NULL. If the link is a
747 * SYNC_STATE_ONLY link, we don't check for reverse dependencies
753 link = NULL;
764 link = NULL;
769 * DL_FLAG_AUTOREMOVE_SUPPLIER indicates that the link will be needed
776 list_for_each_entry(link, &supplier->links.consumers, s_node) {
777 if (link->consumer != consumer)
780 if (link->flags & DL_FLAG_INFERRED &&
782 link->flags &= ~DL_FLAG_INFERRED;
785 if (!(link->flags & DL_FLAG_PM_RUNTIME)) {
787 link->flags |= DL_FLAG_PM_RUNTIME;
790 refcount_inc(&link->rpm_active);
794 kref_get(&link->kref);
795 if (link->flags & DL_FLAG_SYNC_STATE_ONLY &&
796 !(link->flags & DL_FLAG_STATELESS)) {
797 link->flags |= DL_FLAG_STATELESS;
800 link->flags |= DL_FLAG_STATELESS;
806 * If the life time of the link following from the new flags is
807 * longer than indicated by the flags of the existing link,
808 * update the existing link to stay around longer.
811 if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) {
812 link->flags &= ~DL_FLAG_AUTOREMOVE_CONSUMER;
813 link->flags |= DL_FLAG_AUTOREMOVE_SUPPLIER;
816 link->flags &= ~(DL_FLAG_AUTOREMOVE_CONSUMER |
819 if (!(link->flags & DL_FLAG_MANAGED)) {
820 kref_get(&link->kref);
821 link->flags |= DL_FLAG_MANAGED;
822 device_link_init_status(link, consumer, supplier);
824 if (link->flags & DL_FLAG_SYNC_STATE_ONLY &&
826 link->flags &= ~DL_FLAG_SYNC_STATE_ONLY;
833 link = kzalloc(sizeof(*link), GFP_KERNEL);
834 if (!link)
837 refcount_set(&link->rpm_active, 1);
840 link->supplier = supplier;
841 INIT_LIST_HEAD(&link->s_node);
843 link->consumer = consumer;
844 INIT_LIST_HEAD(&link->c_node);
845 link->flags = flags;
846 kref_init(&link->kref);
848 link->link_dev.class = &devlink_class;
849 device_set_pm_not_required(&link->link_dev);
850 dev_set_name(&link->link_dev, "%s:%s--%s:%s",
853 if (device_register(&link->link_dev)) {
854 put_device(&link->link_dev);
855 link = NULL;
861 refcount_inc(&link->rpm_active);
866 /* Determine the initial link state. */
868 link->status = DL_STATE_NONE;
870 device_link_init_status(link, consumer, supplier);
873 * Some callers expect the link creation during consumer driver probe to
876 if (link->status == DL_STATE_CONSUMER_PROBE &&
880 list_add_tail_rcu(&link->s_node, &supplier->links.consumers);
881 list_add_tail_rcu(&link->c_node, &consumer->links.suppliers);
906 if ((flags & DL_FLAG_PM_RUNTIME && flags & DL_FLAG_RPM_ACTIVE) && !link)
909 return link;
915 struct device_link *link = container_of(kref, struct device_link, kref);
917 dev_dbg(link->consumer, "Dropping the link to %s\n",
918 dev_name(link->supplier));
920 pm_runtime_drop_link(link);
922 device_link_remove_from_lists(link);
923 device_unregister(&link->link_dev);
926 static void device_link_put_kref(struct device_link *link)
928 if (link->flags & DL_FLAG_STATELESS)
929 kref_put(&link->kref, __device_link_del);
930 else if (!device_is_registered(link->consumer))
931 __device_link_del(&link->kref);
933 WARN(1, "Unable to drop a managed device link reference\n");
937 * device_link_del - Delete a stateless link between two devices.
938 * @link: Device link to delete.
941 * PM. If the link was added multiple times, it needs to be deleted as often.
945 void device_link_del(struct device_link *link)
948 device_link_put_kref(link);
954 * device_link_remove - Delete a stateless link between two devices.
955 * @consumer: Consumer end of the link.
956 * @supplier: Supplier end of the link.
963 struct device_link *link;
970 list_for_each_entry(link, &supplier->links.consumers, s_node) {
971 if (link->consumer == consumer) {
972 device_link_put_kref(link);
983 struct device_link *link;
985 list_for_each_entry(link, &dev->links.suppliers, c_node) {
986 if (link->status != DL_STATE_CONSUMER_PROBE)
989 if (link->supplier->links.status == DL_DEV_DRIVER_BOUND) {
990 WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
992 WARN_ON(!(link->flags & DL_FLAG_SYNC_STATE_ONLY));
993 WRITE_ONCE(link->status, DL_STATE_DORMANT);
1007 struct fwnode_link *link;
1012 list_for_each_entry(link, &fwnode->suppliers, c_hook)
1013 if (!(link->flags & FWLINK_FLAG_CYCLE))
1014 return link->supplier;
1030 * mark the link as "consumer probe in progress" to make the supplier removal
1037 struct device_link *link;
1062 list_for_each_entry(link, &dev->links.suppliers, c_node) {
1063 if (!(link->flags & DL_FLAG_MANAGED))
1066 if (link->status != DL_STATE_AVAILABLE &&
1067 !(link->flags & DL_FLAG_SYNC_STATE_ONLY)) {
1070 link->flags & DL_FLAG_INFERRED &&
1071 !link->supplier->can_match) {
1079 dev_name(link->supplier));
1083 WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE);
1113 struct device_link *link;
1120 list_for_each_entry(link, &dev->links.consumers, s_node) {
1121 if (!(link->flags & DL_FLAG_MANAGED))
1123 if (link->status != DL_STATE_ACTIVE)
1219 static void device_link_drop_managed(struct device_link *link)
1221 link->flags &= ~DL_FLAG_MANAGED;
1222 WRITE_ONCE(link->status, DL_STATE_NONE);
1223 kref_put(&link->kref, __device_link_del);
1247 * supplier before it's bound to the driver. We still want the device link
1252 * the device link status is set to CONSUMER_PROBE. Otherwise, the device link
1257 struct device_link *link, *ln;
1261 list_for_each_entry_safe(link, ln, &dev->links.suppliers, c_node) {
1262 if (!(link->flags & DL_FLAG_MANAGED))
1265 if (link->status != DL_STATE_AVAILABLE) {
1266 device_link_drop_managed(link);
1269 WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE);
1289 struct device_link *link, *ln;
1320 list_for_each_entry(link, &dev->links.consumers, s_node) {
1321 if (!(link->flags & DL_FLAG_MANAGED))
1330 if (link->status == DL_STATE_CONSUMER_PROBE ||
1331 link->status == DL_STATE_ACTIVE)
1334 WARN_ON(link->status != DL_STATE_DORMANT);
1335 WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
1337 if (link->flags & DL_FLAG_AUTOPROBE_CONSUMER)
1338 driver_deferred_probe_add(link->consumer);
1346 list_for_each_entry_safe(link, ln, &dev->links.suppliers, c_node) {
1349 if (!(link->flags & DL_FLAG_MANAGED))
1352 supplier = link->supplier;
1353 if (link->flags & DL_FLAG_SYNC_STATE_ONLY) {
1357 * save to drop the managed link completely.
1359 device_link_drop_managed(link);
1361 link->flags & DL_FLAG_INFERRED &&
1362 link->status != DL_STATE_CONSUMER_PROBE &&
1363 !link->supplier->can_match) {
1368 * point in maintaining a device link in a weird state
1371 device_link_drop_managed(link);
1373 WARN_ON(link->status != DL_STATE_CONSUMER_PROBE);
1374 WRITE_ONCE(link->status, DL_STATE_ACTIVE);
1379 * DL_FLAG_SYNC_STATE_ONLY device link in case it was the last
1380 * device link that was preventing the supplier from getting a
1410 struct device_link *link, *ln;
1412 list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers, c_node) {
1413 if (!(link->flags & DL_FLAG_MANAGED))
1416 if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) {
1417 device_link_drop_managed(link);
1421 if (link->status != DL_STATE_CONSUMER_PROBE &&
1422 link->status != DL_STATE_ACTIVE)
1425 if (link->supplier->links.status == DL_DEV_DRIVER_BOUND) {
1426 WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
1428 WARN_ON(!(link->flags & DL_FLAG_SYNC_STATE_ONLY));
1429 WRITE_ONCE(link->status, DL_STATE_DORMANT);
1448 struct device_link *link;
1452 list_for_each_entry(link, &dev->links.consumers, s_node) {
1453 if (!(link->flags & DL_FLAG_MANAGED))
1457 * The probe has failed, so if the status of the link is
1463 if (link->status == DL_STATE_CONSUMER_PROBE ||
1464 link->status == DL_STATE_ACTIVE)
1465 WRITE_ONCE(link->status, DL_STATE_DORMANT);
1485 struct device_link *link, *ln;
1489 list_for_each_entry_safe(link, ln, &dev->links.consumers, s_node) {
1490 if (!(link->flags & DL_FLAG_MANAGED))
1493 WARN_ON(link->flags & DL_FLAG_AUTOREMOVE_CONSUMER);
1494 WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND);
1498 * devices that are not active, i.e. where the link state
1501 if (link->status == DL_STATE_SUPPLIER_UNBIND &&
1502 link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER)
1503 device_link_drop_managed(link);
1505 WRITE_ONCE(link->status, DL_STATE_DORMANT);
1518 * Check each consumer of the device and return 'true' if its link's status
1520 * probing right now or its driver is present). Otherwise, change the link
1530 struct device_link *link;
1535 list_for_each_entry(link, &dev->links.consumers, s_node) {
1536 if (!(link->flags & DL_FLAG_MANAGED))
1539 if (link->status == DL_STATE_CONSUMER_PROBE
1540 || link->status == DL_STATE_ACTIVE) {
1544 WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND);
1561 * If that's not the case, change the status of the link to "supplier unbind"
1562 * and check if the link was in the "active" state. If so, force the consumer
1564 * changed the state of the link already).
1570 struct device_link *link;
1575 list_for_each_entry(link, &dev->links.consumers, s_node) {
1578 if (!(link->flags & DL_FLAG_MANAGED) ||
1579 link->flags & DL_FLAG_SYNC_STATE_ONLY)
1582 status = link->status;
1589 WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND);
1591 struct device *consumer = link->consumer;
1613 struct device_link *link, *ln;
1624 list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers, c_node) {
1625 WARN_ON(link->status == DL_STATE_ACTIVE);
1626 __device_link_del(&link->kref);
1629 list_for_each_entry_safe_reverse(link, ln, &dev->links.consumers, s_node) {
1630 WARN_ON(link->status != DL_STATE_DORMANT &&
1631 link->status != DL_STATE_NONE);
1632 __device_link_del(&link->kref);
1733 static void fw_devlink_relax_link(struct device_link *link)
1735 if (!(link->flags & DL_FLAG_INFERRED))
1738 if (device_link_flag_is_sync_state_only(link->flags))
1741 pm_runtime_drop_link(link);
1742 link->flags = DL_FLAG_MANAGED | FW_DEVLINK_FLAGS_PERMISSIVE;
1743 dev_dbg(link->consumer, "Relaxing link with %s\n",
1744 dev_name(link->supplier));
1749 struct device_link *link = to_devlink(dev);
1751 if (!link->supplier->can_match)
1752 fw_devlink_relax_link(link);
1768 struct device_link *link = to_devlink(dev);
1769 struct device *sup = link->supplier;
1771 if (!(link->flags & DL_FLAG_MANAGED) ||
1772 link->status == DL_STATE_ACTIVE || sup->state_synced ||
1778 dev_name(link->consumer));
1862 struct device_link *link;
1868 list_for_each_entry(link, &dev->links.consumers, s_node)
1869 fw_devlink_relax_link(link);
1908 * Needs to be called with fwnode_lock and device link lock held.
1915 * converted into a device link in the future, they are created as
1927 struct fwnode_link *link;
1962 list_for_each_entry(link, &sup_handle->suppliers, c_hook) {
1963 if (__fw_devlink_relax_cycles(con, link->supplier)) {
1964 __fwnode_link_cycle(link);
2009 * fw_devlink_create_devlink - Create a device link from a consumer to fwnode
2010 * @con: consumer device for the device link
2012 * @link: fwnode link that's being converted to a device link
2014 * This function will try to create a device link between the consumer device
2020 * device link from the consumer to a missing supplier.
2023 * 0 on successfully creating a device link
2024 * -EINVAL if the device link cannot be created as expected
2025 * -EAGAIN if the device link cannot be created right now, but it may be
2030 struct fwnode_link *link)
2036 if (con->fwnode == link->consumer)
2037 flags = fw_devlink_get_flags(link->flags);
2063 * However, if the device link was marked as SYNC_STATE_ONLY because
2072 __fwnode_link_cycle(link);
2073 flags = fw_devlink_get_flags(link->flags);
2101 dev_err(con, "Failed to create device link (0x%x) with %s\n",
2134 * SYNC_STATE_ONLY link between @dev (supplier) and the closest ancestor device
2145 struct fwnode_link *link, *tmp;
2147 list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) {
2152 con_dev = get_dev_from_fwnode(link->consumer);
2155 * SYNC_STATE_ONLY link from the consumer's parent device to
2158 * consumer can create a device link to the supplier.
2160 * This proxy link step is needed to handle the case where the
2164 con_dev = fwnode_get_next_parent_dev(link->consumer);
2168 * consumer-supplier link from the parent to its child
2183 ret = fw_devlink_create_devlink(con_dev, fwnode, link);
2188 __fwnode_link_del(link);
2219 struct fwnode_link *link, *tmp;
2222 list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) {
2224 struct fwnode_handle *sup = link->supplier;
2226 ret = fw_devlink_create_devlink(dev, sup, link);
2230 __fwnode_link_del(link);
2235 * all the descendants. This proxy link step is needed to handle the
3370 dev_warn(dev, "Error %d creating of_node link\n",error);
3389 /* link in the class directory pointing to the device */
3617 * link to it.
3623 * waiting consumers can link to it before the driver is bound to the