Deleted Added
full compact
acpi_pcib_acpi.c (154079) acpi_pcib_acpi.c (164264)
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_acpi.c 154079 2006-01-06 19:22:19Z jhb $");
29__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_pcib_acpi.c 164264 2006-11-13 21:47:30Z jhb $");
30
31#include "opt_acpi.h"
32#include <sys/param.h>
33#include <sys/bus.h>
34#include <sys/kernel.h>
35#include <sys/malloc.h>
36#include <sys/module.h>
37#include <sys/sysctl.h>
38
39#include <contrib/dev/acpica/acpi.h>
40#include <dev/acpica/acpivar.h>
41
42#include <machine/pci_cfgreg.h>
43#include <dev/pci/pcivar.h>
44#include <dev/pci/pcib_private.h>
45#include "pcib_if.h"
46
47#include <dev/acpica/acpi_pcibvar.h>
48
49/* Hooks for the ACPI CA debugging infrastructure. */
50#define _COMPONENT ACPI_BUS
51ACPI_MODULE_NAME("PCI_ACPI")
52
53struct acpi_hpcib_softc {
54 device_t ap_dev;
55 ACPI_HANDLE ap_handle;
56 int ap_flags;
57
58 int ap_segment; /* analagous to Alpha 'hose' */
59 int ap_bus; /* bios-assigned bus number */
60
61 ACPI_BUFFER ap_prt; /* interrupt routing table */
62};
63
64static int acpi_pcib_acpi_probe(device_t bus);
65static int acpi_pcib_acpi_attach(device_t bus);
66static int acpi_pcib_acpi_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_write_ivar(device_t dev, device_t child,
70 int which, uintptr_t value);
71static uint32_t acpi_pcib_read_config(device_t dev, int bus, int slot,
72 int func, int reg, int bytes);
73static void acpi_pcib_write_config(device_t dev, int bus, int slot,
74 int func, int reg, uint32_t data, int bytes);
75static int acpi_pcib_acpi_route_interrupt(device_t pcib,
76 device_t dev, int pin);
77static struct resource *acpi_pcib_acpi_alloc_resource(device_t dev,
78 device_t child, int type, int *rid,
79 u_long start, u_long end, u_long count,
80 u_int flags);
81
82static device_method_t acpi_pcib_acpi_methods[] = {
83 /* Device interface */
84 DEVMETHOD(device_probe, acpi_pcib_acpi_probe),
85 DEVMETHOD(device_attach, acpi_pcib_acpi_attach),
86 DEVMETHOD(device_shutdown, bus_generic_shutdown),
87 DEVMETHOD(device_suspend, bus_generic_suspend),
88 DEVMETHOD(device_resume, acpi_pcib_acpi_resume),
89
90 /* Bus interface */
91 DEVMETHOD(bus_print_child, bus_generic_print_child),
92 DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar),
93 DEVMETHOD(bus_write_ivar, acpi_pcib_write_ivar),
94 DEVMETHOD(bus_alloc_resource, acpi_pcib_acpi_alloc_resource),
95 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
96 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
97 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
98 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
99 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
100
101 /* pcib interface */
102 DEVMETHOD(pcib_maxslots, pcib_maxslots),
103 DEVMETHOD(pcib_read_config, acpi_pcib_read_config),
104 DEVMETHOD(pcib_write_config, acpi_pcib_write_config),
105 DEVMETHOD(pcib_route_interrupt, acpi_pcib_acpi_route_interrupt),
30
31#include "opt_acpi.h"
32#include <sys/param.h>
33#include <sys/bus.h>
34#include <sys/kernel.h>
35#include <sys/malloc.h>
36#include <sys/module.h>
37#include <sys/sysctl.h>
38
39#include <contrib/dev/acpica/acpi.h>
40#include <dev/acpica/acpivar.h>
41
42#include <machine/pci_cfgreg.h>
43#include <dev/pci/pcivar.h>
44#include <dev/pci/pcib_private.h>
45#include "pcib_if.h"
46
47#include <dev/acpica/acpi_pcibvar.h>
48
49/* Hooks for the ACPI CA debugging infrastructure. */
50#define _COMPONENT ACPI_BUS
51ACPI_MODULE_NAME("PCI_ACPI")
52
53struct acpi_hpcib_softc {
54 device_t ap_dev;
55 ACPI_HANDLE ap_handle;
56 int ap_flags;
57
58 int ap_segment; /* analagous to Alpha 'hose' */
59 int ap_bus; /* bios-assigned bus number */
60
61 ACPI_BUFFER ap_prt; /* interrupt routing table */
62};
63
64static int acpi_pcib_acpi_probe(device_t bus);
65static int acpi_pcib_acpi_attach(device_t bus);
66static int acpi_pcib_acpi_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_write_ivar(device_t dev, device_t child,
70 int which, uintptr_t value);
71static uint32_t acpi_pcib_read_config(device_t dev, int bus, int slot,
72 int func, int reg, int bytes);
73static void acpi_pcib_write_config(device_t dev, int bus, int slot,
74 int func, int reg, uint32_t data, int bytes);
75static int acpi_pcib_acpi_route_interrupt(device_t pcib,
76 device_t dev, int pin);
77static struct resource *acpi_pcib_acpi_alloc_resource(device_t dev,
78 device_t child, int type, int *rid,
79 u_long start, u_long end, u_long count,
80 u_int flags);
81
82static device_method_t acpi_pcib_acpi_methods[] = {
83 /* Device interface */
84 DEVMETHOD(device_probe, acpi_pcib_acpi_probe),
85 DEVMETHOD(device_attach, acpi_pcib_acpi_attach),
86 DEVMETHOD(device_shutdown, bus_generic_shutdown),
87 DEVMETHOD(device_suspend, bus_generic_suspend),
88 DEVMETHOD(device_resume, acpi_pcib_acpi_resume),
89
90 /* Bus interface */
91 DEVMETHOD(bus_print_child, bus_generic_print_child),
92 DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar),
93 DEVMETHOD(bus_write_ivar, acpi_pcib_write_ivar),
94 DEVMETHOD(bus_alloc_resource, acpi_pcib_acpi_alloc_resource),
95 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
96 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
97 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
98 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
99 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
100
101 /* pcib interface */
102 DEVMETHOD(pcib_maxslots, pcib_maxslots),
103 DEVMETHOD(pcib_read_config, acpi_pcib_read_config),
104 DEVMETHOD(pcib_write_config, acpi_pcib_write_config),
105 DEVMETHOD(pcib_route_interrupt, acpi_pcib_acpi_route_interrupt),
106 DEVMETHOD(pcib_alloc_msi, pcib_alloc_msi),
107 DEVMETHOD(pcib_release_msi, pcib_release_msi),
108 DEVMETHOD(pcib_alloc_msix, pcib_alloc_msix),
109 DEVMETHOD(pcib_release_msix, pcib_release_msix),
106
107 {0, 0}
108};
109
110static devclass_t pcib_devclass;
111
112DEFINE_CLASS_0(pcib, acpi_pcib_acpi_driver, acpi_pcib_acpi_methods,
113 sizeof(struct acpi_hpcib_softc));
114DRIVER_MODULE(acpi_pcib, acpi, acpi_pcib_acpi_driver, pcib_devclass, 0, 0);
115MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1);
116
117static int
118acpi_pcib_acpi_probe(device_t dev)
119{
120 static char *pcib_ids[] = { "PNP0A03", NULL };
121
122 if (acpi_disabled("pcib") ||
123 ACPI_ID_PROBE(device_get_parent(dev), dev, pcib_ids) == NULL)
124 return (ENXIO);
125
126 if (pci_cfgregopen() == 0)
127 return (ENXIO);
128 device_set_desc(dev, "ACPI Host-PCI bridge");
129 return (0);
130}
131
132static int
133acpi_pcib_acpi_attach(device_t dev)
134{
135 struct acpi_hpcib_softc *sc;
136 ACPI_STATUS status;
137 u_int addr, slot, func, busok;
138 uint8_t busno;
139
140 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
141
142 sc = device_get_softc(dev);
143 sc->ap_dev = dev;
144 sc->ap_handle = acpi_get_handle(dev);
145
146 /*
147 * Get our base bus number by evaluating _BBN.
148 * If this doesn't work, we assume we're bus number 0.
149 *
150 * XXX note that it may also not exist in the case where we are
151 * meant to use a private configuration space mechanism for this bus,
152 * so we should dig out our resources and check to see if we have
153 * anything like that. How do we do this?
154 * XXX If we have the requisite information, and if we don't think the
155 * default PCI configuration space handlers can deal with this bus,
156 * we should attach our own handler.
157 * XXX invoke _REG on this for the PCI config space address space?
158 * XXX It seems many BIOS's with multiple Host-PCI bridges do not set
159 * _BBN correctly. They set _BBN to zero for all bridges. Thus,
160 * if _BBN is zero and pcib0 already exists, we try to read our
161 * bus number from the configuration registers at address _ADR.
162 */
163 status = acpi_GetInteger(sc->ap_handle, "_BBN", &sc->ap_bus);
164 if (ACPI_FAILURE(status)) {
165 if (status != AE_NOT_FOUND) {
166 device_printf(dev, "could not evaluate _BBN - %s\n",
167 AcpiFormatException(status));
168 return_VALUE (ENXIO);
169 } else {
170 /* If it's not found, assume 0. */
171 sc->ap_bus = 0;
172 }
173 }
174
175 /*
176 * If the bus is zero and pcib0 already exists, read the bus number
177 * via PCI config space.
178 */
179 busok = 1;
180 if (sc->ap_bus == 0 && devclass_get_device(pcib_devclass, 0) != dev) {
181 busok = 0;
182 status = acpi_GetInteger(sc->ap_handle, "_ADR", &addr);
183 if (ACPI_FAILURE(status)) {
184 if (status != AE_NOT_FOUND) {
185 device_printf(dev, "could not evaluate _ADR - %s\n",
186 AcpiFormatException(status));
187 return_VALUE (ENXIO);
188 } else
189 device_printf(dev, "couldn't find _ADR\n");
190 } else {
191 /* XXX: We assume bus 0. */
192 slot = ACPI_ADR_PCI_SLOT(addr);
193 func = ACPI_ADR_PCI_FUNC(addr);
194 if (bootverbose)
195 device_printf(dev, "reading config registers from 0:%d:%d\n",
196 slot, func);
197 if (host_pcib_get_busno(pci_cfgregread, 0, slot, func, &busno) == 0)
198 device_printf(dev, "couldn't read bus number from cfg space\n");
199 else {
200 sc->ap_bus = busno;
201 busok = 1;
202 }
203 }
204 }
205
206 /*
207 * If nothing else worked, hope that ACPI at least lays out the
208 * host-PCI bridges in order and that as a result our unit number
209 * is actually our bus number. There are several reasons this
210 * might not be true.
211 */
212 if (busok == 0) {
213 sc->ap_bus = device_get_unit(dev);
214 device_printf(dev, "trying bus number %d\n", sc->ap_bus);
215 }
216
217 /*
218 * Get our segment number by evaluating _SEG
219 * It's OK for this to not exist.
220 */
221 status = acpi_GetInteger(sc->ap_handle, "_SEG", &sc->ap_segment);
222 if (ACPI_FAILURE(status)) {
223 if (status != AE_NOT_FOUND) {
224 device_printf(dev, "could not evaluate _SEG - %s\n",
225 AcpiFormatException(status));
226 return_VALUE (ENXIO);
227 }
228 /* If it's not found, assume 0. */
229 sc->ap_segment = 0;
230 }
231
232 return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_bus));
233}
234
235static int
236acpi_pcib_acpi_resume(device_t dev)
237{
238
239 return (acpi_pcib_resume(dev));
240}
241
242/*
243 * Support for standard PCI bridge ivars.
244 */
245static int
246acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
247{
248 struct acpi_hpcib_softc *sc = device_get_softc(dev);
249
250 switch (which) {
251 case PCIB_IVAR_BUS:
252 *result = sc->ap_bus;
253 return (0);
254 case ACPI_IVAR_HANDLE:
255 *result = (uintptr_t)sc->ap_handle;
256 return (0);
257 case ACPI_IVAR_FLAGS:
258 *result = (uintptr_t)sc->ap_flags;
259 return (0);
260 }
261 return (ENOENT);
262}
263
264static int
265acpi_pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
266{
267 struct acpi_hpcib_softc *sc = device_get_softc(dev);
268
269 switch (which) {
270 case PCIB_IVAR_BUS:
271 sc->ap_bus = value;
272 return (0);
273 case ACPI_IVAR_HANDLE:
274 sc->ap_handle = (ACPI_HANDLE)value;
275 return (0);
276 case ACPI_IVAR_FLAGS:
277 sc->ap_flags = (int)value;
278 return (0);
279 }
280 return (ENOENT);
281}
282
283static uint32_t
284acpi_pcib_read_config(device_t dev, int bus, int slot, int func, int reg,
285 int bytes)
286{
287 return (pci_cfgregread(bus, slot, func, reg, bytes));
288}
289
290static void
291acpi_pcib_write_config(device_t dev, int bus, int slot, int func, int reg,
292 uint32_t data, int bytes)
293{
294 pci_cfgregwrite(bus, slot, func, reg, data, bytes);
295}
296
297static int
298acpi_pcib_acpi_route_interrupt(device_t pcib, device_t dev, int pin)
299{
300 struct acpi_hpcib_softc *sc = device_get_softc(pcib);
301
302 return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt));
303}
304
305static u_long acpi_host_mem_start = 0x80000000;
306TUNABLE_ULONG("hw.acpi.host_mem_start", &acpi_host_mem_start);
307
308struct resource *
309acpi_pcib_acpi_alloc_resource(device_t dev, device_t child, int type, int *rid,
310 u_long start, u_long end, u_long count, u_int flags)
311{
312 /*
313 * If no memory preference is given, use upper 32MB slot most
314 * bioses use for their memory window. Typically other bridges
315 * before us get in the way to assert their preferences on memory.
316 * Hardcoding like this sucks, so a more MD/MI way needs to be
317 * found to do it. This is typically only used on older laptops
318 * that don't have pci busses behind pci bridge, so assuming > 32MB
319 * is liekly OK.
320 */
321 if (type == SYS_RES_MEMORY && start == 0UL && end == ~0UL)
322 start = acpi_host_mem_start;
323 if (type == SYS_RES_IOPORT && start == 0UL && end == ~0UL)
324 start = 0x1000;
325 return (bus_generic_alloc_resource(dev, child, type, rid, start, end,
326 count, flags));
327}
110
111 {0, 0}
112};
113
114static devclass_t pcib_devclass;
115
116DEFINE_CLASS_0(pcib, acpi_pcib_acpi_driver, acpi_pcib_acpi_methods,
117 sizeof(struct acpi_hpcib_softc));
118DRIVER_MODULE(acpi_pcib, acpi, acpi_pcib_acpi_driver, pcib_devclass, 0, 0);
119MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1);
120
121static int
122acpi_pcib_acpi_probe(device_t dev)
123{
124 static char *pcib_ids[] = { "PNP0A03", NULL };
125
126 if (acpi_disabled("pcib") ||
127 ACPI_ID_PROBE(device_get_parent(dev), dev, pcib_ids) == NULL)
128 return (ENXIO);
129
130 if (pci_cfgregopen() == 0)
131 return (ENXIO);
132 device_set_desc(dev, "ACPI Host-PCI bridge");
133 return (0);
134}
135
136static int
137acpi_pcib_acpi_attach(device_t dev)
138{
139 struct acpi_hpcib_softc *sc;
140 ACPI_STATUS status;
141 u_int addr, slot, func, busok;
142 uint8_t busno;
143
144 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
145
146 sc = device_get_softc(dev);
147 sc->ap_dev = dev;
148 sc->ap_handle = acpi_get_handle(dev);
149
150 /*
151 * Get our base bus number by evaluating _BBN.
152 * If this doesn't work, we assume we're bus number 0.
153 *
154 * XXX note that it may also not exist in the case where we are
155 * meant to use a private configuration space mechanism for this bus,
156 * so we should dig out our resources and check to see if we have
157 * anything like that. How do we do this?
158 * XXX If we have the requisite information, and if we don't think the
159 * default PCI configuration space handlers can deal with this bus,
160 * we should attach our own handler.
161 * XXX invoke _REG on this for the PCI config space address space?
162 * XXX It seems many BIOS's with multiple Host-PCI bridges do not set
163 * _BBN correctly. They set _BBN to zero for all bridges. Thus,
164 * if _BBN is zero and pcib0 already exists, we try to read our
165 * bus number from the configuration registers at address _ADR.
166 */
167 status = acpi_GetInteger(sc->ap_handle, "_BBN", &sc->ap_bus);
168 if (ACPI_FAILURE(status)) {
169 if (status != AE_NOT_FOUND) {
170 device_printf(dev, "could not evaluate _BBN - %s\n",
171 AcpiFormatException(status));
172 return_VALUE (ENXIO);
173 } else {
174 /* If it's not found, assume 0. */
175 sc->ap_bus = 0;
176 }
177 }
178
179 /*
180 * If the bus is zero and pcib0 already exists, read the bus number
181 * via PCI config space.
182 */
183 busok = 1;
184 if (sc->ap_bus == 0 && devclass_get_device(pcib_devclass, 0) != dev) {
185 busok = 0;
186 status = acpi_GetInteger(sc->ap_handle, "_ADR", &addr);
187 if (ACPI_FAILURE(status)) {
188 if (status != AE_NOT_FOUND) {
189 device_printf(dev, "could not evaluate _ADR - %s\n",
190 AcpiFormatException(status));
191 return_VALUE (ENXIO);
192 } else
193 device_printf(dev, "couldn't find _ADR\n");
194 } else {
195 /* XXX: We assume bus 0. */
196 slot = ACPI_ADR_PCI_SLOT(addr);
197 func = ACPI_ADR_PCI_FUNC(addr);
198 if (bootverbose)
199 device_printf(dev, "reading config registers from 0:%d:%d\n",
200 slot, func);
201 if (host_pcib_get_busno(pci_cfgregread, 0, slot, func, &busno) == 0)
202 device_printf(dev, "couldn't read bus number from cfg space\n");
203 else {
204 sc->ap_bus = busno;
205 busok = 1;
206 }
207 }
208 }
209
210 /*
211 * If nothing else worked, hope that ACPI at least lays out the
212 * host-PCI bridges in order and that as a result our unit number
213 * is actually our bus number. There are several reasons this
214 * might not be true.
215 */
216 if (busok == 0) {
217 sc->ap_bus = device_get_unit(dev);
218 device_printf(dev, "trying bus number %d\n", sc->ap_bus);
219 }
220
221 /*
222 * Get our segment number by evaluating _SEG
223 * It's OK for this to not exist.
224 */
225 status = acpi_GetInteger(sc->ap_handle, "_SEG", &sc->ap_segment);
226 if (ACPI_FAILURE(status)) {
227 if (status != AE_NOT_FOUND) {
228 device_printf(dev, "could not evaluate _SEG - %s\n",
229 AcpiFormatException(status));
230 return_VALUE (ENXIO);
231 }
232 /* If it's not found, assume 0. */
233 sc->ap_segment = 0;
234 }
235
236 return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_bus));
237}
238
239static int
240acpi_pcib_acpi_resume(device_t dev)
241{
242
243 return (acpi_pcib_resume(dev));
244}
245
246/*
247 * Support for standard PCI bridge ivars.
248 */
249static int
250acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
251{
252 struct acpi_hpcib_softc *sc = device_get_softc(dev);
253
254 switch (which) {
255 case PCIB_IVAR_BUS:
256 *result = sc->ap_bus;
257 return (0);
258 case ACPI_IVAR_HANDLE:
259 *result = (uintptr_t)sc->ap_handle;
260 return (0);
261 case ACPI_IVAR_FLAGS:
262 *result = (uintptr_t)sc->ap_flags;
263 return (0);
264 }
265 return (ENOENT);
266}
267
268static int
269acpi_pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
270{
271 struct acpi_hpcib_softc *sc = device_get_softc(dev);
272
273 switch (which) {
274 case PCIB_IVAR_BUS:
275 sc->ap_bus = value;
276 return (0);
277 case ACPI_IVAR_HANDLE:
278 sc->ap_handle = (ACPI_HANDLE)value;
279 return (0);
280 case ACPI_IVAR_FLAGS:
281 sc->ap_flags = (int)value;
282 return (0);
283 }
284 return (ENOENT);
285}
286
287static uint32_t
288acpi_pcib_read_config(device_t dev, int bus, int slot, int func, int reg,
289 int bytes)
290{
291 return (pci_cfgregread(bus, slot, func, reg, bytes));
292}
293
294static void
295acpi_pcib_write_config(device_t dev, int bus, int slot, int func, int reg,
296 uint32_t data, int bytes)
297{
298 pci_cfgregwrite(bus, slot, func, reg, data, bytes);
299}
300
301static int
302acpi_pcib_acpi_route_interrupt(device_t pcib, device_t dev, int pin)
303{
304 struct acpi_hpcib_softc *sc = device_get_softc(pcib);
305
306 return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt));
307}
308
309static u_long acpi_host_mem_start = 0x80000000;
310TUNABLE_ULONG("hw.acpi.host_mem_start", &acpi_host_mem_start);
311
312struct resource *
313acpi_pcib_acpi_alloc_resource(device_t dev, device_t child, int type, int *rid,
314 u_long start, u_long end, u_long count, u_int flags)
315{
316 /*
317 * If no memory preference is given, use upper 32MB slot most
318 * bioses use for their memory window. Typically other bridges
319 * before us get in the way to assert their preferences on memory.
320 * Hardcoding like this sucks, so a more MD/MI way needs to be
321 * found to do it. This is typically only used on older laptops
322 * that don't have pci busses behind pci bridge, so assuming > 32MB
323 * is liekly OK.
324 */
325 if (type == SYS_RES_MEMORY && start == 0UL && end == ~0UL)
326 start = acpi_host_mem_start;
327 if (type == SYS_RES_IOPORT && start == 0UL && end == ~0UL)
328 start = 0x1000;
329 return (bus_generic_alloc_resource(dev, child, type, rid, start, end,
330 count, flags));
331}