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 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/config.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>
42 #define _COMPONENT ACPI_PCI_COMPONENT
43 ACPI_MODULE_NAME ("pci_irq")
45 static struct acpi_prt_list acpi_prt
;
46 static DEFINE_SPINLOCK(acpi_prt_lock
);
48 /* --------------------------------------------------------------------------
49 PCI IRQ Routing Table (PRT) Support
50 -------------------------------------------------------------------------- */
52 static struct acpi_prt_entry
*
53 acpi_pci_irq_find_prt_entry (
59 struct list_head
*node
= NULL
;
60 struct acpi_prt_entry
*entry
= NULL
;
62 ACPI_FUNCTION_TRACE("acpi_pci_irq_find_prt_entry");
68 * Parse through all PRT entries looking for a match on the specified
69 * PCI device's segment, bus, device, and pin (don't care about func).
72 spin_lock(&acpi_prt_lock
);
73 list_for_each(node
, &acpi_prt
.entries
) {
74 entry
= list_entry(node
, struct acpi_prt_entry
, node
);
75 if ((segment
== entry
->id
.segment
)
76 && (bus
== entry
->id
.bus
)
77 && (device
== entry
->id
.device
)
78 && (pin
== entry
->pin
)) {
79 spin_unlock(&acpi_prt_lock
);
84 spin_unlock(&acpi_prt_lock
);
90 acpi_pci_irq_add_entry (
94 struct acpi_pci_routing_table
*prt
)
96 struct acpi_prt_entry
*entry
= NULL
;
98 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_entry");
101 return_VALUE(-EINVAL
);
103 entry
= kmalloc(sizeof(struct acpi_prt_entry
), GFP_KERNEL
);
105 return_VALUE(-ENOMEM
);
106 memset(entry
, 0, sizeof(struct acpi_prt_entry
));
108 entry
->id
.segment
= segment
;
110 entry
->id
.device
= (prt
->address
>> 16) & 0xFFFF;
111 entry
->id
.function
= prt
->address
& 0xFFFF;
112 entry
->pin
= prt
->pin
;
117 * The 'source' field specifies the PCI interrupt link device used to
118 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
119 * indicates which resource descriptor in the resource template (of
120 * the link device) this interrupt is allocated from.
122 * NOTE: Don't query the Link Device for IRQ information at this time
123 * because Link Device enumeration may not have occurred yet
124 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
127 if (prt
->source
[0]) {
128 acpi_get_handle(handle
, prt
->source
, &entry
->link
.handle
);
129 entry
->link
.index
= prt
->source_index
;
134 * The 'source' field is NULL, and the 'source_index' field specifies
135 * the IRQ value, which is hardwired to specific interrupt inputs on
136 * the interrupt controller.
139 entry
->link
.index
= prt
->source_index
;
141 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO
,
142 " %02X:%02X:%02X[%c] -> %s[%d]\n",
143 entry
->id
.segment
, entry
->id
.bus
, entry
->id
.device
,
144 ('A' + entry
->pin
), prt
->source
, entry
->link
.index
));
146 spin_lock(&acpi_prt_lock
);
147 list_add_tail(&entry
->node
, &acpi_prt
.entries
);
149 spin_unlock(&acpi_prt_lock
);
156 acpi_pci_irq_del_entry (
159 struct acpi_prt_entry
*entry
)
161 if (segment
== entry
->id
.segment
&& bus
== entry
->id
.bus
){
163 list_del(&entry
->node
);
170 acpi_pci_irq_add_prt (
175 acpi_status status
= AE_OK
;
176 char *pathname
= NULL
;
177 struct acpi_buffer buffer
= {0, NULL
};
178 struct acpi_pci_routing_table
*prt
= NULL
;
179 struct acpi_pci_routing_table
*entry
= NULL
;
180 static int first_time
= 1;
182 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_prt");
184 pathname
= (char *) kmalloc(ACPI_PATHNAME_MAX
, GFP_KERNEL
);
186 return_VALUE(-ENOMEM
);
187 memset(pathname
, 0, ACPI_PATHNAME_MAX
);
191 INIT_LIST_HEAD(&acpi_prt
.entries
);
196 * NOTE: We're given a 'handle' to the _PRT object's parent device
197 * (either a PCI root bridge or PCI-PCI bridge).
200 buffer
.length
= ACPI_PATHNAME_MAX
;
201 buffer
.pointer
= pathname
;
202 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
204 printk(KERN_DEBUG
"ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
208 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
212 buffer
.pointer
= NULL
;
214 status
= acpi_get_irq_routing_table(handle
, &buffer
);
215 if (status
!= AE_BUFFER_OVERFLOW
) {
216 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error evaluating _PRT [%s]\n",
217 acpi_format_exception(status
)));
218 return_VALUE(-ENODEV
);
221 prt
= kmalloc(buffer
.length
, GFP_KERNEL
);
223 return_VALUE(-ENOMEM
);
225 memset(prt
, 0, buffer
.length
);
226 buffer
.pointer
= prt
;
228 status
= acpi_get_irq_routing_table(handle
, &buffer
);
229 if (ACPI_FAILURE(status
)) {
230 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error evaluating _PRT [%s]\n",
231 acpi_format_exception(status
)));
232 kfree(buffer
.pointer
);
233 return_VALUE(-ENODEV
);
238 while (entry
&& (entry
->length
> 0)) {
239 acpi_pci_irq_add_entry(handle
, segment
, bus
, entry
);
240 entry
= (struct acpi_pci_routing_table
*)
241 ((unsigned long) entry
+ entry
->length
);
250 acpi_pci_irq_del_prt (int segment
, int bus
)
252 struct list_head
*node
= NULL
, *n
= NULL
;
253 struct acpi_prt_entry
*entry
= NULL
;
255 if (!acpi_prt
.count
) {
259 printk(KERN_DEBUG
"ACPI: Delete PCI Interrupt Routing Table for %x:%x\n",
261 spin_lock(&acpi_prt_lock
);
262 list_for_each_safe(node
, n
, &acpi_prt
.entries
) {
263 entry
= list_entry(node
, struct acpi_prt_entry
, node
);
265 acpi_pci_irq_del_entry(segment
, bus
, entry
);
267 spin_unlock(&acpi_prt_lock
);
269 /* --------------------------------------------------------------------------
270 PCI Interrupt Routing Support
271 -------------------------------------------------------------------------- */
274 * acpi_pci_irq_lookup
275 * success: return IRQ >= 0
279 acpi_pci_irq_lookup (
284 int *active_high_low
,
287 struct acpi_prt_entry
*entry
= NULL
;
288 int segment
= pci_domain_nr(bus
);
289 int bus_nr
= bus
->number
;
292 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup");
294 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
295 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
296 segment
, bus_nr
, device
, ('A' + pin
)));
298 entry
= acpi_pci_irq_find_prt_entry(segment
, bus_nr
, device
, pin
);
300 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "PRT entry not found\n"));
304 if (entry
->link
.handle
) {
305 irq
= acpi_pci_link_get_irq(entry
->link
.handle
,
306 entry
->link
.index
, edge_level
, active_high_low
, link
);
308 ACPI_DEBUG_PRINT((ACPI_DB_WARN
, "Invalid IRQ link routing entry\n"));
312 irq
= entry
->link
.index
;
313 *edge_level
= ACPI_LEVEL_SENSITIVE
;
314 *active_high_low
= ACPI_ACTIVE_LOW
;
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found IRQ %d\n", irq
));
323 * acpi_pci_irq_derive
324 * success: return IRQ >= 0
325 * failure: return < 0
328 acpi_pci_irq_derive (
332 int *active_high_low
,
335 struct pci_dev
*bridge
= dev
;
339 ACPI_FUNCTION_TRACE("acpi_pci_irq_derive");
342 return_VALUE(-EINVAL
);
345 * Attempt to derive an IRQ for this device from a parent bridge's
346 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
348 while (irq
< 0 && bridge
->bus
->self
) {
349 pin
= (pin
+ PCI_SLOT(bridge
->devfn
)) % 4;
350 bridge
= bridge
->bus
->self
;
352 if ((bridge
->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS
) {
353 /* PC card has the same IRQ as its cardbridge */
354 pci_read_config_byte(bridge
, PCI_INTERRUPT_PIN
, &bridge_pin
);
356 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
357 "No interrupt pin configured for device %s\n", pci_name(bridge
)));
360 /* Pin is from 0 to 3 */
365 irq
= acpi_pci_irq_lookup(bridge
->bus
, PCI_SLOT(bridge
->devfn
),
366 pin
, edge_level
, active_high_low
, link
);
370 ACPI_DEBUG_PRINT((ACPI_DB_WARN
, "Unable to derive IRQ for device %s\n", pci_name(dev
)));
374 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Derive IRQ %d for device %s from %s\n",
375 irq
, pci_name(dev
), pci_name(bridge
)));
381 * acpi_pci_irq_enable
383 * failure: return < 0
387 acpi_pci_irq_enable (
392 int edge_level
= ACPI_LEVEL_SENSITIVE
;
393 int active_high_low
= ACPI_ACTIVE_LOW
;
396 ACPI_FUNCTION_TRACE("acpi_pci_irq_enable");
399 return_VALUE(-EINVAL
);
401 pci_read_config_byte(dev
, PCI_INTERRUPT_PIN
, &pin
);
403 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No interrupt pin configured for device %s\n", pci_name(dev
)));
409 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Invalid (NULL) 'bus' field\n"));
410 return_VALUE(-ENODEV
);
414 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
415 * values override any BIOS-assigned IRQs set during boot.
417 irq
= acpi_pci_irq_lookup(dev
->bus
, PCI_SLOT(dev
->devfn
), pin
,
418 &edge_level
, &active_high_low
, &link
);
421 * If no PRT entry was found, we'll try to derive an IRQ from the
422 * device's parent bridge.
425 irq
= acpi_pci_irq_derive(dev
, pin
, &edge_level
,
426 &active_high_low
, &link
);
429 * No IRQ known to the ACPI subsystem - maybe the BIOS /
430 * driver reported one, then use it. Exit in any case.
433 printk(KERN_WARNING PREFIX
"PCI Interrupt %s[%c]: no GSI",
434 pci_name(dev
), ('A' + pin
));
435 /* Interrupt Line values above 0xF are forbidden */
436 if (dev
->irq
> 0 && (dev
->irq
<= 0xF)) {
437 printk(" - using IRQ %d\n", dev
->irq
);
438 acpi_register_gsi(dev
->irq
, ACPI_LEVEL_SENSITIVE
, ACPI_ACTIVE_LOW
);
447 dev
->irq
= acpi_register_gsi(irq
, edge_level
, active_high_low
);
449 printk(KERN_INFO PREFIX
"PCI Interrupt %s[%c] -> ",
450 pci_name(dev
), 'A' + pin
);
453 printk("Link [%s] -> ", link
);
455 printk("GSI %u (%s, %s) -> IRQ %d\n", irq
,
456 (edge_level
== ACPI_LEVEL_SENSITIVE
) ? "level" : "edge",
457 (active_high_low
== ACPI_ACTIVE_LOW
) ? "low" : "high",
462 EXPORT_SYMBOL(acpi_pci_irq_enable
);
465 #ifdef CONFIG_ACPI_DEALLOCATE_IRQ
467 acpi_pci_irq_disable (
472 int edge_level
= ACPI_LEVEL_SENSITIVE
;
473 int active_high_low
= ACPI_ACTIVE_LOW
;
475 ACPI_FUNCTION_TRACE("acpi_pci_irq_disable");
480 pci_read_config_byte(dev
, PCI_INTERRUPT_PIN
, &pin
);
489 * First we check the PCI IRQ routing table (PRT) for an IRQ.
491 gsi
= acpi_pci_irq_lookup(dev
->bus
, PCI_SLOT(dev
->devfn
), pin
,
492 &edge_level
, &active_high_low
, NULL
);
494 * If no PRT entry was found, we'll try to derive an IRQ from the
495 * device's parent bridge.
498 gsi
= acpi_pci_irq_derive(dev
, pin
,
499 &edge_level
, &active_high_low
, NULL
);
504 * TBD: It might be worth clearing dev->irq by magic constant
505 * (e.g. PCI_UNDEFINED_IRQ).
508 printk(KERN_INFO PREFIX
"PCI interrupt for device %s disabled\n",
511 acpi_unregister_gsi(gsi
);
515 #endif /* CONFIG_ACPI_DEALLOCATE_IRQ */