[PATCH 3/5] core: introduce dev_read_addr_name[_size]_ptr() functions

Matthias Schiffer matthias.schiffer at ew.tq-group.com
Wed Sep 27 15:33:32 CEST 2023


Same as dev_read_addr_name[_size](), but returns a pointer, cast
through map_sysmem().

Signed-off-by: Matthias Schiffer <matthias.schiffer at ew.tq-group.com>
---
 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(+)

diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c
index 426bb762754..560b0b634a2 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 49066b59cda..0908321c846 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 d3ad77faebf..750ca0076ed 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 <addr, size> 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 <addr, size> 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 da7732a170f..c936645e0a8 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 <addr, size> 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 <addr, size> 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
@@ -979,6 +1007,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)
@@ -986,6 +1020,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);
-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/



More information about the U-Boot mailing list