Skip to contentSkip to conversation

device property: Add fwnode_get_name() helper

PATCH Superseded Heikki Krogerus 2 participants 8 messages Nov 27, 2018 – Nov 28, 2018

Subsystems (4)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Heikki Krogerus

author reviewer
#0 lore raw

v4 cover device property: Add fwnode_get_name() helper

Hi,

I'm now returning -EOVERFLOW if the buffer is not big enough as proposed by Andy.

This is the cover letter from v3:

This is the third version of my proposal for this helper. The second version can be checked here:
https://lkml.org/lkml/2018/11/8/1005

I'm now passing the length as proposed by both Rob and Andy. I'm also leaving the .get_named_child_node fwnode op untouched.

--
heikki

Heikki Krogerus (4):
device property: Introduce fwnode_get_name()
ACPI: property: Add acpi_fwnode_name() of/property: Add of_fwnode_name()
driver core: Add fwnode member to struct device_connection

 drivers/acpi/property.c  | 28 ++++++++++++++++++++++++++++
 drivers/base/property.c  | 36 ++++++++++++++++++++++++++++++++++++
 drivers/of/property.c    | 13 +++++++++++++
 include/linux/device.h   |  6 ++++++
 include/linux/fwnode.h   |  3 +++
 include/linux/property.h |  2 ++
 6 files changed, 88 insertions(+)
Signature · 1 line
2.19.2
author reviewer
#1 lore raw

PATCH v4 1/4 device property: Introduce fwnode_get_name()

This helper returns the name of the node. The name is primarily expected to be returned from a new fwnode operation meant for this purpose, but when no name is returned, the helper will also attempt to read a device property "name".

---
 drivers/base/property.c  | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/fwnode.h   |  3 +++
 include/linux/property.h |  2 ++
 3 files changed, 41 insertions(+)
drivers/base/property.c +36 -0
index 240ab5230ff6..8bd35b44d9ec 100644
@@ -1156,6 +1156,42 @@ void fwnode_handle_put(struct fwnode_handle *fwnode)
 }
 EXPORT_SYMBOL_GPL(fwnode_handle_put);
 
+/**
+ * fwnode_get_name - Copy the name of an fwnode to a buffer
+ * @fwnode: Pointer to the node
+ * @buf: Buffer where the name is copied to
+ * @len: Size of the buffer
+ *
+ * Copies the node name of @fwnode to @buf. The routine attempts to first use
+ * the get_name fwnode op of @fwnode, and if it fails, the routine attempts to
+ * read a property "name".
+ *
+ * NOTE: @buf must be large enough to accommodate the name and trailing '\0'.
+ *
+ * Returns 0 on success or errno in case of an error.
+ */
+int fwnode_get_name(const struct fwnode_handle *fwnode, char *buf, size_t len)
+{
+	const char *name;
+	int ret;
+
+	ret = fwnode_call_int_op(fwnode, get_name, buf, len);
+	if (ret == 0 || ret == -EOVERFLOW)
+		return ret;
+
+	ret = fwnode_call_int_op(fwnode, property_read_string_array,
+				 "name", &name, 1);
+	if (ret)
+		return ret;
+
+	if (len < strlen(name) + 1)
+		return -EOVERFLOW;
+
+	sprintf(buf, "%s", name);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(fwnode_get_name);
+
 /**
  * fwnode_device_is_available - check if a device is available for use
  * @fwnode: Pointer to the fwnode of the device.
include/linux/fwnode.h +3 -0
index faebf0ca0686..a211b55a5da1 100644
@@ -52,6 +52,7 @@ struct fwnode_reference_args {
  * struct fwnode_operations - Operations for fwnode interface
  * @get: Get a reference to an fwnode.
  * @put: Put a reference to an fwnode.
+ * @get_name: Get the name of an fwnode
  * @device_get_match_data: Return the device driver match data.
  * @property_present: Return true if a property is present.
  * @property_read_integer_array: Read an array of integer properties. Return
@@ -72,6 +73,8 @@ struct fwnode_reference_args {
 struct fwnode_operations {
 	struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
 	void (*put)(struct fwnode_handle *fwnode);
+	int (*get_name)(const struct fwnode_handle *fwnode, char *buf,
+			size_t len);
 	bool (*device_is_available)(const struct fwnode_handle *fwnode);
 	const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
 					     const struct device *dev);
include/linux/property.h +2 -0
index ac8a1ebc4c1b..e77f08f49c48 100644
@@ -109,6 +109,8 @@ struct fwnode_handle *device_get_named_child_node(struct device *dev,
 struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
 void fwnode_handle_put(struct fwnode_handle *fwnode);
 
+int fwnode_get_name(const struct fwnode_handle *fwnode, char *name, size_t len);
+
 int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
 
 unsigned int device_get_child_node_count(struct device *dev);
Signature · 1 line
2.19.2
author reviewer
#2 lore raw

PATCH v4 2/4 ACPI: property: Add acpi_fwnode_name()

In reply to Heikki Krogerus

This implements the get_name fwnode op for ACPI.

---
 drivers/acpi/property.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/acpi/property.c +28 -0
index 8c7c4583b52d..c24cf02e9214 100644
@@ -1219,6 +1219,33 @@ acpi_graph_get_remote_endpoint(const struct fwnode_handle *__fwnode)
 	return acpi_graph_get_child_prop_value(fwnode, "endpoint", endpoint_nr);
 }
 
+static int
+acpi_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf, size_t len)
+{
+	struct acpi_buffer buffer;
+	acpi_status status;
+
+	if (is_acpi_data_node(fwnode)) {
+		if (len < strlen(to_acpi_data_node(fwnode)->name) + 1)
+			return -EOVERFLOW;
+		sprintf(buf, "%s", to_acpi_data_node(fwnode)->name);
+		return 0;
+	}
+
+	if (len < ACPI_NAME_SIZE + 1)
+		return -EOVERFLOW;
+
+	buffer.length = ACPI_NAME_SIZE + 1;
+	buffer.pointer = buf;
+
+	status = acpi_get_name(to_acpi_device_node(fwnode)->handle,
+			       ACPI_SINGLE_NAME, &buffer);
+	if (ACPI_FAILURE(status))
+		return -ENXIO;
+
+	return 0;
+}
+
 static bool acpi_fwnode_device_is_available(const struct fwnode_handle *fwnode)
 {
 	if (!is_acpi_device_node(fwnode))
@@ -1310,6 +1337,7 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
 
 #define DECLARE_ACPI_FWNODE_OPS(ops) \
 	const struct fwnode_operations ops = {				\
+		.get_name = acpi_fwnode_get_name,			\
 		.device_is_available = acpi_fwnode_device_is_available, \
 		.device_get_match_data = acpi_fwnode_device_get_match_data, \
 		.property_present = acpi_fwnode_property_present,	\
Signature · 1 line
2.19.2
author reviewer
#3 lore raw

PATCH v4 3/4 of/property: Add of_fwnode_name()

In reply to Heikki Krogerus

This implements get_name fwnode op for DT.

---
 drivers/of/property.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/of/property.c +13 -0
index f46828e3b082..403bc9cbbaf4 100644
@@ -823,6 +823,18 @@ static void of_fwnode_put(struct fwnode_handle *fwnode)
 	of_node_put(to_of_node(fwnode));
 }
 
+static int of_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf,
+			      size_t len)
+{
+	const struct device_node *node = to_of_node(fwnode);
+
+	if (len < snprintf(NULL, 0, "%pOFn", node) + 1)
+		return -EOVERFLOW;
+
+	sprintf(buf, "%pOFn", node);
+	return 0;
+}
+
 static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode)
 {
 	return of_device_is_available(to_of_node(fwnode));
@@ -987,6 +999,7 @@ of_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
+	.get_name = of_fwnode_get_name,
 	.device_is_available = of_fwnode_device_is_available,
 	.device_get_match_data = of_fwnode_device_get_match_data,
 	.property_present = of_fwnode_property_present,
Signature · 1 line
2.19.2
author reviewer
#4 lore raw

PATCH v4 4/4 driver core: Add fwnode member to struct device_connection

In reply to Heikki Krogerus

This will prepare the device connection API for connections described in firmware.

---
 include/linux/device.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/linux/device.h +6 -0
index 1b25c7a43f4c..25e0409e0b0c 100644
@@ -757,11 +757,17 @@ struct device_dma_parameters {
 
 /**
  * struct device_connection - Device Connection Descriptor
+ * @fwnode: The device node of the connected device
  * @endpoint: The names of the two devices connected together
  * @id: Unique identifier for the connection
  * @list: List head, private, for internal use only
+ *
+ * NOTE: @fwnode is not used together with @endpoint. @fwnode is used when
+ * platform firmware defines the connection. When the connection is registeded
+ * with device_connection_add() @endpoint is used instead.
  */
 struct device_connection {
+	struct fwnode_handle	*fwnode;
 	const char		*endpoint[2];
 	const char		*id;
 	struct list_head	list;
Signature · 1 line
2.19.2
author reviewer
#5 lore raw

Re: [PATCH v4 4/4] driver core: Add fwnode member to struct device_connection

Quoted 2 lines · Heikki Krogerus

This will prepare the device connection API for connections described in firmware.

This one does not belong to this series, sorry. Please skip it, or if you prefer, I'll resend.

thanks,

Signature · 1 line
heikki
reviewer Reviewed-by
#6 lore raw

Re: [PATCH v4 4/4] driver core: Add fwnode member to struct device_connection

Quoted 6 lines · Heikki Krogerus
Quoted 2 lines · Heikki Krogerus

This will prepare the device connection API for connections described in firmware.

This one does not belong to this series, sorry. Please skip it, or if you prefer, I'll resend.

Please, resend. It would reduce amount of confusion,

Otherwise the series looks good to me.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#7 lore raw

Re: [PATCH v4 4/4] driver core: Add fwnode member to struct device_connection

Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Heikki Krogerus
Quoted 2 lines · Heikki Krogerus

This will prepare the device connection API for connections described in firmware.

Quoted 8 lines
Quoted 2 lines

This one does not belong to this series, sorry. Please skip it, or if you prefer, I'll resend.

Please, resend. It would reduce amount of confusion,

Otherwise the series looks good to me.

Sure. I'll resend. Thanks Andy!

br,

Signature · 1 line
heikki