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 #define PREFIX "PCI: "
53 struct acpi_prt_list acpi_prt;
56 extern void eisa_set_level_irq(unsigned int irq);
60 /* --------------------------------------------------------------------------
61 PCI IRQ Routing Table (PRT) Support
62 -------------------------------------------------------------------------- */
64 static struct acpi_prt_entry *
65 acpi_pci_irq_find_prt_entry (
71 struct list_head *node = NULL;
72 struct acpi_prt_entry *entry = NULL;
74 ACPI_FUNCTION_TRACE("acpi_pci_irq_find_prt_entry");
80 * Parse through all PRT entries looking for a match on the specified
81 * PCI device's segment, bus, device, and pin (don't care about func).
83 * TBD: Acquire/release lock
85 list_for_each(node, &acpi_prt.entries) {
86 entry = list_entry(node, struct acpi_prt_entry, node);
87 if ((segment == entry->id.segment)
88 && (bus == entry->id.bus)
89 && (device == entry->id.device)
90 && (pin == entry->pin)) {
100 acpi_pci_irq_add_entry (
104 struct acpi_pci_routing_table *prt)
106 struct acpi_prt_entry *entry = NULL;
108 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_entry");
111 return_VALUE(-EINVAL);
113 entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
115 return_VALUE(-ENOMEM);
116 memset(entry, 0, sizeof(struct acpi_prt_entry));
118 entry->id.segment = segment;
120 entry->id.device = (prt->address >> 16) & 0xFFFF;
121 entry->id.function = prt->address & 0xFFFF;
122 entry->pin = prt->pin;
127 * The 'source' field specifies the PCI interrupt link device used to
128 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
129 * indicates which resource descriptor in the resource template (of
130 * the link device) this interrupt is allocated from.
132 * NOTE: Don't query the Link Device for IRQ information at this time
133 * because Link Device enumeration may not have occurred yet
134 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
137 if (prt->source[0]) {
138 acpi_get_handle(handle, prt->source, &entry->link.handle);
139 entry->link.index = prt->source_index;
144 * The 'source' field is NULL, and the 'source_index' field specifies
145 * the IRQ value, which is hardwired to specific interrupt inputs on
146 * the interrupt controller.
149 entry->link.index = prt->source_index;
151 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
152 " %02X:%02X:%02X[%c] -> %s[%d]\n",
153 entry->id.segment, entry->id.bus, entry->id.device,
154 ('A' + entry->pin), prt->source, entry->link.index));
156 /* TBD: Acquire/release lock */
157 list_add_tail(&entry->node, &acpi_prt.entries);
165 acpi_pci_irq_add_prt (
170 acpi_status status = AE_OK;
171 char pathname[ACPI_PATHNAME_MAX] = {0};
172 struct acpi_buffer buffer = {0, NULL};
173 struct acpi_pci_routing_table *prt = NULL;
174 struct acpi_pci_routing_table *entry = NULL;
175 static int first_time = 1;
177 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_prt");
181 INIT_LIST_HEAD(&acpi_prt.entries);
186 * NOTE: We're given a 'handle' to the _PRT object's parent device
187 * (either a PCI root bridge or PCI-PCI bridge).
190 buffer.length = sizeof(pathname);
191 buffer.pointer = pathname;
192 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
194 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
198 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
202 buffer.pointer = NULL;
203 status = acpi_get_irq_routing_table(handle, &buffer);
204 if (status != AE_BUFFER_OVERFLOW) {
205 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n",
206 acpi_format_exception(status)));
207 return_VALUE(-ENODEV);
210 prt = kmalloc(buffer.length, GFP_KERNEL);
212 return_VALUE(-ENOMEM);
213 memset(prt, 0, buffer.length);
214 buffer.pointer = prt;
216 status = acpi_get_irq_routing_table(handle, &buffer);
217 if (ACPI_FAILURE(status)) {
218 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n",
219 acpi_format_exception(status)));
220 kfree(buffer.pointer);
221 return_VALUE(-ENODEV);
226 while (entry && (entry->length > 0)) {
227 acpi_pci_irq_add_entry(handle, segment, bus, entry);
228 entry = (struct acpi_pci_routing_table *)
229 ((unsigned long) entry + entry->length);
238 /* --------------------------------------------------------------------------
239 PCI Interrupt Routing Support
240 -------------------------------------------------------------------------- */
243 acpi_pci_irq_lookup (
249 struct acpi_prt_entry *entry = NULL;
251 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup");
253 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
254 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
255 segment, bus, device, ('A' + pin)));
257 entry = acpi_pci_irq_find_prt_entry(segment, bus, device, pin);
259 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n"));
263 if (!entry->irq && entry->link.handle) {
264 entry->irq = acpi_pci_link_get_irq(entry->link.handle, entry->link.index, NULL, NULL);
266 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid IRQ link routing entry\n"));
270 else if (!entry->irq) {
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid static routing entry (IRQ 0)\n"));
275 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", entry->irq));
277 return_VALUE(entry->irq);
281 acpi_pci_irq_derive (
285 struct pci_dev *bridge = dev;
289 ACPI_FUNCTION_TRACE("acpi_pci_irq_derive");
292 return_VALUE(-EINVAL);
295 * Attempt to derive an IRQ for this device from a parent bridge's
296 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge)
298 while (!irq && bridge->bus->self) {
299 pin = (pin + PCI_SLOT(bridge->devfn)) % 4;
300 bridge = bridge->bus->self;
302 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
303 /* PC card has the same IRQ as its cardbridge */
304 pci_read_config_byte(bridge, PCI_INTERRUPT_PIN, &bridge_pin);
306 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
307 "No interrupt pin configured for device %s\n",
311 /* Pin is from 0 to 3 */
316 irq = acpi_pci_irq_lookup(0, bridge->bus->number,
317 PCI_SLOT(bridge->devfn), pin);
321 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to derive IRQ for device %s\n", dev->slot_name));
325 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n",
326 irq, pci_name(dev), pci_name(bridge)));
333 acpi_pci_irq_enable (
338 extern int via_interrupt_line_quirk;
340 ACPI_FUNCTION_TRACE("acpi_pci_irq_enable");
343 return_VALUE(-EINVAL);
345 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
347 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No interrupt pin configured for device %s\n", dev->slot_name));
353 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) 'bus' field\n"));
354 return_VALUE(-ENODEV);
358 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
359 * values override any BIOS-assigned IRQs set during boot.
361 irq = acpi_pci_irq_lookup(0, dev->bus->number, PCI_SLOT(dev->devfn), pin);
364 * If no PRT entry was found, we'll try to derive an IRQ from the
365 * device's parent bridge.
368 irq = acpi_pci_irq_derive(dev, pin);
371 * No IRQ known to the ACPI subsystem - maybe the BIOS /
372 * driver reported one, then use it. Exit in any case.
375 printk(KERN_WARNING PREFIX "No IRQ known for interrupt pin %c of device %s", ('A' + pin), dev->slot_name);
376 /* Interrupt Line values above 0xF are forbidden */
377 if (dev->irq && (dev->irq <= 0xF)) {
378 printk(" - using IRQ %d\n", dev->irq);
379 return_VALUE(dev->irq);
387 if (via_interrupt_line_quirk)
388 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq & 15);
392 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device %s using IRQ %d\n", dev->slot_name, dev->irq));
395 * Make sure all (legacy) PCI IRQs are set as level-triggered.
400 if ((dev->irq < 16) && !((1 << dev->irq) & irq_mask)) {
401 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Setting IRQ %d as level-triggered\n", dev->irq));
402 irq_mask |= (1 << dev->irq);
403 eisa_set_level_irq(dev->irq);
407 #ifdef CONFIG_IOSAPIC
408 if (acpi_irq_model == ACPI_IRQ_MODEL_IOSAPIC)
409 iosapic_enable_intr(dev->irq);
412 return_VALUE(dev->irq);
417 acpi_pci_irq_init (void)
419 struct pci_dev *dev = NULL;
421 ACPI_FUNCTION_TRACE("acpi_pci_irq_init");
423 if (!acpi_prt.count) {
424 printk(KERN_WARNING PREFIX "ACPI tables contain no PCI IRQ "
425 "routing entries\n");
426 return_VALUE(-ENODEV);
429 /* Make sure all link devices have a valid IRQ. */
430 if (acpi_pci_link_check()) {
431 return_VALUE(-ENODEV);
434 #ifdef CONFIG_X86_IO_APIC
435 /* Program IOAPICs using data from PRT entries. */
436 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
439 #ifdef CONFIG_IOSAPIC
440 if (acpi_irq_model == ACPI_IRQ_MODEL_IOSAPIC)
444 pci_for_each_dev(dev)
445 acpi_pci_irq_enable(dev);