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