diff --git a/sys/amd64/acpica/acpi_wakeup.c b/sys/amd64/acpica/acpi_wakeup.c index 351cd16ff9ca78..280c617ad1d02b 100644 --- a/sys/amd64/acpica/acpi_wakeup.c +++ b/sys/amd64/acpica/acpi_wakeup.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index 58a135e827a857..ae36c412a0361e 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -51,7 +51,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index e2ae3843a119bf..8ad42c312ce991 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -119,7 +119,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index 3b7220369b61db..d9c6c36295813f 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -153,7 +153,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c index a6d6c792ee92ce..d5df3a2e6f1b18 100644 --- a/sys/amd64/amd64/trap.c +++ b/sys/amd64/amd64/trap.c @@ -83,7 +83,7 @@ PMC_SOFT_DEFINE( , , page_fault, write); #include #include -#include +#include #include #include #include diff --git a/sys/amd64/ia32/ia32_syscall.c b/sys/amd64/ia32/ia32_syscall.c index c61587a93d1f0f..904c1f5c0fd58c 100644 --- a/sys/amd64/ia32/ia32_syscall.c +++ b/sys/amd64/ia32/ia32_syscall.c @@ -75,7 +75,7 @@ #include #include -#include +#include #include #include diff --git a/sys/amd64/include/intr_machdep.h b/sys/amd64/include/interrupt.h similarity index 98% rename from sys/amd64/include/intr_machdep.h rename to sys/amd64/include/interrupt.h index 1b78875bf85355..449aab8190f394 100644 --- a/sys/amd64/include/intr_machdep.h +++ b/sys/amd64/include/interrupt.h @@ -28,7 +28,7 @@ #ifndef __MACHINE_INTR_MACHDEP_H__ #define __MACHINE_INTR_MACHDEP_H__ -#include +#include /* * The following data structure holds per-cpu data, and is placed just diff --git a/sys/arm/allwinner/a10/a10_intc.c b/sys/arm/allwinner/a10/a10_intc.c index 0bac9edbfd0805..690d520c0f3dce 100644 --- a/sys/arm/allwinner/a10/a10_intc.c +++ b/sys/arm/allwinner/a10/a10_intc.c @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/allwinner/a10_sramc.c b/sys/arm/allwinner/a10_sramc.c index fe7dd4025d7e14..3e27ce85895517 100644 --- a/sys/arm/allwinner/a10_sramc.c +++ b/sys/arm/allwinner/a10_sramc.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/allwinner/a10_timer.c b/sys/arm/allwinner/a10_timer.c index 18fb2a56da3a9a..e48a33c4fcc02c 100644 --- a/sys/arm/allwinner/a10_timer.c +++ b/sys/arm/allwinner/a10_timer.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/allwinner/a20/a20_cpu_cfg.c b/sys/arm/allwinner/a20/a20_cpu_cfg.c index ffbb2cc183e762..01c1bd63d17022 100644 --- a/sys/arm/allwinner/a20/a20_cpu_cfg.c +++ b/sys/arm/allwinner/a20/a20_cpu_cfg.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/allwinner/aw_gpio.c b/sys/arm/allwinner/aw_gpio.c index 6ff0516acb3f3f..e6dbd47680651a 100644 --- a/sys/arm/allwinner/aw_gpio.c +++ b/sys/arm/allwinner/aw_gpio.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/allwinner/aw_mp.c b/sys/arm/allwinner/aw_mp.c index 0c773f71ac4141..04719367e9ae0c 100644 --- a/sys/arm/allwinner/aw_mp.c +++ b/sys/arm/allwinner/aw_mp.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/allwinner/aw_nmi.c b/sys/arm/allwinner/aw_nmi.c index febf970c7ffbc2..4abf4adac5b309 100644 --- a/sys/arm/allwinner/aw_nmi.c +++ b/sys/arm/allwinner/aw_nmi.c @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/allwinner/aw_r_intc.c b/sys/arm/allwinner/aw_r_intc.c index 6a2629a3576588..1af9c614247a15 100644 --- a/sys/arm/allwinner/aw_r_intc.c +++ b/sys/arm/allwinner/aw_r_intc.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/allwinner/if_emac.c b/sys/arm/allwinner/if_emac.c index 1db43cbca26c87..2a0cf161c833dd 100644 --- a/sys/arm/allwinner/if_emac.c +++ b/sys/arm/allwinner/if_emac.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/altera/socfpga/socfpga_a10_manager.c b/sys/arm/altera/socfpga/socfpga_a10_manager.c index 01267bcaacf1b6..2888d912b31556 100644 --- a/sys/arm/altera/socfpga/socfpga_a10_manager.c +++ b/sys/arm/altera/socfpga/socfpga_a10_manager.c @@ -52,7 +52,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/altera/socfpga/socfpga_manager.c b/sys/arm/altera/socfpga/socfpga_manager.c index d25d34ab80e75d..bd1df393cbe2bb 100644 --- a/sys/arm/altera/socfpga/socfpga_manager.c +++ b/sys/arm/altera/socfpga/socfpga_manager.c @@ -51,7 +51,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/altera/socfpga/socfpga_mp.c b/sys/arm/altera/socfpga/socfpga_mp.c index fd752b11267c38..f85d8b4a1b4598 100644 --- a/sys/arm/altera/socfpga/socfpga_mp.c +++ b/sys/arm/altera/socfpga/socfpga_mp.c @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/altera/socfpga/socfpga_rstmgr.c b/sys/arm/altera/socfpga/socfpga_rstmgr.c index 4fbed06e3954f6..557d85a8c94e77 100644 --- a/sys/arm/altera/socfpga/socfpga_rstmgr.c +++ b/sys/arm/altera/socfpga/socfpga_rstmgr.c @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/annapurna/alpine/alpine_machdep_mp.c b/sys/arm/annapurna/alpine/alpine_machdep_mp.c index 00a6578621c390..51a5263fd4c284 100644 --- a/sys/arm/annapurna/alpine/alpine_machdep_mp.c +++ b/sys/arm/annapurna/alpine/alpine_machdep_mp.c @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/arm/generic_timer.c b/sys/arm/arm/generic_timer.c index 9b5f0f52368b8f..9239796acbb541 100644 --- a/sys/arm/arm/generic_timer.c +++ b/sys/arm/arm/generic_timer.c @@ -54,7 +54,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/arm/gic.c b/sys/arm/arm/gic.c index b1b7aacd63abb2..8f50edecb6df32 100644 --- a/sys/arm/arm/gic.c +++ b/sys/arm/arm/gic.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -58,7 +59,7 @@ #include #include -#include +#include #include #ifdef FDT @@ -128,7 +129,8 @@ static u_int sgi_to_ipi[GIC_LAST_SGI - GIC_FIRST_SGI + 1]; static u_int sgi_first_unused = GIC_FIRST_SGI; #endif -#define GIC_INTR_ISRC(sc, irq) (&sc->gic_irqs[irq].gi_isrc) +#define GIC_INTR(sc, irq) (*(struct gic_irqsrc *)intrtab_lookup(rman_get_start((sc)->gic_intrs) + (irq))) +#define GIC_INTR_ISRC(sc, irq) (&GIC_INTR((sc), (irq)).gi_isrc) static struct resource_spec arm_gic_spec[] = { { SYS_RES_MEMORY, 0, RF_ACTIVE }, /* Distributor registers */ @@ -244,37 +246,51 @@ arm_gic_register_isrcs(struct arm_gic_softc *sc, uint32_t num) { int error; uint32_t irq; - struct gic_irqsrc *irqs; struct intr_irqsrc *isrc; const char *name; - irqs = malloc(num * sizeof(struct gic_irqsrc), M_DEVBUF, - M_WAITOK | M_ZERO); + sc->gic_intrs = intrtab_alloc_intr(sc->gic_dev, num); + if (sc->gic_intrs == NULL) { + device_printf(sc->gic_dev, "could not allocate interrupts\n"); + return (ENOSPC); + } name = device_get_nameunit(sc->gic_dev); for (irq = 0; irq < num; irq++) { - irqs[irq].gi_irq = irq; - irqs[irq].gi_pol = INTR_POLARITY_CONFORM; - irqs[irq].gi_trig = INTR_TRIGGER_CONFORM; + struct gic_irqsrc *gi; + + gi = malloc(sizeof(*gi), M_DEVBUF, M_WAITOK | M_ZERO); - isrc = &irqs[irq].gi_isrc; + gi->gi_irq = irq; + gi->gi_pol = INTR_POLARITY_CONFORM; + gi->gi_trig = INTR_TRIGGER_CONFORM; + + isrc = &gi->gi_isrc; if (irq <= GIC_LAST_SGI) { error = intr_isrc_register(isrc, sc->gic_dev, - INTR_ISRCF_IPI, "%s,i%u", name, irq - GIC_FIRST_SGI); + INTR_ISRCF_NOIRQ | INTR_ISRCF_IPI, "%s,i%u", name, + irq - GIC_FIRST_SGI); } else if (irq <= GIC_LAST_PPI) { error = intr_isrc_register(isrc, sc->gic_dev, - INTR_ISRCF_PPI, "%s,p%u", name, irq - GIC_FIRST_PPI); + INTR_ISRCF_NOIRQ | INTR_ISRCF_PPI, "%s,p%u", name, + irq - GIC_FIRST_PPI); } else { - error = intr_isrc_register(isrc, sc->gic_dev, 0, - "%s,s%u", name, irq - GIC_FIRST_SPI); + error = intr_isrc_register(isrc, sc->gic_dev, + INTR_ISRCF_NOIRQ, "%s,s%u", name, + irq - GIC_FIRST_SPI); } if (error != 0) { /* XXX call intr_isrc_deregister() */ - free(irqs, M_DEVBUF); + free(gi, M_DEVBUF); return (error); } + + if (intrtab_set(sc->gic_intrs, rman_get_start(sc->gic_intrs) + + irq, &gi->gi_isrc, NULL) != 0) + panic("%s(): Failed when setting up IRQ %u (%lu)", + __func__, irq, + (u_long)rman_get_start(sc->gic_intrs) + irq); } - sc->gic_irqs = irqs; sc->nirqs = num; return (0); } @@ -291,18 +307,19 @@ arm_gic_reserve_msi_range(device_t dev, u_int start, u_int count) ("%s: Trying to allocate too many MSI IRQs: %d + %d > %d", __func__, start, count, sc->nirqs)); for (i = 0; i < count; i++) { - KASSERT(sc->gic_irqs[start + i].gi_isrc.isrc_handlers == 0, + struct gic_irqsrc *gi = &GIC_INTR(sc, start + i); + KASSERT(gi->gi_isrc.isrc_handlers == 0, ("%s: MSI interrupt %d already has a handler", __func__, count + i)); - KASSERT(sc->gic_irqs[start + i].gi_pol == INTR_POLARITY_CONFORM, + KASSERT(gi->gi_pol == INTR_POLARITY_CONFORM, ("%s: MSI interrupt %d already has a polarity", __func__, count + i)); - KASSERT(sc->gic_irqs[start + i].gi_trig == INTR_TRIGGER_CONFORM, + KASSERT(gi->gi_trig == INTR_TRIGGER_CONFORM, ("%s: MSI interrupt %d already has a trigger", __func__, count + i)); - sc->gic_irqs[start + i].gi_pol = INTR_POLARITY_HIGH; - sc->gic_irqs[start + i].gi_trig = INTR_TRIGGER_EDGE; - sc->gic_irqs[start + i].gi_flags |= GI_FLAG_MSI; + gi->gi_pol = INTR_POLARITY_HIGH; + gi->gi_trig = INTR_TRIGGER_EDGE; + gi->gi_flags |= GI_FLAG_MSI; } } @@ -407,8 +424,38 @@ arm_gic_detach(device_t dev) sc = device_get_softc(dev); - if (sc->gic_irqs != NULL) - free(sc->gic_irqs, M_DEVBUF); + if (sc->gic_intrs != NULL) { + unsigned long i; + + for(i = rman_get_start(sc->gic_intrs); + i <= rman_get_end(sc->gic_intrs); ++i) { + interrupt_t *gi = intrtab_lookup(i); + int error; + + if (gi == NULL) + continue; + + error = intrtab_set(sc->gic_intrs, i, NULL, gi); + if (error != 0) { + device_printf(sc->gic_dev, "%s(): failed to " + "remove interrupt table entry %lu, leaking " + "entry\n", __func__, i); + continue; + } + + error = intr_isrc_deregister(gi); + if (error != 0) { + device_printf(sc->gic_dev, "%s(): failed to " + "deregister interrupt, leaking memory\n", + __func__); + continue; + } + + free(gi, M_DEVBUF); + } + + intrtab_release_intr(sc->gic_intrs); + } bus_release_resources(dev, arm_gic_spec, sc->gic_res); @@ -570,7 +617,7 @@ arm_gic_intr(void *arg) tf = curthread->td_intr_frame; dispatch_irq: - gi = sc->gic_irqs + irq; + gi = &GIC_INTR(sc, irq); /* * Note that GIC_FIRST_SGI is zero and is not used in 'if' statement * as compiler complains that comparing u_int >= 0 is always true. @@ -781,7 +828,7 @@ gic_map_intr(device_t dev, struct intr_map_data *data, u_int *irqp, &trig) != 0) return (EINVAL); KASSERT(irq >= sc->nirqs || - (sc->gic_irqs[irq].gi_flags & GI_FLAG_MSI) == 0, + (GIC_INTR(sc, irq).gi_flags & GI_FLAG_MSI) == 0, ("%s: Attempting to map a MSI interrupt from FDT", __func__)); break; @@ -1055,11 +1102,11 @@ arm_gic_alloc_msi(device_t dev, u_int mbi_start, u_int mbi_count, int count, break; } - KASSERT((sc->gic_irqs[end_irq].gi_flags & GI_FLAG_MSI)!= 0, + KASSERT((GIC_INTR(sc, end_irq).gi_flags & GI_FLAG_MSI)!= 0, ("%s: Non-MSI interrupt found", __func__)); /* This is already used */ - if ((sc->gic_irqs[end_irq].gi_flags & GI_FLAG_MSI_USED) == + if ((GIC_INTR(sc, end_irq).gi_flags & GI_FLAG_MSI_USED) == GI_FLAG_MSI_USED) { found = false; break; @@ -1077,12 +1124,12 @@ arm_gic_alloc_msi(device_t dev, u_int mbi_start, u_int mbi_count, int count, for (i = 0; i < count; i++) { /* Mark the interrupt as used */ - sc->gic_irqs[irq + i].gi_flags |= GI_FLAG_MSI_USED; + GIC_INTR(sc, irq + i).gi_flags |= GI_FLAG_MSI_USED; } mtx_unlock_spin(&sc->mutex); for (i = 0; i < count; i++) - isrc[i] = (struct intr_irqsrc *)&sc->gic_irqs[irq + i]; + isrc[i] = GIC_INTR_ISRC(sc, irq + i); return (0); } @@ -1123,9 +1170,9 @@ arm_gic_alloc_msix(device_t dev, u_int mbi_start, u_int mbi_count, mtx_lock_spin(&sc->mutex); /* Find an unused interrupt */ for (irq = mbi_start; irq < mbi_start + mbi_count; irq++) { - KASSERT((sc->gic_irqs[irq].gi_flags & GI_FLAG_MSI) != 0, + KASSERT((GIC_INTR(sc, irq).gi_flags & GI_FLAG_MSI) != 0, ("%s: Non-MSI interrupt found", __func__)); - if ((sc->gic_irqs[irq].gi_flags & GI_FLAG_MSI_USED) == 0) + if ((GIC_INTR(sc, irq).gi_flags & GI_FLAG_MSI_USED) == 0) break; } /* No free interrupt was found */ @@ -1135,10 +1182,10 @@ arm_gic_alloc_msix(device_t dev, u_int mbi_start, u_int mbi_count, } /* Mark the interrupt as used */ - sc->gic_irqs[irq].gi_flags |= GI_FLAG_MSI_USED; + GIC_INTR(sc, irq).gi_flags |= GI_FLAG_MSI_USED; mtx_unlock_spin(&sc->mutex); - *isrc = (struct intr_irqsrc *)&sc->gic_irqs[irq]; + *isrc = GIC_INTR_ISRC(sc, irq); return (0); } diff --git a/sys/arm/arm/gic.h b/sys/arm/arm/gic.h index 848fd04d389138..62367146eaebf8 100644 --- a/sys/arm/arm/gic.h +++ b/sys/arm/arm/gic.h @@ -47,7 +47,7 @@ struct arm_gic_softc { device_t gic_dev; void * gic_intrhand; - struct gic_irqsrc * gic_irqs; + struct resource *gic_intrs; #define GIC_RES_DIST 0 #define GIC_RES_CPU 1 struct resource * gic_res[3]; diff --git a/sys/arm/arm/gic_acpi.c b/sys/arm/arm/gic_acpi.c index 6fd6f5271375e0..0cda81eeb6a84c 100644 --- a/sys/arm/arm/gic_acpi.c +++ b/sys/arm/arm/gic_acpi.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/arm/gic_fdt.c b/sys/arm/arm/gic_fdt.c index 06a869eaae42a9..68b5b4bbe245ba 100644 --- a/sys/arm/arm/gic_fdt.c +++ b/sys/arm/arm/gic_fdt.c @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/arm/machdep_intr.c b/sys/arm/arm/machdep_intr.c index 712336e7c0483f..976b74b93b69bb 100644 --- a/sys/arm/arm/machdep_intr.c +++ b/sys/arm/arm/machdep_intr.c @@ -32,7 +32,7 @@ #include #include -#include +#include /* * arm_irq_memory_barrier() diff --git a/sys/arm/arm/mpcore_timer.c b/sys/arm/arm/mpcore_timer.c index b4da9426128a51..0994090f9287dc 100644 --- a/sys/arm/arm/mpcore_timer.c +++ b/sys/arm/arm/mpcore_timer.c @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include /* For arm_set_delay */ diff --git a/sys/arm/arm/nexus.c b/sys/arm/arm/nexus.c index 8274a792839d8e..66808ad41ac70e 100644 --- a/sys/arm/arm/nexus.c +++ b/sys/arm/arm/nexus.c @@ -53,7 +53,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/arm/pl310.c b/sys/arm/arm/pl310.c index 46bf654de90b94..c57869028b6e35 100644 --- a/sys/arm/arm/pl310.c +++ b/sys/arm/arm/pl310.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/arm/platform.c b/sys/arm/arm/platform.c index 9cf2968ace6c50..ffc409f55ef0cc 100644 --- a/sys/arm/arm/platform.c +++ b/sys/arm/arm/platform.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/arm/arm/pmu.c b/sys/arm/arm/pmu.c index 1c9e17a85c5791..c90ca2a2f51064 100644 --- a/sys/arm/arm/pmu.c +++ b/sys/arm/arm/pmu.c @@ -50,7 +50,7 @@ #include #include -#include +#include #include "pmu.h" diff --git a/sys/arm/arm/sp804.c b/sys/arm/arm/sp804.c index 98d6fa361a9856..eb58553f338fd4 100644 --- a/sys/arm/arm/sp804.c +++ b/sys/arm/arm/sp804.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include /* For arm_set_delay */ diff --git a/sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c b/sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c index 3ef564c6ae13c6..aed2fcd72c2fec 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/broadcom/bcm2835/bcm2835_ft5406.c b/sys/arm/broadcom/bcm2835/bcm2835_ft5406.c index bb8833574471aa..e9f419fa2c8126 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_ft5406.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_ft5406.c @@ -52,7 +52,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/broadcom/bcm2835/bcm2835_gpio.c b/sys/arm/broadcom/bcm2835/bcm2835_gpio.c index e4fc57b79ba58a..d5747372beb332 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_gpio.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_gpio.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/broadcom/bcm2835/bcm2835_intr.c b/sys/arm/broadcom/bcm2835/bcm2835_intr.c index 65ada57c0b605d..db26333897e4e5 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_intr.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_intr.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/broadcom/bcm2835/bcm2835_spi.c b/sys/arm/broadcom/bcm2835/bcm2835_spi.c index 17419be0c8a764..116c631694ad66 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_spi.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_spi.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/broadcom/bcm2835/bcm2836.c b/sys/arm/broadcom/bcm2835/bcm2836.c index 7ed9dedaa77ebb..b676b37f64a8d3 100644 --- a/sys/arm/broadcom/bcm2835/bcm2836.c +++ b/sys/arm/broadcom/bcm2835/bcm2836.c @@ -44,7 +44,7 @@ #endif #include -#include +#include #include #ifdef SMP #include diff --git a/sys/arm/broadcom/bcm2835/bcm2836_mp.c b/sys/arm/broadcom/bcm2835/bcm2836_mp.c index c9b5599a416246..dbe3befc050c6e 100644 --- a/sys/arm/broadcom/bcm2835/bcm2836_mp.c +++ b/sys/arm/broadcom/bcm2835/bcm2836_mp.c @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/broadcom/bcm2835/bcm2838_pci.c b/sys/arm/broadcom/bcm2835/bcm2838_pci.c index 0f41dcff37ca41..fa1cc0e8eca024 100644 --- a/sys/arm/broadcom/bcm2835/bcm2838_pci.c +++ b/sys/arm/broadcom/bcm2835/bcm2838_pci.c @@ -47,7 +47,7 @@ #include #include -#include +#include #include "pcib_if.h" #include "msi_if.h" diff --git a/sys/arm/freescale/imx/imx6_audmux.c b/sys/arm/freescale/imx/imx6_audmux.c index 45f00d362a1eee..91c3e5163c3091 100644 --- a/sys/arm/freescale/imx/imx6_audmux.c +++ b/sys/arm/freescale/imx/imx6_audmux.c @@ -47,7 +47,7 @@ #include #include -#include +#include #define READ4(_sc, _reg) \ bus_space_read_4(_sc->bst, _sc->bsh, _reg) diff --git a/sys/arm/freescale/imx/imx6_machdep.c b/sys/arm/freescale/imx/imx6_machdep.c index 9cfae5b9c802d1..75329c3a213806 100644 --- a/sys/arm/freescale/imx/imx6_machdep.c +++ b/sys/arm/freescale/imx/imx6_machdep.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/imx/imx6_mp.c b/sys/arm/freescale/imx/imx6_mp.c index 0a8b9109c8bdf8..934f0f94a5d6c7 100644 --- a/sys/arm/freescale/imx/imx6_mp.c +++ b/sys/arm/freescale/imx/imx6_mp.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/imx/imx6_sdma.c b/sys/arm/freescale/imx/imx6_sdma.c index 805024903b4e7c..cb343a50b558fd 100644 --- a/sys/arm/freescale/imx/imx6_sdma.c +++ b/sys/arm/freescale/imx/imx6_sdma.c @@ -53,7 +53,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/freescale/imx/imx6_ssi.c b/sys/arm/freescale/imx/imx6_ssi.c index cb77f1454e631e..eae7f852100a05 100644 --- a/sys/arm/freescale/imx/imx6_ssi.c +++ b/sys/arm/freescale/imx/imx6_ssi.c @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/imx/imx_epit.c b/sys/arm/freescale/imx/imx_epit.c index 3ea6b642fc8887..30d21faabbfcf8 100644 --- a/sys/arm/freescale/imx/imx_epit.c +++ b/sys/arm/freescale/imx/imx_epit.c @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/imx/imx_gpio.c b/sys/arm/freescale/imx/imx_gpio.c index 7610d28af90e99..c3212c4980f048 100644 --- a/sys/arm/freescale/imx/imx_gpio.c +++ b/sys/arm/freescale/imx/imx_gpio.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/imx/imx_gpt.c b/sys/arm/freescale/imx/imx_gpt.c index 59d43b828dd826..84c541e7d189b3 100644 --- a/sys/arm/freescale/imx/imx_gpt.c +++ b/sys/arm/freescale/imx/imx_gpt.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include /* For arm_set_delay */ #include diff --git a/sys/arm/freescale/imx/imx_spi.c b/sys/arm/freescale/imx/imx_spi.c index 388b25b7ec28b2..c7d79b43393b80 100644 --- a/sys/arm/freescale/imx/imx_spi.c +++ b/sys/arm/freescale/imx/imx_spi.c @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include diff --git a/sys/arm/freescale/imx/imx_wdog.c b/sys/arm/freescale/imx/imx_wdog.c index 5bd6fabc3fe700..ad2eb21cb0396d 100644 --- a/sys/arm/freescale/imx/imx_wdog.c +++ b/sys/arm/freescale/imx/imx_wdog.c @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/vybrid/vf_adc.c b/sys/arm/freescale/vybrid/vf_adc.c index cca30517dc20b2..0bb42f40e68991 100644 --- a/sys/arm/freescale/vybrid/vf_adc.c +++ b/sys/arm/freescale/vybrid/vf_adc.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/vybrid/vf_anadig.c b/sys/arm/freescale/vybrid/vf_anadig.c index 17688a40604fa7..cba34f7ba8b71f 100644 --- a/sys/arm/freescale/vybrid/vf_anadig.c +++ b/sys/arm/freescale/vybrid/vf_anadig.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/freescale/vybrid/vf_ccm.c b/sys/arm/freescale/vybrid/vf_ccm.c index 35faf4bb735b86..c6dffabe2bde2f 100644 --- a/sys/arm/freescale/vybrid/vf_ccm.c +++ b/sys/arm/freescale/vybrid/vf_ccm.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/freescale/vybrid/vf_dcu4.c b/sys/arm/freescale/vybrid/vf_dcu4.c index eae381de85561f..2090827ade7d85 100644 --- a/sys/arm/freescale/vybrid/vf_dcu4.c +++ b/sys/arm/freescale/vybrid/vf_dcu4.c @@ -61,7 +61,7 @@ #include #include #include -#include +#include #include "fb_if.h" diff --git a/sys/arm/freescale/vybrid/vf_dmamux.c b/sys/arm/freescale/vybrid/vf_dmamux.c index 19891c6af98051..807b69f76436d9 100644 --- a/sys/arm/freescale/vybrid/vf_dmamux.c +++ b/sys/arm/freescale/vybrid/vf_dmamux.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/vybrid/vf_edma.c b/sys/arm/freescale/vybrid/vf_edma.c index 5b8b7eaab7763d..81ccff51f6bf3a 100644 --- a/sys/arm/freescale/vybrid/vf_edma.c +++ b/sys/arm/freescale/vybrid/vf_edma.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/vybrid/vf_gpio.c b/sys/arm/freescale/vybrid/vf_gpio.c index c81524a8a27e0e..89d16f9f2da5b5 100644 --- a/sys/arm/freescale/vybrid/vf_gpio.c +++ b/sys/arm/freescale/vybrid/vf_gpio.c @@ -51,7 +51,7 @@ #include #include -#include +#include #include "gpio_if.h" diff --git a/sys/arm/freescale/vybrid/vf_iomuxc.c b/sys/arm/freescale/vybrid/vf_iomuxc.c index 3e90761513c6a6..7296b564ddb443 100644 --- a/sys/arm/freescale/vybrid/vf_iomuxc.c +++ b/sys/arm/freescale/vybrid/vf_iomuxc.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/vybrid/vf_mscm.c b/sys/arm/freescale/vybrid/vf_mscm.c index 5f986050ae9da6..12594fd123efd7 100644 --- a/sys/arm/freescale/vybrid/vf_mscm.c +++ b/sys/arm/freescale/vybrid/vf_mscm.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/freescale/vybrid/vf_port.c b/sys/arm/freescale/vybrid/vf_port.c index 215b66b346699c..8ec8c91a7500fb 100644 --- a/sys/arm/freescale/vybrid/vf_port.c +++ b/sys/arm/freescale/vybrid/vf_port.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/vybrid/vf_sai.c b/sys/arm/freescale/vybrid/vf_sai.c index e895529c481042..017f75fe21f608 100644 --- a/sys/arm/freescale/vybrid/vf_sai.c +++ b/sys/arm/freescale/vybrid/vf_sai.c @@ -51,7 +51,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/vybrid/vf_spi.c b/sys/arm/freescale/vybrid/vf_spi.c index 5d32723e118c0e..4eb6f503107125 100644 --- a/sys/arm/freescale/vybrid/vf_spi.c +++ b/sys/arm/freescale/vybrid/vf_spi.c @@ -51,7 +51,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/freescale/vybrid/vf_src.c b/sys/arm/freescale/vybrid/vf_src.c index c038c816d0dedc..cbb8fef63dcaaa 100644 --- a/sys/arm/freescale/vybrid/vf_src.c +++ b/sys/arm/freescale/vybrid/vf_src.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/freescale/vybrid/vf_tcon.c b/sys/arm/freescale/vybrid/vf_tcon.c index f66f37383bd602..1cc6076b47e3bc 100644 --- a/sys/arm/freescale/vybrid/vf_tcon.c +++ b/sys/arm/freescale/vybrid/vf_tcon.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/include/interrupt.h b/sys/arm/include/interrupt.h new file mode 100644 index 00000000000000..10e9838662a140 --- /dev/null +++ b/sys/arm/include/interrupt.h @@ -0,0 +1,54 @@ +/* $NetBSD: intr.h,v 1.7 2003/06/16 20:01:00 thorpej Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (c) 1997 Mark Brinicombe. + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mark Brinicombe + * for the NetBSD Project. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + */ + +#ifndef __MACHINE_INTERRUPT_H__ +#define __MACHINE_INTERRUPT_H__ + +#include + +#ifdef FDT +#include +#endif + +#ifndef NIRQ +#define NIRQ 1024 /* XXX - It should be an option. */ +#endif + +void arm_irq_memory_barrier(uintptr_t); + +#endif /* __MACHINE_INTERRUPT_H__ */ diff --git a/sys/arm/include/intr.h b/sys/arm/include/intr.h index e64edd47dad2f7..e22de7d138870f 100644 --- a/sys/arm/include/intr.h +++ b/sys/arm/include/intr.h @@ -1,52 +1,5 @@ -/* $NetBSD: intr.h,v 1.7 2003/06/16 20:01:00 thorpej Exp $ */ - /*- - * SPDX-License-Identifier: BSD-4-Clause - * - * Copyright (c) 1997 Mark Brinicombe. - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Mark Brinicombe - * for the NetBSD Project. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 file is in the public domain. */ -#ifndef _MACHINE_INTR_H_ -#define _MACHINE_INTR_H_ - -#ifdef FDT -#include -#endif - -#ifndef NIRQ -#define NIRQ 1024 /* XXX - It should be an option. */ -#endif - -void arm_irq_memory_barrier(uintptr_t); - -#endif /* _MACHINE_INTR_H */ +#include diff --git a/sys/arm/mv/a37x0_spi.c b/sys/arm/mv/a37x0_spi.c index 4bcbbc503218e8..fe316852806fb0 100644 --- a/sys/arm/mv/a37x0_spi.c +++ b/sys/arm/mv/a37x0_spi.c @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/armada38x/armada38x_mp.c b/sys/arm/mv/armada38x/armada38x_mp.c index 69e2df36eaec88..fb50255aa365fc 100644 --- a/sys/arm/mv/armada38x/armada38x_mp.c +++ b/sys/arm/mv/armada38x/armada38x_mp.c @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/gpio.c b/sys/arm/mv/gpio.c index 934c00236153af..90615b9490bd3d 100644 --- a/sys/arm/mv/gpio.c +++ b/sys/arm/mv/gpio.c @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include @@ -425,7 +425,7 @@ mv_gpio_setup_intrhandler(device_t dev, const char *name, driver_filter_t *filt, } else if (sc->gpio_setup[pin].gp_flags & MV_GPIO_IN_IRQ_DOUBLE_EDGE) mv_gpio_double_edge_init(dev, pin); MV_GPIO_UNLOCK(); - error = intr_event_create(&event, (void *)s, 0, pin, + error = intr_event_create(&event, (void *)s, 0, (void (*)(void *))mv_gpio_intr_mask, (void (*)(void *))mv_gpio_intr_unmask, (void (*)(void *))mv_gpio_int_ack, @@ -433,6 +433,7 @@ mv_gpio_setup_intrhandler(device_t dev, const char *name, driver_filter_t *filt, "gpio%d:", pin); if (error != 0) return (error); + event->ie_irq = pin; sc->gpio_events[pin] = event; } diff --git a/sys/arm/mv/ic.c b/sys/arm/mv/ic.c index aaea59ae2ca62a..5e64bd3ba60266 100644 --- a/sys/arm/mv/ic.c +++ b/sys/arm/mv/ic.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mpic.c b/sys/arm/mv/mpic.c index 232eb85569484e..149c7521e78f7a 100644 --- a/sys/arm/mv/mpic.c +++ b/sys/arm/mv/mpic.c @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mv_ap806_clock.c b/sys/arm/mv/mv_ap806_clock.c index 6d15d5687088f6..ee72198e9dba25 100644 --- a/sys/arm/mv/mv_ap806_clock.c +++ b/sys/arm/mv/mv_ap806_clock.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mv_ap806_gicp.c b/sys/arm/mv/mv_ap806_gicp.c index 5a2ff8faddab48..59131fc505f9ec 100644 --- a/sys/arm/mv/mv_ap806_gicp.c +++ b/sys/arm/mv/mv_ap806_gicp.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/mv/mv_ap806_sei.c b/sys/arm/mv/mv_ap806_sei.c index d711c646395620..11c870be2150e5 100644 --- a/sys/arm/mv/mv_ap806_sei.c +++ b/sys/arm/mv/mv_ap806_sei.c @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mv_common.c b/sys/arm/mv/mv_common.c index 5bfe4c08d7622a..7a539fd2745eff 100644 --- a/sys/arm/mv/mv_common.c +++ b/sys/arm/mv/mv_common.c @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mv_cp110_clock.c b/sys/arm/mv/mv_cp110_clock.c index 9edc01e95074fe..e6da55e3dc3711 100644 --- a/sys/arm/mv/mv_cp110_clock.c +++ b/sys/arm/mv/mv_cp110_clock.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mv_cp110_icu.c b/sys/arm/mv/mv_cp110_icu.c index 25ec19bee57593..3570bd57aabdfc 100644 --- a/sys/arm/mv/mv_cp110_icu.c +++ b/sys/arm/mv/mv_cp110_icu.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/mv/mv_pci.c b/sys/arm/mv/mv_pci.c index 69c72c074c67b0..cfdd00a4ce2dba 100644 --- a/sys/arm/mv/mv_pci.c +++ b/sys/arm/mv/mv_pci.c @@ -54,7 +54,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mv_spi.c b/sys/arm/mv/mv_spi.c index 621594624b7bc4..b656202a1381a8 100644 --- a/sys/arm/mv/mv_spi.c +++ b/sys/arm/mv/mv_spi.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mv_thermal.c b/sys/arm/mv/mv_thermal.c index 9240666ec726cc..761a24dc003407 100644 --- a/sys/arm/mv/mv_thermal.c +++ b/sys/arm/mv/mv_thermal.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mvebu_gpio.c b/sys/arm/mv/mvebu_gpio.c index a2001589867c0b..88996d7ec07409 100644 --- a/sys/arm/mv/mvebu_gpio.c +++ b/sys/arm/mv/mvebu_gpio.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/mv/mvebu_pinctrl.c b/sys/arm/mv/mvebu_pinctrl.c index 7e9ecda1a67a3f..19a3bc645fbd7f 100644 --- a/sys/arm/mv/mvebu_pinctrl.c +++ b/sys/arm/mv/mvebu_pinctrl.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include diff --git a/sys/arm/mv/timer.c b/sys/arm/mv/timer.c index 8b5306fc7a94dc..5caa8329f260ee 100644 --- a/sys/arm/mv/timer.c +++ b/sys/arm/mv/timer.c @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/nvidia/tegra124/tegra124_machdep.c b/sys/arm/nvidia/tegra124/tegra124_machdep.c index 4f06622d1dacfe..3137fc3ee7b5b8 100644 --- a/sys/arm/nvidia/tegra124/tegra124_machdep.c +++ b/sys/arm/nvidia/tegra124/tegra124_machdep.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/nvidia/tegra124/tegra124_mp.c b/sys/arm/nvidia/tegra124/tegra124_mp.c index 7764d6f36b31ce..cd68596478596f 100644 --- a/sys/arm/nvidia/tegra124/tegra124_mp.c +++ b/sys/arm/nvidia/tegra124/tegra124_mp.c @@ -35,7 +35,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/arm/nvidia/tegra_gpio.c b/sys/arm/nvidia/tegra_gpio.c index 29bc8624e27ad5..22f39a918e0bcd 100644 --- a/sys/arm/nvidia/tegra_gpio.c +++ b/sys/arm/nvidia/tegra_gpio.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/nvidia/tegra_lic.c b/sys/arm/nvidia/tegra_lic.c index e1d64163535162..e6306fd76a06c9 100644 --- a/sys/arm/nvidia/tegra_lic.c +++ b/sys/arm/nvidia/tegra_lic.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/nvidia/tegra_pcie.c b/sys/arm/nvidia/tegra_pcie.c index 2a91a81d40a913..2fd2e34d5f5894 100644 --- a/sys/arm/nvidia/tegra_pcie.c +++ b/sys/arm/nvidia/tegra_pcie.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/nvidia/tegra_sdhci.c b/sys/arm/nvidia/tegra_sdhci.c index 2b152227d95fe0..dc328536ab1c59 100644 --- a/sys/arm/nvidia/tegra_sdhci.c +++ b/sys/arm/nvidia/tegra_sdhci.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/qemu/virt_mp.c b/sys/arm/qemu/virt_mp.c index a3471b1eb76468..0aa7f1f8c3cf6c 100644 --- a/sys/arm/qemu/virt_mp.c +++ b/sys/arm/qemu/virt_mp.c @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/qualcomm/ipq4018_machdep.c b/sys/arm/qualcomm/ipq4018_machdep.c index 206f428111bacb..8bf7bd5cf731fe 100644 --- a/sys/arm/qualcomm/ipq4018_machdep.c +++ b/sys/arm/qualcomm/ipq4018_machdep.c @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/qualcomm/ipq4018_mp.c b/sys/arm/qualcomm/ipq4018_mp.c index cdcc0dfb95502f..12a2217ebc73f3 100644 --- a/sys/arm/qualcomm/ipq4018_mp.c +++ b/sys/arm/qualcomm/ipq4018_mp.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/arm/qualcomm/qcom_cpu_kpssv2.c b/sys/arm/qualcomm/qcom_cpu_kpssv2.c index c265f0f897e2ad..2e03939d7e085b 100644 --- a/sys/arm/qualcomm/qcom_cpu_kpssv2.c +++ b/sys/arm/qualcomm/qcom_cpu_kpssv2.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/arm/qualcomm/qcom_scm_legacy.c b/sys/arm/qualcomm/qcom_scm_legacy.c index b614843b1ce87d..f5e55b4c37928e 100644 --- a/sys/arm/qualcomm/qcom_scm_legacy.c +++ b/sys/arm/qualcomm/qcom_scm_legacy.c @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/rockchip/rk32xx_machdep.c b/sys/arm/rockchip/rk32xx_machdep.c index 56410a0f47248e..9cb848bfda16bd 100644 --- a/sys/arm/rockchip/rk32xx_machdep.c +++ b/sys/arm/rockchip/rk32xx_machdep.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/aintc.c b/sys/arm/ti/aintc.c index b822a2038211b2..e4df21c059872b 100644 --- a/sys/arm/ti/aintc.c +++ b/sys/arm/ti/aintc.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/ti/am335x/am335x_gpio.c b/sys/arm/ti/am335x/am335x_gpio.c index 78665b19857ab8..32365bc4151e4d 100644 --- a/sys/arm/ti/am335x/am335x_gpio.c +++ b/sys/arm/ti/am335x/am335x_gpio.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/am335x/am335x_lcd_syscons.c b/sys/arm/ti/am335x/am335x_lcd_syscons.c index 09505adac8f39d..f49438a56644dd 100644 --- a/sys/arm/ti/am335x/am335x_lcd_syscons.c +++ b/sys/arm/ti/am335x/am335x_lcd_syscons.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/am335x/am335x_scm_padconf.c b/sys/arm/ti/am335x/am335x_scm_padconf.c index 1d28a8003d551e..b09f7ff0e6cb85 100644 --- a/sys/arm/ti/am335x/am335x_scm_padconf.c +++ b/sys/arm/ti/am335x/am335x_scm_padconf.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/omap4/omap4_gpio.c b/sys/arm/ti/omap4/omap4_gpio.c index 08c878107b486f..a6277bcfb43afc 100644 --- a/sys/arm/ti/omap4/omap4_gpio.c +++ b/sys/arm/ti/omap4/omap4_gpio.c @@ -35,7 +35,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/omap4/omap4_mp.c b/sys/arm/ti/omap4/omap4_mp.c index 1affd08583dbd1..c9c7030845e393 100644 --- a/sys/arm/ti/omap4/omap4_mp.c +++ b/sys/arm/ti/omap4/omap4_mp.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/ti/omap4/omap4_prcm_clks.c b/sys/arm/ti/omap4/omap4_prcm_clks.c index 63c679f178bc08..0094ea3d2ff27b 100644 --- a/sys/arm/ti/omap4/omap4_prcm_clks.c +++ b/sys/arm/ti/omap4/omap4_prcm_clks.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/omap4/omap4_wugen.c b/sys/arm/ti/omap4/omap4_wugen.c index d9264e60efc977..d9015c5a0a9ff8 100644 --- a/sys/arm/ti/omap4/omap4_wugen.c +++ b/sys/arm/ti/omap4/omap4_wugen.c @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/ti_cpuid.c b/sys/arm/ti/ti_cpuid.c index b2e7e61c287b81..0b1abfe50ef488 100644 --- a/sys/arm/ti/ti_cpuid.c +++ b/sys/arm/ti/ti_cpuid.c @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/ti/ti_gpio.c b/sys/arm/ti/ti_gpio.c index 68561b96bad217..b33d771da6cb8a 100644 --- a/sys/arm/ti/ti_gpio.c +++ b/sys/arm/ti/ti_gpio.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/ti_mbox.c b/sys/arm/ti/ti_mbox.c index d844d3b86dec1e..e90eca6df21609 100644 --- a/sys/arm/ti/ti_mbox.c +++ b/sys/arm/ti/ti_mbox.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/ti/ti_prcm.c b/sys/arm/ti/ti_prcm.c index 0006d0eaec9bfd..3cc887f16e3fb7 100644 --- a/sys/arm/ti/ti_prcm.c +++ b/sys/arm/ti/ti_prcm.c @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/ti/ti_pruss.c b/sys/arm/ti/ti_pruss.c index b7a04f2cfb4285..876fa269306c13 100644 --- a/sys/arm/ti/ti_pruss.c +++ b/sys/arm/ti/ti_pruss.c @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/ti/ti_sdhci.c b/sys/arm/ti/ti_sdhci.c index 29035fee77c9d9..362737bce6f4a2 100644 --- a/sys/arm/ti/ti_sdhci.c +++ b/sys/arm/ti/ti_sdhci.c @@ -60,7 +60,7 @@ #include #include -#include +#include #include "opt_mmccam.h" diff --git a/sys/arm/ti/ti_sdma.c b/sys/arm/ti/ti_sdma.c index e89a5c7b4f3c39..096b1a439a837a 100644 --- a/sys/arm/ti/ti_sdma.c +++ b/sys/arm/ti/ti_sdma.c @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/ti/ti_spi.c b/sys/arm/ti/ti_spi.c index 9fabed46917d66..004e0cbe6e088d 100644 --- a/sys/arm/ti/ti_spi.c +++ b/sys/arm/ti/ti_spi.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/ti_wdt.c b/sys/arm/ti/ti_wdt.c index db580cd17cdfe6..ba502aae8f6c43 100644 --- a/sys/arm/ti/ti_wdt.c +++ b/sys/arm/ti/ti_wdt.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm/ti/twl/twl.c b/sys/arm/ti/twl/twl.c index 88391b136df30f..ba16b4922d7907 100644 --- a/sys/arm/ti/twl/twl.c +++ b/sys/arm/ti/twl/twl.c @@ -58,7 +58,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/twl/twl_clks.c b/sys/arm/ti/twl/twl_clks.c index 30dec7bcfc3729..155cb6153ad9b0 100644 --- a/sys/arm/ti/twl/twl_clks.c +++ b/sys/arm/ti/twl/twl_clks.c @@ -63,7 +63,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/ti/twl/twl_vreg.c b/sys/arm/ti/twl/twl_vreg.c index 7609ed9a9c4f67..05d32a7f56f382 100644 --- a/sys/arm/ti/twl/twl_vreg.c +++ b/sys/arm/ti/twl/twl_vreg.c @@ -64,7 +64,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm/xilinx/zy7_mp.c b/sys/arm/xilinx/zy7_mp.c index def950cadf0be6..f506bebf31ac83 100644 --- a/sys/arm/xilinx/zy7_mp.c +++ b/sys/arm/xilinx/zy7_mp.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm64/acpica/acpi_iort.c b/sys/arm64/acpica/acpi_iort.c index a0e24788b7754d..4779970501f5b1 100644 --- a/sys/arm64/acpica/acpi_iort.c +++ b/sys/arm64/acpica/acpi_iort.c @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm64/arm64/autoconf.c b/sys/arm64/arm64/autoconf.c index 2c914e94c7e91e..9042fe2ba01a55 100644 --- a/sys/arm64/arm64/autoconf.c +++ b/sys/arm64/arm64/autoconf.c @@ -43,7 +43,7 @@ #include #include -#include +#include static void configure_first(void *); static void configure(void *); diff --git a/sys/arm64/arm64/gic_v3.c b/sys/arm64/arm64/gic_v3.c index 964a129111e274..27191682731b76 100644 --- a/sys/arm64/arm64/gic_v3.c +++ b/sys/arm64/arm64/gic_v3.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -54,7 +55,7 @@ #include #include -#include +#include #ifdef FDT #include @@ -276,18 +277,19 @@ gic_v3_reserve_msi_range(device_t dev, u_int start, u_int count) ("%s: Trying to allocate too many MSI IRQs: %d + %d > %d", __func__, start, count, sc->gic_nirqs)); for (i = 0; i < count; i++) { - KASSERT(sc->gic_irqs[start + i].gi_isrc.isrc_handlers == 0, + struct gic_v3_irqsrc *gi = &GIC_INTR(sc, start + i); + KASSERT(gi->gi_isrc.isrc_handlers == 0, ("%s: MSI interrupt %d already has a handler", __func__, count + i)); - KASSERT(sc->gic_irqs[start + i].gi_pol == INTR_POLARITY_CONFORM, + KASSERT(gi->gi_pol == INTR_POLARITY_CONFORM, ("%s: MSI interrupt %d already has a polarity", __func__, count + i)); - KASSERT(sc->gic_irqs[start + i].gi_trig == INTR_TRIGGER_CONFORM, + KASSERT(gi->gi_trig == INTR_TRIGGER_CONFORM, ("%s: MSI interrupt %d already has a trigger", __func__, count + i)); - sc->gic_irqs[start + i].gi_pol = INTR_POLARITY_HIGH; - sc->gic_irqs[start + i].gi_trig = INTR_TRIGGER_EDGE; - sc->gic_irqs[start + i].gi_flags |= GI_FLAG_MSI; + gi->gi_pol = INTR_POLARITY_HIGH; + gi->gi_trig = INTR_TRIGGER_EDGE; + gi->gi_flags |= GI_FLAG_MSI; } } @@ -353,32 +355,48 @@ gic_v3_attach(device_t dev) if (sc->gic_nirqs > GIC_I_NUM_MAX) sc->gic_nirqs = GIC_I_NUM_MAX; - sc->gic_irqs = malloc(sizeof(*sc->gic_irqs) * sc->gic_nirqs, - M_GIC_V3, M_WAITOK | M_ZERO); + sc->gic_intrs = intrtab_alloc_intr(dev, sc->gic_nirqs); + if (sc->gic_intrs == NULL) { + device_printf(dev, "could not allocate interrupts\n"); + return (ENOSPC); + } + name = device_get_nameunit(dev); for (irq = 0; irq < sc->gic_nirqs; irq++) { + struct gic_v3_irqsrc *gi; struct intr_irqsrc *isrc; - sc->gic_irqs[irq].gi_irq = irq; - sc->gic_irqs[irq].gi_pol = INTR_POLARITY_CONFORM; - sc->gic_irqs[irq].gi_trig = INTR_TRIGGER_CONFORM; + gi = malloc(sizeof(*gi), M_GIC_V3, M_WAITOK | M_ZERO); + + gi->gi_irq = irq; + gi->gi_pol = INTR_POLARITY_CONFORM; + gi->gi_trig = INTR_TRIGGER_CONFORM; - isrc = &sc->gic_irqs[irq].gi_isrc; + isrc = &gi->gi_isrc; if (irq <= GIC_LAST_SGI) { err = intr_isrc_register(isrc, sc->dev, - INTR_ISRCF_IPI, "%s,i%u", name, irq - GIC_FIRST_SGI); + INTR_ISRCF_NOIRQ | INTR_ISRCF_IPI, "%s,i%u", name, + irq - GIC_FIRST_SGI); } else if (irq <= GIC_LAST_PPI) { err = intr_isrc_register(isrc, sc->dev, - INTR_ISRCF_PPI, "%s,p%u", name, irq - GIC_FIRST_PPI); + INTR_ISRCF_NOIRQ | INTR_ISRCF_PPI, "%s,p%u", name, + irq - GIC_FIRST_PPI); } else { - err = intr_isrc_register(isrc, sc->dev, 0, - "%s,s%u", name, irq - GIC_FIRST_SPI); + err = intr_isrc_register(isrc, sc->dev, + INTR_ISRCF_NOIRQ, "%s,s%u", name, + irq - GIC_FIRST_SPI); } if (err != 0) { /* XXX call intr_isrc_deregister() */ - free(sc->gic_irqs, M_DEVBUF); + free(gi, M_GIC_V3); return (err); } + + if (intrtab_set(sc->gic_intrs, + rman_get_start(sc->gic_intrs) + irq, &gi->gi_isrc, NULL) != + 0) + panic("%s(): Failed when setting up IRQ %u (%lu)", + __func__, irq, rman_get_start(sc->gic_intrs) + irq); } mtx_init(&sc->gic_mbi_mtx, "GICv3 mbi lock", NULL, MTX_DEF); @@ -439,6 +457,40 @@ gic_v3_detach(device_t dev) if (sc->gic_registered) panic("Trying to detach registered PIC"); } + + if (sc->gic_intrs != NULL) { + unsigned long i; + + for(i = rman_get_start(sc->gic_intrs); + i <= rman_get_end(sc->gic_intrs); ++i) { + interrupt_t *gi = intrtab_lookup(i); + int error; + + if (gi == NULL) + continue; + + error = intrtab_set(sc->gic_intrs, i, NULL, gi); + if (error != 0) { + device_printf(sc->dev, "%s(): failed to remove " + "interrupt table entry %lu, leaking " + "entry\n", __func__, i); + continue; + } + + error = intr_isrc_deregister(gi); + if (error != 0) { + device_printf(sc->dev, "%s(): failed to " + "deregister interrupt, leaking memory\n", + __func__); + continue; + } + + free(gi, M_GIC_V3); + } + + intrtab_release_intr(sc->gic_intrs); + } + for (rid = 0; rid < (sc->gic_redists.nregions + 1); rid++) bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->gic_res[rid]); @@ -629,7 +681,7 @@ arm_gic_v3_intr(void *arg) return (FILTER_HANDLED); tf = curthread->td_intr_frame; - gi = &sc->gic_irqs[active_irq]; + gi = &GIC_INTR(sc, active_irq); if (active_irq <= GIC_LAST_SGI) { /* Call EOI for all IPI before dispatch. */ gic_icc_write(EOIR1, (uint64_t)active_irq); @@ -1543,11 +1595,11 @@ gic_v3_gic_alloc_msi(device_t dev, u_int mbi_start, u_int mbi_count, break; } - KASSERT((sc->gic_irqs[end_irq].gi_flags & GI_FLAG_MSI)!= 0, + KASSERT((GIC_INTR(sc, end_irq).gi_flags & GI_FLAG_MSI)!= 0, ("%s: Non-MSI interrupt found", __func__)); /* This is already used */ - if ((sc->gic_irqs[end_irq].gi_flags & GI_FLAG_MSI_USED) == + if ((GIC_INTR(sc, end_irq).gi_flags & GI_FLAG_MSI_USED) == GI_FLAG_MSI_USED) { found = false; break; @@ -1565,12 +1617,12 @@ gic_v3_gic_alloc_msi(device_t dev, u_int mbi_start, u_int mbi_count, for (i = 0; i < count; i++) { /* Mark the interrupt as used */ - sc->gic_irqs[irq + i].gi_flags |= GI_FLAG_MSI_USED; + GIC_INTR(sc, irq + i).gi_flags |= GI_FLAG_MSI_USED; } mtx_unlock(&sc->gic_mbi_mtx); for (i = 0; i < count; i++) - isrc[i] = (struct intr_irqsrc *)&sc->gic_irqs[irq + i]; + isrc[i] = GIC_INTR_ISRC(sc, irq + i); return (0); } @@ -1611,9 +1663,9 @@ gic_v3_gic_alloc_msix(device_t dev, u_int mbi_start, u_int mbi_count, mtx_lock(&sc->gic_mbi_mtx); /* Find an unused interrupt */ for (irq = mbi_start; irq < mbi_start + mbi_count; irq++) { - KASSERT((sc->gic_irqs[irq].gi_flags & GI_FLAG_MSI) != 0, + KASSERT((GIC_INTR(sc, irq).gi_flags & GI_FLAG_MSI) != 0, ("%s: Non-MSI interrupt found", __func__)); - if ((sc->gic_irqs[irq].gi_flags & GI_FLAG_MSI_USED) == 0) + if ((GIC_INTR(sc, irq).gi_flags & GI_FLAG_MSI_USED) == 0) break; } /* No free interrupt was found */ @@ -1623,10 +1675,10 @@ gic_v3_gic_alloc_msix(device_t dev, u_int mbi_start, u_int mbi_count, } /* Mark the interrupt as used */ - sc->gic_irqs[irq].gi_flags |= GI_FLAG_MSI_USED; + GIC_INTR(sc, irq).gi_flags |= GI_FLAG_MSI_USED; mtx_unlock(&sc->gic_mbi_mtx); - *isrcp = (struct intr_irqsrc *)&sc->gic_irqs[irq]; + *isrcp = GIC_INTR_ISRC(sc, irq); return (0); } diff --git a/sys/arm64/arm64/gic_v3_acpi.c b/sys/arm64/arm64/gic_v3_acpi.c index 86ddb316da1d41..e7e13cabab06dd 100644 --- a/sys/arm64/arm64/gic_v3_acpi.c +++ b/sys/arm64/arm64/gic_v3_acpi.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm64/arm64/gic_v3_fdt.c b/sys/arm64/arm64/gic_v3_fdt.c index f913d3bfaee660..48db0c88765ae1 100644 --- a/sys/arm64/arm64/gic_v3_fdt.c +++ b/sys/arm64/arm64/gic_v3_fdt.c @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm64/arm64/gic_v3_var.h b/sys/arm64/arm64/gic_v3_var.h index 1c5d354ee2172a..c3655307957e28 100644 --- a/sys/arm64/arm64/gic_v3_var.h +++ b/sys/arm64/arm64/gic_v3_var.h @@ -82,7 +82,7 @@ struct gic_v3_softc { int gic_nchildren; device_t *gic_children; struct intr_pic *gic_pic; - struct gic_v3_irqsrc *gic_irqs; + struct resource *gic_intrs; int nranges; struct arm_gic_range * ranges; @@ -94,7 +94,8 @@ struct gic_v3_devinfo { int is_vgic; }; -#define GIC_INTR_ISRC(sc, irq) (&sc->gic_irqs[irq].gi_isrc) +#define GIC_INTR(sc, irq) (*(struct gic_v3_irqsrc *)intrtab_lookup(rman_get_start((sc)->gic_intrs) + (irq))) +#define GIC_INTR_ISRC(sc, irq) (&GIC_INTR((sc), (irq)).gi_isrc) MALLOC_DECLARE(M_GIC_V3); diff --git a/sys/arm64/arm64/gicv3_its.c b/sys/arm64/arm64/gicv3_its.c index 5ecd9b8c0e9496..c06c4580c2717a 100644 --- a/sys/arm64/arm64/gicv3_its.c +++ b/sys/arm64/arm64/gicv3_its.c @@ -61,7 +61,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm64/arm64/mp_machdep.c b/sys/arm64/arm64/mp_machdep.c index e9b01544347792..e8afcf482476ea 100644 --- a/sys/arm64/arm64/mp_machdep.c +++ b/sys/arm64/arm64/mp_machdep.c @@ -57,7 +57,7 @@ #include #include #include -#include +#include #include #ifdef VFP #include diff --git a/sys/arm64/arm64/nexus.c b/sys/arm64/arm64/nexus.c index d780c9950e639b..d5fbc85dd5d398 100644 --- a/sys/arm64/arm64/nexus.c +++ b/sys/arm64/arm64/nexus.c @@ -54,7 +54,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/arm64/cavium/thunder_pcie_common.c b/sys/arm64/cavium/thunder_pcie_common.c index 1fe6b1a683be4b..0d777e5eeaabe0 100644 --- a/sys/arm64/cavium/thunder_pcie_common.c +++ b/sys/arm64/cavium/thunder_pcie_common.c @@ -40,7 +40,7 @@ #include #include -#include +#include #ifdef FDT #include diff --git a/sys/arm64/cavium/thunder_pcie_pem.c b/sys/arm64/cavium/thunder_pcie_pem.c index 6b57aeee0732b9..70a1f7d6923757 100644 --- a/sys/arm64/cavium/thunder_pcie_pem.c +++ b/sys/arm64/cavium/thunder_pcie_pem.c @@ -57,7 +57,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/arm64/cavium/thunder_pcie_pem_fdt.c b/sys/arm64/cavium/thunder_pcie_pem_fdt.c index 74c9f0e5572830..fb85c8b8567020 100644 --- a/sys/arm64/cavium/thunder_pcie_pem_fdt.c +++ b/sys/arm64/cavium/thunder_pcie_pem_fdt.c @@ -49,7 +49,7 @@ #include #include -#include +#include #include "thunder_pcie_common.h" #include "thunder_pcie_pem.h" diff --git a/sys/arm64/freescale/imx/imx7gpc.c b/sys/arm64/freescale/imx/imx7gpc.c index b3edb0c51adf55..03842cdf7a54b9 100644 --- a/sys/arm64/freescale/imx/imx7gpc.c +++ b/sys/arm64/freescale/imx/imx7gpc.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm64/include/interrupt.h b/sys/arm64/include/interrupt.h new file mode 100644 index 00000000000000..07fa929817ea61 --- /dev/null +++ b/sys/arm64/include/interrupt.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2014 Andrew Turner + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#ifndef __MACHINE_INTERRUPT_H__ +#define __MACHINE_INTERRUPT_H__ + +#include + +#ifdef FDT +#include +#endif + +#ifndef NIRQ +#define NIRQ 16384 /* XXX - It should be an option. */ +#endif + +static inline void +arm_irq_memory_barrier(uintptr_t irq) +{ +} + +#ifdef DEV_ACPI +#define ACPI_INTR_XREF 1 +#define ACPI_MSI_XREF 2 +#define ACPI_GPIO_XREF 3 +#endif + +#define INTR_ROOT_FIQ 1 +#define INTR_ROOT_NUM 2 + +#endif /* __MACHINE_INTERRUPT_H__ */ diff --git a/sys/arm64/include/intr.h b/sys/arm64/include/intr.h index 38cba6ae8b0d7d..e22de7d138870f 100644 --- a/sys/arm64/include/intr.h +++ b/sys/arm64/include/intr.h @@ -1,52 +1,5 @@ /*- - * Copyright (c) 2014 Andrew Turner - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 file is in the public domain. */ -#ifndef _MACHINE_INTR_H_ -#define _MACHINE_INTR_H_ - -#ifdef FDT -#include -#endif - -#ifndef NIRQ -#define NIRQ 16384 /* XXX - It should be an option. */ -#endif - -static inline void -arm_irq_memory_barrier(uintptr_t irq) -{ -} - -#ifdef DEV_ACPI -#define ACPI_INTR_XREF 1 -#define ACPI_MSI_XREF 2 -#define ACPI_GPIO_XREF 3 -#endif - -#define INTR_ROOT_FIQ 1 -#define INTR_ROOT_NUM 2 - -#endif /* _MACHINE_INTR_H */ +#include diff --git a/sys/arm64/intel/stratix10-soc-fpga-mgr.c b/sys/arm64/intel/stratix10-soc-fpga-mgr.c index baa35b9a85a6c8..640f661face7b4 100644 --- a/sys/arm64/intel/stratix10-soc-fpga-mgr.c +++ b/sys/arm64/intel/stratix10-soc-fpga-mgr.c @@ -58,7 +58,7 @@ #include #include -#include +#include #define SVC_BUF_SIZE (512 * 1024) diff --git a/sys/arm64/intel/stratix10-svc.c b/sys/arm64/intel/stratix10-svc.c index d06d8d27e13dad..1eaa6519d4db75 100644 --- a/sys/arm64/intel/stratix10-svc.c +++ b/sys/arm64/intel/stratix10-svc.c @@ -60,7 +60,7 @@ #include #include -#include +#include struct s10_svc_softc { device_t dev; diff --git a/sys/arm64/qoriq/qoriq_dw_pci.c b/sys/arm64/qoriq/qoriq_dw_pci.c index 2d7de343564a67..64544afe9eb97f 100644 --- a/sys/arm64/qoriq/qoriq_dw_pci.c +++ b/sys/arm64/qoriq/qoriq_dw_pci.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm64/rockchip/rk3568_pcie.c b/sys/arm64/rockchip/rk3568_pcie.c index d55bfb1bcc7390..aa6b5dfc5c17e4 100644 --- a/sys/arm64/rockchip/rk3568_pcie.c +++ b/sys/arm64/rockchip/rk3568_pcie.c @@ -55,7 +55,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm64/rockchip/rk_gpio.c b/sys/arm64/rockchip/rk_gpio.c index a86392f1662406..70f0d13cfaf47c 100644 --- a/sys/arm64/rockchip/rk_gpio.c +++ b/sys/arm64/rockchip/rk_gpio.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm64/rockchip/rk_pcie.c b/sys/arm64/rockchip/rk_pcie.c index 54619ca5b1d86b..ed13d233274f05 100644 --- a/sys/arm64/rockchip/rk_pcie.c +++ b/sys/arm64/rockchip/rk_pcie.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/arm64/rockchip/rk_pinctrl.c b/sys/arm64/rockchip/rk_pinctrl.c index 4cf266df3cbfb7..7d8791f06b8395 100644 --- a/sys/arm64/rockchip/rk_pinctrl.c +++ b/sys/arm64/rockchip/rk_pinctrl.c @@ -39,7 +39,7 @@ #include #include -#include +#include #include diff --git a/sys/arm64/vmm/io/vgic_v3.c b/sys/arm64/vmm/io/vgic_v3.c index 67afb3374815ca..460c4089578579 100644 --- a/sys/arm64/vmm/io/vgic_v3.c +++ b/sys/arm64/vmm/io/vgic_v3.c @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/compat/linuxkpi/common/include/linux/hardirq.h b/sys/compat/linuxkpi/common/include/linux/hardirq.h index f79451dd0d35a6..1ec01c95e1e3a8 100644 --- a/sys/compat/linuxkpi/common/include/linux/hardirq.h +++ b/sys/compat/linuxkpi/common/include/linux/hardirq.h @@ -35,8 +35,9 @@ #include #include #include +#include -#define synchronize_irq(irq) _intr_drain((irq)) +#define synchronize_irq(irq) _intr_drain(intr2event(intrtab_lookup((irq)))) /* * FIXME: In the i915 driver's `intel_engine_cs.c` file, diff --git a/sys/compat/linuxkpi/common/include/linux/interrupt.h b/sys/compat/linuxkpi/common/include/linux/interrupt.h index dfd9816da8bee7..a55ba21dabfe06 100644 --- a/sys/compat/linuxkpi/common/include/linux/interrupt.h +++ b/sys/compat/linuxkpi/common/include/linux/interrupt.h @@ -37,6 +37,7 @@ #include #include +#include typedef irqreturn_t (*irq_handler_t)(int, void *); @@ -131,11 +132,12 @@ static inline int irq_set_affinity_hint(int vector, const cpumask_t *mask) { int error; + struct intr_event *event = intr2event(intrtab_lookup(vector)); if (mask != NULL) - error = intr_setaffinity(vector, CPU_WHICH_IRQ, mask); + error = intr_setaffinity(event, CPU_WHICH_IRQ, mask); else - error = intr_setaffinity(vector, CPU_WHICH_IRQ, cpuset_root); + error = intr_setaffinity(event, CPU_WHICH_IRQ, cpuset_root); return (-error); } diff --git a/sys/conf/files b/sys/conf/files index 7bf2cffe8b0979..69f9fe326d0d58 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -3818,6 +3818,7 @@ kern/kern_fork.c standard kern/kern_hhook.c standard kern/kern_idle.c standard kern/kern_intr.c standard +kern/kern_intrtab.c standard kern/kern_jail.c standard kern/kern_kcov.c optional kcov \ compile-with "${NOSAN_C} ${MSAN_CFLAGS}" diff --git a/sys/contrib/ncsw/user/env/xx.c b/sys/contrib/ncsw/user/env/xx.c index ecfe052e59664e..68445c8222c8fc 100644 --- a/sys/contrib/ncsw/user/env/xx.c +++ b/sys/contrib/ncsw/user/env/xx.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kmod.c b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kmod.c index 5b47377735f143..9607bb16c8bc52 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kmod.c +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kmod.c @@ -39,7 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #include diff --git a/sys/dev/beri/beri_mem.c b/sys/dev/beri/beri_mem.c index cc9dba34b494bf..79dd0fe1795a5c 100644 --- a/sys/dev/beri/beri_mem.c +++ b/sys/dev/beri/beri_mem.c @@ -52,7 +52,7 @@ #include #include #include -#include +#include struct beri_mem_softc { struct resource *res[1]; diff --git a/sys/dev/beri/beri_ring.c b/sys/dev/beri/beri_ring.c index 5ff0a74d8b079f..a8a6390a1ae994 100644 --- a/sys/dev/beri/beri_ring.c +++ b/sys/dev/beri/beri_ring.c @@ -56,7 +56,7 @@ #include #include #include -#include +#include #define READ4(_sc, _reg) \ bus_read_4((_sc)->res[0], _reg) diff --git a/sys/dev/beri/virtio/network/if_vtbe.c b/sys/dev/beri/virtio/network/if_vtbe.c index de1a8ebaac9739..559e6657b9ae39 100644 --- a/sys/dev/beri/virtio/network/if_vtbe.c +++ b/sys/dev/beri/virtio/network/if_vtbe.c @@ -74,7 +74,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/dev/beri/virtio/virtio.c b/sys/dev/beri/virtio/virtio.c index 533a6f1209e1c7..2259e46e8658f0 100644 --- a/sys/dev/beri/virtio/virtio.c +++ b/sys/dev/beri/virtio/virtio.c @@ -54,7 +54,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/dev/beri/virtio/virtio_block.c b/sys/dev/beri/virtio/virtio_block.c index 0d4a37ea97724f..dcd9757694c1f9 100644 --- a/sys/dev/beri/virtio/virtio_block.c +++ b/sys/dev/beri/virtio/virtio_block.c @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/dev/cesa/cesa.c b/sys/dev/cesa/cesa.c index 2dcdb0258844d7..a8d05c640e6812 100644 --- a/sys/dev/cesa/cesa.c +++ b/sys/dev/cesa/cesa.c @@ -52,7 +52,7 @@ #include #include -#include +#include #include #include diff --git a/sys/dev/clk/starfive/jh7110_clk.c b/sys/dev/clk/starfive/jh7110_clk.c index adb5707b3f6407..4070114751b96b 100644 --- a/sys/dev/clk/starfive/jh7110_clk.c +++ b/sys/dev/clk/starfive/jh7110_clk.c @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/sys/dev/gpio/dwgpio/dwgpio.c b/sys/dev/gpio/dwgpio/dwgpio.c index 5acb99ca591e36..411cf62e865560 100644 --- a/sys/dev/gpio/dwgpio/dwgpio.c +++ b/sys/dev/gpio/dwgpio/dwgpio.c @@ -56,7 +56,7 @@ #include #include -#include +#include #include "gpio_if.h" #include "dwgpio_if.h" diff --git a/sys/dev/gpio/pl061.c b/sys/dev/gpio/pl061.c index cc39790322b6b1..20d3f9b8372000 100644 --- a/sys/dev/gpio/pl061.c +++ b/sys/dev/gpio/pl061.c @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include diff --git a/sys/dev/gpio/pl061_acpi.c b/sys/dev/gpio/pl061_acpi.c index f5885025083e2e..88e38d43c43a73 100644 --- a/sys/dev/gpio/pl061_acpi.c +++ b/sys/dev/gpio/pl061_acpi.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include diff --git a/sys/dev/hwpmc/hwpmc_core.c b/sys/dev/hwpmc/hwpmc_core.c index bf224ded126f84..2f468d94f0a633 100644 --- a/sys/dev/hwpmc/hwpmc_core.c +++ b/sys/dev/hwpmc/hwpmc_core.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/dev/hwpmc/hwpmc_uncore.c b/sys/dev/hwpmc/hwpmc_uncore.c index 6a7ffac370b740..604d8946ac9304 100644 --- a/sys/dev/hwpmc/hwpmc_uncore.c +++ b/sys/dev/hwpmc/hwpmc_uncore.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/dev/hwpmc/hwpmc_x86.c b/sys/dev/hwpmc/hwpmc_x86.c index 1d04a6610674e3..638fd5813e0d8d 100644 --- a/sys/dev/hwpmc/hwpmc_x86.c +++ b/sys/dev/hwpmc/hwpmc_x86.c @@ -40,7 +40,7 @@ #include #include -#include /* For x86/apicvar.h */ +#include /* For x86/apicvar.h */ #include #include #include diff --git a/sys/dev/hyperv/pcib/vmbus_pcib.c b/sys/dev/hyperv/pcib/vmbus_pcib.c index 7c596c724e52c6..29b8f0bde4416c 100644 --- a/sys/dev/hyperv/pcib/vmbus_pcib.c +++ b/sys/dev/hyperv/pcib/vmbus_pcib.c @@ -49,7 +49,7 @@ #include #if defined(__aarch64__) -#include +#include #endif #include #include @@ -64,7 +64,7 @@ #include #include "pcib_if.h" #if defined(__i386__) || defined(__amd64__) -#include +#include #include #include #endif diff --git a/sys/dev/hyperv/vmbus/vmbus.c b/sys/dev/hyperv/vmbus/vmbus.c index 5d0b23a0921371..52c73219a3a02a 100644 --- a/sys/dev/hyperv/vmbus/vmbus.c +++ b/sys/dev/hyperv/vmbus/vmbus.c @@ -57,7 +57,7 @@ #else #include #include -#include +#include #include #endif #include diff --git a/sys/dev/hyperv/vmbus/x86/vmbus_x86.c b/sys/dev/hyperv/vmbus/x86/vmbus_x86.c index 0ed3b1b5f9d97c..a94205efde3afa 100644 --- a/sys/dev/hyperv/vmbus/x86/vmbus_x86.c +++ b/sys/dev/hyperv/vmbus/x86/vmbus_x86.c @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/dev/iicbus/controller/vybrid/vf_i2c.c b/sys/dev/iicbus/controller/vybrid/vf_i2c.c index ea0e1eeac7fbe8..f9d82c4718b1ca 100644 --- a/sys/dev/iicbus/controller/vybrid/vf_i2c.c +++ b/sys/dev/iicbus/controller/vybrid/vf_i2c.c @@ -55,7 +55,7 @@ #include #include -#include +#include #include diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c index 5081c1a0b782db..188cd850032a32 100644 --- a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c +++ b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -2534,7 +2535,8 @@ mlx5e_open_channels(struct mlx5e_priv *priv) CPU_ZERO(&cpuset); CPU_SET(cpu, &cpuset); - intr_setaffinity(irq, CPU_WHICH_INTRHANDLER, &cpuset); + intr_setaffinity(intr2event(intrtab_lookup(irq)), + CPU_WHICH_INTRHANDLER, &cpuset); } } free(cparam, M_MLX5EN); diff --git a/sys/dev/mmc/host/dwmmc.c b/sys/dev/mmc/host/dwmmc.c index f39a2033f64cda..c9241e53572140 100644 --- a/sys/dev/mmc/host/dwmmc.c +++ b/sys/dev/mmc/host/dwmmc.c @@ -58,7 +58,7 @@ #include #include -#include +#include #include diff --git a/sys/dev/ntb/ntb_hw/ntb_hw_intel.c b/sys/dev/ntb/ntb_hw/ntb_hw_intel.c index d4852917085d74..03ff321e569287 100644 --- a/sys/dev/ntb/ntb_hw/ntb_hw_intel.c +++ b/sys/dev/ntb/ntb_hw/ntb_hw_intel.c @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/dev/ntb/ntb_hw/ntb_hw_plx.c b/sys/dev/ntb/ntb_hw/ntb_hw_plx.c index 9066601160679d..76805d30ceda04 100644 --- a/sys/dev/ntb/ntb_hw/ntb_hw_plx.c +++ b/sys/dev/ntb/ntb_hw/ntb_hw_plx.c @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 843f70a594a019..a53d34fc39c79f 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -61,7 +61,7 @@ #include #if defined(__i386__) || defined(__amd64__) || defined(__powerpc__) -#include +#include #endif #include diff --git a/sys/dev/pci/pci_dw.c b/sys/dev/pci/pci_dw.c index cf67d1ab06cf3a..10f73e0f3970bd 100644 --- a/sys/dev/pci/pci_dw.c +++ b/sys/dev/pci/pci_dw.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/dev/pci/pci_dw_mv.c b/sys/dev/pci/pci_dw_mv.c index 97d957932d42cb..f8c279317c9593 100644 --- a/sys/dev/pci/pci_dw_mv.c +++ b/sys/dev/pci/pci_dw_mv.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/dev/pci/pci_host_generic.c b/sys/dev/pci/pci_host_generic.c index b47a90348388d7..767dd3a8aa0c91 100644 --- a/sys/dev/pci/pci_host_generic.c +++ b/sys/dev/pci/pci_host_generic.c @@ -48,7 +48,7 @@ #include #include -#include +#include #include "pcib_if.h" diff --git a/sys/dev/pci/pci_host_generic_acpi.c b/sys/dev/pci/pci_host_generic_acpi.c index 439d41fb3df648..d274b9b240f1e7 100644 --- a/sys/dev/pci/pci_host_generic_acpi.c +++ b/sys/dev/pci/pci_host_generic_acpi.c @@ -59,7 +59,7 @@ #include #include -#include +#include #include "pcib_if.h" #include "acpi_bus_if.h" diff --git a/sys/dev/pci/pci_host_generic_fdt.c b/sys/dev/pci/pci_host_generic_fdt.c index 3e057553999b8c..67174c2b61e86f 100644 --- a/sys/dev/pci/pci_host_generic_fdt.c +++ b/sys/dev/pci/pci_host_generic_fdt.c @@ -44,9 +44,7 @@ #include #include -#if defined(INTRNG) -#include -#endif +#include #include #include @@ -59,8 +57,6 @@ #include #include -#include - #include "pcib_if.h" #define SPACE_CODE_SHIFT 24 diff --git a/sys/dev/sdhci/fsl_sdhci.c b/sys/dev/sdhci/fsl_sdhci.c index c3c1b6207a23ea..387ba778edbb34 100644 --- a/sys/dev/sdhci/fsl_sdhci.c +++ b/sys/dev/sdhci/fsl_sdhci.c @@ -53,7 +53,7 @@ #include #include #ifdef __arm__ -#include +#include #include #endif diff --git a/sys/dev/sound/macio/davbus.c b/sys/dev/sound/macio/davbus.c index 9dc3676a37a0e5..6ea73365d86659 100644 --- a/sys/dev/sound/macio/davbus.c +++ b/sys/dev/sound/macio/davbus.c @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include diff --git a/sys/dev/sound/macio/i2s.c b/sys/dev/sound/macio/i2s.c index 647d66c27bba64..28c936d4ec864c 100644 --- a/sys/dev/sound/macio/i2s.c +++ b/sys/dev/sound/macio/i2s.c @@ -66,7 +66,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/dev/sound/macio/onyx.c b/sys/dev/sound/macio/onyx.c index d13f3da92db61f..817063b4d2348e 100644 --- a/sys/dev/sound/macio/onyx.c +++ b/sys/dev/sound/macio/onyx.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/dev/sound/macio/snapper.c b/sys/dev/sound/macio/snapper.c index 0b31bded928fa4..c7da48c2c70f8b 100644 --- a/sys/dev/sound/macio/snapper.c +++ b/sys/dev/sound/macio/snapper.c @@ -66,7 +66,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/dev/sound/macio/tumbler.c b/sys/dev/sound/macio/tumbler.c index 505fb7ba15b138..7c1246d001681f 100644 --- a/sys/dev/sound/macio/tumbler.c +++ b/sys/dev/sound/macio/tumbler.c @@ -66,7 +66,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/dev/tpm/tpm_isa.c b/sys/dev/tpm/tpm_isa.c index 311246c16b4974..2ec1633a5d16f6 100644 --- a/sys/dev/tpm/tpm_isa.c +++ b/sys/dev/tpm/tpm_isa.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/dev/vmd/vmd.c b/sys/dev/vmd/vmd.c index 1eeeb630433ab2..8e46f2659372ed 100644 --- a/sys/dev/vmd/vmd.c +++ b/sys/dev/vmd/vmd.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/dev/xen/control/control.c b/sys/dev/xen/control/control.c index 123df49928949f..ba8f5ffdb136d3 100644 --- a/sys/dev/xen/control/control.c +++ b/sys/dev/xen/control/control.c @@ -96,7 +96,7 @@ #include #if defined(__amd64__) || defined(__i386__) -#include +#include #include #endif diff --git a/sys/dev/xen/pcifront/pcifront.c b/sys/dev/xen/pcifront/pcifront.c index d8d2ac48dbb7a9..cbc5e36e2f88a2 100644 --- a/sys/dev/xen/pcifront/pcifront.c +++ b/sys/dev/xen/pcifront/pcifront.c @@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include #include #include diff --git a/sys/dev/xilinx/axi_quad_spi.c b/sys/dev/xilinx/axi_quad_spi.c index 54f4c6aa8810b7..a386d2c4bcbad5 100644 --- a/sys/dev/xilinx/axi_quad_spi.c +++ b/sys/dev/xilinx/axi_quad_spi.c @@ -59,7 +59,7 @@ #include #include -#include +#include #define READ4(_sc, _reg) \ bus_space_read_4(_sc->bst, _sc->bsh, _reg) diff --git a/sys/dev/xilinx/xlnx_pcib.c b/sys/dev/xilinx/xlnx_pcib.c index d549ec445ea942..2a1ec672e58976 100644 --- a/sys/dev/xilinx/xlnx_pcib.c +++ b/sys/dev/xilinx/xlnx_pcib.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include diff --git a/sys/i386/acpica/acpi_wakeup.c b/sys/i386/acpica/acpi_wakeup.c index 2d60d5e037a07e..47ca59bfcd29c5 100644 --- a/sys/i386/acpica/acpi_wakeup.c +++ b/sys/i386/acpica/acpi_wakeup.c @@ -47,7 +47,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 008d67017f687f..c8d33f6caef9fa 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -118,7 +118,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/i386/i386/npx.c b/sys/i386/i386/npx.c index a81413c291b346..99882a5db14246 100644 --- a/sys/i386/i386/npx.c +++ b/sys/i386/i386/npx.c @@ -65,7 +65,7 @@ #include #include -#include +#include #ifdef DEV_ISA #include diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c index 57ba48d399c361..1c90578d4d73d6 100644 --- a/sys/i386/i386/pmap.c +++ b/sys/i386/i386/pmap.c @@ -142,7 +142,7 @@ #ifdef DEV_APIC #include -#include +#include #include #endif #include diff --git a/sys/i386/i386/pmap_base.c b/sys/i386/i386/pmap_base.c index f6252a7ca5dac6..f7931dae9b9cb2 100644 --- a/sys/i386/i386/pmap_base.c +++ b/sys/i386/i386/pmap_base.c @@ -98,7 +98,7 @@ #include #ifdef DEV_APIC #include -#include +#include #include #endif #include diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index 693e3a2f94b48c..6ad3b175b3bb37 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -83,7 +83,7 @@ PMC_SOFT_DEFINE( , , page_fault, write); #include #include -#include +#include #include #include #include diff --git a/sys/i386/include/intr_machdep.h b/sys/i386/include/interrupt.h similarity index 61% rename from sys/i386/include/intr_machdep.h rename to sys/i386/include/interrupt.h index dc9ab793cee560..00ea0c64de8da8 100644 --- a/sys/i386/include/intr_machdep.h +++ b/sys/i386/include/interrupt.h @@ -2,4 +2,4 @@ * This file is in the public domain. */ -#include +#include diff --git a/sys/i386/include/smp.h b/sys/i386/include/smp.h index 7d107da2d93efa..db08124c0c6796 100644 --- a/sys/i386/include/smp.h +++ b/sys/i386/include/smp.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include diff --git a/sys/kern/kern_cpuset.c b/sys/kern/kern_cpuset.c index 5d9e2f2f326be5..8739378c592837 100644 --- a/sys/kern/kern_cpuset.c +++ b/sys/kern/kern_cpuset.c @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -2044,7 +2045,8 @@ kern_cpuset_getaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, case CPU_WHICH_IRQ: case CPU_WHICH_INTRHANDLER: case CPU_WHICH_ITHREAD: - error = intr_getaffinity(id, which, mask); + error = intr_getaffinity(intr2event(intrtab_lookup(id)), + which, mask); break; case CPU_WHICH_DOMAIN: if (id < 0 || id >= MAXMEMDOM) @@ -2205,7 +2207,8 @@ kern_cpuset_setaffinity(struct thread *td, cpulevel_t level, cpuwhich_t which, case CPU_WHICH_IRQ: case CPU_WHICH_INTRHANDLER: case CPU_WHICH_ITHREAD: - error = intr_setaffinity(id, which, mask); + error = intr_setaffinity(intr2event(intrtab_lookup(id)), + which, mask); break; default: error = EINVAL; diff --git a/sys/kern/kern_intr.c b/sys/kern/kern_intr.c index ad0cc135167e70..f096938893275e 100644 --- a/sys/kern/kern_intr.c +++ b/sys/kern/kern_intr.c @@ -276,7 +276,7 @@ intr_event_update(struct intr_event *ie) } int -intr_event_create(struct intr_event **event, void *source, int flags, u_int irq, +intr_event_create(struct intr_event **event, void *source, int flags, void (*pre_ithread)(void *), void (*post_ithread)(void *), void (*post_filter)(void *), int (*assign_cpu)(void *, int), const char *fmt, ...) @@ -294,7 +294,7 @@ intr_event_create(struct intr_event **event, void *source, int flags, u_int irq, ie->ie_post_filter = post_filter; ie->ie_assign_cpu = assign_cpu; ie->ie_flags = flags; - ie->ie_irq = irq; + ie->ie_irq = -1; ie->ie_cpu = NOCPU; CK_SLIST_INIT(&ie->ie_handlers); mtx_init(&ie->ie_lock, "intr event", NULL, MTX_DEF); @@ -427,25 +427,9 @@ intr_event_bind_ithread_cpuset(struct intr_event *ie, cpuset_t *cs) return (ENODEV); } -static struct intr_event * -intr_lookup(int irq) -{ - struct intr_event *ie; - - mtx_lock(&event_lock); - TAILQ_FOREACH(ie, &event_list, ie_list) - if (ie->ie_irq == irq && - (ie->ie_flags & IE_SOFT) == 0 && - CK_SLIST_FIRST(&ie->ie_handlers) != NULL) - break; - mtx_unlock(&event_lock); - return (ie); -} - int -intr_setaffinity(int irq, int mode, const void *m) +intr_setaffinity(struct intr_event *ie, int mode, const void *m) { - struct intr_event *ie; const cpuset_t *mask; int cpu, n; @@ -464,7 +448,6 @@ intr_setaffinity(int irq, int mode, const void *m) cpu = n; } } - ie = intr_lookup(irq); if (ie == NULL) return (ESRCH); switch (mode) { @@ -480,9 +463,8 @@ intr_setaffinity(int irq, int mode, const void *m) } int -intr_getaffinity(int irq, int mode, void *m) +intr_getaffinity(struct intr_event *ie, int mode, void *m) { - struct intr_event *ie; struct thread *td; struct proc *p; cpuset_t *mask; @@ -490,7 +472,6 @@ intr_getaffinity(int irq, int mode, void *m) int error; mask = m; - ie = intr_lookup(irq); if (ie == NULL) return (ESRCH); @@ -817,13 +798,11 @@ intr_handler_barrier(struct intr_handler *handler) * Do not use in BSD code. */ void -_intr_drain(int irq) +_intr_drain(struct intr_event *ie) { - struct intr_event *ie; struct intr_thread *ithd; struct thread *td; - ie = intr_lookup(irq); if (ie == NULL) return; if (ie->ie_thread == NULL) @@ -1046,10 +1025,11 @@ swi_add(struct intr_event **eventp, const char *name, driver_intr_t handler, if (!(ie->ie_flags & IE_SOFT)) return (EINVAL); } else { - error = intr_event_create(&ie, NULL, IE_SOFT, 0, + error = intr_event_create(&ie, NULL, IE_SOFT, NULL, NULL, NULL, swi_assign_cpu, "swi%d:", pri); if (error) return (error); + ie->ie_irq = 0; if (eventp != NULL) *eventp = ie; } diff --git a/sys/kern/kern_intrtab.c b/sys/kern/kern_intrtab.c new file mode 100644 index 00000000000000..1629692e9417d9 --- /dev/null +++ b/sys/kern/kern_intrtab.c @@ -0,0 +1,128 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright © 2023 Elliott Mitchell + * + * 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 AUTHOR 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 AUTHOR 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 +#include +#include +#include +#include +#include +#include +#include + +MALLOC_DECLARE(M_INTRTAB); +MALLOC_DEFINE(M_INTRTAB, "intrtab", "interrupt table handling"); + +/* + * The resource manager for interrupt numbers + */ +static struct rman *mgr; + +/* + * The main table + */ +static interrupt_t **table; + +void +intrtab_setup(struct rman *newmgr) +{ + + if (mgr != NULL || table != NULL) + printf("%s(): called after already initialized!", __func__); + + mgr = newmgr; +} + +void +intrtab_init(void) +{ + + table = mallocarray(mgr->rm_end - mgr->rm_start, sizeof(interrupt_t *), + M_INTRTAB, M_WAITOK | M_ZERO); + table -= mgr->rm_start; +} + +/* + * Allocate a block of interrupt numbers + */ +struct resource * +intrtab_alloc_intr(device_t dev, u_int count) +{ + + return (rman_reserve_resource(mgr, 0, ~0, count, + RF_ACTIVE | RF_UNMAPPED, dev)); +} + +/* + * Release a block of interrupt numbers + */ +void +intrtab_release_intr(struct resource *range) +{ + u_long i; + + if (range == NULL || !rman_is_region_manager(range, mgr)) + return; + + for (i = rman_get_start(range); i <= rman_get_end(range); ++i) + table[i] = NULL; + + rman_release_resource(range); +} + +int +intrtab_set(struct resource *res, u_int intr, interrupt_t *new, + const interrupt_t *const old) +{ + interrupt_t **entr; + + MPASS(intr2event(new) == NULL || _intr2event(new)->ie_irq == intr); + + if (!rman_is_region_manager(res, mgr)) + return (EINVAL); + + if (intr < rman_get_start(res) || intr > rman_get_end(res)) + return (EINVAL); + + entr = table + intr; + + if (*entr != old) + return (EEXIST); + + *entr = new; + return (0); +} + +interrupt_t * +intrtab_lookup(u_int intr) +{ + + if (intr - mgr->rm_start > mgr->rm_end - mgr->rm_start) + return (NULL); + + return (table[intr]); +} diff --git a/sys/kern/subr_intr.c b/sys/kern/subr_intr.c index b8d85bf20f289b..7b3c308d63fb7b 100644 --- a/sys/kern/subr_intr.c +++ b/sys/kern/subr_intr.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -164,7 +165,10 @@ static struct intr_pic *pic_lookup(device_t dev, intptr_t xref, u_int flags); /* Interrupt source definition. */ static struct mtx isrc_table_lock; static struct intr_irqsrc **irq_sources; -static u_int irq_next_free; +static u_int irq_next_free = INTR_IRQ_INVALID; + +static struct rman intr_mgr; +static struct resource *intrng_res; #ifdef SMP #ifdef EARLY_AP_STARTUP @@ -225,8 +229,21 @@ intr_irq_init(void *dummy __unused) /* Allocate the bitmap tracking counter allocations. */ intrcnt_bitmap = bit_alloc(nintrcnt, M_INTRNG, M_WAITOK | M_ZERO); - irq_sources = mallocarray(intr_nirq, sizeof(struct intr_irqsrc*), - M_INTRNG, M_WAITOK | M_ZERO); + intr_mgr.rm_start = 0; + intr_mgr.rm_end = intr_nirq; + intr_mgr.rm_type = RMAN_ARRAY; + intr_mgr.rm_descr = "INTRNG interrupt event manager"; + if (rman_init(&intr_mgr) || rman_manage_region(&intr_mgr, 0, intr_nirq)) + panic("%s(): failure initializing interrupt rman", __func__); + + intrtab_setup(&intr_mgr); + intrtab_init(); + + intrng_res = rman_reserve_resource(&intr_mgr, intr_nirq, intr_nirq, 0, + RF_ACTIVE | RF_UNMAPPED, NULL); + if (intrng_res == NULL) + panic("%s(): unable to initialize INTRNG interrupt region", + __func__); } SYSINIT(intr_irq_init, SI_SUB_INTR, SI_ORDER_FIRST, intr_irq_init, NULL); @@ -436,28 +453,44 @@ intr_isrc_dispatch(struct intr_irqsrc *isrc, struct trapframe *tf) static inline int isrc_alloc_irq(struct intr_irqsrc *isrc) { + u_int limit = rman_get_start(intrng_res); u_int irq; + int rc; mtx_assert(&isrc_table_lock, MA_OWNED); - if (irq_next_free >= intr_nirq) + if (irq_next_free < intr_nirq) { + for (irq = irq_next_free; irq < intr_nirq; irq++) { + if (intrtab_lookup(irq) == NULL) + goto found; + } + for (irq = limit; irq < irq_next_free; irq++) { + if (intrtab_lookup(irq) == NULL) + goto found; + } + } + + if (limit <= 0) { + irq_next_free = intr_nirq; return (ENOSPC); + } else if (limit >= 10) + limit -= 10; + else + limit = 0; - for (irq = irq_next_free; irq < intr_nirq; irq++) { - if (irq_sources[irq] == NULL) - goto found; - } - for (irq = 0; irq < irq_next_free; irq++) { - if (irq_sources[irq] == NULL) - goto found; + if (rman_adjust_resource(intrng_res, limit, intr_nirq) != 0) { + irq_next_free = intr_nirq; + return (ENOSPC); } - irq_next_free = intr_nirq; - return (ENOSPC); + irq = limit; + irq_next_free = limit + 1; found: isrc->isrc_irq = irq; - irq_sources[irq] = isrc; + rc = intrtab_set(intrng_res, irq, isrc, NULL); + if (rc != 0) + panic("Failed to modify interrupt table rc = %d", rc); irq_next_free = irq + 1; if (irq_next_free >= intr_nirq) @@ -471,6 +504,7 @@ isrc_alloc_irq(struct intr_irqsrc *isrc) static inline int isrc_free_irq(struct intr_irqsrc *isrc) { + int rc; mtx_assert(&isrc_table_lock, MA_OWNED); @@ -479,7 +513,9 @@ isrc_free_irq(struct intr_irqsrc *isrc) if (irq_sources[isrc->isrc_irq] != isrc) return (EINVAL); - irq_sources[isrc->isrc_irq] = NULL; + rc = intrtab_set(intrng_res, isrc->isrc_irq, NULL, isrc); + if (rc != 0) + panic("Failed to modify interrupt table rc = %d", rc); isrc->isrc_irq = INTR_IRQ_INVALID; /* just to be safe */ /* @@ -489,7 +525,7 @@ isrc_free_irq(struct intr_irqsrc *isrc) * order. */ if (irq_next_free >= intr_nirq) - irq_next_free = 0; + irq_next_free = rman_get_start(intrng_res); return (0); } @@ -512,6 +548,16 @@ intr_isrc_register(struct intr_irqsrc *isrc, device_t dev, u_int flags, int error; va_list ap; + if (!(flags & (INTR_ISRCF_NOIRQ | INTR_ISRCF_IRQ))) { +#ifdef notyet +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) + printf("WARNING: %s() called without specifying interrupt " + "approach\n", __func__); +#endif +#endif + flags |= INTR_ISRCF_IRQ; + } + bzero(isrc, sizeof(struct intr_irqsrc)); isrc->isrc_dev = dev; isrc->isrc_irq = INTR_IRQ_INVALID; /* just to be safe */ @@ -522,10 +568,12 @@ intr_isrc_register(struct intr_irqsrc *isrc, device_t dev, u_int flags, va_end(ap); mtx_lock(&isrc_table_lock); - error = isrc_alloc_irq(isrc); - if (error != 0) { - mtx_unlock(&isrc_table_lock); - return (error); + if (flags & INTR_ISRCF_IRQ) { + error = isrc_alloc_irq(isrc); + if (error != 0) { + mtx_unlock(&isrc_table_lock); + return (error); + } } /* * Setup interrupt counters, but not for IPI sources. Those are setup @@ -544,12 +592,15 @@ intr_isrc_register(struct intr_irqsrc *isrc, device_t dev, u_int flags, int intr_isrc_deregister(struct intr_irqsrc *isrc) { - int error; + int error = 0; mtx_lock(&isrc_table_lock); if ((isrc->isrc_flags & INTR_ISRCF_IPI) == 0) isrc_release_counters(isrc); - error = isrc_free_irq(isrc); + if (isrc->isrc_irq >= rman_get_start(intrng_res) && + isrc->isrc_irq <= rman_get_end(intrng_res)) { + error = isrc_free_irq(isrc); + } mtx_unlock(&isrc_table_lock); return (error); } @@ -693,11 +744,12 @@ isrc_event_create(struct intr_irqsrc *isrc) struct intr_event *ie; int error; - error = intr_event_create(&ie, isrc, 0, isrc->isrc_irq, + error = intr_event_create(&ie, isrc, 0, intr_isrc_pre_ithread, intr_isrc_post_ithread, intr_isrc_post_filter, intr_isrc_assign_cpu, "%s:", isrc->isrc_name); if (error) return (error); + ie->ie_irq = isrc->isrc_irq; mtx_lock(&isrc_table_lock); /* @@ -1299,7 +1351,7 @@ intr_irq_shuffle(void *arg __unused) mtx_lock(&isrc_table_lock); irq_assign_cpu = true; for (i = 0; i < intr_nirq; i++) { - isrc = irq_sources[i]; + isrc = intrtab_lookup(i); if (isrc == NULL || isrc->isrc_handlers == 0 || isrc->isrc_flags & (INTR_ISRCF_PPI | INTR_ISRCF_IPI)) continue; @@ -1604,7 +1656,7 @@ DB_SHOW_COMMAND_FLAGS(irqs, db_show_irqs, DB_CMD_MEMSAFE) struct intr_irqsrc *isrc; for (irqsum = 0, i = 0; i < intr_nirq; i++) { - isrc = irq_sources[i]; + isrc = intrtab_lookup(i); if (isrc == NULL) continue; diff --git a/sys/powerpc/aim/mp_cpudep.c b/sys/powerpc/aim/mp_cpudep.c index 98acfc1a5c3759..b42ed6e3edd84e 100644 --- a/sys/powerpc/aim/mp_cpudep.c +++ b/sys/powerpc/aim/mp_cpudep.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/amigaone/platform_amigaone.c b/sys/powerpc/amigaone/platform_amigaone.c index d9ff3f85987cec..a118b45fd50104 100644 --- a/sys/powerpc/amigaone/platform_amigaone.c +++ b/sys/powerpc/amigaone/platform_amigaone.c @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/include/intr_machdep.h b/sys/powerpc/include/interrupt.h similarity index 85% rename from sys/powerpc/include/intr_machdep.h rename to sys/powerpc/include/interrupt.h index e46e2b5f9ba97e..afa34a41a2dae6 100644 --- a/sys/powerpc/include/intr_machdep.h +++ b/sys/powerpc/include/interrupt.h @@ -25,8 +25,17 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _MACHINE_INTR_MACHDEP_H_ -#define _MACHINE_INTR_MACHDEP_H_ +#ifndef __MACHINE_INTERRUPT_H__ +#define __MACHINE_INTERRUPT_H__ + +/* FreeBSD standard interrupt controller interface */ + +typedef struct powerpc_intr interrupt_t; + +extern struct intr_event *_intr2event(interrupt_t *intr); +#define intr2event(intr) ((intr) != NULL ? _intr2event(intr) : NULL) + +/* FreeBSD standard interrupt controller interface */ #define INTR_VECTORS 256 @@ -61,4 +70,4 @@ int powerpc_fw_config_intr(int irq, int sense_code); void powerpc_intr_mask(u_int irq); void powerpc_intr_unmask(u_int irq); -#endif /* _MACHINE_INTR_MACHDEP_H_ */ +#endif /* __MACHINE_INTERRUPT_H__ */ diff --git a/sys/powerpc/mpc85xx/atpic.c b/sys/powerpc/mpc85xx/atpic.c index 8c69af8b4b4d23..8a899e40456f37 100644 --- a/sys/powerpc/mpc85xx/atpic.c +++ b/sys/powerpc/mpc85xx/atpic.c @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/mpc85xx/isa.c b/sys/powerpc/mpc85xx/isa.c index d730ecb6f3e9d4..d3880704dad7bb 100644 --- a/sys/powerpc/mpc85xx/isa.c +++ b/sys/powerpc/mpc85xx/isa.c @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/mpc85xx/pci_mpc85xx.c b/sys/powerpc/mpc85xx/pci_mpc85xx.c index 8e349df03a51fd..68061dab8a0641 100644 --- a/sys/powerpc/mpc85xx/pci_mpc85xx.c +++ b/sys/powerpc/mpc85xx/pci_mpc85xx.c @@ -70,7 +70,7 @@ #include #include -#include +#include #include diff --git a/sys/powerpc/mpc85xx/pci_mpc85xx_pcib.c b/sys/powerpc/mpc85xx/pci_mpc85xx_pcib.c index a70df6e1c92229..399b1983bcb720 100644 --- a/sys/powerpc/mpc85xx/pci_mpc85xx_pcib.c +++ b/sys/powerpc/mpc85xx/pci_mpc85xx_pcib.c @@ -56,7 +56,7 @@ #include #include -#include +#include #include "pcib_if.h" diff --git a/sys/powerpc/ofw/ofw_pcib_pci.c b/sys/powerpc/ofw/ofw_pcib_pci.c index 055aab9cf4c631..576067cc9e7329 100644 --- a/sys/powerpc/ofw/ofw_pcib_pci.c +++ b/sys/powerpc/ofw/ofw_pcib_pci.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include "pcib_if.h" diff --git a/sys/powerpc/ofw/ofw_pcibus.c b/sys/powerpc/ofw/ofw_pcibus.c index 9619ccc6c89981..10ff5c5ab7da2d 100644 --- a/sys/powerpc/ofw/ofw_pcibus.c +++ b/sys/powerpc/ofw/ofw_pcibus.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/ofw/openpic_ofw.c b/sys/powerpc/ofw/openpic_ofw.c index fdab55fb30f56b..5dec2619e51fe1 100644 --- a/sys/powerpc/ofw/openpic_ofw.c +++ b/sys/powerpc/ofw/openpic_ofw.c @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powermac/ata_kauai.c b/sys/powerpc/powermac/ata_kauai.c index 1c1c85ef9b44d9..72ba114c87e6cf 100644 --- a/sys/powerpc/powermac/ata_kauai.c +++ b/sys/powerpc/powermac/ata_kauai.c @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/powermac/cpcht.c b/sys/powerpc/powermac/cpcht.c index 138aefda5cdb34..1e87b666346387 100644 --- a/sys/powerpc/powermac/cpcht.c +++ b/sys/powerpc/powermac/cpcht.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powermac/cuda.c b/sys/powerpc/powermac/cuda.c index 367eb7a059c25b..7582efb57491a3 100644 --- a/sys/powerpc/powermac/cuda.c +++ b/sys/powerpc/powermac/cuda.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powermac/grackle.c b/sys/powerpc/powermac/grackle.c index cddf66e6d5f13c..c63029cedca54d 100644 --- a/sys/powerpc/powermac/grackle.c +++ b/sys/powerpc/powermac/grackle.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powermac/hrowpic.c b/sys/powerpc/powermac/hrowpic.c index cd1a1f17694f8c..1f0d017358bf66 100644 --- a/sys/powerpc/powermac/hrowpic.c +++ b/sys/powerpc/powermac/hrowpic.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powermac/macgpio.c b/sys/powerpc/powermac/macgpio.c index 7c4f6911817bd1..41203907e61093 100644 --- a/sys/powerpc/powermac/macgpio.c +++ b/sys/powerpc/powermac/macgpio.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/powermac/macio.c b/sys/powerpc/powermac/macio.c index b6ed3a25995fc2..c5c303f318cf77 100644 --- a/sys/powerpc/powermac/macio.c +++ b/sys/powerpc/powermac/macio.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/powermac/pmu.c b/sys/powerpc/powermac/pmu.c index e0358c6f988748..a3a5d7bb37a448 100644 --- a/sys/powerpc/powermac/pmu.c +++ b/sys/powerpc/powermac/pmu.c @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powermac/smu.c b/sys/powerpc/powermac/smu.c index 8a7e210d5e2ccf..268bc42de6c1a2 100644 --- a/sys/powerpc/powermac/smu.c +++ b/sys/powerpc/powermac/smu.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/powermac/uninorth.c b/sys/powerpc/powermac/uninorth.c index 5df0319bd21353..119383a4fa4160 100644 --- a/sys/powerpc/powermac/uninorth.c +++ b/sys/powerpc/powermac/uninorth.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powermac/uninorthpci.c b/sys/powerpc/powermac/uninorthpci.c index 3df853080f0fdb..022610c86a90f3 100644 --- a/sys/powerpc/powermac/uninorthpci.c +++ b/sys/powerpc/powermac/uninorthpci.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powernv/opal_pci.c b/sys/powerpc/powernv/opal_pci.c index 8dee2c45c089d7..c08296753c510f 100644 --- a/sys/powerpc/powernv/opal_pci.c +++ b/sys/powerpc/powernv/opal_pci.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/powernv/xive.c b/sys/powerpc/powernv/xive.c index 384ff4ef20d262..894b289184dc01 100644 --- a/sys/powerpc/powernv/xive.c +++ b/sys/powerpc/powernv/xive.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/powerpc/autoconf.c b/sys/powerpc/powerpc/autoconf.c index a2f48c2da49c36..d84ddbc3eb7aea 100644 --- a/sys/powerpc/powerpc/autoconf.c +++ b/sys/powerpc/powerpc/autoconf.c @@ -34,7 +34,7 @@ #include #include -#include +#include #ifdef DEV_ISA extern void isa_probe_children(device_t dev); diff --git a/sys/powerpc/powerpc/clock.c b/sys/powerpc/powerpc/clock.c index b294563706dd47..191b07b8dcc7a8 100644 --- a/sys/powerpc/powerpc/clock.c +++ b/sys/powerpc/powerpc/clock.c @@ -72,7 +72,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/powerpc/interrupt.c b/sys/powerpc/powerpc/interrupt.c index c2e79761e1d7cb..d81b07442b7c2e 100644 --- a/sys/powerpc/powerpc/interrupt.c +++ b/sys/powerpc/powerpc/interrupt.c @@ -57,7 +57,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powerpc/intr_machdep.c b/sys/powerpc/powerpc/intr_machdep.c index 9d361c73a24083..05f2366f231d40 100644 --- a/sys/powerpc/powerpc/intr_machdep.c +++ b/sys/powerpc/powerpc/intr_machdep.c @@ -67,18 +67,20 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include #include #include -#include +#include #include #include #include @@ -114,7 +116,6 @@ struct pic { static u_int intrcnt_index = 0; static struct mtx intr_table_lock; -static struct powerpc_intr **powerpc_intrs; static struct pic piclist[MAX_PICS]; static u_int nvectors; /* Allocated vectors */ static u_int npics; /* PICs registered */ @@ -141,6 +142,9 @@ u_int num_io_irqs = 768; u_int num_io_irqs = 256; #endif +static struct rman intr_mgr; +static struct resource *intr_res; + device_t root_pic; #ifdef SMP @@ -167,8 +171,20 @@ static void intr_init_sources(void *arg __unused) { - powerpc_intrs = mallocarray(num_io_irqs, sizeof(*powerpc_intrs), - M_INTR, M_WAITOK | M_ZERO); + intr_mgr.rm_start = 0; + intr_mgr.rm_end = num_io_irqs - 1; + intr_mgr.rm_type = RMAN_ARRAY; + intr_mgr.rm_descr = "PowerPC interrupt event manager"; + if (rman_init(&intr_mgr) || + rman_manage_region(&intr_mgr, intr_mgr.rm_start, intr_mgr.rm_end)) + panic("%s(): failure initializing interrupt rman", __func__); + + intrtab_setup(&intr_mgr); + intrtab_init(); + + intr_res = rman_reserve_resource(&intr_mgr, 0, intr_mgr.rm_end, + num_io_irqs, RF_ACTIVE | RF_UNMAPPED, NULL); + nintrcnt = 1 + num_io_irqs * 2 + mp_ncpus * 2; #ifdef COUNT_IPIS if (mp_ncpus > 1) @@ -197,7 +213,7 @@ smp_intr_init(void *dummy __unused) int vector; for (vector = 0; vector < nvectors; vector++) { - i = powerpc_intrs[vector]; + i = intrtab_lookup(vector); if (i != NULL && i->event != NULL && i->pic == root_pic) PIC_BIND(i->pic, i->intline, i->pi_cpuset, &i->priv); } @@ -227,7 +243,7 @@ intr_lookup(u_int irq) mtx_lock(&intr_table_lock); for (vector = 0; vector < nvectors; vector++) { - i = powerpc_intrs[vector]; + i = intrtab_lookup(vector); if (i != NULL && i->irq == irq) { mtx_unlock(&intr_table_lock); return (i); @@ -259,7 +275,7 @@ intr_lookup(u_int irq) for (vector = 0; vector < num_io_irqs && vector <= nvectors; vector++) { - iscan = powerpc_intrs[vector]; + iscan = intrtab_lookup(vector); if (iscan != NULL && iscan->irq == irq) break; if (iscan == NULL && i->vector == -1) @@ -268,7 +284,9 @@ intr_lookup(u_int irq) } if (iscan == NULL && i->vector != -1) { - powerpc_intrs[i->vector] = i; + int rc = intrtab_set(intr_res, vector, i, NULL); + if (rc != 0) + panic("Failed to modify interrupt table rc = %d", rc); i->cntindex = atomic_fetchadd_int(&intrcnt_index, 1); i->cntp = &intrcnt[i->cntindex]; sprintf(intrname, "irq%u:", i->irq); @@ -285,6 +303,13 @@ intr_lookup(u_int irq) return (i); } +struct intr_event * +_intr2event(interrupt_t *intr) +{ + + return (intr->event); +} + static int powerpc_map_irq(struct powerpc_intr *i) { @@ -487,7 +512,7 @@ powerpc_enable_intr(void) #endif for (vector = 0; vector < nvectors; vector++) { - i = powerpc_intrs[vector]; + i = intrtab_lookup(vector); if (i == NULL) continue; @@ -522,11 +547,12 @@ powerpc_setup_intr(const char *name, u_int irq, driver_filter_t filter, return (ENOMEM); if (i->event == NULL) { - error = intr_event_create(&i->event, (void *)i, 0, irq, + error = intr_event_create(&i->event, (void *)i, 0, powerpc_intr_pre_ithread, powerpc_intr_post_ithread, powerpc_intr_eoi, powerpc_assign_intr_cpu, "irq%u:", irq); if (error) return (error); + i->event->ie_irq = i->vector; enable = 1; } @@ -634,7 +660,7 @@ powerpc_dispatch_intr(u_int vector, struct trapframe *tf) struct powerpc_intr *i; struct intr_event *ie; - i = powerpc_intrs[vector]; + i = intrtab_lookup(vector); if (i == NULL) goto stray; diff --git a/sys/powerpc/powerpc/mp_machdep.c b/sys/powerpc/powerpc/mp_machdep.c index d6d140aa0ea294..bca0960d7333a4 100644 --- a/sys/powerpc/powerpc/mp_machdep.c +++ b/sys/powerpc/powerpc/mp_machdep.c @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/powerpc/nexus.c b/sys/powerpc/powerpc/nexus.c index 2f7b2ba055ff22..2c91c904595c96 100644 --- a/sys/powerpc/powerpc/nexus.c +++ b/sys/powerpc/powerpc/nexus.c @@ -54,7 +54,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/powerpc/openpic.c b/sys/powerpc/powerpc/openpic.c index 0c717aaf6060c2..72283838515e66 100644 --- a/sys/powerpc/powerpc/openpic.c +++ b/sys/powerpc/powerpc/openpic.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/ps3/ps3pic.c b/sys/powerpc/ps3/ps3pic.c index c947b3e3e502f6..fa2c8efbfb4153 100644 --- a/sys/powerpc/ps3/ps3pic.c +++ b/sys/powerpc/ps3/ps3pic.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/pseries/rtas_pci.c b/sys/powerpc/pseries/rtas_pci.c index 02d1a559e7dd16..a782afcd6f2b27 100644 --- a/sys/powerpc/pseries/rtas_pci.c +++ b/sys/powerpc/pseries/rtas_pci.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/powerpc/pseries/vdevice.c b/sys/powerpc/pseries/vdevice.c index 77764d8eb9f197..79d7328be4a5d3 100644 --- a/sys/powerpc/pseries/vdevice.c +++ b/sys/powerpc/pseries/vdevice.c @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/powerpc/pseries/xics.c b/sys/powerpc/pseries/xics.c index 6195307114b750..dba2bb27069976 100644 --- a/sys/powerpc/pseries/xics.c +++ b/sys/powerpc/pseries/xics.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include diff --git a/sys/powerpc/psim/openpic_iobus.c b/sys/powerpc/psim/openpic_iobus.c index bf5bd8235a6c6f..7033d41ea87300 100644 --- a/sys/powerpc/psim/openpic_iobus.c +++ b/sys/powerpc/psim/openpic_iobus.c @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/riscv/include/interrupt.h b/sys/riscv/include/interrupt.h new file mode 100644 index 00000000000000..d6b1bf9af54e33 --- /dev/null +++ b/sys/riscv/include/interrupt.h @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2015-2016 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 AUTHOR 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 AUTHOR 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. + */ + +#ifndef __MACHINE_INTERRUPT_H__ +#define __MACHINE_INTERRUPT_H__ + +#include + +#ifndef NIRQ +#define NIRQ 1024 +#endif + +enum { + IRQ_SOFTWARE_USER, + IRQ_SOFTWARE_SUPERVISOR, + IRQ_SOFTWARE_HYPERVISOR, + IRQ_SOFTWARE_MACHINE, + IRQ_TIMER_USER, + IRQ_TIMER_SUPERVISOR, + IRQ_TIMER_HYPERVISOR, + IRQ_TIMER_MACHINE, + IRQ_EXTERNAL_USER, + IRQ_EXTERNAL_SUPERVISOR, + IRQ_EXTERNAL_HYPERVISOR, + IRQ_EXTERNAL_MACHINE, +}; + +#endif /* !__MACHINE_INTERRUPT_H__ */ diff --git a/sys/riscv/include/intr.h b/sys/riscv/include/intr.h index 657781efb62061..e22de7d138870f 100644 --- a/sys/riscv/include/intr.h +++ b/sys/riscv/include/intr.h @@ -1,57 +1,5 @@ /*- - * Copyright (c) 2015-2016 Ruslan Bukin - * All rights reserved. - * - * Portions of this software were developed by SRI International and the - * University of Cambridge Computer Laboratory under DARPA/AFRL contract - * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. - * - * Portions of this software were developed by the University of Cambridge - * Computer Laboratory as part of the CTSRD Project, with support from the - * UK Higher Education Innovation Fund (HEIF). - * - * 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 AUTHOR 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 AUTHOR 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 file is in the public domain. */ -#ifndef _MACHINE_INTR_MACHDEP_H_ -#define _MACHINE_INTR_MACHDEP_H_ - -#ifndef NIRQ -#define NIRQ 1024 -#endif - -enum { - IRQ_SOFTWARE_USER, - IRQ_SOFTWARE_SUPERVISOR, - IRQ_SOFTWARE_HYPERVISOR, - IRQ_SOFTWARE_MACHINE, - IRQ_TIMER_USER, - IRQ_TIMER_SUPERVISOR, - IRQ_TIMER_HYPERVISOR, - IRQ_TIMER_MACHINE, - IRQ_EXTERNAL_USER, - IRQ_EXTERNAL_SUPERVISOR, - IRQ_EXTERNAL_HYPERVISOR, - IRQ_EXTERNAL_MACHINE, -}; - -#endif /* !_MACHINE_INTR_MACHDEP_H_ */ +#include diff --git a/sys/riscv/riscv/aplic.c b/sys/riscv/riscv/aplic.c index 6550b7ba36d138..a2f7e019832e26 100644 --- a/sys/riscv/riscv/aplic.c +++ b/sys/riscv/riscv/aplic.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include diff --git a/sys/riscv/riscv/genassym.c b/sys/riscv/riscv/genassym.c index 74b70858edab64..13ab53a57fcb68 100644 --- a/sys/riscv/riscv/genassym.c +++ b/sys/riscv/riscv/genassym.c @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/riscv/riscv/intc.c b/sys/riscv/riscv/intc.c index 248175e8bea39f..551132362971fd 100644 --- a/sys/riscv/riscv/intc.c +++ b/sys/riscv/riscv/intc.c @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c index eda7ebc32bbf68..d80bb8125b0a24 100644 --- a/sys/riscv/riscv/machdep.c +++ b/sys/riscv/riscv/machdep.c @@ -81,7 +81,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/riscv/riscv/nexus.c b/sys/riscv/riscv/nexus.c index b8b4eb6604aed4..70631152bd84eb 100644 --- a/sys/riscv/riscv/nexus.c +++ b/sys/riscv/riscv/nexus.c @@ -52,7 +52,7 @@ #include #include -#include +#include #ifdef FDT #include diff --git a/sys/riscv/riscv/plic.c b/sys/riscv/riscv/plic.c index b7dda1d19daf9c..6b514ff1602196 100644 --- a/sys/riscv/riscv/plic.c +++ b/sys/riscv/riscv/plic.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include diff --git a/sys/riscv/riscv/riscv_console.c b/sys/riscv/riscv/riscv_console.c index e582b338538435..1f4c16e536e544 100644 --- a/sys/riscv/riscv/riscv_console.c +++ b/sys/riscv/riscv/riscv_console.c @@ -59,7 +59,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/riscv/riscv/sbi_ipi.c b/sys/riscv/riscv/sbi_ipi.c index fac5c0c39b997e..c8400cd2dfd391 100644 --- a/sys/riscv/riscv/sbi_ipi.c +++ b/sys/riscv/riscv/sbi_ipi.c @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include diff --git a/sys/riscv/sifive/fe310_aon.c b/sys/riscv/sifive/fe310_aon.c index d64cf12ff456a0..d18f3b6e680536 100644 --- a/sys/riscv/sifive/fe310_aon.c +++ b/sys/riscv/sifive/fe310_aon.c @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include "clock_if.h" diff --git a/sys/riscv/sifive/fu740_pci_dw.c b/sys/riscv/sifive/fu740_pci_dw.c index d0490d6548f24e..734eb5d5ca5bbb 100644 --- a/sys/riscv/sifive/fu740_pci_dw.c +++ b/sys/riscv/sifive/fu740_pci_dw.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/riscv/vmm/vmm_riscv.c b/sys/riscv/vmm/vmm_riscv.c index 6a76f8cf4f2601..ce50bfc69be769 100644 --- a/sys/riscv/vmm/vmm_riscv.c +++ b/sys/riscv/vmm/vmm_riscv.c @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include #include diff --git a/sys/sys/interrupt.h b/sys/sys/interrupt.h index 899d65e386e0ab..f6c12390f8d6f8 100644 --- a/sys/sys/interrupt.h +++ b/sys/sys/interrupt.h @@ -175,10 +175,10 @@ struct _cpuset; int intr_event_bind_ithread_cpuset(struct intr_event *ie, struct _cpuset *mask); int intr_event_create(struct intr_event **event, void *source, - int flags, u_int irq, void (*pre_ithread)(void *), + int flags, void (*pre_ithread)(void *), void (*post_ithread)(void *), void (*post_filter)(void *), int (*assign_cpu)(void *, int), const char *fmt, ...) - __printflike(9, 10); + __printflike(8, 9); int intr_event_describe_handler(struct intr_event *ie, void *cookie, const char *descr); int intr_event_destroy(struct intr_event *ie); @@ -186,10 +186,10 @@ int intr_event_handle(struct intr_event *ie, struct trapframe *frame); int intr_event_remove_handler(void *cookie); int intr_event_suspend_handler(void *cookie); int intr_event_resume_handler(void *cookie); -int intr_getaffinity(int irq, int mode, void *mask); +int intr_getaffinity(struct intr_event *ie, int mode, void *mask); void *intr_handler_source(void *cookie); -int intr_setaffinity(int irq, int mode, const void *mask); -void _intr_drain(int irq); /* LinuxKPI only. */ +int intr_setaffinity(struct intr_event *ie, int mode, const void *mask); +void _intr_drain(struct intr_event *ie); /* LinuxKPI only. */ int swi_add(struct intr_event **eventp, const char *name, driver_intr_t handler, void *arg, int pri, enum intr_type flags, void **cookiep); diff --git a/sys/sys/intr.h b/sys/sys/intr.h index f11e96777927a9..01c4f5c2001ccd 100644 --- a/sys/sys/intr.h +++ b/sys/sys/intr.h @@ -37,6 +37,15 @@ #include +/* FreeBSD standard interrupt controller interface */ + +typedef struct intr_irqsrc interrupt_t; + +#define _intr2event(intr) ((intr)->isrc_event) +#define intr2event(intr) ((intr) != NULL ? _intr2event(intr) : NULL) + +/* FreeBSD standard interrupt controller interface */ + #define INTR_IRQ_INVALID 0xFFFFFFFF #define INTR_ROOT_IRQ 0 @@ -78,6 +87,8 @@ typedef int intr_child_irq_filter_t(void *arg, uintptr_t irq); #define INTR_ISRCF_IPI 0x01 /* IPI interrupt */ #define INTR_ISRCF_PPI 0x02 /* PPI interrupt */ #define INTR_ISRCF_BOUND 0x04 /* bound to a CPU */ +#define INTR_ISRCF_NOIRQ 0x10 /* don't allocate interrupt # */ +#define INTR_ISRCF_IRQ 0x20 /* allocate an interrupt # */ struct intr_pic; diff --git a/sys/sys/intrtab.h b/sys/sys/intrtab.h new file mode 100644 index 00000000000000..8110b309d072ed --- /dev/null +++ b/sys/sys/intrtab.h @@ -0,0 +1,82 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright © 2023 Elliott Mitchell + * + * 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 AUTHOR 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 AUTHOR 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. + */ + +#ifndef _SYS_INTRTAB_H_ +#define _SYS_INTRTAB_H_ + +#include + +#include +#include +#include + +#include + +/* + * Initialize the interrupt table + * + * newmgr: used to ensure ownership of allocated interrupt numbers. + */ +extern void intrtab_setup(struct rman *newmgr); + +/* + * Initialize interrupt table internals + * + * Call after intrtab_setup() to intialize the internals to an operational + * state. + */ +extern void intrtab_init(void); + +/* + * Allocate a block of interrupt numbers + */ +extern struct resource *intrtab_alloc_intr(device_t dev, u_int count); + +/* + * Release a block of interrupt numbers + */ +extern void intrtab_release_intr(struct resource *res); + +/* + * Set the interrupt associated with an interrupt number + * + * res: resource indicating ownership of interrupt number. + * intr: interrupt number to modify. + * new: pointer to new interrupt. + * old: pointer to existing interrupt (ensure consistency). + */ +extern int intrtab_set(struct resource *res, u_int intr, interrupt_t *new, + const interrupt_t *const old) __result_use_check; + +/* + * Lookup an interrupt number + * + * intr: interrupt number to lookup. + */ +extern interrupt_t *intrtab_lookup(u_int intr) __pure; + +#endif diff --git a/sys/x86/acpica/madt.c b/sys/x86/acpica/madt.c index a593028ffb5ab9..4d5ddb84b3f4d7 100644 --- a/sys/x86/acpica/madt.c +++ b/sys/x86/acpica/madt.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include #include diff --git a/sys/x86/include/intr_machdep.h b/sys/x86/include/interrupt.h similarity index 92% rename from sys/x86/include/intr_machdep.h rename to sys/x86/include/interrupt.h index d7bfcdc126a9e4..69bf861e8b27fc 100644 --- a/sys/x86/include/intr_machdep.h +++ b/sys/x86/include/interrupt.h @@ -25,11 +25,20 @@ * SUCH DAMAGE. */ -#ifndef __X86_INTR_MACHDEP_H__ -#define __X86_INTR_MACHDEP_H__ +#ifndef __MACHINE_INTERRUPT_H__ +#define __MACHINE_INTERRUPT_H__ #ifdef _KERNEL +/* FreeBSD standard interrupt controller interface */ + +typedef struct intsrc interrupt_t; + +#define _intr2event(intr) ((intr)->is_event) +#define intr2event(intr) ((intr) != NULL ? _intr2event(intr) : NULL) + +/* FreeBSD standard interrupt controller interface */ + /* * Values used in determining the allocation of IRQ values among * different types of I/O interrupts. These values are used as @@ -62,8 +71,6 @@ extern u_int num_msi_irqs; */ #define MSI_INTEL_ADDR_BASE 0xfee00000 -#ifndef LOCORE - typedef void inthand_t(void); #define IDTVEC(name) __CONCAT(X,name) @@ -82,7 +89,6 @@ struct pic { void (*pic_eoi_source)(struct intsrc *); void (*pic_enable_intr)(struct intsrc *); void (*pic_disable_intr)(struct intsrc *); - int (*pic_vector)(struct intsrc *); int (*pic_source_pending)(struct intsrc *); void (*pic_suspend)(struct pic *); void (*pic_resume)(struct pic *, bool suspend_cancelled); @@ -146,9 +152,9 @@ int intr_config_intr(struct intsrc *isrc, enum intr_trigger trig, int intr_describe(struct intsrc *isrc, void *ih, const char *descr); void intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame); u_int intr_next_cpu(int domain); -struct intsrc *intr_lookup_source(int vector); int intr_register_pic(struct pic *pic); -int intr_register_source(struct intsrc *isrc); +int intr_register_source(struct resource *ires, u_int vector, + struct intsrc *isrc); int intr_remove_handler(void *cookie); void intr_resume(bool suspend_cancelled); void intr_suspend(void); @@ -165,6 +171,5 @@ int msix_release(int irq); void xen_intr_alloc_irqs(void); #endif -#endif /* !LOCORE */ #endif /* _KERNEL */ -#endif /* !__X86_INTR_MACHDEP_H__ */ +#endif /* !__MACHINE_INTERRUPT_H__ */ diff --git a/sys/x86/include/x86_smp.h b/sys/x86/include/x86_smp.h index 8b9eb2ec9b6629..ae43d6d5f8b965 100644 --- a/sys/x86/include/x86_smp.h +++ b/sys/x86/include/x86_smp.h @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include diff --git a/sys/x86/include/xen/arch-intr.h b/sys/x86/include/xen/arch-intr.h index 5ce0ca06e925c1..20a60db2605f6a 100644 --- a/sys/x86/include/xen/arch-intr.h +++ b/sys/x86/include/xen/arch-intr.h @@ -29,12 +29,11 @@ #ifndef _MACHINE__XEN_ARCH_INTR_H_ #define _MACHINE__XEN_ARCH_INTR_H_ -#include +#include #include typedef struct { struct intsrc intsrc; /* @TOP -> *xen_arch_isrc */ - u_int vector; /* Global isrc vector number */ } xen_arch_isrc_t; #include diff --git a/sys/x86/iommu/amd_drv.c b/sys/x86/iommu/amd_drv.c index 257de73baab5a1..a3b1087be380f6 100644 --- a/sys/x86/iommu/amd_drv.c +++ b/sys/x86/iommu/amd_drv.c @@ -60,7 +60,7 @@ #include #include #include "pcib_if.h" -#include +#include #include #include #include diff --git a/sys/x86/iommu/amd_event.c b/sys/x86/iommu/amd_event.c index 4a52e42260c232..325c3f576365eb 100644 --- a/sys/x86/iommu/amd_event.c +++ b/sys/x86/iommu/amd_event.c @@ -58,7 +58,7 @@ #include #include #include "pcib_if.h" -#include +#include #include #include #include diff --git a/sys/x86/iommu/amd_intrmap.c b/sys/x86/iommu/amd_intrmap.c index a4c1a783626844..3706468d8f8d7d 100644 --- a/sys/x86/iommu/amd_intrmap.c +++ b/sys/x86/iommu/amd_intrmap.c @@ -63,7 +63,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/x86/iommu/intel_drv.c b/sys/x86/iommu/intel_drv.c index b21c8460e83008..f268adab197ee9 100644 --- a/sys/x86/iommu/intel_drv.c +++ b/sys/x86/iommu/intel_drv.c @@ -75,7 +75,7 @@ #ifdef DEV_APIC #include "pcib_if.h" -#include +#include #include #include #endif diff --git a/sys/x86/iommu/intel_intrmap.c b/sys/x86/iommu/intel_intrmap.c index 06e41523624b89..0ae2bfbc859f0d 100644 --- a/sys/x86/iommu/intel_intrmap.c +++ b/sys/x86/iommu/intel_intrmap.c @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/x86/iommu/intel_utils.c b/sys/x86/iommu/intel_utils.c index 287b5fe9376ab3..e327f21ed44615 100644 --- a/sys/x86/iommu/intel_utils.c +++ b/sys/x86/iommu/intel_utils.c @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/x86/iommu/iommu_utils.c b/sys/x86/iommu/iommu_utils.c index 2db02a98ca914e..f9c5db5f33c9f3 100644 --- a/sys/x86/iommu/iommu_utils.c +++ b/sys/x86/iommu/iommu_utils.c @@ -69,7 +69,7 @@ #include #ifdef DEV_APIC #include "pcib_if.h" -#include +#include #include #include #endif diff --git a/sys/x86/isa/atpic.c b/sys/x86/isa/atpic.c index 4ea80cfff7f94d..7aa0b20e435964 100644 --- a/sys/x86/isa/atpic.c +++ b/sys/x86/isa/atpic.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ #include #include -#include +#include #include #include #include @@ -100,7 +101,6 @@ inthand_t .pic_eoi_source = (eoi), \ .pic_enable_intr = atpic_enable_intr, \ .pic_disable_intr = atpic_disable_intr, \ - .pic_vector = atpic_vector, \ .pic_source_pending = atpic_source_pending, \ .pic_resume = atpic_resume, \ .pic_config_intr = atpic_config_intr, \ @@ -174,6 +174,8 @@ static struct atpic_intsrc atintrs[] = { CTASSERT(nitems(atintrs) == NUM_ISA_IRQS); +static struct resource *isa_intrs; + static __inline void _atpic_eoi_master(struct intsrc *isrc) { @@ -227,15 +229,17 @@ atpic_register_sources(struct pic *pic) */ if (ap != &atpics[MASTER]) return; + if (isa_intrs == NULL) + return; for (i = 0; i < NUM_ISA_IRQS; i++) - if (intr_lookup_source(i) != NULL) + if (intrtab_lookup(i) != NULL) return; /* Loop through all interrupt sources and add them. */ for (i = 0, ai = atintrs; i < NUM_ISA_IRQS; i++, ai++) { if (i == ICU_SLAVEID) continue; - intr_register_source(&ai->at_intsrc); + intr_register_source(isa_intrs, i, &ai->at_intsrc); } } @@ -512,8 +516,13 @@ atpic_init(void *dummy __unused) intr_register_pic(&atpics[1].at_pic) != 0) panic("Unable to register ATPICs"); - if (num_io_irqs == 0) - num_io_irqs = NUM_ISA_IRQS; + isa_intrs = intrtab_alloc_intr(NULL, NUM_ISA_IRQS); + if (isa_intrs == NULL) + panic("%s(): failed reserving interrupts", __func__); + if (rman_get_start(isa_intrs) != 0) { + intrtab_release_intr(isa_intrs); + isa_intrs = NULL; + } } SYSINIT(atpic_init, SI_SUB_INTR, SI_ORDER_FOURTH, atpic_init, NULL); diff --git a/sys/x86/isa/atrtc.c b/sys/x86/isa/atrtc.c index 63f41d866679cc..3e753aba31b9e1 100644 --- a/sys/x86/isa/atrtc.c +++ b/sys/x86/isa/atrtc.c @@ -50,7 +50,7 @@ #include #include #endif -#include +#include #include "clock_if.h" #ifdef DEV_ACPI #include diff --git a/sys/x86/isa/clock.c b/sys/x86/isa/clock.c index 68d6085d5891e0..97f818781ac67c 100644 --- a/sys/x86/isa/clock.c +++ b/sys/x86/isa/clock.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,7 @@ #include #include -#include +#include #include #include #include @@ -569,7 +570,7 @@ attimer_attach(device_t dev) if (!(sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid, IO_TIMER1, IO_TIMER1 + 3, 4, RF_ACTIVE))) device_printf(dev,"Warning: Couldn't map I/O.\n"); - i8254_intsrc = intr_lookup_source(0); + i8254_intsrc = intrtab_lookup(0); if (i8254_intsrc != NULL) i8254_pending = i8254_intsrc->is_pic->pic_source_pending; resource_int_value(device_get_name(dev), device_get_unit(dev), diff --git a/sys/x86/isa/elcr.c b/sys/x86/isa/elcr.c index 6d400fefafa360..fadd5a54e7aad5 100644 --- a/sys/x86/isa/elcr.c +++ b/sys/x86/isa/elcr.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #define ELCR_PORT 0x4d0 #define ELCR_MASK(irq) (1 << (irq)) diff --git a/sys/x86/x86/identcpu.c b/sys/x86/x86/identcpu.c index d3aec5b5e0c6b6..07a39df9338a6d 100644 --- a/sys/x86/x86/identcpu.c +++ b/sys/x86/x86/identcpu.c @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/x86/x86/intr_machdep.c b/sys/x86/x86/intr_machdep.c index 023c3df22580de..a74c1295e6f9c4 100644 --- a/sys/x86/x86/intr_machdep.c +++ b/sys/x86/x86/intr_machdep.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,7 @@ #include #include #include -#include +#include #include #ifdef DDB #include @@ -87,6 +88,7 @@ static struct sx intrsrc_lock; static struct mtx intrpic_lock; static struct mtx intrcnt_lock; static TAILQ_HEAD(pics_head, pic) pics; +static struct rman intr_mgr; u_int num_io_irqs; #if defined(SMP) && !defined(EARLY_AP_STARTUP) @@ -164,11 +166,15 @@ static void intr_init_sources(void *arg) { struct pic *pic; + rman_res_t end, discard; MPASS(num_io_irqs > 0); - interrupt_sources = mallocarray(num_io_irqs, sizeof(*interrupt_sources), - M_INTR, M_WAITOK | M_ZERO); + if (rman_last_free_region(&intr_mgr, &end, &discard) != 0) + panic("%s(): failure retrieving IRQ range", __func__); + intr_mgr.rm_end = end; + intrtab_init(); + #ifdef SMP interrupt_sorted = mallocarray(num_io_irqs, sizeof(*interrupt_sorted), M_INTR, M_WAITOK | M_ZERO); @@ -216,44 +222,35 @@ SYSINIT(intr_init_sources, SI_SUB_INTR, SI_ORDER_FOURTH + 1, intr_init_sources, * called. */ int -intr_register_source(struct intsrc *isrc) +intr_register_source(struct resource *ires, u_int vector, struct intsrc *isrc) { - int error, vector; + int error; KASSERT(intr_pic_registered(isrc->is_pic), ("unregistered PIC")); - vector = isrc->is_pic->pic_vector(isrc); - KASSERT(vector < num_io_irqs, ("IRQ %d too large (%u irqs)", vector, - num_io_irqs)); - if (interrupt_sources[vector] != NULL) + if (vector < num_io_irqs && intrtab_lookup(vector) != NULL) return (EEXIST); - error = intr_event_create(&isrc->is_event, isrc, 0, vector, + error = intr_event_create(&isrc->is_event, isrc, 0, intr_disable_src, (mask_fn)isrc->is_pic->pic_enable_source, (mask_fn)isrc->is_pic->pic_eoi_source, intr_assign_cpu, "irq%d:", vector); if (error) return (error); - sx_xlock(&intrsrc_lock); - if (interrupt_sources[vector] != NULL) { + isrc->is_event->ie_irq = vector; + isrc->is_handlers = 0; + if (ires != NULL) { + sx_xlock(&intrsrc_lock); + error = intrtab_set(ires, vector, isrc, NULL); + if (error != 0) { + sx_xunlock(&intrsrc_lock); + intr_event_destroy(isrc->is_event); + isrc->is_event = NULL; + return (error); + } sx_xunlock(&intrsrc_lock); - intr_event_destroy(isrc->is_event); - return (EEXIST); } - intrcnt_register(isrc); - interrupt_sources[vector] = isrc; - isrc->is_handlers = 0; - sx_xunlock(&intrsrc_lock); return (0); } -struct intsrc * -intr_lookup_source(int vector) -{ - - if (vector < 0 || vector >= num_io_irqs) - return (NULL); - return (interrupt_sources[vector]); -} - int intr_add_handler(struct intsrc *isrc, const char *name, driver_filter_t filter, driver_intr_t handler, void *arg, enum intr_type flags, void **cookiep, @@ -336,7 +333,7 @@ intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame) * XXX: We assume that IRQ 0 is only used for the ISA timer * device (clk). */ - vector = isrc->is_pic->pic_vector(isrc); + vector = isrc->is_event->ie_irq; if (vector == 0) clkintr_pending = 1; @@ -436,7 +433,7 @@ intrcnt_register(struct intsrc *is) is->is_index = intrcnt_index; intrcnt_index += 2; snprintf(straystr, sizeof(straystr), "stray irq%d", - is->is_pic->pic_vector(is)); + is->is_event->ie_irq); intrcnt_updatename(is); is->is_count = &intrcnt[is->is_index]; intrcnt_setname(straystr, is->is_index + 1); @@ -464,6 +461,16 @@ intr_init(void *dummy __unused) mtx_init(&intrpic_lock, "intrpic", NULL, MTX_DEF); sx_init(&intrsrc_lock, "intrsrc"); mtx_init(&intrcnt_lock, "intrcnt", NULL, MTX_SPIN); + + intr_mgr.rm_start = 0; + intr_mgr.rm_end = -1; + intr_mgr.rm_type = RMAN_ARRAY; + intr_mgr.rm_descr = "x86 interrupt event manager"; + if (rman_init(&intr_mgr) || + rman_manage_region(&intr_mgr, intr_mgr.rm_start, intr_mgr.rm_end)) + panic("%s(): failure initializing interrupt rman", __func__); + + intrtab_setup(&intr_mgr); } SYSINIT(intr_init, SI_SUB_INTR, SI_ORDER_FIRST, intr_init, NULL); diff --git a/sys/x86/x86/io_apic.c b/sys/x86/x86/io_apic.c index 525547f9482a91..762290b240b276 100644 --- a/sys/x86/x86/io_apic.c +++ b/sys/x86/x86/io_apic.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,7 @@ #include #include -#include +#include #include #include #include @@ -92,11 +93,10 @@ struct ioapic_intsrc { struct ioapic { struct pic io_pic; + struct resource *intrs; u_int io_id:8; /* logical ID */ u_int io_apic_id:8; /* Id as enumerated by MADT */ u_int io_hw_apic_id:8; /* Content of APIC ID register */ - u_int io_intbase:8; /* System Interrupt base */ - u_int io_numintr:8; u_int io_haseoi:1; volatile ioapic_t *io_addr; /* XXX: should use bus_space */ vm_paddr_t io_paddr; @@ -117,7 +117,6 @@ static void ioapic_disable_source(struct intsrc *isrc, int eoi); static void ioapic_eoi_source(struct intsrc *isrc); static void ioapic_enable_intr(struct intsrc *isrc); static void ioapic_disable_intr(struct intsrc *isrc); -static int ioapic_vector(struct intsrc *isrc); static int ioapic_source_pending(struct intsrc *isrc); static int ioapic_config_intr(struct intsrc *isrc, enum intr_trigger trig, enum intr_polarity pol); @@ -134,7 +133,6 @@ struct pic ioapic_template = { .pic_eoi_source = ioapic_eoi_source, .pic_enable_intr = ioapic_enable_intr, .pic_disable_intr = ioapic_disable_intr, - .pic_vector = ioapic_vector, .pic_source_pending = ioapic_source_pending, .pic_suspend = NULL, .pic_resume = ioapic_resume, @@ -528,15 +526,6 @@ ioapic_disable_intr(struct intsrc *isrc) } } -static int -ioapic_vector(struct intsrc *isrc) -{ - struct ioapic_intsrc *pin; - - pin = (struct ioapic_intsrc *)isrc; - return (pin->io_irq); -} - static int ioapic_source_pending(struct intsrc *isrc) { @@ -598,7 +587,8 @@ ioapic_resume(struct pic *pic, bool suspend_cancelled) int i; mtx_lock_spin(&icu_lock); - for (i = 0; i < io->io_numintr; i++) + for (i = 0; i < rman_get_end(io->intrs) - rman_get_start(io->intrs); + i++) ioapic_program_intpin(&io->io_pins[i]); mtx_unlock_spin(&icu_lock); } @@ -649,11 +639,22 @@ ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase) } else if (intbase != next_ioapic_base && bootverbose) printf("ioapic%u: WARNING: intbase %d != expected base %d\n", io->io_id, intbase, next_ioapic_base); - io->io_intbase = intbase; + + io->intrs = intrtab_alloc_intr(NULL, numintr); + if (io->intrs == NULL) + panic("%s(): failed allocating interrupt resource", __func__); + + if (rman_get_start(io->intrs) < intbase) { + if (rman_adjust_resource(io->intrs, rman_get_start(io->intrs), + intbase + numintr) != 0) + panic("%s(): failed setting upper interrupt", __func__); + if (rman_adjust_resource(io->intrs, intbase, intbase + numintr) + != 0) + panic("%s(): failed setting lower interrupt", __func__); + } else if (rman_get_start(io->intrs) > intbase) + panic("%s(): unable to get lowest interrupt", __func__); + next_ioapic_base = intbase + numintr; - if (next_ioapic_base > num_io_irqs) - num_io_irqs = next_ioapic_base; - io->io_numintr = numintr; io->io_addr = apic; io->io_paddr = addr; @@ -732,7 +733,7 @@ ioapic_get_vector(void *cookie, u_int pin) struct ioapic *io; io = (struct ioapic *)cookie; - if (pin >= io->io_numintr) + if (pin >= rman_get_end(io->intrs) - rman_get_start(io->intrs)) return (-1); return (io->io_pins[pin].io_irq); } @@ -743,7 +744,7 @@ ioapic_disable_pin(void *cookie, u_int pin) struct ioapic *io; io = (struct ioapic *)cookie; - if (pin >= io->io_numintr) + if (pin >= rman_get_end(io->intrs) - rman_get_start(io->intrs)) return (EINVAL); if (io->io_pins[pin].io_irq == IRQ_DISABLED) return (EINVAL); @@ -759,7 +760,8 @@ ioapic_remap_vector(void *cookie, u_int pin, int vector) struct ioapic *io; io = (struct ioapic *)cookie; - if (pin >= io->io_numintr || vector < 0) + if (pin >= rman_get_end(io->intrs) - rman_get_start(io->intrs) || + vector < 0) return (EINVAL); if (io->io_pins[pin].io_irq < 0) return (EINVAL); @@ -778,7 +780,7 @@ ioapic_set_bus(void *cookie, u_int pin, int bus_type) if (bus_type < 0 || bus_type > APIC_BUS_MAX) return (EINVAL); io = (struct ioapic *)cookie; - if (pin >= io->io_numintr) + if (pin >= rman_get_end(io->intrs) - rman_get_start(io->intrs)) return (EINVAL); if (io->io_pins[pin].io_irq < 0) return (EINVAL); @@ -797,7 +799,7 @@ ioapic_set_nmi(void *cookie, u_int pin) struct ioapic *io; io = (struct ioapic *)cookie; - if (pin >= io->io_numintr) + if (pin >= rman_get_end(io->intrs) - rman_get_start(io->intrs)) return (EINVAL); if (io->io_pins[pin].io_irq == IRQ_NMI) return (0); @@ -820,7 +822,7 @@ ioapic_set_smi(void *cookie, u_int pin) struct ioapic *io; io = (struct ioapic *)cookie; - if (pin >= io->io_numintr) + if (pin >= rman_get_end(io->intrs) - rman_get_start(io->intrs)) return (EINVAL); if (io->io_pins[pin].io_irq == IRQ_SMI) return (0); @@ -843,7 +845,7 @@ ioapic_set_extint(void *cookie, u_int pin) struct ioapic *io; io = (struct ioapic *)cookie; - if (pin >= io->io_numintr) + if (pin >= rman_get_end(io->intrs) - rman_get_start(io->intrs)) return (EINVAL); if (io->io_pins[pin].io_irq == IRQ_EXTINT) return (0); @@ -870,7 +872,8 @@ ioapic_set_polarity(void *cookie, u_int pin, enum intr_polarity pol) int activehi; io = (struct ioapic *)cookie; - if (pin >= io->io_numintr || pol == INTR_POLARITY_CONFORM) + if (pin >= rman_get_end(io->intrs) - rman_get_start(io->intrs) || + pol == INTR_POLARITY_CONFORM) return (EINVAL); if (io->io_pins[pin].io_irq < 0) return (EINVAL); @@ -891,7 +894,8 @@ ioapic_set_triggermode(void *cookie, u_int pin, enum intr_trigger trigger) int edgetrigger; io = (struct ioapic *)cookie; - if (pin >= io->io_numintr || trigger == INTR_TRIGGER_CONFORM) + if (pin >= rman_get_end(io->intrs) - rman_get_start(io->intrs) || + trigger == INTR_TRIGGER_CONFORM) return (EINVAL); if (io->io_pins[pin].io_irq < 0) return (EINVAL); @@ -923,16 +927,18 @@ ioapic_register(void *cookie) flags = ioapic_read(apic, IOAPIC_VER) & IOART_VER_VERSION; STAILQ_INSERT_TAIL(&ioapic_list, io, io_next); mtx_unlock_spin(&icu_lock); - printf("ioapic%u irqs %u-%u\n", - io->io_id, flags >> 4, flags & 0xf, io->io_intbase, - io->io_intbase + io->io_numintr - 1); + printf("ioapic%u irqs %lu-%lu\n", + io->io_id, flags >> 4, flags & 0xf, + (u_long)rman_get_start(io->intrs), + (u_long)rman_get_end(io->intrs) - 1); /* * Reprogram pins to handle special case pins (such as NMI and * SMI) and disable normal pins until a handler is registered. */ intr_register_pic(&io->io_pic); - for (i = 0, pin = io->io_pins; i < io->io_numintr; i++, pin++) + for (i = 0, pin = io->io_pins; i < rman_get_end(io->intrs) - + rman_get_start(io->intrs); i++, pin++) ioapic_reprogram_intpin(&pin->io_intsrc); } @@ -947,9 +953,11 @@ ioapic_register_sources(struct pic *pic) int i; io = (struct ioapic *)pic; - for (i = 0, pin = io->io_pins; i < io->io_numintr; i++, pin++) { + for (i = 0, pin = io->io_pins; i < rman_get_end(io->intrs) - + rman_get_start(io->intrs); i++, pin++) { if (pin->io_irq >= 0) - intr_register_source(&pin->io_intsrc); + intr_register_source(io->intrs, pin->io_irq, + &pin->io_intsrc); } } diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c index 6a913883cc5c0d..883c0a79e1819a 100644 --- a/sys/x86/x86/local_apic.c +++ b/sys/x86/x86/local_apic.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ #include #include #include -#include +#include #include #include #include @@ -1282,8 +1283,7 @@ lapic_handle_intr(int vector, struct trapframe *frame) kmsan_mark(frame, sizeof(*frame), KMSAN_STATE_INITED); trap_check_kstack(); - isrc = intr_lookup_source(apic_idt_to_irq(PCPU_GET(apic_id), - vector)); + isrc = intrtab_lookup(apic_idt_to_irq(PCPU_GET(apic_id), vector)); intr_execute_handlers(isrc, frame); } @@ -1727,7 +1727,7 @@ DB_SHOW_COMMAND_FLAGS(apic, db_show_apic, DB_CMD_MEMSAFE) if (irq == IRQ_TIMER) db_printf("lapic timer\n"); else if (irq < num_io_irqs) { - isrc = intr_lookup_source(irq); + isrc = intrtab_lookup(irq); if (isrc == NULL || verbose == 0) db_printf("IRQ %u\n", irq); else diff --git a/sys/x86/x86/mca.c b/sys/x86/x86/mca.c index b293fcedbd8418..8c64810dfde35a 100644 --- a/sys/x86/x86/mca.c +++ b/sys/x86/x86/mca.c @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/x86/x86/mptable.c b/sys/x86/x86/mptable.c index 03b4d4362baa9d..c501da1e349c79 100644 --- a/sys/x86/x86/mptable.c +++ b/sys/x86/x86/mptable.c @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sys/x86/x86/msi.c b/sys/x86/x86/msi.c index 9d5a51f9753c2b..5283bc91aec8dc 100644 --- a/sys/x86/x86/msi.c +++ b/sys/x86/x86/msi.c @@ -42,6 +42,8 @@ #include #include +#include +#include #include #include #include @@ -54,7 +56,7 @@ #include #include #include -#include +#include #include #include #include @@ -115,7 +117,6 @@ struct msi_intsrc { device_t msi_dev; /* Owning device. (g) */ struct msi_intsrc *msi_first; /* First source in group. */ u_int *msi_irqs; /* Group's IRQ list. (g) */ - u_int msi_irq; /* IRQ cookie. */ u_int msi_cpu; /* Local APIC ID. (g) */ u_int msi_remap_cookie; /* IOMMU cookie. */ u_int msi_vector:8; /* IDT vector. */ @@ -131,7 +132,6 @@ static void msi_disable_source(struct intsrc *isrc, int eoi); static void msi_eoi_source(struct intsrc *isrc); static void msi_enable_intr(struct intsrc *isrc); static void msi_disable_intr(struct intsrc *isrc); -static int msi_vector(struct intsrc *isrc); static int msi_source_pending(struct intsrc *isrc); static int msi_config_intr(struct intsrc *isrc, enum intr_trigger trig, enum intr_polarity pol); @@ -143,7 +143,6 @@ struct pic msi_pic = { .pic_eoi_source = msi_eoi_source, .pic_enable_intr = msi_enable_intr, .pic_disable_intr = msi_disable_intr, - .pic_vector = msi_vector, .pic_source_pending = msi_source_pending, .pic_suspend = NULL, .pic_resume = NULL, @@ -152,6 +151,8 @@ struct pic msi_pic = { .pic_reprogram_pin = NULL, }; +struct resource *msi_intrs; + u_int first_msi_irq; SYSCTL_UINT(_machdep, OID_AUTO, first_msi_irq, CTLFLAG_RD, &first_msi_irq, 0, "Number of first IRQ reserved for MSI and MSI-X interrupts"); @@ -226,14 +227,6 @@ msi_disable_intr(struct intsrc *isrc) } } -static int -msi_vector(struct intsrc *isrc) -{ - struct msi_intsrc *msi = (struct msi_intsrc *)isrc; - - return (msi->msi_irq); -} - static int msi_source_pending(struct intsrc *isrc) { @@ -281,7 +274,8 @@ msi_assign_cpu(struct intsrc *isrc, u_int apic_id) vector = apic_alloc_vectors(apic_id, msi->msi_irqs, msi->msi_count, msi->msi_maxcount); } else - vector = apic_alloc_vector(apic_id, msi->msi_irq); + vector = apic_alloc_vector(apic_id, + msi->msi_intsrc.is_event->ie_irq); if (vector == 0) return (ENOSPC); @@ -293,27 +287,28 @@ msi_assign_cpu(struct intsrc *isrc, u_int apic_id) apic_enable_vector(apic_id, vector + i); } error = BUS_REMAP_INTR(device_get_parent(msi->msi_dev), msi->msi_dev, - msi->msi_irq); + msi->msi_intsrc.is_event->ie_irq); if (error == 0) { if (bootverbose) { printf("msi: Assigning %s IRQ %d to local APIC %u vector %u\n", - msi->msi_msix ? "MSI-X" : "MSI", msi->msi_irq, + msi->msi_msix ? "MSI-X" : "MSI", + msi->msi_intsrc.is_event->ie_irq, msi->msi_cpu, msi->msi_vector); } for (i = 1; i < msi->msi_count; i++) { - sib = (struct msi_intsrc *)intr_lookup_source( + sib = (struct msi_intsrc *)intrtab_lookup( msi->msi_irqs[i]); sib->msi_cpu = apic_id; sib->msi_vector = vector + i; if (bootverbose) printf("msi: Assigning MSI IRQ %d to local APIC %u vector %u\n", - sib->msi_irq, sib->msi_cpu, - sib->msi_vector); + sib->msi_intsrc.is_event->ie_irq, + sib->msi_cpu, sib->msi_vector); } } else { device_printf(msi->msi_dev, "remap irq %u to APIC ID %u failed (error %d)\n", - msi->msi_irq, apic_id, error); + msi->msi_intsrc.is_event->ie_irq, apic_id, error); msi->msi_cpu = old_id; msi->msi_vector = old_vector; old_id = apic_id; @@ -329,7 +324,7 @@ msi_assign_cpu(struct intsrc *isrc, u_int apic_id) for (i = 0; i < msi->msi_count; i++) apic_disable_vector(old_id, old_vector + i); } - apic_free_vector(old_id, old_vector, msi->msi_irq); + apic_free_vector(old_id, old_vector, msi->msi_intsrc.is_event->ie_irq); for (i = 1; i < msi->msi_count; i++) apic_free_vector(old_id, old_vector + i, msi->msi_irqs[i]); return (error); @@ -364,10 +359,10 @@ msi_init(void) if (num_msi_irqs == 0) return; - first_msi_irq = num_io_irqs; - if (num_msi_irqs > UINT_MAX - first_msi_irq) + msi_intrs = intrtab_alloc_intr(NULL, num_msi_irqs); + if (msi_intrs == NULL) panic("num_msi_irqs too high"); - num_io_irqs = first_msi_irq + num_msi_irqs; + first_msi_irq = rman_get_start(msi_intrs); msi_enabled = 1; intr_register_pic(&msi_pic); @@ -391,8 +386,7 @@ msi_create_source(void) msi = malloc(sizeof(struct msi_intsrc), M_MSI, M_WAITOK | M_ZERO); msi->msi_intsrc.is_pic = &msi_pic; - msi->msi_irq = irq; - intr_register_source(&msi->msi_intsrc); + intr_register_source(msi_intrs, irq, &msi->msi_intsrc); nexus_add_irq(irq); } @@ -426,7 +420,7 @@ msi_alloc(device_t dev, int count, int maxcount, int *irqs) /* Try to find 'count' free IRQs. */ cnt = 0; for (i = first_msi_irq; i < first_msi_irq + num_msi_irqs; i++) { - msi = (struct msi_intsrc *)intr_lookup_source(i); + msi = (struct msi_intsrc *)intrtab_lookup(i); /* End of allocated sources, so break. */ if (msi == NULL) @@ -485,22 +479,23 @@ msi_alloc(device_t dev, int count, int maxcount, int *irqs) return (error); } for (i = 0; i < count; i++) { - msi = (struct msi_intsrc *)intr_lookup_source(irqs[i]); + msi = (struct msi_intsrc *)intrtab_lookup(irqs[i]); msi->msi_remap_cookie = cookies[i]; } #endif /* Assign IDT vectors and make these messages owned by 'dev'. */ - fsrc = (struct msi_intsrc *)intr_lookup_source(irqs[0]); + fsrc = (struct msi_intsrc *)intrtab_lookup(irqs[0]); for (i = 0; i < count; i++) { - msi = (struct msi_intsrc *)intr_lookup_source(irqs[i]); + msi = (struct msi_intsrc *)intrtab_lookup(irqs[i]); msi->msi_cpu = cpu; msi->msi_dev = dev; msi->msi_vector = vector + i; if (bootverbose) printf( "msi: routing MSI IRQ %d to local APIC %u vector %u\n", - msi->msi_irq, msi->msi_cpu, msi->msi_vector); + msi->msi_intsrc.is_event->ie_irq, msi->msi_cpu, + msi->msi_vector); msi->msi_first = fsrc; KASSERT(msi->msi_intsrc.is_handlers == 0, ("dead MSI has handlers")); @@ -521,7 +516,7 @@ msi_release(int *irqs, int count) int i; mtx_lock(&msi_lock); - first = (struct msi_intsrc *)intr_lookup_source(irqs[0]); + first = (struct msi_intsrc *)intrtab_lookup(irqs[0]); if (first == NULL) { mtx_unlock(&msi_lock); return (ENOENT); @@ -551,7 +546,7 @@ msi_release(int *irqs, int count) /* Clear all the extra messages in the group. */ for (i = 1; i < count; i++) { - msi = (struct msi_intsrc *)intr_lookup_source(irqs[i]); + msi = (struct msi_intsrc *)intrtab_lookup(irqs[i]); KASSERT(msi->msi_first == first, ("message not in group")); KASSERT(msi->msi_dev == first->msi_dev, ("owner mismatch")); #ifdef IOMMU @@ -561,7 +556,8 @@ msi_release(int *irqs, int count) #endif msi->msi_first = NULL; msi->msi_dev = NULL; - apic_free_vector(msi->msi_cpu, msi->msi_vector, msi->msi_irq); + apic_free_vector(msi->msi_cpu, msi->msi_vector, + msi->msi_intsrc.is_event->ie_irq); msi->msi_vector = 0; } @@ -573,7 +569,8 @@ msi_release(int *irqs, int count) #endif first->msi_first = NULL; first->msi_dev = NULL; - apic_free_vector(first->msi_cpu, first->msi_vector, first->msi_irq); + apic_free_vector(first->msi_cpu, first->msi_vector, + first->msi_intsrc.is_event->ie_irq); first->msi_vector = 0; first->msi_count = 0; first->msi_maxcount = 0; @@ -595,7 +592,7 @@ msi_map(int irq, uint64_t *addr, uint32_t *data) #endif mtx_lock(&msi_lock); - msi = (struct msi_intsrc *)intr_lookup_source(irq); + msi = (struct msi_intsrc *)intrtab_lookup(irq); if (msi == NULL) { mtx_unlock(&msi_lock); return (ENOENT); @@ -624,9 +621,9 @@ msi_map(int irq, uint64_t *addr, uint32_t *data) if (!msi->msi_msix) { for (k = msi->msi_count - 1, i = first_msi_irq; k > 0 && i < first_msi_irq + num_msi_irqs; i++) { - if (i == msi->msi_irq) + if (i == msi->msi_intsrc.is_event->ie_irq) continue; - msi1 = (struct msi_intsrc *)intr_lookup_source(i); + msi1 = (struct msi_intsrc *)intrtab_lookup(i); if (!msi1->msi_msix && msi1->msi_first == msi) { mtx_unlock(&msi_lock); iommu_map_msi_intr(msi1->msi_dev, @@ -679,7 +676,7 @@ msix_alloc(device_t dev, int *irq) /* Find a free IRQ. */ for (i = first_msi_irq; i < first_msi_irq + num_msi_irqs; i++) { - msi = (struct msi_intsrc *)intr_lookup_source(i); + msi = (struct msi_intsrc *)intrtab_lookup(i); /* End of allocated sources, so break. */ if (msi == NULL) @@ -731,7 +728,7 @@ msix_alloc(device_t dev, int *irq) if (bootverbose) printf("msi: routing MSI-X IRQ %d to local APIC %u vector %u\n", - msi->msi_irq, cpu, vector); + msi->msi_intsrc.is_event->ie_irq, cpu, vector); /* Setup source. */ msi->msi_cpu = cpu; @@ -755,7 +752,7 @@ msix_release(int irq) struct msi_intsrc *msi; mtx_lock(&msi_lock); - msi = (struct msi_intsrc *)intr_lookup_source(irq); + msi = (struct msi_intsrc *)intrtab_lookup(irq); if (msi == NULL) { mtx_unlock(&msi_lock); return (ENOENT); @@ -777,7 +774,8 @@ msix_release(int irq) #endif msi->msi_first = NULL; msi->msi_dev = NULL; - apic_free_vector(msi->msi_cpu, msi->msi_vector, msi->msi_irq); + apic_free_vector(msi->msi_cpu, msi->msi_vector, + msi->msi_intsrc.is_event->ie_irq); msi->msi_vector = 0; msi->msi_msix = false; msi->msi_count = 0; diff --git a/sys/x86/x86/nexus.c b/sys/x86/x86/nexus.c index d7bb0292157e2f..17a8e04dfde236 100644 --- a/sys/x86/x86/nexus.c +++ b/sys/x86/x86/nexus.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ #include #include -#include +#include #include #include #include @@ -216,7 +217,7 @@ nexus_init_resources(void) * resource manager. */ for (irq = 0; irq < num_io_irqs; irq++) - if (intr_lookup_source(irq) != NULL) + if (intrtab_lookup(irq) != NULL) if (rman_manage_region(&irq_rman, irq, irq) != 0) panic("nexus_init_resources irq_rman add"); @@ -477,7 +478,7 @@ nexus_setup_intr(device_t bus, device_t child, struct resource *irq, if (bus_get_domain(child, &domain) != 0) domain = 0; - isrc = intr_lookup_source(rman_get_start(irq)); + isrc = intrtab_lookup(rman_get_start(irq)); if (isrc == NULL) return (EINVAL); error = intr_add_handler(isrc, device_get_nameunit(child), @@ -517,7 +518,7 @@ nexus_bind_intr(device_t dev, device_t child, struct resource *irq, int cpu) { struct intsrc *isrc; - isrc = intr_lookup_source(rman_get_start(irq)); + isrc = intrtab_lookup(rman_get_start(irq)); if (isrc == NULL) return (EINVAL); return (intr_event_bind(isrc->is_event, cpu)); @@ -530,7 +531,7 @@ nexus_config_intr(device_t dev, int irq, enum intr_trigger trig, { struct intsrc *isrc; - isrc = intr_lookup_source(irq); + isrc = intrtab_lookup(irq); if (isrc == NULL) return (EINVAL); return (intr_config_intr(isrc, trig, pol)); @@ -542,7 +543,7 @@ nexus_describe_intr(device_t dev, device_t child, struct resource *irq, { struct intsrc *isrc; - isrc = intr_lookup_source(rman_get_start(irq)); + isrc = intrtab_lookup(rman_get_start(irq)); if (isrc == NULL) return (EINVAL); return (intr_describe(isrc, cookie, descr)); diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c index 388543d6425410..4c0fc9079957dd 100644 --- a/sys/x86/xen/pv.c +++ b/sys/x86/xen/pv.c @@ -59,13 +59,12 @@ #include #include -#include +#include #include #include #include #include #include -#include #include #include #include diff --git a/sys/x86/xen/xen_apic.c b/sys/x86/xen/xen_apic.c index 994dc3e0804c3f..9c01d3a3336f0f 100644 --- a/sys/x86/xen/xen_apic.c +++ b/sys/x86/xen/xen_apic.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include diff --git a/sys/x86/xen/xen_arch_intr.c b/sys/x86/xen/xen_arch_intr.c index dcf8b4aa35f160..0a4de9788b1fb6 100644 --- a/sys/x86/xen/xen_arch_intr.c +++ b/sys/x86/xen/xen_arch_intr.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -117,7 +118,7 @@ static MALLOC_DEFINE(M_XENINTR, "xen_intr", "Xen Interrupt Services"); */ static struct mtx xen_intr_x86_lock; -static u_int first_evtchn_irq; +static struct resource *intrs; static u_int xen_intr_auto_vector_count; @@ -137,10 +138,9 @@ void xen_intr_alloc_irqs(void) { - if (num_io_irqs > UINT_MAX - NR_EVENT_CHANNELS) + intrs = intrtab_alloc_intr(NULL, NR_EVENT_CHANNELS); + if (intrs == NULL) panic("IRQ allocation overflow (num_msi_irqs too high?)"); - first_evtchn_irq = num_io_irqs; - num_io_irqs += NR_EVENT_CHANNELS; } static void @@ -191,24 +191,6 @@ xen_intr_pic_disable_intr(struct intsrc *isrc) xen_intr_disable_intr((struct xenisrc *)isrc); } -/** - * Determine the global interrupt vector number for - * a Xen interrupt source. - * - * \param isrc The interrupt source to query. - * - * \return The vector number corresponding to the given interrupt source. - */ -static int -xen_intr_pic_vector(struct intsrc *isrc) -{ - - _Static_assert(offsetof(struct xenisrc, xi_arch.intsrc) == 0, - "xi_arch MUST be at top of xenisrc for x86"); - - return (((struct xenisrc *)isrc)->xi_arch.vector); -} - /** * Determine whether or not interrupt events are pending on the * the given interrupt source. @@ -282,7 +264,6 @@ static struct pic xen_intr_pic = { .pic_eoi_source = xen_intr_pic_eoi_source, .pic_enable_intr = xen_intr_pic_enable_intr, .pic_disable_intr = xen_intr_pic_disable_intr, - .pic_vector = xen_intr_pic_vector, .pic_source_pending = xen_intr_pic_source_pending, .pic_suspend = xen_intr_pic_suspend, .pic_resume = xen_intr_pic_resume, @@ -345,17 +326,16 @@ xen_arch_intr_alloc(void) return (NULL); } - vector = first_evtchn_irq + xen_intr_auto_vector_count; + vector = rman_get_start(intrs) + xen_intr_auto_vector_count; xen_intr_auto_vector_count++; - KASSERT((intr_lookup_source(vector) == NULL), + KASSERT((intrtab_lookup(vector) == NULL), ("Trying to use an already allocated vector")); mtx_unlock(&xen_intr_x86_lock); isrc = malloc(sizeof(*isrc), M_XENINTR, M_WAITOK | M_ZERO); isrc->xi_arch.intsrc.is_pic = &xen_intr_pic; - isrc->xi_arch.vector = vector; - error = intr_register_source(&isrc->xi_arch.intsrc); + error = intr_register_source(intrs, vector, &isrc->xi_arch.intsrc); if (error != 0) panic("%s(): failed registering interrupt %u, error=%d\n", __func__, vector, error);