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_HID "PNP0A03"
42 #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
43 static int acpi_pci_root_add(struct acpi_device *device);
44 static int acpi_pci_root_remove(struct acpi_device *device, int type);
45 static int acpi_pci_root_start(struct acpi_device *device);
47 static struct acpi_driver acpi_pci_root_driver = {
49 .class = ACPI_PCI_ROOT_CLASS,
50 .ids = ACPI_PCI_ROOT_HID,
52 .add = acpi_pci_root_add,
53 .remove = acpi_pci_root_remove,
54 .start = acpi_pci_root_start,
58 struct acpi_pci_root {
59 struct list_head node;
60 struct acpi_device * device;
61 struct acpi_pci_id id;
65 static LIST_HEAD(acpi_pci_roots);
67 static struct acpi_pci_driver *sub_driver;
69 int acpi_pci_register_driver(struct acpi_pci_driver *driver)
72 struct list_head *entry;
74 struct acpi_pci_driver **pptr = &sub_driver;
76 pptr = &(*pptr)->next;
82 list_for_each(entry, &acpi_pci_roots) {
83 struct acpi_pci_root *root;
84 root = list_entry(entry, struct acpi_pci_root, node);
85 driver->add(root->device->handle);
92 EXPORT_SYMBOL(acpi_pci_register_driver);
94 void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
96 struct list_head *entry;
98 struct acpi_pci_driver **pptr = &sub_driver;
102 pptr = &(*pptr)->next;
105 *pptr = (*pptr)->next;
110 list_for_each(entry, &acpi_pci_roots) {
111 struct acpi_pci_root *root;
112 root = list_entry(entry, struct acpi_pci_root, node);
113 driver->remove(root->device->handle);
117 EXPORT_SYMBOL(acpi_pci_unregister_driver);
119 acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
121 struct acpi_pci_root *tmp;
123 list_for_each_entry(tmp, &acpi_pci_roots, node) {
124 if ((tmp->id.segment == (u16) seg) && (tmp->id.bus == (u16) bus))
125 return tmp->device->handle;
130 EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
133 get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
136 struct acpi_resource_address64 address;
138 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
139 resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
140 resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
143 acpi_resource_to_address64(resource, &address);
144 if ((address.address_length > 0) &&
145 (address.resource_type == ACPI_BUS_NUMBER_RANGE))
146 *busnr = address.minimum;
151 static acpi_status try_get_root_bridge_busnr(acpi_handle handle, int *busnum)
157 acpi_walk_resources(handle, METHOD_NAME__CRS,
158 get_root_bridge_busnr_callback, busnum);
159 if (ACPI_FAILURE(status))
161 /* Check if we really get a bus number from _CRS */
167 static void acpi_pci_bridge_scan(struct acpi_device *device)
170 struct acpi_device *child = NULL;
172 if (device->flags.bus_address)
173 if (device->parent && device->parent->ops.bind) {
174 status = device->parent->ops.bind(device);
176 list_for_each_entry(child, &device->children, node)
177 acpi_pci_bridge_scan(child);
182 static int acpi_pci_root_add(struct acpi_device *device)
185 struct acpi_pci_root *root = NULL;
186 struct acpi_pci_root *tmp;
187 acpi_status status = AE_OK;
188 unsigned long value = 0;
189 acpi_handle handle = NULL;
190 struct acpi_device *child;
196 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
199 INIT_LIST_HEAD(&root->node);
201 root->device = device;
202 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
203 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
204 acpi_driver_data(device) = root;
206 device->ops.bind = acpi_pci_bind;
211 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
213 status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL,
217 root->id.segment = (u16) value;
220 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
221 "Assuming segment 0 (no _SEG)\n"));
222 root->id.segment = 0;
225 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SEG"));
233 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
235 status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL,
239 root->id.bus = (u16) value;
242 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Assuming bus 0 (no _BBN)\n"));
246 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BBN"));
251 /* Some systems have wrong _BBN */
252 list_for_each_entry(tmp, &acpi_pci_roots, node) {
253 if ((tmp->id.segment == root->id.segment)
254 && (tmp->id.bus == root->id.bus)) {
258 printk(KERN_ERR PREFIX
259 "Wrong _BBN value, reboot"
260 " and use option 'pci=noacpi'\n");
262 status = try_get_root_bridge_busnr(device->handle, &bus);
263 if (ACPI_FAILURE(status))
265 if (bus != root->id.bus) {
266 printk(KERN_INFO PREFIX
267 "PCI _CRS %d overrides _BBN 0\n", bus);
276 * Obtained from _ADR (which has already been evaluated for us).
278 root->id.device = device->pnp.bus_address >> 16;
279 root->id.function = device->pnp.bus_address & 0xFFFF;
282 * TBD: Need PCI interface for enumeration/configuration of roots.
286 list_add_tail(&root->node, &acpi_pci_roots);
288 printk(KERN_INFO PREFIX "%s [%s] (%04x:%02x)\n",
289 acpi_device_name(device), acpi_device_bid(device),
290 root->id.segment, root->id.bus);
293 * Scan the Root Bridge
294 * --------------------
295 * Must do this prior to any attempt to bind the root device, as the
296 * PCI namespace does not get created until this call is made (and
297 * thus the root bridge's pci_dev does not exist).
299 root->bus = pci_acpi_scan_root(device, root->id.segment, root->id.bus);
301 printk(KERN_ERR PREFIX
302 "Bus %04x:%02x not present in PCI namespace\n",
303 root->id.segment, root->id.bus);
309 * Attach ACPI-PCI Context
310 * -----------------------
311 * Thus binding the ACPI and PCI devices.
313 result = acpi_pci_bind_root(device, &root->id, root->bus);
320 * Evaluate and parse _PRT, if exists.
322 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
323 if (ACPI_SUCCESS(status))
324 result = acpi_pci_irq_add_prt(device->handle, root->id.segment,
328 * Scan and bind all _ADR-Based Devices
330 list_for_each_entry(child, &device->children, node)
331 acpi_pci_bridge_scan(child);
335 if (!list_empty(&root->node))
336 list_del(&root->node);
343 static int acpi_pci_root_start(struct acpi_device *device)
345 struct acpi_pci_root *root;
348 list_for_each_entry(root, &acpi_pci_roots, node) {
349 if (root->device == device) {
350 pci_bus_add_devices(root->bus);
357 static int acpi_pci_root_remove(struct acpi_device *device, int type)
359 struct acpi_pci_root *root = NULL;
362 if (!device || !acpi_driver_data(device))
365 root = acpi_driver_data(device);
372 static int __init acpi_pci_root_init(void)
375 if (acpi_pci_disabled)
379 acpi_dbg_layer = ACPI_PCI_COMPONENT;
380 acpi_dbg_level = 0xFFFFFFFF;
383 if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0)
389 subsys_initcall(acpi_pci_root_init);