driver core: Add support for linking devices during device addition

The firmware corresponding to a device (dev.fwnode) might be able to
provide functional dependency information between a device and its
supplier and consumer devices.  Tracking this functional dependency
allows optimizing device probe order and informing a supplier when all
its consumers have probed (and thereby actively managing their
resources).

The existing device links feature allows tracking and using
supplier-consumer relationships. So, this patch adds the add_links()
fwnode callback to allow firmware to create device links for each
device as the device is added.

However, when consumer devices are added, they might not have a supplier
device to link to despite needing mandatory resources/functionality from
one or more suppliers. A waiting_for_suppliers list is created to track
such consumers and retry linking them when new devices get added.

Signed-off-by: Saravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20190904211126.47518-3-saravanak@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Saravana Kannan 2019-09-04 14:11:21 -07:00 committed by Greg Kroah-Hartman
parent 372a67c0c5
commit e2ae9bcc4a
4 changed files with 109 additions and 1 deletions

View file

@ -66,6 +66,21 @@ struct fwnode_reference_args {
* endpoint node.
* @graph_get_port_parent: Return the parent node of a port node.
* @graph_parse_endpoint: Parse endpoint for port and endpoint id.
* @add_links: Called after the device corresponding to the fwnode is added
* using device_add(). The function is expected to create device
* links to all the suppliers of the device that are available at
* the time this function is called. The function must NOT stop
* at the first failed device link if other unlinked supplier
* devices are present in the system. If some suppliers are not
* yet available, this function will be called again when other
* devices are added to allow creating device links to any newly
* available suppliers.
*
* Return 0 if device links have been successfully created to all
* the suppliers of this device or if the supplier information is
* not known. Return an error if and only if the supplier
* information is known but some of the suppliers are not yet
* available to create device links to.
*/
struct fwnode_operations {
struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
@ -103,6 +118,8 @@ struct fwnode_operations {
(*graph_get_port_parent)(struct fwnode_handle *fwnode);
int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
struct fwnode_endpoint *endpoint);
int (*add_links)(const struct fwnode_handle *fwnode,
struct device *dev);
};
#define fwnode_has_op(fwnode, op) \