| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pcihost_fdt.c,v 1.29 2022/09/04 10:20:33 skrll Exp $ */ | | 1 | /* $NetBSD: pcihost_fdt.c,v 1.30 2022/09/04 16:01:25 skrll Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2018 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2018 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: pcihost_fdt.c,v 1.29 2022/09/04 10:20:33 skrll Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: pcihost_fdt.c,v 1.30 2022/09/04 16:01:25 skrll Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | | | 33 | |
34 | #include <sys/bus.h> | | 34 | #include <sys/bus.h> |
35 | #include <sys/device.h> | | 35 | #include <sys/device.h> |
36 | #include <sys/intr.h> | | 36 | #include <sys/intr.h> |
37 | #include <sys/kernel.h> | | 37 | #include <sys/kernel.h> |
38 | #include <sys/kmem.h> | | 38 | #include <sys/kmem.h> |
39 | #include <sys/lwp.h> | | 39 | #include <sys/lwp.h> |
40 | #include <sys/mutex.h> | | 40 | #include <sys/mutex.h> |
41 | #include <sys/queue.h> | | 41 | #include <sys/queue.h> |
42 | #include <sys/systm.h> | | 42 | #include <sys/systm.h> |
43 | | | 43 | |
| @@ -590,74 +590,52 @@ pcihost_intr_setattr(void *v, pci_intr_h | | | @@ -590,74 +590,52 @@ pcihost_intr_setattr(void *v, pci_intr_h |
590 | { | | 590 | { |
591 | switch (attr) { | | 591 | switch (attr) { |
592 | case PCI_INTR_MPSAFE: | | 592 | case PCI_INTR_MPSAFE: |
593 | if (data) | | 593 | if (data) |
594 | *ih |= ARM_PCI_INTR_MPSAFE; | | 594 | *ih |= ARM_PCI_INTR_MPSAFE; |
595 | else | | 595 | else |
596 | *ih &= ~ARM_PCI_INTR_MPSAFE; | | 596 | *ih &= ~ARM_PCI_INTR_MPSAFE; |
597 | return 0; | | 597 | return 0; |
598 | default: | | 598 | default: |
599 | return ENODEV; | | 599 | return ENODEV; |
600 | } | | 600 | } |
601 | } | | 601 | } |
602 | | | 602 | |
603 | struct pcihost_cookie { | | | |
604 | pci_intr_handle_t phic_pih; | | | |
605 | void *phic_ih; | | | |
606 | }; | | | |
607 | | | | |
608 | | | | |
609 | static void * | | 603 | static void * |
610 | pcihost_intr_establish(void *v, pci_intr_handle_t pih, int ipl, | | 604 | pcihost_intr_establish(void *v, pci_intr_handle_t ih, int ipl, |
611 | int (*callback)(void *), void *arg, const char *xname) | | 605 | int (*callback)(void *), void *arg, const char *xname) |
612 | { | | 606 | { |
613 | struct pcihost_softc *sc = v; | | 607 | struct pcihost_softc *sc = v; |
614 | const int flags = (pih & ARM_PCI_INTR_MPSAFE) ? FDT_INTR_MPSAFE : 0; | | 608 | const int flags = (ih & ARM_PCI_INTR_MPSAFE) ? FDT_INTR_MPSAFE : 0; |
615 | const u_int *specifier; | | 609 | const u_int *specifier; |
616 | int ihandle; | | 610 | int ihandle; |
617 | | | 611 | |
618 | struct pcihost_cookie * const phic = kmem_alloc(sizeof(*phic), KM_SLEEP); | | 612 | if ((ih & (ARM_PCI_INTR_MSI | ARM_PCI_INTR_MSIX)) != 0) |
619 | phic->phic_pih = pih; | | 613 | return arm_pci_msi_intr_establish(&sc->sc_pc, ih, ipl, callback, arg, xname); |
620 | if ((pih & (ARM_PCI_INTR_MSI | ARM_PCI_INTR_MSIX)) != 0) { | | | |
621 | phic->phic_ih = arm_pci_msi_intr_establish(&sc->sc_pc, pih, ipl, | | | |
622 | callback, arg, xname); | | | |
623 | | | | |
624 | return phic; | | | |
625 | } | | | |
626 | | | 614 | |
627 | specifier = pcihost_find_intr(sc, pih & ARM_PCI_INTR_IRQ, &ihandle); | | 615 | specifier = pcihost_find_intr(sc, ih & ARM_PCI_INTR_IRQ, &ihandle); |
628 | if (specifier == NULL) | | 616 | if (specifier == NULL) |
629 | return NULL; | | 617 | return NULL; |
630 | | | 618 | |
631 | phic->phic_ih = fdtbus_intr_establish_raw(ihandle, specifier, ipl, flags, | | 619 | return fdtbus_intr_establish_raw(ihandle, specifier, ipl, flags, |
632 | callback, arg, xname); | | 620 | callback, arg, xname); |
633 | | | | |
634 | return phic; | | | |
635 | } | | 621 | } |
636 | | | 622 | |
637 | static void | | 623 | static void |
638 | pcihost_intr_disestablish(void *v, void *vih) | | 624 | pcihost_intr_disestablish(void *v, void *vih) |
639 | { | | 625 | { |
640 | struct pcihost_softc *sc = v; | | 626 | struct pcihost_softc *sc = v; |
641 | struct pcihost_cookie * const phic = vih; | | | |
642 | const pci_intr_handle_t pih = phic->phic_pih; | | | |
643 | void * const ih = phic->phic_ih; | | | |
644 | | | | |
645 | kmem_free(phic, sizeof(*phic)); | | | |
646 | | | | |
647 | if ((pih & (ARM_PCI_INTR_MSI | ARM_PCI_INTR_MSIX)) != 0) | | | |
648 | return; | | | |
649 | | | 627 | |
650 | fdtbus_intr_disestablish(sc->sc_phandle, ih); | | 628 | fdtbus_intr_disestablish(sc->sc_phandle, vih); |
651 | } | | 629 | } |
652 | | | 630 | |
653 | static int | | 631 | static int |
654 | pcihost_bus_space_map(void *t, bus_addr_t bpa, bus_size_t size, int flag, | | 632 | pcihost_bus_space_map(void *t, bus_addr_t bpa, bus_size_t size, int flag, |
655 | bus_space_handle_t *bshp) | | 633 | bus_space_handle_t *bshp) |
656 | { | | 634 | { |
657 | struct pcih_bus_space * const pbs = t; | | 635 | struct pcih_bus_space * const pbs = t; |
658 | | | 636 | |
659 | if ((pbs->flags & PCI_FLAGS_IO_OKAY) != 0) { | | 637 | if ((pbs->flags & PCI_FLAGS_IO_OKAY) != 0) { |
660 | /* Force strongly ordered mapping for all I/O space */ | | 638 | /* Force strongly ordered mapping for all I/O space */ |
661 | flag = _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED; | | 639 | flag = _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED; |
662 | } | | 640 | } |
663 | | | 641 | |