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/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/proc_fs.h>
32 #include <linux/spinlock.h>
34 #include <linux/pci.h>
35 #include <linux/acpi.h>
36 #ifdef CONFIG_X86_IO_APIC
37 #include <asm/mpspec.h>
39 #include <acpi/acpi_bus.h>
40 #include <acpi/acpi_drivers.h>
43 #define _COMPONENT ACPI_PCI_COMPONENT
44 ACPI_MODULE_NAME ("pci_irq")
46 struct acpi_prt_list acpi_prt;
49 extern void eisa_set_level_irq(unsigned int irq);
53 /* --------------------------------------------------------------------------
54 PCI IRQ Routing Table (PRT) Support
55 -------------------------------------------------------------------------- */
57 static struct acpi_prt_entry *
58 acpi_pci_irq_find_prt_entry (
64 struct list_head *node = NULL;
65 struct acpi_prt_entry *entry = NULL;
67 ACPI_FUNCTION_TRACE("acpi_pci_irq_find_prt_entry");
70 * Parse through all PRT entries looking for a match on the specified
71 * PCI device's segment, bus, device, and pin (don't care about func).
73 * TBD: Acquire/release lock
75 list_for_each(node, &acpi_prt.entries) {
76 entry = list_entry(node, struct acpi_prt_entry, node);
77 if ((segment == entry->id.segment)
78 && (bus == entry->id.bus)
79 && (device == entry->id.device)
80 && (pin == entry->pin)) {
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 /* TBD: Acquire/release lock */
147 list_add_tail(&entry->node, &acpi_prt.entries);
155 acpi_pci_irq_add_prt (
160 acpi_status status = AE_OK;
161 char pathname[ACPI_PATHNAME_MAX] = {0};
162 struct acpi_buffer buffer = {0, NULL};
163 struct acpi_pci_routing_table *prt = NULL;
164 struct acpi_pci_routing_table *entry = NULL;
165 static int first_time = 1;
167 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_prt");
171 INIT_LIST_HEAD(&acpi_prt.entries);
176 * NOTE: We're given a 'handle' to the _PRT object's parent device
177 * (either a PCI root bridge or PCI-PCI bridge).
180 buffer.length = sizeof(pathname);
181 buffer.pointer = pathname;
182 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
184 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
188 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
192 buffer.pointer = NULL;
193 status = acpi_get_irq_routing_table(handle, &buffer);
194 if (status != AE_BUFFER_OVERFLOW) {
195 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n",
196 acpi_format_exception(status)));
197 return_VALUE(-ENODEV);
200 prt = kmalloc(buffer.length, GFP_KERNEL);
202 return_VALUE(-ENOMEM);
203 memset(prt, 0, buffer.length);
204 buffer.pointer = prt;
206 status = acpi_get_irq_routing_table(handle, &buffer);
207 if (ACPI_FAILURE(status)) {
208 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n",
209 acpi_format_exception(status)));
210 kfree(buffer.pointer);
211 return_VALUE(-ENODEV);
216 while (entry && (entry->length > 0)) {
217 acpi_pci_irq_add_entry(handle, segment, bus, entry);
218 entry = (struct acpi_pci_routing_table *)
219 ((unsigned long) entry + entry->length);
228 /* --------------------------------------------------------------------------
229 PCI Interrupt Routing Support
230 -------------------------------------------------------------------------- */
233 acpi_pci_irq_lookup (struct pci_bus *bus, int device, int pin)
235 struct acpi_prt_entry *entry = NULL;
236 int segment = pci_domain_nr(bus);
237 int bus_nr = bus->number;
239 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup");
241 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
242 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
243 segment, bus_nr, device, ('A' + pin)));
245 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin);
247 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n"));
251 if (!entry->irq && entry->link.handle) {
252 entry->irq = acpi_pci_link_get_irq(entry->link.handle, entry->link.index);
254 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid IRQ link routing entry\n"));
258 else if (!entry->irq) {
259 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid static routing entry (IRQ 0)\n"));
263 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", entry->irq));
265 return_VALUE(entry->irq);
270 acpi_pci_irq_derive (
274 struct pci_dev *bridge = dev;
277 ACPI_FUNCTION_TRACE("acpi_pci_irq_derive");
280 return_VALUE(-EINVAL);
283 * Attempt to derive an IRQ for this device from a parent bridge's
284 * PCI interrupt routing entry (a.k.a. the "bridge swizzle").
286 while (!irq && bridge->bus->self) {
287 pin = (pin + PCI_SLOT(bridge->devfn)) % 4;
288 bridge = bridge->bus->self;
289 irq = acpi_pci_irq_lookup(bridge->bus,
290 PCI_SLOT(bridge->devfn), pin);
294 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to derive IRQ for device %s\n", pci_name(dev)));
298 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derived IRQ %d\n", irq));
305 acpi_pci_irq_enable (
310 static u16 irq_mask = 0;
312 ACPI_FUNCTION_TRACE("acpi_pci_irq_enable");
315 return_VALUE(-EINVAL);
317 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
319 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No interrupt pin configured for device %s\n", pci_name(dev)));
325 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) 'bus' field\n"));
326 return_VALUE(-ENODEV);
330 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
331 * values override any BIOS-assigned IRQs set during boot.
333 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin);
336 * If no PRT entry was found, we'll try to derive an IRQ from the
337 * device's parent bridge.
340 irq = acpi_pci_irq_derive(dev, pin);
343 * No IRQ known to the ACPI subsystem - maybe the BIOS /
344 * driver reported one, then use it. Exit in any case.
347 printk(KERN_WARNING PREFIX "No IRQ known for interrupt pin %c of device %s", ('A' + pin), pci_name(dev));
348 /* Interrupt Line values above 0xF are forbidden */
349 if (dev->irq && dev->irq >= 0xF) {
350 printk(" - using IRQ %d\n", dev->irq);
351 return_VALUE(dev->irq);
361 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device %s using IRQ %d\n", pci_name(dev), dev->irq));
364 * Make sure all (legacy) PCI IRQs are set as level-triggered.
367 if ((dev->irq < 16) && !((1 << dev->irq) & irq_mask)) {
368 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Setting IRQ %d as level-triggered\n", dev->irq));
369 irq_mask |= (1 << dev->irq);
370 eisa_set_level_irq(dev->irq);
373 #ifdef CONFIG_IOSAPIC
374 if (acpi_irq_model == ACPI_IRQ_MODEL_IOSAPIC)
375 iosapic_enable_intr(dev->irq);
378 return_VALUE(dev->irq);
383 acpi_pci_irq_init (void)
385 struct pci_dev *dev = NULL;
387 ACPI_FUNCTION_TRACE("acpi_pci_irq_init");
389 if (!acpi_prt.count) {
390 printk(KERN_WARNING PREFIX "ACPI tables contain no PCI IRQ "
391 "routing entries\n");
392 return_VALUE(-ENODEV);
395 /* Make sure all link devices have a valid IRQ. */
396 acpi_pci_link_check();
398 #ifdef CONFIG_X86_IO_APIC
399 /* Program IOAPICs using data from PRT entries. */
400 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
403 #ifdef CONFIG_IOSAPIC
404 if (acpi_irq_model == ACPI_IRQ_MODEL_IOSAPIC)
408 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL)
409 acpi_pci_irq_enable(dev);