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

Re: [Minios-devel] [UNIKRAFT PATCHv4 3/9] plat/common: Introduce fdt_interrupt_cells helper to parse irq



Hello Jia He,

This patch seems fine.

Reviewed-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>

Thanks & Regards
Sharan

On 3/27/19 3:34 AM, Jia He wrote:
From: Wei Chen <wei.chen@xxxxxxx>

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.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Signed-off-by: Jia He <justin.he@xxxxxxx>
---
  plat/common/fdt.c         | 42 +++++++++++++++++++++++++++++++++++++++
  plat/common/include/fdt.h | 20 +++++++++++++++++++
  2 files changed, 62 insertions(+)

diff --git a/plat/common/fdt.c b/plat/common/fdt.c
index 47f7c74..916a263 100644
--- a/plat/common/fdt.c
+++ b/plat/common/fdt.c
@@ -57,3 +57,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/fdt.h b/plat/common/include/fdt.h
index 8ff88d7..afc4753 100644
--- a/plat/common/include/fdt.h
+++ b/plat/common/include/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


_______________________________________________
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®.