blob: 6a9f3ddb322e2f11a23a0958b634989d8f699c56 [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
Bjorn Helgaas391df5d2008-03-11 13:45:15 -070028#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#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>
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define _COMPONENT ACPI_PCI_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050042ACPI_MODULE_NAME("pci_irq");
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Len Brown4be44fc2005-08-05 00:44:28 -040044static struct acpi_prt_list acpi_prt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static DEFINE_SPINLOCK(acpi_prt_lock);
46
47/* --------------------------------------------------------------------------
48 PCI IRQ Routing Table (PRT) Support
49 -------------------------------------------------------------------------- */
50
Len Brown4be44fc2005-08-05 00:44:28 -040051static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(int segment,
52 int bus,
53 int device, int pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Len Brown4be44fc2005-08-05 00:44:28 -040055 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 if (!acpi_prt.count)
Patrick Mocheld550d982006-06-27 00:41:40 -040058 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 /*
61 * Parse through all PRT entries looking for a match on the specified
62 * PCI device's segment, bus, device, and pin (don't care about func).
63 *
64 */
65 spin_lock(&acpi_prt_lock);
Matthias Kaehlcke1a3b77a2008-02-04 23:31:20 -080066 list_for_each_entry(entry, &acpi_prt.entries, node) {
Len Brown4be44fc2005-08-05 00:44:28 -040067 if ((segment == entry->id.segment)
68 && (bus == entry->id.bus)
69 && (device == entry->id.device)
70 && (pin == entry->pin)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 spin_unlock(&acpi_prt_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -040072 return entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 }
74 }
75
76 spin_unlock(&acpi_prt_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -040077 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
Bjorn Helgaas391df5d2008-03-11 13:45:15 -070080/* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
81static struct dmi_system_id medion_md9580[] = {
82 {
83 .ident = "Medion MD9580-F laptop",
84 .matches = {
85 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
86 DMI_MATCH(DMI_PRODUCT_NAME, "A555"),
87 },
88 },
89 { }
90};
91
92/* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
93static struct dmi_system_id dell_optiplex[] = {
94 {
95 .ident = "Dell Optiplex GX1",
96 .matches = {
97 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
98 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX1 600S+"),
99 },
100 },
101 { }
102};
103
104/* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */
105static struct dmi_system_id hp_t5710[] = {
106 {
107 .ident = "HP t5710",
108 .matches = {
109 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
110 DMI_MATCH(DMI_PRODUCT_NAME, "hp t5000 series"),
111 DMI_MATCH(DMI_BOARD_NAME, "098Ch"),
112 },
113 },
114 { }
115};
116
117struct prt_quirk {
118 struct dmi_system_id *system;
119 unsigned int segment;
120 unsigned int bus;
121 unsigned int device;
122 unsigned char pin;
123 char *source; /* according to BIOS */
124 char *actual_source;
125};
126
127/*
128 * These systems have incorrect _PRT entries. The BIOS claims the PCI
129 * interrupt at the listed segment/bus/device/pin is connected to the first
130 * link device, but it is actually connected to the second.
131 */
132static struct prt_quirk prt_quirks[] = {
133 { medion_md9580, 0, 0, 9, 'A',
Bjorn Helgaasb97d4802008-03-25 11:21:11 -0600134 "\\_SB_.PCI0.ISA_.LNKA",
135 "\\_SB_.PCI0.ISA_.LNKB"},
Bjorn Helgaas391df5d2008-03-11 13:45:15 -0700136 { dell_optiplex, 0, 0, 0xd, 'A',
137 "\\_SB_.LNKB",
138 "\\_SB_.LNKA"},
139 { hp_t5710, 0, 0, 1, 'A',
140 "\\_SB_.PCI0.LNK1",
141 "\\_SB_.PCI0.LNK3"},
142};
143
144static void
145do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt)
146{
147 int i;
148 struct prt_quirk *quirk;
149
150 for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) {
151 quirk = &prt_quirks[i];
152
153 /* All current quirks involve link devices, not GSIs */
154 if (!prt->source)
155 continue;
156
157 if (dmi_check_system(quirk->system) &&
158 entry->id.segment == quirk->segment &&
159 entry->id.bus == quirk->bus &&
160 entry->id.device == quirk->device &&
161 entry->pin + 'A' == quirk->pin &&
162 !strcmp(prt->source, quirk->source) &&
163 strlen(prt->source) >= strlen(quirk->actual_source)) {
164 printk(KERN_WARNING PREFIX "firmware reports "
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600165 "%04x:%02x:%02x PCI INT %c connected to %s; "
Bjorn Helgaas391df5d2008-03-11 13:45:15 -0700166 "changing to %s\n",
167 entry->id.segment, entry->id.bus,
168 entry->id.device, 'A' + entry->pin,
169 prt->source, quirk->actual_source);
170 strcpy(prt->source, quirk->actual_source);
171 }
172 }
173}
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175static int
Len Brown4be44fc2005-08-05 00:44:28 -0400176acpi_pci_irq_add_entry(acpi_handle handle,
177 int segment, int bus, struct acpi_pci_routing_table *prt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Len Brown4be44fc2005-08-05 00:44:28 -0400179 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Burman Yan36bcbec2006-12-19 12:56:11 -0800181 entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400183 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 entry->id.segment = segment;
186 entry->id.bus = bus;
187 entry->id.device = (prt->address >> 16) & 0xFFFF;
188 entry->id.function = prt->address & 0xFFFF;
189 entry->pin = prt->pin;
190
Bjorn Helgaas391df5d2008-03-11 13:45:15 -0700191 do_prt_fixups(entry, prt);
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 /*
194 * Type 1: Dynamic
195 * ---------------
196 * The 'source' field specifies the PCI interrupt link device used to
197 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
198 * indicates which resource descriptor in the resource template (of
199 * the link device) this interrupt is allocated from.
200 *
201 * NOTE: Don't query the Link Device for IRQ information at this time
202 * because Link Device enumeration may not have occurred yet
203 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
204 * namespace).
205 */
206 if (prt->source[0]) {
207 acpi_get_handle(handle, prt->source, &entry->link.handle);
208 entry->link.index = prt->source_index;
209 }
210 /*
211 * Type 2: Static
212 * --------------
213 * The 'source' field is NULL, and the 'source_index' field specifies
214 * the IRQ value, which is hardwired to specific interrupt inputs on
215 * the interrupt controller.
216 */
217 else
218 entry->link.index = prt->source_index;
219
220 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700221 " %04x:%02x:%02x[%c] -> %s[%d]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400222 entry->id.segment, entry->id.bus,
223 entry->id.device, ('A' + entry->pin), prt->source,
224 entry->link.index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 spin_lock(&acpi_prt_lock);
227 list_add_tail(&entry->node, &acpi_prt.entries);
228 acpi_prt.count++;
229 spin_unlock(&acpi_prt_lock);
230
Patrick Mocheld550d982006-06-27 00:41:40 -0400231 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234static void
Len Brown4be44fc2005-08-05 00:44:28 -0400235acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Len Brown4be44fc2005-08-05 00:44:28 -0400237 if (segment == entry->id.segment && bus == entry->id.bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 acpi_prt.count--;
239 list_del(&entry->node);
240 kfree(entry);
241 }
242}
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700246 acpi_status status;
247 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
248 struct acpi_pci_routing_table *entry;
Len Brown4be44fc2005-08-05 00:44:28 -0400249 static int first_time = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (first_time) {
252 acpi_prt.count = 0;
253 INIT_LIST_HEAD(&acpi_prt.entries);
254 first_time = 0;
255 }
256
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700257 /* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */
258 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
259 if (ACPI_FAILURE(status))
260 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700263 (char *) buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700265 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700267 buffer.length = ACPI_ALLOCATE_BUFFER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 buffer.pointer = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 status = acpi_get_irq_routing_table(handle, &buffer);
271 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400272 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
273 acpi_format_exception(status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -0400275 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
277
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700278 entry = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 while (entry && (entry->length > 0)) {
280 acpi_pci_irq_add_entry(handle, segment, bus, entry);
281 entry = (struct acpi_pci_routing_table *)
Len Brown4be44fc2005-08-05 00:44:28 -0400282 ((unsigned long)entry + entry->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700285 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -0400286 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
Len Brown4be44fc2005-08-05 00:44:28 -0400289void acpi_pci_irq_del_prt(int segment, int bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Len Brown4be44fc2005-08-05 00:44:28 -0400291 struct list_head *node = NULL, *n = NULL;
292 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 if (!acpi_prt.count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 return;
296 }
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 printk(KERN_DEBUG
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700299 "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n",
300 segment, bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 spin_lock(&acpi_prt_lock);
302 list_for_each_safe(node, n, &acpi_prt.entries) {
303 entry = list_entry(node, struct acpi_prt_entry, node);
304
305 acpi_pci_irq_del_entry(segment, bus, entry);
306 }
307 spin_unlock(&acpi_prt_lock);
308}
Len Brown4be44fc2005-08-05 00:44:28 -0400309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310/* --------------------------------------------------------------------------
311 PCI Interrupt Routing Support
312 -------------------------------------------------------------------------- */
Len Brown4be44fc2005-08-05 00:44:28 -0400313typedef int (*irq_lookup_func) (struct acpi_prt_entry *, int *, int *, char **);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
David Shaohua Li87bec662005-07-27 23:02:00 -0400315static int
316acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
Bob Moore50eca3e2005-09-30 19:03:00 -0400317 int *triggering, int *polarity, char **link)
David Shaohua Li87bec662005-07-27 23:02:00 -0400318{
Len Brown4be44fc2005-08-05 00:44:28 -0400319 int irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400320
David Shaohua Li87bec662005-07-27 23:02:00 -0400321
322 if (entry->link.handle) {
323 irq = acpi_pci_link_allocate_irq(entry->link.handle,
Bob Moore50eca3e2005-09-30 19:03:00 -0400324 entry->link.index, triggering,
325 polarity, link);
David Shaohua Li87bec662005-07-27 23:02:00 -0400326 if (irq < 0) {
Len Browncece9292006-06-26 23:04:31 -0400327 printk(KERN_WARNING PREFIX
328 "Invalid IRQ link routing entry\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400329 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400330 }
331 } else {
332 irq = entry->link.index;
Bob Moore50eca3e2005-09-30 19:03:00 -0400333 *triggering = ACPI_LEVEL_SENSITIVE;
334 *polarity = ACPI_ACTIVE_LOW;
David Shaohua Li87bec662005-07-27 23:02:00 -0400335 }
336
337 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq));
Patrick Mocheld550d982006-06-27 00:41:40 -0400338 return irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400339}
340
341static int
342acpi_pci_free_irq(struct acpi_prt_entry *entry,
Bob Moore50eca3e2005-09-30 19:03:00 -0400343 int *triggering, int *polarity, char **link)
David Shaohua Li87bec662005-07-27 23:02:00 -0400344{
Len Brown4be44fc2005-08-05 00:44:28 -0400345 int irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400346
David Shaohua Li87bec662005-07-27 23:02:00 -0400347 if (entry->link.handle) {
348 irq = acpi_pci_link_free_irq(entry->link.handle);
349 } else {
350 irq = entry->link.index;
351 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400352 return irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400353}
Len Brown4be44fc2005-08-05 00:44:28 -0400354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355/*
356 * acpi_pci_irq_lookup
357 * success: return IRQ >= 0
358 * failure: return -1
359 */
360static int
Len Brown4be44fc2005-08-05 00:44:28 -0400361acpi_pci_irq_lookup(struct pci_bus *bus,
362 int device,
363 int pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400364 int *triggering,
365 int *polarity, char **link, irq_lookup_func func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Len Brown4be44fc2005-08-05 00:44:28 -0400367 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 int segment = pci_domain_nr(bus);
369 int bus_nr = bus->number;
David Shaohua Li87bec662005-07-27 23:02:00 -0400370 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Len Brown4be44fc2005-08-05 00:44:28 -0400373 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700374 "Searching for _PRT entry for %04x:%02x:%02x[%c]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400375 segment, bus_nr, device, ('A' + pin)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Len Brown4be44fc2005-08-05 00:44:28 -0400377 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 if (!entry) {
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700379 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_PRT entry not found\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400380 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
Len Brown4be44fc2005-08-05 00:44:28 -0400382
Bob Moore50eca3e2005-09-30 19:03:00 -0400383 ret = func(entry, triggering, polarity, link);
Patrick Mocheld550d982006-06-27 00:41:40 -0400384 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
387/*
388 * acpi_pci_irq_derive
389 * success: return IRQ >= 0
390 * failure: return < 0
391 */
392static int
Len Brown4be44fc2005-08-05 00:44:28 -0400393acpi_pci_irq_derive(struct pci_dev *dev,
394 int pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400395 int *triggering,
396 int *polarity, char **link, irq_lookup_func func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Len Brown4be44fc2005-08-05 00:44:28 -0400398 struct pci_dev *bridge = dev;
399 int irq = -1;
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600400 u8 bridge_pin = 0, orig_pin = pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 /*
404 * Attempt to derive an IRQ for this device from a parent bridge's
405 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
406 */
407 while (irq < 0 && bridge->bus->self) {
408 pin = (pin + PCI_SLOT(bridge->devfn)) % 4;
409 bridge = bridge->bus->self;
410
411 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
412 /* PC card has the same IRQ as its cardbridge */
Kristen Accardi8015a012005-11-02 16:24:35 -0800413 bridge_pin = bridge->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 if (!bridge_pin) {
Len Brown4be44fc2005-08-05 00:44:28 -0400415 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
416 "No interrupt pin configured for device %s\n",
417 pci_name(bridge)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400418 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420 /* Pin is from 0 to 3 */
Len Brown4be44fc2005-08-05 00:44:28 -0400421 bridge_pin--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 pin = bridge_pin;
423 }
424
425 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn),
Bob Moore50eca3e2005-09-30 19:03:00 -0400426 pin, triggering, polarity,
Len Brown4be44fc2005-08-05 00:44:28 -0400427 link, func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429
430 if (irq < 0) {
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600431 dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n",
432 'A' + orig_pin);
Patrick Mocheld550d982006-06-27 00:41:40 -0400433 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 }
435
436 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400437 irq, pci_name(dev), pci_name(bridge)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Patrick Mocheld550d982006-06-27 00:41:40 -0400439 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442/*
443 * acpi_pci_irq_enable
444 * success: return 0
445 * failure: return < 0
446 */
447
Len Brown4be44fc2005-08-05 00:44:28 -0400448int acpi_pci_irq_enable(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Len Brown4be44fc2005-08-05 00:44:28 -0400450 int irq = 0;
451 u8 pin = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400452 int triggering = ACPI_LEVEL_SENSITIVE;
453 int polarity = ACPI_ACTIVE_LOW;
Len Brown4be44fc2005-08-05 00:44:28 -0400454 char *link = NULL;
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600455 char link_desc[16];
Len Brown4be44fc2005-08-05 00:44:28 -0400456 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Kristen Accardi8015a012005-11-02 16:24:35 -0800459 pin = dev->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 if (!pin) {
Len Brown4be44fc2005-08-05 00:44:28 -0400461 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
462 "No interrupt pin configured for device %s\n",
463 pci_name(dev)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400464 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
466 pin--;
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 /*
469 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
470 * values override any BIOS-assigned IRQs set during boot.
471 */
Len Brown4be44fc2005-08-05 00:44:28 -0400472 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400473 &triggering, &polarity, &link,
Len Brown4be44fc2005-08-05 00:44:28 -0400474 acpi_pci_allocate_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 /*
477 * If no PRT entry was found, we'll try to derive an IRQ from the
478 * device's parent bridge.
479 */
480 if (irq < 0)
Bob Moore50eca3e2005-09-30 19:03:00 -0400481 irq = acpi_pci_irq_derive(dev, pin, &triggering,
482 &polarity, &link,
Len Brown4be44fc2005-08-05 00:44:28 -0400483 acpi_pci_allocate_irq);
484
Alan Cox96c2a872008-01-10 22:49:58 -0500485 if (irq < 0) {
486 /*
487 * IDE legacy mode controller IRQs are magic. Why do compat
488 * extensions always make such a nasty mess.
489 */
490 if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
491 (dev->class & 0x05) == 0)
492 return 0;
493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 /*
495 * No IRQ known to the ACPI subsystem - maybe the BIOS /
496 * driver reported one, then use it. Exit in any case.
497 */
498 if (irq < 0) {
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600499 dev_warn(&dev->dev, "PCI INT %c: no GSI", 'A' + pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /* Interrupt Line values above 0xF are forbidden */
Linus Torvalds44f8e1a2005-07-02 10:35:33 -0700501 if (dev->irq > 0 && (dev->irq <= 0xF)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 printk(" - using IRQ %d\n", dev->irq);
Len Brown4be44fc2005-08-05 00:44:28 -0400503 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE,
504 ACPI_ACTIVE_LOW);
Patrick Mocheld550d982006-06-27 00:41:40 -0400505 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400506 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 printk("\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400508 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
Len Brown4be44fc2005-08-05 00:44:28 -0400510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Bob Moore50eca3e2005-09-30 19:03:00 -0400512 rc = acpi_register_gsi(irq, triggering, polarity);
Kenji Kaneshige349f0d52005-07-28 14:42:00 -0400513 if (rc < 0) {
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600514 dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n",
515 'A' + pin);
Patrick Mocheld550d982006-06-27 00:41:40 -0400516 return rc;
Kenji Kaneshige349f0d52005-07-28 14:42:00 -0400517 }
518 dev->irq = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (link)
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600521 snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link);
522 else
523 link_desc[0] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600525 dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n",
526 'A' + pin, link_desc, irq,
527 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
528 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Patrick Mocheld550d982006-06-27 00:41:40 -0400530 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}
Len Brown4be44fc2005-08-05 00:44:28 -0400532
David Shaohua Li87bec662005-07-27 23:02:00 -0400533/* FIXME: implement x86/x86_64 version */
Len Brown4be44fc2005-08-05 00:44:28 -0400534void __attribute__ ((weak)) acpi_unregister_gsi(u32 i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535{
Len Brown4be44fc2005-08-05 00:44:28 -0400536}
537
538void acpi_pci_irq_disable(struct pci_dev *dev)
539{
540 int gsi = 0;
541 u8 pin = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400542 int triggering = ACPI_LEVEL_SENSITIVE;
543 int polarity = ACPI_ACTIVE_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Kristen Accardi8015a012005-11-02 16:24:35 -0800546 pin = dev->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 if (!pin)
Patrick Mocheld550d982006-06-27 00:41:40 -0400548 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 pin--;
550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 /*
552 * First we check the PCI IRQ routing table (PRT) for an IRQ.
553 */
Len Brown4be44fc2005-08-05 00:44:28 -0400554 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400555 &triggering, &polarity, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400556 acpi_pci_free_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 /*
558 * If no PRT entry was found, we'll try to derive an IRQ from the
559 * device's parent bridge.
560 */
561 if (gsi < 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400562 gsi = acpi_pci_irq_derive(dev, pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400563 &triggering, &polarity, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400564 acpi_pci_free_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 if (gsi < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400566 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 /*
569 * TBD: It might be worth clearing dev->irq by magic constant
570 * (e.g. PCI_UNDEFINED_IRQ).
571 */
572
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600573 dev_info(&dev->dev, "PCI INT %c disabled\n", 'A' + pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 acpi_unregister_gsi(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}