drm/i915: make hw page ioremap use ioremap_wc
[linux-2.6-block.git] / drivers / acpi / pci_irq.c
CommitLineData
1da177e4
LT
1/*
2 * pci_irq.c - ACPI PCI Interrupt Routing ($Revision: 11 $)
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 * Copyright (C) 2002 Dominik Brodowski <devel@brodo.de>
39488b04
BH
7 * (c) Copyright 2008 Hewlett-Packard Development Company, L.P.
8 * Bjorn Helgaas <bjorn.helgaas@hp.com>
1da177e4
LT
9 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 *
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 */
28
1da177e4 29
391df5dc 30#include <linux/dmi.h>
1da177e4
LT
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/init.h>
34#include <linux/types.h>
35#include <linux/proc_fs.h>
36#include <linux/spinlock.h>
37#include <linux/pm.h>
38#include <linux/pci.h>
39#include <linux/acpi.h>
40#include <acpi/acpi_bus.h>
41#include <acpi/acpi_drivers.h>
42
1da177e4 43#define _COMPONENT ACPI_PCI_COMPONENT
f52fd66d 44ACPI_MODULE_NAME("pci_irq");
1da177e4 45
f748bafa 46struct acpi_prt_entry {
3604a9f4 47 struct list_head list;
f748bafa
BH
48 struct acpi_pci_id id;
49 u8 pin;
4eaf6db3
BH
50 acpi_handle link;
51 u32 index; /* GSI, or link _CRS index */
f748bafa
BH
52};
53
3604a9f4 54static LIST_HEAD(acpi_prt_list);
1da177e4
LT
55static DEFINE_SPINLOCK(acpi_prt_lock);
56
cf68b80b
BH
57static inline char pin_name(int pin)
58{
e64e9db5 59 return 'A' + pin - 1;
cf68b80b
BH
60}
61
1da177e4
LT
62/* --------------------------------------------------------------------------
63 PCI IRQ Routing Table (PRT) Support
64 -------------------------------------------------------------------------- */
65
063563b4
BH
66static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(struct pci_dev *dev,
67 int pin)
1da177e4 68{
3604a9f4 69 struct acpi_prt_entry *entry;
063563b4
BH
70 int segment = pci_domain_nr(dev->bus);
71 int bus = dev->bus->number;
72 int device = PCI_SLOT(dev->devfn);
1da177e4 73
1da177e4 74 spin_lock(&acpi_prt_lock);
3604a9f4 75 list_for_each_entry(entry, &acpi_prt_list, list) {
4be44fcd
LB
76 if ((segment == entry->id.segment)
77 && (bus == entry->id.bus)
78 && (device == entry->id.device)
79 && (pin == entry->pin)) {
1da177e4 80 spin_unlock(&acpi_prt_lock);
d550d98d 81 return entry;
1da177e4
LT
82 }
83 }
1da177e4 84 spin_unlock(&acpi_prt_lock);
d550d98d 85 return NULL;
1da177e4
LT
86}
87
391df5dc
BH
88/* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
89static struct dmi_system_id medion_md9580[] = {
90 {
91 .ident = "Medion MD9580-F laptop",
92 .matches = {
93 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
94 DMI_MATCH(DMI_PRODUCT_NAME, "A555"),
95 },
96 },
97 { }
98};
99
100/* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
101static struct dmi_system_id dell_optiplex[] = {
102 {
103 .ident = "Dell Optiplex GX1",
104 .matches = {
105 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
106 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX1 600S+"),
107 },
108 },
109 { }
110};
111
112/* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */
113static struct dmi_system_id hp_t5710[] = {
114 {
115 .ident = "HP t5710",
116 .matches = {
117 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
118 DMI_MATCH(DMI_PRODUCT_NAME, "hp t5000 series"),
119 DMI_MATCH(DMI_BOARD_NAME, "098Ch"),
120 },
121 },
122 { }
123};
124
125struct prt_quirk {
126 struct dmi_system_id *system;
127 unsigned int segment;
128 unsigned int bus;
129 unsigned int device;
130 unsigned char pin;
131 char *source; /* according to BIOS */
132 char *actual_source;
133};
134
c458033c
BH
135#define PCI_INTX_PIN(c) (c - 'A' + 1)
136
391df5dc
BH
137/*
138 * These systems have incorrect _PRT entries. The BIOS claims the PCI
139 * interrupt at the listed segment/bus/device/pin is connected to the first
140 * link device, but it is actually connected to the second.
141 */
142static struct prt_quirk prt_quirks[] = {
c458033c 143 { medion_md9580, 0, 0, 9, PCI_INTX_PIN('A'),
b97d4803
BH
144 "\\_SB_.PCI0.ISA_.LNKA",
145 "\\_SB_.PCI0.ISA_.LNKB"},
c458033c 146 { dell_optiplex, 0, 0, 0xd, PCI_INTX_PIN('A'),
391df5dc
BH
147 "\\_SB_.LNKB",
148 "\\_SB_.LNKA"},
c458033c 149 { hp_t5710, 0, 0, 1, PCI_INTX_PIN('A'),
391df5dc
BH
150 "\\_SB_.PCI0.LNK1",
151 "\\_SB_.PCI0.LNK3"},
152};
153
3f0f3c27
BH
154static void do_prt_fixups(struct acpi_prt_entry *entry,
155 struct acpi_pci_routing_table *prt)
391df5dc
BH
156{
157 int i;
158 struct prt_quirk *quirk;
159
160 for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) {
161 quirk = &prt_quirks[i];
162
163 /* All current quirks involve link devices, not GSIs */
164 if (!prt->source)
165 continue;
166
167 if (dmi_check_system(quirk->system) &&
168 entry->id.segment == quirk->segment &&
169 entry->id.bus == quirk->bus &&
170 entry->id.device == quirk->device &&
c458033c 171 entry->pin == quirk->pin &&
391df5dc
BH
172 !strcmp(prt->source, quirk->source) &&
173 strlen(prt->source) >= strlen(quirk->actual_source)) {
174 printk(KERN_WARNING PREFIX "firmware reports "
c83642d5 175 "%04x:%02x:%02x PCI INT %c connected to %s; "
391df5dc
BH
176 "changing to %s\n",
177 entry->id.segment, entry->id.bus,
cf68b80b 178 entry->id.device, pin_name(entry->pin),
391df5dc
BH
179 prt->source, quirk->actual_source);
180 strcpy(prt->source, quirk->actual_source);
181 }
182 }
183}
184
3f0f3c27
BH
185static int acpi_pci_irq_add_entry(acpi_handle handle, int segment, int bus,
186 struct acpi_pci_routing_table *prt)
1da177e4 187{
3604a9f4 188 struct acpi_prt_entry *entry;
1da177e4 189
36bcbec7 190 entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
1da177e4 191 if (!entry)
d550d98d 192 return -ENOMEM;
1da177e4 193
e64e9db5
BH
194 /*
195 * Note that the _PRT uses 0=INTA, 1=INTB, etc, while PCI uses
196 * 1=INTA, 2=INTB. We use the PCI encoding throughout, so convert
197 * it here.
198 */
1da177e4
LT
199 entry->id.segment = segment;
200 entry->id.bus = bus;
201 entry->id.device = (prt->address >> 16) & 0xFFFF;
e64e9db5 202 entry->pin = prt->pin + 1;
1da177e4 203
391df5dc
BH
204 do_prt_fixups(entry, prt);
205
4eaf6db3
BH
206 entry->index = prt->source_index;
207
1da177e4
LT
208 /*
209 * Type 1: Dynamic
210 * ---------------
211 * The 'source' field specifies the PCI interrupt link device used to
212 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
213 * indicates which resource descriptor in the resource template (of
214 * the link device) this interrupt is allocated from.
215 *
216 * NOTE: Don't query the Link Device for IRQ information at this time
217 * because Link Device enumeration may not have occurred yet
218 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
219 * namespace).
220 */
4eaf6db3
BH
221 if (prt->source[0])
222 acpi_get_handle(handle, prt->source, &entry->link);
223
1da177e4
LT
224 /*
225 * Type 2: Static
226 * --------------
227 * The 'source' field is NULL, and the 'source_index' field specifies
228 * the IRQ value, which is hardwired to specific interrupt inputs on
229 * the interrupt controller.
230 */
1da177e4
LT
231
232 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
21a53283 233 " %04x:%02x:%02x[%c] -> %s[%d]\n",
4be44fcd 234 entry->id.segment, entry->id.bus,
cf68b80b 235 entry->id.device, pin_name(entry->pin),
4eaf6db3 236 prt->source, entry->index));
1da177e4
LT
237
238 spin_lock(&acpi_prt_lock);
3604a9f4 239 list_add_tail(&entry->list, &acpi_prt_list);
1da177e4
LT
240 spin_unlock(&acpi_prt_lock);
241
d550d98d 242 return 0;
1da177e4
LT
243}
244
4be44fcd 245int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
1da177e4 246{
2320ac6c
BH
247 acpi_status status;
248 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
249 struct acpi_pci_routing_table *entry;
1da177e4 250
2320ac6c
BH
251 /* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */
252 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
253 if (ACPI_FAILURE(status))
254 return -ENODEV;
1da177e4
LT
255
256 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
2320ac6c 257 (char *) buffer.pointer);
1da177e4 258
2320ac6c 259 kfree(buffer.pointer);
1da177e4 260
2320ac6c 261 buffer.length = ACPI_ALLOCATE_BUFFER;
1da177e4 262 buffer.pointer = NULL;
1da177e4
LT
263
264 status = acpi_get_irq_routing_table(handle, &buffer);
265 if (ACPI_FAILURE(status)) {
a6fc6720
TR
266 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
267 acpi_format_exception(status)));
1da177e4 268 kfree(buffer.pointer);
d550d98d 269 return -ENODEV;
1da177e4
LT
270 }
271
2320ac6c 272 entry = buffer.pointer;
1da177e4
LT
273 while (entry && (entry->length > 0)) {
274 acpi_pci_irq_add_entry(handle, segment, bus, entry);
275 entry = (struct acpi_pci_routing_table *)
4be44fcd 276 ((unsigned long)entry + entry->length);
1da177e4
LT
277 }
278
2320ac6c 279 kfree(buffer.pointer);
d550d98d 280 return 0;
1da177e4
LT
281}
282
4be44fcd 283void acpi_pci_irq_del_prt(int segment, int bus)
1da177e4 284{
3604a9f4 285 struct acpi_prt_entry *entry, *tmp;
1da177e4 286
4be44fcd 287 printk(KERN_DEBUG
21a53283
BH
288 "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n",
289 segment, bus);
1da177e4 290 spin_lock(&acpi_prt_lock);
3604a9f4
BH
291 list_for_each_entry_safe(entry, tmp, &acpi_prt_list, list) {
292 if (segment == entry->id.segment && bus == entry->id.bus) {
293 list_del(&entry->list);
294 kfree(entry);
295 }
1da177e4
LT
296 }
297 spin_unlock(&acpi_prt_lock);
298}
4be44fcd 299
1da177e4
LT
300/* --------------------------------------------------------------------------
301 PCI Interrupt Routing Support
302 -------------------------------------------------------------------------- */
3f0f3c27 303static struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin)
1da177e4 304{
beba8a64 305 struct acpi_prt_entry *entry;
5697b7ca
BH
306 struct pci_dev *bridge;
307 u8 bridge_pin, orig_pin = pin;
1da177e4 308
063563b4 309 entry = acpi_pci_irq_find_prt_entry(dev, pin);
3b1ea18d
BH
310 if (entry) {
311 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %s[%c] _PRT entry\n",
1350487e 312 pci_name(dev), pin_name(pin)));
3b1ea18d 313 return entry;
1da177e4 314 }
4be44fcd 315
1da177e4
LT
316 /*
317 * Attempt to derive an IRQ for this device from a parent bridge's
318 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
319 */
ee401363
BH
320 bridge = dev->bus->self;
321 while (bridge) {
322 pin = (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1;
1da177e4
LT
323
324 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
325 /* PC card has the same IRQ as its cardbridge */
8015a014 326 bridge_pin = bridge->pin;
1da177e4 327 if (!bridge_pin) {
4be44fcd
LB
328 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
329 "No interrupt pin configured for device %s\n",
330 pci_name(bridge)));
beba8a64 331 return NULL;
1da177e4 332 }
1da177e4
LT
333 pin = bridge_pin;
334 }
335
5697b7ca 336 entry = acpi_pci_irq_find_prt_entry(bridge, pin);
3b1ea18d
BH
337 if (entry) {
338 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
339 "Derived GSI for %s INT %c from %s\n",
340 pci_name(dev), pin_name(orig_pin),
341 pci_name(bridge)));
342 return entry;
343 }
ee401363
BH
344
345 dev = bridge;
346 bridge = dev->bus->self;
1da177e4
LT
347 }
348
3b1ea18d
BH
349 dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n",
350 pin_name(orig_pin));
351 return NULL;
1da177e4
LT
352}
353
4be44fcd 354int acpi_pci_irq_enable(struct pci_dev *dev)
1da177e4 355{
beba8a64 356 struct acpi_prt_entry *entry;
3f0f3c27
BH
357 int gsi;
358 u8 pin;
50eca3eb
BM
359 int triggering = ACPI_LEVEL_SENSITIVE;
360 int polarity = ACPI_ACTIVE_LOW;
4be44fcd 361 char *link = NULL;
c83642d5 362 char link_desc[16];
4be44fcd 363 int rc;
1da177e4 364
8015a014 365 pin = dev->pin;
1da177e4 366 if (!pin) {
4be44fcd
LB
367 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
368 "No interrupt pin configured for device %s\n",
369 pci_name(dev)));
d550d98d 370 return 0;
1da177e4 371 }
1da177e4 372
beba8a64 373 entry = acpi_pci_irq_lookup(dev, pin);
5697b7ca 374 if (!entry) {
96c2a876
AC
375 /*
376 * IDE legacy mode controller IRQs are magic. Why do compat
377 * extensions always make such a nasty mess.
378 */
379 if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
380 (dev->class & 0x05) == 0)
381 return 0;
382 }
5697b7ca 383
74f82af1
BH
384 if (entry) {
385 if (entry->link)
386 gsi = acpi_pci_link_allocate_irq(entry->link,
387 entry->index,
388 &triggering, &polarity,
389 &link);
390 else
391 gsi = entry->index;
392 } else
5697b7ca
BH
393 gsi = -1;
394
1da177e4
LT
395 /*
396 * No IRQ known to the ACPI subsystem - maybe the BIOS /
397 * driver reported one, then use it. Exit in any case.
398 */
c13f889a 399 if (gsi < 0) {
cf68b80b 400 dev_warn(&dev->dev, "PCI INT %c: no GSI", pin_name(pin));
1da177e4 401 /* Interrupt Line values above 0xF are forbidden */
44f8e1a2 402 if (dev->irq > 0 && (dev->irq <= 0xF)) {
1da177e4 403 printk(" - using IRQ %d\n", dev->irq);
4be44fcd
LB
404 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE,
405 ACPI_ACTIVE_LOW);
d550d98d 406 return 0;
4be44fcd 407 } else {
1da177e4 408 printk("\n");
d550d98d 409 return 0;
1da177e4 410 }
4be44fcd 411 }
1da177e4 412
c13f889a 413 rc = acpi_register_gsi(gsi, triggering, polarity);
349f0d56 414 if (rc < 0) {
c83642d5 415 dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n",
cf68b80b 416 pin_name(pin));
d550d98d 417 return rc;
349f0d56
KK
418 }
419 dev->irq = rc;
1da177e4 420
1da177e4 421 if (link)
c83642d5
BH
422 snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link);
423 else
424 link_desc[0] = '\0';
1da177e4 425
c83642d5 426 dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n",
cf68b80b 427 pin_name(pin), link_desc, gsi,
c83642d5
BH
428 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
429 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
1da177e4 430
d550d98d 431 return 0;
1da177e4 432}
1da177e4 433
87bec66b 434/* FIXME: implement x86/x86_64 version */
4be44fcd
LB
435void __attribute__ ((weak)) acpi_unregister_gsi(u32 i)
436{
437}
87bec66b 438
4be44fcd 439void acpi_pci_irq_disable(struct pci_dev *dev)
1da177e4 440{
beba8a64 441 struct acpi_prt_entry *entry;
3f0f3c27
BH
442 int gsi;
443 u8 pin;
1da177e4 444
8015a014 445 pin = dev->pin;
1da177e4 446 if (!pin)
d550d98d 447 return;
1da177e4 448
beba8a64 449 entry = acpi_pci_irq_lookup(dev, pin);
beba8a64 450 if (!entry)
d550d98d 451 return;
1da177e4 452
74f82af1
BH
453 if (entry->link)
454 gsi = acpi_pci_link_free_irq(entry->link);
455 else
456 gsi = entry->index;
beba8a64 457
1da177e4
LT
458 /*
459 * TBD: It might be worth clearing dev->irq by magic constant
460 * (e.g. PCI_UNDEFINED_IRQ).
461 */
462
cf68b80b 463 dev_info(&dev->dev, "PCI INT %c disabled\n", pin_name(pin));
1da177e4 464 acpi_unregister_gsi(gsi);
1da177e4 465}