1 /*
2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
3 * Copyright (c) 2000, Michael Smith <msmith@freebsd.org>
4 * Copyright (c) 2000, BSDi
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
12 * disclaimer.
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.
16 *
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.
27 *
28 * $FreeBSD: releng/5.1/sys/dev/acpica/acpi_pci.c 111056 2003-02-17 21:20:35Z imp $
29 *
30 */
31
32 #include "opt_bus.h"
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/bus.h>
37 #include <sys/kernel.h>
38 #include <sys/malloc.h>
39 #include <sys/module.h>
40
41 #include "acpi.h"
42
43 #include <dev/acpica/acpivar.h>
44
45 #include <sys/pciio.h>
46 #include <dev/pci/pcireg.h>
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/pci_private.h>
49
50 #include "pcib_if.h"
51 #include "pci_if.h"
52
53 /*
54 * Hooks for the ACPI CA debugging infrastructure
55 */
56 #define _COMPONENT ACPI_BUS
57 ACPI_MODULE_NAME("PCI")
58
59 struct acpi_pci_devinfo {
60 struct pci_devinfo ap_dinfo;
61 ACPI_HANDLE ap_handle;
62 };
63
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,
67 uintptr_t *result);
68 #if 0
69 static int acpi_pci_set_powerstate_method(device_t dev, device_t child,
70 int state);
71 static int acpi_pci_get_powerstate_method(device_t dev, device_t child);
72 #endif
73 static ACPI_STATUS acpi_pci_save_handle(ACPI_HANDLE handle, UINT32 level,
74 void *context, void **status);
75
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, bus_generic_resume),
83
84 /* Bus interface */
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),
92
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),
103
104 /* PCI interface */
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
115 { 0, 0 }
116 };
117
118 static driver_t acpi_pci_driver = {
119 "pci",
120 acpi_pci_methods,
121 0, /* no softc */
122 };
123
124 DRIVER_MODULE(acpi_pci, pcib, acpi_pci_driver, pci_devclass, 0, 0);
125 MODULE_VERSION(acpi_pci, 1);
126 MODULE_DEPEND(acpi_pci, pci, 1, 1, 1);
127
128 static int
129 acpi_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
130 {
131 struct acpi_pci_devinfo *dinfo;
132
133 switch (which) {
134 case ACPI_IVAR_HANDLE:
135 dinfo = device_get_ivars(child);
136 *result = (uintptr_t)dinfo->ap_handle;
137 return(0);
138 }
139 return(pci_read_ivar(dev, child, which, result));
140 }
141
142 #if 0
143 /*
144 * PCI power manangement
145 */
146 static int
147 acpi_pci_set_powerstate_method(device_t dev, device_t child, int state)
148 {
149 /* XXX: TODO */
150 return (ENXIO);
151 }
152
153 static int
154 acpi_pci_get_powerstate_method(device_t dev, device_t child)
155 {
156 /* XXX: TODO */
157 return (ENXIO);
158 }
159 #endif
160
161 static ACPI_STATUS
162 acpi_pci_save_handle(ACPI_HANDLE handle, UINT32 level, void *context,
163 void **status)
164 {
165 struct acpi_pci_devinfo *dinfo;
166 device_t *devlist;
167 int devcount, i, func, slot;
168 UINT32 address;
169
170 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
171
172 if (ACPI_FAILURE(acpi_EvaluateInteger(handle, "_ADR", &address)))
173 return_ACPI_STATUS(AE_OK);
174 slot = address >> 16;
175 func = address & 0xffff;
176 if (device_get_children((device_t)context, &devlist, &devcount) != 0)
177 return_ACPI_STATUS(AE_OK);
178 for (i = 0; i < devcount; i++) {
179 dinfo = device_get_ivars(devlist[i]);
180 if (dinfo->ap_dinfo.cfg.func == func &&
181 dinfo->ap_dinfo.cfg.slot == slot) {
182 dinfo->ap_handle = handle;
183 free(devlist, M_TEMP);
184 return_ACPI_STATUS(AE_OK);
185 }
186 }
187 free(devlist, M_TEMP);
188 return_ACPI_STATUS(AE_OK);
189 }
190
191 static int
192 acpi_pci_probe(device_t dev)
193 {
194
195 if (pcib_get_bus(dev) < 0)
196 return (ENXIO);
197
198 device_set_desc(dev, "ACPI PCI bus");
199
200 if (acpi_get_handle(dev) == NULL)
201 return (ENXIO);
202 return (0);
203 }
204
205 static int
206 acpi_pci_attach(device_t dev)
207 {
208 int busno;
209
210 /*
211 * Since there can be multiple independantly numbered PCI
212 * busses on some large alpha systems, we can't use the unit
213 * number to decide what bus we are probing. We ask the parent
214 * pcib what our bus number is.
215 */
216 busno = pcib_get_bus(dev);
217 if (bootverbose)
218 device_printf(dev, "physical bus=%d\n", busno);
219
220 /*
221 * First, PCI devices are added as in the normal PCI bus driver.
222 * Afterwards, the ACPI namespace under the bridge driver is
223 * walked to save ACPI handles to all the devices that appear in
224 * the ACPI namespace as immediate descendants of the bridge.
225 *
226 * XXX: Sometimes PCI devices show up in the ACPI namespace that
227 * pci_add_children() doesn't find. We currently just ignore
228 * these devices.
229 */
230 pci_add_children(dev, busno, sizeof(struct acpi_pci_devinfo));
231 (void) AcpiWalkNamespace(ACPI_TYPE_DEVICE, acpi_get_handle(dev), 1,
232 acpi_pci_save_handle, dev, NULL);
233
234 return (bus_generic_attach(dev));
235 }
Cache object: 8f3b0548aaaa62f37e9da5cdb002fc52
|