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

[Minios-devel] [UNIKRAFT PATCHv8 2/7] plat/common: Introduce fdt_interrupt_cells helper to parse irq



From: Jianyong Wu <jianyong.wu@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.

This also enable the build support for unikraft internal fdt interfaces.

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 | 58 ++++++++++++++++++++++++
 plat/drivers/ofw/fdt.c         | 82 ++++++++++++++++++++++++++++++++++
 plat/kvm/Makefile.uk           |  2 +
 3 files changed, 142 insertions(+)
 create mode 100644 plat/drivers/include/ofw/fdt.h
 create mode 100644 plat/drivers/ofw/fdt.c

diff --git a/plat/drivers/include/ofw/fdt.h b/plat/drivers/include/ofw/fdt.h
new file mode 100644
index 0000000..290abd5
--- /dev/null
+++ b/plat/drivers/include/ofw/fdt.h
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Wei Chen <Wei.Chen@xxxxxxx>
+ *          Jianyong Wu <Jianyong.Wu@xxxxxxx>
+ *
+ * Copyright (c) 2018, Arm Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#ifndef _PLAT_DRIVER_OFW_FDT_H
+#define _PLAT_DRIVER_OFW_FDT_H
+
+/**
+ * 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
new file mode 100644
index 0000000..73a361f
--- /dev/null
+++ b/plat/drivers/ofw/fdt.c
@@ -0,0 +1,82 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Wei Chen <Wei.Chen@xxxxxxx>
+ *          Jianyong Wu <Jianyong.Wu@xxxxxxx>
+ *
+ * Copyright (c) 2018, Arm Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#include <libfdt_env.h>
+#include <fdt.h>
+#include <libfdt.h>
+
+#include <uk/print.h>
+#include <uk/assert.h>
+
+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/kvm/Makefile.uk b/plat/kvm/Makefile.uk
index 71c4c41..3c3c006 100644
--- a/plat/kvm/Makefile.uk
+++ b/plat/kvm/Makefile.uk
@@ -18,6 +18,7 @@ LIBKVMPLAT_ASINCLUDES-y        += -I$(LIBKVMPLAT_BASE)/include
 LIBKVMPLAT_ASINCLUDES-y        += -I$(UK_PLAT_COMMON_BASE)/include
 LIBKVMPLAT_CINCLUDES-y         += -I$(LIBKVMPLAT_BASE)/include
 LIBKVMPLAT_CINCLUDES-y         += -I$(UK_PLAT_COMMON_BASE)/include
+LIBKVMPLAT_CINCLUDES-y         += -I$(UK_PLAT_DRIVERS_BASE)/include
 
 LIBKVMPLAT_ASFLAGS             += -DKVMPLAT
 LIBKVMPLAT_CFLAGS              += -DKVMPLAT
@@ -65,6 +66,7 @@ LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/cache64.S|co
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/psci_arm64.S|common
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/time.c|common
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_COMMON_BASE)/arm/traps.c|common
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += 
$(UK_PLAT_DRIVERS_BASE)/ofw/fdt.c|common
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/entry64.S
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/exceptions.S
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/pagetable64.S
-- 
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®.