drm/i915: make hw page ioremap use ioremap_wc
[linux-2.6-block.git] / drivers / acpi / pci_root.c
CommitLineData
1da177e4
LT
1/*
2 * pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 40 $)
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
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.
13 *
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.
18 *
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.
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
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>
32#include <linux/pm.h>
33#include <linux/pci.h>
990a7ac5 34#include <linux/pci-acpi.h>
1da177e4
LT
35#include <linux/acpi.h>
36#include <acpi/acpi_bus.h>
37#include <acpi/acpi_drivers.h>
38
1da177e4 39#define _COMPONENT ACPI_PCI_COMPONENT
f52fd66d 40ACPI_MODULE_NAME("pci_root");
1da177e4 41#define ACPI_PCI_ROOT_CLASS "pci_bridge"
1da177e4 42#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
4be44fcd
LB
43static int acpi_pci_root_add(struct acpi_device *device);
44static int acpi_pci_root_remove(struct acpi_device *device, int type);
45static int acpi_pci_root_start(struct acpi_device *device);
1da177e4 46
1ba90e3a
TR
47static struct acpi_device_id root_device_ids[] = {
48 {"PNP0A03", 0},
49 {"", 0},
50};
51MODULE_DEVICE_TABLE(acpi, root_device_ids);
52
1da177e4 53static struct acpi_driver acpi_pci_root_driver = {
c2b6705b 54 .name = "pci_root",
4be44fcd 55 .class = ACPI_PCI_ROOT_CLASS,
1ba90e3a 56 .ids = root_device_ids,
4be44fcd
LB
57 .ops = {
58 .add = acpi_pci_root_add,
59 .remove = acpi_pci_root_remove,
60 .start = acpi_pci_root_start,
61 },
1da177e4
LT
62};
63
64struct acpi_pci_root {
4be44fcd 65 struct list_head node;
32917e5b 66 struct acpi_device * device;
4be44fcd
LB
67 struct acpi_pci_id id;
68 struct pci_bus *bus;
1da177e4
LT
69};
70
71static LIST_HEAD(acpi_pci_roots);
72
73static struct acpi_pci_driver *sub_driver;
74
75int acpi_pci_register_driver(struct acpi_pci_driver *driver)
76{
77 int n = 0;
78 struct list_head *entry;
79
80 struct acpi_pci_driver **pptr = &sub_driver;
81 while (*pptr)
82 pptr = &(*pptr)->next;
83 *pptr = driver;
84
85 if (!driver->add)
86 return 0;
87
88 list_for_each(entry, &acpi_pci_roots) {
89 struct acpi_pci_root *root;
90 root = list_entry(entry, struct acpi_pci_root, node);
2d1e0a02 91 driver->add(root->device->handle);
1da177e4
LT
92 n++;
93 }
94
95 return n;
96}
4be44fcd 97
1da177e4
LT
98EXPORT_SYMBOL(acpi_pci_register_driver);
99
100void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
101{
102 struct list_head *entry;
103
104 struct acpi_pci_driver **pptr = &sub_driver;
105 while (*pptr) {
f10bb254
AM
106 if (*pptr == driver)
107 break;
108 pptr = &(*pptr)->next;
1da177e4 109 }
f10bb254
AM
110 BUG_ON(!*pptr);
111 *pptr = (*pptr)->next;
1da177e4
LT
112
113 if (!driver->remove)
114 return;
115
116 list_for_each(entry, &acpi_pci_roots) {
117 struct acpi_pci_root *root;
118 root = list_entry(entry, struct acpi_pci_root, node);
2d1e0a02 119 driver->remove(root->device->handle);
1da177e4
LT
120 }
121}
4be44fcd 122
1da177e4
LT
123EXPORT_SYMBOL(acpi_pci_unregister_driver);
124
d91a0078
JC
125acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
126{
127 struct acpi_pci_root *tmp;
128
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;
132 }
133 return NULL;
134}
135
136EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
137
1da177e4 138static acpi_status
4be44fcd 139get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
1da177e4 140{
50dd0969 141 int *busnr = data;
1da177e4
LT
142 struct acpi_resource_address64 address;
143
50eca3eb
BM
144 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
145 resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
146 resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
1da177e4
LT
147 return AE_OK;
148
149 acpi_resource_to_address64(resource, &address);
4be44fcd
LB
150 if ((address.address_length > 0) &&
151 (address.resource_type == ACPI_BUS_NUMBER_RANGE))
50eca3eb 152 *busnr = address.minimum;
1da177e4
LT
153
154 return AE_OK;
155}
156
4be44fcd 157static acpi_status try_get_root_bridge_busnr(acpi_handle handle, int *busnum)
1da177e4
LT
158{
159 acpi_status status;
160
161 *busnum = -1;
4be44fcd
LB
162 status =
163 acpi_walk_resources(handle, METHOD_NAME__CRS,
164 get_root_bridge_busnr_callback, busnum);
1da177e4
LT
165 if (ACPI_FAILURE(status))
166 return status;
167 /* Check if we really get a bus number from _CRS */
168 if (*busnum == -1)
169 return AE_ERROR;
170 return AE_OK;
171}
172
2786f6e3
RZ
173static void acpi_pci_bridge_scan(struct acpi_device *device)
174{
175 int status;
176 struct acpi_device *child = NULL;
177
178 if (device->flags.bus_address)
179 if (device->parent && device->parent->ops.bind) {
180 status = device->parent->ops.bind(device);
181 if (!status) {
182 list_for_each_entry(child, &device->children, node)
183 acpi_pci_bridge_scan(child);
184 }
185 }
186}
187
b5678a34 188static int __devinit acpi_pci_root_add(struct acpi_device *device)
1da177e4 189{
4be44fcd
LB
190 int result = 0;
191 struct acpi_pci_root *root = NULL;
192 struct acpi_pci_root *tmp;
193 acpi_status status = AE_OK;
27663c58 194 unsigned long long value = 0;
4be44fcd 195 acpi_handle handle = NULL;
2786f6e3 196 struct acpi_device *child;
0ef5f8f6 197 u32 flags, base_flags;
1da177e4 198
1da177e4
LT
199
200 if (!device)
d550d98d 201 return -EINVAL;
1da177e4 202
36bcbec7 203 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
1da177e4 204 if (!root)
d550d98d 205 return -ENOMEM;
c431ada4 206 INIT_LIST_HEAD(&root->node);
1da177e4 207
32917e5b 208 root->device = device;
1da177e4
LT
209 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
210 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
db89b4f0 211 device->driver_data = root;
1da177e4 212
1da177e4
LT
213 device->ops.bind = acpi_pci_bind;
214
990a7ac5
AP
215 /*
216 * All supported architectures that use ACPI have support for
217 * PCI domains, so we indicate this in _OSC support capabilities.
218 */
0ef5f8f6 219 flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
990a7ac5
AP
220 pci_acpi_osc_support(device->handle, flags);
221
1da177e4
LT
222 /*
223 * Segment
224 * -------
225 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
226 */
2d1e0a02 227 status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL,
4be44fcd 228 &value);
1da177e4
LT
229 switch (status) {
230 case AE_OK:
231 root->id.segment = (u16) value;
232 break;
233 case AE_NOT_FOUND:
4be44fcd
LB
234 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
235 "Assuming segment 0 (no _SEG)\n"));
1da177e4
LT
236 root->id.segment = 0;
237 break;
238 default:
a6fc6720 239 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SEG"));
1da177e4
LT
240 result = -ENODEV;
241 goto end;
242 }
243
244 /*
245 * Bus
246 * ---
247 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
248 */
2d1e0a02 249 status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL,
4be44fcd 250 &value);
1da177e4
LT
251 switch (status) {
252 case AE_OK:
253 root->id.bus = (u16) value;
254 break;
255 case AE_NOT_FOUND:
256 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Assuming bus 0 (no _BBN)\n"));
257 root->id.bus = 0;
258 break;
259 default:
a6fc6720 260 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BBN"));
1da177e4
LT
261 result = -ENODEV;
262 goto end;
263 }
264
265 /* Some systems have wrong _BBN */
266 list_for_each_entry(tmp, &acpi_pci_roots, node) {
267 if ((tmp->id.segment == root->id.segment)
4be44fcd 268 && (tmp->id.bus == root->id.bus)) {
1da177e4
LT
269 int bus = 0;
270 acpi_status status;
271
6468463a 272 printk(KERN_ERR PREFIX
a6fc6720 273 "Wrong _BBN value, reboot"
6468463a 274 " and use option 'pci=noacpi'\n");
1da177e4 275
2d1e0a02 276 status = try_get_root_bridge_busnr(device->handle, &bus);
1da177e4
LT
277 if (ACPI_FAILURE(status))
278 break;
279 if (bus != root->id.bus) {
4be44fcd
LB
280 printk(KERN_INFO PREFIX
281 "PCI _CRS %d overrides _BBN 0\n", bus);
1da177e4
LT
282 root->id.bus = bus;
283 }
284 break;
285 }
286 }
287 /*
288 * Device & Function
289 * -----------------
290 * Obtained from _ADR (which has already been evaluated for us).
291 */
292 root->id.device = device->pnp.bus_address >> 16;
293 root->id.function = device->pnp.bus_address & 0xFFFF;
294
295 /*
296 * TBD: Need PCI interface for enumeration/configuration of roots.
297 */
298
4be44fcd
LB
299 /* TBD: Locking */
300 list_add_tail(&root->node, &acpi_pci_roots);
1da177e4 301
4be44fcd
LB
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);
1da177e4
LT
305
306 /*
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).
312 */
313 root->bus = pci_acpi_scan_root(device, root->id.segment, root->id.bus);
314 if (!root->bus) {
6468463a
LB
315 printk(KERN_ERR PREFIX
316 "Bus %04x:%02x not present in PCI namespace\n",
317 root->id.segment, root->id.bus);
1da177e4
LT
318 result = -ENODEV;
319 goto end;
320 }
321
322 /*
323 * Attach ACPI-PCI Context
324 * -----------------------
325 * Thus binding the ACPI and PCI devices.
326 */
327 result = acpi_pci_bind_root(device, &root->id, root->bus);
328 if (result)
329 goto end;
330
331 /*
332 * PCI Routing Table
333 * -----------------
334 * Evaluate and parse _PRT, if exists.
335 */
2d1e0a02 336 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
1da177e4 337 if (ACPI_SUCCESS(status))
2d1e0a02 338 result = acpi_pci_irq_add_prt(device->handle, root->id.segment,
4be44fcd 339 root->id.bus);
1da177e4 340
2786f6e3
RZ
341 /*
342 * Scan and bind all _ADR-Based Devices
343 */
344 list_for_each_entry(child, &device->children, node)
345 acpi_pci_bridge_scan(child);
346
0ef5f8f6
AP
347 /* Indicate support for various _OSC capabilities. */
348 if (pci_ext_cfg_avail(root->bus->self))
349 flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
3e1b1600
AP
350 if (pcie_aspm_enabled())
351 flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
352 OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
07ae95f9
AP
353 if (pci_msi_enabled())
354 flags |= OSC_MSI_SUPPORT;
0ef5f8f6
AP
355 if (flags != base_flags)
356 pci_acpi_osc_support(device->handle, flags);
357
4be44fcd 358 end:
c431ada4
RS
359 if (result) {
360 if (!list_empty(&root->node))
361 list_del(&root->node);
1da177e4 362 kfree(root);
c431ada4 363 }
1da177e4 364
d550d98d 365 return result;
1da177e4
LT
366}
367
4be44fcd 368static int acpi_pci_root_start(struct acpi_device *device)
c431ada4 369{
4be44fcd 370 struct acpi_pci_root *root;
c431ada4 371
c431ada4
RS
372
373 list_for_each_entry(root, &acpi_pci_roots, node) {
432bfaba 374 if (root->device == device) {
c431ada4 375 pci_bus_add_devices(root->bus);
d550d98d 376 return 0;
c431ada4
RS
377 }
378 }
d550d98d 379 return -ENODEV;
c431ada4 380}
1da177e4 381
4be44fcd 382static int acpi_pci_root_remove(struct acpi_device *device, int type)
1da177e4 383{
4be44fcd 384 struct acpi_pci_root *root = NULL;
1da177e4 385
1da177e4
LT
386
387 if (!device || !acpi_driver_data(device))
d550d98d 388 return -EINVAL;
1da177e4 389
50dd0969 390 root = acpi_driver_data(device);
1da177e4
LT
391
392 kfree(root);
393
d550d98d 394 return 0;
1da177e4
LT
395}
396
4be44fcd 397static int __init acpi_pci_root_init(void)
1da177e4 398{
1da177e4 399 if (acpi_pci_disabled)
d550d98d 400 return 0;
1da177e4 401
1da177e4 402 if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0)
d550d98d 403 return -ENODEV;
1da177e4 404
d550d98d 405 return 0;
1da177e4
LT
406}
407
408subsys_initcall(acpi_pci_root_init);