[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCHv4 6/9] 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/common/fdt.c         | 35 +++++++++++++++++++++++++++++++++++
 plat/common/include/fdt.h | 18 ++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/plat/common/fdt.c b/plat/common/fdt.c
index 1246dec..6cbedec 100644
--- a/plat/common/fdt.c
+++ b/plat/common/fdt.c
@@ -292,3 +292,38 @@ bail:
        return result;
 }
 
+int fdt_get_address(const void *fdt, int nodeoffset, uint32_t index,
+                       uint64_t *addr, uint64_t *size)
+{
+       int len, prop_addr, prop_size;
+       int naddr, nsize, term_size;
+       const void *regs;
+
+       naddr = fdt_address_cells_or_parent(fdt, nodeoffset);
+       if (naddr < 0 || naddr >= FDT_MAX_NCELLS)
+               return -FDT_ERR_BADNCELLS;
+
+       nsize = fdt_size_cells_or_parent(fdt, nodeoffset);
+       if (nsize < 0 || nsize >= FDT_MAX_NCELLS)
+               return -FDT_ERR_BADNCELLS;
+
+       /* Get reg content */
+       regs = fdt_getprop(fdt, nodeoffset, "reg", &len);
+       if (regs == NULL)
+               return -FDT_ERR_NOTFOUND;
+
+       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);
+
+       return 0;
+}
diff --git a/plat/common/include/fdt.h b/plat/common/include/fdt.h
index 969cd28..27f4f2c 100644
--- a/plat/common/include/fdt.h
+++ b/plat/common/include/fdt.h
@@ -110,4 +110,22 @@ int fdt_address_cells_or_parent(const void *fdt, int 
nodeoffset);
  */
 int fdt_size_cells_or_parent(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, int index,
+                       uint64_t *addr, uint64_t *size);
+
 #endif
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.