All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] dm: core: Add size operations on device tree references
@ 2021-04-12  6:51 chenguanqiao
  2021-04-12  6:51 ` [PATCH v3 1/2] " chenguanqiao
  2021-04-12  6:51 ` [PATCH v3 2/2] test: dm: add test item for ofnode_get_addr() and ofnode_get_size() chenguanqiao
  0 siblings, 2 replies; 7+ messages in thread
From: chenguanqiao @ 2021-04-12  6:51 UTC (permalink / raw)
  To: u-boot

From: Chen Guanqiao <chenguanqiao@kuaishou.com>

Currently, there is only an interface for obtaining address from node,
and if you want to get the size, you need to traverse the node.

So I added the function to get the size, and added related test case.

Changes for v3:
- Add return error for ofnode_get_size

Changes for v2:
- Add a test to test/dm/ofnode.c

Chen Guanqiao (2):
  dm: core: Add size operations on device tree references
  test: dm: add test item for ofnode_get_addr() and ofnode_get_size()

 drivers/core/ofnode.c | 11 +++++++++++
 include/dm/ofnode.h   | 10 ++++++++++
 include/fdtdec.h      |  5 +++--
 test/dm/ofnode.c      | 31 +++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 2 deletions(-)

--
2.27.0

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

* [PATCH v3 1/2] dm: core: Add size operations on device tree references
  2021-04-12  6:51 [PATCH v3 0/2] dm: core: Add size operations on device tree references chenguanqiao
@ 2021-04-12  6:51 ` chenguanqiao
  2021-04-12 18:04   ` Simon Glass
  2021-04-29 16:03   ` Simon Glass
  2021-04-12  6:51 ` [PATCH v3 2/2] test: dm: add test item for ofnode_get_addr() and ofnode_get_size() chenguanqiao
  1 sibling, 2 replies; 7+ messages in thread
From: chenguanqiao @ 2021-04-12  6:51 UTC (permalink / raw)
  To: u-boot

From: Chen Guanqiao <chenguanqiao@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@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

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

* [PATCH v3 2/2] test: dm: add test item for ofnode_get_addr() and ofnode_get_size()
  2021-04-12  6:51 [PATCH v3 0/2] dm: core: Add size operations on device tree references chenguanqiao
  2021-04-12  6:51 ` [PATCH v3 1/2] " chenguanqiao
@ 2021-04-12  6:51 ` chenguanqiao
  2021-04-12 18:04   ` Simon Glass
  2021-04-29 16:03   ` Simon Glass
  1 sibling, 2 replies; 7+ messages in thread
From: chenguanqiao @ 2021-04-12  6:51 UTC (permalink / raw)
  To: u-boot

From: Chen Guanqiao <chenguanqiao@kuaishou.com>

Add test item for getting address and size functions

Test the following function:
- ofnode_get_addr()
- ofnode_get_size()

Signed-off-by: Chen Guanqiao <chenguanqiao@kuaishou.com>
---
 test/dm/ofnode.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index c539134296..e0b525eeb1 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -261,3 +261,34 @@ static int dm_test_ofnode_is_enabled(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_ofnode_is_enabled, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+static int dm_test_ofnode_get_reg(struct unit_test_state *uts)
+{
+	ofnode node;
+	fdt_addr_t addr;
+	fdt_size_t size;
+
+	node = ofnode_path("/translation-test at 8000");
+	ut_assert(ofnode_valid(node));
+	addr = ofnode_get_addr(node);
+	size = ofnode_get_size(node);
+	ut_asserteq(0x8000, addr);
+	ut_asserteq(0x4000, size);
+
+	node = ofnode_path("/translation-test at 8000/dev at 1,100");
+	ut_assert(ofnode_valid(node));
+	addr = ofnode_get_addr(node);
+	size = ofnode_get_size(node);
+	ut_asserteq(0x9000, addr);
+	ut_asserteq(0x1000, size);
+
+	node = ofnode_path("/emul-mux-controller");
+	ut_assert(ofnode_valid(node));
+	addr = ofnode_get_addr(node);
+	size = ofnode_get_size(node);
+	ut_asserteq(FDT_ADDR_T_NONE, addr);
+	ut_asserteq(FDT_SIZE_T_NONE, size);
+
+	return 0;
+}
+DM_TEST(dm_test_ofnode_get_reg, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
--
2.27.0

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

* [PATCH v3 1/2] dm: core: Add size operations on device tree references
  2021-04-12  6:51 ` [PATCH v3 1/2] " chenguanqiao
@ 2021-04-12 18:04   ` Simon Glass
  2021-04-29 16:03   ` Simon Glass
  1 sibling, 0 replies; 7+ messages in thread
From: Simon Glass @ 2021-04-12 18:04 UTC (permalink / raw)
  To: u-boot

On Mon, 12 Apr 2021 at 18:51, chenguanqiao <chenguanqiao@kuaishou.com> wrote:
>
> From: Chen Guanqiao <chenguanqiao@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@kuaishou.com>
> ---
>  drivers/core/ofnode.c | 11 +++++++++++
>  include/dm/ofnode.h   | 10 ++++++++++
>  include/fdtdec.h      |  5 +++--
>  3 files changed, 24 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* [PATCH v3 2/2] test: dm: add test item for ofnode_get_addr() and ofnode_get_size()
  2021-04-12  6:51 ` [PATCH v3 2/2] test: dm: add test item for ofnode_get_addr() and ofnode_get_size() chenguanqiao
@ 2021-04-12 18:04   ` Simon Glass
  2021-04-29 16:03   ` Simon Glass
  1 sibling, 0 replies; 7+ messages in thread
From: Simon Glass @ 2021-04-12 18:04 UTC (permalink / raw)
  To: u-boot

On Mon, 12 Apr 2021 at 18:51, chenguanqiao <chenguanqiao@kuaishou.com> wrote:
>
> From: Chen Guanqiao <chenguanqiao@kuaishou.com>
>
> Add test item for getting address and size functions
>
> Test the following function:
> - ofnode_get_addr()
> - ofnode_get_size()
>
> Signed-off-by: Chen Guanqiao <chenguanqiao@kuaishou.com>
> ---
>  test/dm/ofnode.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* [PATCH v3 2/2] test: dm: add test item for ofnode_get_addr() and ofnode_get_size()
  2021-04-12  6:51 ` [PATCH v3 2/2] test: dm: add test item for ofnode_get_addr() and ofnode_get_size() chenguanqiao
  2021-04-12 18:04   ` Simon Glass
@ 2021-04-29 16:03   ` Simon Glass
  1 sibling, 0 replies; 7+ messages in thread
From: Simon Glass @ 2021-04-29 16:03 UTC (permalink / raw)
  To: u-boot

On Mon, 12 Apr 2021 at 18:51, chenguanqiao <chenguanqiao@kuaishou.com> wrote:
>
> From: Chen Guanqiao <chenguanqiao@kuaishou.com>
>
> Add test item for getting address and size functions
>
> Test the following function:
> - ofnode_get_addr()
> - ofnode_get_size()
>
> Signed-off-by: Chen Guanqiao <chenguanqiao@kuaishou.com>
> ---
>  test/dm/ofnode.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

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

* [PATCH v3 1/2] dm: core: Add size operations on device tree references
  2021-04-12  6:51 ` [PATCH v3 1/2] " chenguanqiao
  2021-04-12 18:04   ` Simon Glass
@ 2021-04-29 16:03   ` Simon Glass
  1 sibling, 0 replies; 7+ messages in thread
From: Simon Glass @ 2021-04-29 16:03 UTC (permalink / raw)
  To: u-boot

On Mon, 12 Apr 2021 at 18:51, chenguanqiao <chenguanqiao@kuaishou.com> wrote:
>
> From: Chen Guanqiao <chenguanqiao@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@kuaishou.com>
> ---
>  drivers/core/ofnode.c | 11 +++++++++++
>  include/dm/ofnode.h   | 10 ++++++++++
>  include/fdtdec.h      |  5 +++--
>  3 files changed, 24 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

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

end of thread, other threads:[~2021-04-29 16:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12  6:51 [PATCH v3 0/2] dm: core: Add size operations on device tree references chenguanqiao
2021-04-12  6:51 ` [PATCH v3 1/2] " chenguanqiao
2021-04-12 18:04   ` Simon Glass
2021-04-29 16:03   ` Simon Glass
2021-04-12  6:51 ` [PATCH v3 2/2] test: dm: add test item for ofnode_get_addr() and ofnode_get_size() chenguanqiao
2021-04-12 18:04   ` Simon Glass
2021-04-29 16:03   ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.