Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | ||
1da177e4 | 27 | |
391df5dc | 28 | #include <linux/dmi.h> |
1da177e4 LT |
29 | #include <linux/kernel.h> |
30 | #include <linux/module.h> | |
31 | #include <linux/init.h> | |
32 | #include <linux/types.h> | |
33 | #include <linux/proc_fs.h> | |
34 | #include <linux/spinlock.h> | |
35 | #include <linux/pm.h> | |
36 | #include <linux/pci.h> | |
37 | #include <linux/acpi.h> | |
38 | #include <acpi/acpi_bus.h> | |
39 | #include <acpi/acpi_drivers.h> | |
40 | ||
1da177e4 | 41 | #define _COMPONENT ACPI_PCI_COMPONENT |
f52fd66d | 42 | ACPI_MODULE_NAME("pci_irq"); |
1da177e4 | 43 | |
4be44fcd | 44 | static struct acpi_prt_list acpi_prt; |
1da177e4 LT |
45 | static DEFINE_SPINLOCK(acpi_prt_lock); |
46 | ||
47 | /* -------------------------------------------------------------------------- | |
48 | PCI IRQ Routing Table (PRT) Support | |
49 | -------------------------------------------------------------------------- */ | |
50 | ||
4be44fcd LB |
51 | static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(int segment, |
52 | int bus, | |
53 | int device, int pin) | |
1da177e4 | 54 | { |
4be44fcd | 55 | struct acpi_prt_entry *entry = NULL; |
1da177e4 | 56 | |
1da177e4 | 57 | if (!acpi_prt.count) |
d550d98d | 58 | return NULL; |
1da177e4 LT |
59 | |
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); | |
1a3b77ae | 66 | list_for_each_entry(entry, &acpi_prt.entries, node) { |
4be44fcd LB |
67 | if ((segment == entry->id.segment) |
68 | && (bus == entry->id.bus) | |
69 | && (device == entry->id.device) | |
70 | && (pin == entry->pin)) { | |
1da177e4 | 71 | spin_unlock(&acpi_prt_lock); |
d550d98d | 72 | return entry; |
1da177e4 LT |
73 | } |
74 | } | |
75 | ||
76 | spin_unlock(&acpi_prt_lock); | |
d550d98d | 77 | return NULL; |
1da177e4 LT |
78 | } |
79 | ||
391df5dc BH |
80 | /* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */ |
81 | static 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 */ | |
93 | static 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 */ | |
105 | static 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 | ||
117 | struct 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 | */ | |
132 | static struct prt_quirk prt_quirks[] = { | |
133 | { medion_md9580, 0, 0, 9, 'A', | |
b97d4803 BH |
134 | "\\_SB_.PCI0.ISA_.LNKA", |
135 | "\\_SB_.PCI0.ISA_.LNKB"}, | |
391df5dc BH |
136 | { 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 | ||
144 | static void | |
145 | do_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 " | |
c83642d5 | 165 | "%04x:%02x:%02x PCI INT %c connected to %s; " |
391df5dc BH |
166 | "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 | ||
1da177e4 | 175 | static int |
4be44fcd LB |
176 | acpi_pci_irq_add_entry(acpi_handle handle, |
177 | int segment, int bus, struct acpi_pci_routing_table *prt) | |
1da177e4 | 178 | { |
4be44fcd | 179 | struct acpi_prt_entry *entry = NULL; |
1da177e4 | 180 | |
1da177e4 LT |
181 | |
182 | if (!prt) | |
d550d98d | 183 | return -EINVAL; |
1da177e4 | 184 | |
36bcbec7 | 185 | entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL); |
1da177e4 | 186 | if (!entry) |
d550d98d | 187 | return -ENOMEM; |
1da177e4 LT |
188 | |
189 | entry->id.segment = segment; | |
190 | entry->id.bus = bus; | |
191 | entry->id.device = (prt->address >> 16) & 0xFFFF; | |
192 | entry->id.function = prt->address & 0xFFFF; | |
193 | entry->pin = prt->pin; | |
194 | ||
391df5dc BH |
195 | do_prt_fixups(entry, prt); |
196 | ||
1da177e4 LT |
197 | /* |
198 | * Type 1: Dynamic | |
199 | * --------------- | |
200 | * The 'source' field specifies the PCI interrupt link device used to | |
201 | * configure the IRQ assigned to this slot|dev|pin. The 'source_index' | |
202 | * indicates which resource descriptor in the resource template (of | |
203 | * the link device) this interrupt is allocated from. | |
204 | * | |
205 | * NOTE: Don't query the Link Device for IRQ information at this time | |
206 | * because Link Device enumeration may not have occurred yet | |
207 | * (e.g. exists somewhere 'below' this _PRT entry in the ACPI | |
208 | * namespace). | |
209 | */ | |
210 | if (prt->source[0]) { | |
211 | acpi_get_handle(handle, prt->source, &entry->link.handle); | |
212 | entry->link.index = prt->source_index; | |
213 | } | |
214 | /* | |
215 | * Type 2: Static | |
216 | * -------------- | |
217 | * The 'source' field is NULL, and the 'source_index' field specifies | |
218 | * the IRQ value, which is hardwired to specific interrupt inputs on | |
219 | * the interrupt controller. | |
220 | */ | |
221 | else | |
222 | entry->link.index = prt->source_index; | |
223 | ||
224 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO, | |
4be44fcd LB |
225 | " %02X:%02X:%02X[%c] -> %s[%d]\n", |
226 | entry->id.segment, entry->id.bus, | |
227 | entry->id.device, ('A' + entry->pin), prt->source, | |
228 | entry->link.index)); | |
1da177e4 LT |
229 | |
230 | spin_lock(&acpi_prt_lock); | |
231 | list_add_tail(&entry->node, &acpi_prt.entries); | |
232 | acpi_prt.count++; | |
233 | spin_unlock(&acpi_prt_lock); | |
234 | ||
d550d98d | 235 | return 0; |
1da177e4 LT |
236 | } |
237 | ||
1da177e4 | 238 | static void |
4be44fcd | 239 | acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry) |
1da177e4 | 240 | { |
4be44fcd | 241 | if (segment == entry->id.segment && bus == entry->id.bus) { |
1da177e4 LT |
242 | acpi_prt.count--; |
243 | list_del(&entry->node); | |
244 | kfree(entry); | |
245 | } | |
246 | } | |
247 | ||
4be44fcd | 248 | int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus) |
1da177e4 | 249 | { |
4be44fcd LB |
250 | acpi_status status = AE_OK; |
251 | char *pathname = NULL; | |
252 | struct acpi_buffer buffer = { 0, NULL }; | |
253 | struct acpi_pci_routing_table *prt = NULL; | |
254 | struct acpi_pci_routing_table *entry = NULL; | |
255 | static int first_time = 1; | |
1da177e4 | 256 | |
1da177e4 | 257 | |
36bcbec7 | 258 | pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); |
4be44fcd | 259 | if (!pathname) |
d550d98d | 260 | return -ENOMEM; |
1da177e4 LT |
261 | |
262 | if (first_time) { | |
263 | acpi_prt.count = 0; | |
264 | INIT_LIST_HEAD(&acpi_prt.entries); | |
265 | first_time = 0; | |
266 | } | |
267 | ||
268 | /* | |
269 | * NOTE: We're given a 'handle' to the _PRT object's parent device | |
270 | * (either a PCI root bridge or PCI-PCI bridge). | |
271 | */ | |
272 | ||
273 | buffer.length = ACPI_PATHNAME_MAX; | |
274 | buffer.pointer = pathname; | |
275 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); | |
276 | ||
277 | printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n", | |
4be44fcd | 278 | pathname); |
1da177e4 LT |
279 | |
280 | /* | |
281 | * Evaluate this _PRT and add its entries to our global list (acpi_prt). | |
282 | */ | |
283 | ||
284 | buffer.length = 0; | |
285 | buffer.pointer = NULL; | |
286 | kfree(pathname); | |
287 | status = acpi_get_irq_routing_table(handle, &buffer); | |
288 | if (status != AE_BUFFER_OVERFLOW) { | |
a6fc6720 TR |
289 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]", |
290 | acpi_format_exception(status))); | |
d550d98d | 291 | return -ENODEV; |
1da177e4 LT |
292 | } |
293 | ||
36bcbec7 | 294 | prt = kzalloc(buffer.length, GFP_KERNEL); |
4be44fcd | 295 | if (!prt) { |
d550d98d | 296 | return -ENOMEM; |
1da177e4 | 297 | } |
1da177e4 LT |
298 | buffer.pointer = prt; |
299 | ||
300 | status = acpi_get_irq_routing_table(handle, &buffer); | |
301 | if (ACPI_FAILURE(status)) { | |
a6fc6720 TR |
302 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]", |
303 | acpi_format_exception(status))); | |
1da177e4 | 304 | kfree(buffer.pointer); |
d550d98d | 305 | return -ENODEV; |
1da177e4 LT |
306 | } |
307 | ||
308 | entry = prt; | |
309 | ||
310 | while (entry && (entry->length > 0)) { | |
311 | acpi_pci_irq_add_entry(handle, segment, bus, entry); | |
312 | entry = (struct acpi_pci_routing_table *) | |
4be44fcd | 313 | ((unsigned long)entry + entry->length); |
1da177e4 LT |
314 | } |
315 | ||
316 | kfree(prt); | |
317 | ||
d550d98d | 318 | return 0; |
1da177e4 LT |
319 | } |
320 | ||
4be44fcd | 321 | void acpi_pci_irq_del_prt(int segment, int bus) |
1da177e4 | 322 | { |
4be44fcd LB |
323 | struct list_head *node = NULL, *n = NULL; |
324 | struct acpi_prt_entry *entry = NULL; | |
1da177e4 | 325 | |
4be44fcd | 326 | if (!acpi_prt.count) { |
1da177e4 LT |
327 | return; |
328 | } | |
329 | ||
4be44fcd LB |
330 | printk(KERN_DEBUG |
331 | "ACPI: Delete PCI Interrupt Routing Table for %x:%x\n", segment, | |
332 | bus); | |
1da177e4 LT |
333 | spin_lock(&acpi_prt_lock); |
334 | list_for_each_safe(node, n, &acpi_prt.entries) { | |
335 | entry = list_entry(node, struct acpi_prt_entry, node); | |
336 | ||
337 | acpi_pci_irq_del_entry(segment, bus, entry); | |
338 | } | |
339 | spin_unlock(&acpi_prt_lock); | |
340 | } | |
4be44fcd | 341 | |
1da177e4 LT |
342 | /* -------------------------------------------------------------------------- |
343 | PCI Interrupt Routing Support | |
344 | -------------------------------------------------------------------------- */ | |
4be44fcd | 345 | typedef int (*irq_lookup_func) (struct acpi_prt_entry *, int *, int *, char **); |
1da177e4 | 346 | |
87bec66b DSL |
347 | static int |
348 | acpi_pci_allocate_irq(struct acpi_prt_entry *entry, | |
50eca3eb | 349 | int *triggering, int *polarity, char **link) |
87bec66b | 350 | { |
4be44fcd | 351 | int irq; |
87bec66b | 352 | |
87bec66b DSL |
353 | |
354 | if (entry->link.handle) { | |
355 | irq = acpi_pci_link_allocate_irq(entry->link.handle, | |
50eca3eb BM |
356 | entry->link.index, triggering, |
357 | polarity, link); | |
87bec66b | 358 | if (irq < 0) { |
cece9296 LB |
359 | printk(KERN_WARNING PREFIX |
360 | "Invalid IRQ link routing entry\n"); | |
d550d98d | 361 | return -1; |
87bec66b DSL |
362 | } |
363 | } else { | |
364 | irq = entry->link.index; | |
50eca3eb BM |
365 | *triggering = ACPI_LEVEL_SENSITIVE; |
366 | *polarity = ACPI_ACTIVE_LOW; | |
87bec66b DSL |
367 | } |
368 | ||
369 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq)); | |
d550d98d | 370 | return irq; |
87bec66b DSL |
371 | } |
372 | ||
373 | static int | |
374 | acpi_pci_free_irq(struct acpi_prt_entry *entry, | |
50eca3eb | 375 | int *triggering, int *polarity, char **link) |
87bec66b | 376 | { |
4be44fcd | 377 | int irq; |
87bec66b | 378 | |
87bec66b DSL |
379 | if (entry->link.handle) { |
380 | irq = acpi_pci_link_free_irq(entry->link.handle); | |
381 | } else { | |
382 | irq = entry->link.index; | |
383 | } | |
d550d98d | 384 | return irq; |
87bec66b | 385 | } |
4be44fcd | 386 | |
e1d3a908 SA |
387 | #ifdef CONFIG_X86_IO_APIC |
388 | extern int noioapicquirk; | |
389 | ||
390 | static int bridge_has_boot_interrupt_variant(struct pci_bus *bus) | |
391 | { | |
392 | struct pci_bus *bus_it; | |
393 | ||
394 | for (bus_it = bus ; bus_it ; bus_it = bus_it->parent) { | |
395 | if (!bus_it->self) | |
396 | return 0; | |
397 | ||
398 | printk(KERN_INFO "vendor=%04x device=%04x\n", bus_it->self->vendor, | |
399 | bus_it->self->device); | |
400 | ||
401 | if (bus_it->self->irq_reroute_variant) | |
402 | return bus_it->self->irq_reroute_variant; | |
403 | } | |
404 | return 0; | |
405 | } | |
406 | #endif /* CONFIG_X86_IO_APIC */ | |
407 | ||
1da177e4 LT |
408 | /* |
409 | * acpi_pci_irq_lookup | |
410 | * success: return IRQ >= 0 | |
411 | * failure: return -1 | |
412 | */ | |
413 | static int | |
4be44fcd LB |
414 | acpi_pci_irq_lookup(struct pci_bus *bus, |
415 | int device, | |
416 | int pin, | |
50eca3eb BM |
417 | int *triggering, |
418 | int *polarity, char **link, irq_lookup_func func) | |
1da177e4 | 419 | { |
4be44fcd | 420 | struct acpi_prt_entry *entry = NULL; |
1da177e4 LT |
421 | int segment = pci_domain_nr(bus); |
422 | int bus_nr = bus->number; | |
87bec66b | 423 | int ret; |
1da177e4 | 424 | |
1da177e4 | 425 | |
4be44fcd LB |
426 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
427 | "Searching for PRT entry for %02x:%02x:%02x[%c]\n", | |
428 | segment, bus_nr, device, ('A' + pin))); | |
1da177e4 | 429 | |
4be44fcd | 430 | entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin); |
1da177e4 LT |
431 | if (!entry) { |
432 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n")); | |
d550d98d | 433 | return -1; |
1da177e4 | 434 | } |
4be44fcd | 435 | |
50eca3eb | 436 | ret = func(entry, triggering, polarity, link); |
e1d3a908 SA |
437 | |
438 | #ifdef CONFIG_X86_IO_APIC | |
439 | /* | |
440 | * Some chipsets (e.g. intel 6700PXH) generate a legacy INTx when the | |
441 | * IRQ entry in the chipset's IO-APIC is masked (as, e.g. the RT kernel | |
442 | * does during interrupt handling). When this INTx generation cannot be | |
443 | * disabled, we reroute these interrupts to their legacy equivalent to | |
444 | * get rid of spurious interrupts. | |
445 | */ | |
446 | if (!noioapicquirk) { | |
447 | switch (bridge_has_boot_interrupt_variant(bus)) { | |
448 | case 0: | |
449 | /* no rerouting necessary */ | |
450 | break; | |
451 | ||
452 | case INTEL_IRQ_REROUTE_VARIANT: | |
453 | /* | |
454 | * Remap according to INTx routing table in 6700PXH | |
455 | * specs, intel order number 302628-002, section | |
456 | * 2.15.2. Other chipsets (80332, ...) have the same | |
457 | * mapping and are handled here as well. | |
458 | */ | |
459 | printk(KERN_INFO "pci irq %d -> rerouted to legacy " | |
460 | "irq %d\n", ret, (ret % 4) + 16); | |
461 | ret = (ret % 4) + 16; | |
462 | break; | |
463 | ||
464 | default: | |
465 | printk(KERN_INFO "not rerouting irq %d to legacy irq: " | |
466 | "unknown mapping\n", ret); | |
467 | break; | |
468 | } | |
469 | } | |
470 | #endif /* CONFIG_X86_IO_APIC */ | |
471 | ||
d550d98d | 472 | return ret; |
1da177e4 LT |
473 | } |
474 | ||
475 | /* | |
476 | * acpi_pci_irq_derive | |
477 | * success: return IRQ >= 0 | |
478 | * failure: return < 0 | |
479 | */ | |
480 | static int | |
4be44fcd LB |
481 | acpi_pci_irq_derive(struct pci_dev *dev, |
482 | int pin, | |
50eca3eb BM |
483 | int *triggering, |
484 | int *polarity, char **link, irq_lookup_func func) | |
1da177e4 | 485 | { |
4be44fcd LB |
486 | struct pci_dev *bridge = dev; |
487 | int irq = -1; | |
c83642d5 | 488 | u8 bridge_pin = 0, orig_pin = pin; |
1da177e4 | 489 | |
1da177e4 LT |
490 | |
491 | if (!dev) | |
d550d98d | 492 | return -EINVAL; |
1da177e4 LT |
493 | |
494 | /* | |
495 | * Attempt to derive an IRQ for this device from a parent bridge's | |
496 | * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge). | |
497 | */ | |
498 | while (irq < 0 && bridge->bus->self) { | |
499 | pin = (pin + PCI_SLOT(bridge->devfn)) % 4; | |
500 | bridge = bridge->bus->self; | |
501 | ||
502 | if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) { | |
503 | /* PC card has the same IRQ as its cardbridge */ | |
8015a014 | 504 | bridge_pin = bridge->pin; |
1da177e4 | 505 | if (!bridge_pin) { |
4be44fcd LB |
506 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
507 | "No interrupt pin configured for device %s\n", | |
508 | pci_name(bridge))); | |
d550d98d | 509 | return -1; |
1da177e4 LT |
510 | } |
511 | /* Pin is from 0 to 3 */ | |
4be44fcd | 512 | bridge_pin--; |
1da177e4 LT |
513 | pin = bridge_pin; |
514 | } | |
515 | ||
516 | irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn), | |
50eca3eb | 517 | pin, triggering, polarity, |
4be44fcd | 518 | link, func); |
1da177e4 LT |
519 | } |
520 | ||
521 | if (irq < 0) { | |
c83642d5 BH |
522 | dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n", |
523 | 'A' + orig_pin); | |
d550d98d | 524 | return -1; |
1da177e4 LT |
525 | } |
526 | ||
527 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n", | |
4be44fcd | 528 | irq, pci_name(dev), pci_name(bridge))); |
1da177e4 | 529 | |
d550d98d | 530 | return irq; |
1da177e4 LT |
531 | } |
532 | ||
533 | /* | |
534 | * acpi_pci_irq_enable | |
535 | * success: return 0 | |
536 | * failure: return < 0 | |
537 | */ | |
538 | ||
4be44fcd | 539 | int acpi_pci_irq_enable(struct pci_dev *dev) |
1da177e4 | 540 | { |
4be44fcd LB |
541 | int irq = 0; |
542 | u8 pin = 0; | |
50eca3eb BM |
543 | int triggering = ACPI_LEVEL_SENSITIVE; |
544 | int polarity = ACPI_ACTIVE_LOW; | |
4be44fcd | 545 | char *link = NULL; |
c83642d5 | 546 | char link_desc[16]; |
4be44fcd | 547 | int rc; |
1da177e4 | 548 | |
1da177e4 LT |
549 | |
550 | if (!dev) | |
d550d98d | 551 | return -EINVAL; |
4be44fcd | 552 | |
8015a014 | 553 | pin = dev->pin; |
1da177e4 | 554 | if (!pin) { |
4be44fcd LB |
555 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
556 | "No interrupt pin configured for device %s\n", | |
557 | pci_name(dev))); | |
d550d98d | 558 | return 0; |
1da177e4 LT |
559 | } |
560 | pin--; | |
561 | ||
562 | if (!dev->bus) { | |
c83642d5 | 563 | dev_err(&dev->dev, "invalid (NULL) 'bus' field\n"); |
d550d98d | 564 | return -ENODEV; |
1da177e4 LT |
565 | } |
566 | ||
567 | /* | |
568 | * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT | |
569 | * values override any BIOS-assigned IRQs set during boot. | |
570 | */ | |
4be44fcd | 571 | irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, |
50eca3eb | 572 | &triggering, &polarity, &link, |
4be44fcd | 573 | acpi_pci_allocate_irq); |
1da177e4 LT |
574 | |
575 | /* | |
576 | * If no PRT entry was found, we'll try to derive an IRQ from the | |
577 | * device's parent bridge. | |
578 | */ | |
579 | if (irq < 0) | |
50eca3eb BM |
580 | irq = acpi_pci_irq_derive(dev, pin, &triggering, |
581 | &polarity, &link, | |
4be44fcd LB |
582 | acpi_pci_allocate_irq); |
583 | ||
96c2a876 AC |
584 | if (irq < 0) { |
585 | /* | |
586 | * IDE legacy mode controller IRQs are magic. Why do compat | |
587 | * extensions always make such a nasty mess. | |
588 | */ | |
589 | if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE && | |
590 | (dev->class & 0x05) == 0) | |
591 | return 0; | |
592 | } | |
1da177e4 LT |
593 | /* |
594 | * No IRQ known to the ACPI subsystem - maybe the BIOS / | |
595 | * driver reported one, then use it. Exit in any case. | |
596 | */ | |
597 | if (irq < 0) { | |
c83642d5 | 598 | dev_warn(&dev->dev, "PCI INT %c: no GSI", 'A' + pin); |
1da177e4 | 599 | /* Interrupt Line values above 0xF are forbidden */ |
44f8e1a2 | 600 | if (dev->irq > 0 && (dev->irq <= 0xF)) { |
1da177e4 | 601 | printk(" - using IRQ %d\n", dev->irq); |
4be44fcd LB |
602 | acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, |
603 | ACPI_ACTIVE_LOW); | |
d550d98d | 604 | return 0; |
4be44fcd | 605 | } else { |
1da177e4 | 606 | printk("\n"); |
d550d98d | 607 | return 0; |
1da177e4 | 608 | } |
4be44fcd | 609 | } |
1da177e4 | 610 | |
50eca3eb | 611 | rc = acpi_register_gsi(irq, triggering, polarity); |
349f0d56 | 612 | if (rc < 0) { |
c83642d5 BH |
613 | dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n", |
614 | 'A' + pin); | |
d550d98d | 615 | return rc; |
349f0d56 KK |
616 | } |
617 | dev->irq = rc; | |
1da177e4 | 618 | |
1da177e4 | 619 | if (link) |
c83642d5 BH |
620 | snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link); |
621 | else | |
622 | link_desc[0] = '\0'; | |
1da177e4 | 623 | |
c83642d5 BH |
624 | dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n", |
625 | 'A' + pin, link_desc, irq, | |
626 | (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge", | |
627 | (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq); | |
1da177e4 | 628 | |
d550d98d | 629 | return 0; |
1da177e4 | 630 | } |
1da177e4 | 631 | |
87bec66b | 632 | /* FIXME: implement x86/x86_64 version */ |
4be44fcd LB |
633 | void __attribute__ ((weak)) acpi_unregister_gsi(u32 i) |
634 | { | |
635 | } | |
87bec66b | 636 | |
4be44fcd | 637 | void acpi_pci_irq_disable(struct pci_dev *dev) |
1da177e4 | 638 | { |
4be44fcd LB |
639 | int gsi = 0; |
640 | u8 pin = 0; | |
50eca3eb BM |
641 | int triggering = ACPI_LEVEL_SENSITIVE; |
642 | int polarity = ACPI_ACTIVE_LOW; | |
1da177e4 | 643 | |
1da177e4 | 644 | |
5f0110f2 | 645 | if (!dev || !dev->bus) |
d550d98d | 646 | return; |
1da177e4 | 647 | |
8015a014 | 648 | pin = dev->pin; |
1da177e4 | 649 | if (!pin) |
d550d98d | 650 | return; |
1da177e4 LT |
651 | pin--; |
652 | ||
1da177e4 LT |
653 | /* |
654 | * First we check the PCI IRQ routing table (PRT) for an IRQ. | |
655 | */ | |
4be44fcd | 656 | gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, |
50eca3eb | 657 | &triggering, &polarity, NULL, |
4be44fcd | 658 | acpi_pci_free_irq); |
1da177e4 LT |
659 | /* |
660 | * If no PRT entry was found, we'll try to derive an IRQ from the | |
661 | * device's parent bridge. | |
662 | */ | |
663 | if (gsi < 0) | |
4be44fcd | 664 | gsi = acpi_pci_irq_derive(dev, pin, |
50eca3eb | 665 | &triggering, &polarity, NULL, |
4be44fcd | 666 | acpi_pci_free_irq); |
1da177e4 | 667 | if (gsi < 0) |
d550d98d | 668 | return; |
1da177e4 LT |
669 | |
670 | /* | |
671 | * TBD: It might be worth clearing dev->irq by magic constant | |
672 | * (e.g. PCI_UNDEFINED_IRQ). | |
673 | */ | |
674 | ||
c83642d5 | 675 | dev_info(&dev->dev, "PCI INT %c disabled\n", 'A' + pin); |
1da177e4 | 676 | acpi_unregister_gsi(gsi); |
1da177e4 | 677 | } |