Message ID | 6487e8db-c954-9ee0-f6cf-88ac1fcfac96@gmail.com |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show |
Series | [v2,1/2] core: fdtaddr: add devfdt_get_addr_size_index_ptr function | expand |
Hi On Sat, Feb 25, 2023 at 12:43 PM Johan Jonker <jbx6244@gmail.com> wrote: > > Add devfdt_get_addr_size_index_ptr function with the same > functionality as devfdt_get_addr_size_index, but instead > a return pointer is given. > > Suggested-by: Michael Nazzareno Trimarchi <michael@amarulasolutions.com> > Signed-off-by: Johan Jonker <jbx6244@gmail.com> > --- > drivers/core/fdtaddr.c | 8 ++++++++ > include/dm/fdtaddr.h | 15 +++++++++++++++ > 2 files changed, 23 insertions(+) > > diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c > index 91bcd1a2..84bb8d8b 100644 > --- a/drivers/core/fdtaddr.c > +++ b/drivers/core/fdtaddr.c > @@ -122,6 +122,14 @@ fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, > #endif > } > > +void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index, > + fdt_size_t *size) > +{ > + fdt_addr_t addr = devfdt_get_addr_size_index(dev, index, size); > + > + return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr; > +} > + > fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name) > { > #if CONFIG_IS_ENABLED(OF_CONTROL) > diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h > index c9d2b27b..7fc3ea5c 100644 > --- a/include/dm/fdtaddr.h > +++ b/include/dm/fdtaddr.h > @@ -119,6 +119,21 @@ void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index); > fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, > fdt_size_t *size); > > +/** > + * devfdt_get_addr_size_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 > + * @size: Pointer to size varible - this function returns the size > + * specified in the 'reg' property here > + * > + * Return: Pointer to addr, or NULL if there is no such property > + */ > +void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index, > + fdt_size_t *size); > + > /** > * devfdt_get_addr_name() - Get the reg property of a device, indexed by name > * > -- > 2.20.1 > Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
Hi Johan On Sat, Feb 25, 2023 at 12:47 PM Michael Nazzareno Trimarchi <michael@amarulasolutions.com> wrote: > > Hi > > On Sat, Feb 25, 2023 at 12:43 PM Johan Jonker <jbx6244@gmail.com> wrote: > > > > Add devfdt_get_addr_size_index_ptr function with the same > > functionality as devfdt_get_addr_size_index, but instead > > a return pointer is given. > > > > Suggested-by: Michael Nazzareno Trimarchi <michael@amarulasolutions.com> > > Signed-off-by: Johan Jonker <jbx6244@gmail.com> > > --- > > drivers/core/fdtaddr.c | 8 ++++++++ > > include/dm/fdtaddr.h | 15 +++++++++++++++ > > 2 files changed, 23 insertions(+) > > > > diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c > > index 91bcd1a2..84bb8d8b 100644 [snip] > > +/** > > + * devfdt_get_addr_size_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 > > + * @size: Pointer to size varible - this function returns the size > > + * specified in the 'reg' property here > > + * > > + * Return: Pointer to addr, or NULL if there is no such property > > + */ > > +void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index, > > + fdt_size_t *size); > > + > > /** > > * devfdt_get_addr_name() - Get the reg property of a device, indexed by name > > * > > -- > > 2.20.1 > > git grep "== FDT_ADDR_T_NONE" I think using both function some of use cases can be rewritten now MIchael
diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index 91bcd1a2..84bb8d8b 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -122,6 +122,14 @@ fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, #endif } +void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index, + fdt_size_t *size) +{ + fdt_addr_t addr = devfdt_get_addr_size_index(dev, index, size); + + return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr; +} + fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name) { #if CONFIG_IS_ENABLED(OF_CONTROL) diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index c9d2b27b..7fc3ea5c 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -119,6 +119,21 @@ void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index); fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, fdt_size_t *size); +/** + * devfdt_get_addr_size_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 + * @size: Pointer to size varible - this function returns the size + * specified in the 'reg' property here + * + * Return: Pointer to addr, or NULL if there is no such property + */ +void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index, + fdt_size_t *size); + /** * devfdt_get_addr_name() - Get the reg property of a device, indexed by name *
Add devfdt_get_addr_size_index_ptr function with the same functionality as devfdt_get_addr_size_index, but instead a return pointer is given. Suggested-by: Michael Nazzareno Trimarchi <michael@amarulasolutions.com> Signed-off-by: Johan Jonker <jbx6244@gmail.com> --- drivers/core/fdtaddr.c | 8 ++++++++ include/dm/fdtaddr.h | 15 +++++++++++++++ 2 files changed, 23 insertions(+) -- 2.20.1