summaryrefslogtreecommitdiff
path: root/include/dm
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-05-19 02:08:59 (GMT)
committerSimon Glass <sjg@chromium.org>2017-06-01 13:03:07 (GMT)
commit38d21b418dd2207c89cdbdd6f38f7ee512c47da1 (patch)
tree5025446732089d079ad988f8407a935870c57cb0 /include/dm
parent9e51204527dcae59a326c51a71c9b80effd8db05 (diff)
downloadu-boot-38d21b418dd2207c89cdbdd6f38f7ee512c47da1.tar.xz
dm: core: Add livetree address functions
Add functions to access addresses in the device tree. These are brought in from Linux 4.10. Also fix up the header guard for fdtaddr.h to avoid confusion. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/dm')
-rw-r--r--include/dm/fdtaddr.h4
-rw-r--r--include/dm/of_addr.h64
2 files changed, 66 insertions, 2 deletions
diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h
index ef6e863..c46f0e9 100644
--- a/include/dm/fdtaddr.h
+++ b/include/dm/fdtaddr.h
@@ -8,8 +8,8 @@
* SPDX-License-Identifier: GPL-2.0+
*/
-#ifndef _DM_ADDR_H
-#define _DM_ADDR_H
+#ifndef _DM_FDTADDR_H
+#define _DM_FDTADDR_H
#include <fdtdec.h>
diff --git a/include/dm/of_addr.h b/include/dm/of_addr.h
new file mode 100644
index 0000000..25ca05b
--- /dev/null
+++ b/include/dm/of_addr.h
@@ -0,0 +1,64 @@
+/*
+ * Taken from Linux v4.9 drivers/of/address.c
+ *
+ * Modified for U-Boot
+ * Copyright (c) 2017 Google, Inc
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _DM_OF_ADDR_H
+#define _DM_OF_ADDR_H
+
+/**
+ * of_translate_address() - translate a device-tree address to a CPU address
+ *
+ * Translate an address from the device-tree into a CPU physical address,
+ * this walks up the tree and applies the various bus mappings on the way.
+ *
+ * Note: We consider that crossing any level with #size-cells == 0 to mean
+ * that translation is impossible (that is we are not dealing with a value
+ * that can be mapped to a cpu physical address). This is not really specified
+ * that way, but this is traditionally the way IBM at least do things
+ *
+ * @np: node to check
+ * @in_addr: pointer to input address
+ * @return translated address or OF_BAD_ADDR on error
+ */
+u64 of_translate_address(const struct device_node *no, const __be32 *in_addr);
+
+/**
+ * of_get_address() - obtain an address from a node
+ *
+ * Extract an address from a node, returns the region size and the address
+ * space flags too. The PCI version uses a BAR number instead of an absolute
+ * index.
+ *
+ * @np: Node to check
+ * @index: Index of address to read (0 = first)
+ * @size: place to put size on success
+ * @flags: place to put flags on success
+ * @return pointer to address which can be read
+ */
+const __be32 *of_get_address(const struct device_node *no, int index,
+ u64 *size, unsigned int *flags);
+
+struct resource;
+
+/**
+ * of_address_to_resource() - translate device tree address to resource
+ *
+ * Note that if your address is a PIO address, the conversion will fail if
+ * the physical address can't be internally converted to an IO token with
+ * pci_address_to_pio(), that is because it's either called to early or it
+ * can't be matched to any host bridge IO space
+ *
+ * @np: node to check
+ * @index: index of address to read (0 = first)
+ * @r: place to put resource information
+ * @return 0 if OK, -ve on error
+ */
+int of_address_to_resource(const struct device_node *no, int index,
+ struct resource *r);
+
+#endif