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
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>
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
,
58 struct acpi_prt_entry
*entry
= 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
);
79 spin_unlock(&acpi_prt_lock
);
83 <<<<<<< HEAD
:drivers
/acpi
/pci_irq
.c
85 /* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
86 static struct dmi_system_id medion_md9580
[] = {
88 .ident
= "Medion MD9580-F laptop",
90 DMI_MATCH(DMI_SYS_VENDOR
, "MEDIONNB"),
91 DMI_MATCH(DMI_PRODUCT_NAME
, "A555"),
97 /* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
98 static struct dmi_system_id dell_optiplex
[] = {
100 .ident
= "Dell Optiplex GX1",
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
[] = {
114 DMI_MATCH(DMI_SYS_VENDOR
, "Hewlett-Packard"),
115 DMI_MATCH(DMI_PRODUCT_NAME
, "hp t5000 series"),
116 DMI_MATCH(DMI_BOARD_NAME
, "098Ch"),
123 struct dmi_system_id
*system
;
124 unsigned int segment
;
128 char *source
; /* according to BIOS */
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',
144 { hp_t5710
, 0, 0, 1, 'A',
150 do_prt_fixups(struct acpi_prt_entry
*entry
, struct acpi_pci_routing_table
*prt
)
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 */
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; "
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
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
;
191 entry
= kzalloc(sizeof(struct acpi_prt_entry
), GFP_KERNEL
);
195 entry
->id
.segment
= segment
;
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
203 do_prt_fixups(entry
, prt
);
205 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/pci_irq
.c
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
219 if (prt
->source
[0]) {
220 acpi_get_handle(handle
, prt
->source
, &entry
->link
.handle
);
221 entry
->link
.index
= prt
->source_index
;
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.
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
,
239 spin_lock(&acpi_prt_lock
);
240 list_add_tail(&entry
->node
, &acpi_prt
.entries
);
242 spin_unlock(&acpi_prt_lock
);
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
) {
252 list_del(&entry
->node
);
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
);
273 INIT_LIST_HEAD(&acpi_prt
.entries
);
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",
290 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
294 buffer
.pointer
= NULL
;
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
)));
303 prt
= kzalloc(buffer
.length
, GFP_KERNEL
);
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
);
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
);
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
) {
340 "ACPI: Delete PCI Interrupt Routing Table for %x:%x\n", segment
,
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 **);
357 acpi_pci_allocate_irq(struct acpi_prt_entry
*entry
,
358 int *triggering
, int *polarity
, char **link
)
363 if (entry
->link
.handle
) {
364 irq
= acpi_pci_link_allocate_irq(entry
->link
.handle
,
365 entry
->link
.index
, triggering
,
368 printk(KERN_WARNING PREFIX
369 "Invalid IRQ link routing entry\n");
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
));
383 acpi_pci_free_irq(struct acpi_prt_entry
*entry
,
384 int *triggering
, int *polarity
, char **link
)
388 if (entry
->link
.handle
) {
389 irq
= acpi_pci_link_free_irq(entry
->link
.handle
);
391 irq
= entry
->link
.index
;
397 * acpi_pci_irq_lookup
398 * success: return IRQ >= 0
402 acpi_pci_irq_lookup(struct pci_bus
*bus
,
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
;
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
);
420 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "PRT entry not found\n"));
424 ret
= func(entry
, triggering
, polarity
, link
);
429 * acpi_pci_irq_derive
430 * success: return IRQ >= 0
431 * failure: return < 0
434 acpi_pci_irq_derive(struct pci_dev
*dev
,
437 int *polarity
, char **link
, irq_lookup_func func
)
439 struct pci_dev
*bridge
= dev
;
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
;
459 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
460 "No interrupt pin configured for device %s\n",
464 /* Pin is from 0 to 3 */
469 irq
= acpi_pci_irq_lookup(bridge
->bus
, PCI_SLOT(bridge
->devfn
),
470 pin
, triggering
, polarity
,
475 printk(KERN_WARNING PREFIX
"Unable to derive IRQ for device %s\n",
480 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Derive IRQ %d for device %s from %s\n",
481 irq
, pci_name(dev
), pci_name(bridge
)));
487 * acpi_pci_irq_enable
489 * failure: return < 0
492 int acpi_pci_irq_enable(struct pci_dev
*dev
)
496 int triggering
= ACPI_LEVEL_SENSITIVE
;
497 int polarity
= ACPI_ACTIVE_LOW
;
507 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
508 "No interrupt pin configured for device %s\n",
515 printk(KERN_ERR PREFIX
"Invalid (NULL) 'bus' field\n");
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.
532 irq
= acpi_pci_irq_derive(dev
, pin
, &triggering
,
534 acpi_pci_allocate_irq
);
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)
546 * No IRQ known to the ACPI subsystem - maybe the BIOS /
547 * driver reported one, then use it. Exit in any case.
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
,
564 rc
= acpi_register_gsi(irq
, triggering
, polarity
);
566 printk(KERN_WARNING PREFIX
"PCI Interrupt %s[%c]: failed "
567 "to register GSI\n", pci_name(dev
), ('A' + pin
));
572 printk(KERN_INFO PREFIX
"PCI Interrupt %s[%c] -> ",
573 pci_name(dev
), 'A' + pin
);
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
);
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
)
594 int triggering
= ACPI_LEVEL_SENSITIVE
;
595 int polarity
= ACPI_ACTIVE_LOW
;
598 if (!dev
|| !dev
->bus
)
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
,
613 * If no PRT entry was found, we'll try to derive an IRQ from the
614 * device's parent bridge.
617 gsi
= acpi_pci_irq_derive(dev
, pin
,
618 &triggering
, &polarity
, NULL
,
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",
631 acpi_unregister_gsi(gsi
);