[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCHv2 4/8] lib/fdt: Add a fdt_interrupr_cells helper to parse irq
From: Wei Chen <wei.chen@xxxxxxx> We will use this helper to parse IRQ number for devices, like timers and UARTs. Jira: ENTOS-860 Signed-off-by: Wei Chen <wei.chen@xxxxxxx> Signed-off-by: Jia He <justin.he@xxxxxxx> --- lib/fdt/Makefile.uk | 1 + lib/fdt/exportsyms.uk | 1 + lib/fdt/fdt_interrupts.c | 89 ++++++++++++++++++++++++++++++++++++++++ lib/fdt/include/libfdt.h | 19 +++++++++ 4 files changed, 110 insertions(+) create mode 100644 lib/fdt/fdt_interrupts.c diff --git a/lib/fdt/Makefile.uk b/lib/fdt/Makefile.uk index 03251f6..0ba9cec 100644 --- a/lib/fdt/Makefile.uk +++ b/lib/fdt/Makefile.uk @@ -7,6 +7,7 @@ LIBFDT_CFLAGS-y += -Wno-sign-compare LIBFDT_SRCS-y += $(LIBFDT_BASE)/fdt.c LIBFDT_SRCS-y += $(LIBFDT_BASE)/fdt_addresses.c +LIBFDT_SRCS-y += $(LIBFDT_BASE)/fdt_interrupts.c LIBFDT_SRCS-y += $(LIBFDT_BASE)/fdt_empty_tree.c LIBFDT_SRCS-y += $(LIBFDT_BASE)/fdt_overlay.c LIBFDT_SRCS-y += $(LIBFDT_BASE)/fdt_ro.c diff --git a/lib/fdt/exportsyms.uk b/lib/fdt/exportsyms.uk index d64d9dc..b11df90 100644 --- a/lib/fdt/exportsyms.uk +++ b/lib/fdt/exportsyms.uk @@ -61,3 +61,4 @@ fdt_stringlist_contains fdt_resize fdt_overlay_apply fdt_getprop_u32_by_offset +fdt_interrupt_cells diff --git a/lib/fdt/fdt_interrupts.c b/lib/fdt/fdt_interrupts.c new file mode 100644 index 0000000..45ae963 --- /dev/null +++ b/lib/fdt/fdt_interrupts.c @@ -0,0 +1,89 @@ +/* + * libfdt - Flat Device Tree manipulation + * Copyright (C) 2014 David Gibson <david@xxxxxxxxxxxxxxxxxxxxx> + * Copyright (C) 2018 Arm Ltd,. <Wei.Chen@xxxxxxx> + * + * libfdt is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * + * a) This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * Alternatively, + * + * b) 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. + * + * 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 OWNER 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. + */ +#include "libfdt_env.h" + +#include <fdt.h> +#include <libfdt.h> + +#include "libfdt_internal.h" + +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; + + intc_offset = fdt_find_irq_parent_offset(fdt, offset); + if (intc_offset < 0) + return intc_offset; + + return fdt_get_cells(fdt, "#interrupt-cells", intc_offset); +} diff --git a/lib/fdt/include/libfdt.h b/lib/fdt/include/libfdt.h index 798a57a..b0815af 100644 --- a/lib/fdt/include/libfdt.h +++ b/lib/fdt/include/libfdt.h @@ -1141,6 +1141,25 @@ int fdt_address_cells(const void *fdt, int nodeoffset); */ int fdt_size_cells(const void *fdt, int nodeoffset); +/** + * 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); /**********************************************************************/ /* Write-in-place functions */ -- 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 |