blob: 76d9c669d2d8e4e7cc9662e3f3ea8c68148b059d [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 acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 if (!acpi_prt.count)
Patrick Mocheld550d982006-06-27 00:41:40 -040057 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 /*
60 * Parse through all PRT entries looking for a match on the specified
61 * PCI device's segment, bus, device, and pin (don't care about func).
62 *
63 */
64 spin_lock(&acpi_prt_lock);
Matthias Kaehlcke1a3b77a2008-02-04 23:31:20 -080065 list_for_each_entry(entry, &acpi_prt.entries, node) {
Len Brown4be44fc2005-08-05 00:44:28 -040066 if ((segment == entry->id.segment)
67 && (bus == entry->id.bus)
68 && (device == entry->id.device)
69 && (pin == entry->pin)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 spin_unlock(&acpi_prt_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -040071 return entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 }
73 }
74
75 spin_unlock(&acpi_prt_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -040076 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static int
Len Brown4be44fc2005-08-05 00:44:28 -040080acpi_pci_irq_add_entry(acpi_handle handle,
81 int segment, int bus, struct acpi_pci_routing_table *prt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Len Brown4be44fc2005-08-05 00:44:28 -040083 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 if (!prt)
Patrick Mocheld550d982006-06-27 00:41:40 -040087 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Burman Yan36bcbec2006-12-19 12:56:11 -080089 entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -040091 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 entry->id.segment = segment;
94 entry->id.bus = bus;
95 entry->id.device = (prt->address >> 16) & 0xFFFF;
96 entry->id.function = prt->address & 0xFFFF;
97 entry->pin = prt->pin;
98
99 /*
100 * Type 1: Dynamic
101 * ---------------
102 * The 'source' field specifies the PCI interrupt link device used to
103 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
104 * indicates which resource descriptor in the resource template (of
105 * the link device) this interrupt is allocated from.
106 *
107 * NOTE: Don't query the Link Device for IRQ information at this time
108 * because Link Device enumeration may not have occurred yet
109 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
110 * namespace).
111 */
112 if (prt->source[0]) {
113 acpi_get_handle(handle, prt->source, &entry->link.handle);
114 entry->link.index = prt->source_index;
115 }
116 /*
117 * Type 2: Static
118 * --------------
119 * The 'source' field is NULL, and the 'source_index' field specifies
120 * the IRQ value, which is hardwired to specific interrupt inputs on
121 * the interrupt controller.
122 */
123 else
124 entry->link.index = prt->source_index;
125
126 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400127 " %02X:%02X:%02X[%c] -> %s[%d]\n",
128 entry->id.segment, entry->id.bus,
129 entry->id.device, ('A' + entry->pin), prt->source,
130 entry->link.index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 spin_lock(&acpi_prt_lock);
133 list_add_tail(&entry->node, &acpi_prt.entries);
134 acpi_prt.count++;
135 spin_unlock(&acpi_prt_lock);
136
Patrick Mocheld550d982006-06-27 00:41:40 -0400137 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140static void
Len Brown4be44fc2005-08-05 00:44:28 -0400141acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Len Brown4be44fc2005-08-05 00:44:28 -0400143 if (segment == entry->id.segment && bus == entry->id.bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 acpi_prt.count--;
145 list_del(&entry->node);
146 kfree(entry);
147 }
148}
149
Len Brown4be44fc2005-08-05 00:44:28 -0400150int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Len Brown4be44fc2005-08-05 00:44:28 -0400152 acpi_status status = AE_OK;
153 char *pathname = NULL;
154 struct acpi_buffer buffer = { 0, NULL };
155 struct acpi_pci_routing_table *prt = NULL;
156 struct acpi_pci_routing_table *entry = NULL;
157 static int first_time = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Burman Yan36bcbec2006-12-19 12:56:11 -0800160 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
Len Brown4be44fc2005-08-05 00:44:28 -0400161 if (!pathname)
Patrick Mocheld550d982006-06-27 00:41:40 -0400162 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 if (first_time) {
165 acpi_prt.count = 0;
166 INIT_LIST_HEAD(&acpi_prt.entries);
167 first_time = 0;
168 }
169
170 /*
171 * NOTE: We're given a 'handle' to the _PRT object's parent device
172 * (either a PCI root bridge or PCI-PCI bridge).
173 */
174
175 buffer.length = ACPI_PATHNAME_MAX;
176 buffer.pointer = pathname;
177 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
178
179 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400180 pathname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 /*
183 * Evaluate this _PRT and add its entries to our global list (acpi_prt).
184 */
185
186 buffer.length = 0;
187 buffer.pointer = NULL;
188 kfree(pathname);
189 status = acpi_get_irq_routing_table(handle, &buffer);
190 if (status != AE_BUFFER_OVERFLOW) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400191 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
192 acpi_format_exception(status)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400193 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
195
Burman Yan36bcbec2006-12-19 12:56:11 -0800196 prt = kzalloc(buffer.length, GFP_KERNEL);
Len Brown4be44fc2005-08-05 00:44:28 -0400197 if (!prt) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400198 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 buffer.pointer = prt;
201
202 status = acpi_get_irq_routing_table(handle, &buffer);
203 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400204 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
205 acpi_format_exception(status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -0400207 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 }
209
210 entry = prt;
211
212 while (entry && (entry->length > 0)) {
213 acpi_pci_irq_add_entry(handle, segment, bus, entry);
214 entry = (struct acpi_pci_routing_table *)
Len Brown4be44fc2005-08-05 00:44:28 -0400215 ((unsigned long)entry + entry->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
217
218 kfree(prt);
219
Patrick Mocheld550d982006-06-27 00:41:40 -0400220 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
222
Len Brown4be44fc2005-08-05 00:44:28 -0400223void acpi_pci_irq_del_prt(int segment, int bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Len Brown4be44fc2005-08-05 00:44:28 -0400225 struct list_head *node = NULL, *n = NULL;
226 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Len Brown4be44fc2005-08-05 00:44:28 -0400228 if (!acpi_prt.count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 return;
230 }
231
Len Brown4be44fc2005-08-05 00:44:28 -0400232 printk(KERN_DEBUG
233 "ACPI: Delete PCI Interrupt Routing Table for %x:%x\n", segment,
234 bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 spin_lock(&acpi_prt_lock);
236 list_for_each_safe(node, n, &acpi_prt.entries) {
237 entry = list_entry(node, struct acpi_prt_entry, node);
238
239 acpi_pci_irq_del_entry(segment, bus, entry);
240 }
241 spin_unlock(&acpi_prt_lock);
242}
Len Brown4be44fc2005-08-05 00:44:28 -0400243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/* --------------------------------------------------------------------------
245 PCI Interrupt Routing Support
246 -------------------------------------------------------------------------- */
Len Brown4be44fc2005-08-05 00:44:28 -0400247typedef int (*irq_lookup_func) (struct acpi_prt_entry *, int *, int *, char **);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
David Shaohua Li87bec662005-07-27 23:02:00 -0400249static int
250acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
Bob Moore50eca3e2005-09-30 19:03:00 -0400251 int *triggering, int *polarity, char **link)
David Shaohua Li87bec662005-07-27 23:02:00 -0400252{
Len Brown4be44fc2005-08-05 00:44:28 -0400253 int irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400254
David Shaohua Li87bec662005-07-27 23:02:00 -0400255
256 if (entry->link.handle) {
257 irq = acpi_pci_link_allocate_irq(entry->link.handle,
Bob Moore50eca3e2005-09-30 19:03:00 -0400258 entry->link.index, triggering,
259 polarity, link);
David Shaohua Li87bec662005-07-27 23:02:00 -0400260 if (irq < 0) {
Len Browncece9292006-06-26 23:04:31 -0400261 printk(KERN_WARNING PREFIX
262 "Invalid IRQ link routing entry\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400263 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400264 }
265 } else {
266 irq = entry->link.index;
Bob Moore50eca3e2005-09-30 19:03:00 -0400267 *triggering = ACPI_LEVEL_SENSITIVE;
268 *polarity = ACPI_ACTIVE_LOW;
David Shaohua Li87bec662005-07-27 23:02:00 -0400269 }
270
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq));
Patrick Mocheld550d982006-06-27 00:41:40 -0400272 return irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400273}
274
275static int
276acpi_pci_free_irq(struct acpi_prt_entry *entry,
Bob Moore50eca3e2005-09-30 19:03:00 -0400277 int *triggering, int *polarity, char **link)
David Shaohua Li87bec662005-07-27 23:02:00 -0400278{
Len Brown4be44fc2005-08-05 00:44:28 -0400279 int irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400280
David Shaohua Li87bec662005-07-27 23:02:00 -0400281 if (entry->link.handle) {
282 irq = acpi_pci_link_free_irq(entry->link.handle);
283 } else {
284 irq = entry->link.index;
285 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400286 return irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400287}
Len Brown4be44fc2005-08-05 00:44:28 -0400288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289/*
290 * acpi_pci_irq_lookup
291 * success: return IRQ >= 0
292 * failure: return -1
293 */
294static int
Len Brown4be44fc2005-08-05 00:44:28 -0400295acpi_pci_irq_lookup(struct pci_bus *bus,
296 int device,
297 int pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400298 int *triggering,
299 int *polarity, char **link, irq_lookup_func func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Len Brown4be44fc2005-08-05 00:44:28 -0400301 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 int segment = pci_domain_nr(bus);
303 int bus_nr = bus->number;
David Shaohua Li87bec662005-07-27 23:02:00 -0400304 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Len Brown4be44fc2005-08-05 00:44:28 -0400307 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
308 "Searching for PRT entry for %02x:%02x:%02x[%c]\n",
309 segment, bus_nr, device, ('A' + pin)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Len Brown4be44fc2005-08-05 00:44:28 -0400311 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 if (!entry) {
313 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400314 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
Len Brown4be44fc2005-08-05 00:44:28 -0400316
Bob Moore50eca3e2005-09-30 19:03:00 -0400317 ret = func(entry, triggering, polarity, link);
Patrick Mocheld550d982006-06-27 00:41:40 -0400318 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
321/*
322 * acpi_pci_irq_derive
323 * success: return IRQ >= 0
324 * failure: return < 0
325 */
326static int
Len Brown4be44fc2005-08-05 00:44:28 -0400327acpi_pci_irq_derive(struct pci_dev *dev,
328 int pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400329 int *triggering,
330 int *polarity, char **link, irq_lookup_func func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Len Brown4be44fc2005-08-05 00:44:28 -0400332 struct pci_dev *bridge = dev;
333 int irq = -1;
334 u8 bridge_pin = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400338 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 /*
341 * Attempt to derive an IRQ for this device from a parent bridge's
342 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
343 */
344 while (irq < 0 && bridge->bus->self) {
345 pin = (pin + PCI_SLOT(bridge->devfn)) % 4;
346 bridge = bridge->bus->self;
347
348 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
349 /* PC card has the same IRQ as its cardbridge */
Kristen Accardi8015a012005-11-02 16:24:35 -0800350 bridge_pin = bridge->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 if (!bridge_pin) {
Len Brown4be44fc2005-08-05 00:44:28 -0400352 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
353 "No interrupt pin configured for device %s\n",
354 pci_name(bridge)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400355 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357 /* Pin is from 0 to 3 */
Len Brown4be44fc2005-08-05 00:44:28 -0400358 bridge_pin--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 pin = bridge_pin;
360 }
361
362 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn),
Bob Moore50eca3e2005-09-30 19:03:00 -0400363 pin, triggering, polarity,
Len Brown4be44fc2005-08-05 00:44:28 -0400364 link, func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366
367 if (irq < 0) {
Len Browncece9292006-06-26 23:04:31 -0400368 printk(KERN_WARNING PREFIX "Unable to derive IRQ for device %s\n",
369 pci_name(dev));
Patrick Mocheld550d982006-06-27 00:41:40 -0400370 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
372
373 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400374 irq, pci_name(dev), pci_name(bridge)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Patrick Mocheld550d982006-06-27 00:41:40 -0400376 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377}
378
379/*
380 * acpi_pci_irq_enable
381 * success: return 0
382 * failure: return < 0
383 */
384
Len Brown4be44fc2005-08-05 00:44:28 -0400385int acpi_pci_irq_enable(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Len Brown4be44fc2005-08-05 00:44:28 -0400387 int irq = 0;
388 u8 pin = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400389 int triggering = ACPI_LEVEL_SENSITIVE;
390 int polarity = ACPI_ACTIVE_LOW;
Len Brown4be44fc2005-08-05 00:44:28 -0400391 char *link = NULL;
392 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400396 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400397
Kristen Accardi8015a012005-11-02 16:24:35 -0800398 pin = dev->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (!pin) {
Len Brown4be44fc2005-08-05 00:44:28 -0400400 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
401 "No interrupt pin configured for device %s\n",
402 pci_name(dev)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400403 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405 pin--;
406
407 if (!dev->bus) {
Len Brown64684632006-06-26 23:41:38 -0400408 printk(KERN_ERR PREFIX "Invalid (NULL) 'bus' field\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400409 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
411
412 /*
413 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
414 * values override any BIOS-assigned IRQs set during boot.
415 */
Len Brown4be44fc2005-08-05 00:44:28 -0400416 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400417 &triggering, &polarity, &link,
Len Brown4be44fc2005-08-05 00:44:28 -0400418 acpi_pci_allocate_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 /*
421 * If no PRT entry was found, we'll try to derive an IRQ from the
422 * device's parent bridge.
423 */
424 if (irq < 0)
Bob Moore50eca3e2005-09-30 19:03:00 -0400425 irq = acpi_pci_irq_derive(dev, pin, &triggering,
426 &polarity, &link,
Len Brown4be44fc2005-08-05 00:44:28 -0400427 acpi_pci_allocate_irq);
428
Alan Cox96c2a872008-01-10 22:49:58 -0500429 if (irq < 0) {
430 /*
431 * IDE legacy mode controller IRQs are magic. Why do compat
432 * extensions always make such a nasty mess.
433 */
434 if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
435 (dev->class & 0x05) == 0)
436 return 0;
437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 /*
439 * No IRQ known to the ACPI subsystem - maybe the BIOS /
440 * driver reported one, then use it. Exit in any case.
441 */
442 if (irq < 0) {
443 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI",
Len Brown4be44fc2005-08-05 00:44:28 -0400444 pci_name(dev), ('A' + pin));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 /* Interrupt Line values above 0xF are forbidden */
Linus Torvalds44f8e1a2005-07-02 10:35:33 -0700446 if (dev->irq > 0 && (dev->irq <= 0xF)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 printk(" - using IRQ %d\n", dev->irq);
Len Brown4be44fc2005-08-05 00:44:28 -0400448 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE,
449 ACPI_ACTIVE_LOW);
Patrick Mocheld550d982006-06-27 00:41:40 -0400450 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400451 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 printk("\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400453 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
Len Brown4be44fc2005-08-05 00:44:28 -0400455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Bob Moore50eca3e2005-09-30 19:03:00 -0400457 rc = acpi_register_gsi(irq, triggering, polarity);
Kenji Kaneshige349f0d52005-07-28 14:42:00 -0400458 if (rc < 0) {
459 printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: failed "
460 "to register GSI\n", pci_name(dev), ('A' + pin));
Patrick Mocheld550d982006-06-27 00:41:40 -0400461 return rc;
Kenji Kaneshige349f0d52005-07-28 14:42:00 -0400462 }
463 dev->irq = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 printk(KERN_INFO PREFIX "PCI Interrupt %s[%c] -> ",
Len Brown4be44fc2005-08-05 00:44:28 -0400466 pci_name(dev), 'A' + pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 if (link)
469 printk("Link [%s] -> ", link);
470
471 printk("GSI %u (%s, %s) -> IRQ %d\n", irq,
Bob Moore50eca3e2005-09-30 19:03:00 -0400472 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
473 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Patrick Mocheld550d982006-06-27 00:41:40 -0400475 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476}
Len Brown4be44fc2005-08-05 00:44:28 -0400477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478EXPORT_SYMBOL(acpi_pci_irq_enable);
479
David Shaohua Li87bec662005-07-27 23:02:00 -0400480/* FIXME: implement x86/x86_64 version */
Len Brown4be44fc2005-08-05 00:44:28 -0400481void __attribute__ ((weak)) acpi_unregister_gsi(u32 i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Len Brown4be44fc2005-08-05 00:44:28 -0400483}
484
485void acpi_pci_irq_disable(struct pci_dev *dev)
486{
487 int gsi = 0;
488 u8 pin = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400489 int triggering = ACPI_LEVEL_SENSITIVE;
490 int polarity = ACPI_ACTIVE_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Kenji Kaneshige5f0110f2005-09-03 00:34:32 -0400493 if (!dev || !dev->bus)
Patrick Mocheld550d982006-06-27 00:41:40 -0400494 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Kristen Accardi8015a012005-11-02 16:24:35 -0800496 pin = dev->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (!pin)
Patrick Mocheld550d982006-06-27 00:41:40 -0400498 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 pin--;
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 /*
502 * First we check the PCI IRQ routing table (PRT) for an IRQ.
503 */
Len Brown4be44fc2005-08-05 00:44:28 -0400504 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400505 &triggering, &polarity, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400506 acpi_pci_free_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 /*
508 * If no PRT entry was found, we'll try to derive an IRQ from the
509 * device's parent bridge.
510 */
511 if (gsi < 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400512 gsi = acpi_pci_irq_derive(dev, pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400513 &triggering, &polarity, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400514 acpi_pci_free_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (gsi < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400516 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 /*
519 * TBD: It might be worth clearing dev->irq by magic constant
520 * (e.g. PCI_UNDEFINED_IRQ).
521 */
522
523 printk(KERN_INFO PREFIX "PCI interrupt for device %s disabled\n",
524 pci_name(dev));
525
526 acpi_unregister_gsi(gsi);
527
Patrick Mocheld550d982006-06-27 00:41:40 -0400528 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529}