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 #include <linux/dmi.h>
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/types.h>
33 #include <linux/proc_fs.h>
34 #include <linux/spinlock.h>
36 #include <linux/pci.h>
37 #include <linux/acpi.h>
38 #include <acpi/acpi_bus.h>
39 #include <acpi/acpi_drivers.h>
41 #define _COMPONENT ACPI_PCI_COMPONENT
42 ACPI_MODULE_NAME("pci_irq");
44 struct acpi_prt_entry {
45 struct list_head node;
46 struct acpi_pci_id id;
55 struct acpi_prt_list {
57 struct list_head entries;
60 static struct acpi_prt_list acpi_prt;
61 static DEFINE_SPINLOCK(acpi_prt_lock);
63 static inline char pin_name(int pin)
68 /* --------------------------------------------------------------------------
69 PCI IRQ Routing Table (PRT) Support
70 -------------------------------------------------------------------------- */
72 static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(struct pci_dev *dev,
75 struct acpi_prt_entry *entry = NULL;
76 int segment = pci_domain_nr(dev->bus);
77 int bus = dev->bus->number;
78 int device = PCI_SLOT(dev->devfn);
84 * Parse through all PRT entries looking for a match on the specified
85 * PCI device's segment, bus, device, and pin (don't care about func).
88 spin_lock(&acpi_prt_lock);
89 list_for_each_entry(entry, &acpi_prt.entries, node) {
90 if ((segment == entry->id.segment)
91 && (bus == entry->id.bus)
92 && (device == entry->id.device)
93 && (pin == entry->pin)) {
94 spin_unlock(&acpi_prt_lock);
99 spin_unlock(&acpi_prt_lock);
103 /* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
104 static struct dmi_system_id medion_md9580[] = {
106 .ident = "Medion MD9580-F laptop",
108 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
109 DMI_MATCH(DMI_PRODUCT_NAME, "A555"),
115 /* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
116 static struct dmi_system_id dell_optiplex[] = {
118 .ident = "Dell Optiplex GX1",
120 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
121 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX1 600S+"),
127 /* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */
128 static struct dmi_system_id hp_t5710[] = {
132 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
133 DMI_MATCH(DMI_PRODUCT_NAME, "hp t5000 series"),
134 DMI_MATCH(DMI_BOARD_NAME, "098Ch"),
141 struct dmi_system_id *system;
142 unsigned int segment;
146 char *source; /* according to BIOS */
150 #define PCI_INTX_PIN(c) (c - 'A' + 1)
153 * These systems have incorrect _PRT entries. The BIOS claims the PCI
154 * interrupt at the listed segment/bus/device/pin is connected to the first
155 * link device, but it is actually connected to the second.
157 static struct prt_quirk prt_quirks[] = {
158 { medion_md9580, 0, 0, 9, PCI_INTX_PIN('A'),
159 "\\_SB_.PCI0.ISA_.LNKA",
160 "\\_SB_.PCI0.ISA_.LNKB"},
161 { dell_optiplex, 0, 0, 0xd, PCI_INTX_PIN('A'),
164 { hp_t5710, 0, 0, 1, PCI_INTX_PIN('A'),
170 do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt)
173 struct prt_quirk *quirk;
175 for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) {
176 quirk = &prt_quirks[i];
178 /* All current quirks involve link devices, not GSIs */
182 if (dmi_check_system(quirk->system) &&
183 entry->id.segment == quirk->segment &&
184 entry->id.bus == quirk->bus &&
185 entry->id.device == quirk->device &&
186 entry->pin == quirk->pin &&
187 !strcmp(prt->source, quirk->source) &&
188 strlen(prt->source) >= strlen(quirk->actual_source)) {
189 printk(KERN_WARNING PREFIX "firmware reports "
190 "%04x:%02x:%02x PCI INT %c connected to %s; "
192 entry->id.segment, entry->id.bus,
193 entry->id.device, pin_name(entry->pin),
194 prt->source, quirk->actual_source);
195 strcpy(prt->source, quirk->actual_source);
201 acpi_pci_irq_add_entry(acpi_handle handle,
202 int segment, int bus, struct acpi_pci_routing_table *prt)
204 struct acpi_prt_entry *entry = NULL;
206 entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
211 * Note that the _PRT uses 0=INTA, 1=INTB, etc, while PCI uses
212 * 1=INTA, 2=INTB. We use the PCI encoding throughout, so convert
215 entry->id.segment = segment;
217 entry->id.device = (prt->address >> 16) & 0xFFFF;
218 entry->pin = prt->pin + 1;
220 do_prt_fixups(entry, prt);
225 * The 'source' field specifies the PCI interrupt link device used to
226 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
227 * indicates which resource descriptor in the resource template (of
228 * the link device) this interrupt is allocated from.
230 * NOTE: Don't query the Link Device for IRQ information at this time
231 * because Link Device enumeration may not have occurred yet
232 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
235 if (prt->source[0]) {
236 acpi_get_handle(handle, prt->source, &entry->link.handle);
237 entry->link.index = prt->source_index;
242 * The 'source' field is NULL, and the 'source_index' field specifies
243 * the IRQ value, which is hardwired to specific interrupt inputs on
244 * the interrupt controller.
247 entry->link.index = prt->source_index;
249 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
250 " %04x:%02x:%02x[%c] -> %s[%d]\n",
251 entry->id.segment, entry->id.bus,
252 entry->id.device, pin_name(entry->pin),
253 prt->source, entry->link.index));
255 spin_lock(&acpi_prt_lock);
256 list_add_tail(&entry->node, &acpi_prt.entries);
258 spin_unlock(&acpi_prt_lock);
264 acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry)
266 if (segment == entry->id.segment && bus == entry->id.bus) {
268 list_del(&entry->node);
273 int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
276 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
277 struct acpi_pci_routing_table *entry;
278 static int first_time = 1;
282 INIT_LIST_HEAD(&acpi_prt.entries);
286 /* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */
287 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
288 if (ACPI_FAILURE(status))
291 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
292 (char *) buffer.pointer);
294 kfree(buffer.pointer);
296 buffer.length = ACPI_ALLOCATE_BUFFER;
297 buffer.pointer = NULL;
299 status = acpi_get_irq_routing_table(handle, &buffer);
300 if (ACPI_FAILURE(status)) {
301 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
302 acpi_format_exception(status)));
303 kfree(buffer.pointer);
307 entry = buffer.pointer;
308 while (entry && (entry->length > 0)) {
309 acpi_pci_irq_add_entry(handle, segment, bus, entry);
310 entry = (struct acpi_pci_routing_table *)
311 ((unsigned long)entry + entry->length);
314 kfree(buffer.pointer);
318 void acpi_pci_irq_del_prt(int segment, int bus)
320 struct list_head *node = NULL, *n = NULL;
321 struct acpi_prt_entry *entry = NULL;
323 if (!acpi_prt.count) {
328 "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n",
330 spin_lock(&acpi_prt_lock);
331 list_for_each_safe(node, n, &acpi_prt.entries) {
332 entry = list_entry(node, struct acpi_prt_entry, node);
334 acpi_pci_irq_del_entry(segment, bus, entry);
336 spin_unlock(&acpi_prt_lock);
339 /* --------------------------------------------------------------------------
340 PCI Interrupt Routing Support
341 -------------------------------------------------------------------------- */
342 typedef int (*irq_lookup_func) (struct acpi_prt_entry *, int *, int *, char **);
345 acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
346 int *triggering, int *polarity, char **link)
351 if (entry->link.handle) {
352 irq = acpi_pci_link_allocate_irq(entry->link.handle,
353 entry->link.index, triggering,
356 printk(KERN_WARNING PREFIX
357 "Invalid IRQ link routing entry\n");
361 irq = entry->link.index;
362 *triggering = ACPI_LEVEL_SENSITIVE;
363 *polarity = ACPI_ACTIVE_LOW;
366 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found GSI %d\n", irq));
371 acpi_pci_free_irq(struct acpi_prt_entry *entry,
372 int *triggering, int *polarity, char **link)
376 if (entry->link.handle) {
377 irq = acpi_pci_link_free_irq(entry->link.handle);
379 irq = entry->link.index;
385 * acpi_pci_irq_lookup
386 * success: return IRQ >= 0
390 acpi_pci_irq_lookup(struct pci_dev *dev, int pin,
392 int *polarity, char **link, irq_lookup_func func)
394 struct acpi_prt_entry *entry = NULL;
398 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Searching for _PRT entry for %s[%c]\n",
399 pci_name(dev), pin_name(pin)));
401 entry = acpi_pci_irq_find_prt_entry(dev, pin);
403 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_PRT entry not found\n"));
407 ret = func(entry, triggering, polarity, link);
412 * acpi_pci_irq_derive
413 * success: return IRQ >= 0
414 * failure: return < 0
417 acpi_pci_irq_derive(struct pci_dev *dev,
420 int *polarity, char **link, irq_lookup_func func)
422 struct pci_dev *bridge = dev;
424 u8 bridge_pin = 0, orig_pin = pin;
428 * Attempt to derive an IRQ for this device from a parent bridge's
429 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
431 while (irq < 0 && bridge->bus->self) {
432 pin = (((pin - 1) + PCI_SLOT(bridge->devfn)) % 4) + 1;
433 bridge = bridge->bus->self;
435 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
436 /* PC card has the same IRQ as its cardbridge */
437 bridge_pin = bridge->pin;
439 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
440 "No interrupt pin configured for device %s\n",
447 irq = acpi_pci_irq_lookup(bridge,
448 pin, triggering, polarity,
453 dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n",
458 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive GSI %d for device %s from %s\n",
459 irq, pci_name(dev), pci_name(bridge)));
465 * acpi_pci_irq_enable
467 * failure: return < 0
470 int acpi_pci_irq_enable(struct pci_dev *dev)
474 int triggering = ACPI_LEVEL_SENSITIVE;
475 int polarity = ACPI_ACTIVE_LOW;
483 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
484 "No interrupt pin configured for device %s\n",
490 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
491 * values override any BIOS-assigned IRQs set during boot.
493 gsi = acpi_pci_irq_lookup(dev, pin,
494 &triggering, &polarity, &link,
495 acpi_pci_allocate_irq);
498 * If no PRT entry was found, we'll try to derive an IRQ from the
499 * device's parent bridge.
502 gsi = acpi_pci_irq_derive(dev, pin, &triggering,
504 acpi_pci_allocate_irq);
508 * IDE legacy mode controller IRQs are magic. Why do compat
509 * extensions always make such a nasty mess.
511 if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
512 (dev->class & 0x05) == 0)
516 * No IRQ known to the ACPI subsystem - maybe the BIOS /
517 * driver reported one, then use it. Exit in any case.
520 dev_warn(&dev->dev, "PCI INT %c: no GSI", pin_name(pin));
521 /* Interrupt Line values above 0xF are forbidden */
522 if (dev->irq > 0 && (dev->irq <= 0xF)) {
523 printk(" - using IRQ %d\n", dev->irq);
524 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE,
533 rc = acpi_register_gsi(gsi, triggering, polarity);
535 dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n",
542 snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link);
546 dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n",
547 pin_name(pin), link_desc, gsi,
548 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
549 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
554 /* FIXME: implement x86/x86_64 version */
555 void __attribute__ ((weak)) acpi_unregister_gsi(u32 i)
559 void acpi_pci_irq_disable(struct pci_dev *dev)
563 int triggering = ACPI_LEVEL_SENSITIVE;
564 int polarity = ACPI_ACTIVE_LOW;
572 * First we check the PCI IRQ routing table (PRT) for an IRQ.
574 gsi = acpi_pci_irq_lookup(dev, pin,
575 &triggering, &polarity, NULL,
578 * If no PRT entry was found, we'll try to derive an IRQ from the
579 * device's parent bridge.
582 gsi = acpi_pci_irq_derive(dev, pin,
583 &triggering, &polarity, NULL,
589 * TBD: It might be worth clearing dev->irq by magic constant
590 * (e.g. PCI_UNDEFINED_IRQ).
593 dev_info(&dev->dev, "PCI INT %c disabled\n", pin_name(pin));
594 acpi_unregister_gsi(gsi);