From: =?UTF-8?Q?=c3=81lvaro_Fern=c3=a1ndez_Rojas?= Date: Fri, 30 Nov 2018 18:10:19 +0100 Subject: [U-Boot] [PATCH 1/1] dm: core: add functions to get/remap I/O addresses by name In-Reply-To: <2599b07f-3f92-e9d1-c923-b04e4de8bf85@gmail.com> References: <20181129195745.20615-1-noltari@gmail.com> <2599b07f-3f92-e9d1-c923-b04e4de8bf85@gmail.com> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit To: u-boot@lists.denx.de Hi Daniel, El 30/11/2018 a las 14:29, Daniel Schwierzeck escribió: > > Am 29.11.18 um 20:57 schrieb Álvaro Fernández Rojas: >> Signed-off-by: Álvaro Fernández Rojas >> --- >> drivers/core/fdtaddr.c | 10 ++++++++++ >> drivers/core/read.c | 20 ++++++++++++++++++++ >> include/dm/fdtaddr.h | 13 +++++++++++++ >> include/dm/read.h | 36 ++++++++++++++++++++++++++++++++++++ >> 4 files changed, 79 insertions(+) > nice, but I guess Simon will insist on some tests in test/dm/test-fdt.c. > > You could copy and adapt dm_test_fdt_remap_addr_flat() and > dm_test_fdt_remap_addr_live(). Ok, I will send a new version with the suggested test. > >> diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c >> index bfd9580050..e113f1dd39 100644 >> --- a/drivers/core/fdtaddr.c >> +++ b/drivers/core/fdtaddr.c >> @@ -146,6 +146,16 @@ void *devfdt_remap_addr_index(struct udevice *dev, int index) >> return map_physmem(addr, 0, MAP_NOCACHE); >> } >> >> +void *devfdt_remap_addr_name(struct udevice *dev, const char *name) >> +{ >> + fdt_addr_t addr = devfdt_get_addr_name(dev, name); >> + >> + if (addr == FDT_ADDR_T_NONE) >> + return NULL; >> + >> + return map_physmem(addr, 0, MAP_NOCACHE); >> +} >> + >> void *devfdt_remap_addr(struct udevice *dev) >> { >> return devfdt_remap_addr_index(dev, 0); >> diff --git a/drivers/core/read.c b/drivers/core/read.c >> index 96766c7876..cdd78be03e 100644 >> --- a/drivers/core/read.c >> +++ b/drivers/core/read.c >> @@ -69,6 +69,26 @@ void *dev_remap_addr_index(struct udevice *dev, int index) >> return map_physmem(addr, 0, MAP_NOCACHE); >> } >> >> +fdt_addr_t dev_read_addr_name(struct udevice *dev, const char *name) >> +{ >> + int index = dev_read_stringlist_search(dev, "reg-names", name); >> + >> + if (index < 0) >> + return FDT_ADDR_T_NONE; >> + else >> + return dev_read_addr_index(dev, index); >> +} >> + >> +void *dev_remap_addr_name(struct udevice *dev, const char *name) >> +{ >> + fdt_addr_t addr = dev_read_addr_name(dev, name); >> + >> + if (addr == FDT_ADDR_T_NONE) >> + return NULL; >> + >> + return map_physmem(addr, 0, MAP_NOCACHE); >> +} >> + >> fdt_addr_t dev_read_addr(struct udevice *dev) >> { >> return dev_read_addr_index(dev, 0); >> diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h >> index 49a6ffd5f8..c171d9bc2f 100644 >> --- a/include/dm/fdtaddr.h >> +++ b/include/dm/fdtaddr.h >> @@ -56,6 +56,19 @@ void *devfdt_remap_addr(struct udevice *dev); >> void *devfdt_remap_addr_index(struct udevice *dev, int index); >> >> /** >> + * devfdt_remap_addr_name() - Get the reg property of a device, indexed by >> + * name, as a memory-mapped I/O pointer >> + * @name: the 'reg' property can hold a list of pairs, with the >> + * 'reg-names' property providing named-based identification. @index >> + * indicates the value to search for in 'reg-names'. >> + * >> + * @dev: Pointer to a device >> + * >> + * @return Pointer to addr, or NULL if there is no such property >> + */ >> +void *devfdt_remap_addr_name(struct udevice *dev, const char *name); >> + >> +/** >> * devfdt_map_physmem() - Read device address from reg property of the >> * device node and map the address into CPU address >> * space. >> diff --git a/include/dm/read.h b/include/dm/read.h >> index a27b8554fb..efcbee15ec 100644 >> --- a/include/dm/read.h >> +++ b/include/dm/read.h >> @@ -125,6 +125,31 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); >> void *dev_remap_addr_index(struct udevice *dev, int index); >> >> /** >> + * dev_read_addr_name() - Get the reg property of a device, indexed by name >> + * >> + * @dev: Device to read from >> + * @name: the 'reg' property can hold a list of pairs, with the >> + * 'reg-names' property providing named-based identification. @index >> + * indicates the value to search for in 'reg-names'. >> + * >> + * @return address or FDT_ADDR_T_NONE if not found >> + */ >> +fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name); >> + >> +/** >> + * dev_remap_addr_name() - Get the reg property of a device, indexed by name, >> + * as a memory-mapped I/O pointer >> + * >> + * @dev: Device to read from >> + * @name: the 'reg' property can hold a list of pairs, with the >> + * 'reg-names' property providing named-based identification. @index >> + * indicates the value to search for in 'reg-names'. >> + * >> + * @return pointer or NULL if not found >> + */ >> +void *dev_remap_addr_name(struct udevice *dev, const char* name); >> + >> +/** >> * dev_read_addr() - Get the reg property of a device >> * >> * @dev: Device to read from >> @@ -494,6 +519,12 @@ static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) >> return devfdt_get_addr_index(dev, index); >> } >> >> +static inline fdt_addr_t dev_read_addr_name(struct udevice *dev, >> + const char *name) >> +{ >> + return devfdt_get_addr_name(dev, name); >> +} >> + >> static inline fdt_addr_t dev_read_addr(struct udevice *dev) >> { >> return devfdt_get_addr(dev); >> @@ -514,6 +545,11 @@ static inline void *dev_remap_addr_index(struct udevice *dev, int index) >> return devfdt_remap_addr_index(dev, index); >> } >> >> +static inline void *dev_remap_addr_name(struct udevice *dev, const char *name) >> +{ >> + return devfdt_remap_addr_name(dev, name); >> +} >> + >> static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, >> const char *propname, >> fdt_size_t *sizep) >>