Module Name: src Committed By: jmcneill Date: Thu Feb 13 00:42:59 UTC 2020
Modified Files: src/sys/arch/arm/cortex: gicv3.c gicv3.h gicv3_its.c Log Message: Since all ITS instances share a common LPI configuration table, used a shared vmem arena to allocate pic irqs. Idea from FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sys/arch/arm/cortex/gicv3.c cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/cortex/gicv3.h cvs rdiff -u -r1.25 -r1.26 src/sys/arch/arm/cortex/gicv3_its.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/arm/cortex/gicv3.c diff -u src/sys/arch/arm/cortex/gicv3.c:1.22 src/sys/arch/arm/cortex/gicv3.c:1.23 --- src/sys/arch/arm/cortex/gicv3.c:1.22 Tue Dec 24 09:12:56 2019 +++ src/sys/arch/arm/cortex/gicv3.c Thu Feb 13 00:42:59 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gicv3.c,v 1.22 2019/12/24 09:12:56 skrll Exp $ */ +/* $NetBSD: gicv3.c,v 1.23 2020/02/13 00:42:59 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca> @@ -31,7 +31,7 @@ #define _INTR_PRIVATE #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.22 2019/12/24 09:12:56 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1.23 2020/02/13 00:42:59 jmcneill Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: gicv3.c,v 1. #include <sys/intr.h> #include <sys/systm.h> #include <sys/cpu.h> +#include <sys/vmem.h> #include <machine/cpufunc.h> @@ -828,6 +829,11 @@ gicv3_init(struct gicv3_softc *sc) snprintf(sc->sc_lpi.pic_name, sizeof(sc->sc_lpi.pic_name), "gicv3-lpi"); pic_add(&sc->sc_lpi, GIC_LPI_BASE); + sc->sc_lpi_pool = vmem_create("gicv3-lpi", 0, sc->sc_lpi.pic_maxsources, + 1, NULL, NULL, NULL, 0, VM_SLEEP, IPL_HIGH); + if (sc->sc_lpi_pool == NULL) + panic("failed to create gicv3 lpi pool\n"); + gicv3_lpi_init(sc); } Index: src/sys/arch/arm/cortex/gicv3.h diff -u src/sys/arch/arm/cortex/gicv3.h:1.7 src/sys/arch/arm/cortex/gicv3.h:1.8 --- src/sys/arch/arm/cortex/gicv3.h:1.7 Sun Jun 30 11:11:38 2019 +++ src/sys/arch/arm/cortex/gicv3.h Thu Feb 13 00:42:59 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gicv3.h,v 1.7 2019/06/30 11:11:38 jmcneill Exp $ */ +/* $NetBSD: gicv3.h,v 1.8 2020/02/13 00:42:59 jmcneill Exp $ */ /*- * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca> @@ -30,6 +30,7 @@ #define _ARM_CORTEX_GICV3_H #include <sys/intr.h> +#include <sys/vmem.h> struct gicv3_dma { bus_dma_segment_t segs[1]; @@ -73,6 +74,9 @@ struct gicv3_softc { /* LPI pending tables */ struct gicv3_dma sc_lpipend[MAXCPUS]; + /* LPI IDs */ + vmem_t *sc_lpi_pool; + /* Unique identifier for PEs */ u_int sc_processor_id[MAXCPUS]; Index: src/sys/arch/arm/cortex/gicv3_its.c diff -u src/sys/arch/arm/cortex/gicv3_its.c:1.25 src/sys/arch/arm/cortex/gicv3_its.c:1.26 --- src/sys/arch/arm/cortex/gicv3_its.c:1.25 Sat Feb 1 15:33:48 2020 +++ src/sys/arch/arm/cortex/gicv3_its.c Thu Feb 13 00:42:59 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: gicv3_its.c,v 1.25 2020/02/01 15:33:48 jmcneill Exp $ */ +/* $NetBSD: gicv3_its.c,v 1.26 2020/02/13 00:42:59 jmcneill Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #define _INTR_PRIVATE #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: gicv3_its.c,v 1.25 2020/02/01 15:33:48 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gicv3_its.c,v 1.26 2020/02/13 00:42:59 jmcneill Exp $"); #include <sys/param.h> #include <sys/kmem.h> @@ -284,18 +284,19 @@ gicv3_its_msi_alloc_lpi(struct gicv3_its const struct pci_attach_args *pa) { struct pci_attach_args *new_pa; - int n; + vmem_addr_t n; - for (n = 0; n < its->its_pic->pic_maxsources; n++) { - if (its->its_pa[n] == NULL) { - new_pa = kmem_alloc(sizeof(*new_pa), KM_SLEEP); - memcpy(new_pa, pa, sizeof(*new_pa)); - its->its_pa[n] = new_pa; - return n + its->its_pic->pic_irqbase; - } - } + KASSERT(its->its_gic->sc_lpi_pool != NULL); - return -1; + if (vmem_alloc(its->its_gic->sc_lpi_pool, 1, VM_INSTANTFIT|VM_SLEEP, &n) != 0) + return -1; + + KASSERT(its->its_pa[n] == NULL); + + new_pa = kmem_alloc(sizeof(*new_pa), KM_SLEEP); + memcpy(new_pa, pa, sizeof(*new_pa)); + its->its_pa[n] = new_pa; + return n + its->its_pic->pic_irqbase; } static void @@ -303,11 +304,14 @@ gicv3_its_msi_free_lpi(struct gicv3_its { struct pci_attach_args *pa; + KASSERT(its->its_gic->sc_lpi_pool != NULL); KASSERT(lpi >= its->its_pic->pic_irqbase); pa = its->its_pa[lpi - its->its_pic->pic_irqbase]; its->its_pa[lpi - its->its_pic->pic_irqbase] = NULL; kmem_free(pa, sizeof(*pa)); + + vmem_free(its->its_gic->sc_lpi_pool, lpi - its->its_pic->pic_irqbase, 1); } static uint32_t