2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
3 * Copyright (c) 2000, Michael Smith <msmith@freebsd.org>
4 * Copyright (c) 2000, BSDi
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/sys/dev/acpica/acpi_pci.c,v 1.6 2003/09/17 08:32:44 iwasaki Exp $
29 * $DragonFly: src/sys/dev/acpica5/acpi_pci.c,v 1.1 2004/02/21 06:48:08 dillon Exp $
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/malloc.h>
39 #include <sys/module.h>
45 #include <sys/pciio.h>
46 #include <bus/pci/pcireg.h>
47 #include <bus/pci/pcivar.h>
48 #include <bus/pci/pci_private.h>
54 * Hooks for the ACPI CA debugging infrastructure
56 #define _COMPONENT ACPI_BUS
57 ACPI_MODULE_NAME("PCI")
59 struct acpi_pci_devinfo {
60 struct pci_devinfo ap_dinfo;
61 ACPI_HANDLE ap_handle;
64 static int acpi_pci_probe(device_t dev);
65 static int acpi_pci_attach(device_t dev);
66 static int acpi_pci_read_ivar(device_t dev, device_t child, int which,
69 static int acpi_pci_set_powerstate_method(device_t dev, device_t child,
71 static int acpi_pci_get_powerstate_method(device_t dev, device_t child);
73 static ACPI_STATUS acpi_pci_save_handle(ACPI_HANDLE handle, UINT32 level,
74 void *context, void **status);
76 static device_method_t acpi_pci_methods[] = {
77 /* Device interface */
78 DEVMETHOD(device_probe, acpi_pci_probe),
79 DEVMETHOD(device_attach, acpi_pci_attach),
80 DEVMETHOD(device_shutdown, bus_generic_shutdown),
81 DEVMETHOD(device_suspend, bus_generic_suspend),
82 DEVMETHOD(device_resume, pci_resume),
85 DEVMETHOD(bus_print_child, pci_print_child),
86 DEVMETHOD(bus_probe_nomatch, pci_probe_nomatch),
87 DEVMETHOD(bus_read_ivar, acpi_pci_read_ivar),
88 DEVMETHOD(bus_write_ivar, pci_write_ivar),
89 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
90 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
91 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
93 DEVMETHOD(bus_get_resource_list,pci_get_resource_list),
94 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
95 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
96 DEVMETHOD(bus_delete_resource, pci_delete_resource),
97 DEVMETHOD(bus_alloc_resource, pci_alloc_resource),
98 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
99 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
100 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
101 DEVMETHOD(bus_child_pnpinfo_str, pci_child_pnpinfo_str_method),
102 DEVMETHOD(bus_child_location_str, pci_child_location_str_method),
105 DEVMETHOD(pci_read_config, pci_read_config_method),
106 DEVMETHOD(pci_write_config, pci_write_config_method),
107 DEVMETHOD(pci_enable_busmaster, pci_enable_busmaster_method),
108 DEVMETHOD(pci_disable_busmaster, pci_disable_busmaster_method),
109 DEVMETHOD(pci_enable_io, pci_enable_io_method),
110 DEVMETHOD(pci_disable_io, pci_disable_io_method),
111 /* XXX: We should override these two. */
112 DEVMETHOD(pci_get_powerstate, pci_get_powerstate_method),
113 DEVMETHOD(pci_set_powerstate, pci_set_powerstate_method),
114 DEVMETHOD(pci_assign_interrupt, pci_assign_interrupt_method),
119 static driver_t acpi_pci_driver = {
125 DRIVER_MODULE(acpi_pci, pcib, acpi_pci_driver, pci_devclass, 0, 0);
126 MODULE_VERSION(acpi_pci, 1);
127 MODULE_DEPEND(acpi_pci, pci, 1, 1, 1);
130 acpi_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
132 struct acpi_pci_devinfo *dinfo;
135 case ACPI_IVAR_HANDLE:
136 dinfo = device_get_ivars(child);
137 *result = (uintptr_t)dinfo->ap_handle;
140 return(pci_read_ivar(dev, child, which, result));
145 * PCI power manangement
148 acpi_pci_set_powerstate_method(device_t dev, device_t child, int state)
155 acpi_pci_get_powerstate_method(device_t dev, device_t child)
163 acpi_pci_save_handle(ACPI_HANDLE handle, UINT32 level, void *context,
166 struct acpi_pci_devinfo *dinfo;
168 int devcount, i, func, slot;
171 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
173 if (ACPI_FAILURE(acpi_EvaluateInteger(handle, "_ADR", &address)))
174 return_ACPI_STATUS(AE_OK);
175 slot = address >> 16;
176 func = address & 0xffff;
177 if (device_get_children((device_t)context, &devlist, &devcount) != 0)
178 return_ACPI_STATUS(AE_OK);
179 for (i = 0; i < devcount; i++) {
180 dinfo = device_get_ivars(devlist[i]);
181 if (dinfo->ap_dinfo.cfg.func == func &&
182 dinfo->ap_dinfo.cfg.slot == slot) {
183 dinfo->ap_handle = handle;
184 free(devlist, M_TEMP);
185 return_ACPI_STATUS(AE_OK);
188 free(devlist, M_TEMP);
189 return_ACPI_STATUS(AE_OK);
193 acpi_pci_probe(device_t dev)
196 if (pcib_get_bus(dev) < 0)
199 device_set_desc(dev, "ACPI PCI bus");
201 if (acpi_get_handle(dev) == NULL)
207 acpi_pci_attach(device_t dev)
212 * Since there can be multiple independantly numbered PCI
213 * busses on some large alpha systems, we can't use the unit
214 * number to decide what bus we are probing. We ask the parent
215 * pcib what our bus number is.
217 busno = pcib_get_bus(dev);
219 device_printf(dev, "physical bus=%d\n", busno);
222 * First, PCI devices are added as in the normal PCI bus driver.
223 * Afterwards, the ACPI namespace under the bridge driver is
224 * walked to save ACPI handles to all the devices that appear in
225 * the ACPI namespace as immediate descendants of the bridge.
227 * XXX: Sometimes PCI devices show up in the ACPI namespace that
228 * pci_add_children() doesn't find. We currently just ignore
231 pci_add_children(dev, busno, sizeof(struct acpi_pci_devinfo));
232 (void) AcpiWalkNamespace(ACPI_TYPE_DEVICE, acpi_get_handle(dev), 1,
233 acpi_pci_save_handle, dev, NULL);
235 return (bus_generic_attach(dev));