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

[Minios-devel] [UNIKRAFT PATCH 6/8] lib/fdt: Add fdt_get_interrupt helper



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

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
---
 lib/fdt/exportsyms.uk    |  1 +
 lib/fdt/fdt_interrupts.c | 23 +++++++++++++++++++++++
 lib/fdt/include/libfdt.h | 12 ++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/lib/fdt/exportsyms.uk b/lib/fdt/exportsyms.uk
index c893caf..bdef33c 100644
--- a/lib/fdt/exportsyms.uk
+++ b/lib/fdt/exportsyms.uk
@@ -63,3 +63,4 @@ fdt_overlay_apply
 fdt_getprop_u32_by_offset
 fdt_interrupt_cells
 fdt_get_address
+fdt_get_interrupt
diff --git a/lib/fdt/fdt_interrupts.c b/lib/fdt/fdt_interrupts.c
index 45ae963..705392f 100644
--- a/lib/fdt/fdt_interrupts.c
+++ b/lib/fdt/fdt_interrupts.c
@@ -87,3 +87,26 @@ int fdt_interrupt_cells(const void *fdt, int offset)
 
        return fdt_get_cells(fdt, "#interrupt-cells", intc_offset);
 }
+
+const void *fdt_get_interrupt(const void *fdt, int nodeoffset,
+                       int index, int *size)
+{
+       int nintr, len, term_size;
+       const void *regs;
+
+       nintr = fdt_interrupt_cells(fdt, nodeoffset);
+       if (nintr < 0 || nintr >= FDT_MAX_NCELLS)
+               return NULL;
+
+       /*
+        * Interrupt content must cover the index specific irq infomation.
+        */
+       regs = fdt_getprop(fdt, nodeoffset, "interrupts", &len);
+       term_size = (int)sizeof(fdt32_t) * nintr;
+       if (regs == NULL || len < term_size * (index + 1))
+               return NULL;
+
+       *size = nintr;
+
+       return regs + term_size * index;
+}
diff --git a/lib/fdt/include/libfdt.h b/lib/fdt/include/libfdt.h
index d43e710..7ee929f 100644
--- a/lib/fdt/include/libfdt.h
+++ b/lib/fdt/include/libfdt.h
@@ -1178,6 +1178,18 @@ int fdt_interrupt_cells(const void *fdt, int nodeoffset);
  */
 int fdt_get_address(const void *fdt, int nodeoffset, int index,
                        uint64_t *addr, uint64_t *size);
+/**
+ * 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 retrive
+ * @size: interrupt cell size in fdt32_t
+ *
+ * returns:
+ *      NULL on failed, non-NULL on success
+ */
+const void *fdt_get_interrupt(const void *fdt, int nodeoffset,
+                       int index, int *size);
 
 /**********************************************************************/
 /* Write-in-place functions                                           */
-- 
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®.