Skip to content

Commit fb0e6ca

Browse files
marcanjannau
authored andcommitted
driver core: fw_devlink: Add fw_devlink_count_absent_consumers()
Some platforms have power domains that are active on boot and must remain powered up until all of their consumers probe. The genpd core needs a way to count how many consumers haven't probed yet to avoid powering off such domains. Add a fw_devlink_count_absent_consumers() function, which returns the total count of consumer devices which either have not been created at all yet (only fwlinks exist) or have been created but have no driver bound and fully probed yet. Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent 2f22582 commit fb0e6ca

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

drivers/base/core.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,32 @@ static void fw_devlink_link_device(struct device *dev)
23442344
mutex_unlock(&fwnode_link_lock);
23452345
}
23462346

2347+
/**
2348+
* fw_devlink_count_absent_consumers - Return how many consumers have
2349+
* either not been created yet, or do not yet have a driver attached.
2350+
* @fwnode: fwnode of the supplier
2351+
*/
2352+
int fw_devlink_count_absent_consumers(struct fwnode_handle *fwnode)
2353+
{
2354+
struct fwnode_link *link, *tmp;
2355+
struct device_link *dlink, *dtmp;
2356+
struct device *sup_dev = get_dev_from_fwnode(fwnode);
2357+
int count = 0;
2358+
2359+
list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook)
2360+
count++;
2361+
2362+
if (!sup_dev)
2363+
return count;
2364+
2365+
list_for_each_entry_safe(dlink, dtmp, &sup_dev->links.consumers, s_node)
2366+
if (dlink->consumer->links.status != DL_DEV_DRIVER_BOUND)
2367+
count++;
2368+
2369+
return count;
2370+
}
2371+
EXPORT_SYMBOL_GPL(fw_devlink_count_absent_consumers);
2372+
23472373
/* Device links support end. */
23482374

23492375
int (*platform_notify)(struct device *dev) = NULL;

include/linux/fwnode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,5 +221,6 @@ int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup,
221221
void fwnode_links_purge(struct fwnode_handle *fwnode);
222222
void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
223223
bool fw_devlink_is_strict(void);
224+
int fw_devlink_count_absent_consumers(struct fwnode_handle *fwnode);
224225

225226
#endif

0 commit comments

Comments
 (0)