pcihost: Track MSI/MSI-X interrupt handlers.
Track the MSI/MSI-X interrupt handlers so that fdtbus_intr_disestablish doesn't get called for them. This avoids a KASSERT firing when using 'drvctl -d' on a pci device that uses MSI/MSI-X interrupts.
This commit is contained in:
parent
8da94dbc75
commit
ff4e9f7008
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pcihost_fdt.c,v 1.30 2022/09/04 16:01:25 skrll Exp $ */
|
||||
/* $NetBSD: pcihost_fdt.c,v 1.31 2022/09/06 11:55:07 skrll Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2018 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
|
@ -27,7 +27,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: pcihost_fdt.c,v 1.30 2022/09/04 16:01:25 skrll Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: pcihost_fdt.c,v 1.31 2022/09/06 11:55:07 skrll Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
|
@ -101,6 +101,12 @@ static const struct device_compatible_entry compat_data[] = {
|
|||
DEVICE_COMPAT_EOL
|
||||
};
|
||||
|
||||
struct pcihost_msi_handler {
|
||||
LIST_ENTRY(pcihost_msi_handler) pmh_next;
|
||||
void *pmh_ih;
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
pcihost_match(device_t parent, cfdata_t cf, void *aux)
|
||||
{
|
||||
|
@ -178,6 +184,8 @@ pcihost_init2(struct pcihost_softc *sc)
|
|||
if (of_getprop_uint32(sc->sc_phandle, "linux,pci-domain", &sc->sc_seg))
|
||||
sc->sc_seg = pcihost_segment++;
|
||||
|
||||
mutex_init(&sc->sc_msi_handlers_mutex, MUTEX_DEFAULT, IPL_NONE);
|
||||
|
||||
if (pcihost_config(sc) != 0)
|
||||
return;
|
||||
|
||||
|
@ -601,18 +609,30 @@ pcihost_intr_setattr(void *v, pci_intr_handle_t *ih, int attr, uint64_t data)
|
|||
}
|
||||
|
||||
static void *
|
||||
pcihost_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
|
||||
pcihost_intr_establish(void *v, pci_intr_handle_t pih, int ipl,
|
||||
int (*callback)(void *), void *arg, const char *xname)
|
||||
{
|
||||
struct pcihost_softc *sc = v;
|
||||
const int flags = (ih & ARM_PCI_INTR_MPSAFE) ? FDT_INTR_MPSAFE : 0;
|
||||
const int flags = (pih & ARM_PCI_INTR_MPSAFE) ? FDT_INTR_MPSAFE : 0;
|
||||
const u_int *specifier;
|
||||
int ihandle;
|
||||
|
||||
if ((ih & (ARM_PCI_INTR_MSI | ARM_PCI_INTR_MSIX)) != 0)
|
||||
return arm_pci_msi_intr_establish(&sc->sc_pc, ih, ipl, callback, arg, xname);
|
||||
if ((pih & (ARM_PCI_INTR_MSI | ARM_PCI_INTR_MSIX)) != 0) {
|
||||
void *ih = arm_pci_msi_intr_establish(&sc->sc_pc, pih, ipl,
|
||||
callback, arg, xname);
|
||||
|
||||
specifier = pcihost_find_intr(sc, ih & ARM_PCI_INTR_IRQ, &ihandle);
|
||||
if (ih) {
|
||||
struct pcihost_msi_handler * const pmh =
|
||||
kmem_alloc(sizeof(*pmh), KM_SLEEP);
|
||||
pmh->pmh_ih = ih;
|
||||
mutex_enter(&sc->sc_msi_handlers_mutex);
|
||||
LIST_INSERT_HEAD(&sc->sc_msi_handlers, pmh, pmh_next);
|
||||
mutex_exit(&sc->sc_msi_handlers_mutex);
|
||||
}
|
||||
return ih;
|
||||
}
|
||||
|
||||
specifier = pcihost_find_intr(sc, pih & ARM_PCI_INTR_IRQ, &ihandle);
|
||||
if (specifier == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -625,6 +645,18 @@ pcihost_intr_disestablish(void *v, void *vih)
|
|||
{
|
||||
struct pcihost_softc *sc = v;
|
||||
|
||||
mutex_enter(&sc->sc_msi_handlers_mutex);
|
||||
struct pcihost_msi_handler *pmh;
|
||||
LIST_FOREACH(pmh, &sc->sc_msi_handlers, pmh_next) {
|
||||
if (pmh->pmh_ih == vih) {
|
||||
LIST_REMOVE(pmh, pmh_next);
|
||||
mutex_exit(&sc->sc_msi_handlers_mutex);
|
||||
kmem_free(pmh, sizeof(*pmh));
|
||||
return;
|
||||
}
|
||||
}
|
||||
mutex_exit(&sc->sc_msi_handlers_mutex);
|
||||
|
||||
fdtbus_intr_disestablish(sc->sc_phandle, vih);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pcihost_fdtvar.h,v 1.4 2021/09/06 14:03:17 jmcneill Exp $ */
|
||||
/* $NetBSD: pcihost_fdtvar.h,v 1.5 2022/09/06 11:55:07 skrll Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2018 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
|
@ -47,6 +47,8 @@ enum pcihost_type {
|
|||
PCIHOST_ECAM,
|
||||
};
|
||||
|
||||
struct pcihost_msi_handlers;
|
||||
|
||||
struct pcih_bus_space {
|
||||
struct bus_space bst;
|
||||
|
||||
|
@ -85,6 +87,10 @@ struct pcihost_softc {
|
|||
|
||||
const u_int *sc_pci_ranges;
|
||||
u_int sc_pci_ranges_cells;
|
||||
|
||||
kmutex_t sc_msi_handlers_mutex;
|
||||
LIST_HEAD(, pcihost_msi_handler)
|
||||
sc_msi_handlers;
|
||||
};
|
||||
|
||||
void pcihost_init2(struct pcihost_softc *);
|
||||
|
|
Loading…
Reference in New Issue