[PATCH v3 1/2] dm: core: Add size operations on device tree references
chenguanqiao
chenguanqiao at kuaishou.com
Mon Apr 12 08:51:11 CEST 2021
From: Chen Guanqiao <chenguanqiao at kuaishou.com>
Add functions to add size of addresses in the device tree using ofnode
references.
If the size is not set, return FDT_SIZE_T_NONE.
Signed-off-by: Chen Guanqiao <chenguanqiao at kuaishou.com>
---
drivers/core/ofnode.c | 11 +++++++++++
include/dm/ofnode.h | 10 ++++++++++
include/fdtdec.h | 5 +++--
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index fa0bd2a9c4..d50533338e 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -303,6 +303,8 @@ fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
{
int na, ns;
+ *size = FDT_SIZE_T_NONE;
+
if (ofnode_is_np(node)) {
const __be32 *prop_val;
u64 size64;
@@ -347,6 +349,15 @@ fdt_addr_t ofnode_get_addr(ofnode node)
return ofnode_get_addr_index(node, 0);
}
+fdt_size_t ofnode_get_size(ofnode node)
+{
+ fdt_size_t size;
+
+ ofnode_get_addr_size_index(node, 0, &size);
+
+ return size;
+}
+
int ofnode_stringlist_search(ofnode node, const char *property,
const char *string)
{
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 2c0597c407..8a69fd87da 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -510,6 +510,16 @@ phys_addr_t ofnode_get_addr_index(ofnode node, int index);
*/
phys_addr_t ofnode_get_addr(ofnode node);
+/**
+ * ofnode_get_size() - get size from a node
+ *
+ * This reads the register size from a node
+ *
+ * @node: node to read from
+ * @return size of the address, or FDT_SIZE_T_NONE if not present or invalid
+ */
+fdt_size_t ofnode_get_size(ofnode node);
+
/**
* ofnode_stringlist_search() - find a string in a string list and return index
*
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 62d1660973..e0a49b1e57 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -24,15 +24,16 @@
typedef phys_addr_t fdt_addr_t;
typedef phys_size_t fdt_size_t;
-#ifdef CONFIG_PHYS_64BIT
#define FDT_ADDR_T_NONE (-1U)
+#define FDT_SIZE_T_NONE (-1U)
+
+#ifdef CONFIG_PHYS_64BIT
#define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
#define fdt_size_to_cpu(reg) be64_to_cpu(reg)
#define cpu_to_fdt_addr(reg) cpu_to_be64(reg)
#define cpu_to_fdt_size(reg) cpu_to_be64(reg)
typedef fdt64_t fdt_val_t;
#else
-#define FDT_ADDR_T_NONE (-1U)
#define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
#define fdt_size_to_cpu(reg) be32_to_cpu(reg)
#define cpu_to_fdt_addr(reg) cpu_to_be32(reg)
--
2.27.0
More information about the U-Boot
mailing list