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/pci-acpi.h>
35 #include <linux/acpi.h>
36 #include <acpi/acpi_bus.h>
37 #include <acpi/acpi_drivers.h>
39 #define _COMPONENT ACPI_PCI_COMPONENT
40 ACPI_MODULE_NAME("pci_root");
41 #define ACPI_PCI_ROOT_CLASS "pci_bridge"
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_device_id root_device_ids
[] = {
51 MODULE_DEVICE_TABLE(acpi
, root_device_ids
);
53 static struct acpi_driver acpi_pci_root_driver
= {
55 .class = ACPI_PCI_ROOT_CLASS
,
56 .ids
= root_device_ids
,
58 .add
= acpi_pci_root_add
,
59 .remove
= acpi_pci_root_remove
,
60 .start
= acpi_pci_root_start
,
64 struct acpi_pci_root
{
65 struct list_head node
;
66 struct acpi_device
* device
;
67 struct acpi_pci_id id
;
71 static LIST_HEAD(acpi_pci_roots
);
73 static struct acpi_pci_driver
*sub_driver
;
75 int acpi_pci_register_driver(struct acpi_pci_driver
*driver
)
78 struct list_head
*entry
;
80 struct acpi_pci_driver
**pptr
= &sub_driver
;
82 pptr
= &(*pptr
)->next
;
88 list_for_each(entry
, &acpi_pci_roots
) {
89 struct acpi_pci_root
*root
;
90 root
= list_entry(entry
, struct acpi_pci_root
, node
);
91 driver
->add(root
->device
->handle
);
98 EXPORT_SYMBOL(acpi_pci_register_driver
);
100 void acpi_pci_unregister_driver(struct acpi_pci_driver
*driver
)
102 struct list_head
*entry
;
104 struct acpi_pci_driver
**pptr
= &sub_driver
;
108 pptr
= &(*pptr
)->next
;
111 *pptr
= (*pptr
)->next
;
116 list_for_each(entry
, &acpi_pci_roots
) {
117 struct acpi_pci_root
*root
;
118 root
= list_entry(entry
, struct acpi_pci_root
, node
);
119 driver
->remove(root
->device
->handle
);
123 EXPORT_SYMBOL(acpi_pci_unregister_driver
);
125 acpi_handle
acpi_get_pci_rootbridge_handle(unsigned int seg
, unsigned int bus
)
127 struct acpi_pci_root
*tmp
;
129 list_for_each_entry(tmp
, &acpi_pci_roots
, node
) {
130 if ((tmp
->id
.segment
== (u16
) seg
) && (tmp
->id
.bus
== (u16
) bus
))
131 return tmp
->device
->handle
;
136 EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle
);
139 get_root_bridge_busnr_callback(struct acpi_resource
*resource
, void *data
)
142 struct acpi_resource_address64 address
;
144 if (resource
->type
!= ACPI_RESOURCE_TYPE_ADDRESS16
&&
145 resource
->type
!= ACPI_RESOURCE_TYPE_ADDRESS32
&&
146 resource
->type
!= ACPI_RESOURCE_TYPE_ADDRESS64
)
149 acpi_resource_to_address64(resource
, &address
);
150 if ((address
.address_length
> 0) &&
151 (address
.resource_type
== ACPI_BUS_NUMBER_RANGE
))
152 *busnr
= address
.minimum
;
157 static acpi_status
try_get_root_bridge_busnr(acpi_handle handle
, int *busnum
)
163 acpi_walk_resources(handle
, METHOD_NAME__CRS
,
164 get_root_bridge_busnr_callback
, busnum
);
165 if (ACPI_FAILURE(status
))
167 /* Check if we really get a bus number from _CRS */
173 static void acpi_pci_bridge_scan(struct acpi_device
*device
)
176 struct acpi_device
*child
= NULL
;
178 if (device
->flags
.bus_address
)
179 if (device
->parent
&& device
->parent
->ops
.bind
) {
180 status
= device
->parent
->ops
.bind(device
);
182 list_for_each_entry(child
, &device
->children
, node
)
183 acpi_pci_bridge_scan(child
);
188 static int __devinit
acpi_pci_root_add(struct acpi_device
*device
)
191 struct acpi_pci_root
*root
= NULL
;
192 struct acpi_pci_root
*tmp
;
193 acpi_status status
= AE_OK
;
194 unsigned long long value
= 0;
195 acpi_handle handle
= NULL
;
196 struct acpi_device
*child
;
197 u32 flags
, base_flags
;
203 root
= kzalloc(sizeof(struct acpi_pci_root
), GFP_KERNEL
);
206 INIT_LIST_HEAD(&root
->node
);
208 root
->device
= device
;
209 strcpy(acpi_device_name(device
), ACPI_PCI_ROOT_DEVICE_NAME
);
210 strcpy(acpi_device_class(device
), ACPI_PCI_ROOT_CLASS
);
211 device
->driver_data
= root
;
213 device
->ops
.bind
= acpi_pci_bind
;
216 * All supported architectures that use ACPI have support for
217 * PCI domains, so we indicate this in _OSC support capabilities.
219 flags
= base_flags
= OSC_PCI_SEGMENT_GROUPS_SUPPORT
;
220 pci_acpi_osc_support(device
->handle
, flags
);
225 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
227 status
= acpi_evaluate_integer(device
->handle
, METHOD_NAME__SEG
, NULL
,
231 root
->id
.segment
= (u16
) value
;
234 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
235 "Assuming segment 0 (no _SEG)\n"));
236 root
->id
.segment
= 0;
239 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _SEG"));
247 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
249 status
= acpi_evaluate_integer(device
->handle
, METHOD_NAME__BBN
, NULL
,
253 root
->id
.bus
= (u16
) value
;
256 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Assuming bus 0 (no _BBN)\n"));
260 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _BBN"));
265 /* Some systems have wrong _BBN */
266 list_for_each_entry(tmp
, &acpi_pci_roots
, node
) {
267 if ((tmp
->id
.segment
== root
->id
.segment
)
268 && (tmp
->id
.bus
== root
->id
.bus
)) {
272 printk(KERN_ERR PREFIX
273 "Wrong _BBN value, reboot"
274 " and use option 'pci=noacpi'\n");
276 status
= try_get_root_bridge_busnr(device
->handle
, &bus
);
277 if (ACPI_FAILURE(status
))
279 if (bus
!= root
->id
.bus
) {
280 printk(KERN_INFO PREFIX
281 "PCI _CRS %d overrides _BBN 0\n", bus
);
290 * Obtained from _ADR (which has already been evaluated for us).
292 root
->id
.device
= device
->pnp
.bus_address
>> 16;
293 root
->id
.function
= device
->pnp
.bus_address
& 0xFFFF;
296 * TBD: Need PCI interface for enumeration/configuration of roots.
300 list_add_tail(&root
->node
, &acpi_pci_roots
);
302 printk(KERN_INFO PREFIX
"%s [%s] (%04x:%02x)\n",
303 acpi_device_name(device
), acpi_device_bid(device
),
304 root
->id
.segment
, root
->id
.bus
);
307 * Scan the Root Bridge
308 * --------------------
309 * Must do this prior to any attempt to bind the root device, as the
310 * PCI namespace does not get created until this call is made (and
311 * thus the root bridge's pci_dev does not exist).
313 root
->bus
= pci_acpi_scan_root(device
, root
->id
.segment
, root
->id
.bus
);
315 printk(KERN_ERR PREFIX
316 "Bus %04x:%02x not present in PCI namespace\n",
317 root
->id
.segment
, root
->id
.bus
);
323 * Attach ACPI-PCI Context
324 * -----------------------
325 * Thus binding the ACPI and PCI devices.
327 result
= acpi_pci_bind_root(device
, &root
->id
, root
->bus
);
334 * Evaluate and parse _PRT, if exists.
336 status
= acpi_get_handle(device
->handle
, METHOD_NAME__PRT
, &handle
);
337 if (ACPI_SUCCESS(status
))
338 result
= acpi_pci_irq_add_prt(device
->handle
, root
->id
.segment
,
342 * Scan and bind all _ADR-Based Devices
344 list_for_each_entry(child
, &device
->children
, node
)
345 acpi_pci_bridge_scan(child
);
347 /* Indicate support for various _OSC capabilities. */
348 if (pci_ext_cfg_avail(root
->bus
->self
))
349 flags
|= OSC_EXT_PCI_CONFIG_SUPPORT
;
350 if (pcie_aspm_enabled())
351 flags
|= OSC_ACTIVE_STATE_PWR_SUPPORT
|
352 OSC_CLOCK_PWR_CAPABILITY_SUPPORT
;
353 if (flags
!= base_flags
)
354 pci_acpi_osc_support(device
->handle
, flags
);
358 if (!list_empty(&root
->node
))
359 list_del(&root
->node
);
366 static int acpi_pci_root_start(struct acpi_device
*device
)
368 struct acpi_pci_root
*root
;
371 list_for_each_entry(root
, &acpi_pci_roots
, node
) {
372 if (root
->device
== device
) {
373 pci_bus_add_devices(root
->bus
);
380 static int acpi_pci_root_remove(struct acpi_device
*device
, int type
)
382 struct acpi_pci_root
*root
= NULL
;
385 if (!device
|| !acpi_driver_data(device
))
388 root
= acpi_driver_data(device
);
395 static int __init
acpi_pci_root_init(void)
397 if (acpi_pci_disabled
)
400 if (acpi_bus_register_driver(&acpi_pci_root_driver
) < 0)
406 subsys_initcall(acpi_pci_root_init
);