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 #ifdef CONFIG_X86_IO_APIC
39 #include <asm/mpspec.h>
42 # include <asm/iosapic.h>
44 #include <acpi/acpi_bus.h>
45 #include <acpi/acpi_drivers.h>
48 #define _COMPONENT ACPI_PCI_COMPONENT
49 ACPI_MODULE_NAME ("pci_irq")
51 struct acpi_prt_list acpi_prt;
54 extern void eisa_set_level_irq(unsigned int irq);
58 /* --------------------------------------------------------------------------
59 PCI IRQ Routing Table (PRT) Support
60 -------------------------------------------------------------------------- */
62 static struct acpi_prt_entry *
63 acpi_pci_irq_find_prt_entry (
69 struct list_head *node = NULL;
70 struct acpi_prt_entry *entry = NULL;
72 ACPI_FUNCTION_TRACE("acpi_pci_irq_find_prt_entry");
78 * Parse through all PRT entries looking for a match on the specified
79 * PCI device's segment, bus, device, and pin (don't care about func).
81 * TBD: Acquire/release lock
83 list_for_each(node, &acpi_prt.entries) {
84 entry = list_entry(node, struct acpi_prt_entry, node);
85 if ((segment == entry->id.segment)
86 && (bus == entry->id.bus)
87 && (device == entry->id.device)
88 && (pin == entry->pin)) {
98 acpi_pci_irq_add_entry (
102 struct acpi_pci_routing_table *prt)
104 struct acpi_prt_entry *entry = NULL;
106 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_entry");
109 return_VALUE(-EINVAL);
111 entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
113 return_VALUE(-ENOMEM);
114 memset(entry, 0, sizeof(struct acpi_prt_entry));
116 entry->id.segment = segment;
118 entry->id.device = (prt->address >> 16) & 0xFFFF;
119 entry->id.function = prt->address & 0xFFFF;
120 entry->pin = prt->pin;
125 * The 'source' field specifies the PCI interrupt link device used to
126 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
127 * indicates which resource descriptor in the resource template (of
128 * the link device) this interrupt is allocated from.
130 * NOTE: Don't query the Link Device for IRQ information at this time
131 * because Link Device enumeration may not have occurred yet
132 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
135 if (prt->source[0]) {
136 acpi_get_handle(handle, prt->source, &entry->link.handle);
137 entry->link.index = prt->source_index;
142 * The 'source' field is NULL, and the 'source_index' field specifies
143 * the IRQ value, which is hardwired to specific interrupt inputs on
144 * the interrupt controller.
147 entry->link.index = prt->source_index;
149 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
150 " %02X:%02X:%02X[%c] -> %s[%d]\n",
151 entry->id.segment, entry->id.bus, entry->id.device,
152 ('A' + entry->pin), prt->source, entry->link.index));
154 /* TBD: Acquire/release lock */
155 list_add_tail(&entry->node, &acpi_prt.entries);
163 acpi_pci_irq_add_prt (
168 acpi_status status = AE_OK;
169 char pathname[ACPI_PATHNAME_MAX] = {0};
170 struct acpi_buffer buffer = {0, NULL};
171 struct acpi_pci_routing_table *prt = NULL;
172 struct acpi_pci_routing_table *entry = NULL;
173 static int first_time = 1;
175 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_prt");
179 INIT_LIST_HEAD(&acpi_prt.entries);
184 * NOTE: We're given a 'handle' to the _PRT object's parent device
185 * (either a PCI root bridge or PCI-PCI bridge).
188 buffer.length = sizeof(pathname);
189 buffer.pointer = pathname;
190 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
192 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
196 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
200 buffer.pointer = NULL;
201 status = acpi_get_irq_routing_table(handle, &buffer);
202 if (status != AE_BUFFER_OVERFLOW) {
203 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n",
204 acpi_format_exception(status)));
205 return_VALUE(-ENODEV);
208 prt = kmalloc(buffer.length, GFP_KERNEL);
210 return_VALUE(-ENOMEM);
211 memset(prt, 0, buffer.length);
212 buffer.pointer = prt;
214 status = acpi_get_irq_routing_table(handle, &buffer);
215 if (ACPI_FAILURE(status)) {
216 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n",
217 acpi_format_exception(status)));
218 kfree(buffer.pointer);
219 return_VALUE(-ENODEV);
224 while (entry && (entry->length > 0)) {
225 acpi_pci_irq_add_entry(handle, segment, bus, entry);
226 entry = (struct acpi_pci_routing_table *)
227 ((unsigned long) entry + entry->length);
236 /* --------------------------------------------------------------------------
237 PCI Interrupt Routing Support
238 -------------------------------------------------------------------------- */
241 acpi_pci_irq_lookup (struct pci_bus *bus, int device, int pin)
243 struct acpi_prt_entry *entry = NULL;
244 int segment = pci_domain_nr(bus);
245 int bus_nr = bus->number;
247 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup");
249 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
250 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
251 segment, bus_nr, device, ('A' + pin)));
253 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin);
255 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n"));
259 if (!entry->irq && entry->link.handle) {
260 entry->irq = acpi_pci_link_get_irq(entry->link.handle, entry->link.index, NULL, NULL);
262 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid IRQ link routing entry\n"));
266 else if (!entry->irq) {
267 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid static routing entry (IRQ 0)\n"));
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", entry->irq));
273 return_VALUE(entry->irq);
277 acpi_pci_irq_derive (
281 struct pci_dev *bridge = dev;
285 ACPI_FUNCTION_TRACE("acpi_pci_irq_derive");
288 return_VALUE(-EINVAL);
291 * Attempt to derive an IRQ for this device from a parent bridge's
292 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
294 while (!irq && bridge->bus->self) {
295 pin = (pin + PCI_SLOT(bridge->devfn)) % 4;
296 bridge = bridge->bus->self;
298 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
299 /* PC card has the same IRQ as its cardbridge */
300 pci_read_config_byte(bridge, PCI_INTERRUPT_PIN, &bridge_pin);
302 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
303 "No interrupt pin configured for device %s\n", pci_name(bridge)));
306 /* Pin is from 0 to 3 */
311 irq = acpi_pci_irq_lookup(bridge->bus,
312 PCI_SLOT(bridge->devfn), pin);
316 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to derive IRQ for device %s\n", pci_name(dev)));
320 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n",
321 irq, pci_name(dev), pci_name(bridge)));
328 acpi_pci_irq_enable (
334 ACPI_FUNCTION_TRACE("acpi_pci_irq_enable");
337 return_VALUE(-EINVAL);
339 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
341 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No interrupt pin configured for device %s\n", pci_name(dev)));
347 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) 'bus' field\n"));
348 return_VALUE(-ENODEV);
352 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
353 * values override any BIOS-assigned IRQs set during boot.
355 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin);
358 * If no PRT entry was found, we'll try to derive an IRQ from the
359 * device's parent bridge.
362 irq = acpi_pci_irq_derive(dev, pin);
365 * No IRQ known to the ACPI subsystem - maybe the BIOS /
366 * driver reported one, then use it. Exit in any case.
369 printk(KERN_WARNING PREFIX "No IRQ known for interrupt pin %c of device %s", ('A' + pin), pci_name(dev));
370 /* Interrupt Line values above 0xF are forbidden */
371 if (dev->irq && (dev->irq <= 0xF)) {
372 printk(" - using IRQ %d\n", dev->irq);
373 return_VALUE(dev->irq);
383 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device %s using IRQ %d\n", pci_name(dev), dev->irq));
386 * Make sure all (legacy) PCI IRQs are set as level-triggered.
391 if ((dev->irq < 16) && !((1 << dev->irq) & irq_mask)) {
392 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Setting IRQ %d as level-triggered\n", dev->irq));
393 irq_mask |= (1 << dev->irq);
394 eisa_set_level_irq(dev->irq);
398 #ifdef CONFIG_IOSAPIC
399 if (acpi_irq_model == ACPI_IRQ_MODEL_IOSAPIC)
400 iosapic_enable_intr(dev->irq);
403 return_VALUE(dev->irq);
408 acpi_pci_irq_init (void)
410 struct pci_dev *dev = NULL;
412 ACPI_FUNCTION_TRACE("acpi_pci_irq_init");
414 if (!acpi_prt.count) {
415 printk(KERN_WARNING PREFIX "ACPI tables contain no PCI IRQ "
416 "routing entries\n");
417 return_VALUE(-ENODEV);
420 /* Make sure all link devices have a valid IRQ. */
421 if (acpi_pci_link_check()) {
422 return_VALUE(-ENODEV);
425 #ifdef CONFIG_X86_IO_APIC
426 /* Program IOAPICs using data from PRT entries. */
427 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
430 #ifdef CONFIG_IOSAPIC
431 if (acpi_irq_model == ACPI_IRQ_MODEL_IOSAPIC)
435 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL)
436 acpi_pci_irq_enable(dev);