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 | |
f748bafa BH |
44 | struct 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 | ||
55 | struct acpi_prt_list { | |
56 | int count; | |
57 | struct list_head entries; | |
58 | }; | |
59 | ||
4be44fcd | 60 | static struct acpi_prt_list acpi_prt; |
1da177e4 LT |
61 | static DEFINE_SPINLOCK(acpi_prt_lock); |
62 | ||
cf68b80b BH |
63 | static inline char pin_name(int pin) |
64 | { | |
e64e9db5 | 65 | return 'A' + pin - 1; |
cf68b80b BH |
66 | } |
67 | ||
1da177e4 LT |
68 | /* -------------------------------------------------------------------------- |
69 | PCI IRQ Routing Table (PRT) Support | |
70 | -------------------------------------------------------------------------- */ | |
71 | ||
4be44fcd LB |
72 | static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(int segment, |
73 | int bus, | |
74 | int device, int pin) | |
1da177e4 | 75 | { |
4be44fcd | 76 | struct acpi_prt_entry *entry = NULL; |
1da177e4 | 77 | |
1da177e4 | 78 | if (!acpi_prt.count) |
d550d98d | 79 | return NULL; |
1da177e4 LT |
80 | |
81 | /* | |
82 | * Parse through all PRT entries looking for a match on the specified | |
83 | * PCI device's segment, bus, device, and pin (don't care about func). | |
84 | * | |
85 | */ | |
86 | spin_lock(&acpi_prt_lock); | |
1a3b77ae | 87 | list_for_each_entry(entry, &acpi_prt.entries, node) { |
4be44fcd LB |
88 | if ((segment == entry->id.segment) |
89 | && (bus == entry->id.bus) | |
90 | && (device == entry->id.device) | |
91 | && (pin == entry->pin)) { | |
1da177e4 | 92 | spin_unlock(&acpi_prt_lock); |
d550d98d | 93 | return entry; |
1da177e4 LT |
94 | } |
95 | } | |
96 | ||
97 | spin_unlock(&acpi_prt_lock); | |
d550d98d | 98 | return NULL; |
1da177e4 LT |
99 | } |
100 | ||
391df5dc BH |
101 | /* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */ |
102 | static struct dmi_system_id medion_md9580[] = { | |
103 | { | |
104 | .ident = "Medion MD9580-F laptop", | |
105 | .matches = { | |
106 | DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"), | |
107 | DMI_MATCH(DMI_PRODUCT_NAME, "A555"), | |
108 | }, | |
109 | }, | |
110 | { } | |
111 | }; | |
112 | ||
113 | /* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */ | |
114 | static struct dmi_system_id dell_optiplex[] = { | |
115 | { | |
116 | .ident = "Dell Optiplex GX1", | |
117 | .matches = { | |
118 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), | |
119 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX1 600S+"), | |
120 | }, | |
121 | }, | |
122 | { } | |
123 | }; | |
124 | ||
125 | /* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */ | |
126 | static struct dmi_system_id hp_t5710[] = { | |
127 | { | |
128 | .ident = "HP t5710", | |
129 | .matches = { | |
130 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), | |
131 | DMI_MATCH(DMI_PRODUCT_NAME, "hp t5000 series"), | |
132 | DMI_MATCH(DMI_BOARD_NAME, "098Ch"), | |
133 | }, | |
134 | }, | |
135 | { } | |
136 | }; | |
137 | ||
138 | struct prt_quirk { | |
139 | struct dmi_system_id *system; | |
140 | unsigned int segment; | |
141 | unsigned int bus; | |
142 | unsigned int device; | |
143 | unsigned char pin; | |
144 | char *source; /* according to BIOS */ | |
145 | char *actual_source; | |
146 | }; | |
147 | ||
c458033c BH |
148 | #define PCI_INTX_PIN(c) (c - 'A' + 1) |
149 | ||
391df5dc BH |
150 | /* |
151 | * These systems have incorrect _PRT entries. The BIOS claims the PCI | |
152 | * interrupt at the listed segment/bus/device/pin is connected to the first | |
153 | * link device, but it is actually connected to the second. | |
154 | */ | |
155 | static struct prt_quirk prt_quirks[] = { | |
c458033c | 156 | { medion_md9580, 0, 0, 9, PCI_INTX_PIN('A'), |
b97d4803 BH |
157 | "\\_SB_.PCI0.ISA_.LNKA", |
158 | "\\_SB_.PCI0.ISA_.LNKB"}, | |
c458033c | 159 | { dell_optiplex, 0, 0, 0xd, PCI_INTX_PIN('A'), |
391df5dc BH |
160 | "\\_SB_.LNKB", |
161 | "\\_SB_.LNKA"}, | |
c458033c | 162 | { hp_t5710, 0, 0, 1, PCI_INTX_PIN('A'), |
391df5dc BH |
163 | "\\_SB_.PCI0.LNK1", |
164 | "\\_SB_.PCI0.LNK3"}, | |
165 | }; | |
166 | ||
167 | static void | |
168 | do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt) | |
169 | { | |
170 | int i; | |
171 | struct prt_quirk *quirk; | |
172 | ||
173 | for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) { | |
174 | quirk = &prt_quirks[i]; | |
175 | ||
176 | /* All current quirks involve link devices, not GSIs */ | |
177 | if (!prt->source) | |
178 | continue; | |
179 | ||
180 | if (dmi_check_system(quirk->system) && | |
181 | entry->id.segment == quirk->segment && | |
182 | entry->id.bus == quirk->bus && | |
183 | entry->id.device == quirk->device && | |
c458033c | 184 | entry->pin == quirk->pin && |
391df5dc BH |
185 | !strcmp(prt->source, quirk->source) && |
186 | strlen(prt->source) >= strlen(quirk->actual_source)) { | |
187 | printk(KERN_WARNING PREFIX "firmware reports " | |
c83642d5 | 188 | "%04x:%02x:%02x PCI INT %c connected to %s; " |
391df5dc BH |
189 | "changing to %s\n", |
190 | entry->id.segment, entry->id.bus, | |
cf68b80b | 191 | entry->id.device, pin_name(entry->pin), |
391df5dc BH |
192 | prt->source, quirk->actual_source); |
193 | strcpy(prt->source, quirk->actual_source); | |
194 | } | |
195 | } | |
196 | } | |
197 | ||
1da177e4 | 198 | static int |
4be44fcd LB |
199 | acpi_pci_irq_add_entry(acpi_handle handle, |
200 | int segment, int bus, struct acpi_pci_routing_table *prt) | |
1da177e4 | 201 | { |
4be44fcd | 202 | struct acpi_prt_entry *entry = NULL; |
1da177e4 | 203 | |
36bcbec7 | 204 | entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL); |
1da177e4 | 205 | if (!entry) |
d550d98d | 206 | return -ENOMEM; |
1da177e4 | 207 | |
e64e9db5 BH |
208 | /* |
209 | * Note that the _PRT uses 0=INTA, 1=INTB, etc, while PCI uses | |
210 | * 1=INTA, 2=INTB. We use the PCI encoding throughout, so convert | |
211 | * it here. | |
212 | */ | |
1da177e4 LT |
213 | entry->id.segment = segment; |
214 | entry->id.bus = bus; | |
215 | entry->id.device = (prt->address >> 16) & 0xFFFF; | |
e64e9db5 | 216 | entry->pin = prt->pin + 1; |
1da177e4 | 217 | |
391df5dc BH |
218 | do_prt_fixups(entry, prt); |
219 | ||
1da177e4 LT |
220 | /* |
221 | * Type 1: Dynamic | |
222 | * --------------- | |
223 | * The 'source' field specifies the PCI interrupt link device used to | |
224 | * configure the IRQ assigned to this slot|dev|pin. The 'source_index' | |
225 | * indicates which resource descriptor in the resource template (of | |
226 | * the link device) this interrupt is allocated from. | |
227 | * | |
228 | * NOTE: Don't query the Link Device for IRQ information at this time | |
229 | * because Link Device enumeration may not have occurred yet | |
230 | * (e.g. exists somewhere 'below' this _PRT entry in the ACPI | |
231 | * namespace). | |
232 | */ | |
233 | if (prt->source[0]) { | |
234 | acpi_get_handle(handle, prt->source, &entry->link.handle); | |
235 | entry->link.index = prt->source_index; | |
236 | } | |
237 | /* | |
238 | * Type 2: Static | |
239 | * -------------- | |
240 | * The 'source' field is NULL, and the 'source_index' field specifies | |
241 | * the IRQ value, which is hardwired to specific interrupt inputs on | |
242 | * the interrupt controller. | |
243 | */ | |
244 | else | |
245 | entry->link.index = prt->source_index; | |
246 | ||
247 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO, | |
21a53283 | 248 | " %04x:%02x:%02x[%c] -> %s[%d]\n", |
4be44fcd | 249 | entry->id.segment, entry->id.bus, |
cf68b80b BH |
250 | entry->id.device, pin_name(entry->pin), |
251 | prt->source, entry->link.index)); | |
1da177e4 LT |
252 | |
253 | spin_lock(&acpi_prt_lock); | |
254 | list_add_tail(&entry->node, &acpi_prt.entries); | |
255 | acpi_prt.count++; | |
256 | spin_unlock(&acpi_prt_lock); | |
257 | ||
d550d98d | 258 | return 0; |
1da177e4 LT |
259 | } |
260 | ||
1da177e4 | 261 | static void |
4be44fcd | 262 | acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry) |
1da177e4 | 263 | { |
4be44fcd | 264 | if (segment == entry->id.segment && bus == entry->id.bus) { |
1da177e4 LT |
265 | acpi_prt.count--; |
266 | list_del(&entry->node); | |
267 | kfree(entry); | |
268 | } | |
269 | } | |
270 | ||
4be44fcd | 271 | int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus) |
1da177e4 | 272 | { |
2320ac6c BH |
273 | acpi_status status; |
274 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
275 | struct acpi_pci_routing_table *entry; | |
4be44fcd | 276 | static int first_time = 1; |
1da177e4 | 277 | |
1da177e4 LT |
278 | if (first_time) { |
279 | acpi_prt.count = 0; | |
280 | INIT_LIST_HEAD(&acpi_prt.entries); | |
281 | first_time = 0; | |
282 | } | |
283 | ||
2320ac6c BH |
284 | /* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */ |
285 | status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); | |
286 | if (ACPI_FAILURE(status)) | |
287 | return -ENODEV; | |
1da177e4 LT |
288 | |
289 | printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n", | |
2320ac6c | 290 | (char *) buffer.pointer); |
1da177e4 | 291 | |
2320ac6c | 292 | kfree(buffer.pointer); |
1da177e4 | 293 | |
2320ac6c | 294 | buffer.length = ACPI_ALLOCATE_BUFFER; |
1da177e4 | 295 | buffer.pointer = NULL; |
1da177e4 LT |
296 | |
297 | status = acpi_get_irq_routing_table(handle, &buffer); | |
298 | if (ACPI_FAILURE(status)) { | |
a6fc6720 TR |
299 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]", |
300 | acpi_format_exception(status))); | |
1da177e4 | 301 | kfree(buffer.pointer); |
d550d98d | 302 | return -ENODEV; |
1da177e4 LT |
303 | } |
304 | ||
2320ac6c | 305 | entry = buffer.pointer; |
1da177e4 LT |
306 | while (entry && (entry->length > 0)) { |
307 | acpi_pci_irq_add_entry(handle, segment, bus, entry); | |
308 | entry = (struct acpi_pci_routing_table *) | |
4be44fcd | 309 | ((unsigned long)entry + entry->length); |
1da177e4 LT |
310 | } |
311 | ||
2320ac6c | 312 | kfree(buffer.pointer); |
d550d98d | 313 | return 0; |
1da177e4 LT |
314 | } |
315 | ||
4be44fcd | 316 | void acpi_pci_irq_del_prt(int segment, int bus) |
1da177e4 | 317 | { |
4be44fcd LB |
318 | struct list_head *node = NULL, *n = NULL; |
319 | struct acpi_prt_entry *entry = NULL; | |
1da177e4 | 320 | |
4be44fcd | 321 | if (!acpi_prt.count) { |
1da177e4 LT |
322 | return; |
323 | } | |
324 | ||
4be44fcd | 325 | printk(KERN_DEBUG |
21a53283 BH |
326 | "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n", |
327 | segment, bus); | |
1da177e4 LT |
328 | spin_lock(&acpi_prt_lock); |
329 | list_for_each_safe(node, n, &acpi_prt.entries) { | |
330 | entry = list_entry(node, struct acpi_prt_entry, node); | |
331 | ||
332 | acpi_pci_irq_del_entry(segment, bus, entry); | |
333 | } | |
334 | spin_unlock(&acpi_prt_lock); | |
335 | } | |
4be44fcd | 336 | |
1da177e4 LT |
337 | /* -------------------------------------------------------------------------- |
338 | PCI Interrupt Routing Support | |
339 | -------------------------------------------------------------------------- */ | |
4be44fcd | 340 | typedef int (*irq_lookup_func) (struct acpi_prt_entry *, int *, int *, char **); |
1da177e4 | 341 | |
87bec66b DSL |
342 | static int |
343 | acpi_pci_allocate_irq(struct acpi_prt_entry *entry, | |
50eca3eb | 344 | int *triggering, int *polarity, char **link) |
87bec66b | 345 | { |
4be44fcd | 346 | int irq; |
87bec66b | 347 | |
87bec66b DSL |
348 | |
349 | if (entry->link.handle) { | |
350 | irq = acpi_pci_link_allocate_irq(entry->link.handle, | |
50eca3eb BM |
351 | entry->link.index, triggering, |
352 | polarity, link); | |
87bec66b | 353 | if (irq < 0) { |
cece9296 LB |
354 | printk(KERN_WARNING PREFIX |
355 | "Invalid IRQ link routing entry\n"); | |
d550d98d | 356 | return -1; |
87bec66b DSL |
357 | } |
358 | } else { | |
359 | irq = entry->link.index; | |
50eca3eb BM |
360 | *triggering = ACPI_LEVEL_SENSITIVE; |
361 | *polarity = ACPI_ACTIVE_LOW; | |
87bec66b DSL |
362 | } |
363 | ||
c13f889a | 364 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found GSI %d\n", irq)); |
d550d98d | 365 | return irq; |
87bec66b DSL |
366 | } |
367 | ||
368 | static int | |
369 | acpi_pci_free_irq(struct acpi_prt_entry *entry, | |
50eca3eb | 370 | int *triggering, int *polarity, char **link) |
87bec66b | 371 | { |
4be44fcd | 372 | int irq; |
87bec66b | 373 | |
87bec66b DSL |
374 | if (entry->link.handle) { |
375 | irq = acpi_pci_link_free_irq(entry->link.handle); | |
376 | } else { | |
377 | irq = entry->link.index; | |
378 | } | |
d550d98d | 379 | return irq; |
87bec66b | 380 | } |
4be44fcd | 381 | |
1da177e4 LT |
382 | /* |
383 | * acpi_pci_irq_lookup | |
384 | * success: return IRQ >= 0 | |
385 | * failure: return -1 | |
386 | */ | |
387 | static int | |
4be44fcd LB |
388 | acpi_pci_irq_lookup(struct pci_bus *bus, |
389 | int device, | |
390 | int pin, | |
50eca3eb BM |
391 | int *triggering, |
392 | int *polarity, char **link, irq_lookup_func func) | |
1da177e4 | 393 | { |
4be44fcd | 394 | struct acpi_prt_entry *entry = NULL; |
1da177e4 LT |
395 | int segment = pci_domain_nr(bus); |
396 | int bus_nr = bus->number; | |
87bec66b | 397 | int ret; |
1da177e4 | 398 | |
1da177e4 | 399 | |
4be44fcd | 400 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
21a53283 | 401 | "Searching for _PRT entry for %04x:%02x:%02x[%c]\n", |
cf68b80b | 402 | segment, bus_nr, device, pin_name(pin))); |
1da177e4 | 403 | |
4be44fcd | 404 | entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin); |
1da177e4 | 405 | if (!entry) { |
21a53283 | 406 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_PRT entry not found\n")); |
d550d98d | 407 | return -1; |
1da177e4 | 408 | } |
4be44fcd | 409 | |
50eca3eb | 410 | ret = func(entry, triggering, polarity, link); |
d550d98d | 411 | return ret; |
1da177e4 LT |
412 | } |
413 | ||
414 | /* | |
415 | * acpi_pci_irq_derive | |
416 | * success: return IRQ >= 0 | |
417 | * failure: return < 0 | |
418 | */ | |
419 | static int | |
4be44fcd LB |
420 | acpi_pci_irq_derive(struct pci_dev *dev, |
421 | int pin, | |
50eca3eb BM |
422 | int *triggering, |
423 | int *polarity, char **link, irq_lookup_func func) | |
1da177e4 | 424 | { |
4be44fcd LB |
425 | struct pci_dev *bridge = dev; |
426 | int irq = -1; | |
c83642d5 | 427 | u8 bridge_pin = 0, orig_pin = pin; |
1da177e4 | 428 | |
1da177e4 | 429 | |
1da177e4 LT |
430 | /* |
431 | * Attempt to derive an IRQ for this device from a parent bridge's | |
432 | * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge). | |
433 | */ | |
434 | while (irq < 0 && bridge->bus->self) { | |
e64e9db5 | 435 | pin = (((pin - 1) + PCI_SLOT(bridge->devfn)) % 4) + 1; |
1da177e4 LT |
436 | bridge = bridge->bus->self; |
437 | ||
438 | if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) { | |
439 | /* PC card has the same IRQ as its cardbridge */ | |
8015a014 | 440 | bridge_pin = bridge->pin; |
1da177e4 | 441 | if (!bridge_pin) { |
4be44fcd LB |
442 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
443 | "No interrupt pin configured for device %s\n", | |
444 | pci_name(bridge))); | |
d550d98d | 445 | return -1; |
1da177e4 | 446 | } |
1da177e4 LT |
447 | pin = bridge_pin; |
448 | } | |
449 | ||
450 | irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn), | |
50eca3eb | 451 | pin, triggering, polarity, |
4be44fcd | 452 | link, func); |
1da177e4 LT |
453 | } |
454 | ||
455 | if (irq < 0) { | |
c83642d5 | 456 | dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n", |
cf68b80b | 457 | pin_name(orig_pin)); |
d550d98d | 458 | return -1; |
1da177e4 LT |
459 | } |
460 | ||
c13f889a | 461 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive GSI %d for device %s from %s\n", |
4be44fcd | 462 | irq, pci_name(dev), pci_name(bridge))); |
1da177e4 | 463 | |
d550d98d | 464 | return irq; |
1da177e4 LT |
465 | } |
466 | ||
467 | /* | |
468 | * acpi_pci_irq_enable | |
469 | * success: return 0 | |
470 | * failure: return < 0 | |
471 | */ | |
472 | ||
4be44fcd | 473 | int acpi_pci_irq_enable(struct pci_dev *dev) |
1da177e4 | 474 | { |
c13f889a | 475 | int gsi = 0; |
4be44fcd | 476 | u8 pin = 0; |
50eca3eb BM |
477 | int triggering = ACPI_LEVEL_SENSITIVE; |
478 | int polarity = ACPI_ACTIVE_LOW; | |
4be44fcd | 479 | char *link = NULL; |
c83642d5 | 480 | char link_desc[16]; |
4be44fcd | 481 | int rc; |
1da177e4 | 482 | |
1da177e4 | 483 | |
8015a014 | 484 | pin = dev->pin; |
1da177e4 | 485 | if (!pin) { |
4be44fcd LB |
486 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
487 | "No interrupt pin configured for device %s\n", | |
488 | pci_name(dev))); | |
d550d98d | 489 | return 0; |
1da177e4 | 490 | } |
1da177e4 | 491 | |
1da177e4 LT |
492 | /* |
493 | * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT | |
494 | * values override any BIOS-assigned IRQs set during boot. | |
495 | */ | |
c13f889a | 496 | gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, |
50eca3eb | 497 | &triggering, &polarity, &link, |
4be44fcd | 498 | acpi_pci_allocate_irq); |
1da177e4 LT |
499 | |
500 | /* | |
501 | * If no PRT entry was found, we'll try to derive an IRQ from the | |
502 | * device's parent bridge. | |
503 | */ | |
c13f889a BH |
504 | if (gsi < 0) |
505 | gsi = acpi_pci_irq_derive(dev, pin, &triggering, | |
50eca3eb | 506 | &polarity, &link, |
4be44fcd LB |
507 | acpi_pci_allocate_irq); |
508 | ||
c13f889a | 509 | if (gsi < 0) { |
96c2a876 AC |
510 | /* |
511 | * IDE legacy mode controller IRQs are magic. Why do compat | |
512 | * extensions always make such a nasty mess. | |
513 | */ | |
514 | if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE && | |
515 | (dev->class & 0x05) == 0) | |
516 | return 0; | |
517 | } | |
1da177e4 LT |
518 | /* |
519 | * No IRQ known to the ACPI subsystem - maybe the BIOS / | |
520 | * driver reported one, then use it. Exit in any case. | |
521 | */ | |
c13f889a | 522 | if (gsi < 0) { |
cf68b80b | 523 | dev_warn(&dev->dev, "PCI INT %c: no GSI", pin_name(pin)); |
1da177e4 | 524 | /* Interrupt Line values above 0xF are forbidden */ |
44f8e1a2 | 525 | if (dev->irq > 0 && (dev->irq <= 0xF)) { |
1da177e4 | 526 | printk(" - using IRQ %d\n", dev->irq); |
4be44fcd LB |
527 | acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, |
528 | ACPI_ACTIVE_LOW); | |
d550d98d | 529 | return 0; |
4be44fcd | 530 | } else { |
1da177e4 | 531 | printk("\n"); |
d550d98d | 532 | return 0; |
1da177e4 | 533 | } |
4be44fcd | 534 | } |
1da177e4 | 535 | |
c13f889a | 536 | rc = acpi_register_gsi(gsi, triggering, polarity); |
349f0d56 | 537 | if (rc < 0) { |
c83642d5 | 538 | dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n", |
cf68b80b | 539 | pin_name(pin)); |
d550d98d | 540 | return rc; |
349f0d56 KK |
541 | } |
542 | dev->irq = rc; | |
1da177e4 | 543 | |
1da177e4 | 544 | if (link) |
c83642d5 BH |
545 | snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link); |
546 | else | |
547 | link_desc[0] = '\0'; | |
1da177e4 | 548 | |
c83642d5 | 549 | dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n", |
cf68b80b | 550 | pin_name(pin), link_desc, gsi, |
c83642d5 BH |
551 | (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge", |
552 | (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq); | |
1da177e4 | 553 | |
d550d98d | 554 | return 0; |
1da177e4 | 555 | } |
1da177e4 | 556 | |
87bec66b | 557 | /* FIXME: implement x86/x86_64 version */ |
4be44fcd LB |
558 | void __attribute__ ((weak)) acpi_unregister_gsi(u32 i) |
559 | { | |
560 | } | |
87bec66b | 561 | |
4be44fcd | 562 | void acpi_pci_irq_disable(struct pci_dev *dev) |
1da177e4 | 563 | { |
4be44fcd LB |
564 | int gsi = 0; |
565 | u8 pin = 0; | |
50eca3eb BM |
566 | int triggering = ACPI_LEVEL_SENSITIVE; |
567 | int polarity = ACPI_ACTIVE_LOW; | |
1da177e4 | 568 | |
1da177e4 | 569 | |
8015a014 | 570 | pin = dev->pin; |
1da177e4 | 571 | if (!pin) |
d550d98d | 572 | return; |
1da177e4 | 573 | |
1da177e4 LT |
574 | /* |
575 | * First we check the PCI IRQ routing table (PRT) for an IRQ. | |
576 | */ | |
4be44fcd | 577 | gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, |
50eca3eb | 578 | &triggering, &polarity, NULL, |
4be44fcd | 579 | acpi_pci_free_irq); |
1da177e4 LT |
580 | /* |
581 | * If no PRT entry was found, we'll try to derive an IRQ from the | |
582 | * device's parent bridge. | |
583 | */ | |
584 | if (gsi < 0) | |
4be44fcd | 585 | gsi = acpi_pci_irq_derive(dev, pin, |
50eca3eb | 586 | &triggering, &polarity, NULL, |
4be44fcd | 587 | acpi_pci_free_irq); |
1da177e4 | 588 | if (gsi < 0) |
d550d98d | 589 | return; |
1da177e4 LT |
590 | |
591 | /* | |
592 | * TBD: It might be worth clearing dev->irq by magic constant | |
593 | * (e.g. PCI_UNDEFINED_IRQ). | |
594 | */ | |
595 | ||
cf68b80b | 596 | dev_info(&dev->dev, "PCI INT %c disabled\n", pin_name(pin)); |
1da177e4 | 597 | acpi_unregister_gsi(gsi); |
1da177e4 | 598 | } |