[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCHv7 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 b84c184..0b8c1d5 100644 --- a/plat/drivers/include/ofw/fdt.h +++ b/plat/drivers/include/ofw/fdt.h @@ -94,4 +94,22 @@ static inline uint64_t fdt_reg_read_number(const fdt32_t *regs, uint32_t size) return number; } + +/** + * 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 075e542..0ac6006 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 && \ @@ -220,3 +221,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 |