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. Use map_sysmem() function as cast for the return. Make same fix for devfdt_get_addr_index_ptr() function.
Suggested-by: Michael Nazzareno Trimarchi <mich...@amarulasolutions.com> Signed-off-by: Johan Jonker <jbx6...@gmail.com> Reviewed-by: Michael Trimarchi <mich...@amarulasolutions.com> Reviewed-by: Simon Glass <s...@chromium.org> --- Changed V7: use map_sysmem() Changed V5: fix spelling use tabs --- drivers/core/fdtaddr.c | 17 ++++++++++++++++- include/dm/fdtaddr.h | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index 91bcd1a2..546db675 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -12,6 +12,7 @@ #include <dm.h> #include <fdt_support.h> #include <log.h> +#include <mapmem.h> #include <asm/global_data.h> #include <asm/io.h> #include <dm/device-internal.h> @@ -97,7 +98,10 @@ 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; + if (addr == FDT_ADDR_T_NONE) + return NULL; + + return map_sysmem(addr, 0); } fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, @@ -122,6 +126,17 @@ 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); + + if (addr == FDT_ADDR_T_NONE) + return NULL; + + return map_sysmem(addr, 0); +} + 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..dcdc1913 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -111,7 +111,7 @@ void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index); * @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 + * @size: Pointer to size variable - this function returns the size * specified in the 'reg' property here * * Return: addr @@ -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 variable - 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