blob: 62010c2481b3614b9b9ddd3e1cbbae2118f40fd7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * pci_irq.c - ACPI PCI Interrupt Routing ($Revision: 11 $)
3 *
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>
7 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
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.
14 *
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.
19 *
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.
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 */
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/types.h>
32#include <linux/proc_fs.h>
33#include <linux/spinlock.h>
34#include <linux/pm.h>
35#include <linux/pci.h>
36#include <linux/acpi.h>
37#include <acpi/acpi_bus.h>
38#include <acpi/acpi_drivers.h>
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define _COMPONENT ACPI_PCI_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050041ACPI_MODULE_NAME("pci_irq");
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Len Brown4be44fc2005-08-05 00:44:28 -040043static struct acpi_prt_list acpi_prt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static DEFINE_SPINLOCK(acpi_prt_lock);
45
46/* --------------------------------------------------------------------------
47 PCI IRQ Routing Table (PRT) Support
48 -------------------------------------------------------------------------- */
49
Len Brown4be44fc2005-08-05 00:44:28 -040050static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(int segment,
51 int bus,
52 int device, int pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Len Brown4be44fc2005-08-05 00:44:28 -040054 struct list_head *node = NULL;
55 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 if (!acpi_prt.count)
Patrick Mocheld550d982006-06-27 00:41:40 -040059 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 /*
62 * Parse through all PRT entries looking for a match on the specified
63 * PCI device's segment, bus, device, and pin (don't care about func).
64 *
65 */
66 spin_lock(&acpi_prt_lock);
67 list_for_each(node, &acpi_prt.entries) {
68 entry = list_entry(node, struct acpi_prt_entry, node);
Len Brown4be44fc2005-08-05 00:44:28 -040069 if ((segment == entry->id.segment)
70 && (bus == entry->id.bus)
71 && (device == entry->id.device)
72 && (pin == entry->pin)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 spin_unlock(&acpi_prt_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -040074 return entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
76 }
77
78 spin_unlock(&acpi_prt_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -040079 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static int
Len Brown4be44fc2005-08-05 00:44:28 -040083acpi_pci_irq_add_entry(acpi_handle handle,
84 int segment, int bus, struct acpi_pci_routing_table *prt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Len Brown4be44fc2005-08-05 00:44:28 -040086 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 if (!prt)
Patrick Mocheld550d982006-06-27 00:41:40 -040090 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Burman Yan36bcbec2006-12-19 12:56:11 -080092 entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -040094 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 entry->id.segment = segment;
97 entry->id.bus = bus;
98 entry->id.device = (prt->address >> 16) & 0xFFFF;
99 entry->id.function = prt->address & 0xFFFF;
100 entry->pin = prt->pin;
101
102 /*
103 * Type 1: Dynamic
104 * ---------------
105 * The 'source' field specifies the PCI interrupt link device used to
106 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
107 * indicates which resource descriptor in the resource template (of
108 * the link device) this interrupt is allocated from.
109 *
110 * NOTE: Don't query the Link Device for IRQ information at this time
111 * because Link Device enumeration may not have occurred yet
112 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
113 * namespace).
114 */
115 if (prt->source[0]) {
116 acpi_get_handle(handle, prt->source, &entry->link.handle);
117 entry->link.index = prt->source_index;
118 }
119 /*
120 * Type 2: Static
121 * --------------
122 * The 'source' field is NULL, and the 'source_index' field specifies
123 * the IRQ value, which is hardwired to specific interrupt inputs on
124 * the interrupt controller.
125 */
126 else
127 entry->link.index = prt->source_index;
128
129 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400130 " %02X:%02X:%02X[%c] -> %s[%d]\n",
131 entry->id.segment, entry->id.bus,
132 entry->id.device, ('A' + entry->pin), prt->source,
133 entry->link.index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 spin_lock(&acpi_prt_lock);
136 list_add_tail(&entry->node, &acpi_prt.entries);
137 acpi_prt.count++;
138 spin_unlock(&acpi_prt_lock);
139
Patrick Mocheld550d982006-06-27 00:41:40 -0400140 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static void
Len Brown4be44fc2005-08-05 00:44:28 -0400144acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Len Brown4be44fc2005-08-05 00:44:28 -0400146 if (segment == entry->id.segment && bus == entry->id.bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 acpi_prt.count--;
148 list_del(&entry->node);
149 kfree(entry);
150 }
151}
152
Len Brown4be44fc2005-08-05 00:44:28 -0400153int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Len Brown4be44fc2005-08-05 00:44:28 -0400155 acpi_status status = AE_OK;
156 char *pathname = NULL;
157 struct acpi_buffer buffer = { 0, NULL };
158 struct acpi_pci_routing_table *prt = NULL;
159 struct acpi_pci_routing_table *entry = NULL;
160 static int first_time = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Burman Yan36bcbec2006-12-19 12:56:11 -0800163 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
Len Brown4be44fc2005-08-05 00:44:28 -0400164 if (!pathname)
Patrick Mocheld550d982006-06-27 00:41:40 -0400165 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 if (first_time) {
168 acpi_prt.count = 0;
169 INIT_LIST_HEAD(&acpi_prt.entries);
170 first_time = 0;
171 }
172
173 /*
174 * NOTE: We're given a 'handle' to the _PRT object's parent device
175 * (either a PCI root bridge or PCI-PCI bridge).
176 */
177
178 buffer.length = ACPI_PATHNAME_MAX;
179 buffer.pointer = pathname;
180 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
181
182 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400183 pathname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 /*
186 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
187 */
188
189 buffer.length = 0;
190 buffer.pointer = NULL;
191 kfree(pathname);
192 status = acpi_get_irq_routing_table(handle, &buffer);
193 if (status != AE_BUFFER_OVERFLOW) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400194 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
195 acpi_format_exception(status)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400196 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198
Burman Yan36bcbec2006-12-19 12:56:11 -0800199 prt = kzalloc(buffer.length, GFP_KERNEL);
Len Brown4be44fc2005-08-05 00:44:28 -0400200 if (!prt) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400201 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 buffer.pointer = prt;
204
205 status = acpi_get_irq_routing_table(handle, &buffer);
206 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400207 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
208 acpi_format_exception(status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -0400210 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212
213 entry = prt;
214
215 while (entry && (entry->length > 0)) {
216 acpi_pci_irq_add_entry(handle, segment, bus, entry);
217 entry = (struct acpi_pci_routing_table *)
Len Brown4be44fc2005-08-05 00:44:28 -0400218 ((unsigned long)entry + entry->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
220
221 kfree(prt);
222
Patrick Mocheld550d982006-06-27 00:41:40 -0400223 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
Len Brown4be44fc2005-08-05 00:44:28 -0400226void acpi_pci_irq_del_prt(int segment, int bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Len Brown4be44fc2005-08-05 00:44:28 -0400228 struct list_head *node = NULL, *n = NULL;
229 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Len Brown4be44fc2005-08-05 00:44:28 -0400231 if (!acpi_prt.count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return;
233 }
234
Len Brown4be44fc2005-08-05 00:44:28 -0400235 printk(KERN_DEBUG
236 "ACPI: Delete PCI Interrupt Routing Table for %x:%x\n", segment,
237 bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 spin_lock(&acpi_prt_lock);
239 list_for_each_safe(node, n, &acpi_prt.entries) {
240 entry = list_entry(node, struct acpi_prt_entry, node);
241
242 acpi_pci_irq_del_entry(segment, bus, entry);
243 }
244 spin_unlock(&acpi_prt_lock);
245}
Len Brown4be44fc2005-08-05 00:44:28 -0400246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247/* --------------------------------------------------------------------------
248 PCI Interrupt Routing Support
249 -------------------------------------------------------------------------- */
Len Brown4be44fc2005-08-05 00:44:28 -0400250typedef int (*irq_lookup_func) (struct acpi_prt_entry *, int *, int *, char **);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
David Shaohua Li87bec662005-07-27 23:02:00 -0400252static int
253acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
Bob Moore50eca3e2005-09-30 19:03:00 -0400254 int *triggering, int *polarity, char **link)
David Shaohua Li87bec662005-07-27 23:02:00 -0400255{
Len Brown4be44fc2005-08-05 00:44:28 -0400256 int irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400257
David Shaohua Li87bec662005-07-27 23:02:00 -0400258
259 if (entry->link.handle) {
260 irq = acpi_pci_link_allocate_irq(entry->link.handle,
Bob Moore50eca3e2005-09-30 19:03:00 -0400261 entry->link.index, triggering,
262 polarity, link);
David Shaohua Li87bec662005-07-27 23:02:00 -0400263 if (irq < 0) {
Len Browncece9292006-06-26 23:04:31 -0400264 printk(KERN_WARNING PREFIX
265 "Invalid IRQ link routing entry\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400266 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400267 }
268 } else {
269 irq = entry->link.index;
Bob Moore50eca3e2005-09-30 19:03:00 -0400270 *triggering = ACPI_LEVEL_SENSITIVE;
271 *polarity = ACPI_ACTIVE_LOW;
David Shaohua Li87bec662005-07-27 23:02:00 -0400272 }
273
274 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq));
Patrick Mocheld550d982006-06-27 00:41:40 -0400275 return irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400276}
277
278static int
279acpi_pci_free_irq(struct acpi_prt_entry *entry,
Bob Moore50eca3e2005-09-30 19:03:00 -0400280 int *triggering, int *polarity, char **link)
David Shaohua Li87bec662005-07-27 23:02:00 -0400281{
Len Brown4be44fc2005-08-05 00:44:28 -0400282 int irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400283
David Shaohua Li87bec662005-07-27 23:02:00 -0400284 if (entry->link.handle) {
285 irq = acpi_pci_link_free_irq(entry->link.handle);
286 } else {
287 irq = entry->link.index;
288 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400289 return irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400290}
Len Brown4be44fc2005-08-05 00:44:28 -0400291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292/*
293 * acpi_pci_irq_lookup
294 * success: return IRQ >= 0
295 * failure: return -1
296 */
297static int
Len Brown4be44fc2005-08-05 00:44:28 -0400298acpi_pci_irq_lookup(struct pci_bus *bus,
299 int device,
300 int pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400301 int *triggering,
302 int *polarity, char **link, irq_lookup_func func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Len Brown4be44fc2005-08-05 00:44:28 -0400304 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 int segment = pci_domain_nr(bus);
306 int bus_nr = bus->number;
David Shaohua Li87bec662005-07-27 23:02:00 -0400307 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Len Brown4be44fc2005-08-05 00:44:28 -0400310 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
311 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
312 segment, bus_nr, device, ('A' + pin)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (!entry) {
316 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400317 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 }
Len Brown4be44fc2005-08-05 00:44:28 -0400319
Bob Moore50eca3e2005-09-30 19:03:00 -0400320 ret = func(entry, triggering, polarity, link);
Patrick Mocheld550d982006-06-27 00:41:40 -0400321 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
324/*
325 * acpi_pci_irq_derive
326 * success: return IRQ >= 0
327 * failure: return < 0
328 */
329static int
Len Brown4be44fc2005-08-05 00:44:28 -0400330acpi_pci_irq_derive(struct pci_dev *dev,
331 int pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400332 int *triggering,
333 int *polarity, char **link, irq_lookup_func func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Len Brown4be44fc2005-08-05 00:44:28 -0400335 struct pci_dev *bridge = dev;
336 int irq = -1;
337 u8 bridge_pin = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400341 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 /*
344 * Attempt to derive an IRQ for this device from a parent bridge's
345 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
346 */
347 while (irq < 0 && bridge->bus->self) {
348 pin = (pin + PCI_SLOT(bridge->devfn)) % 4;
349 bridge = bridge->bus->self;
350
351 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
352 /* PC card has the same IRQ as its cardbridge */
Kristen Accardi8015a012005-11-02 16:24:35 -0800353 bridge_pin = bridge->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (!bridge_pin) {
Len Brown4be44fc2005-08-05 00:44:28 -0400355 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
356 "No interrupt pin configured for device %s\n",
357 pci_name(bridge)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400358 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
360 /* Pin is from 0 to 3 */
Len Brown4be44fc2005-08-05 00:44:28 -0400361 bridge_pin--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 pin = bridge_pin;
363 }
364
365 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn),
Bob Moore50eca3e2005-09-30 19:03:00 -0400366 pin, triggering, polarity,
Len Brown4be44fc2005-08-05 00:44:28 -0400367 link, func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369
370 if (irq < 0) {
Len Browncece9292006-06-26 23:04:31 -0400371 printk(KERN_WARNING PREFIX "Unable to derive IRQ for device %s\n",
372 pci_name(dev));
Patrick Mocheld550d982006-06-27 00:41:40 -0400373 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 }
375
376 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400377 irq, pci_name(dev), pci_name(bridge)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Patrick Mocheld550d982006-06-27 00:41:40 -0400379 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
382/*
383 * acpi_pci_irq_enable
384 * success: return 0
385 * failure: return < 0
386 */
387
Len Brown4be44fc2005-08-05 00:44:28 -0400388int acpi_pci_irq_enable(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Len Brown4be44fc2005-08-05 00:44:28 -0400390 int irq = 0;
391 u8 pin = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400392 int triggering = ACPI_LEVEL_SENSITIVE;
393 int polarity = ACPI_ACTIVE_LOW;
Len Brown4be44fc2005-08-05 00:44:28 -0400394 char *link = NULL;
395 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400399 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400400
Kristen Accardi8015a012005-11-02 16:24:35 -0800401 pin = dev->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 if (!pin) {
Len Brown4be44fc2005-08-05 00:44:28 -0400403 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
404 "No interrupt pin configured for device %s\n",
405 pci_name(dev)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400406 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
408 pin--;
409
410 if (!dev->bus) {
Len Brown64684632006-06-26 23:41:38 -0400411 printk(KERN_ERR PREFIX "Invalid (NULL) 'bus' field\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400412 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
414
415 /*
416 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
417 * values override any BIOS-assigned IRQs set during boot.
418 */
Len Brown4be44fc2005-08-05 00:44:28 -0400419 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400420 &triggering, &polarity, &link,
Len Brown4be44fc2005-08-05 00:44:28 -0400421 acpi_pci_allocate_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 /*
424 * If no PRT entry was found, we'll try to derive an IRQ from the
425 * device's parent bridge.
426 */
427 if (irq < 0)
Bob Moore50eca3e2005-09-30 19:03:00 -0400428 irq = acpi_pci_irq_derive(dev, pin, &triggering,
429 &polarity, &link,
Len Brown4be44fc2005-08-05 00:44:28 -0400430 acpi_pci_allocate_irq);
431
Alan Cox96c2a872008-01-10 22:49:58 -0500432 if (irq < 0) {
433 /*
434 * IDE legacy mode controller IRQs are magic. Why do compat
435 * extensions always make such a nasty mess.
436 */
437 if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
438 (dev->class & 0x05) == 0)
439 return 0;
440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 /*
442 * No IRQ known to the ACPI subsystem - maybe the BIOS /
443 * driver reported one, then use it. Exit in any case.
444 */
445 if (irq < 0) {
446 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI",
Len Brown4be44fc2005-08-05 00:44:28 -0400447 pci_name(dev), ('A' + pin));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 /* Interrupt Line values above 0xF are forbidden */
Linus Torvalds44f8e1a2005-07-02 10:35:33 -0700449 if (dev->irq > 0 && (dev->irq <= 0xF)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 printk(" - using IRQ %d\n", dev->irq);
Len Brown4be44fc2005-08-05 00:44:28 -0400451 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE,
452 ACPI_ACTIVE_LOW);
Patrick Mocheld550d982006-06-27 00:41:40 -0400453 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400454 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 printk("\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400456 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
Len Brown4be44fc2005-08-05 00:44:28 -0400458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Bob Moore50eca3e2005-09-30 19:03:00 -0400460 rc = acpi_register_gsi(irq, triggering, polarity);
Kenji Kaneshige349f0d52005-07-28 14:42:00 -0400461 if (rc < 0) {
462 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: failed "
463 "to register GSI\n", pci_name(dev), ('A' + pin));
Patrick Mocheld550d982006-06-27 00:41:40 -0400464 return rc;
Kenji Kaneshige349f0d52005-07-28 14:42:00 -0400465 }
466 dev->irq = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 printk(KERN_INFO PREFIX "PCI Interrupt %s[%c] -> ",
Len Brown4be44fc2005-08-05 00:44:28 -0400469 pci_name(dev), 'A' + pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 if (link)
472 printk("Link [%s] -> ", link);
473
474 printk("GSI %u (%s, %s) -> IRQ %d\n", irq,
Bob Moore50eca3e2005-09-30 19:03:00 -0400475 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
476 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Patrick Mocheld550d982006-06-27 00:41:40 -0400478 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
Len Brown4be44fc2005-08-05 00:44:28 -0400480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481EXPORT_SYMBOL(acpi_pci_irq_enable);
482
David Shaohua Li87bec662005-07-27 23:02:00 -0400483/* FIXME: implement x86/x86_64 version */
Len Brown4be44fc2005-08-05 00:44:28 -0400484void __attribute__ ((weak)) acpi_unregister_gsi(u32 i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Len Brown4be44fc2005-08-05 00:44:28 -0400486}
487
488void acpi_pci_irq_disable(struct pci_dev *dev)
489{
490 int gsi = 0;
491 u8 pin = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400492 int triggering = ACPI_LEVEL_SENSITIVE;
493 int polarity = ACPI_ACTIVE_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Kenji Kaneshige5f0110f2005-09-03 00:34:32 -0400496 if (!dev || !dev->bus)
Patrick Mocheld550d982006-06-27 00:41:40 -0400497 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Kristen Accardi8015a012005-11-02 16:24:35 -0800499 pin = dev->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if (!pin)
Patrick Mocheld550d982006-06-27 00:41:40 -0400501 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 pin--;
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 /*
505 * First we check the PCI IRQ routing table (PRT) for an IRQ.
506 */
Len Brown4be44fc2005-08-05 00:44:28 -0400507 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400508 &triggering, &polarity, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400509 acpi_pci_free_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 /*
511 * If no PRT entry was found, we'll try to derive an IRQ from the
512 * device's parent bridge.
513 */
514 if (gsi < 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400515 gsi = acpi_pci_irq_derive(dev, pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400516 &triggering, &polarity, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400517 acpi_pci_free_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 if (gsi < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400519 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521 /*
522 * TBD: It might be worth clearing dev->irq by magic constant
523 * (e.g. PCI_UNDEFINED_IRQ).
524 */
525
526 printk(KERN_INFO PREFIX "PCI interrupt for device %s disabled\n",
527 pci_name(dev));
528
529 acpi_unregister_gsi(gsi);
530
Patrick Mocheld550d982006-06-27 00:41:40 -0400531 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}