Skip to content

Commit 98decb0

Browse files
committed
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 <[email protected]>
1 parent 49e57e6 commit 98decb0

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

drivers/base/core.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,33 @@ void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode)
202202
}
203203
EXPORT_SYMBOL_GPL(fw_devlink_purge_absent_suppliers);
204204

205+
/**
206+
* fw_devlink_count_absent_consumers - Return how many consumers have
207+
* either not been created yet, or do not yet have a driver attached.
208+
* @fwnode: fwnode of the supplier
209+
*/
210+
int fw_devlink_count_absent_consumers(struct fwnode_handle *fwnode)
211+
{
212+
struct fwnode_link *link, *tmp;
213+
struct device_link *dlink, *dtmp;
214+
struct device *sup_dev = get_dev_from_fwnode(fwnode);
215+
int count = 0;
216+
217+
list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook)
218+
count++;
219+
220+
if (!sup_dev)
221+
return count;
222+
223+
list_for_each_entry_safe(dlink, dtmp, &sup_dev->links.consumers, s_node)
224+
if (dlink->consumer->links.status != DL_DEV_DRIVER_BOUND)
225+
count++;
226+
227+
return count;
228+
}
229+
EXPORT_SYMBOL_GPL(fw_devlink_count_absent_consumers);
230+
231+
205232
/**
206233
* __fwnode_links_move_consumers - Move consumer from @from to @to fwnode_handle
207234
* @from: move consumers away from this fwnode

include/linux/fwnode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,6 @@ extern bool fw_devlink_is_strict(void);
211211
int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
212212
void fwnode_links_purge(struct fwnode_handle *fwnode);
213213
void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
214+
int fw_devlink_count_absent_consumers(struct fwnode_handle *fwnode);
214215

215216
#endif

0 commit comments

Comments
 (0)