[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCHv7 3/8] plat/common: Introduce fdt_interrupt_cells helper to parse irq
From: Wei Chen <wei.chen@xxxxxxx> This helper retrieves the number of cells by scan "#interrupt-cells" property of fdt. We will use this helper to parse IRQ number for devices, like timers and UARTs. Reviewed-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> Signed-off-by: Wei Chen <wei.chen@xxxxxxx> Signed-off-by: Jia He <justin.he@xxxxxxx> --- plat/drivers/include/ofw/fdt.h | 20 ++++++++++++++++ plat/drivers/ofw/fdt.c | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/plat/drivers/include/ofw/fdt.h b/plat/drivers/include/ofw/fdt.h index c202671..7d40fba 100644 --- a/plat/drivers/include/ofw/fdt.h +++ b/plat/drivers/include/ofw/fdt.h @@ -56,4 +56,24 @@ int fdt_getprop_u32_by_offset(const void *fdt, int nodeoffset, const char *name, uint32_t *out); +/** + * fdt_interrupt_cells - retrieve the number of cells needed to encode an + * interrupt source + * @fdt: pointer to the device tree blob + * @nodeoffset: offset of the node to find the interrupt for. + * + * When the node has a valid #interrupt-cells property, returns its value. + * + * returns: + * 0 <= n < FDT_MAX_NCELLS, on success + * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid + * #interrupt-cells property + * -FDT_ERR_BADMAGIC, + * -FDT_ERR_BADVERSION, + * -FDT_ERR_BADSTATE, + * -FDT_ERR_BADSTRUCTURE, + * -FDT_ERR_TRUNCATED, standard meanings + */ +int fdt_interrupt_cells(const void *fdt, int nodeoffset); + #endif diff --git a/plat/drivers/ofw/fdt.c b/plat/drivers/ofw/fdt.c index e23b7a3..a596df3 100644 --- a/plat/drivers/ofw/fdt.c +++ b/plat/drivers/ofw/fdt.c @@ -58,3 +58,45 @@ int fdt_getprop_u32_by_offset(const void *fdt, int offset, return -FDT_ERR_NOTFOUND; } + +static int fdt_find_irq_parent_offset(const void *fdt, int offset) +{ + uint32_t irq_parent; + + do { + /* Find the interrupt-parent phandle */ + if (!fdt_getprop_u32_by_offset(fdt, offset, + "interrupt-parent", &irq_parent)) + break; + + /* Try to find in parent node */ + offset = fdt_parent_offset(fdt, offset); + } while (offset >= 0); + + if (offset < 0) + return offset; + + /* Get interrupt parent node by phandle */ + return fdt_node_offset_by_phandle(fdt, irq_parent); +} + +int fdt_interrupt_cells(const void *fdt, int offset) +{ + int intc_offset; + int val; + int ret; + + intc_offset = fdt_find_irq_parent_offset(fdt, offset); + if (intc_offset < 0) + return intc_offset; + + ret = fdt_getprop_u32_by_offset(fdt, intc_offset, "#interrupt-cells", + (uint32_t *)&val); + if (ret < 0) + return ret; + + if ((val <= 0) || (val > FDT_MAX_NCELLS)) + return -FDT_ERR_BADNCELLS; + + return val; +} -- 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 |