From e42c4d6d90c60f6b7fe01e88f458782c42cee8c9 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 27 Sep 2023 15:33:30 +0200 Subject: core: fix doc comments of dev_read_addr*() and related functions - The dev_read_addr_name*() family of functions has no "index" argument, doc comments should refer to "name" - Specify the error return for several devfdt_get_addr*() functions Signed-off-by: Matthias Schiffer Reviewed-by: Simon Glass --- include/dm/fdtaddr.h | 12 ++++++------ include/dm/read.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'include/dm') diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index 6d2fa8f1044..5e8eafc203a 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -19,7 +19,7 @@ struct udevice; * * @dev: Pointer to a device * - * Return: addr + * Return: Address, or FDT_ADDR_T_NONE if there is no such property */ fdt_addr_t devfdt_get_addr(const struct udevice *dev); @@ -59,7 +59,7 @@ void *devfdt_remap_addr_index(const 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 + * 'reg-names' property providing named-based identification. @name * indicates the value to search for in 'reg-names'. * * @dev: Pointer to a device @@ -87,7 +87,7 @@ void *devfdt_map_physmem(const struct udevice *dev, unsigned long size); * @index: the 'reg' property can hold a list of pairs * and @index is used to select which one is required * - * Return: addr + * Return: Address, or FDT_ADDR_T_NONE if there is no such property */ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index); @@ -114,7 +114,7 @@ void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index); * @size: Pointer to size variable - this function returns the size * specified in the 'reg' property here * - * Return: addr + * Return: Address, or FDT_ADDR_T_NONE if there is no such property */ fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, fdt_size_t *size); @@ -139,7 +139,7 @@ void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index, * * @dev: Pointer to a device * @name: the 'reg' property can hold a list of pairs, with the - * 'reg-names' property providing named-based identification. @index + * 'reg-names' property providing named-based identification. @name * indicates the value to search for in 'reg-names'. * * Return: addr @@ -154,7 +154,7 @@ fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name); * * @dev: Pointer to a device * @name: the 'reg' property can hold a list of pairs, with the - * 'reg-names' property providing named-based identification. @index + * 'reg-names' property providing named-based identification. @name * indicates the value to search for in 'reg-names'. * @size: Pointer to size variable - this function returns the size * specified in the 'reg' property here diff --git a/include/dm/read.h b/include/dm/read.h index 3c2eea6f0c4..517795cc206 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -277,7 +277,7 @@ void *dev_remap_addr_index(const struct udevice *dev, int index); * * @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 + * 'reg-names' property providing named-based identification. @name * indicates the value to search for in 'reg-names'. * * Return: address or FDT_ADDR_T_NONE if not found @@ -289,7 +289,7 @@ fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *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 + * 'reg-names' property providing named-based identification. @name * indicates the value to search for in 'reg-names'. * @size: place to put size value (on success) * @@ -304,7 +304,7 @@ fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *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 + * 'reg-names' property providing named-based identification. @name * indicates the value to search for in 'reg-names'. * * Return: pointer or NULL if not found -- cgit v1.2.3 From e367305769d091bc8a0026d69136eb77fd055784 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 27 Sep 2023 15:33:31 +0200 Subject: core: return FDT_ADDR_T_NONE from devfdt_get_addr_[size_]name() on errors Checking for the error cast to fdt_addr_t is rather awkward - IS_ERR() can be used, but it's not really made to be used on fdt_addr_t, which may not even be the same size as a native pointer. Most places in U-Boot only check for FDT_ADDR_T_NONE; let's adjust the error return to match the expectation. Signed-off-by: Matthias Schiffer Reviewed-by: Simon Glass --- drivers/core/fdtaddr.c | 4 ++-- include/dm/fdtaddr.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'include/dm') diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index b79d138c419..0f4eff6707d 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -145,7 +145,7 @@ fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name) index = fdt_stringlist_search(gd->fdt_blob, dev_of_offset(dev), "reg-names", name); if (index < 0) - return index; + return FDT_ADDR_T_NONE; return devfdt_get_addr_index(dev, index); #else @@ -162,7 +162,7 @@ fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, index = fdt_stringlist_search(gd->fdt_blob, dev_of_offset(dev), "reg-names", name); if (index < 0) - return index; + return FDT_ADDR_T_NONE; return devfdt_get_addr_size_index(dev, index, size); #else diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index 5e8eafc203a..c577d4369ce 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -142,7 +142,7 @@ void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index, * 'reg-names' property providing named-based identification. @name * indicates the value to search for in 'reg-names'. * - * Return: addr + * Return: Address, or FDT_ADDR_T_NONE if there is no such property */ fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name); @@ -159,7 +159,7 @@ fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name); * @size: Pointer to size variable - this function returns the size * specified in the 'reg' property here * - * Return: addr + * Return: Address, or FDT_ADDR_T_NONE if there is no such property */ fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size); -- cgit v1.2.3 From bc8fa1cbfd429138ebd894a170ce36b07f86b150 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 27 Sep 2023 15:33:32 +0200 Subject: core: introduce dev_read_addr_name[_size]_ptr() functions Same as dev_read_addr_name[_size](), but returns a pointer, cast through map_sysmem(). Signed-off-by: Matthias Schiffer Reviewed-by: Simon Glass --- drivers/core/fdtaddr.c | 21 +++++++++++++++++++++ drivers/core/read.c | 21 +++++++++++++++++++++ include/dm/fdtaddr.h | 31 +++++++++++++++++++++++++++++++ include/dm/read.h | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) (limited to 'include/dm') diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index 0f4eff6707d..8e774d49ce6 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -153,6 +153,16 @@ fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name) #endif } +void *devfdt_get_addr_name_ptr(const 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_sysmem(addr, 0); +} + fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size) { @@ -170,6 +180,17 @@ fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, #endif } +void *devfdt_get_addr_size_name_ptr(const struct udevice *dev, + const char *name, fdt_size_t *size) +{ + fdt_addr_t addr = devfdt_get_addr_size_name(dev, name, size); + + if (addr == FDT_ADDR_T_NONE) + return NULL; + + return map_sysmem(addr, 0); +} + fdt_addr_t devfdt_get_addr(const struct udevice *dev) { return devfdt_get_addr_index(dev, 0); diff --git a/drivers/core/read.c b/drivers/core/read.c index 419013451f0..1a4a95cddea 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -181,6 +181,16 @@ fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name) return dev_read_addr_index(dev, index); } +void *dev_read_addr_name_ptr(const 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_sysmem(addr, 0); +} + fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size) { @@ -192,6 +202,17 @@ fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, return dev_read_addr_size_index(dev, index, size); } +void *dev_read_addr_size_name_ptr(const struct udevice *dev, const char *name, + fdt_size_t *size) +{ + fdt_addr_t addr = dev_read_addr_size_name(dev, name, size); + + if (addr == FDT_ADDR_T_NONE) + return NULL; + + return map_sysmem(addr, 0); +} + void *dev_remap_addr_name(const struct udevice *dev, const char *name) { fdt_addr_t addr = dev_read_addr_name(dev, name); diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index c577d4369ce..bf8132deb86 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -146,6 +146,19 @@ void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index, */ fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name); +/** + * devfdt_get_addr_name_ptr() - Get the reg property of a device as a pointer, + * indexed by name + * + * @dev: Pointer to a device + * @name: the 'reg' property can hold a list of pairs, with the + * 'reg-names' property providing named-based identification. @name + * indicates the value to search for in 'reg-names'. + * + * Return: Pointer to addr, or NULL if there is no such property + */ +void *devfdt_get_addr_name_ptr(const struct udevice *dev, const char *name); + /** * devfdt_get_addr_size_name() - Get the reg property and its size for a device, * indexed by name @@ -164,6 +177,24 @@ fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name); fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size); +/** + * devfdt_get_addr_size_name_ptr() - Get the reg property for a device as a + * pointer, indexed by name + * + * Returns the address and size specified in the 'reg' property of a device. + * + * @dev: Pointer to a device + * @name: the 'reg' property can hold a list of pairs, with the + * 'reg-names' property providing named-based identification. @name + * indicates the value to search for in 'reg-names'. + * @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_name_ptr(const struct udevice *dev, + const char *name, fdt_size_t *size); + /** * devfdt_get_addr_pci() - Read an address and handle PCI address translation * diff --git a/include/dm/read.h b/include/dm/read.h index 517795cc206..894bc698bb4 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -284,6 +284,19 @@ void *dev_remap_addr_index(const struct udevice *dev, int index); */ fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name); +/** + * dev_read_addr_name_ptr() - Get the reg property of a device as a pointer, + * 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. @name + * indicates the value to search for in 'reg-names'. + * + * Return: pointer or NULL if not found + */ +void *dev_read_addr_name_ptr(const struct udevice *dev, const char *name); + /** * dev_read_addr_size_name() - Get the reg property of a device, indexed by name * @@ -298,6 +311,21 @@ fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name); fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size); +/** + * dev_read_addr_size_name_ptr() - Get the reg property of a device as a pointer, + * 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. @name + * indicates the value to search for in 'reg-names'. + * @size: place to put size value (on success) + * + * Return: pointer or NULL if not found + */ +void *dev_read_addr_size_name_ptr(const struct udevice *dev, const char *name, + fdt_size_t *size); + /** * dev_remap_addr_name() - Get the reg property of a device, indexed by name, * as a memory-mapped I/O pointer @@ -980,6 +1008,12 @@ static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev, return devfdt_get_addr_name(dev, name); } +static inline void *dev_read_addr_name_ptr(const struct udevice *dev, + const char *name) +{ + return devfdt_get_addr_name_ptr(dev, name); +} + static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size) @@ -987,6 +1021,13 @@ static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, return devfdt_get_addr_size_name(dev, name, size); } +static inline void *dev_read_addr_size_name_ptr(const struct udevice *dev, + const char *name, + fdt_size_t *size) +{ + return devfdt_get_addr_size_name_ptr(dev, name, size); +} + static inline fdt_addr_t dev_read_addr(const struct udevice *dev) { return devfdt_get_addr(dev); -- cgit v1.2.3