Make fw_devlink=on more forgiving
Subsystems (5)
v3 cover Make fw_devlink=on more forgiving
I dropped a few patches from v2 of the series that are still work in progress. So v3 of the series only includes definitive patches and the patch numbering has changed.
Patch 1/4 and 2/4 addresses the issue of firmware nodes that look like they'll have struct devices created for them, but will never actually have struct devices added for them. For example, DT nodes with a compatible property that don't have devices added for them.
Patch 3/4 and 4/4 allow for handling optional DT bindings.
v1 -> v2:
Patch 1: Added a flag to fwnodes that aren't devices.
Patch 3: New patch to ise the flag set in patch 1 to not create bad links.
v2 -> v3:
- Patch 1: Added Rafael's Ack
- New patches 3 and 4
Saravana Kannan (4):
driver core: fw_devlink: Detect supplier devices that will never be
added
of: property: Don't add links to absent suppliers
driver core: Add fw_devlink.strict kernel param
of: property: Add fw_devlink support for optional properties
.../admin-guide/kernel-parameters.txt | 5 +++ drivers/base/core.c | 43 +++++++++++++++++-- drivers/of/property.c | 16 +++++-- include/linux/fwnode.h | 3 ++ 4 files changed, 60 insertions(+), 7 deletions(-)
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 1/4 driver core: fw_devlink: Detect supplier devices that will never be added
During the initial parsing of firmware by fw_devlink, fw_devlink might infer that some supplier firmware nodes would get populated as devices. But the inference is not always correct. This patch tries to logically detect and fix such mistakes as boot progresses or more devices probe.
fw_devlink makes a fundamental assumption that once a device binds to a driver, it will populate (i.e: add as struct devices) all the child firmware nodes that could be populated as devices (if they aren't populated already).
So, whenever a device probes, we check all its child firmware nodes. If a child firmware node has a corresponding device populated, we don't modify the child node or its descendants. However, if a child firmware node has not been populated as a device, we delete all the fwnode links where the child node or its descendants are suppliers. This ensures that no other device is blocked on a firmware node that will never be populated as a device. We also mark such fwnodes as NOT_DEVICE, so that no new fwnode links are created with these nodes as suppliers.
--- drivers/base/core.c | 31 ++++++++++++++++++++++++++++--- include/linux/fwnode.h | 2 ++ 2 files changed, 30 insertions(+), 3 deletions(-)
drivers/base/core.c +28 -3
@@ -148,6 +148,21 @@ void fwnode_links_purge(struct fwnode_handle *fwnode)fwnode_links_purge_consumers (fwnode); } +static void fw_devlink_purge_absent_suppliers (struct fwnode_handle *fwnode) +{ +struct fwnode_handle *child; + +/* Don't purge consumer links of an added child */ +if (fwnode->dev) +return ; + + fwnode->flags |=FWNODE_FLAG_NOT_DEVICE ; +fwnode_links_purge_consumers (fwnode); + +fwnode_for_each_available_child_node (fwnode, child) +fw_devlink_purge_absent_suppliers (child); +} +#ifdef CONFIG_SRCU static DEFINE_MUTEX (device_links_lock);DEFINE_STATIC_SRCU (device_links_srcu);
@@ -1154,12 +1169,22 @@ void device_links_driver_bound(struct device *dev)LIST_HEAD (sync_list);/* -* If a device probes successfully, it's expected to have created all +* If a device binds successfully, it's expected to have created all * the device links it needs to or make new device links as it needs -* them. So, it no longer needs to wait on any suppliers. +* them. So, fw_devlink no longer needs to create device links to any +* of the device's suppliers. +* +* Also, if a child firmware node of this bound device is not added as +* a device by now, assume it is never going to be added and make sure +* other devices don't defer probe indefinitely by waiting for such a +* child device. */ -if (dev->fwnode && dev->fwnode->dev == dev) +if (dev->fwnode && dev->fwnode->dev == dev) { +struct fwnode_handle *child;fwnode_links_purge_suppliers (dev->fwnode); +fwnode_for_each_available_child_node (dev->fwnode, child) +fw_devlink_purge_absent_suppliers (child); + }device_remove_file (dev, &dev_attr_waiting_for_supplier);device_links_write_lock ();
include/linux/fwnode.h +2 -0
@@ -19,8 +19,10 @@ struct device;* fwnode link flags * * LINKS_ADDED: The fwnode has already be parsed to add fwnode links. +* NOT_DEVICE: The fwnode will never be populated as a struct device. */ #define FWNODE_FLAG_LINKS_ADDED BIT(0) +#define FWNODE_FLAG_NOT_DEVICE BIT(1)struct fwnode_handle {struct fwnode_handle *secondary;
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 2/4 of: property: Don't add links to absent suppliers
In reply to Saravana KannanIf driver core marks a firmware node as not a device, don't add fwnode links where it's a supplier.
--- drivers/of/property.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/of/property.c +3 -1
@@ -1103,7 +1103,9 @@ static int of_link_to_phandle(struct device_node *con_np,* created for them. */ sup_dev =get_dev_from_fwnode (&sup_np->fwnode); -if (!sup_dev &&of_node_check_flag (sup_np,OF_POPULATED )) { +if (!sup_dev && + (of_node_check_flag (sup_np,OF_POPULATED ) || + sup_np->fwnode.flags &FWNODE_FLAG_NOT_DEVICE )) {pr_debug ("Not linking %pOFP to %pOFP - No struct device\n" , con_np, sup_np);of_node_put (sup_np);
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 3/4 driver core: Add fw_devlink.strict kernel param
In reply to Saravana KannanThis param allows forcing all dependencies to be treated as mandatory. This will be useful for boards in which all optional dependencies like IOMMUs and DMAs need to be treated as mandatory dependencies.
--- Documentation/admin-guide/kernel-parameters.txt | 5 +++++ drivers/base/core.c | 12 ++++++++++++ include/linux/fwnode.h | 1 + 3 files changed, 18 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -1433,6 +1433,11 @@ to enforce probe and suspend/resume ordering. rpm -- Like "on", but also use to order runtime PM. + fw_devlink.strict=<bool> + [KNL] Treat all inferred dependencies as mandatory + dependencies. This only applies for fw_devlink=on|rpm. + Format: <bool> + gamecon.map[2|3]= [HW,JOY] Multisystem joystick and NES/SNES/PSX pad support via parallel port (up to 5 devices per port)
drivers/base/core.c +12 -0
@@ -1521,6 +1521,13 @@ static int __init fw_devlink_setup(char *arg) }early_param ("fw_devlink" , fw_devlink_setup); +static bool fw_devlink_strict; +static int __init fw_devlink_strict_setup (char *arg) +{ +return strtobool (arg, &fw_devlink_strict); +} +early_param ("fw_devlink.strict" , fw_devlink_strict_setup); +u32 fw_devlink_get_flags (void ) {return fw_devlink_flags;
@@ -1531,6 +1538,11 @@ static bool fw_devlink_is_permissive(void)return fw_devlink_flags ==FW_DEVLINK_FLAGS_PERMISSIVE ; } +bool fw_devlink_is_strict (void ) +{ +return fw_devlink_strict && !fw_devlink_is_permissive (); +} +static void fw_devlink_parse_fwnode (struct fwnode_handle *fwnode) {if (fwnode->flags &FWNODE_FLAG_LINKS_ADDED )
include/linux/fwnode.h +1 -0
@@ -162,6 +162,7 @@ static inline void fwnode_init(struct fwnode_handle *fwnode, }extern u32 fw_devlink_get_flags (void ); +extern bool fw_devlink_is_strict (void );int fwnode_link_add (struct fwnode_handle *con,struct fwnode_handle *sup);void fwnode_links_purge (struct fwnode_handle *fwnode);
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v3 4/4 of: property: Add fw_devlink support for optional properties
In reply to Saravana KannanNot all DT bindings are mandatory bindings. Add support for optional DT bindings and mark iommus, iommu-map, dmas as optional DT bindings.
--- drivers/of/property.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/of/property.c +9 -3
@@ -1235,6 +1235,7 @@ static struct device_node *parse_##fname(struct device_node *np, \struct supplier_bindings {struct device_node *(*parse_prop)(struct device_node *np,const char *prop_name,int index); +bool optional; };DEFINE_SIMPLE_PROP (clocks,"clocks" ,"#clock-cells" )
@@ -1308,12 +1309,12 @@ static struct device_node *parse_interrupts(struct device_node *np,static const struct supplier_bindings of_supplier_bindings[] = { { .parse_prop = parse_clocks, }, { .parse_prop = parse_interconnects, }, - { .parse_prop = parse_iommus, }, - { .parse_prop = parse_iommu_maps, }, + { .parse_prop = parse_iommus, .optional = true, }, + { .parse_prop = parse_iommu_maps, .optional = true, }, { .parse_prop = parse_mboxes, }, { .parse_prop = parse_io_channels, }, { .parse_prop = parse_interrupt_parent, }, - { .parse_prop = parse_dmas, }, + { .parse_prop = parse_dmas, .optional = true, }, { .parse_prop = parse_power_domains, }, { .parse_prop = parse_hwlocks, }, { .parse_prop = parse_extcon, },
@@ -1368,6 +1369,11 @@ static int of_link_property(struct device_node *con_np, const char *prop_name)/* Do not stop at first failed link, link all available suppliers. */ while (!matched && s->parse_prop) { +if (s->optional && !fw_devlink_is_strict ()) { + s++; +continue ; + } +while ((phandle = s->parse_prop (con_np, prop_name, i))) { matched = true; i++;
Signature · 1 line
2.30.0.365.g02bc693789-goog