Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/fdt pcihost: Track MSI/MSI-X interrupt handlers.



details:   https://anonhg.NetBSD.org/src/rev/abf390364181
branches:  trunk
changeset: 369886:abf390364181
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Sep 06 11:55:07 2022 +0000

description:
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.

diffstat:

 sys/arch/arm/fdt/pcihost_fdt.c    |  46 +++++++++++++++++++++++++++++++++-----
 sys/arch/arm/fdt/pcihost_fdtvar.h |   8 +++++-
 2 files changed, 46 insertions(+), 8 deletions(-)

diffs (124 lines):

diff -r 1f568b2e6bfb -r abf390364181 sys/arch/arm/fdt/pcihost_fdt.c
--- a/sys/arch/arm/fdt/pcihost_fdt.c    Tue Sep 06 02:31:08 2022 +0000
+++ b/sys/arch/arm/fdt/pcihost_fdt.c    Tue Sep 06 11:55:07 2022 +0000
@@ -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@localhost>
@@ -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 @@
        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 @@
        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 @@
 }
 
 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 @@
 {
        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);
 }
 
diff -r 1f568b2e6bfb -r abf390364181 sys/arch/arm/fdt/pcihost_fdtvar.h
--- a/sys/arch/arm/fdt/pcihost_fdtvar.h Tue Sep 06 02:31:08 2022 +0000
+++ b/sys/arch/arm/fdt/pcihost_fdtvar.h Tue Sep 06 11:55:07 2022 +0000
@@ -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@localhost>
@@ -47,6 +47,8 @@
        PCIHOST_ECAM,
 };
 
+struct pcihost_msi_handlers;
+
 struct pcih_bus_space {
        struct bus_space        bst;
 
@@ -85,6 +87,10 @@
 
        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 *);



Home | Main Index | Thread Index | Old Index