initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / pci_irq.c
blob23e99452233485d677a7874fef3d2041d5060c06
1 /*
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>
35 #include <linux/pm.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 (
54 int segment,
55 int bus,
56 int device,
57 int pin)
59 struct list_head *node = NULL;
60 struct acpi_prt_entry *entry = NULL;
62 ACPI_FUNCTION_TRACE("acpi_pci_irq_find_prt_entry");
64 if (!acpi_prt.count)
65 return_PTR(NULL);
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)) {
79 return_PTR(entry);
83 return_PTR(NULL);
87 static int
88 acpi_pci_irq_add_entry (
89 acpi_handle handle,
90 int segment,
91 int bus,
92 struct acpi_pci_routing_table *prt)
94 struct acpi_prt_entry *entry = NULL;
96 ACPI_FUNCTION_TRACE("acpi_pci_irq_add_entry");
98 if (!prt)
99 return_VALUE(-EINVAL);
101 entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
102 if (!entry)
103 return_VALUE(-ENOMEM);
104 memset(entry, 0, sizeof(struct acpi_prt_entry));
106 entry->id.segment = segment;
107 entry->id.bus = bus;
108 entry->id.device = (prt->address >> 16) & 0xFFFF;
109 entry->id.function = prt->address & 0xFFFF;
110 entry->pin = prt->pin;
113 * Type 1: Dynamic
114 * ---------------
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
123 * namespace).
125 if (prt->source[0]) {
126 acpi_get_handle(handle, prt->source, &entry->link.handle);
127 entry->link.index = prt->source_index;
130 * Type 2: Static
131 * --------------
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.
136 else
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);
146 acpi_prt.count++;
148 return_VALUE(0);
153 acpi_pci_irq_add_prt (
154 acpi_handle handle,
155 int segment,
156 int bus)
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");
167 if (first_time) {
168 acpi_prt.count = 0;
169 INIT_LIST_HEAD(&acpi_prt.entries);
170 first_time = 0;
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",
183 pathname);
186 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
189 buffer.length = 0;
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);
199 if (!prt)
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);
212 entry = prt;
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);
220 kfree(prt);
222 return_VALUE(0);
226 /* --------------------------------------------------------------------------
227 PCI Interrupt Routing Support
228 -------------------------------------------------------------------------- */
230 static int
231 acpi_pci_irq_lookup (
232 struct pci_bus *bus,
233 int device,
234 int pin,
235 int *edge_level,
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;
241 int irq;
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);
250 if (!entry) {
251 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n"));
252 return_VALUE(0);
255 if (entry->link.handle) {
256 irq = acpi_pci_link_get_irq(entry->link.handle, entry->link.index, edge_level, active_high_low);
257 if (!irq) {
258 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid IRQ link routing entry\n"));
259 return_VALUE(0);
261 } else {
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));
269 return_VALUE(irq);
272 static int
273 acpi_pci_irq_derive (
274 struct pci_dev *dev,
275 int pin,
276 int *edge_level,
277 int *active_high_low)
279 struct pci_dev *bridge = dev;
280 int irq = 0;
281 u8 bridge_pin = 0;
283 ACPI_FUNCTION_TRACE("acpi_pci_irq_derive");
285 if (!dev)
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);
299 if (!bridge_pin) {
300 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
301 "No interrupt pin configured for device %s\n", pci_name(bridge)));
302 return_VALUE(0);
304 /* Pin is from 0 to 3 */
305 bridge_pin --;
306 pin = bridge_pin;
309 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn),
310 pin, edge_level, active_high_low);
313 if (!irq) {
314 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to derive IRQ for device %s\n", pci_name(dev)));
315 return_VALUE(0);
318 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n",
319 irq, pci_name(dev), pci_name(bridge)));
321 return_VALUE(irq);
326 acpi_pci_irq_enable (
327 struct pci_dev *dev)
329 int irq = 0;
330 u8 pin = 0;
331 int edge_level = ACPI_LEVEL_SENSITIVE;
332 int active_high_low = ACPI_ACTIVE_LOW;
334 ACPI_FUNCTION_TRACE("acpi_pci_irq_enable");
336 if (!dev)
337 return_VALUE(-EINVAL);
339 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
340 if (!pin) {
341 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No interrupt pin configured for device %s\n", pci_name(dev)));
342 return_VALUE(0);
344 pin--;
346 if (!dev->bus) {
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.
361 if (!irq)
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.
368 if (!irq) {
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);
376 else {
377 printk("\n");
378 return_VALUE(0);
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",
389 dev->irq);
391 return_VALUE(dev->irq);