diff mbox series

[5/9] dm: core: Add a new API devfdt_get_addr_index_ptr()

Message ID 20210912031516.24885-5-bmeng.cn@gmail.com
State Accepted
Commit fb9bec8e8a7378d921478d5fbcc941e0fa80c01e
Delegated to: Andes
Headers show
Series [1/9] cache: sifive: Fix -Wint-to-pointer-cast warning | expand

Commit Message

Bin Meng Sept. 12, 2021, 3:15 a.m. UTC
At present there is only devfdt_get_addr_ptr() which only returns
the first <addr, size> pair in the 'reg' property. Add a new API
devfdt_get_addr_index_ptr() to return the indexed pointer.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 drivers/core/fdtaddr.c | 11 ++++++++---
 include/dm/fdtaddr.h   | 12 ++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)

Comments

Leo Liang Sept. 15, 2021, 7:21 a.m. UTC | #1
On Sun, Sep 12, 2021 at 11:15:12AM +0800, Bin Meng wrote:
> At present there is only devfdt_get_addr_ptr() which only returns
> the first <addr, size> pair in the 'reg' property. Add a new API
> devfdt_get_addr_index_ptr() to return the indexed pointer.
> 
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
> 
>  drivers/core/fdtaddr.c | 11 ++++++++---
>  include/dm/fdtaddr.h   | 12 ++++++++++++
>  2 files changed, 20 insertions(+), 3 deletions(-)

Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
Simon Glass Sept. 30, 2021, 4:09 a.m. UTC | #2
Hi Bin,

On Sat, 11 Sept 2021 at 21:15, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> At present there is only devfdt_get_addr_ptr() which only returns
> the first <addr, size> pair in the 'reg' property. Add a new API
> devfdt_get_addr_index_ptr() to return the indexed pointer.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
>  drivers/core/fdtaddr.c | 11 ++++++++---
>  include/dm/fdtaddr.h   | 12 ++++++++++++
>  2 files changed, 20 insertions(+), 3 deletions(-)

Please do update the tests for this new function.
diff mbox series

Patch

diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c
index 4ffbd6b2eb..8dbb06ab03 100644
--- a/drivers/core/fdtaddr.c
+++ b/drivers/core/fdtaddr.c
@@ -93,6 +93,13 @@  fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
 #endif
 }
 
+void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index)
+{
+	fdt_addr_t addr = devfdt_get_addr_index(dev, index);
+
+	return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr;
+}
+
 fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index,
 				      fdt_size_t *size)
 {
@@ -155,9 +162,7 @@  fdt_addr_t devfdt_get_addr(const struct udevice *dev)
 
 void *devfdt_get_addr_ptr(const struct udevice *dev)
 {
-	fdt_addr_t addr = devfdt_get_addr_index(dev, 0);
-
-	return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr;
+	return devfdt_get_addr_index_ptr(dev, 0);
 }
 
 void *devfdt_remap_addr_index(const struct udevice *dev, int index)
diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h
index a4fda581a7..d2c1994291 100644
--- a/include/dm/fdtaddr.h
+++ b/include/dm/fdtaddr.h
@@ -92,6 +92,18 @@  void *devfdt_map_physmem(const struct udevice *dev, unsigned long size);
  */
 fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index);
 
+/**
+ * devfdt_get_addr_index_ptr() - Return indexed pointer to the address of the
+ *                               reg property of a device
+ *
+ * @dev: Pointer to a device
+ * @index: the 'reg' property can hold a list of <addr, size> pairs
+ *	   and @index is used to select which one is required
+ *
+ * @return Pointer to addr, or NULL if there is no such property
+ */
+void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index);
+
 /**
  * devfdt_get_addr_size_index() - Get the indexed reg property of a device
  *