2 * pci_bind.c - ACPI PCI Device Binding ($Revision: 2 $)
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 struct acpi_pci_data
{
43 struct acpi_pci_id id
;
50 acpi_pci_data_handler (
55 ACPI_FUNCTION_TRACE("acpi_pci_data_handler");
57 /* TBD: Anything we need to do here? */
66 * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem)
67 * to resolve PCI information for ACPI-PCI devices defined in the namespace.
68 * This typically occurs when resolving PCI operation region information.
73 struct acpi_pci_id
*id
)
76 acpi_status status
= AE_OK
;
77 struct acpi_device
*device
= NULL
;
78 struct acpi_pci_data
*data
= NULL
;
80 ACPI_FUNCTION_TRACE("acpi_get_pci_id");
83 return_ACPI_STATUS(AE_BAD_PARAMETER
);
85 result
= acpi_bus_get_device(handle
, &device
);
87 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
88 "Invalid ACPI Bus context for device %s\n",
89 acpi_device_bid(device
)));
90 return_ACPI_STATUS(AE_NOT_EXIST
);
93 status
= acpi_get_data(handle
, acpi_pci_data_handler
, (void**) &data
);
94 if (ACPI_FAILURE(status
) || !data
) {
95 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
96 "Invalid ACPI-PCI context for device %s\n",
97 acpi_device_bid(device
)));
98 return_ACPI_STATUS(status
);
104 id->segment = data->id.segment;
105 id->bus = data->id.bus;
106 id->device = data->id.device;
107 id->function = data->id.function;
110 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
111 "Device %s has PCI address %02x:%02x:%02x.%02x\n",
112 acpi_device_bid(device
), id
->segment
, id
->bus
,
113 id
->device
, id
->function
));
115 return_ACPI_STATUS(AE_OK
);
117 EXPORT_SYMBOL(acpi_get_pci_id
);
122 struct acpi_device
*device
)
125 acpi_status status
= AE_OK
;
126 struct acpi_pci_data
*data
= NULL
;
127 struct acpi_pci_data
*pdata
= NULL
;
128 char *pathname
= NULL
;
129 struct acpi_buffer buffer
= {0, NULL
};
130 acpi_handle handle
= NULL
;
134 ACPI_FUNCTION_TRACE("acpi_pci_bind");
136 if (!device
|| !device
->parent
)
137 return_VALUE(-EINVAL
);
139 pathname
= kmalloc(ACPI_PATHNAME_MAX
, GFP_KERNEL
);
141 return_VALUE(-ENOMEM
);
142 memset(pathname
, 0, ACPI_PATHNAME_MAX
);
143 buffer
.length
= ACPI_PATHNAME_MAX
;
144 buffer
.pointer
= pathname
;
146 data
= kmalloc(sizeof(struct acpi_pci_data
), GFP_KERNEL
);
149 return_VALUE(-ENOMEM
);
151 memset(data
, 0, sizeof(struct acpi_pci_data
));
153 acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
154 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Binding PCI device [%s]...\n",
160 * These are obtained via the parent device's ACPI-PCI context.
162 status
= acpi_get_data(device
->parent
->handle
, acpi_pci_data_handler
,
164 if (ACPI_FAILURE(status
) || !pdata
|| !pdata
->bus
) {
165 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
166 "Invalid ACPI-PCI context for parent device %s\n",
167 acpi_device_bid(device
->parent
)));
171 data
->id
.segment
= pdata
->id
.segment
;
172 data
->id
.bus
= pdata
->bus
->number
;
177 * These are simply obtained from the device's _ADR method. Note
178 * that a value of zero is valid.
180 data
->id
.device
= device
->pnp
.bus_address
>> 16;
181 data
->id
.function
= device
->pnp
.bus_address
& 0xFFFF;
183 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "...to %02x:%02x:%02x.%02x\n",
184 data
->id
.segment
, data
->id
.bus
, data
->id
.device
,
188 * TBD: Support slot devices (e.g. function=0xFFFF).
194 * Locate matching device in PCI namespace. If it doesn't exist
195 * this typically means that the device isn't currently inserted
196 * (e.g. docking station, port replicator, etc.).
197 * We cannot simply search the global pci device list, since
198 * PCI devices are added to the global pci list when the root
199 * bridge start ops are run, which may not have happened yet.
201 bus
= pci_find_bus(data
->id
.segment
, data
->id
.bus
);
203 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
204 if (dev
->devfn
== PCI_DEVFN(data
->id
.device
,
205 data
->id
.function
)) {
212 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
213 "Device %02x:%02x:%02x.%02x not present in PCI namespace\n",
214 data
->id
.segment
, data
->id
.bus
,
215 data
->id
.device
, data
->id
.function
));
219 if (!data
->dev
->bus
) {
220 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
221 "Device %02x:%02x:%02x.%02x has invalid 'bus' field\n",
222 data
->id
.segment
, data
->id
.bus
,
223 data
->id
.device
, data
->id
.function
));
231 * If so, set the 'bus' field and install the 'bind' function to
232 * facilitate callbacks for all of its children.
234 if (data
->dev
->subordinate
) {
235 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
236 "Device %02x:%02x:%02x.%02x is a PCI bridge\n",
237 data
->id
.segment
, data
->id
.bus
,
238 data
->id
.device
, data
->id
.function
));
239 data
->bus
= data
->dev
->subordinate
;
240 device
->ops
.bind
= acpi_pci_bind
;
241 device
->ops
.unbind
= acpi_pci_unbind
;
245 * Attach ACPI-PCI Context
246 * -----------------------
247 * Thus binding the ACPI and PCI devices.
249 status
= acpi_attach_data(device
->handle
, acpi_pci_data_handler
, data
);
250 if (ACPI_FAILURE(status
)) {
251 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
252 "Unable to attach ACPI-PCI context to device %s\n",
253 acpi_device_bid(device
)));
261 * Evaluate and parse _PRT, if exists. This code is independent of
262 * PCI bridges (above) to allow parsing of _PRT objects within the
263 * scope of non-bridge devices. Note that _PRTs within the scope of
264 * a PCI bridge assume the bridge's subordinate bus number.
266 * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
268 status
= acpi_get_handle(device
->handle
, METHOD_NAME__PRT
, &handle
);
269 if (ACPI_SUCCESS(status
)) {
270 if (data
->bus
) /* PCI-PCI bridge */
271 acpi_pci_irq_add_prt(device
->handle
, data
->id
.segment
,
273 else /* non-bridge PCI device */
274 acpi_pci_irq_add_prt(device
->handle
, data
->id
.segment
,
283 return_VALUE(result
);
287 struct acpi_device
*device
)
290 acpi_status status
= AE_OK
;
291 struct acpi_pci_data
*data
= NULL
;
292 char *pathname
= NULL
;
293 struct acpi_buffer buffer
= {0, NULL
};
295 ACPI_FUNCTION_TRACE("acpi_pci_unbind");
297 if (!device
|| !device
->parent
)
298 return_VALUE(-EINVAL
);
300 pathname
= (char *) kmalloc(ACPI_PATHNAME_MAX
, GFP_KERNEL
);
302 return_VALUE(-ENOMEM
);
303 memset(pathname
, 0, ACPI_PATHNAME_MAX
);
305 buffer
.length
= ACPI_PATHNAME_MAX
;
306 buffer
.pointer
= pathname
;
307 acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
308 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Unbinding PCI device [%s]...\n",
312 status
= acpi_get_data(device
->handle
, acpi_pci_data_handler
, (void**)&data
);
313 if (ACPI_FAILURE(status
)) {
314 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
315 "Unable to get data from device %s\n",
316 acpi_device_bid(device
)));
321 status
= acpi_detach_data(device
->handle
, acpi_pci_data_handler
);
322 if (ACPI_FAILURE(status
)) {
323 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
324 "Unable to detach data from device %s\n",
325 acpi_device_bid(device
)));
329 if (data
->dev
->subordinate
) {
330 acpi_pci_irq_del_prt(data
->id
.segment
, data
->bus
->number
);
335 return_VALUE(result
);
340 struct acpi_device
*device
,
341 struct acpi_pci_id
*id
,
345 acpi_status status
= AE_OK
;
346 struct acpi_pci_data
*data
= NULL
;
347 char *pathname
= NULL
;
348 struct acpi_buffer buffer
= {0, NULL
};
350 ACPI_FUNCTION_TRACE("acpi_pci_bind_root");
352 pathname
= (char *)kmalloc(ACPI_PATHNAME_MAX
, GFP_KERNEL
);
354 return_VALUE(-ENOMEM
);
355 memset(pathname
, 0, ACPI_PATHNAME_MAX
);
357 buffer
.length
= ACPI_PATHNAME_MAX
;
358 buffer
.pointer
= pathname
;
360 if (!device
|| !id
|| !bus
){
362 return_VALUE(-EINVAL
);
365 data
= kmalloc(sizeof(struct acpi_pci_data
), GFP_KERNEL
);
368 return_VALUE(-ENOMEM
);
370 memset(data
, 0, sizeof(struct acpi_pci_data
));
374 device
->ops
.bind
= acpi_pci_bind
;
375 device
->ops
.unbind
= acpi_pci_unbind
;
377 acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
379 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Binding PCI root bridge [%s] to "
380 "%02x:%02x\n", pathname
, id
->segment
, id
->bus
));
382 status
= acpi_attach_data(device
->handle
, acpi_pci_data_handler
, data
);
383 if (ACPI_FAILURE(status
)) {
384 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
385 "Unable to attach ACPI-PCI context to device %s\n",
396 return_VALUE(result
);