* [U-Boot] [PATCH 1/1] dm: core: add functions to get/remap I/O addresses by name @ 2018-11-29 19:57 Álvaro Fernández Rojas 2018-11-30 13:29 ` Daniel Schwierzeck 2018-12-01 19:31 ` [U-Boot] [PATCH v2 " Álvaro Fernández Rojas 0 siblings, 2 replies; 9+ messages in thread From: Álvaro Fernández Rojas @ 2018-11-29 19:57 UTC (permalink / raw) To: u-boot Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> --- 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(+) 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 <addr, size> 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 <addr, size> 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 <addr, size> 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) -- 2.11.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [U-Boot] [PATCH 1/1] dm: core: add functions to get/remap I/O addresses by name 2018-11-29 19:57 [U-Boot] [PATCH 1/1] dm: core: add functions to get/remap I/O addresses by name Álvaro Fernández Rojas @ 2018-11-30 13:29 ` Daniel Schwierzeck 2018-11-30 17:10 ` Álvaro Fernández Rojas 2018-12-01 19:31 ` [U-Boot] [PATCH v2 " Álvaro Fernández Rojas 1 sibling, 1 reply; 9+ messages in thread From: Daniel Schwierzeck @ 2018-11-30 13:29 UTC (permalink / raw) To: u-boot Am 29.11.18 um 20:57 schrieb Álvaro Fernández Rojas: > Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> > --- > 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(). > > 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 <addr, size> 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 <addr, size> 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 <addr, size> 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) > -- - Daniel -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181130/fefbd5df/attachment.sig> ^ permalink raw reply [flat|nested] 9+ messages in thread
* [U-Boot] [PATCH 1/1] dm: core: add functions to get/remap I/O addresses by name 2018-11-30 13:29 ` Daniel Schwierzeck @ 2018-11-30 17:10 ` Álvaro Fernández Rojas 0 siblings, 0 replies; 9+ messages in thread From: Álvaro Fernández Rojas @ 2018-11-30 17:10 UTC (permalink / raw) To: u-boot 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 <noltari@gmail.com> >> --- >> 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 <addr, size> 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 <addr, size> 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 <addr, size> 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) >> ^ permalink raw reply [flat|nested] 9+ messages in thread
* [U-Boot] [PATCH v2 1/1] dm: core: add functions to get/remap I/O addresses by name 2018-11-29 19:57 [U-Boot] [PATCH 1/1] dm: core: add functions to get/remap I/O addresses by name Álvaro Fernández Rojas 2018-11-30 13:29 ` Daniel Schwierzeck @ 2018-12-01 19:31 ` Álvaro Fernández Rojas 2018-12-03 18:20 ` Simon Glass 2018-12-03 18:37 ` [U-Boot] [PATCH v3 " Álvaro Fernández Rojas 1 sibling, 2 replies; 9+ messages in thread From: Álvaro Fernández Rojas @ 2018-12-01 19:31 UTC (permalink / raw) To: u-boot Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> --- v2: add remap tests arch/sandbox/dts/test.dts | 1 + drivers/core/fdtaddr.c | 10 ++++++ drivers/core/read.c | 20 ++++++++++++ include/dm/fdtaddr.h | 13 ++++++++ include/dm/read.h | 36 +++++++++++++++++++++ test/dm/test-fdt.c | 82 +++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 160 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 2c6b422312..df523b0c37 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -680,6 +680,7 @@ dev at 0,0 { compatible = "denx,u-boot-fdt-dummy"; reg = <0 0x0 0x1000>; + reg-names = "sandbox-dummy-0"; }; dev at 1,100 { 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 <addr, size> 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 <addr, size> 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 <addr, size> 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) diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index e43acb21d5..8b4cd9533b 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -490,7 +490,6 @@ static int dm_test_fdt_translation(struct unit_test_state *uts) } DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -/* Test devfdt_remap_addr_index() */ static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts) { struct udevice *dev; @@ -511,7 +510,46 @@ static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts) DM_TEST(dm_test_fdt_remap_addr_flat, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); -/* Test dev_remap_addr_index() */ +static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = devfdt_get_addr_index(dev, 0); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, devfdt_remap_addr_index(dev, 0)); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_index_flat, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); + +static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = devfdt_get_addr_name(dev, "sandbox-dummy-0"); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, devfdt_remap_addr_name(dev, "sandbox-dummy-0")); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_name_flat, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); + static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts) { struct udevice *dev; @@ -532,6 +570,46 @@ static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts) DM_TEST(dm_test_fdt_remap_addr_live, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = dev_read_addr_index(dev, 0); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, dev_remap_addr_index(dev, 0)); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_index_live, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = dev_read_addr_name(dev, "sandbox-dummy-0"); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, dev_remap_addr_name(dev, "sandbox-dummy-0")); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_name_live, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + static int dm_test_fdt_livetree_writing(struct unit_test_state *uts) { struct udevice *dev; -- 2.11.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [U-Boot] [PATCH v2 1/1] dm: core: add functions to get/remap I/O addresses by name 2018-12-01 19:31 ` [U-Boot] [PATCH v2 " Álvaro Fernández Rojas @ 2018-12-03 18:20 ` Simon Glass 2018-12-03 18:37 ` [U-Boot] [PATCH v3 " Álvaro Fernández Rojas 1 sibling, 0 replies; 9+ messages in thread From: Simon Glass @ 2018-12-03 18:20 UTC (permalink / raw) To: u-boot Hi Alvaro, On Sat, 1 Dec 2018 at 12:31, Álvaro Fernández Rojas <noltari@gmail.com> wrote: > Please add a commit message here. It is important to describe the motivation and effect for each commit. It should be the most enjoyable bit of each commit :-) Looks good otherwise. > Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> > --- > v2: add remap tests > > arch/sandbox/dts/test.dts | 1 + > drivers/core/fdtaddr.c | 10 ++++++ > drivers/core/read.c | 20 ++++++++++++ > include/dm/fdtaddr.h | 13 ++++++++ > include/dm/read.h | 36 +++++++++++++++++++++ > test/dm/test-fdt.c | 82 +++++++++++++++++++++++++++++++++++++++++++++-- > 6 files changed, 160 insertions(+), 2 deletions(-) > Regards, Simon ^ permalink raw reply [flat|nested] 9+ messages in thread
* [U-Boot] [PATCH v3 1/1] dm: core: add functions to get/remap I/O addresses by name 2018-12-01 19:31 ` [U-Boot] [PATCH v2 " Álvaro Fernández Rojas 2018-12-03 18:20 ` Simon Glass @ 2018-12-03 18:37 ` Álvaro Fernández Rojas 2018-12-03 20:18 ` Daniel Schwierzeck 2018-12-03 23:44 ` Simon Glass 1 sibling, 2 replies; 9+ messages in thread From: Álvaro Fernández Rojas @ 2018-12-03 18:37 UTC (permalink / raw) To: u-boot This functions allow us to get and remap I/O addresses by name, which is useful when there are multiple reg addresses indexed by reg-names property. This is needed in bmips dma/eth patch series, but can also be used on many other drivers. Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> --- v3: add commit message v2: add remap tests arch/sandbox/dts/test.dts | 1 + drivers/core/fdtaddr.c | 10 ++++++ drivers/core/read.c | 20 ++++++++++++ include/dm/fdtaddr.h | 13 ++++++++ include/dm/read.h | 36 +++++++++++++++++++++ test/dm/test-fdt.c | 82 +++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 160 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 252aa7b6b6..6722e18bc3 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -690,6 +690,7 @@ dev at 0,0 { compatible = "denx,u-boot-fdt-dummy"; reg = <0 0x0 0x1000>; + reg-names = "sandbox-dummy-0"; }; dev at 1,100 { 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 <addr, size> 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 <addr, size> 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 <addr, size> 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) diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 0fbd9be765..96d2528acc 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -490,7 +490,6 @@ static int dm_test_fdt_translation(struct unit_test_state *uts) } DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -/* Test devfdt_remap_addr_index() */ static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts) { struct udevice *dev; @@ -511,7 +510,46 @@ static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts) DM_TEST(dm_test_fdt_remap_addr_flat, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); -/* Test dev_remap_addr_index() */ +static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = devfdt_get_addr_index(dev, 0); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, devfdt_remap_addr_index(dev, 0)); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_index_flat, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); + +static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = devfdt_get_addr_name(dev, "sandbox-dummy-0"); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, devfdt_remap_addr_name(dev, "sandbox-dummy-0")); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_name_flat, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); + static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts) { struct udevice *dev; @@ -532,6 +570,46 @@ static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts) DM_TEST(dm_test_fdt_remap_addr_live, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = dev_read_addr_index(dev, 0); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, dev_remap_addr_index(dev, 0)); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_index_live, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = dev_read_addr_name(dev, "sandbox-dummy-0"); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, dev_remap_addr_name(dev, "sandbox-dummy-0")); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_name_live, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + static int dm_test_fdt_livetree_writing(struct unit_test_state *uts) { struct udevice *dev; -- 2.11.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [U-Boot] [PATCH v3 1/1] dm: core: add functions to get/remap I/O addresses by name 2018-12-03 18:37 ` [U-Boot] [PATCH v3 " Álvaro Fernández Rojas @ 2018-12-03 20:18 ` Daniel Schwierzeck 2018-12-03 23:44 ` Simon Glass 1 sibling, 0 replies; 9+ messages in thread From: Daniel Schwierzeck @ 2018-12-03 20:18 UTC (permalink / raw) To: u-boot Am 03.12.18 um 19:37 schrieb Álvaro Fernández Rojas: > This functions allow us to get and remap I/O addresses by name, which is useful when there are multiple reg addresses indexed by reg-names property. > This is needed in bmips dma/eth patch series, but can also be used on many > other drivers. > > Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> > --- > v3: add commit message > v2: add remap tests > > arch/sandbox/dts/test.dts | 1 + > drivers/core/fdtaddr.c | 10 ++++++ > drivers/core/read.c | 20 ++++++++++++ > include/dm/fdtaddr.h | 13 ++++++++ > include/dm/read.h | 36 +++++++++++++++++++++ > test/dm/test-fdt.c | 82 +++++++++++++++++++++++++++++++++++++++++++++-- > 6 files changed, 160 insertions(+), 2 deletions(-) > Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com> -- - Daniel ^ permalink raw reply [flat|nested] 9+ messages in thread
* [U-Boot] [PATCH v3 1/1] dm: core: add functions to get/remap I/O addresses by name 2018-12-03 18:37 ` [U-Boot] [PATCH v3 " Álvaro Fernández Rojas 2018-12-03 20:18 ` Daniel Schwierzeck @ 2018-12-03 23:44 ` Simon Glass 2018-12-05 23:10 ` sjg at google.com 1 sibling, 1 reply; 9+ messages in thread From: Simon Glass @ 2018-12-03 23:44 UTC (permalink / raw) To: u-boot On Mon, 3 Dec 2018 at 11:37, Álvaro Fernández Rojas <noltari@gmail.com> wrote: > > This functions allow us to get and remap I/O addresses by name, which is useful when there are multiple reg addresses indexed by reg-names property. > This is needed in bmips dma/eth patch series, but can also be used on many > other drivers. > > Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> > --- > v3: add commit message > v2: add remap tests > > arch/sandbox/dts/test.dts | 1 + > drivers/core/fdtaddr.c | 10 ++++++ > drivers/core/read.c | 20 ++++++++++++ > include/dm/fdtaddr.h | 13 ++++++++ > include/dm/read.h | 36 +++++++++++++++++++++ > test/dm/test-fdt.c | 82 +++++++++++++++++++++++++++++++++++++++++++++-- > 6 files changed, 160 insertions(+), 2 deletions(-) Reviewed-by: Simon Glass <sjg@chromium.org> ^ permalink raw reply [flat|nested] 9+ messages in thread
* [U-Boot] [PATCH v3 1/1] dm: core: add functions to get/remap I/O addresses by name 2018-12-03 23:44 ` Simon Glass @ 2018-12-05 23:10 ` sjg at google.com 0 siblings, 0 replies; 9+ messages in thread From: sjg at google.com @ 2018-12-05 23:10 UTC (permalink / raw) To: u-boot On Mon, 3 Dec 2018 at 11:37, Álvaro Fernández Rojas <noltari@gmail.com> wrote: > > This functions allow us to get and remap I/O addresses by name, which is useful when there are multiple reg addresses indexed by reg-names property. > This is needed in bmips dma/eth patch series, but can also be used on many > other drivers. > > Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> > --- > v3: add commit message > v2: add remap tests > > arch/sandbox/dts/test.dts | 1 + > drivers/core/fdtaddr.c | 10 ++++++ > drivers/core/read.c | 20 ++++++++++++ > include/dm/fdtaddr.h | 13 ++++++++ > include/dm/read.h | 36 +++++++++++++++++++++ > test/dm/test-fdt.c | 82 +++++++++++++++++++++++++++++++++++++++++++++-- > 6 files changed, 160 insertions(+), 2 deletions(-) Reviewed-by: Simon Glass <sjg@chromium.org> Applied to u-boot-dm/master, thanks! ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-12-05 23:10 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-11-29 19:57 [U-Boot] [PATCH 1/1] dm: core: add functions to get/remap I/O addresses by name Álvaro Fernández Rojas 2018-11-30 13:29 ` Daniel Schwierzeck 2018-11-30 17:10 ` Álvaro Fernández Rojas 2018-12-01 19:31 ` [U-Boot] [PATCH v2 " Álvaro Fernández Rojas 2018-12-03 18:20 ` Simon Glass 2018-12-03 18:37 ` [U-Boot] [PATCH v3 " Álvaro Fernández Rojas 2018-12-03 20:18 ` Daniel Schwierzeck 2018-12-03 23:44 ` Simon Glass 2018-12-05 23:10 ` sjg at google.com
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox