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_DRIVER_NAME "ACPI PCI Root Bridge Driver"
43 #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
44 static int acpi_pci_root_add(struct acpi_device
*device
);
45 static int acpi_pci_root_remove(struct acpi_device
*device
, int type
);
46 static int acpi_pci_root_start(struct acpi_device
*device
);
48 static struct acpi_driver acpi_pci_root_driver
= {
49 .name
= ACPI_PCI_ROOT_DRIVER_NAME
,
50 .class = ACPI_PCI_ROOT_CLASS
,
51 .ids
= ACPI_PCI_ROOT_HID
,
53 .add
= acpi_pci_root_add
,
54 .remove
= acpi_pci_root_remove
,
55 .start
= acpi_pci_root_start
,
59 struct acpi_pci_root
{
60 struct list_head node
;
62 struct acpi_pci_id id
;
66 static LIST_HEAD(acpi_pci_roots
);
68 static struct acpi_pci_driver
*sub_driver
;
70 int acpi_pci_register_driver(struct acpi_pci_driver
*driver
)
73 struct list_head
*entry
;
75 struct acpi_pci_driver
**pptr
= &sub_driver
;
77 pptr
= &(*pptr
)->next
;
83 list_for_each(entry
, &acpi_pci_roots
) {
84 struct acpi_pci_root
*root
;
85 root
= list_entry(entry
, struct acpi_pci_root
, node
);
86 driver
->add(root
->handle
);
93 EXPORT_SYMBOL(acpi_pci_register_driver
);
95 void acpi_pci_unregister_driver(struct acpi_pci_driver
*driver
)
97 struct list_head
*entry
;
99 struct acpi_pci_driver
**pptr
= &sub_driver
;
103 *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
->handle
);
117 EXPORT_SYMBOL(acpi_pci_unregister_driver
);
120 get_root_bridge_busnr_callback(struct acpi_resource
*resource
, void *data
)
122 int *busnr
= (int *)data
;
123 struct acpi_resource_address64 address
;
125 if (resource
->type
!= ACPI_RESOURCE_TYPE_ADDRESS16
&&
126 resource
->type
!= ACPI_RESOURCE_TYPE_ADDRESS32
&&
127 resource
->type
!= ACPI_RESOURCE_TYPE_ADDRESS64
)
130 acpi_resource_to_address64(resource
, &address
);
131 if ((address
.address_length
> 0) &&
132 (address
.resource_type
== ACPI_BUS_NUMBER_RANGE
))
133 *busnr
= address
.minimum
;
138 static acpi_status
try_get_root_bridge_busnr(acpi_handle handle
, int *busnum
)
144 acpi_walk_resources(handle
, METHOD_NAME__CRS
,
145 get_root_bridge_busnr_callback
, busnum
);
146 if (ACPI_FAILURE(status
))
148 /* Check if we really get a bus number from _CRS */
154 static int acpi_pci_root_add(struct acpi_device
*device
)
157 struct acpi_pci_root
*root
= NULL
;
158 struct acpi_pci_root
*tmp
;
159 acpi_status status
= AE_OK
;
160 unsigned long value
= 0;
161 acpi_handle handle
= NULL
;
163 ACPI_FUNCTION_TRACE("acpi_pci_root_add");
166 return_VALUE(-EINVAL
);
168 root
= kmalloc(sizeof(struct acpi_pci_root
), GFP_KERNEL
);
170 return_VALUE(-ENOMEM
);
171 memset(root
, 0, sizeof(struct acpi_pci_root
));
172 INIT_LIST_HEAD(&root
->node
);
174 root
->handle
= device
->handle
;
175 strcpy(acpi_device_name(device
), ACPI_PCI_ROOT_DEVICE_NAME
);
176 strcpy(acpi_device_class(device
), ACPI_PCI_ROOT_CLASS
);
177 acpi_driver_data(device
) = root
;
180 * TBD: Doesn't the bus driver automatically set this?
182 device
->ops
.bind
= acpi_pci_bind
;
187 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
189 status
= acpi_evaluate_integer(root
->handle
, METHOD_NAME__SEG
, NULL
,
193 root
->id
.segment
= (u16
) value
;
196 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
197 "Assuming segment 0 (no _SEG)\n"));
198 root
->id
.segment
= 0;
201 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error evaluating _SEG\n"));
209 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
211 status
= acpi_evaluate_integer(root
->handle
, METHOD_NAME__BBN
, NULL
,
215 root
->id
.bus
= (u16
) value
;
218 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Assuming bus 0 (no _BBN)\n"));
222 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error evaluating _BBN\n"));
227 /* Some systems have wrong _BBN */
228 list_for_each_entry(tmp
, &acpi_pci_roots
, node
) {
229 if ((tmp
->id
.segment
== root
->id
.segment
)
230 && (tmp
->id
.bus
== root
->id
.bus
)) {
234 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
235 "Wrong _BBN value, please reboot and using option 'pci=noacpi'\n"));
237 status
= try_get_root_bridge_busnr(root
->handle
, &bus
);
238 if (ACPI_FAILURE(status
))
240 if (bus
!= root
->id
.bus
) {
241 printk(KERN_INFO PREFIX
242 "PCI _CRS %d overrides _BBN 0\n", bus
);
251 * Obtained from _ADR (which has already been evaluated for us).
253 root
->id
.device
= device
->pnp
.bus_address
>> 16;
254 root
->id
.function
= device
->pnp
.bus_address
& 0xFFFF;
257 * TBD: Need PCI interface for enumeration/configuration of roots.
261 list_add_tail(&root
->node
, &acpi_pci_roots
);
263 printk(KERN_INFO PREFIX
"%s [%s] (%04x:%02x)\n",
264 acpi_device_name(device
), acpi_device_bid(device
),
265 root
->id
.segment
, root
->id
.bus
);
268 * Scan the Root Bridge
269 * --------------------
270 * Must do this prior to any attempt to bind the root device, as the
271 * PCI namespace does not get created until this call is made (and
272 * thus the root bridge's pci_dev does not exist).
274 root
->bus
= pci_acpi_scan_root(device
, root
->id
.segment
, root
->id
.bus
);
276 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
277 "Bus %04x:%02x not present in PCI namespace\n",
278 root
->id
.segment
, root
->id
.bus
));
284 * Attach ACPI-PCI Context
285 * -----------------------
286 * Thus binding the ACPI and PCI devices.
288 result
= acpi_pci_bind_root(device
, &root
->id
, root
->bus
);
295 * Evaluate and parse _PRT, if exists.
297 status
= acpi_get_handle(root
->handle
, METHOD_NAME__PRT
, &handle
);
298 if (ACPI_SUCCESS(status
))
299 result
= acpi_pci_irq_add_prt(root
->handle
, root
->id
.segment
,
304 if (!list_empty(&root
->node
))
305 list_del(&root
->node
);
309 return_VALUE(result
);
312 static int acpi_pci_root_start(struct acpi_device
*device
)
314 struct acpi_pci_root
*root
;
316 ACPI_FUNCTION_TRACE("acpi_pci_root_start");
318 list_for_each_entry(root
, &acpi_pci_roots
, node
) {
319 if (root
->handle
== device
->handle
) {
320 pci_bus_add_devices(root
->bus
);
324 return_VALUE(-ENODEV
);
327 static int acpi_pci_root_remove(struct acpi_device
*device
, int type
)
329 struct acpi_pci_root
*root
= NULL
;
331 ACPI_FUNCTION_TRACE("acpi_pci_root_remove");
333 if (!device
|| !acpi_driver_data(device
))
334 return_VALUE(-EINVAL
);
336 root
= (struct acpi_pci_root
*)acpi_driver_data(device
);
343 static int __init
acpi_pci_root_init(void)
345 ACPI_FUNCTION_TRACE("acpi_pci_root_init");
347 if (acpi_pci_disabled
)
351 acpi_dbg_layer = ACPI_PCI_COMPONENT;
352 acpi_dbg_level = 0xFFFFFFFF;
355 if (acpi_bus_register_driver(&acpi_pci_root_driver
) < 0)
356 return_VALUE(-ENODEV
);
361 subsys_initcall(acpi_pci_root_init
);