Skip to contentSkip to conversation

Documentation/minor coding style fix ups

PATCH In review Saravana Kannan 3 participants 7 messages Oct 11, 2019 – Oct 15, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Documentation/minor coding style fix ups

Addressing a few coding style comments and adding a bunch of documentation.

Saravana Kannan (3):
of: property: Minor code formatting/style clean ups
driver: core: Improve documentation for fwnode_operations.add_links()
docs: driver-model: Add documentation for sync_state

 .../driver-api/driver-model/driver.rst        | 43 +++++++++++++++++++
 drivers/of/property.c                         | 12 +++---
 include/linux/fwnode.h                        | 21 ++++++++-
 3 files changed, 68 insertions(+), 8 deletions(-)
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
#1 lore raw

PATCH 1/3 of: property: Minor code formatting/style clean ups

Better variable and function names. Remove "," after the sentinel in an array initialization list.

---
 drivers/of/property.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/of/property.c +6 -6
index 923d6f88a99c..6f6e1d9644cf 100644
@@ -1147,11 +1147,11 @@ struct supplier_bindings {
 					  const char *prop_name, int index);
 };
 
-static const struct supplier_bindings bindings[] = {
+static const struct supplier_bindings of_supplier_bindings[] = {
 	{ .parse_prop = parse_clocks, },
 	{ .parse_prop = parse_interconnects, },
 	{ .parse_prop = parse_regulators, },
-	{},
+	{}
 };
 
 /**
@@ -1177,7 +1177,7 @@ static int of_link_property(struct device *dev, struct device_node *con_np,
 			     const char *prop_name)
 {
 	struct device_node *phandle;
-	const struct supplier_bindings *s = bindings;
+	const struct supplier_bindings *s = of_supplier_bindings;
 	unsigned int i = 0;
 	bool matched = false;
 	int ret = 0;
@@ -1196,7 +1196,7 @@ static int of_link_property(struct device *dev, struct device_node *con_np,
 	return ret;
 }
 
-static int __of_link_to_suppliers(struct device *dev,
+static int of_link_to_suppliers(struct device *dev,
 				  struct device_node *con_np)
 {
 	struct device_node *child;
@@ -1208,7 +1208,7 @@ static int __of_link_to_suppliers(struct device *dev,
 			ret = -EAGAIN;
 
 	for_each_child_of_node(con_np, child)
-		if (__of_link_to_suppliers(dev, child))
+		if (of_link_to_suppliers(dev, child))
 			ret = -EAGAIN;
 
 	return ret;
@@ -1226,7 +1226,7 @@ static int of_fwnode_add_links(const struct fwnode_handle *fwnode,
 	if (unlikely(!is_of_node(fwnode)))
 		return 0;
 
-	return __of_link_to_suppliers(dev, to_of_node(fwnode));
+	return of_link_to_suppliers(dev, to_of_node(fwnode));
 }
 
 const struct fwnode_operations of_fwnode_ops = {
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH v1 1/3] of: property: Minor code formatting/style clean ups

Quoted 8 lines · Saravana Kannan

Better variable and function names. Remove "," after the sentinel in an array initialization list.

---
 drivers/of/property.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
#3 lore raw

PATCH 2/3 driver: core: Improve documentation for fwnode_operations.add_links()

In reply to Saravana Kannan

The add_links() ops shouldn't return on the first failed device link add. It needs to continue trying to add device links to other suppliers that are available. The documentation didn't explain WHY this behavior is necessary. So, update the documentation with an example that explains why this is necessary.

---
 include/linux/fwnode.h | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
include/linux/fwnode.h +19 -2
index 6ae05b9ce359..97223e2410bd 100644
@@ -71,8 +71,25 @@ struct fwnode_reference_args {
  *		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 present in the system.  This is necessary for the
+ *		driver/bus sync_state() callbacks to work correctly.
+ *
+ *		For example, say Device-C depends on suppliers Device-S1 and
+ *		Device-S2 and the dependency is listed in that order in the
+ *		firmware.  Say, S1 gets populated from the firmware after
+ *		late_initcall_sync().  Say S2 is populated and probed way
+ *		before that in device_initcall(). When C is populated, if this
+ *		add_links() function doesn't continue past a "failed linking to
+ *		S1" and continue linking C to S2, then S2 will get a
+ *		sync_state() callback before C is probed. This is because from
+ *		the perspective of S2, C was never a consumer when its
+ *		sync_state() evaluation is done. To avoid this, the add_links()
+ *		function has to go through all available suppliers of the
+ *		device (that corresponds to this fwnode) and link to them
+ *		before returning.
+ *
+ *		If some suppliers are not yet available (indicated by an error
+ *		return value), this function will be called again when other
  *		devices are added to allow creating device links to any newly
  *		available suppliers.
  *
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
#4 lore raw

PATCH 3/3 docs: driver-model: Add documentation for sync_state

In reply to Saravana Kannan

The sync_state() driver callback was added recently, but the documentation was missing. Adding it now.

---
 .../driver-api/driver-model/driver.rst        | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
Documentation/driver-api/driver-model/driver.rst +43 -0
index 11d281506a04..baa6a85c8287 100644
@@ -169,6 +169,49 @@ A driver's probe() may return a negative errno value to indicate that
 the driver did not bind to this device, in which case it should have
 released all resources it allocated::
 
+	void (*sync_state)(struct device *dev);
+
+sync_state is called only once for a device. It's called when all the consumer
+devices of the device have successfully probed. The list of consumers of the
+device is obtained by looking at the device links connecting that device to its
+consumer devices.
+
+The first attempt to call sync_state() is made during late_initcall_sync() to
+give firmware and drivers time to link devices to each other. During the first
+attempt at calling sync_state(), if all the consumers of the device at that
+point in time have already probed successfully, sync_state() is called right
+away. If there are no consumers of the device during the first attempt, that
+too is considered as "all consumers of the device have probed" and sync_state()
+is called right away.
+
+If during the first attempt at calling sync_state() for a device, there are
+still consumers that haven't probed successfully, the sync_state() call is
+postponed and reattempted in the future only when one or more consumers of the
+device probe successfully. If during the reattempt, the driver core finds that
+there are one or more consumers of the device that haven't probed yet, then
+sync_state() call is postponed again.
+
+A typical use case for sync_state() is to have the kernel cleanly take over
+management of devices from the bootloader. For example, if a device is left on
+and at a particular hardware configuration by the bootloader, the device's
+driver might need to keep the device in the boot configuration until all the
+consumers of the device have probed. Once all the consumers of the device have
+probed, the device's driver can synchronize the hardware state of the device to
+match the aggregated software state requested by all the consumers. Hence the
+name sync_state().
+
+While obvious examples of resources that can benefit from sync_state() include
+resources such as regulator, sync_state() can also be useful for complex
+resources like IOMMUs. For example, IOMMUs with multiple consumers (devices
+whose addresses are remapped by the IOMMU) might need to keep their mappings
+fixed at (or additive to) the boot configuration until all its consumers have
+probed.
+
+While the typical use case for sync_state() is to have the kernel cleanly take
+over management of devices from the bootloader, the usage of sync_state() is
+not restricted to that. Use it whenever it makes sense to take an action after
+all the consumers of a device have probed.
+
 	int 	(*remove)	(struct device *dev);
 
 remove is called to unbind a driver from a device. This may be
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
#5 lore raw

Re: [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state

Quoting Saravana Kannan (2019-10-11 12:15:21)

Quoted 13 lines

The sync_state() driver callback was added recently, but the documentation was missing. Adding it now.

---
 .../driver-api/driver-model/driver.rst        | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
Documentation/driver-api/driver-model/driver.rst +0 -0
index 11d281506a04..baa6a85c8287 100644

Documentation/driver-api/driver-model/driver.rst A driver's probe() may return a negative errno value to indicate that · line 172

Quoted 4 lines
Documentation/driver-api/driver-model/driver.rst +1 -0
@@ -169,6 +169,49 @@ A driver's probe() may return a negative errno value to indicate that
 the driver did not bind to this device, in which case it should have
 released all resources it allocated::
 
+       void (*sync_state)(struct device *dev);

This is only in -next as far as I can tell. Will this be combined with a resend of the patch series that introduces this hook?

#6 lore raw

Re: [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state

Quoted 18 lines · Stephen Boyd

Quoting Saravana Kannan (2019-10-11 12:15:21)

Quoted 16 lines

The sync_state() driver callback was added recently, but the documentation was missing. Adding it now.

---
 .../driver-api/driver-model/driver.rst        | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
Documentation/driver-api/driver-model/driver.rst +0 -0
index 11d281506a04..baa6a85c8287 100644
@@ -169,6 +169,49 @@ A driver's probe() may return a negative errno value to indicate that
 the driver did not bind to this device, in which case it should have
 released all resources it allocated::
 
Quoted 4 lines

Documentation/driver-api/driver-model/driver.rst A driver's probe() may return a negative errno value to indicate that · line 172

Quoted 1 line
Documentation/driver-api/driver-model/driver.rst +1 -0
+       void (*sync_state)(struct device *dev);

This is only in -next as far as I can tell. Will this be combined with a resend of the patch series that introduces this hook?

Based on what Greg said in the other email, I think he's going to pick this up for driver-core-next.

-Saravana