Blame view
drivers/acpi/pci_irq.c
12.4 KB
1da177e4c
|
1 2 3 4 5 6 |
/* * pci_irq.c - ACPI PCI Interrupt Routing ($Revision: 11 $) * * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> * Copyright (C) 2002 Dominik Brodowski <devel@brodo.de> |
39488b041
|
7 8 |
* (c) Copyright 2008 Hewlett-Packard Development Company, L.P. * Bjorn Helgaas <bjorn.helgaas@hp.com> |
1da177e4c
|
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
1da177e4c
|
28 |
|
391df5dce
|
29 |
#include <linux/dmi.h> |
1da177e4c
|
30 31 32 33 34 35 36 37 38 |
#include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/types.h> #include <linux/proc_fs.h> #include <linux/spinlock.h> #include <linux/pm.h> #include <linux/pci.h> #include <linux/acpi.h> |
5a0e3ad6a
|
39 |
#include <linux/slab.h> |
1da177e4c
|
40 41 |
#include <acpi/acpi_bus.h> #include <acpi/acpi_drivers.h> |
a192a9580
|
42 |
#define PREFIX "ACPI: " |
1da177e4c
|
43 |
#define _COMPONENT ACPI_PCI_COMPONENT |
f52fd66d2
|
44 |
ACPI_MODULE_NAME("pci_irq"); |
1da177e4c
|
45 |
|
f748bafa3
|
46 |
struct acpi_prt_entry { |
3604a9f44
|
47 |
struct list_head list; |
f748bafa3
|
48 49 |
struct acpi_pci_id id; u8 pin; |
4eaf6db3e
|
50 51 |
acpi_handle link; u32 index; /* GSI, or link _CRS index */ |
f748bafa3
|
52 |
}; |
3604a9f44
|
53 |
static LIST_HEAD(acpi_prt_list); |
1da177e4c
|
54 |
static DEFINE_SPINLOCK(acpi_prt_lock); |
cf68b80b0
|
55 56 |
static inline char pin_name(int pin) { |
e64e9db53
|
57 |
return 'A' + pin - 1; |
cf68b80b0
|
58 |
} |
1da177e4c
|
59 60 61 |
/* -------------------------------------------------------------------------- PCI IRQ Routing Table (PRT) Support -------------------------------------------------------------------------- */ |
063563b4b
|
62 63 |
static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(struct pci_dev *dev, int pin) |
1da177e4c
|
64 |
{ |
3604a9f44
|
65 |
struct acpi_prt_entry *entry; |
063563b4b
|
66 67 68 |
int segment = pci_domain_nr(dev->bus); int bus = dev->bus->number; int device = PCI_SLOT(dev->devfn); |
1da177e4c
|
69 |
|
1da177e4c
|
70 |
spin_lock(&acpi_prt_lock); |
3604a9f44
|
71 |
list_for_each_entry(entry, &acpi_prt_list, list) { |
4be44fcd3
|
72 73 74 75 |
if ((segment == entry->id.segment) && (bus == entry->id.bus) && (device == entry->id.device) && (pin == entry->pin)) { |
1da177e4c
|
76 |
spin_unlock(&acpi_prt_lock); |
d550d98d3
|
77 |
return entry; |
1da177e4c
|
78 79 |
} } |
1da177e4c
|
80 |
spin_unlock(&acpi_prt_lock); |
d550d98d3
|
81 |
return NULL; |
1da177e4c
|
82 |
} |
391df5dce
|
83 |
/* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */ |
609d4bc94
|
84 |
static const struct dmi_system_id medion_md9580[] = { |
391df5dce
|
85 86 87 88 89 90 91 92 93 94 95 |
{ .ident = "Medion MD9580-F laptop", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"), DMI_MATCH(DMI_PRODUCT_NAME, "A555"), }, }, { } }; /* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */ |
609d4bc94
|
96 |
static const struct dmi_system_id dell_optiplex[] = { |
391df5dce
|
97 98 99 100 101 102 103 104 105 106 107 |
{ .ident = "Dell Optiplex GX1", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX1 600S+"), }, }, { } }; /* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */ |
609d4bc94
|
108 |
static const struct dmi_system_id hp_t5710[] = { |
391df5dce
|
109 110 111 112 113 114 115 116 117 118 119 120 |
{ .ident = "HP t5710", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), DMI_MATCH(DMI_PRODUCT_NAME, "hp t5000 series"), DMI_MATCH(DMI_BOARD_NAME, "098Ch"), }, }, { } }; struct prt_quirk { |
609d4bc94
|
121 |
const struct dmi_system_id *system; |
391df5dce
|
122 123 124 125 |
unsigned int segment; unsigned int bus; unsigned int device; unsigned char pin; |
609d4bc94
|
126 127 |
const char *source; /* according to BIOS */ const char *actual_source; |
391df5dce
|
128 |
}; |
c458033c9
|
129 |
#define PCI_INTX_PIN(c) (c - 'A' + 1) |
391df5dce
|
130 131 132 133 134 |
/* * These systems have incorrect _PRT entries. The BIOS claims the PCI * interrupt at the listed segment/bus/device/pin is connected to the first * link device, but it is actually connected to the second. */ |
609d4bc94
|
135 |
static const struct prt_quirk prt_quirks[] = { |
c458033c9
|
136 |
{ medion_md9580, 0, 0, 9, PCI_INTX_PIN('A'), |
b97d48034
|
137 138 |
"\\_SB_.PCI0.ISA_.LNKA", "\\_SB_.PCI0.ISA_.LNKB"}, |
c458033c9
|
139 |
{ dell_optiplex, 0, 0, 0xd, PCI_INTX_PIN('A'), |
391df5dce
|
140 141 |
"\\_SB_.LNKB", "\\_SB_.LNKA"}, |
c458033c9
|
142 |
{ hp_t5710, 0, 0, 1, PCI_INTX_PIN('A'), |
391df5dce
|
143 144 145 |
"\\_SB_.PCI0.LNK1", "\\_SB_.PCI0.LNK3"}, }; |
3f0f3c27b
|
146 147 |
static void do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt) |
391df5dce
|
148 149 |
{ int i; |
609d4bc94
|
150 |
const struct prt_quirk *quirk; |
391df5dce
|
151 152 153 154 155 156 157 158 159 160 161 162 |
for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) { quirk = &prt_quirks[i]; /* All current quirks involve link devices, not GSIs */ if (!prt->source) continue; if (dmi_check_system(quirk->system) && entry->id.segment == quirk->segment && entry->id.bus == quirk->bus && entry->id.device == quirk->device && |
c458033c9
|
163 |
entry->pin == quirk->pin && |
391df5dce
|
164 165 166 |
!strcmp(prt->source, quirk->source) && strlen(prt->source) >= strlen(quirk->actual_source)) { printk(KERN_WARNING PREFIX "firmware reports " |
c83642d51
|
167 |
"%04x:%02x:%02x PCI INT %c connected to %s; " |
391df5dce
|
168 169 170 |
"changing to %s ", entry->id.segment, entry->id.bus, |
cf68b80b0
|
171 |
entry->id.device, pin_name(entry->pin), |
391df5dce
|
172 173 174 175 176 |
prt->source, quirk->actual_source); strcpy(prt->source, quirk->actual_source); } } } |
859a3f86c
|
177 |
static int acpi_pci_irq_add_entry(acpi_handle handle, struct pci_bus *bus, |
3f0f3c27b
|
178 |
struct acpi_pci_routing_table *prt) |
1da177e4c
|
179 |
{ |
3604a9f44
|
180 |
struct acpi_prt_entry *entry; |
1da177e4c
|
181 |
|
36bcbec7c
|
182 |
entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL); |
1da177e4c
|
183 |
if (!entry) |
d550d98d3
|
184 |
return -ENOMEM; |
1da177e4c
|
185 |
|
e64e9db53
|
186 187 188 189 190 |
/* * Note that the _PRT uses 0=INTA, 1=INTB, etc, while PCI uses * 1=INTA, 2=INTB. We use the PCI encoding throughout, so convert * it here. */ |
859a3f86c
|
191 192 |
entry->id.segment = pci_domain_nr(bus); entry->id.bus = bus->number; |
1da177e4c
|
193 |
entry->id.device = (prt->address >> 16) & 0xFFFF; |
e64e9db53
|
194 |
entry->pin = prt->pin + 1; |
1da177e4c
|
195 |
|
391df5dce
|
196 |
do_prt_fixups(entry, prt); |
4eaf6db3e
|
197 |
entry->index = prt->source_index; |
1da177e4c
|
198 199 200 201 202 203 204 205 206 207 208 209 210 |
/* * Type 1: Dynamic * --------------- * The 'source' field specifies the PCI interrupt link device used to * configure the IRQ assigned to this slot|dev|pin. The 'source_index' * indicates which resource descriptor in the resource template (of * the link device) this interrupt is allocated from. * * NOTE: Don't query the Link Device for IRQ information at this time * because Link Device enumeration may not have occurred yet * (e.g. exists somewhere 'below' this _PRT entry in the ACPI * namespace). */ |
4eaf6db3e
|
211 212 |
if (prt->source[0]) acpi_get_handle(handle, prt->source, &entry->link); |
1da177e4c
|
213 214 215 216 217 218 219 |
/* * Type 2: Static * -------------- * The 'source' field is NULL, and the 'source_index' field specifies * the IRQ value, which is hardwired to specific interrupt inputs on * the interrupt controller. */ |
1da177e4c
|
220 221 |
ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO, |
21a53283a
|
222 223 |
" %04x:%02x:%02x[%c] -> %s[%d] ", |
4be44fcd3
|
224 |
entry->id.segment, entry->id.bus, |
cf68b80b0
|
225 |
entry->id.device, pin_name(entry->pin), |
4eaf6db3e
|
226 |
prt->source, entry->index)); |
1da177e4c
|
227 228 |
spin_lock(&acpi_prt_lock); |
3604a9f44
|
229 |
list_add_tail(&entry->list, &acpi_prt_list); |
1da177e4c
|
230 |
spin_unlock(&acpi_prt_lock); |
d550d98d3
|
231 |
return 0; |
1da177e4c
|
232 |
} |
859a3f86c
|
233 |
int acpi_pci_irq_add_prt(acpi_handle handle, struct pci_bus *bus) |
1da177e4c
|
234 |
{ |
2320ac6cb
|
235 236 237 |
acpi_status status; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_pci_routing_table *entry; |
1da177e4c
|
238 |
|
2320ac6cb
|
239 240 241 242 |
/* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */ status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); if (ACPI_FAILURE(status)) return -ENODEV; |
1da177e4c
|
243 244 245 |
printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT] ", |
2320ac6cb
|
246 |
(char *) buffer.pointer); |
1da177e4c
|
247 |
|
2320ac6cb
|
248 |
kfree(buffer.pointer); |
1da177e4c
|
249 |
|
2320ac6cb
|
250 |
buffer.length = ACPI_ALLOCATE_BUFFER; |
1da177e4c
|
251 |
buffer.pointer = NULL; |
1da177e4c
|
252 253 254 |
status = acpi_get_irq_routing_table(handle, &buffer); if (ACPI_FAILURE(status)) { |
a6fc67202
|
255 256 |
ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]", acpi_format_exception(status))); |
1da177e4c
|
257 |
kfree(buffer.pointer); |
d550d98d3
|
258 |
return -ENODEV; |
1da177e4c
|
259 |
} |
2320ac6cb
|
260 |
entry = buffer.pointer; |
1da177e4c
|
261 |
while (entry && (entry->length > 0)) { |
859a3f86c
|
262 |
acpi_pci_irq_add_entry(handle, bus, entry); |
1da177e4c
|
263 |
entry = (struct acpi_pci_routing_table *) |
4be44fcd3
|
264 |
((unsigned long)entry + entry->length); |
1da177e4c
|
265 |
} |
2320ac6cb
|
266 |
kfree(buffer.pointer); |
d550d98d3
|
267 |
return 0; |
1da177e4c
|
268 |
} |
d9efae368
|
269 |
void acpi_pci_irq_del_prt(struct pci_bus *bus) |
1da177e4c
|
270 |
{ |
3604a9f44
|
271 |
struct acpi_prt_entry *entry, *tmp; |
1da177e4c
|
272 |
|
4be44fcd3
|
273 |
printk(KERN_DEBUG |
21a53283a
|
274 275 |
"ACPI: Delete PCI Interrupt Routing Table for %04x:%02x ", |
d9efae368
|
276 |
pci_domain_nr(bus), bus->number); |
1da177e4c
|
277 |
spin_lock(&acpi_prt_lock); |
3604a9f44
|
278 |
list_for_each_entry_safe(entry, tmp, &acpi_prt_list, list) { |
d9efae368
|
279 280 |
if (pci_domain_nr(bus) == entry->id.segment && bus->number == entry->id.bus) { |
3604a9f44
|
281 282 283 |
list_del(&entry->list); kfree(entry); } |
1da177e4c
|
284 285 286 |
} spin_unlock(&acpi_prt_lock); } |
4be44fcd3
|
287 |
|
1da177e4c
|
288 289 290 |
/* -------------------------------------------------------------------------- PCI Interrupt Routing Support -------------------------------------------------------------------------- */ |
3f0f3c27b
|
291 |
static struct acpi_prt_entry *acpi_pci_irq_lookup(struct pci_dev *dev, int pin) |
1da177e4c
|
292 |
{ |
beba8a643
|
293 |
struct acpi_prt_entry *entry; |
5697b7ca4
|
294 295 |
struct pci_dev *bridge; u8 bridge_pin, orig_pin = pin; |
1da177e4c
|
296 |
|
063563b4b
|
297 |
entry = acpi_pci_irq_find_prt_entry(dev, pin); |
3b1ea18d3
|
298 299 300 |
if (entry) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %s[%c] _PRT entry ", |
1350487ee
|
301 |
pci_name(dev), pin_name(pin))); |
3b1ea18d3
|
302 |
return entry; |
1da177e4c
|
303 |
} |
4be44fcd3
|
304 |
|
1da177e4c
|
305 306 307 308 |
/* * Attempt to derive an IRQ for this device from a parent bridge's * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge). */ |
ee4013631
|
309 310 |
bridge = dev->bus->self; while (bridge) { |
c686d141c
|
311 |
pin = pci_swizzle_interrupt_pin(dev, pin); |
1da177e4c
|
312 313 314 |
if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) { /* PC card has the same IRQ as its cardbridge */ |
8015a0148
|
315 |
bridge_pin = bridge->pin; |
1da177e4c
|
316 |
if (!bridge_pin) { |
4be44fcd3
|
317 318 319 320 |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No interrupt pin configured for device %s ", pci_name(bridge))); |
beba8a643
|
321 |
return NULL; |
1da177e4c
|
322 |
} |
1da177e4c
|
323 324 |
pin = bridge_pin; } |
5697b7ca4
|
325 |
entry = acpi_pci_irq_find_prt_entry(bridge, pin); |
3b1ea18d3
|
326 327 328 329 330 331 332 333 |
if (entry) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derived GSI for %s INT %c from %s ", pci_name(dev), pin_name(orig_pin), pci_name(bridge))); return entry; } |
ee4013631
|
334 335 336 |
dev = bridge; bridge = dev->bus->self; |
1da177e4c
|
337 |
} |
3b1ea18d3
|
338 339 340 341 |
dev_warn(&dev->dev, "can't derive routing for PCI INT %c ", pin_name(orig_pin)); return NULL; |
1da177e4c
|
342 |
} |
4be44fcd3
|
343 |
int acpi_pci_irq_enable(struct pci_dev *dev) |
1da177e4c
|
344 |
{ |
beba8a643
|
345 |
struct acpi_prt_entry *entry; |
3f0f3c27b
|
346 347 |
int gsi; u8 pin; |
50eca3eb8
|
348 349 |
int triggering = ACPI_LEVEL_SENSITIVE; int polarity = ACPI_ACTIVE_LOW; |
4be44fcd3
|
350 |
char *link = NULL; |
c83642d51
|
351 |
char link_desc[16]; |
4be44fcd3
|
352 |
int rc; |
1da177e4c
|
353 |
|
8015a0148
|
354 |
pin = dev->pin; |
1da177e4c
|
355 |
if (!pin) { |
4be44fcd3
|
356 357 358 359 |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No interrupt pin configured for device %s ", pci_name(dev))); |
d550d98d3
|
360 |
return 0; |
1da177e4c
|
361 |
} |
1da177e4c
|
362 |
|
beba8a643
|
363 |
entry = acpi_pci_irq_lookup(dev, pin); |
5697b7ca4
|
364 |
if (!entry) { |
96c2a8766
|
365 366 367 368 369 370 371 372 |
/* * IDE legacy mode controller IRQs are magic. Why do compat * extensions always make such a nasty mess. */ if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE && (dev->class & 0x05) == 0) return 0; } |
5697b7ca4
|
373 |
|
74f82af1e
|
374 375 376 377 378 379 380 381 382 |
if (entry) { if (entry->link) gsi = acpi_pci_link_allocate_irq(entry->link, entry->index, &triggering, &polarity, &link); else gsi = entry->index; } else |
5697b7ca4
|
383 |
gsi = -1; |
1da177e4c
|
384 385 386 387 |
/* * No IRQ known to the ACPI subsystem - maybe the BIOS / * driver reported one, then use it. Exit in any case. */ |
c13f889a2
|
388 |
if (gsi < 0) { |
414d3448d
|
389 |
u32 dev_gsi; |
cf68b80b0
|
390 |
dev_warn(&dev->dev, "PCI INT %c: no GSI", pin_name(pin)); |
1da177e4c
|
391 |
/* Interrupt Line values above 0xF are forbidden */ |
414d3448d
|
392 393 394 395 396 |
if (dev->irq > 0 && (dev->irq <= 0xF) && (acpi_isa_irq_to_gsi(dev->irq, &dev_gsi) == 0)) { printk(" - using ISA IRQ %d ", dev->irq); acpi_register_gsi(&dev->dev, dev_gsi, |
a2f809b08
|
397 |
ACPI_LEVEL_SENSITIVE, |
4be44fcd3
|
398 |
ACPI_ACTIVE_LOW); |
d550d98d3
|
399 |
return 0; |
4be44fcd3
|
400 |
} else { |
1da177e4c
|
401 402 |
printk(" "); |
d550d98d3
|
403 |
return 0; |
1da177e4c
|
404 |
} |
4be44fcd3
|
405 |
} |
1da177e4c
|
406 |
|
a2f809b08
|
407 |
rc = acpi_register_gsi(&dev->dev, gsi, triggering, polarity); |
349f0d564
|
408 |
if (rc < 0) { |
c83642d51
|
409 410 |
dev_warn(&dev->dev, "PCI INT %c: failed to register GSI ", |
cf68b80b0
|
411 |
pin_name(pin)); |
d550d98d3
|
412 |
return rc; |
349f0d564
|
413 414 |
} dev->irq = rc; |
1da177e4c
|
415 |
|
1da177e4c
|
416 |
if (link) |
c83642d51
|
417 418 419 |
snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link); else link_desc[0] = '\0'; |
1da177e4c
|
420 |
|
c83642d51
|
421 422 |
dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d ", |
cf68b80b0
|
423 |
pin_name(pin), link_desc, gsi, |
c83642d51
|
424 425 |
(triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge", (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq); |
1da177e4c
|
426 |
|
d550d98d3
|
427 |
return 0; |
1da177e4c
|
428 |
} |
1da177e4c
|
429 |
|
87bec66b9
|
430 |
/* FIXME: implement x86/x86_64 version */ |
4be44fcd3
|
431 432 433 |
void __attribute__ ((weak)) acpi_unregister_gsi(u32 i) { } |
87bec66b9
|
434 |
|
4be44fcd3
|
435 |
void acpi_pci_irq_disable(struct pci_dev *dev) |
1da177e4c
|
436 |
{ |
beba8a643
|
437 |
struct acpi_prt_entry *entry; |
3f0f3c27b
|
438 439 |
int gsi; u8 pin; |
1da177e4c
|
440 |
|
8015a0148
|
441 |
pin = dev->pin; |
1da177e4c
|
442 |
if (!pin) |
d550d98d3
|
443 |
return; |
1da177e4c
|
444 |
|
beba8a643
|
445 |
entry = acpi_pci_irq_lookup(dev, pin); |
beba8a643
|
446 |
if (!entry) |
d550d98d3
|
447 |
return; |
1da177e4c
|
448 |
|
74f82af1e
|
449 450 451 452 |
if (entry->link) gsi = acpi_pci_link_free_irq(entry->link); else gsi = entry->index; |
beba8a643
|
453 |
|
1da177e4c
|
454 455 456 457 |
/* * TBD: It might be worth clearing dev->irq by magic constant * (e.g. PCI_UNDEFINED_IRQ). */ |
cf68b80b0
|
458 459 |
dev_info(&dev->dev, "PCI INT %c disabled ", pin_name(pin)); |
1da177e4c
|
460 |
acpi_unregister_gsi(gsi); |
1da177e4c
|
461 |
} |