Deleted Added
full compact
acpi_pcib_pci.c (139339) acpi_pcib_pci.c (150003)
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.
26 */
27
28#include <sys/cdefs.h>
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.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_pcib_pci.c 139339 2004-12-27 05:36:47Z njl $");
29__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_pcib_pci.c 150003 2005-09-11 18:39:03Z obrien $");
30
31#include "opt_acpi.h"
32
33#include <sys/param.h>
34#include <sys/bus.h>
35#include <sys/kernel.h>
36#include <sys/malloc.h>
37#include <sys/module.h>
38
30
31#include "opt_acpi.h"
32
33#include <sys/param.h>
34#include <sys/bus.h>
35#include <sys/kernel.h>
36#include <sys/malloc.h>
37#include <sys/module.h>
38
39#include "acpi.h"
39#include <contrib/dev/acpica/acpi.h>
40#include <dev/acpica/acpivar.h>
41#include <dev/acpica/acpi_pcibvar.h>
42
43#include <machine/pci_cfgreg.h>
44#include <dev/pci/pcivar.h>
45#include <dev/pci/pcireg.h>
46#include <dev/pci/pcib_private.h>
47#include "pcib_if.h"
48
49/* Hooks for the ACPI CA debugging infrastructure. */
50#define _COMPONENT ACPI_BUS
51ACPI_MODULE_NAME("PCI_PCI")
52
53struct acpi_pcib_softc {
54 struct pcib_softc ap_pcibsc;
55 ACPI_HANDLE ap_handle;
56 ACPI_BUFFER ap_prt; /* interrupt routing table */
57};
58
59struct acpi_pcib_lookup_info {
60 UINT32 address;
61 ACPI_HANDLE handle;
62};
63
64static int acpi_pcib_pci_probe(device_t bus);
65static int acpi_pcib_pci_attach(device_t bus);
66static int acpi_pcib_pci_resume(device_t bus);
67static int acpi_pcib_read_ivar(device_t dev, device_t child,
68 int which, uintptr_t *result);
69static int acpi_pcib_pci_route_interrupt(device_t pcib,
70 device_t dev, int pin);
71
72static device_method_t acpi_pcib_pci_methods[] = {
73 /* Device interface */
74 DEVMETHOD(device_probe, acpi_pcib_pci_probe),
75 DEVMETHOD(device_attach, acpi_pcib_pci_attach),
76 DEVMETHOD(device_shutdown, bus_generic_shutdown),
77 DEVMETHOD(device_suspend, bus_generic_suspend),
78 DEVMETHOD(device_resume, acpi_pcib_pci_resume),
79
80 /* Bus interface */
81 DEVMETHOD(bus_print_child, bus_generic_print_child),
82 DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar),
83 DEVMETHOD(bus_write_ivar, pcib_write_ivar),
84 DEVMETHOD(bus_alloc_resource, pcib_alloc_resource),
85 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
86 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
87 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
88 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
89 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
90
91 /* pcib interface */
92 DEVMETHOD(pcib_maxslots, pcib_maxslots),
93 DEVMETHOD(pcib_read_config, pcib_read_config),
94 DEVMETHOD(pcib_write_config, pcib_write_config),
95 DEVMETHOD(pcib_route_interrupt, acpi_pcib_pci_route_interrupt),
96
97 {0, 0}
98};
99
100static driver_t acpi_pcib_pci_driver = {
101 "pcib",
102 acpi_pcib_pci_methods,
103 sizeof(struct acpi_pcib_softc),
104};
105
106DRIVER_MODULE(acpi_pcib, pci, acpi_pcib_pci_driver, pcib_devclass, 0, 0);
107MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1);
108
109static int
110acpi_pcib_pci_probe(device_t dev)
111{
112
113 if (pci_get_class(dev) != PCIC_BRIDGE ||
114 pci_get_subclass(dev) != PCIS_BRIDGE_PCI ||
115 acpi_disabled("pci"))
116 return (ENXIO);
117 if (acpi_get_handle(dev) == NULL)
118 return (ENXIO);
119 if (pci_cfgregopen() == 0)
120 return (ENXIO);
121
122 device_set_desc(dev, "ACPI PCI-PCI bridge");
123 return (-1000);
124}
125
126static int
127acpi_pcib_pci_attach(device_t dev)
128{
129 struct acpi_pcib_softc *sc;
130
131 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
132
133 pcib_attach_common(dev);
134 sc = device_get_softc(dev);
135 sc->ap_handle = acpi_get_handle(dev);
136 return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_pcibsc.secbus));
137}
138
139static int
140acpi_pcib_pci_resume(device_t dev)
141{
142
143 return (acpi_pcib_resume(dev));
144}
145
146static int
147acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
148{
149 struct acpi_pcib_softc *sc = device_get_softc(dev);
150
151 switch (which) {
152 case ACPI_IVAR_HANDLE:
153 *result = (uintptr_t)sc->ap_handle;
154 return (0);
155 }
156 return (pcib_read_ivar(dev, child, which, result));
157}
158
159static int
160acpi_pcib_pci_route_interrupt(device_t pcib, device_t dev, int pin)
161{
162 struct acpi_pcib_softc *sc;
163
164 sc = device_get_softc(pcib);
165
166 /*
167 * If we don't have a _PRT, fall back to the swizzle method
168 * for routing interrupts.
169 */
170 if (sc->ap_prt.Pointer == NULL)
171 return (pcib_route_interrupt(pcib, dev, pin));
172 else
173 return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt));
174}
40#include <dev/acpica/acpivar.h>
41#include <dev/acpica/acpi_pcibvar.h>
42
43#include <machine/pci_cfgreg.h>
44#include <dev/pci/pcivar.h>
45#include <dev/pci/pcireg.h>
46#include <dev/pci/pcib_private.h>
47#include "pcib_if.h"
48
49/* Hooks for the ACPI CA debugging infrastructure. */
50#define _COMPONENT ACPI_BUS
51ACPI_MODULE_NAME("PCI_PCI")
52
53struct acpi_pcib_softc {
54 struct pcib_softc ap_pcibsc;
55 ACPI_HANDLE ap_handle;
56 ACPI_BUFFER ap_prt; /* interrupt routing table */
57};
58
59struct acpi_pcib_lookup_info {
60 UINT32 address;
61 ACPI_HANDLE handle;
62};
63
64static int acpi_pcib_pci_probe(device_t bus);
65static int acpi_pcib_pci_attach(device_t bus);
66static int acpi_pcib_pci_resume(device_t bus);
67static int acpi_pcib_read_ivar(device_t dev, device_t child,
68 int which, uintptr_t *result);
69static int acpi_pcib_pci_route_interrupt(device_t pcib,
70 device_t dev, int pin);
71
72static device_method_t acpi_pcib_pci_methods[] = {
73 /* Device interface */
74 DEVMETHOD(device_probe, acpi_pcib_pci_probe),
75 DEVMETHOD(device_attach, acpi_pcib_pci_attach),
76 DEVMETHOD(device_shutdown, bus_generic_shutdown),
77 DEVMETHOD(device_suspend, bus_generic_suspend),
78 DEVMETHOD(device_resume, acpi_pcib_pci_resume),
79
80 /* Bus interface */
81 DEVMETHOD(bus_print_child, bus_generic_print_child),
82 DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar),
83 DEVMETHOD(bus_write_ivar, pcib_write_ivar),
84 DEVMETHOD(bus_alloc_resource, pcib_alloc_resource),
85 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
86 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
87 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
88 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
89 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
90
91 /* pcib interface */
92 DEVMETHOD(pcib_maxslots, pcib_maxslots),
93 DEVMETHOD(pcib_read_config, pcib_read_config),
94 DEVMETHOD(pcib_write_config, pcib_write_config),
95 DEVMETHOD(pcib_route_interrupt, acpi_pcib_pci_route_interrupt),
96
97 {0, 0}
98};
99
100static driver_t acpi_pcib_pci_driver = {
101 "pcib",
102 acpi_pcib_pci_methods,
103 sizeof(struct acpi_pcib_softc),
104};
105
106DRIVER_MODULE(acpi_pcib, pci, acpi_pcib_pci_driver, pcib_devclass, 0, 0);
107MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1);
108
109static int
110acpi_pcib_pci_probe(device_t dev)
111{
112
113 if (pci_get_class(dev) != PCIC_BRIDGE ||
114 pci_get_subclass(dev) != PCIS_BRIDGE_PCI ||
115 acpi_disabled("pci"))
116 return (ENXIO);
117 if (acpi_get_handle(dev) == NULL)
118 return (ENXIO);
119 if (pci_cfgregopen() == 0)
120 return (ENXIO);
121
122 device_set_desc(dev, "ACPI PCI-PCI bridge");
123 return (-1000);
124}
125
126static int
127acpi_pcib_pci_attach(device_t dev)
128{
129 struct acpi_pcib_softc *sc;
130
131 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
132
133 pcib_attach_common(dev);
134 sc = device_get_softc(dev);
135 sc->ap_handle = acpi_get_handle(dev);
136 return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_pcibsc.secbus));
137}
138
139static int
140acpi_pcib_pci_resume(device_t dev)
141{
142
143 return (acpi_pcib_resume(dev));
144}
145
146static int
147acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
148{
149 struct acpi_pcib_softc *sc = device_get_softc(dev);
150
151 switch (which) {
152 case ACPI_IVAR_HANDLE:
153 *result = (uintptr_t)sc->ap_handle;
154 return (0);
155 }
156 return (pcib_read_ivar(dev, child, which, result));
157}
158
159static int
160acpi_pcib_pci_route_interrupt(device_t pcib, device_t dev, int pin)
161{
162 struct acpi_pcib_softc *sc;
163
164 sc = device_get_softc(pcib);
165
166 /*
167 * If we don't have a _PRT, fall back to the swizzle method
168 * for routing interrupts.
169 */
170 if (sc->ap_prt.Pointer == NULL)
171 return (pcib_route_interrupt(pcib, dev, pin));
172 else
173 return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt));
174}