|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCHv5 5/8] plat/common: Introduce fdt_get_address helper
From: Wei Chen <wei.chen@xxxxxxx>
This helper will be used very frequently for device libraries
to parse their addresses. Introduce this helper to avoid using
fdt_address_cells and fdt_size_cells everywhere.
Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Signed-off-by: Jianyong Wu <jianyong.wu@xxxxxxx>
Signed-off-by: Jia He <justin.he@xxxxxxx>
---
plat/drivers/include/ofw/fdt.h | 18 +++++++++++++++
plat/drivers/ofw/fdt.c | 42 ++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/plat/drivers/include/ofw/fdt.h b/plat/drivers/include/ofw/fdt.h
index 9ef3c8e..c9ae8e5 100644
--- a/plat/drivers/include/ofw/fdt.h
+++ b/plat/drivers/include/ofw/fdt.h
@@ -78,4 +78,22 @@ int fdt_getprop_u32_by_offset(const void *fdt, int
nodeoffset,
*/
int fdt_interrupt_cells(const void *fdt, int nodeoffset);
+/**
+ * fdt_get_address - retrieve device address of a given index
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node to find the address for.
+ * @index: index of region
+ * @addr: return the region address
+ * @size: return the region size
+ *
+ * returns:
+ * 0, on success
+ * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
+ * address property
+ * -FDT_ERR_NOTFOUND, if the node doesn't have address property
+ * -FDT_ERR_NOSPACE, if the node doesn't have address for index
+ */
+int fdt_get_address(const void *fdt, int nodeoffset, uint32_t index,
+ uint64_t *addr, uint64_t *size);
+
#endif
diff --git a/plat/drivers/ofw/fdt.c b/plat/drivers/ofw/fdt.c
index d891ab3..b72c1df 100644
--- a/plat/drivers/ofw/fdt.c
+++ b/plat/drivers/ofw/fdt.c
@@ -38,6 +38,7 @@
#include <ofw/fdt.h>
#include <uk/print.h>
+#include <uk/assert.h>
#define FDT_MAX_ADDR_CELLS FDT_MAX_NCELLS
#define FDT_CHECK_COUNTS(na, ns) ((na) > 0 && (na) <= FDT_MAX_ADDR_CELLS && \
@@ -237,3 +238,44 @@ bail:
return result;
}
+int fdt_get_address(const void *fdt, int nodeoffset, uint32_t index,
+ uint64_t *addr, uint64_t *size)
+{
+ int parent;
+ int len, prop_addr, prop_size;
+ int naddr, nsize, term_size;
+ const void *regs;
+
+ UK_ASSERT(addr && size);
+
+ /* Get address,size cell from parent */
+ parent = fdt_parent_offset(fdt, nodeoffset);
+ naddr = fdt_address_cells(fdt, parent);
+ if (naddr < 0 || naddr >= FDT_MAX_NCELLS)
+ return naddr;
+
+ nsize = fdt_size_cells(fdt, parent);
+ if (nsize < 0 || nsize >= FDT_MAX_NCELLS)
+ return nsize;
+
+ /* Get reg content */
+ regs = fdt_getprop(fdt, nodeoffset, "reg", &len);
+ if (regs == NULL)
+ return len;
+
+ term_size = sizeof(fdt32_t) * (nsize + naddr);
+ prop_addr = term_size * index;
+ prop_size = prop_addr + sizeof(fdt32_t) * naddr;
+
+ /* The reg content must cover the reg term[index] at least */
+ if (len < (prop_addr + term_size))
+ return -FDT_ERR_NOSPACE;
+
+ *size = fdt_reg_read_number(regs + prop_size, nsize);
+ /* Handle ranges property, currently only 1:1 mapping is supported */
+ *addr = fdt_translate_address_by_ranges(fdt, nodeoffset,
+ regs + prop_addr);
+ if (*addr == FDT_BAD_ADDR)
+ return -FDT_ERR_NOTFOUND;
+ return 0;
+}
--
2.17.1
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |