kernel: Use NULL for DRIVER_MODULE()'s evh & arg (which are pointers).
[dragonfly.git] / sys / dev / acpica5 / acpi_pcib_pci.c
CommitLineData
5ed44076
MD
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
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
25 * SUCH DAMAGE.
32af04f7
SW
26 *
27 * $FreeBSD: src/sys/dev/acpica/acpi_pcib_pci.c,v 1.17.8.1 2009/04/15 03:14:26 kensmith Exp $
5ed44076
MD
28 */
29
30#include "opt_acpi.h"
31
32#include <sys/param.h>
33#include <sys/bus.h>
5ed44076 34#include <sys/kernel.h>
49e48b8a
MD
35#include <sys/malloc.h>
36#include <sys/module.h>
5ed44076
MD
37
38#include "acpi.h"
10f97674
AP
39#include <dev/acpica5/acpivar.h>
40#include <dev/acpica5/acpi_pcibvar.h>
5ed44076 41
5ed44076
MD
42#include <bus/pci/pcivar.h>
43#include <bus/pci/pcireg.h>
44#include <bus/pci/pcib_private.h>
5ed44076
MD
45#include "pcib_if.h"
46
49e48b8a 47/* Hooks for the ACPI CA debugging infrastructure. */
5ed44076
MD
48#define _COMPONENT ACPI_BUS
49ACPI_MODULE_NAME("PCI_PCI")
50
51struct acpi_pcib_softc {
52 struct pcib_softc ap_pcibsc;
53 ACPI_HANDLE ap_handle;
54 ACPI_BUFFER ap_prt; /* interrupt routing table */
55};
49e48b8a 56
5ed44076 57struct acpi_pcib_lookup_info {
49e48b8a
MD
58 UINT32 address;
59 ACPI_HANDLE handle;
5ed44076 60};
49e48b8a 61
5ed44076
MD
62static int acpi_pcib_pci_probe(device_t bus);
63static int acpi_pcib_pci_attach(device_t bus);
64static int acpi_pcib_pci_resume(device_t bus);
49e48b8a
MD
65static int acpi_pcib_read_ivar(device_t dev, device_t child,
66 int which, uintptr_t *result);
5ed44076 67static int acpi_pcib_pci_route_interrupt(device_t pcib,
49e48b8a 68 device_t dev, int pin);
5ed44076
MD
69
70static device_method_t acpi_pcib_pci_methods[] = {
71 /* Device interface */
72 DEVMETHOD(device_probe, acpi_pcib_pci_probe),
73 DEVMETHOD(device_attach, acpi_pcib_pci_attach),
74 DEVMETHOD(device_shutdown, bus_generic_shutdown),
75 DEVMETHOD(device_suspend, bus_generic_suspend),
76 DEVMETHOD(device_resume, acpi_pcib_pci_resume),
77
78 /* Bus interface */
79 DEVMETHOD(bus_print_child, bus_generic_print_child),
80 DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar),
81 DEVMETHOD(bus_write_ivar, pcib_write_ivar),
bf2bba47 82 DEVMETHOD(bus_alloc_resource, pcib_alloc_resource),
5ed44076
MD
83 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
84 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
85 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
86 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
87 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
88
89 /* pcib interface */
90 DEVMETHOD(pcib_maxslots, pcib_maxslots),
91 DEVMETHOD(pcib_read_config, pcib_read_config),
92 DEVMETHOD(pcib_write_config, pcib_write_config),
93 DEVMETHOD(pcib_route_interrupt, acpi_pcib_pci_route_interrupt),
10f97674
AP
94#ifdef MSI
95 DEVMETHOD(pcib_alloc_msi, pcib_alloc_msi),
96 DEVMETHOD(pcib_release_msi, pcib_release_msi),
97 DEVMETHOD(pcib_alloc_msix, pcib_alloc_msix),
98 DEVMETHOD(pcib_release_msix, pcib_release_msix),
99 DEVMETHOD(pcib_map_msi, pcib_map_msi),
100#endif
5ed44076
MD
101 {0, 0}
102};
103
10f97674
AP
104static devclass_t pcib_devclass;
105DEFINE_CLASS_0(pcib, acpi_pcib_pci_driver, acpi_pcib_pci_methods,
106 sizeof(struct acpi_pcib_softc));
aa2b9d05 107DRIVER_MODULE(acpi_pcib, pci, acpi_pcib_pci_driver, pcib_devclass, NULL, NULL);
f9d8cd12 108MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1);
5ed44076
MD
109
110static int
111acpi_pcib_pci_probe(device_t dev)
112{
2c61a93f
SZ
113 int error;
114
49e48b8a
MD
115 if (pci_get_class(dev) != PCIC_BRIDGE ||
116 pci_get_subclass(dev) != PCIS_BRIDGE_PCI ||
b184e355 117 acpi_disabled("pci"))
5ed44076 118 return (ENXIO);
2c61a93f
SZ
119
120 error = acpi_pcib_probe(dev);
121 if (error)
122 return (error);
5ed44076
MD
123
124 device_set_desc(dev, "ACPI PCI-PCI bridge");
10f97674 125 return (-100);
5ed44076
MD
126}
127
128static int
129acpi_pcib_pci_attach(device_t dev)
130{
131 struct acpi_pcib_softc *sc;
6388f614 132
5ed44076 133 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
6388f614 134
5ed44076
MD
135 pcib_attach_common(dev);
136 sc = device_get_softc(dev);
137 sc->ap_handle = acpi_get_handle(dev);
138 return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_pcibsc.secbus));
139}
140
141static int
142acpi_pcib_pci_resume(device_t dev)
143{
10f97674 144 return (acpi_pcib_resume(dev));
5ed44076
MD
145}
146
147static int
148acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
149{
49e48b8a 150 struct acpi_pcib_softc *sc = device_get_softc(dev);
5ed44076
MD
151
152 switch (which) {
49e48b8a 153 case ACPI_IVAR_HANDLE:
5ed44076 154 *result = (uintptr_t)sc->ap_handle;
49e48b8a 155 return (0);
5ed44076 156 }
49e48b8a 157 return (pcib_read_ivar(dev, child, which, result));
5ed44076
MD
158}
159
160static int
161acpi_pcib_pci_route_interrupt(device_t pcib, device_t dev, int pin)
162{
6388f614 163 struct acpi_pcib_softc *sc = device_get_softc(pcib);
f9d8cd12
MD
164
165 /*
166 * If we don't have a _PRT, fall back to the swizzle method
167 * for routing interrupts.
168 */
10f97674 169 if (sc->ap_prt.Pointer == NULL) {
6388f614 170 device_printf(pcib, "No _PRT found, routing with pci\n");
f9d8cd12 171 return (pcib_route_interrupt(pcib, dev, pin));
6388f614 172 } else {
f9d8cd12 173 return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt));
6388f614 174 }
5ed44076 175}