Skip to contentSkip to conversation

of: Add of_get_memory_prop()

PATCH In review Raghavendra Rao Ananta 4 participants 5 messages Sep 18, 2019 – Oct 17, 2019 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of: Add of_get_memory_prop()

On some embedded systems, the '/memory' dt-property gets updated by the bootloader (for example, the DDR configuration) and then gets passed onto the kernel. The device drivers may have to read the properties at runtime to make decisions. Hence, add of_get_memory_prop() for the device drivers to query the requested properties.

---
 drivers/of/fdt.c       | 27 +++++++++++++++++++++++++++
 include/linux/of_fdt.h |  1 +
 2 files changed, 28 insertions(+)
drivers/of/fdt.c +27 -0
index 223d617ecfe1..925cf2852433 100644
@@ -79,6 +79,33 @@ void __init of_fdt_limit_memory(int limit)
 	}
 }
 
+/**
+ * of_fdt_get_memory_prop - Return the requested property from the /memory node
+ *
+ * On match, returns a non-zero positive value which represents the property
+ * value. Otherwise returns -ENOENT.
+ */
+int of_fdt_get_memory_prop(const char *pname)
+{
+	int memory;
+	int len;
+	fdt32_t *prop = NULL;
+
+	if (!pname)
+		return -EINVAL;
+
+	memory = fdt_path_offset(initial_boot_params, "/memory");
+	if (memory > 0)
+		prop = fdt_getprop_w(initial_boot_params, memory,
+				  pname, &len);
+
+	if (!prop || len != sizeof(u32))
+		return -ENOENT;
+
+	return fdt32_to_cpu(*prop);
+}
+EXPORT_SYMBOL_GPL(of_fdt_get_memory_prop);
+
 static bool of_fdt_device_is_available(const void *blob, unsigned long node)
 {
 	const char *status = fdt_getprop(blob, node, "status", NULL);
include/linux/of_fdt.h +1 -0
index acf820e88952..537f29373358 100644
@@ -38,6 +38,7 @@ extern char __dtb_end[];
 /* Other Prototypes */
 extern u64 of_flat_dt_translate_address(unsigned long node);
 extern void of_fdt_limit_memory(int limit);
+extern int of_fdt_get_memory_prop(const char *pname);
 #endif /* CONFIG_OF_FLATTREE */
 
 #ifdef CONFIG_OF_EARLY_FLATTREE
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
Quoted 6 lines · Raghavendra Rao Ananta

On some embedded systems, the '/memory' dt-property gets updated by the bootloader (for example, the DDR configuration) and then gets passed onto the kernel. The device drivers may have to read the properties at runtime to make decisions. Hence, add of_get_memory_prop() for the device drivers to query the requested

Function name doesn't match. Device drivers don't need to access the FDT.

Quoted 7 lines

properties.

---
 drivers/of/fdt.c       | 27 +++++++++++++++++++++++++++
 include/linux/of_fdt.h |  1 +
 2 files changed, 28 insertions(+)

We don't add kernel api's without users.

Quoted 15 lines
drivers/of/fdt.c +6 -0
index 223d617ecfe1..925cf2852433 100644
@@ -79,6 +79,33 @@ void __init of_fdt_limit_memory(int limit)
        }
 }
 
+/**
+ * of_fdt_get_memory_prop - Return the requested property from the /memory node
+ *
+ * On match, returns a non-zero positive value which represents the property
+ * value. Otherwise returns -ENOENT.
+ */

drivers/of/fdt.c void __init of_fdt_limit_memory(int limit) · line 97

Quoted 10 lines
drivers/of/fdt.c +10 -0
+int of_fdt_get_memory_prop(const char *pname)
+{
+       int memory;
+       int len;
+       fdt32_t *prop = NULL;
+
+       if (!pname)
+               return -EINVAL;
+
+       memory = fdt_path_offset(initial_boot_params, "/memory");

Memory nodes should have a unit-address, so this won't work frequently.

Quoted 30 lines
drivers/of/fdt.c +11 -0
+       if (memory > 0)
+               prop = fdt_getprop_w(initial_boot_params, memory,
+                                 pname, &len);
+
+       if (!prop || len != sizeof(u32))
+               return -ENOENT;
+
+       return fdt32_to_cpu(*prop);
+}
+EXPORT_SYMBOL_GPL(of_fdt_get_memory_prop);
+
 static bool of_fdt_device_is_available(const void *blob, unsigned long node)
 {
        const char *status = fdt_getprop(blob, node, "status", NULL);
include/linux/of_fdt.h +1 -1
index acf820e88952..537f29373358 100644
@@ -38,6 +38,7 @@ extern char __dtb_end[];
 /* Other Prototypes */
 extern u64 of_flat_dt_translate_address(unsigned long node);
 extern void of_fdt_limit_memory(int limit);
+extern int of_fdt_get_memory_prop(const char *pname);
 #endif /* CONFIG_OF_FLATTREE */
 
 #ifdef CONFIG_OF_EARLY_FLATTREE
--

The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

#2 lore raw
Quoted 42 lines · Rob Herring
Quoted 6 lines · Raghavendra Rao Ananta

On some embedded systems, the '/memory' dt-property gets updated by the bootloader (for example, the DDR configuration) and then gets passed onto the kernel. The device drivers may have to read the properties at runtime to make decisions. Hence, add of_get_memory_prop() for the device drivers to query the requested

Function name doesn't match. Device drivers don't need to access the FDT.

Quoted 7 lines

properties.

---
 drivers/of/fdt.c       | 27 +++++++++++++++++++++++++++
 include/linux/of_fdt.h |  1 +
 2 files changed, 28 insertions(+)

We don't add kernel api's without users.

Quoted 21 lines
drivers/of/fdt.c +2 -0
index 223d617ecfe1..925cf2852433 100644
@@ -79,6 +79,33 @@ void __init of_fdt_limit_memory(int limit)
        }
 }
 
+/**
+ * of_fdt_get_memory_prop - Return the requested property from the 

/memory node
+ *
+ * On match, returns a non-zero positive value which represents the property
+ * value. Otherwise returns -ENOENT.
+ */

drivers/of/fdt.c +4 -0
+int of_fdt_get_memory_prop(const char *pname)
+{
+       int memory;
+       int len;
Quoted 8 lines

drivers/of/fdt.c void __init of_fdt_limit_memory(int limit) · line 97

Quoted 6 lines
drivers/of/fdt.c +6 -0
+       fdt32_t *prop = NULL;
+
+       if (!pname)
+               return -EINVAL;
+
+       memory = fdt_path_offset(initial_boot_params, "/memory");

Memory nodes should have a unit-address, so this won't work frequently.

Sorry, can you please elaborate more on this? What do you mean by unit-address and working frequently?

Quoted 27 lines
Quoted 27 lines
drivers/of/fdt.c +11 -0
+       if (memory > 0)
+               prop = fdt_getprop_w(initial_boot_params, memory,
+                                 pname, &len);
+
+       if (!prop || len != sizeof(u32))
+               return -ENOENT;
+
+       return fdt32_to_cpu(*prop);
+}
+EXPORT_SYMBOL_GPL(of_fdt_get_memory_prop);
+
 static bool of_fdt_device_is_available(const void *blob, unsigned 

long node)

 {
        const char *status = fdt_getprop(blob, node, "status", NULL);
include/linux/of_fdt.h +1 -0
index acf820e88952..537f29373358 100644
@@ -38,6 +38,7 @@ extern char __dtb_end[];
 /* Other Prototypes */
 extern u64 of_flat_dt_translate_address(unsigned long node);
 extern void of_fdt_limit_memory(int limit);
+extern int of_fdt_get_memory_prop(const char *pname);
 #endif /* CONFIG_OF_FLATTREE */
 
Quoted 5 lines
Quoted 5 lines
include/linux/of_fdt.h +0 -1
 #ifdef CONFIG_OF_EARLY_FLATTREE
--

The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

- Raghavendra

maintainer
#3 lore raw
Quoted 52 lines · On Wed, Sep 18, 2019 at 03:32:14PM -0700, [email protected] wrote:
Quoted 43 lines · Rob Herring
Quoted 6 lines · Raghavendra Rao Ananta

On some embedded systems, the '/memory' dt-property gets updated by the bootloader (for example, the DDR configuration) and then gets passed onto the kernel. The device drivers may have to read the properties at runtime to make decisions. Hence, add of_get_memory_prop() for the device drivers to query the requested

Function name doesn't match. Device drivers don't need to access the FDT.

Quoted 7 lines

properties.

---
 drivers/of/fdt.c       | 27 +++++++++++++++++++++++++++
 include/linux/of_fdt.h |  1 +
 2 files changed, 28 insertions(+)

We don't add kernel api's without users.

Quoted 21 lines
drivers/of/fdt.c +2 -0
index 223d617ecfe1..925cf2852433 100644
@@ -79,6 +79,33 @@ void __init of_fdt_limit_memory(int limit)
        }
 }
 
+/**
+ * of_fdt_get_memory_prop - Return the requested property from the

/memory node
+ *
+ * On match, returns a non-zero positive value which represents the property
+ * value. Otherwise returns -ENOENT.
+ */

drivers/of/fdt.c +4 -0
+int of_fdt_get_memory_prop(const char *pname)
+{
+       int memory;
+       int len;
Quoted 8 lines

drivers/of/fdt.c void __init of_fdt_limit_memory(int limit) · line 97

Quoted 6 lines
drivers/of/fdt.c +6 -0
+       fdt32_t *prop = NULL;
+
+       if (!pname)
+               return -EINVAL;
+
+       memory = fdt_path_offset(initial_boot_params, "/memory");

Memory nodes should have a unit-address, so this won't work frequently.

Quoted 2 lines

Sorry, can you please elaborate more on this? What do you mean by unit-address and working frequently?

A memory node is typically going to be something like: /memory@80000000. So your function will not work for any of those cases. And just '/memory' generates a dtc warning.

Rob

#4 lore raw

Hi Raghavendra,

I have not received your emails in this conversation, and I do not see them in my spam folder. I see some replies from Rob, so I am guessing he added me to the CC: list.

Please add me to future Devicetree emails.

Digging a little deeper, in the devicetree mail list archive, I see myself on the CC: list of your "Date: Wed, 18 Sep 2019 15:32:14 -0700" reply to Rob. I'm not sure why that email did not get through to me.

So just a heads up that something may be interfering with delivery of email from you to me. I've seen disappearing email problem from other senders, even when most of their emails get through.

Thanks,

Frank

Quoted 63 lines · Rob Herring
Quoted 52 lines · On Wed, Sep 18, 2019 at 03:32:14PM -0700, [email protected] wrote:
Quoted 43 lines · Rob Herring
Quoted 6 lines · Raghavendra Rao Ananta

On some embedded systems, the '/memory' dt-property gets updated by the bootloader (for example, the DDR configuration) and then gets passed onto the kernel. The device drivers may have to read the properties at runtime to make decisions. Hence, add of_get_memory_prop() for the device drivers to query the requested

Function name doesn't match. Device drivers don't need to access the FDT.

Quoted 7 lines

properties.

---
 drivers/of/fdt.c       | 27 +++++++++++++++++++++++++++
 include/linux/of_fdt.h |  1 +
 2 files changed, 28 insertions(+)

We don't add kernel api's without users.

Quoted 21 lines
drivers/of/fdt.c +2 -0
index 223d617ecfe1..925cf2852433 100644
@@ -79,6 +79,33 @@ void __init of_fdt_limit_memory(int limit)
        }
 }
 
+/**
+ * of_fdt_get_memory_prop - Return the requested property from the

/memory node
+ *
+ * On match, returns a non-zero positive value which represents the property
+ * value. Otherwise returns -ENOENT.
+ */

drivers/of/fdt.c +4 -0
+int of_fdt_get_memory_prop(const char *pname)
+{
+       int memory;
+       int len;
Quoted 8 lines

drivers/of/fdt.c void __init of_fdt_limit_memory(int limit) · line 97

Quoted 6 lines
drivers/of/fdt.c +6 -0
+       fdt32_t *prop = NULL;
+
+       if (!pname)
+               return -EINVAL;
+
+       memory = fdt_path_offset(initial_boot_params, "/memory");

Memory nodes should have a unit-address, so this won't work frequently.

Quoted 2 lines

Sorry, can you please elaborate more on this? What do you mean by unit-address and working frequently?

A memory node is typically going to be something like: /memory@80000000. So your function will not work for any of those cases. And just '/memory' generates a dtc warning.

Rob