2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/malloc.h>
37 #include <sys/module.h>
40 #include <contrib/dev/acpica/include/acpi.h>
41 #include <contrib/dev/acpica/include/accommon.h>
43 #include <dev/acpica/acpivar.h>
44 #include <dev/acpica/acpi_pcibvar.h>
46 #include <machine/pci_cfgreg.h>
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/pcireg.h>
49 #include <dev/pci/pcib_private.h>
52 /* Hooks for the ACPI CA debugging infrastructure. */
53 #define _COMPONENT ACPI_BUS
54 ACPI_MODULE_NAME("PCI_PCI")
56 struct acpi_pcib_softc {
57 struct pcib_softc ap_pcibsc;
58 ACPI_HANDLE ap_handle;
59 ACPI_BUFFER ap_prt; /* interrupt routing table */
62 struct acpi_pcib_lookup_info {
67 static int acpi_pcib_pci_probe(device_t bus);
68 static int acpi_pcib_pci_attach(device_t bus);
69 static int acpi_pcib_read_ivar(device_t dev, device_t child,
70 int which, uintptr_t *result);
71 static int acpi_pcib_pci_route_interrupt(device_t pcib,
72 device_t dev, int pin);
74 static device_method_t acpi_pcib_pci_methods[] = {
75 /* Device interface */
76 DEVMETHOD(device_probe, acpi_pcib_pci_probe),
77 DEVMETHOD(device_attach, acpi_pcib_pci_attach),
80 DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar),
83 DEVMETHOD(pcib_route_interrupt, acpi_pcib_pci_route_interrupt),
88 static devclass_t pcib_devclass;
90 DEFINE_CLASS_1(pcib, acpi_pcib_pci_driver, acpi_pcib_pci_methods,
91 sizeof(struct acpi_pcib_softc), pcib_driver);
92 DRIVER_MODULE(acpi_pcib, pci, acpi_pcib_pci_driver, pcib_devclass, 0, 0);
93 MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1);
96 acpi_pcib_pci_probe(device_t dev)
99 if (pci_get_class(dev) != PCIC_BRIDGE ||
100 pci_get_subclass(dev) != PCIS_BRIDGE_PCI ||
101 acpi_disabled("pci"))
103 if (acpi_get_handle(dev) == NULL)
105 if (pci_cfgregopen() == 0)
108 device_set_desc(dev, "ACPI PCI-PCI bridge");
113 acpi_pcib_pci_attach(device_t dev)
115 struct acpi_pcib_softc *sc;
117 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
119 pcib_attach_common(dev);
120 sc = device_get_softc(dev);
121 sc->ap_handle = acpi_get_handle(dev);
122 return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_pcibsc.secbus));
126 acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
128 struct acpi_pcib_softc *sc = device_get_softc(dev);
131 case ACPI_IVAR_HANDLE:
132 *result = (uintptr_t)sc->ap_handle;
135 return (pcib_read_ivar(dev, child, which, result));
139 acpi_pcib_pci_route_interrupt(device_t pcib, device_t dev, int pin)
141 struct acpi_pcib_softc *sc;
143 sc = device_get_softc(pcib);
146 * If we don't have a _PRT, fall back to the swizzle method
147 * for routing interrupts.
149 if (sc->ap_prt.Pointer == NULL)
150 return (pcib_route_interrupt(pcib, dev, pin));
152 return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt));