[U-Boot] [PATCH v3] dm: core: add functions to get memory-mapped I/O addresses

Daniel Schwierzeck daniel.schwierzeck at gmail.com
Sun Apr 29 19:56:54 UTC 2018


From: Álvaro Fernández Rojas <noltari at gmail.com>

Signed-off-by: Álvaro Fernández Rojas <noltari at gmail.com>
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck at gmail.com>
Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck at gmail.com>

---
This replaces/updates patch 01/17 from patch series
https://patchwork.ozlabs.org/cover/889542/. The update fixes
some issues with Sandbox and adds unit-tests. The remaining patches
from the patch series can be applied as-is when this patch has been
committed.

Changes in v3:
- replace ioremap() with map_physmem()
- add unit tests
- fix checkpatch.pl warnings

Changes in v2:
- new patch

 drivers/core/fdtaddr.c | 15 +++++++++++++++
 drivers/core/read.c    | 15 +++++++++++++++
 include/dm/fdtaddr.h   | 22 ++++++++++++++++++++++
 include/dm/read.h      | 32 ++++++++++++++++++++++++++++++++
 test/dm/test-fdt.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 126 insertions(+)

diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c
index 9a3b4c312a..afea47bf7c 100644
--- a/drivers/core/fdtaddr.c
+++ b/drivers/core/fdtaddr.c
@@ -137,6 +137,21 @@ void *devfdt_get_addr_ptr(struct udevice *dev)
 	return (void *)(uintptr_t)devfdt_get_addr_index(dev, 0);
 }
 
+void *devfdt_remap_addr_index(struct udevice *dev, int index)
+{
+	fdt_addr_t addr = devfdt_get_addr(dev);
+
+	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);
+}
+
 void *devfdt_map_physmem(struct udevice *dev, unsigned long size)
 {
 	fdt_addr_t addr = devfdt_get_addr(dev);
diff --git a/drivers/core/read.c b/drivers/core/read.c
index 601d1322d6..615551b8f3 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -58,6 +58,16 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
 		return devfdt_get_addr_index(dev, index);
 }
 
+void *dev_remap_addr_index(struct udevice *dev, int index)
+{
+	fdt_addr_t addr = dev_read_addr_index(dev, index);
+
+	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);
@@ -70,6 +80,11 @@ void *dev_read_addr_ptr(struct udevice *dev)
 	return (addr == FDT_ADDR_T_NONE) ? NULL : map_sysmem(addr, 0);
 }
 
+void *dev_remap_addr(struct udevice *dev)
+{
+	return dev_remap_addr_index(dev, 0);
+}
+
 fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property,
 			      fdt_size_t *sizep)
 {
diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h
index c46f0e91d0..82fc5f931d 100644
--- a/include/dm/fdtaddr.h
+++ b/include/dm/fdtaddr.h
@@ -34,6 +34,28 @@ fdt_addr_t devfdt_get_addr(struct udevice *dev);
  */
 void *devfdt_get_addr_ptr(struct udevice *dev);
 
+/**
+ * devfdt_remap_addr() - Return pointer to the memory-mapped I/O address
+ *                           of the reg property of a device
+ *
+ * @dev: Pointer to a device
+ *
+ * @return Pointer to addr, or NULL if there is no such property
+ */
+void *devfdt_remap_addr(struct udevice *dev);
+
+/**
+ * devfdt_remap_addr_index() - Return indexed pointer to the memory-mapped
+ *                                 I/O address of the reg property of a device
+ * @index: the 'reg' property can hold a list of <addr, size> pairs
+ *	   and @index is used to select which one is required
+ *
+ * @dev: Pointer to a device
+ *
+ * @return Pointer to addr, or NULL if there is no such property
+ */
+void *devfdt_remap_addr_index(struct udevice *dev, int index);
+
 /**
  * devfdt_map_physmem() - Read device address from reg property of the
  *                     device node and map the address into CPU address
diff --git a/include/dm/read.h b/include/dm/read.h
index f14c7a7ba8..c826a2235c 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -113,6 +113,18 @@ int dev_read_size(struct udevice *dev, const char *propname);
  */
 fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
 
+/**
+ * dev_remap_addr_index() - Get the indexed reg property of a device
+ *                               as a memory-mapped I/O pointer
+ *
+ * @dev: Device to read from
+ * @index: the 'reg' property can hold a list of <addr, size> pairs
+ *	   and @index is used to select which one is required
+ *
+ * @return pointer or NULL if not found
+ */
+void *dev_remap_addr_index(struct udevice *dev, int index);
+
 /**
  * dev_read_addr() - Get the reg property of a device
  *
@@ -132,6 +144,16 @@ fdt_addr_t dev_read_addr(struct udevice *dev);
  */
 void *dev_read_addr_ptr(struct udevice *dev);
 
+/**
+ * dev_remap_addr() - Get the reg property of a device as a
+ *                         memory-mapped I/O pointer
+ *
+ * @dev: Device to read from
+ *
+ * @return pointer or NULL if not found
+ */
+void *dev_remap_addr(struct udevice *dev);
+
 /**
  * dev_read_addr_size() - get address and size from a device property
  *
@@ -483,6 +505,16 @@ static inline void *dev_read_addr_ptr(struct udevice *dev)
 	return devfdt_get_addr_ptr(dev);
 }
 
+static inline void *dev_remap_addr(struct udevice *dev)
+{
+	return devfdt_remap_addr(dev);
+}
+
+static inline void *dev_remap_addr_index(struct udevice *dev, int index)
+{
+	return devfdt_remap_addr_index(dev, index);
+}
+
 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 0d11bfdb2f..b104a6533e 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -462,3 +462,45 @@ static int dm_test_fdt_translation(struct unit_test_state *uts)
 	return 0;
 }
 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;
+	fdt_addr_t addr;
+	void *paddr;
+
+	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
+
+	addr = devfdt_get_addr(dev);
+	ut_asserteq(0x8000, addr);
+
+	paddr = map_physmem(addr, 0, MAP_NOCACHE);
+	ut_assertnonnull(paddr);
+	ut_asserteq_ptr(paddr, devfdt_remap_addr(dev));
+
+	return 0;
+}
+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_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(dev);
+	ut_asserteq(0x8000, addr);
+
+	paddr = map_physmem(addr, 0, MAP_NOCACHE);
+	ut_assertnonnull(paddr);
+	ut_asserteq_ptr(paddr, dev_remap_addr(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_fdt_remap_addr_live,
+	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_LIVE_TREE);
-- 
2.17.0



More information about the U-Boot mailing list