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_unbind(struct acpi_device
*device
);
49 static void acpi_pci_data_handler(acpi_handle handle
, u32 function
,
53 /* TBD: Anything we need to do here? */
61 * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem)
62 * to resolve PCI information for ACPI-PCI devices defined in the namespace.
63 * This typically occurs when resolving PCI operation region information.
65 acpi_status
acpi_get_pci_id(acpi_handle handle
, struct acpi_pci_id
*id
)
68 acpi_status status
= AE_OK
;
69 struct acpi_device
*device
= NULL
;
70 struct acpi_pci_data
*data
= NULL
;
74 return AE_BAD_PARAMETER
;
76 result
= acpi_bus_get_device(handle
, &device
);
78 printk(KERN_ERR PREFIX
79 "Invalid ACPI Bus context for device %s\n",
80 acpi_device_bid(device
));
84 status
= acpi_get_data(handle
, acpi_pci_data_handler
, (void **)&data
);
85 if (ACPI_FAILURE(status
) || !data
) {
86 ACPI_EXCEPTION((AE_INFO
, status
,
87 "Invalid ACPI-PCI context for device %s",
88 acpi_device_bid(device
)));
95 id->segment = data->id.segment;
96 id->bus = data->id.bus;
97 id->device = data->id.device;
98 id->function = data->id.function;
101 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
102 "Device %s has PCI address %04x:%02x:%02x.%d\n",
103 acpi_device_bid(device
), id
->segment
, id
->bus
,
104 id
->device
, id
->function
));
109 EXPORT_SYMBOL(acpi_get_pci_id
);
111 int acpi_pci_bind(struct acpi_device
*device
)
115 struct acpi_pci_data
*data
;
116 struct acpi_pci_data
*pdata
;
117 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
120 if (!device
|| !device
->parent
)
123 data
= kzalloc(sizeof(struct acpi_pci_data
), GFP_KERNEL
);
127 status
= acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
128 if (ACPI_FAILURE(status
)) {
133 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Binding PCI device [%s]...\n",
134 (char *)buffer
.pointer
));
139 * These are obtained via the parent device's ACPI-PCI context.
141 status
= acpi_get_data(device
->parent
->handle
, acpi_pci_data_handler
,
143 if (ACPI_FAILURE(status
) || !pdata
|| !pdata
->bus
) {
144 ACPI_EXCEPTION((AE_INFO
, status
,
145 "Invalid ACPI-PCI context for parent device %s",
146 acpi_device_bid(device
->parent
)));
150 data
->id
.segment
= pdata
->id
.segment
;
151 data
->id
.bus
= pdata
->bus
->number
;
156 * These are simply obtained from the device's _ADR method. Note
157 * that a value of zero is valid.
159 data
->id
.device
= device
->pnp
.bus_address
>> 16;
160 data
->id
.function
= device
->pnp
.bus_address
& 0xFFFF;
162 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "...to %04x:%02x:%02x.%d\n",
163 data
->id
.segment
, data
->id
.bus
, data
->id
.device
,
167 * TBD: Support slot devices (e.g. function=0xFFFF).
173 * Locate matching device in PCI namespace. If it doesn't exist
174 * this typically means that the device isn't currently inserted
175 * (e.g. docking station, port replicator, etc.).
177 data
->dev
= pci_get_slot(pdata
->bus
,
178 PCI_DEVFN(data
->id
.device
, data
->id
.function
));
180 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
181 "Device %04x:%02x:%02x.%d not present in PCI namespace\n",
182 data
->id
.segment
, data
->id
.bus
,
183 data
->id
.device
, data
->id
.function
));
187 if (!data
->dev
->bus
) {
188 printk(KERN_ERR PREFIX
189 "Device %04x:%02x:%02x.%d has invalid 'bus' field\n",
190 data
->id
.segment
, data
->id
.bus
,
191 data
->id
.device
, data
->id
.function
);
199 * If so, set the 'bus' field and install the 'bind' function to
200 * facilitate callbacks for all of its children.
202 if (data
->dev
->subordinate
) {
203 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
204 "Device %04x:%02x:%02x.%d is a PCI bridge\n",
205 data
->id
.segment
, data
->id
.bus
,
206 data
->id
.device
, data
->id
.function
));
207 data
->bus
= data
->dev
->subordinate
;
208 device
->ops
.bind
= acpi_pci_bind
;
209 device
->ops
.unbind
= acpi_pci_unbind
;
213 * Attach ACPI-PCI Context
214 * -----------------------
215 * Thus binding the ACPI and PCI devices.
217 status
= acpi_attach_data(device
->handle
, acpi_pci_data_handler
, data
);
218 if (ACPI_FAILURE(status
)) {
219 ACPI_EXCEPTION((AE_INFO
, status
,
220 "Unable to attach ACPI-PCI context to device %s",
221 acpi_device_bid(device
)));
229 * Evaluate and parse _PRT, if exists. This code is independent of
230 * PCI bridges (above) to allow parsing of _PRT objects within the
231 * scope of non-bridge devices. Note that _PRTs within the scope of
232 * a PCI bridge assume the bridge's subordinate bus number.
234 * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
236 status
= acpi_get_handle(device
->handle
, METHOD_NAME__PRT
, &handle
);
237 if (ACPI_SUCCESS(status
)) {
238 if (data
->bus
) /* PCI-PCI bridge */
239 acpi_pci_irq_add_prt(device
->handle
, data
->id
.segment
,
241 else /* non-bridge PCI device */
242 acpi_pci_irq_add_prt(device
->handle
, data
->id
.segment
,
247 kfree(buffer
.pointer
);
249 pci_dev_put(data
->dev
);
255 static int acpi_pci_unbind(struct acpi_device
*device
)
259 struct acpi_pci_data
*data
;
260 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
263 if (!device
|| !device
->parent
)
266 status
= acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
267 if (ACPI_FAILURE(status
))
270 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Unbinding PCI device [%s]...\n",
271 (char *) buffer
.pointer
));
272 kfree(buffer
.pointer
);
275 acpi_get_data(device
->handle
, acpi_pci_data_handler
,
277 if (ACPI_FAILURE(status
)) {
282 status
= acpi_detach_data(device
->handle
, acpi_pci_data_handler
);
283 if (ACPI_FAILURE(status
)) {
284 ACPI_EXCEPTION((AE_INFO
, status
,
285 "Unable to detach data from device %s",
286 acpi_device_bid(device
)));
290 if (data
->dev
->subordinate
) {
291 acpi_pci_irq_del_prt(data
->id
.segment
, data
->bus
->number
);
293 pci_dev_put(data
->dev
);
301 acpi_pci_bind_root(struct acpi_device
*device
,
302 struct acpi_pci_id
*id
, struct pci_bus
*bus
)
306 struct acpi_pci_data
*data
= NULL
;
307 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
309 if (!device
|| !id
|| !bus
) {
313 data
= kzalloc(sizeof(struct acpi_pci_data
), GFP_KERNEL
);
319 device
->ops
.bind
= acpi_pci_bind
;
320 device
->ops
.unbind
= acpi_pci_unbind
;
322 status
= acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
323 if (ACPI_FAILURE(status
)) {
328 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Binding PCI root bridge [%s] to "
329 "%04x:%02x\n", (char *)buffer
.pointer
,
330 id
->segment
, id
->bus
));
332 status
= acpi_attach_data(device
->handle
, acpi_pci_data_handler
, data
);
333 if (ACPI_FAILURE(status
)) {
334 ACPI_EXCEPTION((AE_INFO
, status
,
335 "Unable to attach ACPI-PCI context to device %s",
336 (char *)buffer
.pointer
));
342 kfree(buffer
.pointer
);
This page took 0.156883 seconds and 6 git commands to generate.