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>
38 #define _COMPONENT ACPI_PCI_COMPONENT
39 ACPI_MODULE_NAME("pci_bind");
41 struct acpi_pci_data
{
42 struct acpi_pci_id id
;
47 static int acpi_pci_bind(struct acpi_device
*device
);
48 static int acpi_pci_unbind(struct acpi_device
*device
);
50 static void acpi_pci_data_handler(acpi_handle handle
, u32 function
,
54 /* TBD: Anything we need to do here? */
62 * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem)
63 * to resolve PCI information for ACPI-PCI devices defined in the namespace.
64 * This typically occurs when resolving PCI operation region information.
66 acpi_status
acpi_get_pci_id(acpi_handle handle
, struct acpi_pci_id
*id
)
69 acpi_status status
= AE_OK
;
70 struct acpi_device
*device
= NULL
;
71 struct acpi_pci_data
*data
= NULL
;
75 return AE_BAD_PARAMETER
;
77 result
= acpi_bus_get_device(handle
, &device
);
79 printk(KERN_ERR PREFIX
80 "Invalid ACPI Bus context for device %s\n",
81 acpi_device_bid(device
));
85 status
= acpi_get_data(handle
, acpi_pci_data_handler
, (void **)&data
);
86 if (ACPI_FAILURE(status
) || !data
) {
87 ACPI_EXCEPTION((AE_INFO
, status
,
88 "Invalid ACPI-PCI context for device %s",
89 acpi_device_bid(device
)));
96 id->segment = data->id.segment;
97 id->bus = data->id.bus;
98 id->device = data->id.device;
99 id->function = data->id.function;
102 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
103 "Device %s has PCI address %04x:%02x:%02x.%d\n",
104 acpi_device_bid(device
), id
->segment
, id
->bus
,
105 id
->device
, id
->function
));
110 EXPORT_SYMBOL(acpi_get_pci_id
);
112 static int acpi_pci_bind(struct acpi_device
*device
)
116 struct acpi_pci_data
*data
;
117 struct acpi_pci_data
*pdata
;
118 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
121 if (!device
|| !device
->parent
)
124 data
= kzalloc(sizeof(struct acpi_pci_data
), GFP_KERNEL
);
128 status
= acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
129 if (ACPI_FAILURE(status
)) {
134 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Binding PCI device [%s]...\n",
135 (char *)buffer
.pointer
));
140 * These are obtained via the parent device's ACPI-PCI context.
142 status
= acpi_get_data(device
->parent
->handle
, acpi_pci_data_handler
,
144 if (ACPI_FAILURE(status
) || !pdata
|| !pdata
->bus
) {
145 ACPI_EXCEPTION((AE_INFO
, status
,
146 "Invalid ACPI-PCI context for parent device %s",
147 acpi_device_bid(device
->parent
)));
151 data
->id
.segment
= pdata
->id
.segment
;
152 data
->id
.bus
= pdata
->bus
->number
;
157 * These are simply obtained from the device's _ADR method. Note
158 * that a value of zero is valid.
160 data
->id
.device
= device
->pnp
.bus_address
>> 16;
161 data
->id
.function
= device
->pnp
.bus_address
& 0xFFFF;
163 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "...to %04x:%02x:%02x.%d\n",
164 data
->id
.segment
, data
->id
.bus
, data
->id
.device
,
168 * TBD: Support slot devices (e.g. function=0xFFFF).
174 * Locate matching device in PCI namespace. If it doesn't exist
175 * this typically means that the device isn't currently inserted
176 * (e.g. docking station, port replicator, etc.).
178 data
->dev
= pci_get_slot(pdata
->bus
,
179 PCI_DEVFN(data
->id
.device
, data
->id
.function
));
181 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
182 "Device %04x:%02x:%02x.%d not present in PCI namespace\n",
183 data
->id
.segment
, data
->id
.bus
,
184 data
->id
.device
, data
->id
.function
));
188 if (!data
->dev
->bus
) {
189 printk(KERN_ERR PREFIX
190 "Device %04x:%02x:%02x.%d has invalid 'bus' field\n",
191 data
->id
.segment
, data
->id
.bus
,
192 data
->id
.device
, data
->id
.function
);
200 * If so, set the 'bus' field and install the 'bind' function to
201 * facilitate callbacks for all of its children.
203 if (data
->dev
->subordinate
) {
204 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
205 "Device %04x:%02x:%02x.%d is a PCI bridge\n",
206 data
->id
.segment
, data
->id
.bus
,
207 data
->id
.device
, data
->id
.function
));
208 data
->bus
= data
->dev
->subordinate
;
209 device
->ops
.bind
= acpi_pci_bind
;
210 device
->ops
.unbind
= acpi_pci_unbind
;
214 * Attach ACPI-PCI Context
215 * -----------------------
216 * Thus binding the ACPI and PCI devices.
218 status
= acpi_attach_data(device
->handle
, acpi_pci_data_handler
, data
);
219 if (ACPI_FAILURE(status
)) {
220 ACPI_EXCEPTION((AE_INFO
, status
,
221 "Unable to attach ACPI-PCI context to device %s",
222 acpi_device_bid(device
)));
230 * Evaluate and parse _PRT, if exists. This code is independent of
231 * PCI bridges (above) to allow parsing of _PRT objects within the
232 * scope of non-bridge devices. Note that _PRTs within the scope of
233 * a PCI bridge assume the bridge's subordinate bus number.
235 * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
237 status
= acpi_get_handle(device
->handle
, METHOD_NAME__PRT
, &handle
);
238 if (ACPI_SUCCESS(status
)) {
239 if (data
->bus
) /* PCI-PCI bridge */
240 acpi_pci_irq_add_prt(device
->handle
, data
->id
.segment
,
242 else /* non-bridge PCI device */
243 acpi_pci_irq_add_prt(device
->handle
, data
->id
.segment
,
248 kfree(buffer
.pointer
);
250 pci_dev_put(data
->dev
);
256 static int acpi_pci_unbind(struct acpi_device
*device
)
260 struct acpi_pci_data
*data
;
261 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
264 if (!device
|| !device
->parent
)
267 status
= acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
268 if (ACPI_FAILURE(status
))
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Unbinding PCI device [%s]...\n",
272 (char *) buffer
.pointer
));
273 kfree(buffer
.pointer
);
276 acpi_get_data(device
->handle
, acpi_pci_data_handler
,
278 if (ACPI_FAILURE(status
)) {
283 status
= acpi_detach_data(device
->handle
, acpi_pci_data_handler
);
284 if (ACPI_FAILURE(status
)) {
285 ACPI_EXCEPTION((AE_INFO
, status
,
286 "Unable to detach data from device %s",
287 acpi_device_bid(device
)));
291 if (data
->dev
->subordinate
) {
292 acpi_pci_irq_del_prt(data
->id
.segment
, data
->bus
->number
);
294 pci_dev_put(data
->dev
);
302 acpi_pci_bind_root(struct acpi_device
*device
,
303 struct acpi_pci_id
*id
, struct pci_bus
*bus
)
307 struct acpi_pci_data
*data
= NULL
;
308 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
310 if (!device
|| !id
|| !bus
) {
314 data
= kzalloc(sizeof(struct acpi_pci_data
), GFP_KERNEL
);
320 device
->ops
.bind
= acpi_pci_bind
;
321 device
->ops
.unbind
= acpi_pci_unbind
;
323 status
= acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
324 if (ACPI_FAILURE(status
)) {
329 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Binding PCI root bridge [%s] to "
330 "%04x:%02x\n", (char *)buffer
.pointer
,
331 id
->segment
, id
->bus
));
333 status
= acpi_attach_data(device
->handle
, acpi_pci_data_handler
, data
);
334 if (ACPI_FAILURE(status
)) {
335 ACPI_EXCEPTION((AE_INFO
, status
,
336 "Unable to attach ACPI-PCI context to device %s",
337 (char *)buffer
.pointer
));
343 kfree(buffer
.pointer
);