]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/acpi/pci_bind.c
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 void acpi_pci_data_handler(acpi_handle handle
, u32 function
, void *context
)
49 ACPI_FUNCTION_TRACE("acpi_pci_data_handler");
51 /* TBD: Anything we need to do here? */
59 * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem)
60 * to resolve PCI information for ACPI-PCI devices defined in the namespace.
61 * This typically occurs when resolving PCI operation region information.
63 acpi_status
acpi_get_pci_id(acpi_handle handle
, struct acpi_pci_id
*id
)
66 acpi_status status
= AE_OK
;
67 struct acpi_device
*device
= NULL
;
68 struct acpi_pci_data
*data
= NULL
;
70 ACPI_FUNCTION_TRACE("acpi_get_pci_id");
73 return_ACPI_STATUS(AE_BAD_PARAMETER
);
75 result
= acpi_bus_get_device(handle
, &device
);
77 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
78 "Invalid ACPI Bus context for device %s\n",
79 acpi_device_bid(device
)));
80 return_ACPI_STATUS(AE_NOT_EXIST
);
83 status
= acpi_get_data(handle
, acpi_pci_data_handler
, (void **)&data
);
84 if (ACPI_FAILURE(status
) || !data
) {
85 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
86 "Invalid ACPI-PCI context for device %s\n",
87 acpi_device_bid(device
)));
88 return_ACPI_STATUS(status
);
94 id->segment = data->id.segment;
95 id->bus = data->id.bus;
96 id->device = data->id.device;
97 id->function = data->id.function;
100 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
101 "Device %s has PCI address %02x:%02x:%02x.%02x\n",
102 acpi_device_bid(device
), id
->segment
, id
->bus
,
103 id
->device
, id
->function
));
105 return_ACPI_STATUS(AE_OK
);
108 EXPORT_SYMBOL(acpi_get_pci_id
);
110 int acpi_pci_bind(struct acpi_device
*device
)
113 acpi_status status
= AE_OK
;
114 struct acpi_pci_data
*data
= NULL
;
115 struct acpi_pci_data
*pdata
= NULL
;
116 char *pathname
= NULL
;
117 struct acpi_buffer buffer
= { 0, NULL
};
118 acpi_handle handle
= NULL
;
122 ACPI_FUNCTION_TRACE("acpi_pci_bind");
124 if (!device
|| !device
->parent
)
125 return_VALUE(-EINVAL
);
127 pathname
= kmalloc(ACPI_PATHNAME_MAX
, GFP_KERNEL
);
129 return_VALUE(-ENOMEM
);
130 memset(pathname
, 0, ACPI_PATHNAME_MAX
);
131 buffer
.length
= ACPI_PATHNAME_MAX
;
132 buffer
.pointer
= pathname
;
134 data
= kmalloc(sizeof(struct acpi_pci_data
), GFP_KERNEL
);
137 return_VALUE(-ENOMEM
);
139 memset(data
, 0, sizeof(struct acpi_pci_data
));
141 acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
142 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Binding PCI device [%s]...\n",
148 * These are obtained via the parent device's ACPI-PCI context.
150 status
= acpi_get_data(device
->parent
->handle
, acpi_pci_data_handler
,
152 if (ACPI_FAILURE(status
) || !pdata
|| !pdata
->bus
) {
153 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
154 "Invalid ACPI-PCI context for parent device %s\n",
155 acpi_device_bid(device
->parent
)));
159 data
->id
.segment
= pdata
->id
.segment
;
160 data
->id
.bus
= pdata
->bus
->number
;
165 * These are simply obtained from the device's _ADR method. Note
166 * that a value of zero is valid.
168 data
->id
.device
= device
->pnp
.bus_address
>> 16;
169 data
->id
.function
= device
->pnp
.bus_address
& 0xFFFF;
171 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "...to %02x:%02x:%02x.%02x\n",
172 data
->id
.segment
, data
->id
.bus
, data
->id
.device
,
176 * TBD: Support slot devices (e.g. function=0xFFFF).
182 * Locate matching device in PCI namespace. If it doesn't exist
183 * this typically means that the device isn't currently inserted
184 * (e.g. docking station, port replicator, etc.).
185 * We cannot simply search the global pci device list, since
186 * PCI devices are added to the global pci list when the root
187 * bridge start ops are run, which may not have happened yet.
189 bus
= pci_find_bus(data
->id
.segment
, data
->id
.bus
);
191 list_for_each_entry(dev
, &bus
->devices
, bus_list
) {
192 if (dev
->devfn
== PCI_DEVFN(data
->id
.device
,
193 data
->id
.function
)) {
200 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
201 "Device %02x:%02x:%02x.%02x not present in PCI namespace\n",
202 data
->id
.segment
, data
->id
.bus
,
203 data
->id
.device
, data
->id
.function
));
207 if (!data
->dev
->bus
) {
208 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
209 "Device %02x:%02x:%02x.%02x has invalid 'bus' field\n",
210 data
->id
.segment
, data
->id
.bus
,
211 data
->id
.device
, data
->id
.function
));
219 * If so, set the 'bus' field and install the 'bind' function to
220 * facilitate callbacks for all of its children.
222 if (data
->dev
->subordinate
) {
223 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
224 "Device %02x:%02x:%02x.%02x is a PCI bridge\n",
225 data
->id
.segment
, data
->id
.bus
,
226 data
->id
.device
, data
->id
.function
));
227 data
->bus
= data
->dev
->subordinate
;
228 device
->ops
.bind
= acpi_pci_bind
;
229 device
->ops
.unbind
= acpi_pci_unbind
;
233 * Attach ACPI-PCI Context
234 * -----------------------
235 * Thus binding the ACPI and PCI devices.
237 status
= acpi_attach_data(device
->handle
, acpi_pci_data_handler
, data
);
238 if (ACPI_FAILURE(status
)) {
239 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
240 "Unable to attach ACPI-PCI context to device %s\n",
241 acpi_device_bid(device
)));
249 * Evaluate and parse _PRT, if exists. This code is independent of
250 * PCI bridges (above) to allow parsing of _PRT objects within the
251 * scope of non-bridge devices. Note that _PRTs within the scope of
252 * a PCI bridge assume the bridge's subordinate bus number.
254 * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
256 status
= acpi_get_handle(device
->handle
, METHOD_NAME__PRT
, &handle
);
257 if (ACPI_SUCCESS(status
)) {
258 if (data
->bus
) /* PCI-PCI bridge */
259 acpi_pci_irq_add_prt(device
->handle
, data
->id
.segment
,
261 else /* non-bridge PCI device */
262 acpi_pci_irq_add_prt(device
->handle
, data
->id
.segment
,
271 return_VALUE(result
);
274 int acpi_pci_unbind(struct acpi_device
*device
)
277 acpi_status status
= AE_OK
;
278 struct acpi_pci_data
*data
= NULL
;
279 char *pathname
= NULL
;
280 struct acpi_buffer buffer
= { 0, NULL
};
282 ACPI_FUNCTION_TRACE("acpi_pci_unbind");
284 if (!device
|| !device
->parent
)
285 return_VALUE(-EINVAL
);
287 pathname
= (char *)kmalloc(ACPI_PATHNAME_MAX
, GFP_KERNEL
);
289 return_VALUE(-ENOMEM
);
290 memset(pathname
, 0, ACPI_PATHNAME_MAX
);
292 buffer
.length
= ACPI_PATHNAME_MAX
;
293 buffer
.pointer
= pathname
;
294 acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
295 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Unbinding PCI device [%s]...\n",
300 acpi_get_data(device
->handle
, acpi_pci_data_handler
,
302 if (ACPI_FAILURE(status
)) {
303 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
304 "Unable to get data from device %s\n",
305 acpi_device_bid(device
)));
310 status
= acpi_detach_data(device
->handle
, acpi_pci_data_handler
);
311 if (ACPI_FAILURE(status
)) {
312 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
313 "Unable to detach data from device %s\n",
314 acpi_device_bid(device
)));
318 if (data
->dev
->subordinate
) {
319 acpi_pci_irq_del_prt(data
->id
.segment
, data
->bus
->number
);
324 return_VALUE(result
);
328 acpi_pci_bind_root(struct acpi_device
*device
,
329 struct acpi_pci_id
*id
, struct pci_bus
*bus
)
332 acpi_status status
= AE_OK
;
333 struct acpi_pci_data
*data
= NULL
;
334 char *pathname
= NULL
;
335 struct acpi_buffer buffer
= { 0, NULL
};
337 ACPI_FUNCTION_TRACE("acpi_pci_bind_root");
339 pathname
= (char *)kmalloc(ACPI_PATHNAME_MAX
, GFP_KERNEL
);
341 return_VALUE(-ENOMEM
);
342 memset(pathname
, 0, ACPI_PATHNAME_MAX
);
344 buffer
.length
= ACPI_PATHNAME_MAX
;
345 buffer
.pointer
= pathname
;
347 if (!device
|| !id
|| !bus
) {
349 return_VALUE(-EINVAL
);
352 data
= kmalloc(sizeof(struct acpi_pci_data
), GFP_KERNEL
);
355 return_VALUE(-ENOMEM
);
357 memset(data
, 0, sizeof(struct acpi_pci_data
));
361 device
->ops
.bind
= acpi_pci_bind
;
362 device
->ops
.unbind
= acpi_pci_unbind
;
364 acpi_get_name(device
->handle
, ACPI_FULL_PATHNAME
, &buffer
);
366 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Binding PCI root bridge [%s] to "
367 "%02x:%02x\n", pathname
, id
->segment
, id
->bus
));
369 status
= acpi_attach_data(device
->handle
, acpi_pci_data_handler
, data
);
370 if (ACPI_FAILURE(status
)) {
371 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
372 "Unable to attach ACPI-PCI context to device %s\n",
383 return_VALUE(result
);