Skip to contentSkip to conversation

Move firmware specific code to firmware specific locations

PATCH Superseded Sakari Ailus 2 participants 8 messages May 4, 2017 – May 9, 2017 1 message not in the archive

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Sakari Ailus

author reviewer
#0 lore raw

v5 cover Move firmware specific code to firmware specific locations

Hi folks,

This set moves firmware specific implementations of the device / fwnode property API to locations that are specific to firmware implementation, still leaving property set (which isn't really firmware) implementation in drivers/base/property.c.

since v3 (the cover page for v4 was unfortunately lost):

- Rebased on linux-next.

- Depend on "of: Move OF property and graph API from base.c to property.c" posted to devicetree list yesterday. My thinking is this would be better go through Rob's tree. Thinking about it more, the first patch in this set should, too.

- In the old set, patch 1 ("device property: Read strings using string array reading functions") has since been merged to linux-pm tree. Patch 2 ("device property: Implement fwnode_get_next_parent() using fwnode interface") was squashed to "device property: Add fwnode_get_next_parent()" which is in linux-pm as well.

- Refactor the implementation of fwnode graph operations in order to implement basic operations in a firmware specific way separately from the common part. In particular, graph_get_remote_port() and graph_get_remote_port_parent() have been replaced by graph_get_port_parent().

- Added patches 5 and 6 to implement fwnode variant of fwnode_graph_get_remote_node() which is seen as a better API for many (or most) drivers than the other graph API primitives.

since v2:

- Move patches changing the implementation of reading strings and implementing fwnode_get_next_parent() using the fwnode interface alone in front of the set. I kept them separate as they do change the implementation of these operations.

- Merge patches adding the fwnode_operations and moving the implementations of the non-graph portions of the fwnode property API to firmware specific locations.

- Merge moving graph operations to the same struct into another patch. The graph operations in the ops struct are also added in this patch now.

since v1:

- Move the three bugfixes in front of the set into a separate patchset. There are no dependencies to those from the rest of the patches.

- Rebase on current ACPI graph support patches (themselves on PM tree 4.11-rc1 merge).

<URL:http://www.spinics.net/lists/linux-acpi/msg72895.html>

Sakari Ailus (5):
of: Add of_graph_get_port_parent() to obtain a port's parent node device property: Move FW type specific functionality to FW specific
files
device property: Move fwnode graph ops to firmware specific locations device property: Introduce fwnode_device_is_available() device property: Add FW type agnostic fwnode_graph_get_remote_node

 drivers/acpi/property.c  | 126 ++++++++++++++++++
 drivers/acpi/scan.c      |   1 +
 drivers/base/property.c  | 337 +++++++++++++++++++----------------------------
 drivers/of/property.c    | 197 +++++++++++++++++++++++++--
 include/linux/acpi.h     |   4 +
 include/linux/fwnode.h   |  66 ++++++++++
 include/linux/of.h       |   2 +
 include/linux/property.h |   3 +
 8 files changed, 524 insertions(+), 212 deletions(-)
Signature · 1 line
2.7.4
author reviewer
#1 lore raw

PATCH v5 1/5 of: Add of_graph_get_port_parent() to obtain a port's parent node

Split off obtaining a port's parent node. This will be soon needed for implementing the fwnode ops.

Depends-on: ("of: Move OF property and graph API from base.c to property.c")

---
 drivers/of/property.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)
drivers/of/property.c +27 -8
index e5d3e1f..cf704f4 100644
@@ -681,6 +681,30 @@ struct device_node *of_graph_get_endpoint_by_regs(
 EXPORT_SYMBOL(of_graph_get_endpoint_by_regs);
 
 /**
+ * of_graph_get_port_parent() - get port's parent node
+ * @node: pointer to a port node
+ *
+ * Return: Device node which is the parent of the given port node
+ *	   @node. Use of_node_put() on it when done.
+ */
+static struct device_node *
+of_graph_get_port_parent(struct device_node *node)
+{
+	struct device_node *np;
+
+	/* Get the parent of the port */
+	np = of_get_next_parent(node);
+	if (!np)
+		return NULL;
+
+	/* Is there "ports" node? If not, return it. */
+	if (of_node_cmp(np->name, "ports"))
+		return np;
+
+	return of_get_next_parent(np);
+}
+
+/**
  * of_graph_get_remote_port_parent() - get remote port's parent node
  * @node: pointer to a local endpoint device_node
  *
@@ -691,18 +715,13 @@ struct device_node *of_graph_get_remote_port_parent(
 			       const struct device_node *node)
 {
 	struct device_node *np;
-	unsigned int depth;
 
 	/* Get remote endpoint node. */
 	np = of_parse_phandle(node, "remote-endpoint", 0);
+	if (!np)
+		return NULL;
 
-	/* Walk 3 levels up only if there is 'ports' node. */
-	for (depth = 3; depth && np; depth--) {
-		np = of_get_next_parent(np);
-		if (depth == 2 && of_node_cmp(np->name, "ports"))
-			break;
-	}
-	return np;
+	return of_graph_get_port_parent(of_get_next_parent(np));
 }
 EXPORT_SYMBOL(of_graph_get_remote_port_parent);
 
Signature · 1 line
2.7.4
author reviewer
#2 lore raw

PATCH v5 2/5 device property: Move FW type specific functionality to FW specific files

In reply to Sakari Ailus

The device and fwnode property API supports Devicetree, ACPI and pset properties. The implementation of this functionality for each firmware type was embedded in the fwnode property core. Move it out to firmware type specific locations, making it easier to maintain.

---
 drivers/acpi/property.c |  72 +++++++++++++++++
 drivers/acpi/scan.c     |   1 +
 drivers/base/property.c | 206 +++++++++++++++++++-----------------------------
 drivers/of/property.c   |  99 +++++++++++++++++++++++
 include/linux/acpi.h    |   4 +
 include/linux/fwnode.h  |  53 +++++++++++++
 include/linux/of.h      |   2 +
 7 files changed, 312 insertions(+), 125 deletions(-)
drivers/acpi/property.c +72 -0
index 9364398..fb3b96f 100644
@@ -57,6 +57,7 @@ static bool acpi_nondev_subnode_extract(const union acpi_object *desc,
 
 	dn->name = link->package.elements[0].string.pointer;
 	dn->fwnode.type = FWNODE_ACPI_DATA;
+	dn->fwnode.ops = &acpi_fwnode_ops;
 	dn->parent = parent;
 	INIT_LIST_HEAD(&dn->data.subnodes);
 
@@ -1119,3 +1120,74 @@ int acpi_graph_get_remote_endpoint(struct fwnode_handle *fwnode,
 
 	return 0;
 }
+
+static bool acpi_fwnode_property_present(struct fwnode_handle *fwnode,
+					 const char *propname)
+{
+	return !acpi_node_prop_get(fwnode, propname, NULL);
+}
+
+static int acpi_fwnode_property_read_int_array(
+	struct fwnode_handle *fwnode, const char *propname,
+	unsigned int elem_size, void *val, size_t nval)
+{
+	enum dev_prop_type type;
+
+	switch (elem_size) {
+	case sizeof(u8):
+		type = DEV_PROP_U8;
+		break;
+	case sizeof(u16):
+		type = DEV_PROP_U16;
+		break;
+	case sizeof(u32):
+		type = DEV_PROP_U32;
+		break;
+	case sizeof(u64):
+		type = DEV_PROP_U64;
+		break;
+	default:
+		return -ENXIO;
+	}
+
+	return acpi_node_prop_read(fwnode, propname, type, val, nval);
+}
+
+static int acpi_fwnode_property_read_string_array(
+	struct fwnode_handle *fwnode, const char *propname, const char **val,
+	size_t nval)
+{
+	return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
+				   val, nval);
+}
+
+static struct fwnode_handle *acpi_fwnode_get_parent(
+	struct fwnode_handle *fwnode)
+{
+	return acpi_node_get_parent(fwnode);
+}
+
+static struct fwnode_handle *acpi_fwnode_get_named_child_node(
+	struct fwnode_handle *fwnode, const char *childname)
+{
+	struct fwnode_handle *child;
+
+	/*
+	 * Find first matching named child node of this fwnode.
+	 * For ACPI this will be a data only sub-node.
+	 */
+	fwnode_for_each_child_node(fwnode, child)
+		if (acpi_data_node_match(child, childname))
+			return child;
+
+	return NULL;
+}
+
+const struct fwnode_operations acpi_fwnode_ops = {
+	.property_present = acpi_fwnode_property_present,
+	.property_read_int_array = acpi_fwnode_property_read_int_array,
+	.property_read_string_array = acpi_fwnode_property_read_string_array,
+	.get_parent = acpi_fwnode_get_parent,
+	.get_next_child_node = acpi_get_next_subnode,
+	.get_named_child_node = acpi_fwnode_get_named_child_node,
+};
drivers/acpi/scan.c +1 -0
index e39ec7b..3db9192 100644
@@ -1436,6 +1436,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
 	device->handle = handle;
 	device->parent = acpi_bus_get_parent(handle);
 	device->fwnode.type = FWNODE_ACPI;
+	device->fwnode.ops = &acpi_fwnode_ops;
 	acpi_set_device_status(device, sta);
 	acpi_device_get_busid(device);
 	acpi_set_pnp_ids(handle, &device->pnp, type);
drivers/base/property.c +81 -125

303 lines not on this page · raw message

drivers/of/property.c +99 -0

102 lines not on this page · raw message

include/linux/acpi.h +4 -0
index 137e4a3..b8f23c5 100644
@@ -56,6 +56,9 @@ static inline acpi_handle acpi_device_handle(struct acpi_device *adev)
 	acpi_fwnode_handle(adev) : NULL)
 #define ACPI_HANDLE(dev)		acpi_device_handle(ACPI_COMPANION(dev))
 
+
+extern const struct fwnode_operations acpi_fwnode_ops;
+
 static inline struct fwnode_handle *acpi_alloc_fwnode_static(void)
 {
 	struct fwnode_handle *fwnode;
@@ -65,6 +68,7 @@ static inline struct fwnode_handle *acpi_alloc_fwnode_static(void)
 		return NULL;
 
 	fwnode->type = FWNODE_ACPI_STATIC;
+	fwnode->ops = &acpi_fwnode_ops;
 
 	return fwnode;
 }
include/linux/fwnode.h +53 -0

72 lines not on this page · raw message

include/linux/of.h +2 -0
index 50fcdb5..64f4cd6 100644
@@ -100,10 +100,12 @@ struct of_reconfig_data {
 
 /* initialize a node */
 extern struct kobj_type of_node_ktype;
+extern const struct fwnode_operations of_fwnode_ops;
 static inline void of_node_init(struct device_node *node)
 {
 	kobject_init(&node->kobj, &of_node_ktype);
 	node->fwnode.type = FWNODE_OF;
+	node->fwnode.ops = &of_fwnode_ops;
 }
 
 /* true when node is initialized */
Signature · 1 line
2.7.4
author reviewer
#3 lore raw

PATCH v5 3/5 device property: Move fwnode graph ops to firmware specific locations

In reply to Sakari Ailus

Move firmware specific implementations of the fwnode graph operations to firmware specific locations.

---
 drivers/acpi/property.c | 45 +++++++++++++++++++++++
 drivers/base/property.c | 96 ++++++-------------------------------------------
 drivers/of/property.c   | 57 +++++++++++++++++++++++++++++
 include/linux/fwnode.h  | 12 +++++++
 4 files changed, 125 insertions(+), 85 deletions(-)
drivers/acpi/property.c +45 -0
index fb3b96f..d26f24d 100644
@@ -1183,6 +1183,47 @@ static struct fwnode_handle *acpi_fwnode_get_named_child_node(
 	return NULL;
 }
 
+static struct fwnode_handle *acpi_fwnode_graph_get_next_endpoint(
+	struct fwnode_handle *fwnode, struct fwnode_handle *prev)
+{
+	struct fwnode_handle *endpoint;
+
+	endpoint = acpi_graph_get_next_endpoint(fwnode, prev);
+	if (IS_ERR(endpoint))
+		return NULL;
+
+	return endpoint;
+}
+
+static struct fwnode_handle *acpi_fwnode_graph_get_remote_endpoint(
+	struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *endpoint = NULL;
+
+	acpi_graph_get_remote_endpoint(fwnode, NULL, NULL, &endpoint);
+
+	return endpoint;
+}
+
+static struct fwnode_handle *acpi_fwnode_graph_get_port_parent(
+	struct fwnode_handle *fwnode)
+{
+	return acpi_node_get_parent(fwnode);
+}
+
+static int acpi_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
+					    struct fwnode_endpoint *endpoint)
+{
+	struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode);
+
+	endpoint->local_fwnode = fwnode;
+
+	fwnode_property_read_u32(port_fwnode, "port", &endpoint->port);
+	fwnode_property_read_u32(fwnode, "endpoint", &endpoint->id);
+
+	return 0;
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
@@ -1190,4 +1231,8 @@ const struct fwnode_operations acpi_fwnode_ops = {
 	.get_parent = acpi_fwnode_get_parent,
 	.get_next_child_node = acpi_get_next_subnode,
 	.get_named_child_node = acpi_fwnode_get_named_child_node,
+	.graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint,
+	.graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint,
+	.graph_get_port_parent = acpi_fwnode_graph_get_port_parent,
+	.graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint,
 };
drivers/base/property.c +11 -85

129 lines not on this page · raw message

drivers/of/property.c +57 -0

67 lines not on this page · raw message

include/linux/fwnode.h +12 -0
index e05aaef..35f6626 100644
@@ -57,6 +57,10 @@ struct fwnode_endpoint {
  * @get_parent: Return the parent of an fwnode.
  * @get_next_child_node: Return the next child node in an iteration.
  * @get_named_child_node: Return a child node with a given name.
+ * @graph_get_next_endpoint: Return an endpoint node in an iteration.
+ * @graph_get_remote_endpoint: Return the remote endpoint node of a local
+ *			       endpoint node.
+ * @graph_get_port_parent: Return the parent node of a port node.
  */
 struct fwnode_operations {
 	void (*get)(struct fwnode_handle *fwnode);
@@ -75,6 +79,14 @@ struct fwnode_operations {
 		struct fwnode_handle *fwnode, struct fwnode_handle *child);
 	struct fwnode_handle *(*get_named_child_node)(
 		struct fwnode_handle *fwnode, const char *name);
+	struct fwnode_handle *(*graph_get_next_endpoint)(
+		struct fwnode_handle *fwnode, struct fwnode_handle *prev);
+	struct fwnode_handle *(*graph_get_remote_endpoint)(
+		struct fwnode_handle *fwnode);
+	struct fwnode_handle *(*graph_get_port_parent)(
+		struct fwnode_handle *fwnode);
+	int (*graph_parse_endpoint)(struct fwnode_handle *fwnode,
+				    struct fwnode_endpoint *endpoint);
 };
 
 #define fwnode_has_op(fwnode, op)				\
Signature · 1 line
2.7.4
author reviewer
#7 lore raw

PATCH v5 4/5 device property: Introduce fwnode_device_is_available()

In reply to Sakari Ailus

Add fwnode_device_is_available() to tell whether the device corresponding to a certain fwnode_handle is available for use.

---
 drivers/acpi/property.c  |  9 +++++++++
 drivers/base/property.c  | 10 ++++++++++
 drivers/of/property.c    |  6 ++++++
 include/linux/fwnode.h   |  1 +
 include/linux/property.h |  1 +
 5 files changed, 27 insertions(+)
drivers/acpi/property.c +9 -0
index d26f24d..8df71bb 100644
@@ -1121,6 +1121,14 @@ int acpi_graph_get_remote_endpoint(struct fwnode_handle *fwnode,
 	return 0;
 }
 
+static bool acpi_fwnode_device_is_available(struct fwnode_handle *fwnode)
+{
+	if (!is_acpi_device_node(fwnode))
+		return false;
+
+	return acpi_device_is_present(to_acpi_device_node(fwnode));
+}
+
 static bool acpi_fwnode_property_present(struct fwnode_handle *fwnode,
 					 const char *propname)
 {
@@ -1225,6 +1233,7 @@ static int acpi_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
 }
 
 const struct fwnode_operations acpi_fwnode_ops = {
+	.device_is_available = acpi_fwnode_device_is_available,
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
 	.property_read_string_array = acpi_fwnode_property_read_string_array,
drivers/base/property.c +10 -0
index 6eccc4e..ad0de38 100644
@@ -1020,6 +1020,16 @@ void fwnode_handle_put(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_handle_put);
 
 /**
+ * fwnode_device_is_available - check if a device is available for use
+ * @fwnode: Pointer to the fwnode of the device.
+ */
+bool fwnode_device_is_available(struct fwnode_handle *fwnode)
+{
+	return fwnode_call_int_op(fwnode, device_is_available);
+}
+EXPORT_SYMBOL_GPL(fwnode_device_is_available);
+
+/**
  * device_get_child_node_count - return the number of child nodes for device
  * @dev: Device to cound the child nodes for
  */
drivers/of/property.c +6 -0
index bb6ac73..7042f62 100644
@@ -791,6 +791,11 @@ static void of_fwnode_put(struct fwnode_handle *fwnode)
 	of_node_put(to_of_node(fwnode));
 }
 
+static bool of_fwnode_device_is_available(struct fwnode_handle *fwnode)
+{
+	return of_device_is_available(to_of_node(fwnode));
+}
+
 static bool of_fwnode_property_present(struct fwnode_handle *fwnode,
 				       const char *propname)
 {
@@ -925,6 +930,7 @@ static int of_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
+	.device_is_available = of_fwnode_device_is_available,
 	.property_present = of_fwnode_property_present,
 	.property_read_int_array = of_fwnode_property_read_int_array,
 	.property_read_string_array = of_fwnode_property_read_string_array,
include/linux/fwnode.h +1 -0
index 35f6626..4e60b2b 100644
@@ -65,6 +65,7 @@ struct fwnode_endpoint {
 struct fwnode_operations {
 	void (*get)(struct fwnode_handle *fwnode);
 	void (*put)(struct fwnode_handle *fwnode);
+	bool (*device_is_available)(struct fwnode_handle *fwnode);
 	bool (*property_present)(struct fwnode_handle *fwnode,
 				 const char *propname);
 	int (*property_read_int_array)(struct fwnode_handle *fwnode,
include/linux/property.h +1 -0
index 2f48261..7be014a 100644
@@ -51,6 +51,7 @@ int device_property_read_string(struct device *dev, const char *propname,
 int device_property_match_string(struct device *dev,
 				 const char *propname, const char *string);
 
+bool fwnode_device_is_available(struct fwnode_handle *fwnode);
 bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname);
 int fwnode_property_read_u8_array(struct fwnode_handle *fwnode,
 				  const char *propname, u8 *val,
Signature · 1 line
2.7.4
author reviewer
#8 lore raw

PATCH v5 5/5 device property: Add FW type agnostic fwnode_graph_get_remote_node

In reply to Sakari Ailus

Add fwnode_graph_get_remote_node() function which is equivalent to of_graph_get_remote_node() on OF.

---
 drivers/base/property.c  | 37 +++++++++++++++++++++++++++++++++++++
 include/linux/property.h |  2 ++
 2 files changed, 39 insertions(+)
drivers/base/property.c +37 -0
index ad0de38..5914156 100644
@@ -1215,6 +1215,43 @@ fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode)
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
 
 /**
+ * fwnode_graph_get_remote_node - get remote parent node for given port/endpoint
+ * @fwnode: pointer to parent fwnode_handle containing graph port/endpoint
+ * @port_id: identifier of the parent port node
+ * @endpoint_id: identifier of the endpoint node
+ *
+ * Return: Remote fwnode handle associated with remote endpoint node linked
+ *	   to @node. Use fwnode_node_put() on it when done.
+ */
+struct fwnode_handle *fwnode_graph_get_remote_node(
+	struct fwnode_handle *fwnode, u32 port_id, u32 endpoint_id)
+{
+	struct fwnode_handle *endpoint = NULL;
+
+	while ((endpoint = fwnode_graph_get_next_endpoint(fwnode, endpoint))) {
+		struct fwnode_endpoint fwnode_ep;
+		struct fwnode_handle *remote;
+		int ret;
+
+		ret = fwnode_graph_parse_endpoint(endpoint, &fwnode_ep);
+		if (ret < 0)
+			continue;
+
+		if (fwnode_ep.port != port_id || fwnode_ep.id != endpoint_id)
+			continue;
+
+		remote = fwnode_graph_get_remote_port_parent(endpoint);
+		if (!remote)
+			return NULL;
+
+		return fwnode_device_is_available(remote) ? remote : NULL;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_node);
+
+/**
  * fwnode_graph_parse_endpoint - parse common endpoint node properties
  * @fwnode: pointer to endpoint fwnode_handle
  * @endpoint: pointer to the fwnode endpoint data structure
include/linux/property.h +2 -0
index 7be014a..b9f4838 100644
@@ -281,6 +281,8 @@ struct fwnode_handle *fwnode_graph_get_remote_port(
 	struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_graph_get_remote_endpoint(
 	struct fwnode_handle *fwnode);
+struct fwnode_handle *fwnode_graph_get_remote_node(
+	struct fwnode_handle *fwnode, u32 port, u32 endpoint);
 
 int fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
 				struct fwnode_endpoint *endpoint);
Signature · 1 line
2.7.4
#5 lore raw

Re: [PATCH v5 3/5] device property: Move fwnode graph ops to firmware specific locations

In reply to a message not in the archive
Quoted 118 lines · Sakari Ailus

Move firmware specific implementations of the fwnode graph operations to firmware specific locations.

---
 drivers/acpi/property.c | 45 +++++++++++++++++++++++
 drivers/base/property.c | 96 ++++++-------------------------------------------
 drivers/of/property.c   | 57 +++++++++++++++++++++++++++++
 include/linux/fwnode.h  | 12 +++++++
 4 files changed, 125 insertions(+), 85 deletions(-)
drivers/acpi/property.c +45 -0
index fb3b96f..d26f24d 100644
@@ -1183,6 +1183,47 @@ static struct fwnode_handle *acpi_fwnode_get_named_child_node(
        return NULL;
 }
 
+static struct fwnode_handle *acpi_fwnode_graph_get_next_endpoint(
+       struct fwnode_handle *fwnode, struct fwnode_handle *prev)
+{
+       struct fwnode_handle *endpoint;
+
+       endpoint = acpi_graph_get_next_endpoint(fwnode, prev);
+       if (IS_ERR(endpoint))
+               return NULL;
+
+       return endpoint;
+}
+
+static struct fwnode_handle *acpi_fwnode_graph_get_remote_endpoint(
+       struct fwnode_handle *fwnode)
+{
+       struct fwnode_handle *endpoint = NULL;
+
+       acpi_graph_get_remote_endpoint(fwnode, NULL, NULL, &endpoint);
+
+       return endpoint;
+}
+
+static struct fwnode_handle *acpi_fwnode_graph_get_port_parent(
+       struct fwnode_handle *fwnode)
+{
+       return acpi_node_get_parent(fwnode);
+}
+
+static int acpi_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
+                                           struct fwnode_endpoint *endpoint)
+{
+       struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode);
+
+       endpoint->local_fwnode = fwnode;
+
+       fwnode_property_read_u32(port_fwnode, "port", &endpoint->port);
+       fwnode_property_read_u32(fwnode, "endpoint", &endpoint->id);
+
+       return 0;
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
        .property_present = acpi_fwnode_property_present,
        .property_read_int_array = acpi_fwnode_property_read_int_array,
@@ -1190,4 +1231,8 @@ const struct fwnode_operations acpi_fwnode_ops = {
        .get_parent = acpi_fwnode_get_parent,
        .get_next_child_node = acpi_get_next_subnode,
        .get_named_child_node = acpi_fwnode_get_named_child_node,
+       .graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint,
+       .graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint,
+       .graph_get_port_parent = acpi_fwnode_graph_get_port_parent,
+       .graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint,
 };
drivers/base/property.c +1 -30
index 4dc5ab6..6eccc4e 100644
@@ -1154,24 +1154,7 @@ struct fwnode_handle *
 fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode,
                               struct fwnode_handle *prev)
 {
-       struct fwnode_handle *endpoint = NULL;
-
-       if (is_of_node(fwnode)) {
-               struct device_node *node;
-
-               node = of_graph_get_next_endpoint(to_of_node(fwnode),
-                                                 to_of_node(prev));
-
-               if (node)
-                       endpoint = &node->fwnode;
-       } else if (is_acpi_node(fwnode)) {
-               endpoint = acpi_graph_get_next_endpoint(fwnode, prev);
-               if (IS_ERR(endpoint))
-                       endpoint = NULL;
-       }
-
-       return endpoint;
-
+       return fwnode_call_ptr_op(fwnode, graph_get_next_endpoint, prev);
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
 
@@ -1184,24 +1167,11 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
 struct fwnode_handle *
 fwnode_graph_get_remote_port_parent(struct fwnode_handle *fwnode)
 {
-       struct fwnode_handle *parent = NULL;
-
-       if (is_of_node(fwnode)) {
-               struct device_node *node;
-
-               node = of_graph_get_remote_port_parent(to_of_node(fwnode));
-               if (node)
-                       parent = &node->fwnode;
-       } else if (is_acpi_node(fwnode)) {
-               int ret;
-
-               ret = acpi_graph_get_remote_endpoint(fwnode, &parent, NULL,

drivers/base/property.c EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint); · line 1174

Quoted 10 lines
drivers/base/property.c +4 -5
-                                                    NULL);
-               if (ret)
-                       return NULL;
-       }
+       fwnode = fwnode_graph_get_remote_port(fwnode);
+       if (!fwnode)
+               return NULL;
 
-       return parent;
+       return fwnode_call_ptr_op(fwnode, graph_get_port_parent);

Just make fwnode_call_ptr_op(NULL, ...) return NULL.

Quoted 18 lines
drivers/base/property.c +0 -11
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent);
 
@@ -1213,23 +1183,11 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent);
  */
 struct fwnode_handle *fwnode_graph_get_remote_port(struct fwnode_handle *fwnode)
 {
-       struct fwnode_handle *port = NULL;
-
-       if (is_of_node(fwnode)) {
-               struct device_node *node;
-
-               node = of_graph_get_remote_port(to_of_node(fwnode));
-               if (node)
-                       port = &node->fwnode;
-       } else if (is_acpi_node(fwnode)) {
-               int ret;
-

drivers/base/property.c EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent); · line 1190

Quoted 10 lines
drivers/base/property.c +4 -5
-               ret = acpi_graph_get_remote_endpoint(fwnode, NULL, &port, NULL);
-               if (ret)
-                       return NULL;
-       }
+       fwnode = fwnode_graph_get_remote_endpoint(fwnode);
+       if (!fwnode)
+               return NULL;
 
-       return port;
+       return fwnode_get_parent(fwnode);

Just make fwnode_get_parent(NULL) return NULL.

Quoted 63 lines
drivers/base/property.c +2 -34
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
 
@@ -1242,25 +1200,7 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
 struct fwnode_handle *
 fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode)
 {
-       struct fwnode_handle *endpoint = NULL;
-
-       if (is_of_node(fwnode)) {
-               struct device_node *node;
-
-               node = of_parse_phandle(to_of_node(fwnode), "remote-endpoint",
-                                       0);
-               if (node)
-                       endpoint = &node->fwnode;
-       } else if (is_acpi_node(fwnode)) {
-               int ret;
-
-               ret = acpi_graph_get_remote_endpoint(fwnode, NULL, NULL,
-                                                    &endpoint);
-               if (ret)
-                       return NULL;
-       }
-
-       return endpoint;
+       return fwnode_call_ptr_op(fwnode, graph_get_remote_endpoint);
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
 
@@ -1276,22 +1216,8 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
 int fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
                                struct fwnode_endpoint *endpoint)
 {
-       struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode);
-
        memset(endpoint, 0, sizeof(*endpoint));
 
-       endpoint->local_fwnode = fwnode;
-
-       if (is_acpi_node(port_fwnode)) {
-               fwnode_property_read_u32(port_fwnode, "port", &endpoint->port);
-               fwnode_property_read_u32(fwnode, "endpoint", &endpoint->id);
-       } else {
-               fwnode_property_read_u32(port_fwnode, "reg", &endpoint->port);
-               fwnode_property_read_u32(fwnode, "reg", &endpoint->id);
-       }
-
-       fwnode_handle_put(port_fwnode);
-
-       return 0;
+       return fwnode_call_int_op(fwnode, graph_parse_endpoint, endpoint);
 }
 EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
drivers/of/property.c +1 -0
index 984e37e..bb6ac73 100644
@@ -869,6 +869,59 @@ static struct fwnode_handle *of_fwnode_get_named_child_node(
        return NULL;
 }
 
+static struct fwnode_handle *of_fwnode_graph_get_next_endpoint(

drivers/of/property.c static struct fwnode_handle *of_fwnode_get_named_child_node( · line 882

Quoted 10 lines
drivers/of/property.c +10 -0
+       struct fwnode_handle *fwnode, struct fwnode_handle *prev)
+{
+       struct device_node *node;
+
+       node = of_graph_get_next_endpoint(to_of_node(fwnode),
+                                         to_of_node(prev));
+       if (node)
+               return of_fwnode_handle(node);
+
+       return NULL;

Can't of_fwnode_handle() return NULL when node is NULL? Then these functions become one liners:

return of_fwnode_handle(of_graph_get_next_endpoint(to_of_node(fwnode),

                                         to_of_node(prev)));
Quoted 85 lines
drivers/of/property.c +46 -0
+}
+
+static struct fwnode_handle *of_fwnode_graph_get_remote_endpoint(
+       struct fwnode_handle *fwnode)
+{
+       struct device_node *node;
+
+       node = of_parse_phandle(to_of_node(fwnode), "remote-endpoint", 0);
+       if (node)
+               return of_fwnode_handle(node);
+
+       return NULL;
+}
+
+static struct fwnode_handle *of_fwnode_graph_get_port_parent(
+       struct fwnode_handle *fwnode)
+{
+       struct device_node *node;
+
+       node = of_graph_get_port_parent(to_of_node(fwnode));
+       if (node)
+               return of_fwnode_handle(node);
+
+       return NULL;
+}
+
+static int of_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
+                                         struct fwnode_endpoint *endpoint)
+{
+       struct device_node *node = to_of_node(fwnode);
+       struct device_node *port_node = of_get_parent(node);
+
+       endpoint->local_fwnode = fwnode;
+
+       of_property_read_u32(port_node, "reg", &endpoint->port);
+       of_property_read_u32(node, "reg", &endpoint->id);
+
+       of_node_put(port_node);
+
+       return 0;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
        .get = of_fwnode_get,
        .put = of_fwnode_put,
@@ -878,4 +931,8 @@ const struct fwnode_operations of_fwnode_ops = {
        .get_parent = of_fwnode_get_parent,
        .get_next_child_node = of_fwnode_get_next_child_node,
        .get_named_child_node = of_fwnode_get_named_child_node,
+       .graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint,
+       .graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
+       .graph_get_port_parent = of_fwnode_graph_get_port_parent,
+       .graph_parse_endpoint = of_fwnode_graph_parse_endpoint,
 };
include/linux/fwnode.h +12 -1
index e05aaef..35f6626 100644
@@ -57,6 +57,10 @@ struct fwnode_endpoint {
  * @get_parent: Return the parent of an fwnode.
  * @get_next_child_node: Return the next child node in an iteration.
  * @get_named_child_node: Return a child node with a given name.
+ * @graph_get_next_endpoint: Return an endpoint node in an iteration.
+ * @graph_get_remote_endpoint: Return the remote endpoint node of a local
+ *                            endpoint node.
+ * @graph_get_port_parent: Return the parent node of a port node.
  */
 struct fwnode_operations {
        void (*get)(struct fwnode_handle *fwnode);
@@ -75,6 +79,14 @@ struct fwnode_operations {
                struct fwnode_handle *fwnode, struct fwnode_handle *child);
        struct fwnode_handle *(*get_named_child_node)(
                struct fwnode_handle *fwnode, const char *name);
+       struct fwnode_handle *(*graph_get_next_endpoint)(
+               struct fwnode_handle *fwnode, struct fwnode_handle *prev);
+       struct fwnode_handle *(*graph_get_remote_endpoint)(
+               struct fwnode_handle *fwnode);
+       struct fwnode_handle *(*graph_get_port_parent)(
+               struct fwnode_handle *fwnode);
+       int (*graph_parse_endpoint)(struct fwnode_handle *fwnode,
+                                   struct fwnode_endpoint *endpoint);
 };
 
 #define fwnode_has_op(fwnode, op)                              \
--
Quoted 2 lines

2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author reviewer
#6 lore raw

Re: [PATCH v5 3/5] device property: Move fwnode graph ops to firmware specific locations

Hi Rob,

Thanks for the review.

Quoted 2 lines · Rob Herring

On Thu, May 4, 2017 at 2:14 AM, Sakari Ailus
<[email protected]> wrote:

...

Quoted 24 lines
Quoted 24 lines
drivers/base/property.c +3 -16
@@ -1184,24 +1167,11 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
 struct fwnode_handle *
 fwnode_graph_get_remote_port_parent(struct fwnode_handle *fwnode)
 {
-       struct fwnode_handle *parent = NULL;
-
-       if (is_of_node(fwnode)) {
-               struct device_node *node;
-
-               node = of_graph_get_remote_port_parent(to_of_node(fwnode));
-               if (node)
-                       parent = &node->fwnode;
-       } else if (is_acpi_node(fwnode)) {
-               int ret;
-
-               ret = acpi_graph_get_remote_endpoint(fwnode, &parent, NULL,
-                                                    NULL);
-               if (ret)
-                       return NULL;
-       }
+       fwnode = fwnode_graph_get_remote_port(fwnode);
+       if (!fwnode)
+               return NULL;
 
Quoted 4 lines

drivers/base/property.c EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint); · line 1174

Quoted 2 lines
drivers/base/property.c +1 -1
-       return parent;
+       return fwnode_call_ptr_op(fwnode, graph_get_port_parent);

Just make fwnode_call_ptr_op(NULL, ...) return NULL.

Hmm. That already appears to be the case... I'll take that account above, too.

Quoted 27 lines
Quoted 27 lines
drivers/base/property.c +3 -15
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent);
 
@@ -1213,23 +1183,11 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent);
  */
 struct fwnode_handle *fwnode_graph_get_remote_port(struct fwnode_handle *fwnode)
 {
-       struct fwnode_handle *port = NULL;
-
-       if (is_of_node(fwnode)) {
-               struct device_node *node;
-
-               node = of_graph_get_remote_port(to_of_node(fwnode));
-               if (node)
-                       port = &node->fwnode;
-       } else if (is_acpi_node(fwnode)) {
-               int ret;
-
-               ret = acpi_graph_get_remote_endpoint(fwnode, NULL, &port, NULL);
-               if (ret)
-                       return NULL;
-       }
+       fwnode = fwnode_graph_get_remote_endpoint(fwnode);
+       if (!fwnode)
+               return NULL;
 
Quoted 4 lines

drivers/base/property.c EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent); · line 1190

Quoted 2 lines
drivers/base/property.c +1 -1
-       return port;
+       return fwnode_get_parent(fwnode);

Just make fwnode_get_parent(NULL) return NULL.

The same.

Quoted 78 lines
Quoted 64 lines
drivers/base/property.c +2 -34
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
 
@@ -1242,25 +1200,7 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
 struct fwnode_handle *
 fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode)
 {
-       struct fwnode_handle *endpoint = NULL;
-
-       if (is_of_node(fwnode)) {
-               struct device_node *node;
-
-               node = of_parse_phandle(to_of_node(fwnode), "remote-endpoint",
-                                       0);
-               if (node)
-                       endpoint = &node->fwnode;
-       } else if (is_acpi_node(fwnode)) {
-               int ret;
-
-               ret = acpi_graph_get_remote_endpoint(fwnode, NULL, NULL,
-                                                    &endpoint);
-               if (ret)
-                       return NULL;
-       }
-
-       return endpoint;
+       return fwnode_call_ptr_op(fwnode, graph_get_remote_endpoint);
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
 
@@ -1276,22 +1216,8 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
 int fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
                                struct fwnode_endpoint *endpoint)
 {
-       struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode);
-
        memset(endpoint, 0, sizeof(*endpoint));
 
-       endpoint->local_fwnode = fwnode;
-
-       if (is_acpi_node(port_fwnode)) {
-               fwnode_property_read_u32(port_fwnode, "port", &endpoint->port);
-               fwnode_property_read_u32(fwnode, "endpoint", &endpoint->id);
-       } else {
-               fwnode_property_read_u32(port_fwnode, "reg", &endpoint->port);
-               fwnode_property_read_u32(fwnode, "reg", &endpoint->id);
-       }
-
-       fwnode_handle_put(port_fwnode);
-
-       return 0;
+       return fwnode_call_int_op(fwnode, graph_parse_endpoint, endpoint);
 }
 EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
drivers/of/property.c +1 -0
index 984e37e..bb6ac73 100644
@@ -869,6 +869,59 @@ static struct fwnode_handle *of_fwnode_get_named_child_node(
        return NULL;
 }
 
+static struct fwnode_handle *of_fwnode_graph_get_next_endpoint(

drivers/of/property.c static struct fwnode_handle *of_fwnode_get_named_child_node( · line 882

Quoted 10 lines
drivers/of/property.c +10 -0
+       struct fwnode_handle *fwnode, struct fwnode_handle *prev)
+{
+       struct device_node *node;
+
+       node = of_graph_get_next_endpoint(to_of_node(fwnode),
+                                         to_of_node(prev));
+       if (node)
+               return of_fwnode_handle(node);
+
+       return NULL;

Can't of_fwnode_handle() return NULL when node is NULL? Then these functions become one liners:

Quoted 2 lines

return of_fwnode_handle(of_graph_get_next_endpoint(to_of_node(fwnode),

                                         to_of_node(prev)));

Good point. of_fwnode_handle() is a macro (in order to support const / non-const cases) and it'll be a little bit more complex but I guess that's not really an issue.

Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]