2 * pci_bind.c - ACPI PCI Device Binding ($Revision: 3 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/proc_fs.h>
31 #include <linux/spinlock.h>
33 #include <linux/pci.h>
34 #include <linux/acpi.h>
35 #include <acpi/acpi_bus.h>
36 #include <acpi/acpi_drivers.h>
39 #define _COMPONENT ACPI_PCI_COMPONENT
40 ACPI_MODULE_NAME ("pci_bind")
42 #define PREFIX "ACPI: "
45 struct acpi_pci_data {
46 struct acpi_pci_id id;
53 acpi_pci_data_handler (
58 ACPI_FUNCTION_TRACE("acpi_pci_data_handler");
60 /* TBD: Anything we need to do here? */
69 * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem)
70 * to resolve PCI information for ACPI-PCI devices defined in the namespace.
71 * This typically occurs when resolving PCI operation region information.
76 struct acpi_pci_id *id)
79 acpi_status status = AE_OK;
80 struct acpi_device *device = NULL;
81 struct acpi_pci_data *data = NULL;
83 ACPI_FUNCTION_TRACE("acpi_os_get_pci_id");
86 return_ACPI_STATUS(AE_BAD_PARAMETER);
88 result = acpi_bus_get_device(handle, &device);
90 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
91 "Invalid ACPI Bus context for device %s\n",
92 acpi_device_bid(device)));
93 return_ACPI_STATUS(AE_NOT_EXIST);
96 status = acpi_get_data(handle, acpi_pci_data_handler, (void**) &data);
97 if (ACPI_FAILURE(status) || !data || !data->dev) {
98 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
99 "Invalid ACPI-PCI context for device %s\n",
100 acpi_device_bid(device)));
101 return_ACPI_STATUS(status);
107 id->segment = data->id.segment;
108 id->bus = data->id.bus;
109 id->device = data->id.device;
110 id->function = data->id.function;
113 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
114 "Device %s has PCI address %02x:%02x:%02x.%02x\n",
115 acpi_device_bid(device), id->segment, id->bus,
116 id->device, id->function));
118 return_ACPI_STATUS(AE_OK);
124 struct acpi_device *device)
127 acpi_status status = AE_OK;
128 struct acpi_pci_data *data = NULL;
129 struct acpi_pci_data *pdata = NULL;
130 char pathname[ACPI_PATHNAME_MAX] = {0};
131 struct acpi_buffer buffer = {ACPI_PATHNAME_MAX, pathname};
132 acpi_handle handle = NULL;
134 ACPI_FUNCTION_TRACE("acpi_pci_bind");
136 if (!device || !device->parent)
137 return_VALUE(-EINVAL);
139 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
141 return_VALUE(-ENOMEM);
142 memset(data, 0, sizeof(struct acpi_pci_data));
144 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
145 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n",
151 * These are obtained via the parent device's ACPI-PCI context.
153 status = acpi_get_data(device->parent->handle, acpi_pci_data_handler,
155 if (ACPI_FAILURE(status) || !pdata || !pdata->bus) {
156 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
157 "Invalid ACPI-PCI context for parent device %s\n",
158 acpi_device_bid(device->parent)));
162 data->id.segment = pdata->id.segment;
163 data->id.bus = pdata->bus->number;
168 * These are simply obtained from the device's _ADR method. Note
169 * that a value of zero is valid.
171 data->id.device = device->pnp.bus_address >> 16;
172 data->id.function = device->pnp.bus_address & 0xFFFF;
174 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "...to %02x:%02x:%02x.%02x\n",
175 data->id.segment, data->id.bus, data->id.device,
179 * TBD: Support slot devices (e.g. function=0xFFFF).
185 * Locate matching device in PCI namespace. If it doesn't exist
186 * this typically means that the device isn't currently inserted
187 * (e.g. docking station, port replicator, etc.).
189 data->dev = pci_find_slot(data->id.bus, PCI_DEVFN(data->id.device, data->id.function));
191 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
192 "Device %02x:%02x:%02x.%02x not present in PCI namespace\n",
193 data->id.segment, data->id.bus,
194 data->id.device, data->id.function));
198 if (!data->dev->bus) {
199 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
200 "Device %02x:%02x:%02x.%02x has invalid 'bus' field\n",
201 data->id.segment, data->id.bus,
202 data->id.device, data->id.function));
210 * If so, set the 'bus' field and install the 'bind' function to
211 * facilitate callbacks for all of its children.
213 if (data->dev->subordinate) {
214 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
215 "Device %02x:%02x:%02x.%02x is a PCI bridge\n",
216 data->id.segment, data->id.bus,
217 data->id.device, data->id.function));
218 data->bus = data->dev->subordinate;
219 device->ops.bind = acpi_pci_bind;
223 * Attach ACPI-PCI Context
224 * -----------------------
225 * Thus binding the ACPI and PCI devices.
227 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data);
228 if (ACPI_FAILURE(status)) {
229 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
230 "Unable to attach ACPI-PCI context to device %s\n",
231 acpi_device_bid(device)));
239 * Evaluate and parse _PRT, if exists. This code is independent of
240 * PCI bridges (above) to allow parsing of _PRT objects within the
241 * scope of non-bridge devices. Note that _PRTs within the scope of
242 * a PCI bridge assume the bridge's subordinate bus number.
244 * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
246 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
247 if (ACPI_SUCCESS(status)) {
248 if (data->bus) /* PCI-PCI bridge */
249 acpi_pci_irq_add_prt(device->handle, data->id.segment,
251 else /* non-bridge PCI device */
252 acpi_pci_irq_add_prt(device->handle, data->id.segment,
260 return_VALUE(result);
266 struct acpi_device *device,
267 struct acpi_pci_id *id,
271 acpi_status status = AE_OK;
272 struct acpi_pci_data *data = NULL;
273 char pathname[ACPI_PATHNAME_MAX] = {0};
274 struct acpi_buffer buffer = {ACPI_PATHNAME_MAX, pathname};
276 ACPI_FUNCTION_TRACE("acpi_pci_bind_root");
278 if (!device || !id || !bus)
279 return_VALUE(-EINVAL);
281 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
283 return_VALUE(-ENOMEM);
284 memset(data, 0, sizeof(struct acpi_pci_data));
288 device->ops.bind = acpi_pci_bind;
290 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
292 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI root bridge [%s] to "
293 "%02x:%02x\n", pathname, id->segment, id->bus));
295 status = acpi_attach_data(device->handle, acpi_pci_data_handler, data);
296 if (ACPI_FAILURE(status)) {
297 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
298 "Unable to attach ACPI-PCI context to device %s\n",
308 return_VALUE(result);