|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCHv3 2/6] plat/common: Introduce fdt_interrupt_cells helper to parse irq
From: Wei Chen <wei.chen@xxxxxxx>
This helper retrieves the number of cells by scanning "#interrupt-cells"
property of fdt. The #interrupt-cells property is used by the root of an
interrupt domain to define the number of <u32> values needed to encode
an interrupt specifier.
e.g.
intc@8000000 {
phandle = < 0x8001 >;
reg = < 0x00 0x8000000 0x00 0x10000 0x00 0x8010000 0x00
0x10000 >;
compatible = "arm,cortex-a15-gic";
ranges;
#size-cells = < 0x02 >;
#address-cells = < 0x02 >;
interrupt-controller;
#interrupt-cells = < 0x03 >;
We will use this helper to parse IRQ number for devices, like
timers and UARTs.
Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Signed-off-by: Jia He <justin.he@xxxxxxx>
---
plat/common/arm/irq_fdt.c | 42 +++++++++++++++++++++++++++++++
plat/common/include/arm/irq_fdt.h | 19 ++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/plat/common/arm/irq_fdt.c b/plat/common/arm/irq_fdt.c
index 4e9ecd6..9b4bd48 100644
--- a/plat/common/arm/irq_fdt.c
+++ b/plat/common/arm/irq_fdt.c
@@ -55,3 +55,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;
+}
diff --git a/plat/common/include/arm/irq_fdt.h
b/plat/common/include/arm/irq_fdt.h
index 73cfce0..4b76c98 100644
--- a/plat/common/include/arm/irq_fdt.h
+++ b/plat/common/include/arm/irq_fdt.h
@@ -54,3 +54,22 @@
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);
--
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 |