blob: ea003bab7ecd9f686687dd71bab91576750ec51f [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
Bjorn Helgaasf748baf2008-12-08 21:30:31 -070044struct acpi_prt_entry {
45 struct list_head node;
46 struct acpi_pci_id id;
47 u8 pin;
48 struct {
49 acpi_handle handle;
50 u32 index;
51 } link;
52 u32 irq;
53};
54
55struct acpi_prt_list {
56 int count;
57 struct list_head entries;
58};
59
Len Brown4be44fc2005-08-05 00:44:28 -040060static struct acpi_prt_list acpi_prt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static DEFINE_SPINLOCK(acpi_prt_lock);
62
63/* --------------------------------------------------------------------------
64 PCI IRQ Routing Table (PRT) Support
65 -------------------------------------------------------------------------- */
66
Len Brown4be44fc2005-08-05 00:44:28 -040067static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(int segment,
68 int bus,
69 int device, int pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Len Brown4be44fc2005-08-05 00:44:28 -040071 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (!acpi_prt.count)
Patrick Mocheld550d982006-06-27 00:41:40 -040074 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 /*
77 * Parse through all PRT entries looking for a match on the specified
78 * PCI device's segment, bus, device, and pin (don't care about func).
79 *
80 */
81 spin_lock(&acpi_prt_lock);
Matthias Kaehlcke1a3b77a2008-02-04 23:31:20 -080082 list_for_each_entry(entry, &acpi_prt.entries, node) {
Len Brown4be44fc2005-08-05 00:44:28 -040083 if ((segment == entry->id.segment)
84 && (bus == entry->id.bus)
85 && (device == entry->id.device)
86 && (pin == entry->pin)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 spin_unlock(&acpi_prt_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -040088 return entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90 }
91
92 spin_unlock(&acpi_prt_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -040093 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
Bjorn Helgaas391df5d2008-03-11 13:45:15 -070096/* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */
97static struct dmi_system_id medion_md9580[] = {
98 {
99 .ident = "Medion MD9580-F laptop",
100 .matches = {
101 DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"),
102 DMI_MATCH(DMI_PRODUCT_NAME, "A555"),
103 },
104 },
105 { }
106};
107
108/* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */
109static struct dmi_system_id dell_optiplex[] = {
110 {
111 .ident = "Dell Optiplex GX1",
112 .matches = {
113 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
114 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX1 600S+"),
115 },
116 },
117 { }
118};
119
120/* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */
121static struct dmi_system_id hp_t5710[] = {
122 {
123 .ident = "HP t5710",
124 .matches = {
125 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
126 DMI_MATCH(DMI_PRODUCT_NAME, "hp t5000 series"),
127 DMI_MATCH(DMI_BOARD_NAME, "098Ch"),
128 },
129 },
130 { }
131};
132
133struct prt_quirk {
134 struct dmi_system_id *system;
135 unsigned int segment;
136 unsigned int bus;
137 unsigned int device;
138 unsigned char pin;
139 char *source; /* according to BIOS */
140 char *actual_source;
141};
142
143/*
144 * These systems have incorrect _PRT entries. The BIOS claims the PCI
145 * interrupt at the listed segment/bus/device/pin is connected to the first
146 * link device, but it is actually connected to the second.
147 */
148static struct prt_quirk prt_quirks[] = {
149 { medion_md9580, 0, 0, 9, 'A',
Bjorn Helgaasb97d4802008-03-25 11:21:11 -0600150 "\\_SB_.PCI0.ISA_.LNKA",
151 "\\_SB_.PCI0.ISA_.LNKB"},
Bjorn Helgaas391df5d2008-03-11 13:45:15 -0700152 { dell_optiplex, 0, 0, 0xd, 'A',
153 "\\_SB_.LNKB",
154 "\\_SB_.LNKA"},
155 { hp_t5710, 0, 0, 1, 'A',
156 "\\_SB_.PCI0.LNK1",
157 "\\_SB_.PCI0.LNK3"},
158};
159
160static void
161do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt)
162{
163 int i;
164 struct prt_quirk *quirk;
165
166 for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) {
167 quirk = &prt_quirks[i];
168
169 /* All current quirks involve link devices, not GSIs */
170 if (!prt->source)
171 continue;
172
173 if (dmi_check_system(quirk->system) &&
174 entry->id.segment == quirk->segment &&
175 entry->id.bus == quirk->bus &&
176 entry->id.device == quirk->device &&
177 entry->pin + 'A' == quirk->pin &&
178 !strcmp(prt->source, quirk->source) &&
179 strlen(prt->source) >= strlen(quirk->actual_source)) {
180 printk(KERN_WARNING PREFIX "firmware reports "
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600181 "%04x:%02x:%02x PCI INT %c connected to %s; "
Bjorn Helgaas391df5d2008-03-11 13:45:15 -0700182 "changing to %s\n",
183 entry->id.segment, entry->id.bus,
184 entry->id.device, 'A' + entry->pin,
185 prt->source, quirk->actual_source);
186 strcpy(prt->source, quirk->actual_source);
187 }
188 }
189}
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191static int
Len Brown4be44fc2005-08-05 00:44:28 -0400192acpi_pci_irq_add_entry(acpi_handle handle,
193 int segment, int bus, struct acpi_pci_routing_table *prt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Len Brown4be44fc2005-08-05 00:44:28 -0400195 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Burman Yan36bcbec2006-12-19 12:56:11 -0800197 entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400199 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 entry->id.segment = segment;
202 entry->id.bus = bus;
203 entry->id.device = (prt->address >> 16) & 0xFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 entry->pin = prt->pin;
205
Bjorn Helgaas391df5d2008-03-11 13:45:15 -0700206 do_prt_fixups(entry, prt);
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 /*
209 * Type 1: Dynamic
210 * ---------------
211 * The 'source' field specifies the PCI interrupt link device used to
212 * configure the IRQ assigned to this slot|dev|pin. The 'source_index'
213 * indicates which resource descriptor in the resource template (of
214 * the link device) this interrupt is allocated from.
215 *
216 * NOTE: Don't query the Link Device for IRQ information at this time
217 * because Link Device enumeration may not have occurred yet
218 * (e.g. exists somewhere 'below' this _PRT entry in the ACPI
219 * namespace).
220 */
221 if (prt->source[0]) {
222 acpi_get_handle(handle, prt->source, &entry->link.handle);
223 entry->link.index = prt->source_index;
224 }
225 /*
226 * Type 2: Static
227 * --------------
228 * The 'source' field is NULL, and the 'source_index' field specifies
229 * the IRQ value, which is hardwired to specific interrupt inputs on
230 * the interrupt controller.
231 */
232 else
233 entry->link.index = prt->source_index;
234
235 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700236 " %04x:%02x:%02x[%c] -> %s[%d]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400237 entry->id.segment, entry->id.bus,
238 entry->id.device, ('A' + entry->pin), prt->source,
239 entry->link.index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 spin_lock(&acpi_prt_lock);
242 list_add_tail(&entry->node, &acpi_prt.entries);
243 acpi_prt.count++;
244 spin_unlock(&acpi_prt_lock);
245
Patrick Mocheld550d982006-06-27 00:41:40 -0400246 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249static void
Len Brown4be44fc2005-08-05 00:44:28 -0400250acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Len Brown4be44fc2005-08-05 00:44:28 -0400252 if (segment == entry->id.segment && bus == entry->id.bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 acpi_prt.count--;
254 list_del(&entry->node);
255 kfree(entry);
256 }
257}
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700261 acpi_status status;
262 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
263 struct acpi_pci_routing_table *entry;
Len Brown4be44fc2005-08-05 00:44:28 -0400264 static int first_time = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 if (first_time) {
267 acpi_prt.count = 0;
268 INIT_LIST_HEAD(&acpi_prt.entries);
269 first_time = 0;
270 }
271
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700272 /* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */
273 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
274 if (ACPI_FAILURE(status))
275 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n",
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700278 (char *) buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700280 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700282 buffer.length = ACPI_ALLOCATE_BUFFER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 buffer.pointer = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 status = acpi_get_irq_routing_table(handle, &buffer);
286 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400287 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]",
288 acpi_format_exception(status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -0400290 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 }
292
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700293 entry = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 while (entry && (entry->length > 0)) {
295 acpi_pci_irq_add_entry(handle, segment, bus, entry);
296 entry = (struct acpi_pci_routing_table *)
Len Brown4be44fc2005-08-05 00:44:28 -0400297 ((unsigned long)entry + entry->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299
Bjorn Helgaas2320ac62008-12-08 21:30:15 -0700300 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -0400301 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
Len Brown4be44fc2005-08-05 00:44:28 -0400304void acpi_pci_irq_del_prt(int segment, int bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Len Brown4be44fc2005-08-05 00:44:28 -0400306 struct list_head *node = NULL, *n = NULL;
307 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Len Brown4be44fc2005-08-05 00:44:28 -0400309 if (!acpi_prt.count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return;
311 }
312
Len Brown4be44fc2005-08-05 00:44:28 -0400313 printk(KERN_DEBUG
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700314 "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n",
315 segment, bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 spin_lock(&acpi_prt_lock);
317 list_for_each_safe(node, n, &acpi_prt.entries) {
318 entry = list_entry(node, struct acpi_prt_entry, node);
319
320 acpi_pci_irq_del_entry(segment, bus, entry);
321 }
322 spin_unlock(&acpi_prt_lock);
323}
Len Brown4be44fc2005-08-05 00:44:28 -0400324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325/* --------------------------------------------------------------------------
326 PCI Interrupt Routing Support
327 -------------------------------------------------------------------------- */
Len Brown4be44fc2005-08-05 00:44:28 -0400328typedef int (*irq_lookup_func) (struct acpi_prt_entry *, int *, int *, char **);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
David Shaohua Li87bec662005-07-27 23:02:00 -0400330static int
331acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
Bob Moore50eca3e2005-09-30 19:03:00 -0400332 int *triggering, int *polarity, char **link)
David Shaohua Li87bec662005-07-27 23:02:00 -0400333{
Len Brown4be44fc2005-08-05 00:44:28 -0400334 int irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400335
David Shaohua Li87bec662005-07-27 23:02:00 -0400336
337 if (entry->link.handle) {
338 irq = acpi_pci_link_allocate_irq(entry->link.handle,
Bob Moore50eca3e2005-09-30 19:03:00 -0400339 entry->link.index, triggering,
340 polarity, link);
David Shaohua Li87bec662005-07-27 23:02:00 -0400341 if (irq < 0) {
Len Browncece9292006-06-26 23:04:31 -0400342 printk(KERN_WARNING PREFIX
343 "Invalid IRQ link routing entry\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400344 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400345 }
346 } else {
347 irq = entry->link.index;
Bob Moore50eca3e2005-09-30 19:03:00 -0400348 *triggering = ACPI_LEVEL_SENSITIVE;
349 *polarity = ACPI_ACTIVE_LOW;
David Shaohua Li87bec662005-07-27 23:02:00 -0400350 }
351
Bjorn Helgaasc13f8892008-12-08 21:30:26 -0700352 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found GSI %d\n", irq));
Patrick Mocheld550d982006-06-27 00:41:40 -0400353 return irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400354}
355
356static int
357acpi_pci_free_irq(struct acpi_prt_entry *entry,
Bob Moore50eca3e2005-09-30 19:03:00 -0400358 int *triggering, int *polarity, char **link)
David Shaohua Li87bec662005-07-27 23:02:00 -0400359{
Len Brown4be44fc2005-08-05 00:44:28 -0400360 int irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400361
David Shaohua Li87bec662005-07-27 23:02:00 -0400362 if (entry->link.handle) {
363 irq = acpi_pci_link_free_irq(entry->link.handle);
364 } else {
365 irq = entry->link.index;
366 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400367 return irq;
David Shaohua Li87bec662005-07-27 23:02:00 -0400368}
Len Brown4be44fc2005-08-05 00:44:28 -0400369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370/*
371 * acpi_pci_irq_lookup
372 * success: return IRQ >= 0
373 * failure: return -1
374 */
375static int
Len Brown4be44fc2005-08-05 00:44:28 -0400376acpi_pci_irq_lookup(struct pci_bus *bus,
377 int device,
378 int pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400379 int *triggering,
380 int *polarity, char **link, irq_lookup_func func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Len Brown4be44fc2005-08-05 00:44:28 -0400382 struct acpi_prt_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 int segment = pci_domain_nr(bus);
384 int bus_nr = bus->number;
David Shaohua Li87bec662005-07-27 23:02:00 -0400385 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700389 "Searching for _PRT entry for %04x:%02x:%02x[%c]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400390 segment, bus_nr, device, ('A' + pin)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Len Brown4be44fc2005-08-05 00:44:28 -0400392 entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (!entry) {
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700394 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_PRT entry not found\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400395 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
Len Brown4be44fc2005-08-05 00:44:28 -0400397
Bob Moore50eca3e2005-09-30 19:03:00 -0400398 ret = func(entry, triggering, polarity, link);
Patrick Mocheld550d982006-06-27 00:41:40 -0400399 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
402/*
403 * acpi_pci_irq_derive
404 * success: return IRQ >= 0
405 * failure: return < 0
406 */
407static int
Len Brown4be44fc2005-08-05 00:44:28 -0400408acpi_pci_irq_derive(struct pci_dev *dev,
409 int pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400410 int *triggering,
411 int *polarity, char **link, irq_lookup_func func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
Len Brown4be44fc2005-08-05 00:44:28 -0400413 struct pci_dev *bridge = dev;
414 int irq = -1;
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600415 u8 bridge_pin = 0, orig_pin = pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /*
419 * Attempt to derive an IRQ for this device from a parent bridge's
420 * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge).
421 */
422 while (irq < 0 && bridge->bus->self) {
423 pin = (pin + PCI_SLOT(bridge->devfn)) % 4;
424 bridge = bridge->bus->self;
425
426 if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) {
427 /* PC card has the same IRQ as its cardbridge */
Kristen Accardi8015a012005-11-02 16:24:35 -0800428 bridge_pin = bridge->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 if (!bridge_pin) {
Len Brown4be44fc2005-08-05 00:44:28 -0400430 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
431 "No interrupt pin configured for device %s\n",
432 pci_name(bridge)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400433 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 }
435 /* Pin is from 0 to 3 */
Len Brown4be44fc2005-08-05 00:44:28 -0400436 bridge_pin--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 pin = bridge_pin;
438 }
439
440 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn),
Bob Moore50eca3e2005-09-30 19:03:00 -0400441 pin, triggering, polarity,
Len Brown4be44fc2005-08-05 00:44:28 -0400442 link, func);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
444
445 if (irq < 0) {
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600446 dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n",
447 'A' + orig_pin);
Patrick Mocheld550d982006-06-27 00:41:40 -0400448 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450
Bjorn Helgaasc13f8892008-12-08 21:30:26 -0700451 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive GSI %d for device %s from %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400452 irq, pci_name(dev), pci_name(bridge)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Patrick Mocheld550d982006-06-27 00:41:40 -0400454 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
456
457/*
458 * acpi_pci_irq_enable
459 * success: return 0
460 * failure: return < 0
461 */
462
Len Brown4be44fc2005-08-05 00:44:28 -0400463int acpi_pci_irq_enable(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Bjorn Helgaasc13f8892008-12-08 21:30:26 -0700465 int gsi = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400466 u8 pin = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400467 int triggering = ACPI_LEVEL_SENSITIVE;
468 int polarity = ACPI_ACTIVE_LOW;
Len Brown4be44fc2005-08-05 00:44:28 -0400469 char *link = NULL;
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600470 char link_desc[16];
Len Brown4be44fc2005-08-05 00:44:28 -0400471 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Kristen Accardi8015a012005-11-02 16:24:35 -0800474 pin = dev->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 if (!pin) {
Len Brown4be44fc2005-08-05 00:44:28 -0400476 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
477 "No interrupt pin configured for device %s\n",
478 pci_name(dev)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400479 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
481 pin--;
482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 /*
484 * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT
485 * values override any BIOS-assigned IRQs set during boot.
486 */
Bjorn Helgaasc13f8892008-12-08 21:30:26 -0700487 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400488 &triggering, &polarity, &link,
Len Brown4be44fc2005-08-05 00:44:28 -0400489 acpi_pci_allocate_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 /*
492 * If no PRT entry was found, we'll try to derive an IRQ from the
493 * device's parent bridge.
494 */
Bjorn Helgaasc13f8892008-12-08 21:30:26 -0700495 if (gsi < 0)
496 gsi = acpi_pci_irq_derive(dev, pin, &triggering,
Bob Moore50eca3e2005-09-30 19:03:00 -0400497 &polarity, &link,
Len Brown4be44fc2005-08-05 00:44:28 -0400498 acpi_pci_allocate_irq);
499
Bjorn Helgaasc13f8892008-12-08 21:30:26 -0700500 if (gsi < 0) {
Alan Cox96c2a872008-01-10 22:49:58 -0500501 /*
502 * IDE legacy mode controller IRQs are magic. Why do compat
503 * extensions always make such a nasty mess.
504 */
505 if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE &&
506 (dev->class & 0x05) == 0)
507 return 0;
508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 /*
510 * No IRQ known to the ACPI subsystem - maybe the BIOS /
511 * driver reported one, then use it. Exit in any case.
512 */
Bjorn Helgaasc13f8892008-12-08 21:30:26 -0700513 if (gsi < 0) {
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600514 dev_warn(&dev->dev, "PCI INT %c: no GSI", 'A' + pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 /* Interrupt Line values above 0xF are forbidden */
Linus Torvalds44f8e1a2005-07-02 10:35:33 -0700516 if (dev->irq > 0 && (dev->irq <= 0xF)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 printk(" - using IRQ %d\n", dev->irq);
Len Brown4be44fc2005-08-05 00:44:28 -0400518 acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE,
519 ACPI_ACTIVE_LOW);
Patrick Mocheld550d982006-06-27 00:41:40 -0400520 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400521 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 printk("\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400523 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 }
Len Brown4be44fc2005-08-05 00:44:28 -0400525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Bjorn Helgaasc13f8892008-12-08 21:30:26 -0700527 rc = acpi_register_gsi(gsi, triggering, polarity);
Kenji Kaneshige349f0d52005-07-28 14:42:00 -0400528 if (rc < 0) {
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600529 dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n",
530 'A' + pin);
Patrick Mocheld550d982006-06-27 00:41:40 -0400531 return rc;
Kenji Kaneshige349f0d52005-07-28 14:42:00 -0400532 }
533 dev->irq = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 if (link)
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600536 snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link);
537 else
538 link_desc[0] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600540 dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n",
Bjorn Helgaasc13f8892008-12-08 21:30:26 -0700541 'A' + pin, link_desc, gsi,
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600542 (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge",
543 (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Patrick Mocheld550d982006-06-27 00:41:40 -0400545 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
Len Brown4be44fc2005-08-05 00:44:28 -0400547
David Shaohua Li87bec662005-07-27 23:02:00 -0400548/* FIXME: implement x86/x86_64 version */
Len Brown4be44fc2005-08-05 00:44:28 -0400549void __attribute__ ((weak)) acpi_unregister_gsi(u32 i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Len Brown4be44fc2005-08-05 00:44:28 -0400551}
552
553void acpi_pci_irq_disable(struct pci_dev *dev)
554{
555 int gsi = 0;
556 u8 pin = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400557 int triggering = ACPI_LEVEL_SENSITIVE;
558 int polarity = ACPI_ACTIVE_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Kristen Accardi8015a012005-11-02 16:24:35 -0800561 pin = dev->pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (!pin)
Patrick Mocheld550d982006-06-27 00:41:40 -0400563 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 pin--;
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 /*
567 * First we check the PCI IRQ routing table (PRT) for an IRQ.
568 */
Len Brown4be44fc2005-08-05 00:44:28 -0400569 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400570 &triggering, &polarity, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400571 acpi_pci_free_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 /*
573 * If no PRT entry was found, we'll try to derive an IRQ from the
574 * device's parent bridge.
575 */
576 if (gsi < 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400577 gsi = acpi_pci_irq_derive(dev, pin,
Bob Moore50eca3e2005-09-30 19:03:00 -0400578 &triggering, &polarity, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400579 acpi_pci_free_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 if (gsi < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400581 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 /*
584 * TBD: It might be worth clearing dev->irq by magic constant
585 * (e.g. PCI_UNDEFINED_IRQ).
586 */
587
Bjorn Helgaasc83642d2008-06-27 08:45:39 -0600588 dev_info(&dev->dev, "PCI INT %c disabled\n", 'A' + pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 acpi_unregister_gsi(gsi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}