[U-Boot] [RESEND PATCH v2 3/4] core: Add {ofnode, dev}_translate_address functions
Mario Six
mario.six at gdsys.cc
Mon Jan 15 10:07:19 UTC 2018
Reviewed-by: Simon Glass <sjg at chromium.org>
Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
v1 -> v2:
None
---
drivers/core/ofnode.c | 8 ++++++++
drivers/core/read.c | 5 +++++
include/dm/ofnode.h | 13 +++++++++++++
include/dm/read.h | 17 +++++++++++++++++
4 files changed, 43 insertions(+)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index ebcf64d867..0b32f9b085 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -644,3 +644,11 @@ int ofnode_read_resource_byname(ofnode node, const char *name,
return ofnode_read_resource(node, index, res);
}
+
+u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr)
+{
+ if (ofnode_is_np(node))
+ return of_translate_address(ofnode_to_np(node), in_addr);
+ else
+ return fdt_translate_address(gd->fdt_blob, ofnode_to_offset(node), in_addr);
+}
diff --git a/drivers/core/read.c b/drivers/core/read.c
index 08955f81fc..19207a3906 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -188,3 +188,8 @@ int dev_read_resource_byname(struct udevice *dev, const char *name,
{
return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
}
+
+u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
+{
+ return ofnode_translate_address(dev_ofnode(dev), in_addr);
+}
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 8b9932a569..c359a60f95 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -652,4 +652,17 @@ int ofnode_read_resource_byname(ofnode node, const char *name,
ofnode_valid(node); \
node = ofnode_next_subnode(node))
+/**
+ * ofnode_translate_address() - Tranlate a device-tree address
+ *
+ * Translate an address from the device-tree into a CPU physical address. This
+ * function walks up the tree and applies the various bus mappings along the
+ * way.
+ *
+ * @ofnode: Device tree node giving the context in which to translate the
+ * address
+ * @in_addr: pointer to the address to translate
+ * @return the translated address; OF_BAD_ADDR on error
+ */
+u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
#endif
diff --git a/include/dm/read.h b/include/dm/read.h
index 8114037e97..2551e5f0dc 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -410,6 +410,18 @@ int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
int dev_read_resource_byname(struct udevice *dev, const char *name,
struct resource *res);
+/**
+ * dev_translate_address() - Tranlate a device-tree address
+ *
+ * Translate an address from the device-tree into a CPU physical address. This
+ * function walks up the tree and applies the various bus mappings along the
+ * way.
+ *
+ * @dev: device giving the context in which to translate the address
+ * @in_addr: pointer to the address to translate
+ * @return the translated address; OF_BAD_ADDR on error
+ */
+u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
static inline int dev_read_u32_default(struct udevice *dev,
@@ -582,6 +594,11 @@ static inline int dev_read_resource_byname(struct udevice *dev,
return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
}
+static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
+{
+ return ofnode_translate_address(dev_ofnode(dev), in_addr);
+}
+
#endif /* CONFIG_DM_DEV_READ_INLINE */
/**
--
2.11.0
More information about the U-Boot
mailing list