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(int segment
,
76 struct acpi_prt_entry
*entry
= NULL
;
82 * Parse through all PRT entries looking for a match on the specified
83 * PCI device's segment, bus, device, and pin (don't care about func).
86 spin_lock(&acpi_prt_lock
);
87 list_for_each_entry(entry
, &acpi_prt
.entries
, node
) {
88 if ((segment
== entry
->id
.segment
)
89 && (bus
== entry
->id
.bus
)
90 && (device
== entry
->id
.device
)
91 && (pin
== entry
->pin
)) {
92 spin_unlock(&acpi_prt_lock
);
97 spin_unlock(&acpi_prt_lock
);
101 /* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
102 static struct dmi_system_id medion_md9580
[] = {
104 .ident
= "Medion MD9580-F laptop",
106 DMI_MATCH(DMI_SYS_VENDOR
, "MEDIONNB"),
107 DMI_MATCH(DMI_PRODUCT_NAME
, "A555"),
113 /* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
114 static struct dmi_system_id dell_optiplex
[] = {
116 .ident
= "Dell Optiplex GX1",
118 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
119 DMI_MATCH(DMI_PRODUCT_NAME
, "OptiPlex GX1 600S+"),
125 /* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */
126 static struct dmi_system_id hp_t5710
[] = {
130 DMI_MATCH(DMI_SYS_VENDOR
, "Hewlett-Packard"),
131 DMI_MATCH(DMI_PRODUCT_NAME
, "hp t5000 series"),
132 DMI_MATCH(DMI_BOARD_NAME
, "098Ch"),
139 struct dmi_system_id
*system
;
140 unsigned int segment
;
144 char *source
; /* according to BIOS */
149 * These systems have incorrect _PRT entries. The BIOS claims the PCI
150 * interrupt at the listed segment/bus/device/pin is connected to the first
151 * link device, but it is actually connected to the second.
153 static struct prt_quirk prt_quirks
[] = {
154 { medion_md9580
, 0, 0, 9, 'A',
155 "\\_SB_.PCI0.ISA_.LNKA",
156 "\\_SB_.PCI0.ISA_.LNKB"},
157 { dell_optiplex
, 0, 0, 0xd, 'A',
160 { hp_t5710
, 0, 0, 1, 'A',
166 do_prt_fixups(struct acpi_prt_entry
*entry
, struct acpi_pci_routing_table
*prt
)
169 struct prt_quirk
*quirk
;
171 for (i
= 0; i
< ARRAY_SIZE(prt_quirks
); i
++) {
172 quirk
= &prt_quirks
[i
];
174 /* All current quirks involve link devices, not GSIs */
178 if (dmi_check_system(quirk
->system
) &&
179 entry
->id
.segment
== quirk
->segment
&&
180 entry
->id
.bus
== quirk
->bus
&&
181 entry
->id
.device
== quirk
->device
&&
182 pin_name(entry
->pin
) == quirk
->pin
&&
183 !strcmp(prt
->source
, quirk
->source
) &&
184 strlen(prt
->source
) >= strlen(quirk
->actual_source
)) {
185 printk(KERN_WARNING PREFIX
"firmware reports "
186 "%04x:%02x:%02x PCI INT %c connected to %s; "
188 entry
->id
.segment
, entry
->id
.bus
,
189 entry
->id
.device
, pin_name(entry
->pin
),
190 prt
->source
, quirk
->actual_source
);
191 strcpy(prt
->source
, quirk
->actual_source
);
197 acpi_pci_irq_add_entry(acpi_handle handle
,
198 int segment
, int bus
, struct acpi_pci_routing_table
*prt
)
200 struct acpi_prt_entry
*entry
= NULL
;
202 entry
= kzalloc(sizeof(struct acpi_prt_entry
), GFP_KERNEL
);
206 entry
->id
.segment
= segment
;
208 entry
->id
.device
= (prt
->address
>> 16) & 0xFFFF;
209 entry
->pin
= prt
->pin
;
211 do_prt_fixups(entry
, prt
);
216 * The 'source' field specifies the PCI interrupt link device used to
217 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
218 * indicates which resource descriptor in the resource template (of
219 * the link device) this interrupt is allocated from.
221 * NOTE: Don't query the Link Device for IRQ information at this time
222 * because Link Device enumeration may not have occurred yet
223 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
226 if (prt
->source
[0]) {
227 acpi_get_handle(handle
, prt
->source
, &entry
->link
.handle
);
228 entry
->link
.index
= prt
->source_index
;
233 * The 'source' field is NULL, and the 'source_index' field specifies
234 * the IRQ value, which is hardwired to specific interrupt inputs on
235 * the interrupt controller.
238 entry
->link
.index
= prt
->source_index
;
240 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO
,
241 " %04x:%02x:%02x[%c] -> %s[%d]\n",
242 entry
->id
.segment
, entry
->id
.bus
,
243 entry
->id
.device
, pin_name(entry
->pin
),
244 prt
->source
, entry
->link
.index
));
246 spin_lock(&acpi_prt_lock
);
247 list_add_tail(&entry
->node
, &acpi_prt
.entries
);
249 spin_unlock(&acpi_prt_lock
);
255 acpi_pci_irq_del_entry(int segment
, int bus
, struct acpi_prt_entry
*entry
)
257 if (segment
== entry
->id
.segment
&& bus
== entry
->id
.bus
) {
259 list_del(&entry
->node
);
264 int acpi_pci_irq_add_prt(acpi_handle handle
, int segment
, int bus
)
267 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
268 struct acpi_pci_routing_table
*entry
;
269 static int first_time
= 1;
273 INIT_LIST_HEAD(&acpi_prt
.entries
);
277 /* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */
278 status
= acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
279 if (ACPI_FAILURE(status
))
282 printk(KERN_DEBUG
"ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
283 (char *) buffer
.pointer
);
285 kfree(buffer
.pointer
);
287 buffer
.length
= ACPI_ALLOCATE_BUFFER
;
288 buffer
.pointer
= NULL
;
290 status
= acpi_get_irq_routing_table(handle
, &buffer
);
291 if (ACPI_FAILURE(status
)) {
292 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _PRT [%s]",
293 acpi_format_exception(status
)));
294 kfree(buffer
.pointer
);
298 entry
= buffer
.pointer
;
299 while (entry
&& (entry
->length
> 0)) {
300 acpi_pci_irq_add_entry(handle
, segment
, bus
, entry
);
301 entry
= (struct acpi_pci_routing_table
*)
302 ((unsigned long)entry
+ entry
->length
);
305 kfree(buffer
.pointer
);
309 void acpi_pci_irq_del_prt(int segment
, int bus
)
311 struct list_head
*node
= NULL
, *n
= NULL
;
312 struct acpi_prt_entry
*entry
= NULL
;
314 if (!acpi_prt
.count
) {
319 "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n",
321 spin_lock(&acpi_prt_lock
);
322 list_for_each_safe(node
, n
, &acpi_prt
.entries
) {
323 entry
= list_entry(node
, struct acpi_prt_entry
, node
);
325 acpi_pci_irq_del_entry(segment
, bus
, entry
);
327 spin_unlock(&acpi_prt_lock
);
330 /* --------------------------------------------------------------------------
331 PCI Interrupt Routing Support
332 -------------------------------------------------------------------------- */
333 typedef int (*irq_lookup_func
) (struct acpi_prt_entry
*, int *, int *, char **);
336 acpi_pci_allocate_irq(struct acpi_prt_entry
*entry
,
337 int *triggering
, int *polarity
, char **link
)
342 if (entry
->link
.handle
) {
343 irq
= acpi_pci_link_allocate_irq(entry
->link
.handle
,
344 entry
->link
.index
, triggering
,
347 printk(KERN_WARNING PREFIX
348 "Invalid IRQ link routing entry\n");
352 irq
= entry
->link
.index
;
353 *triggering
= ACPI_LEVEL_SENSITIVE
;
354 *polarity
= ACPI_ACTIVE_LOW
;
357 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found GSI %d\n", irq
));
362 acpi_pci_free_irq(struct acpi_prt_entry
*entry
,
363 int *triggering
, int *polarity
, char **link
)
367 if (entry
->link
.handle
) {
368 irq
= acpi_pci_link_free_irq(entry
->link
.handle
);
370 irq
= entry
->link
.index
;
376 * acpi_pci_irq_lookup
377 * success: return IRQ >= 0
381 acpi_pci_irq_lookup(struct pci_bus
*bus
,
385 int *polarity
, char **link
, irq_lookup_func func
)
387 struct acpi_prt_entry
*entry
= NULL
;
388 int segment
= pci_domain_nr(bus
);
389 int bus_nr
= bus
->number
;
393 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
394 "Searching for _PRT entry for %04x:%02x:%02x[%c]\n",
395 segment
, bus_nr
, device
, pin_name(pin
)));
397 entry
= acpi_pci_irq_find_prt_entry(segment
, bus_nr
, device
, pin
);
399 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "_PRT entry not found\n"));
403 ret
= func(entry
, triggering
, polarity
, link
);
408 * acpi_pci_irq_derive
409 * success: return IRQ >= 0
410 * failure: return < 0
413 acpi_pci_irq_derive(struct pci_dev
*dev
,
416 int *polarity
, char **link
, irq_lookup_func func
)
418 struct pci_dev
*bridge
= dev
;
420 u8 bridge_pin
= 0, orig_pin
= pin
;
424 * Attempt to derive an IRQ for this device from a parent bridge's
425 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
427 while (irq
< 0 && bridge
->bus
->self
) {
428 pin
= (pin
+ PCI_SLOT(bridge
->devfn
)) % 4;
429 bridge
= bridge
->bus
->self
;
431 if ((bridge
->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS
) {
432 /* PC card has the same IRQ as its cardbridge */
433 bridge_pin
= bridge
->pin
;
435 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
436 "No interrupt pin configured for device %s\n",
440 /* Pin is from 0 to 3 */
445 irq
= acpi_pci_irq_lookup(bridge
->bus
, PCI_SLOT(bridge
->devfn
),
446 pin
, triggering
, polarity
,
451 dev_warn(&dev
->dev
, "can't derive routing for PCI INT %c\n",
456 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Derive GSI %d for device %s from %s\n",
457 irq
, pci_name(dev
), pci_name(bridge
)));
463 * acpi_pci_irq_enable
465 * failure: return < 0
468 int acpi_pci_irq_enable(struct pci_dev
*dev
)
472 int triggering
= ACPI_LEVEL_SENSITIVE
;
473 int polarity
= ACPI_ACTIVE_LOW
;
481 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
482 "No interrupt pin configured for device %s\n",
489 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
490 * values override any BIOS-assigned IRQs set during boot.
492 gsi
= acpi_pci_irq_lookup(dev
->bus
, PCI_SLOT(dev
->devfn
), pin
,
493 &triggering
, &polarity
, &link
,
494 acpi_pci_allocate_irq
);
497 * If no PRT entry was found, we'll try to derive an IRQ from the
498 * device's parent bridge.
501 gsi
= acpi_pci_irq_derive(dev
, pin
, &triggering
,
503 acpi_pci_allocate_irq
);
507 * IDE legacy mode controller IRQs are magic. Why do compat
508 * extensions always make such a nasty mess.
510 if (dev
->class >> 8 == PCI_CLASS_STORAGE_IDE
&&
511 (dev
->class & 0x05) == 0)
515 * No IRQ known to the ACPI subsystem - maybe the BIOS /
516 * driver reported one, then use it. Exit in any case.
519 dev_warn(&dev
->dev
, "PCI INT %c: no GSI", pin_name(pin
));
520 /* Interrupt Line values above 0xF are forbidden */
521 if (dev
->irq
> 0 && (dev
->irq
<= 0xF)) {
522 printk(" - using IRQ %d\n", dev
->irq
);
523 acpi_register_gsi(dev
->irq
, ACPI_LEVEL_SENSITIVE
,
532 rc
= acpi_register_gsi(gsi
, triggering
, polarity
);
534 dev_warn(&dev
->dev
, "PCI INT %c: failed to register GSI\n",
541 snprintf(link_desc
, sizeof(link_desc
), " -> Link[%s]", link
);
545 dev_info(&dev
->dev
, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n",
546 pin_name(pin
), link_desc
, gsi
,
547 (triggering
== ACPI_LEVEL_SENSITIVE
) ? "level" : "edge",
548 (polarity
== ACPI_ACTIVE_LOW
) ? "low" : "high", dev
->irq
);
553 /* FIXME: implement x86/x86_64 version */
554 void __attribute__ ((weak
)) acpi_unregister_gsi(u32 i
)
558 void acpi_pci_irq_disable(struct pci_dev
*dev
)
562 int triggering
= ACPI_LEVEL_SENSITIVE
;
563 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
->bus
, PCI_SLOT(dev
->devfn
), 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
);