Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / acpi / pci_irq.c
blob70f9361bab42d6fddd2dbef26884e8023fdaf92d
1 /*
2 * pci_irq.c - ACPI PCI Interrupt Routing ($Revision: 11 $)
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>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 <<<<<<< HEAD:drivers/acpi/pci_irq.c
29 =======
30 #include <linux/dmi.h>
31 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/pci_irq.c
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/proc_fs.h>
37 #include <linux/spinlock.h>
38 #include <linux/pm.h>
39 #include <linux/pci.h>
40 #include <linux/acpi.h>
41 #include <acpi/acpi_bus.h>
42 #include <acpi/acpi_drivers.h>
44 #define _COMPONENT ACPI_PCI_COMPONENT
45 ACPI_MODULE_NAME("pci_irq");
47 static struct acpi_prt_list acpi_prt;
48 static DEFINE_SPINLOCK(acpi_prt_lock);
50 /* --------------------------------------------------------------------------
51 PCI IRQ Routing Table (PRT) Support
52 -------------------------------------------------------------------------- */
54 static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(int segment,
55 int bus,
56 int device, int pin)
58 struct acpi_prt_entry *entry = NULL;
60 if (!acpi_prt.count)
61 return NULL;
64 * Parse through all PRT entries looking for a match on the specified
65 * PCI device's segment, bus, device, and pin (don't care about func).
68 spin_lock(&acpi_prt_lock);
69 list_for_each_entry(entry, &acpi_prt.entries, node) {
70 if ((segment == entry->id.segment)
71 && (bus == entry->id.bus)
72 && (device == entry->id.device)
73 && (pin == entry->pin)) {
74 spin_unlock(&acpi_prt_lock);
75 return entry;
79 spin_unlock(&acpi_prt_lock);
80 return NULL;
83 <<<<<<< HEAD:drivers/acpi/pci_irq.c
84 =======
85 /* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
86 static struct dmi_system_id medion_md9580[] = {
88 .ident = "Medion MD9580-F laptop",
89 .matches = {
90 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
91 DMI_MATCH(DMI_PRODUCT_NAME, "A555"),
94 { }
97 /* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
98 static struct dmi_system_id dell_optiplex[] = {
100 .ident = "Dell Optiplex GX1",
101 .matches = {
102 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
103 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX1 600S+"),
109 /* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */
110 static struct dmi_system_id hp_t5710[] = {
112 .ident = "HP t5710",
113 .matches = {
114 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
115 DMI_MATCH(DMI_PRODUCT_NAME, "hp t5000 series"),
116 DMI_MATCH(DMI_BOARD_NAME, "098Ch"),
122 struct prt_quirk {
123 struct dmi_system_id *system;
124 unsigned int segment;
125 unsigned int bus;
126 unsigned int device;
127 unsigned char pin;
128 char *source; /* according to BIOS */
129 char *actual_source;
133 * These systems have incorrect _PRT entries. The BIOS claims the PCI
134 * interrupt at the listed segment/bus/device/pin is connected to the first
135 * link device, but it is actually connected to the second.
137 static struct prt_quirk prt_quirks[] = {
138 { medion_md9580, 0, 0, 9, 'A',
139 "\\_SB_.PCI0.ISA.LNKA",
140 "\\_SB_.PCI0.ISA.LNKB"},
141 { dell_optiplex, 0, 0, 0xd, 'A',
142 "\\_SB_.LNKB",
143 "\\_SB_.LNKA"},
144 { hp_t5710, 0, 0, 1, 'A',
145 "\\_SB_.PCI0.LNK1",
146 "\\_SB_.PCI0.LNK3"},
149 static void
150 do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt)
152 int i;
153 struct prt_quirk *quirk;
155 for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) {
156 quirk = &prt_quirks[i];
158 /* All current quirks involve link devices, not GSIs */
159 if (!prt->source)
160 continue;
162 if (dmi_check_system(quirk->system) &&
163 entry->id.segment == quirk->segment &&
164 entry->id.bus == quirk->bus &&
165 entry->id.device == quirk->device &&
166 entry->pin + 'A' == quirk->pin &&
167 !strcmp(prt->source, quirk->source) &&
168 strlen(prt->source) >= strlen(quirk->actual_source)) {
169 printk(KERN_WARNING PREFIX "firmware reports "
170 "%04x:%02x:%02x[%c] connected to %s; "
171 "changing to %s\n",
172 entry->id.segment, entry->id.bus,
173 entry->id.device, 'A' + entry->pin,
174 prt->source, quirk->actual_source);
175 strcpy(prt->source, quirk->actual_source);
180 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/pci_irq.c
181 static int
182 acpi_pci_irq_add_entry(acpi_handle handle,
183 int segment, int bus, struct acpi_pci_routing_table *prt)
185 struct acpi_prt_entry *entry = NULL;
188 if (!prt)
189 return -EINVAL;
191 entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
192 if (!entry)
193 return -ENOMEM;
195 entry->id.segment = segment;
196 entry->id.bus = bus;
197 entry->id.device = (prt->address >> 16) & 0xFFFF;
198 entry->id.function = prt->address & 0xFFFF;
199 entry->pin = prt->pin;
201 <<<<<<< HEAD:drivers/acpi/pci_irq.c
202 =======
203 do_prt_fixups(entry, prt);
205 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/pci_irq.c
207 * Type 1: Dynamic
208 * ---------------
209 * The 'source' field specifies the PCI interrupt link device used to
210 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
211 * indicates which resource descriptor in the resource template (of
212 * the link device) this interrupt is allocated from.
214 * NOTE: Don't query the Link Device for IRQ information at this time
215 * because Link Device enumeration may not have occurred yet
216 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
217 * namespace).
219 if (prt->source[0]) {
220 acpi_get_handle(handle, prt->source, &entry->link.handle);
221 entry->link.index = prt->source_index;
224 * Type 2: Static
225 * --------------
226 * The 'source' field is NULL, and the 'source_index' field specifies
227 * the IRQ value, which is hardwired to specific interrupt inputs on
228 * the interrupt controller.
230 else
231 entry->link.index = prt->source_index;
233 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
234 " %02X:%02X:%02X[%c] -> %s[%d]\n",
235 entry->id.segment, entry->id.bus,
236 entry->id.device, ('A' + entry->pin), prt->source,
237 entry->link.index));
239 spin_lock(&acpi_prt_lock);
240 list_add_tail(&entry->node, &acpi_prt.entries);
241 acpi_prt.count++;
242 spin_unlock(&acpi_prt_lock);
244 return 0;
247 static void
248 acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry)
250 if (segment == entry->id.segment && bus == entry->id.bus) {
251 acpi_prt.count--;
252 list_del(&entry->node);
253 kfree(entry);
257 int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
259 acpi_status status = AE_OK;
260 char *pathname = NULL;
261 struct acpi_buffer buffer = { 0, NULL };
262 struct acpi_pci_routing_table *prt = NULL;
263 struct acpi_pci_routing_table *entry = NULL;
264 static int first_time = 1;
267 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
268 if (!pathname)
269 return -ENOMEM;
271 if (first_time) {
272 acpi_prt.count = 0;
273 INIT_LIST_HEAD(&acpi_prt.entries);
274 first_time = 0;
278 * NOTE: We're given a 'handle' to the _PRT object's parent device
279 * (either a PCI root bridge or PCI-PCI bridge).
282 buffer.length = ACPI_PATHNAME_MAX;
283 buffer.pointer = pathname;
284 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
286 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
287 pathname);
290 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
293 buffer.length = 0;
294 buffer.pointer = NULL;
295 kfree(pathname);
296 status = acpi_get_irq_routing_table(handle, &buffer);
297 if (status != AE_BUFFER_OVERFLOW) {
298 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
299 acpi_format_exception(status)));
300 return -ENODEV;
303 prt = kzalloc(buffer.length, GFP_KERNEL);
304 if (!prt) {
305 return -ENOMEM;
307 buffer.pointer = prt;
309 status = acpi_get_irq_routing_table(handle, &buffer);
310 if (ACPI_FAILURE(status)) {
311 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
312 acpi_format_exception(status)));
313 kfree(buffer.pointer);
314 return -ENODEV;
317 entry = prt;
319 while (entry && (entry->length > 0)) {
320 acpi_pci_irq_add_entry(handle, segment, bus, entry);
321 entry = (struct acpi_pci_routing_table *)
322 ((unsigned long)entry + entry->length);
325 kfree(prt);
327 return 0;
330 void acpi_pci_irq_del_prt(int segment, int bus)
332 struct list_head *node = NULL, *n = NULL;
333 struct acpi_prt_entry *entry = NULL;
335 if (!acpi_prt.count) {
336 return;
339 printk(KERN_DEBUG
340 "ACPI: Delete PCI Interrupt Routing Table for %x:%x\n", segment,
341 bus);
342 spin_lock(&acpi_prt_lock);
343 list_for_each_safe(node, n, &acpi_prt.entries) {
344 entry = list_entry(node, struct acpi_prt_entry, node);
346 acpi_pci_irq_del_entry(segment, bus, entry);
348 spin_unlock(&acpi_prt_lock);
351 /* --------------------------------------------------------------------------
352 PCI Interrupt Routing Support
353 -------------------------------------------------------------------------- */
354 typedef int (*irq_lookup_func) (struct acpi_prt_entry *, int *, int *, char **);
356 static int
357 acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
358 int *triggering, int *polarity, char **link)
360 int irq;
363 if (entry->link.handle) {
364 irq = acpi_pci_link_allocate_irq(entry->link.handle,
365 entry->link.index, triggering,
366 polarity, link);
367 if (irq < 0) {
368 printk(KERN_WARNING PREFIX
369 "Invalid IRQ link routing entry\n");
370 return -1;
372 } else {
373 irq = entry->link.index;
374 *triggering = ACPI_LEVEL_SENSITIVE;
375 *polarity = ACPI_ACTIVE_LOW;
378 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq));
379 return irq;
382 static int
383 acpi_pci_free_irq(struct acpi_prt_entry *entry,
384 int *triggering, int *polarity, char **link)
386 int irq;
388 if (entry->link.handle) {
389 irq = acpi_pci_link_free_irq(entry->link.handle);
390 } else {
391 irq = entry->link.index;
393 return irq;
397 * acpi_pci_irq_lookup
398 * success: return IRQ >= 0
399 * failure: return -1
401 static int
402 acpi_pci_irq_lookup(struct pci_bus *bus,
403 int device,
404 int pin,
405 int *triggering,
406 int *polarity, char **link, irq_lookup_func func)
408 struct acpi_prt_entry *entry = NULL;
409 int segment = pci_domain_nr(bus);
410 int bus_nr = bus->number;
411 int ret;
414 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
415 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
416 segment, bus_nr, device, ('A' + pin)));
418 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin);
419 if (!entry) {
420 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n"));
421 return -1;
424 ret = func(entry, triggering, polarity, link);
425 return ret;
429 * acpi_pci_irq_derive
430 * success: return IRQ >= 0
431 * failure: return < 0
433 static int
434 acpi_pci_irq_derive(struct pci_dev *dev,
435 int pin,
436 int *triggering,
437 int *polarity, char **link, irq_lookup_func func)
439 struct pci_dev *bridge = dev;
440 int irq = -1;
441 u8 bridge_pin = 0;
444 if (!dev)
445 return -EINVAL;
448 * Attempt to derive an IRQ for this device from a parent bridge's
449 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
451 while (irq < 0 && bridge->bus->self) {
452 pin = (pin + PCI_SLOT(bridge->devfn)) % 4;
453 bridge = bridge->bus->self;
455 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
456 /* PC card has the same IRQ as its cardbridge */
457 bridge_pin = bridge->pin;
458 if (!bridge_pin) {
459 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
460 "No interrupt pin configured for device %s\n",
461 pci_name(bridge)));
462 return -1;
464 /* Pin is from 0 to 3 */
465 bridge_pin--;
466 pin = bridge_pin;
469 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn),
470 pin, triggering, polarity,
471 link, func);
474 if (irq < 0) {
475 printk(KERN_WARNING PREFIX "Unable to derive IRQ for device %s\n",
476 pci_name(dev));
477 return -1;
480 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n",
481 irq, pci_name(dev), pci_name(bridge)));
483 return irq;
487 * acpi_pci_irq_enable
488 * success: return 0
489 * failure: return < 0
492 int acpi_pci_irq_enable(struct pci_dev *dev)
494 int irq = 0;
495 u8 pin = 0;
496 int triggering = ACPI_LEVEL_SENSITIVE;
497 int polarity = ACPI_ACTIVE_LOW;
498 char *link = NULL;
499 int rc;
502 if (!dev)
503 return -EINVAL;
505 pin = dev->pin;
506 if (!pin) {
507 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
508 "No interrupt pin configured for device %s\n",
509 pci_name(dev)));
510 return 0;
512 pin--;
514 if (!dev->bus) {
515 printk(KERN_ERR PREFIX "Invalid (NULL) 'bus' field\n");
516 return -ENODEV;
520 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
521 * values override any BIOS-assigned IRQs set during boot.
523 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
524 &triggering, &polarity, &link,
525 acpi_pci_allocate_irq);
528 * If no PRT entry was found, we'll try to derive an IRQ from the
529 * device's parent bridge.
531 if (irq < 0)
532 irq = acpi_pci_irq_derive(dev, pin, &triggering,
533 &polarity, &link,
534 acpi_pci_allocate_irq);
536 if (irq < 0) {
538 * IDE legacy mode controller IRQs are magic. Why do compat
539 * extensions always make such a nasty mess.
541 if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
542 (dev->class & 0x05) == 0)
543 return 0;
546 * No IRQ known to the ACPI subsystem - maybe the BIOS /
547 * driver reported one, then use it. Exit in any case.
549 if (irq < 0) {
550 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI",
551 pci_name(dev), ('A' + pin));
552 /* Interrupt Line values above 0xF are forbidden */
553 if (dev->irq > 0 && (dev->irq <= 0xF)) {
554 printk(" - using IRQ %d\n", dev->irq);
555 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE,
556 ACPI_ACTIVE_LOW);
557 return 0;
558 } else {
559 printk("\n");
560 return 0;
564 rc = acpi_register_gsi(irq, triggering, polarity);
565 if (rc < 0) {
566 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: failed "
567 "to register GSI\n", pci_name(dev), ('A' + pin));
568 return rc;
570 dev->irq = rc;
572 printk(KERN_INFO PREFIX "PCI Interrupt %s[%c] -> ",
573 pci_name(dev), 'A' + pin);
575 if (link)
576 printk("Link [%s] -> ", link);
578 printk("GSI %u (%s, %s) -> IRQ %d\n", irq,
579 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
580 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
582 return 0;
585 /* FIXME: implement x86/x86_64 version */
586 void __attribute__ ((weak)) acpi_unregister_gsi(u32 i)
590 void acpi_pci_irq_disable(struct pci_dev *dev)
592 int gsi = 0;
593 u8 pin = 0;
594 int triggering = ACPI_LEVEL_SENSITIVE;
595 int polarity = ACPI_ACTIVE_LOW;
598 if (!dev || !dev->bus)
599 return;
601 pin = dev->pin;
602 if (!pin)
603 return;
604 pin--;
607 * First we check the PCI IRQ routing table (PRT) for an IRQ.
609 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
610 &triggering, &polarity, NULL,
611 acpi_pci_free_irq);
613 * If no PRT entry was found, we'll try to derive an IRQ from the
614 * device's parent bridge.
616 if (gsi < 0)
617 gsi = acpi_pci_irq_derive(dev, pin,
618 &triggering, &polarity, NULL,
619 acpi_pci_free_irq);
620 if (gsi < 0)
621 return;
624 * TBD: It might be worth clearing dev->irq by magic constant
625 * (e.g. PCI_UNDEFINED_IRQ).
628 printk(KERN_INFO PREFIX "PCI interrupt for device %s disabled\n",
629 pci_name(dev));
631 acpi_unregister_gsi(gsi);
633 return;