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

[Minios-devel] [UNIKRAFT PATCHv6 7/8] plat/common: Introduce fdt_get_interrupt helper



From: Wei Chen <wei.chen@xxxxxxx>

This helper will be used very frequently for devices to
get their interrupts.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Signed-off-by: Jia He <justin.he@xxxxxxx>
---
v5->v6: fix compilation warning for unsigned/signed comparision

 plat/drivers/include/ofw/fdt.h | 20 ++++++++++++++++++++
 plat/drivers/ofw/fdt.c         | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/plat/drivers/include/ofw/fdt.h b/plat/drivers/include/ofw/fdt.h
index 5e2eb63..f35b4bc 100644
--- a/plat/drivers/include/ofw/fdt.h
+++ b/plat/drivers/include/ofw/fdt.h
@@ -122,4 +122,24 @@ int fdt_get_address(const void *fdt, int nodeoffset, 
uint32_t index,
 int fdt_node_offset_by_compatible_list(const void *fdt, int startoffset,
                                        const char * const compatibles[]);
 
+/**
+ * fdt_get_interrupt - retrieve device interrupt of a given index
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node to find the address for
+ * @index: the index of interrupt we want to retrieve
+ * @size: interrupt cell size in fdt32_t
+ * @prop: return the pointer to property
+ * returns:
+ *     0 on success , < 0 on failed
+ *     -FDT_ERR_NOTFOUND, node does not have named property
+ *     -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
+ *     -FDT_ERR_BADMAGIC,
+ *     -FDT_ERR_BADVERSION,
+ *     -FDT_ERR_BADSTATE,
+ *     -FDT_ERR_BADSTRUCTURE,
+ *     -FDT_ERR_TRUNCATED, standard meanings
+ */
+int fdt_get_interrupt(const void *fdt, int nodeoffset,
+                               uint32_t index, int *size, fdt32_t **prop);
+
 #endif
diff --git a/plat/drivers/ofw/fdt.c b/plat/drivers/ofw/fdt.c
index b4debb9..4cf34e1 100644
--- a/plat/drivers/ofw/fdt.c
+++ b/plat/drivers/ofw/fdt.c
@@ -294,3 +294,36 @@ int fdt_node_offset_by_compatible_list(const void *fdt, 
int startoffset,
 
        return -FDT_ERR_NOTFOUND;
 }
+
+int fdt_get_interrupt(const void *fdt, int nodeoffset,
+                       uint32_t index, int *size, fdt32_t **prop)
+{
+       int nintr, len, term_size;
+       const void *regs;
+
+       UK_ASSERT(size && prop);
+
+       nintr = fdt_interrupt_cells(fdt, nodeoffset);
+       if (nintr < 0 || nintr >= FDT_MAX_NCELLS)
+               return -FDT_ERR_BADNCELLS;
+
+       /* "interrupts-extended" is not supported */
+       regs = fdt_getprop(fdt, nodeoffset, "interrupts-extended", &len);
+       if (regs) {
+               uk_pr_warn("interrupts multiple parents is not supported\n");
+               return -FDT_ERR_INTERNAL;
+       }
+
+       /*
+        * Interrupt content must cover the index specific irq information.
+        */
+       regs = fdt_getprop(fdt, nodeoffset, "interrupts", &len);
+       term_size = sizeof(fdt32_t) * nintr;
+       if (regs == NULL || (uint32_t)len < term_size * (index + 1))
+               return -FDT_ERR_NOTFOUND;
+
+       *size = nintr;
+       *prop = (fdt32_t *)(regs + term_size * index);
+
+       return 0;
+}
-- 
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®.