2 * pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 40 $)
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_root");
40 #define ACPI_PCI_ROOT_CLASS "pci_bridge"
41 #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
42 static int acpi_pci_root_add(struct acpi_device
*device
);
43 static int acpi_pci_root_remove(struct acpi_device
*device
, int type
);
44 static int acpi_pci_root_start(struct acpi_device
*device
);
46 static struct acpi_device_id root_device_ids
[] = {
50 MODULE_DEVICE_TABLE(acpi
, root_device_ids
);
52 static struct acpi_driver acpi_pci_root_driver
= {
54 .class = ACPI_PCI_ROOT_CLASS
,
55 .ids
= root_device_ids
,
57 .add
= acpi_pci_root_add
,
58 .remove
= acpi_pci_root_remove
,
59 .start
= acpi_pci_root_start
,
63 struct acpi_pci_root
{
64 struct list_head node
;
65 struct acpi_device
* device
;
66 struct acpi_pci_id id
;
70 static LIST_HEAD(acpi_pci_roots
);
72 static struct acpi_pci_driver
*sub_driver
;
74 int acpi_pci_register_driver(struct acpi_pci_driver
*driver
)
77 struct list_head
*entry
;
79 struct acpi_pci_driver
**pptr
= &sub_driver
;
81 pptr
= &(*pptr
)->next
;
87 list_for_each(entry
, &acpi_pci_roots
) {
88 struct acpi_pci_root
*root
;
89 root
= list_entry(entry
, struct acpi_pci_root
, node
);
90 driver
->add(root
->device
->handle
);
97 EXPORT_SYMBOL(acpi_pci_register_driver
);
99 void acpi_pci_unregister_driver(struct acpi_pci_driver
*driver
)
101 struct list_head
*entry
;
103 struct acpi_pci_driver
**pptr
= &sub_driver
;
107 pptr
= &(*pptr
)->next
;
110 *pptr
= (*pptr
)->next
;
115 list_for_each(entry
, &acpi_pci_roots
) {
116 struct acpi_pci_root
*root
;
117 root
= list_entry(entry
, struct acpi_pci_root
, node
);
118 driver
->remove(root
->device
->handle
);
122 EXPORT_SYMBOL(acpi_pci_unregister_driver
);
124 acpi_handle
acpi_get_pci_rootbridge_handle(unsigned int seg
, unsigned int bus
)
126 struct acpi_pci_root
*tmp
;
128 list_for_each_entry(tmp
, &acpi_pci_roots
, node
) {
129 if ((tmp
->id
.segment
== (u16
) seg
) && (tmp
->id
.bus
== (u16
) bus
))
130 return tmp
->device
->handle
;
135 EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle
);
138 get_root_bridge_busnr_callback(struct acpi_resource
*resource
, void *data
)
141 struct acpi_resource_address64 address
;
143 if (resource
->type
!= ACPI_RESOURCE_TYPE_ADDRESS16
&&
144 resource
->type
!= ACPI_RESOURCE_TYPE_ADDRESS32
&&
145 resource
->type
!= ACPI_RESOURCE_TYPE_ADDRESS64
)
148 acpi_resource_to_address64(resource
, &address
);
149 if ((address
.address_length
> 0) &&
150 (address
.resource_type
== ACPI_BUS_NUMBER_RANGE
))
151 *busnr
= address
.minimum
;
156 static acpi_status
try_get_root_bridge_busnr(acpi_handle handle
, int *busnum
)
162 acpi_walk_resources(handle
, METHOD_NAME__CRS
,
163 get_root_bridge_busnr_callback
, busnum
);
164 if (ACPI_FAILURE(status
))
166 /* Check if we really get a bus number from _CRS */
172 static void acpi_pci_bridge_scan(struct acpi_device
*device
)
175 struct acpi_device
*child
= NULL
;
177 if (device
->flags
.bus_address
)
178 if (device
->parent
&& device
->parent
->ops
.bind
) {
179 status
= device
->parent
->ops
.bind(device
);
181 list_for_each_entry(child
, &device
->children
, node
)
182 acpi_pci_bridge_scan(child
);
187 <<<<<<< HEAD
:drivers
/acpi
/pci_root
.c
188 static int acpi_pci_root_add(struct acpi_device
*device
)
190 static int __devinit
acpi_pci_root_add(struct acpi_device
*device
)
191 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/pci_root
.c
194 struct acpi_pci_root
*root
= NULL
;
195 struct acpi_pci_root
*tmp
;
196 acpi_status status
= AE_OK
;
197 unsigned long value
= 0;
198 acpi_handle handle
= NULL
;
199 struct acpi_device
*child
;
205 root
= kzalloc(sizeof(struct acpi_pci_root
), GFP_KERNEL
);
208 INIT_LIST_HEAD(&root
->node
);
210 root
->device
= device
;
211 strcpy(acpi_device_name(device
), ACPI_PCI_ROOT_DEVICE_NAME
);
212 strcpy(acpi_device_class(device
), ACPI_PCI_ROOT_CLASS
);
213 acpi_driver_data(device
) = root
;
215 device
->ops
.bind
= acpi_pci_bind
;
220 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
222 status
= acpi_evaluate_integer(device
->handle
, METHOD_NAME__SEG
, NULL
,
226 root
->id
.segment
= (u16
) value
;
229 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
230 "Assuming segment 0 (no _SEG)\n"));
231 root
->id
.segment
= 0;
234 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _SEG"));
242 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
244 status
= acpi_evaluate_integer(device
->handle
, METHOD_NAME__BBN
, NULL
,
248 root
->id
.bus
= (u16
) value
;
251 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Assuming bus 0 (no _BBN)\n"));
255 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _BBN"));
260 /* Some systems have wrong _BBN */
261 list_for_each_entry(tmp
, &acpi_pci_roots
, node
) {
262 if ((tmp
->id
.segment
== root
->id
.segment
)
263 && (tmp
->id
.bus
== root
->id
.bus
)) {
267 printk(KERN_ERR PREFIX
268 "Wrong _BBN value, reboot"
269 " and use option 'pci=noacpi'\n");
271 status
= try_get_root_bridge_busnr(device
->handle
, &bus
);
272 if (ACPI_FAILURE(status
))
274 if (bus
!= root
->id
.bus
) {
275 printk(KERN_INFO PREFIX
276 "PCI _CRS %d overrides _BBN 0\n", bus
);
285 * Obtained from _ADR (which has already been evaluated for us).
287 root
->id
.device
= device
->pnp
.bus_address
>> 16;
288 root
->id
.function
= device
->pnp
.bus_address
& 0xFFFF;
291 * TBD: Need PCI interface for enumeration/configuration of roots.
295 list_add_tail(&root
->node
, &acpi_pci_roots
);
297 printk(KERN_INFO PREFIX
"%s [%s] (%04x:%02x)\n",
298 acpi_device_name(device
), acpi_device_bid(device
),
299 root
->id
.segment
, root
->id
.bus
);
302 * Scan the Root Bridge
303 * --------------------
304 * Must do this prior to any attempt to bind the root device, as the
305 * PCI namespace does not get created until this call is made (and
306 * thus the root bridge's pci_dev does not exist).
308 root
->bus
= pci_acpi_scan_root(device
, root
->id
.segment
, root
->id
.bus
);
310 printk(KERN_ERR PREFIX
311 "Bus %04x:%02x not present in PCI namespace\n",
312 root
->id
.segment
, root
->id
.bus
);
318 * Attach ACPI-PCI Context
319 * -----------------------
320 * Thus binding the ACPI and PCI devices.
322 result
= acpi_pci_bind_root(device
, &root
->id
, root
->bus
);
329 * Evaluate and parse _PRT, if exists.
331 status
= acpi_get_handle(device
->handle
, METHOD_NAME__PRT
, &handle
);
332 if (ACPI_SUCCESS(status
))
333 result
= acpi_pci_irq_add_prt(device
->handle
, root
->id
.segment
,
337 * Scan and bind all _ADR-Based Devices
339 list_for_each_entry(child
, &device
->children
, node
)
340 acpi_pci_bridge_scan(child
);
344 if (!list_empty(&root
->node
))
345 list_del(&root
->node
);
352 static int acpi_pci_root_start(struct acpi_device
*device
)
354 struct acpi_pci_root
*root
;
357 list_for_each_entry(root
, &acpi_pci_roots
, node
) {
358 if (root
->device
== device
) {
359 pci_bus_add_devices(root
->bus
);
366 static int acpi_pci_root_remove(struct acpi_device
*device
, int type
)
368 struct acpi_pci_root
*root
= NULL
;
371 if (!device
|| !acpi_driver_data(device
))
374 root
= acpi_driver_data(device
);
381 static int __init
acpi_pci_root_init(void)
384 if (acpi_pci_disabled
)
388 acpi_dbg_layer = ACPI_PCI_COMPONENT;
389 acpi_dbg_level = 0xFFFFFFFF;
392 if (acpi_bus_register_driver(&acpi_pci_root_driver
) < 0)
398 subsys_initcall(acpi_pci_root_init
);