[PATCH v2 0/2] dm: core: Add size operations on device tree references

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 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 | 9 +++++++++ include/dm/ofnode.h | 10 ++++++++++ test/dm/ofnode.c | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+)

Add functions to add size of addresses in the device tree using ofnode references.
Signed-off-by: Chen Guanqiao chenguanqiao@kuaishou.com --- drivers/core/ofnode.c | 9 +++++++++ include/dm/ofnode.h | 10 ++++++++++ 2 files changed, 19 insertions(+)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index fa0bd2a9c4..952c3cf9dd 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -347,6 +347,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..e91f81282b 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 + */ +fdt_size_t ofnode_get_size(ofnode node); + /** * ofnode_stringlist_search() - find a string in a string list and return index *

On Fri, 2 Apr 2021 at 19:30, chenguanqiao chenguanqiao@kuaishou.com wrote:
Add functions to add size of addresses in the device tree using ofnode references.
Signed-off-by: Chen Guanqiao chenguanqiao@kuaishou.com
drivers/core/ofnode.c | 9 +++++++++ include/dm/ofnode.h | 10 ++++++++++ 2 files changed, 19 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index fa0bd2a9c4..952c3cf9dd 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -347,6 +347,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);
size is not set if this function returns an error, so in that can you need to return something
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..e91f81282b 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
- */
+fdt_size_t ofnode_get_size(ofnode node);
/**
- ofnode_stringlist_search() - find a string in a string list and return index
-- 2.25.1

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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index c539134296..0d958b4900 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -261,3 +261,27 @@ 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@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@8000/dev@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); + + return 0; +} +DM_TEST(dm_test_ofnode_get_reg, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);

On Fri, 2 Apr 2021 at 19:28, chenguanqiao chenguanqiao@kuaishou.com wrote:
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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
participants (2)
-
chenguanqiao
-
Simon Glass