linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/3] Documentation/minor coding style fix ups
@ 2019-10-11 19:15 Saravana Kannan
  2019-10-11 19:15 ` [PATCH v1 1/3] of: property: Minor code formatting/style clean ups Saravana Kannan
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Saravana Kannan @ 2019-10-11 19:15 UTC (permalink / raw)
  To: Jonathan Corbet, Rob Herring, Frank Rowand, Rafael J. Wysocki,
	Len Brown, Greg Kroah-Hartman
  Cc: Saravana Kannan, Stephen Boyd, kernel-team, linux-doc,
	linux-kernel, devicetree, linux-acpi

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(-)

-- 
2.23.0.700.g56cf767bdb-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v1 1/3] of: property: Minor code formatting/style clean ups
  2019-10-11 19:15 [PATCH v1 0/3] Documentation/minor coding style fix ups Saravana Kannan
@ 2019-10-11 19:15 ` Saravana Kannan
  2019-10-15 12:04   ` Rob Herring
  2019-10-11 19:15 ` [PATCH v1 2/3] driver: core: Improve documentation for fwnode_operations.add_links() Saravana Kannan
  2019-10-11 19:15 ` [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state Saravana Kannan
  2 siblings, 1 reply; 7+ messages in thread
From: Saravana Kannan @ 2019-10-11 19:15 UTC (permalink / raw)
  To: Jonathan Corbet, Rob Herring, Frank Rowand, Rafael J. Wysocki,
	Len Brown, Greg Kroah-Hartman
  Cc: Saravana Kannan, Stephen Boyd, kernel-team, linux-doc,
	linux-kernel, devicetree, linux-acpi

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

Signed-off-by: Saravana Kannan <saravanak@google.com>
---
 drivers/of/property.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 923d6f88a99c..6f6e1d9644cf 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -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 = {
-- 
2.23.0.700.g56cf767bdb-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 2/3] driver: core: Improve documentation for fwnode_operations.add_links()
  2019-10-11 19:15 [PATCH v1 0/3] Documentation/minor coding style fix ups Saravana Kannan
  2019-10-11 19:15 ` [PATCH v1 1/3] of: property: Minor code formatting/style clean ups Saravana Kannan
@ 2019-10-11 19:15 ` Saravana Kannan
  2019-10-11 19:15 ` [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state Saravana Kannan
  2 siblings, 0 replies; 7+ messages in thread
From: Saravana Kannan @ 2019-10-11 19:15 UTC (permalink / raw)
  To: Jonathan Corbet, Rob Herring, Frank Rowand, Rafael J. Wysocki,
	Len Brown, Greg Kroah-Hartman
  Cc: Saravana Kannan, Stephen Boyd, kernel-team, linux-doc,
	linux-kernel, devicetree, linux-acpi

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.

Signed-off-by: Saravana Kannan <saravanak@google.com>
---
 include/linux/fwnode.h | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index 6ae05b9ce359..97223e2410bd 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -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.
  *
-- 
2.23.0.700.g56cf767bdb-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state
  2019-10-11 19:15 [PATCH v1 0/3] Documentation/minor coding style fix ups Saravana Kannan
  2019-10-11 19:15 ` [PATCH v1 1/3] of: property: Minor code formatting/style clean ups Saravana Kannan
  2019-10-11 19:15 ` [PATCH v1 2/3] driver: core: Improve documentation for fwnode_operations.add_links() Saravana Kannan
@ 2019-10-11 19:15 ` Saravana Kannan
  2019-10-14 23:28   ` Stephen Boyd
  2 siblings, 1 reply; 7+ messages in thread
From: Saravana Kannan @ 2019-10-11 19:15 UTC (permalink / raw)
  To: Jonathan Corbet, Rob Herring, Frank Rowand, Rafael J. Wysocki,
	Len Brown, Greg Kroah-Hartman
  Cc: Saravana Kannan, Stephen Boyd, kernel-team, linux-doc,
	linux-kernel, devicetree, linux-acpi

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

Signed-off-by: Saravana Kannan <saravanak@google.com>
---
 .../driver-api/driver-model/driver.rst        | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/Documentation/driver-api/driver-model/driver.rst b/Documentation/driver-api/driver-model/driver.rst
index 11d281506a04..baa6a85c8287 100644
--- a/Documentation/driver-api/driver-model/driver.rst
+++ b/Documentation/driver-api/driver-model/driver.rst
@@ -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
-- 
2.23.0.700.g56cf767bdb-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state
  2019-10-11 19:15 ` [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state Saravana Kannan
@ 2019-10-14 23:28   ` Stephen Boyd
  2019-10-14 23:35     ` Saravana Kannan
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Boyd @ 2019-10-14 23:28 UTC (permalink / raw)
  To: Rafael J. Wysocki, Frank Rowand, Greg Kroah-Hartman,
	Jonathan Corbet, Len Brown, Rob Herring, Saravana Kannan
  Cc: Saravana Kannan, kernel-team, linux-doc, linux-kernel,
	devicetree, linux-acpi

Quoting Saravana Kannan (2019-10-11 12:15:21)
> The sync_state() driver callback was added recently, but the
> documentation was missing.  Adding it now.
> 
> Signed-off-by: Saravana Kannan <saravanak@google.com>
> ---
>  .../driver-api/driver-model/driver.rst        | 43 +++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/Documentation/driver-api/driver-model/driver.rst b/Documentation/driver-api/driver-model/driver.rst
> index 11d281506a04..baa6a85c8287 100644
> --- a/Documentation/driver-api/driver-model/driver.rst
> +++ b/Documentation/driver-api/driver-model/driver.rst
> @@ -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?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state
  2019-10-14 23:28   ` Stephen Boyd
@ 2019-10-14 23:35     ` Saravana Kannan
  0 siblings, 0 replies; 7+ messages in thread
From: Saravana Kannan @ 2019-10-14 23:35 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Rafael J. Wysocki, Frank Rowand, Greg Kroah-Hartman,
	Jonathan Corbet, Len Brown, Rob Herring, Android Kernel Team,
	Linux Doc Mailing List, LKML,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-acpi

On Mon, Oct 14, 2019 at 4:28 PM Stephen Boyd <sboyd@kernel.org> wrote:
>
> Quoting Saravana Kannan (2019-10-11 12:15:21)
> > The sync_state() driver callback was added recently, but the
> > documentation was missing.  Adding it now.
> >
> > Signed-off-by: Saravana Kannan <saravanak@google.com>
> > ---
> >  .../driver-api/driver-model/driver.rst        | 43 +++++++++++++++++++
> >  1 file changed, 43 insertions(+)
> >
> > diff --git a/Documentation/driver-api/driver-model/driver.rst b/Documentation/driver-api/driver-model/driver.rst
> > index 11d281506a04..baa6a85c8287 100644
> > --- a/Documentation/driver-api/driver-model/driver.rst
> > +++ b/Documentation/driver-api/driver-model/driver.rst
> > @@ -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?

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

-Saravana

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/3] of: property: Minor code formatting/style clean ups
  2019-10-11 19:15 ` [PATCH v1 1/3] of: property: Minor code formatting/style clean ups Saravana Kannan
@ 2019-10-15 12:04   ` Rob Herring
  0 siblings, 0 replies; 7+ messages in thread
From: Rob Herring @ 2019-10-15 12:04 UTC (permalink / raw)
  To: Saravana Kannan
  Cc: Jonathan Corbet, Frank Rowand, Rafael J. Wysocki, Len Brown,
	Greg Kroah-Hartman, Stephen Boyd, Android Kernel Team,
	Linux Doc Mailing List, linux-kernel, devicetree, linux-acpi

On Fri, Oct 11, 2019 at 2:15 PM Saravana Kannan <saravanak@google.com> wrote:
>
> Better variable and function names. Remove "," after the sentinel in an
> array initialization list.
>
> Signed-off-by: Saravana Kannan <saravanak@google.com>
> ---
>  drivers/of/property.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-10-15 12:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 19:15 [PATCH v1 0/3] Documentation/minor coding style fix ups Saravana Kannan
2019-10-11 19:15 ` [PATCH v1 1/3] of: property: Minor code formatting/style clean ups Saravana Kannan
2019-10-15 12:04   ` Rob Herring
2019-10-11 19:15 ` [PATCH v1 2/3] driver: core: Improve documentation for fwnode_operations.add_links() Saravana Kannan
2019-10-11 19:15 ` [PATCH v1 3/3] docs: driver-model: Add documentation for sync_state Saravana Kannan
2019-10-14 23:28   ` Stephen Boyd
2019-10-14 23:35     ` Saravana Kannan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).