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 struct acpi_prt_list acpi_prt
;
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).
71 * TBD: Acquire/release 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
)) {
88 acpi_pci_irq_add_entry (
92 struct acpi_pci_routing_table
*prt
)
94 struct acpi_prt_entry
*entry
= NULL
;
96 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_entry");
99 return_VALUE(-EINVAL
);
101 entry
= kmalloc(sizeof(struct acpi_prt_entry
), GFP_KERNEL
);
103 return_VALUE(-ENOMEM
);
104 memset(entry
, 0, sizeof(struct acpi_prt_entry
));
106 entry
->id
.segment
= segment
;
108 entry
->id
.device
= (prt
->address
>> 16) & 0xFFFF;
109 entry
->id
.function
= prt
->address
& 0xFFFF;
110 entry
->pin
= prt
->pin
;
115 * The 'source' field specifies the PCI interrupt link device used to
116 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
117 * indicates which resource descriptor in the resource template (of
118 * the link device) this interrupt is allocated from.
120 * NOTE: Don't query the Link Device for IRQ information at this time
121 * because Link Device enumeration may not have occurred yet
122 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
125 if (prt
->source
[0]) {
126 acpi_get_handle(handle
, prt
->source
, &entry
->link
.handle
);
127 entry
->link
.index
= prt
->source_index
;
132 * The 'source' field is NULL, and the 'source_index' field specifies
133 * the IRQ value, which is hardwired to specific interrupt inputs on
134 * the interrupt controller.
137 entry
->link
.index
= prt
->source_index
;
139 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO
,
140 " %02X:%02X:%02X[%c] -> %s[%d]\n",
141 entry
->id
.segment
, entry
->id
.bus
, entry
->id
.device
,
142 ('A' + entry
->pin
), prt
->source
, entry
->link
.index
));
144 /* TBD: Acquire/release lock */
145 list_add_tail(&entry
->node
, &acpi_prt
.entries
);
153 acpi_pci_irq_add_prt (
158 acpi_status status
= AE_OK
;
159 char pathname
[ACPI_PATHNAME_MAX
] = {0};
160 struct acpi_buffer buffer
= {0, NULL
};
161 struct acpi_pci_routing_table
*prt
= NULL
;
162 struct acpi_pci_routing_table
*entry
= NULL
;
163 static int first_time
= 1;
165 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_prt");
169 INIT_LIST_HEAD(&acpi_prt
.entries
);
174 * NOTE: We're given a 'handle' to the _PRT object's parent device
175 * (either a PCI root bridge or PCI-PCI bridge).
178 buffer
.length
= sizeof(pathname
);
179 buffer
.pointer
= pathname
;
180 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
182 printk(KERN_DEBUG
"ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
186 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
190 buffer
.pointer
= NULL
;
191 status
= acpi_get_irq_routing_table(handle
, &buffer
);
192 if (status
!= AE_BUFFER_OVERFLOW
) {
193 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error evaluating _PRT [%s]\n",
194 acpi_format_exception(status
)));
195 return_VALUE(-ENODEV
);
198 prt
= kmalloc(buffer
.length
, GFP_KERNEL
);
200 return_VALUE(-ENOMEM
);
201 memset(prt
, 0, buffer
.length
);
202 buffer
.pointer
= prt
;
204 status
= acpi_get_irq_routing_table(handle
, &buffer
);
205 if (ACPI_FAILURE(status
)) {
206 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error evaluating _PRT [%s]\n",
207 acpi_format_exception(status
)));
208 kfree(buffer
.pointer
);
209 return_VALUE(-ENODEV
);
214 while (entry
&& (entry
->length
> 0)) {
215 acpi_pci_irq_add_entry(handle
, segment
, bus
, entry
);
216 entry
= (struct acpi_pci_routing_table
*)
217 ((unsigned long) entry
+ entry
->length
);
226 /* --------------------------------------------------------------------------
227 PCI Interrupt Routing Support
228 -------------------------------------------------------------------------- */
231 acpi_pci_irq_lookup (
236 int *active_high_low
)
238 struct acpi_prt_entry
*entry
= NULL
;
239 int segment
= pci_domain_nr(bus
);
240 int bus_nr
= bus
->number
;
243 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup");
245 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
246 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
247 segment
, bus_nr
, device
, ('A' + pin
)));
249 entry
= acpi_pci_irq_find_prt_entry(segment
, bus_nr
, device
, pin
);
251 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "PRT entry not found\n"));
255 if (entry
->link
.handle
) {
256 irq
= acpi_pci_link_get_irq(entry
->link
.handle
, entry
->link
.index
, edge_level
, active_high_low
);
258 ACPI_DEBUG_PRINT((ACPI_DB_WARN
, "Invalid IRQ link routing entry\n"));
262 irq
= entry
->link
.index
;
263 *edge_level
= ACPI_LEVEL_SENSITIVE
;
264 *active_high_low
= ACPI_ACTIVE_LOW
;
267 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found IRQ %d\n", irq
));
273 acpi_pci_irq_derive (
277 int *active_high_low
)
279 struct pci_dev
*bridge
= dev
;
283 ACPI_FUNCTION_TRACE("acpi_pci_irq_derive");
286 return_VALUE(-EINVAL
);
289 * Attempt to derive an IRQ for this device from a parent bridge's
290 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
292 while (!irq
&& bridge
->bus
->self
) {
293 pin
= (pin
+ PCI_SLOT(bridge
->devfn
)) % 4;
294 bridge
= bridge
->bus
->self
;
296 if ((bridge
->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS
) {
297 /* PC card has the same IRQ as its cardbridge */
298 pci_read_config_byte(bridge
, PCI_INTERRUPT_PIN
, &bridge_pin
);
300 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
301 "No interrupt pin configured for device %s\n", pci_name(bridge
)));
304 /* Pin is from 0 to 3 */
309 irq
= acpi_pci_irq_lookup(bridge
->bus
, PCI_SLOT(bridge
->devfn
),
310 pin
, edge_level
, active_high_low
);
314 ACPI_DEBUG_PRINT((ACPI_DB_WARN
, "Unable to derive IRQ for device %s\n", pci_name(dev
)));
318 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Derive IRQ %d for device %s from %s\n",
319 irq
, pci_name(dev
), pci_name(bridge
)));
326 acpi_pci_irq_enable (
331 int edge_level
= ACPI_LEVEL_SENSITIVE
;
332 int active_high_low
= ACPI_ACTIVE_LOW
;
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
, &edge_level
, &active_high_low
);
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
, &edge_level
, &active_high_low
);
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
"PCI interrupt %s[%c]: no GSI",
370 pci_name(dev
), ('A' + pin
));
371 /* Interrupt Line values above 0xF are forbidden */
372 if (dev
->irq
&& (dev
->irq
<= 0xF)) {
373 printk(" - using IRQ %d\n", dev
->irq
);
374 return_VALUE(dev
->irq
);
382 dev
->irq
= acpi_register_gsi(irq
, edge_level
, active_high_low
);
384 printk(KERN_INFO PREFIX
"PCI interrupt %s[%c] -> GSI %u "
385 "(%s, %s) -> IRQ %d\n",
386 pci_name(dev
), 'A' + pin
, irq
,
387 (edge_level
== ACPI_LEVEL_SENSITIVE
) ? "level" : "edge",
388 (active_high_low
== ACPI_ACTIVE_LOW
) ? "low" : "high",
391 return_VALUE(dev
->irq
);