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");
75 * Parse through all PRT entries looking for a match on the specified
76 * PCI device's segment, bus, device, and pin (don't care about func).
78 * TBD: Acquire/release lock
80 list_for_each(node, &acpi_prt.entries) {
81 entry = list_entry(node, struct acpi_prt_entry, node);
82 if ((segment == entry->id.segment)
83 && (bus == entry->id.bus)
84 && (device == entry->id.device)
85 && (pin == entry->pin)) {
95 acpi_pci_irq_add_entry (
99 struct acpi_pci_routing_table *prt)
101 struct acpi_prt_entry *entry = NULL;
103 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_entry");
106 return_VALUE(-EINVAL);
108 entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
110 return_VALUE(-ENOMEM);
111 memset(entry, 0, sizeof(struct acpi_prt_entry));
113 entry->id.segment = segment;
115 entry->id.device = (prt->address >> 16) & 0xFFFF;
116 entry->id.function = prt->address & 0xFFFF;
117 entry->pin = prt->pin;
122 * The 'source' field specifies the PCI interrupt link device used to
123 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
124 * indicates which resource descriptor in the resource template (of
125 * the link device) this interrupt is allocated from.
127 * NOTE: Don't query the Link Device for IRQ information at this time
128 * because Link Device enumeration may not have occurred yet
129 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
132 if (prt->source[0]) {
133 acpi_get_handle(handle, prt->source, &entry->link.handle);
134 entry->link.index = prt->source_index;
139 * The 'source' field is NULL, and the 'source_index' field specifies
140 * the IRQ value, which is hardwired to specific interrupt inputs on
141 * the interrupt controller.
144 entry->link.index = prt->source_index;
146 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
147 " %02X:%02X:%02X[%c] -> %s[%d]\n",
148 entry->id.segment, entry->id.bus, entry->id.device,
149 ('A' + entry->pin), prt->source, entry->link.index));
151 /* TBD: Acquire/release lock */
152 list_add_tail(&entry->node, &acpi_prt.entries);
160 acpi_pci_irq_add_prt (
165 acpi_status status = AE_OK;
166 char pathname[ACPI_PATHNAME_MAX] = {0};
167 struct acpi_buffer buffer = {0, NULL};
168 struct acpi_pci_routing_table *prt = NULL;
169 struct acpi_pci_routing_table *entry = NULL;
170 static int first_time = 1;
172 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_prt");
176 INIT_LIST_HEAD(&acpi_prt.entries);
181 * NOTE: We're given a 'handle' to the _PRT object's parent device
182 * (either a PCI root bridge or PCI-PCI bridge).
185 buffer.length = sizeof(pathname);
186 buffer.pointer = pathname;
187 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
189 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
193 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
197 buffer.pointer = NULL;
198 status = acpi_get_irq_routing_table(handle, &buffer);
199 if (status != AE_BUFFER_OVERFLOW) {
200 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n",
201 acpi_format_exception(status)));
202 return_VALUE(-ENODEV);
205 prt = kmalloc(buffer.length, GFP_KERNEL);
207 return_VALUE(-ENOMEM);
208 memset(prt, 0, buffer.length);
209 buffer.pointer = prt;
211 status = acpi_get_irq_routing_table(handle, &buffer);
212 if (ACPI_FAILURE(status)) {
213 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n",
214 acpi_format_exception(status)));
215 kfree(buffer.pointer);
216 return_VALUE(-ENODEV);
221 while (entry && (entry->length > 0)) {
222 acpi_pci_irq_add_entry(handle, segment, bus, entry);
223 entry = (struct acpi_pci_routing_table *)
224 ((unsigned long) entry + entry->length);
233 /* --------------------------------------------------------------------------
234 PCI Interrupt Routing Support
235 -------------------------------------------------------------------------- */
238 acpi_pci_irq_lookup (struct pci_bus *bus, int device, int pin)
240 struct acpi_prt_entry *entry = NULL;
241 int segment = pci_domain_nr(bus);
242 int bus_nr = bus->number;
244 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup");
246 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
247 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
248 segment, bus_nr, device, ('A' + pin)));
250 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin);
252 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n"));
256 if (!entry->irq && entry->link.handle) {
257 entry->irq = acpi_pci_link_get_irq(entry->link.handle, entry->link.index);
259 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid IRQ link routing entry\n"));
263 else if (!entry->irq) {
264 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid static routing entry (IRQ 0)\n"));
268 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", entry->irq));
270 return_VALUE(entry->irq);
275 acpi_pci_irq_derive (
279 struct pci_dev *bridge = dev;
282 ACPI_FUNCTION_TRACE("acpi_pci_irq_derive");
285 return_VALUE(-EINVAL);
288 * Attempt to derive an IRQ for this device from a parent bridge's
289 * PCI interrupt routing entry (a.k.a. the "bridge swizzle").
291 while (!irq && bridge->bus->self) {
292 pin = (pin + PCI_SLOT(bridge->devfn)) % 4;
293 bridge = bridge->bus->self;
294 irq = acpi_pci_irq_lookup(bridge->bus,
295 PCI_SLOT(bridge->devfn), pin);
299 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to derive IRQ for device %s\n", dev->slot_name));
303 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derived IRQ %d\n", irq));
310 acpi_pci_irq_enable (
315 static u16 irq_mask = 0;
317 ACPI_FUNCTION_TRACE("acpi_pci_irq_enable");
320 return_VALUE(-EINVAL);
322 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
324 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No interrupt pin configured for device %s\n", dev->slot_name));
330 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) 'bus' field\n"));
331 return_VALUE(-ENODEV);
335 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
336 * values override any BIOS-assigned IRQs set during boot.
338 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin);
341 * If no PRT entry was found, we'll try to derive an IRQ from the
342 * device's parent bridge.
345 irq = acpi_pci_irq_derive(dev, pin);
348 * No IRQ known to the ACPI subsystem - maybe the BIOS /
349 * driver reported one, then use it. Exit in any case.
352 printk(KERN_WARNING PREFIX "No IRQ known for interrupt pin %c of device %s", ('A' + pin), dev->slot_name);
353 /* Interrupt Line values above 0xF are forbidden */
354 if (dev->irq && dev->irq >= 0xF) {
355 printk(" - using IRQ %d\n", dev->irq);
356 return_VALUE(dev->irq);
366 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device %s using IRQ %d\n", dev->slot_name, dev->irq));
369 * Make sure all (legacy) PCI IRQs are set as level-triggered.
372 if ((dev->irq < 16) && !((1 << dev->irq) & irq_mask)) {
373 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Setting IRQ %d as level-triggered\n", dev->irq));
374 irq_mask |= (1 << dev->irq);
375 eisa_set_level_irq(dev->irq);
378 #ifdef CONFIG_IOSAPIC
379 if (acpi_irq_model == ACPI_IRQ_MODEL_IOSAPIC)
380 iosapic_enable_intr(dev->irq);
383 return_VALUE(dev->irq);
388 acpi_pci_irq_init (void)
390 struct pci_dev *dev = NULL;
392 ACPI_FUNCTION_TRACE("acpi_pci_irq_init");
394 if (!acpi_prt.count) {
395 printk(KERN_WARNING PREFIX "ACPI tables contain no PCI IRQ "
396 "routing entries\n");
397 return_VALUE(-ENODEV);
400 /* Make sure all link devices have a valid IRQ. */
401 acpi_pci_link_check();
403 #ifdef CONFIG_X86_IO_APIC
404 /* Program IOAPICs using data from PRT entries. */
405 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
408 #ifdef CONFIG_IOSAPIC
409 if (acpi_irq_model == ACPI_IRQ_MODEL_IOSAPIC)
413 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL)
414 acpi_pci_irq_enable(dev);