Blame view
drivers/acpi/pci_link.c
24.2 KB
1da177e4c
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/* * pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $) * * 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> * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 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. * |
1da177e4c
|
20 21 22 23 24 25 26 |
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * TBD: * 1. Support more than one IRQ resource entry per link device (index). * 2. Implement start/stop mechanism and use ACPI Bus Driver facilities * for IRQ management (e.g. start()->_SRS). */ |
c3146df2b
|
27 |
#include <linux/syscore_ops.h> |
1da177e4c
|
28 29 30 31 |
#include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/types.h> |
1da177e4c
|
32 33 34 |
#include <linux/spinlock.h> #include <linux/pm.h> #include <linux/pci.h> |
36e430951
|
35 |
#include <linux/mutex.h> |
5a0e3ad6a
|
36 |
#include <linux/slab.h> |
8b48463f8
|
37 |
#include <linux/acpi.h> |
103544d86
|
38 |
#include <linux/irq.h> |
1da177e4c
|
39 |
|
c071b6040
|
40 |
#include "internal.h" |
1c9ca3a7d
|
41 |
#define _COMPONENT ACPI_PCI_COMPONENT |
f52fd66d2
|
42 |
ACPI_MODULE_NAME("pci_link"); |
1da177e4c
|
43 |
#define ACPI_PCI_LINK_CLASS "pci_irq_routing" |
1da177e4c
|
44 45 46 |
#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link" #define ACPI_PCI_LINK_FILE_INFO "info" #define ACPI_PCI_LINK_FILE_STATUS "state" |
1c9ca3a7d
|
47 |
#define ACPI_PCI_LINK_MAX_POSSIBLE 16 |
4daeaf683
|
48 49 50 |
static int acpi_pci_link_add(struct acpi_device *device, const struct acpi_device_id *not_used); static void acpi_pci_link_remove(struct acpi_device *device); |
1da177e4c
|
51 |
|
c97adf9e7
|
52 |
static const struct acpi_device_id link_device_ids[] = { |
1ba90e3a8
|
53 54 55 |
{"PNP0C0F", 0}, {"", 0}, }; |
1ba90e3a8
|
56 |
|
4daeaf683
|
57 |
static struct acpi_scan_handler pci_link_handler = { |
1ba90e3a8
|
58 |
.ids = link_device_ids, |
4daeaf683
|
59 60 |
.attach = acpi_pci_link_add, .detach = acpi_pci_link_remove, |
1da177e4c
|
61 |
}; |
87bec66b9
|
62 63 64 65 |
/* * If a link is initialized, we never change its active and initialized * later even the link is disable. Instead, we just repick the active irq */ |
1da177e4c
|
66 |
struct acpi_pci_link_irq { |
37c593913
|
67 |
u32 active; /* Current IRQ */ |
50eca3eb8
|
68 |
u8 triggering; /* All IRQs */ |
1c9ca3a7d
|
69 |
u8 polarity; /* All IRQs */ |
4be44fcd3
|
70 71 |
u8 resource_type; u8 possible_count; |
37c593913
|
72 |
u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; |
4be44fcd3
|
73 74 |
u8 initialized:1; u8 reserved:7; |
1da177e4c
|
75 76 77 |
}; struct acpi_pci_link { |
5f0dccaa8
|
78 |
struct list_head list; |
1c9ca3a7d
|
79 80 81 |
struct acpi_device *device; struct acpi_pci_link_irq irq; int refcnt; |
1da177e4c
|
82 |
}; |
5f0dccaa8
|
83 |
static LIST_HEAD(acpi_link_list); |
e5685b9d3
|
84 |
static DEFINE_MUTEX(acpi_link_lock); |
f1caa61df
|
85 |
static int sci_irq = -1, sci_penalty; |
1da177e4c
|
86 |
|
1da177e4c
|
87 88 89 90 91 92 93 |
/* -------------------------------------------------------------------------- PCI Link Device Management -------------------------------------------------------------------------- */ /* * set context (link) possible list from resource list */ |
1c9ca3a7d
|
94 95 |
static acpi_status acpi_pci_link_check_possible(struct acpi_resource *resource, void *context) |
1da177e4c
|
96 |
{ |
50dd09697
|
97 |
struct acpi_pci_link *link = context; |
c9d624432
|
98 |
u32 i; |
1da177e4c
|
99 |
|
eca008c81
|
100 |
switch (resource->type) { |
50eca3eb8
|
101 |
case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
4a5e3638b
|
102 |
case ACPI_RESOURCE_TYPE_END_TAG: |
d550d98d3
|
103 |
return AE_OK; |
50eca3eb8
|
104 |
case ACPI_RESOURCE_TYPE_IRQ: |
4be44fcd3
|
105 106 |
{ struct acpi_resource_irq *p = &resource->data.irq; |
50eca3eb8
|
107 |
if (!p || !p->interrupt_count) { |
4a5e3638b
|
108 109 110 |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Blank _PRS IRQ resource ")); |
d550d98d3
|
111 |
return AE_OK; |
1da177e4c
|
112 |
} |
4be44fcd3
|
113 |
for (i = 0; |
50eca3eb8
|
114 |
(i < p->interrupt_count |
4be44fcd3
|
115 116 |
&& i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { if (!p->interrupts[i]) { |
4a5e3638b
|
117 118 119 120 |
printk(KERN_WARNING PREFIX "Invalid _PRS IRQ %d ", p->interrupts[i]); |
4be44fcd3
|
121 122 123 124 125 |
continue; } link->irq.possible[i] = p->interrupts[i]; link->irq.possible_count++; } |
50eca3eb8
|
126 127 128 |
link->irq.triggering = p->triggering; link->irq.polarity = p->polarity; link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ; |
4be44fcd3
|
129 |
break; |
1da177e4c
|
130 |
} |
50eca3eb8
|
131 |
case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
4be44fcd3
|
132 |
{ |
50eca3eb8
|
133 |
struct acpi_resource_extended_irq *p = |
4be44fcd3
|
134 |
&resource->data.extended_irq; |
50eca3eb8
|
135 |
if (!p || !p->interrupt_count) { |
cece92969
|
136 |
printk(KERN_WARNING PREFIX |
4a5e3638b
|
137 138 |
"Blank _PRS EXT IRQ resource "); |
d550d98d3
|
139 |
return AE_OK; |
4be44fcd3
|
140 141 |
} for (i = 0; |
50eca3eb8
|
142 |
(i < p->interrupt_count |
4be44fcd3
|
143 144 |
&& i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { if (!p->interrupts[i]) { |
4a5e3638b
|
145 146 147 148 |
printk(KERN_WARNING PREFIX "Invalid _PRS IRQ %d ", p->interrupts[i]); |
4be44fcd3
|
149 150 151 152 |
continue; } link->irq.possible[i] = p->interrupts[i]; link->irq.possible_count++; |
1da177e4c
|
153 |
} |
50eca3eb8
|
154 155 156 |
link->irq.triggering = p->triggering; link->irq.polarity = p->polarity; link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; |
4be44fcd3
|
157 |
break; |
1da177e4c
|
158 |
} |
1da177e4c
|
159 |
default: |
4a5e3638b
|
160 161 162 |
printk(KERN_ERR PREFIX "_PRS resource type 0x%x isn't an IRQ ", resource->type); |
d550d98d3
|
163 |
return AE_OK; |
1da177e4c
|
164 |
} |
d550d98d3
|
165 |
return AE_CTRL_TERMINATE; |
1da177e4c
|
166 |
} |
4be44fcd3
|
167 |
static int acpi_pci_link_get_possible(struct acpi_pci_link *link) |
1da177e4c
|
168 |
{ |
4be44fcd3
|
169 |
acpi_status status; |
1da177e4c
|
170 |
|
67a713657
|
171 |
status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS, |
4be44fcd3
|
172 |
acpi_pci_link_check_possible, link); |
1da177e4c
|
173 |
if (ACPI_FAILURE(status)) { |
a6fc67202
|
174 |
ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS")); |
d550d98d3
|
175 |
return -ENODEV; |
1da177e4c
|
176 |
} |
4be44fcd3
|
177 178 179 180 |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d possible IRQs ", link->irq.possible_count)); |
1da177e4c
|
181 |
|
d550d98d3
|
182 |
return 0; |
1da177e4c
|
183 |
} |
1c9ca3a7d
|
184 185 |
static acpi_status acpi_pci_link_check_current(struct acpi_resource *resource, void *context) |
1da177e4c
|
186 |
{ |
c9d624432
|
187 |
int *irq = context; |
1da177e4c
|
188 |
|
eca008c81
|
189 |
switch (resource->type) { |
4a5e3638b
|
190 191 192 |
case ACPI_RESOURCE_TYPE_START_DEPENDENT: case ACPI_RESOURCE_TYPE_END_TAG: return AE_OK; |
50eca3eb8
|
193 |
case ACPI_RESOURCE_TYPE_IRQ: |
4be44fcd3
|
194 195 |
{ struct acpi_resource_irq *p = &resource->data.irq; |
50eca3eb8
|
196 |
if (!p || !p->interrupt_count) { |
4be44fcd3
|
197 198 199 200 201 |
/* * IRQ descriptors may have no IRQ# bits set, * particularly those those w/ _STA disabled */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
4a5e3638b
|
202 203 |
"Blank _CRS IRQ resource ")); |
d550d98d3
|
204 |
return AE_OK; |
4be44fcd3
|
205 206 207 |
} *irq = p->interrupts[0]; break; |
1da177e4c
|
208 |
} |
50eca3eb8
|
209 |
case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
4be44fcd3
|
210 |
{ |
50eca3eb8
|
211 |
struct acpi_resource_extended_irq *p = |
4be44fcd3
|
212 |
&resource->data.extended_irq; |
50eca3eb8
|
213 |
if (!p || !p->interrupt_count) { |
4be44fcd3
|
214 215 216 217 |
/* * extended IRQ descriptors must * return at least 1 IRQ */ |
cece92969
|
218 |
printk(KERN_WARNING PREFIX |
4a5e3638b
|
219 220 |
"Blank _CRS EXT IRQ resource "); |
d550d98d3
|
221 |
return AE_OK; |
4be44fcd3
|
222 223 224 |
} *irq = p->interrupts[0]; break; |
1da177e4c
|
225 |
} |
d4ec6c7cc
|
226 |
break; |
1da177e4c
|
227 |
default: |
4a5e3638b
|
228 229 230 |
printk(KERN_ERR PREFIX "_CRS resource type 0x%x isn't an IRQ ", resource->type); |
d550d98d3
|
231 |
return AE_OK; |
1da177e4c
|
232 |
} |
4a5e3638b
|
233 |
|
d550d98d3
|
234 |
return AE_CTRL_TERMINATE; |
1da177e4c
|
235 236 237 238 239 240 241 242 243 |
} /* * Run _CRS and set link->irq.active * * return value: * 0 - success * !0 - failure */ |
4be44fcd3
|
244 |
static int acpi_pci_link_get_current(struct acpi_pci_link *link) |
1da177e4c
|
245 |
{ |
4be44fcd3
|
246 |
int result = 0; |
c9d624432
|
247 |
acpi_status status; |
4be44fcd3
|
248 |
int irq = 0; |
1da177e4c
|
249 |
|
1da177e4c
|
250 251 252 253 254 255 256 |
link->irq.active = 0; /* in practice, status disabled is meaningless, ignore it */ if (acpi_strict) { /* Query _STA, set link->device->status */ result = acpi_bus_get_status(link->device); if (result) { |
6468463ab
|
257 258 |
printk(KERN_ERR PREFIX "Unable to read status "); |
1da177e4c
|
259 260 261 262 263 264 |
goto end; } if (!link->device->status.enabled) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled ")); |
d550d98d3
|
265 |
return 0; |
1da177e4c
|
266 267 268 269 270 271 |
} } /* * Query and parse _CRS to get the current IRQ assignment. */ |
67a713657
|
272 |
status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS, |
4be44fcd3
|
273 |
acpi_pci_link_check_current, &irq); |
1da177e4c
|
274 |
if (ACPI_FAILURE(status)) { |
a6fc67202
|
275 |
ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS")); |
1da177e4c
|
276 277 278 279 280 |
result = -ENODEV; goto end; } if (acpi_strict && !irq) { |
6468463ab
|
281 282 |
printk(KERN_ERR PREFIX "_CRS returned 0 "); |
1da177e4c
|
283 284 285 286 287 288 289 |
result = -ENODEV; } link->irq.active = irq; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d ", link->irq.active)); |
4be44fcd3
|
290 |
end: |
d550d98d3
|
291 |
return result; |
1da177e4c
|
292 |
} |
4be44fcd3
|
293 |
static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) |
1da177e4c
|
294 |
{ |
c9d624432
|
295 296 |
int result; acpi_status status; |
1da177e4c
|
297 |
struct { |
4be44fcd3
|
298 299 300 301 |
struct acpi_resource res; struct acpi_resource end; } *resource; struct acpi_buffer buffer = { 0, NULL }; |
1da177e4c
|
302 |
|
6eca4b4ca
|
303 |
if (!irq) |
d550d98d3
|
304 |
return -EINVAL; |
1da177e4c
|
305 |
|
36bcbec7c
|
306 |
resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); |
4be44fcd3
|
307 |
if (!resource) |
d550d98d3
|
308 |
return -ENOMEM; |
1da177e4c
|
309 |
|
4be44fcd3
|
310 |
buffer.length = sizeof(*resource) + 1; |
1da177e4c
|
311 |
buffer.pointer = resource; |
4be44fcd3
|
312 |
switch (link->irq.resource_type) { |
50eca3eb8
|
313 314 |
case ACPI_RESOURCE_TYPE_IRQ: resource->res.type = ACPI_RESOURCE_TYPE_IRQ; |
1da177e4c
|
315 |
resource->res.length = sizeof(struct acpi_resource); |
50eca3eb8
|
316 317 318 319 320 |
resource->res.data.irq.triggering = link->irq.triggering; resource->res.data.irq.polarity = link->irq.polarity; if (link->irq.triggering == ACPI_EDGE_SENSITIVE) resource->res.data.irq.sharable = |
4be44fcd3
|
321 |
ACPI_EXCLUSIVE; |
1da177e4c
|
322 |
else |
50eca3eb8
|
323 324 |
resource->res.data.irq.sharable = ACPI_SHARED; resource->res.data.irq.interrupt_count = 1; |
1da177e4c
|
325 326 |
resource->res.data.irq.interrupts[0] = irq; break; |
4be44fcd3
|
327 |
|
50eca3eb8
|
328 329 |
case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; |
1da177e4c
|
330 |
resource->res.length = sizeof(struct acpi_resource); |
4be44fcd3
|
331 332 |
resource->res.data.extended_irq.producer_consumer = ACPI_CONSUMER; |
50eca3eb8
|
333 334 335 336 337 338 |
resource->res.data.extended_irq.triggering = link->irq.triggering; resource->res.data.extended_irq.polarity = link->irq.polarity; if (link->irq.triggering == ACPI_EDGE_SENSITIVE) resource->res.data.irq.sharable = |
4be44fcd3
|
339 |
ACPI_EXCLUSIVE; |
1da177e4c
|
340 |
else |
50eca3eb8
|
341 342 |
resource->res.data.irq.sharable = ACPI_SHARED; resource->res.data.extended_irq.interrupt_count = 1; |
1da177e4c
|
343 344 345 346 |
resource->res.data.extended_irq.interrupts[0] = irq; /* ignore resource_source, it's optional */ break; default: |
6468463ab
|
347 348 |
printk(KERN_ERR PREFIX "Invalid Resource_type %d ", link->irq.resource_type); |
1da177e4c
|
349 350 351 352 |
result = -EINVAL; goto end; } |
50eca3eb8
|
353 |
resource->end.type = ACPI_RESOURCE_TYPE_END_TAG; |
f084dbb93
|
354 |
resource->end.length = sizeof(struct acpi_resource); |
1da177e4c
|
355 356 |
/* Attempt to set the resource */ |
67a713657
|
357 |
status = acpi_set_current_resources(link->device->handle, &buffer); |
1da177e4c
|
358 359 360 |
/* check for total failure */ if (ACPI_FAILURE(status)) { |
a6fc67202
|
361 |
ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS")); |
1da177e4c
|
362 363 364 365 366 367 368 |
result = -ENODEV; goto end; } /* Query _STA, set device->status */ result = acpi_bus_get_status(link->device); if (result) { |
6468463ab
|
369 370 |
printk(KERN_ERR PREFIX "Unable to read status "); |
1da177e4c
|
371 372 373 |
goto end; } if (!link->device->status.enabled) { |
cece92969
|
374 375 376 |
printk(KERN_WARNING PREFIX "%s [%s] disabled and referenced, BIOS bug ", |
a6fc67202
|
377 |
acpi_device_name(link->device), |
cece92969
|
378 |
acpi_device_bid(link->device)); |
1da177e4c
|
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
} /* Query _CRS, set link->irq.active */ result = acpi_pci_link_get_current(link); if (result) { goto end; } /* * Is current setting not what we set? * set link->irq.active */ if (link->irq.active != irq) { /* * policy: when _CRS doesn't return what we just _SRS * assume _SRS worked and override _CRS value. */ |
cece92969
|
396 397 398 |
printk(KERN_WARNING PREFIX "%s [%s] BIOS reported IRQ %d, using IRQ %d ", |
a6fc67202
|
399 |
acpi_device_name(link->device), |
cece92969
|
400 |
acpi_device_bid(link->device), link->irq.active, irq); |
1da177e4c
|
401 402 403 404 405 |
link->irq.active = irq; } ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d ", link->irq.active)); |
4be44fcd3
|
406 407 |
end: |
1da177e4c
|
408 |
kfree(resource); |
d550d98d3
|
409 |
return result; |
1da177e4c
|
410 |
} |
1da177e4c
|
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
/* -------------------------------------------------------------------------- PCI Link IRQ Management -------------------------------------------------------------------------- */ /* * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt * Link Devices to move the PIRQs around to minimize sharing. * * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs * that the BIOS has already set to active. This is necessary because * ACPI has no automatic means of knowing what ISA IRQs are used. Note that * if the BIOS doesn't set a Link Device active, ACPI needs to program it * even if acpi_irq_nobalance is set. * * A tables of penalties avoids directing PCI interrupts to well known * ISA IRQs. Boot params are available to over-ride the default table: * * List interrupts that are free for PCI use. * acpi_irq_pci=n[,m] * * List interrupts that should not be used for PCI: * acpi_irq_isa=n[,m] * * Note that PCI IRQ routers have a list of possible IRQs, * which may not include the IRQs this table says are available. * * Since this heuristic can't tell the difference between a link * that no device will attach to, vs. a link which may be shared * by multiple active devices -- it is not optimal. * * If interrupt performance is that important, get an IO-APIC system * with a pin dedicated to each device. Or for that matter, an MSI * enabled system. */ |
5c5087a55
|
445 |
#define ACPI_MAX_ISA_IRQS 16 |
1da177e4c
|
446 |
|
1da177e4c
|
447 448 449 450 451 |
#define PIRQ_PENALTY_PCI_POSSIBLE (16*16) #define PIRQ_PENALTY_PCI_USING (16*16*16) #define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16) #define PIRQ_PENALTY_ISA_USED (16*16*16*16*16) #define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16) |
5c5087a55
|
452 |
static int acpi_isa_irq_penalty[ACPI_MAX_ISA_IRQS] = { |
1da177e4c
|
453 454 455 |
PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */ PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */ PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */ |
4be44fcd3
|
456 457 |
PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */ PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */ |
1da177e4c
|
458 459 460 461 |
PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */ PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */ PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */ PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */ |
103544d86
|
462 463 464 |
0, /* IRQ9 PCI, often acpi */ 0, /* IRQ10 PCI */ 0, /* IRQ11 PCI */ |
1c9ca3a7d
|
465 466 467 468 |
PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */ PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */ PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */ PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */ |
e24971457
|
469 |
/* >IRQ15 */ |
1da177e4c
|
470 |
}; |
103544d86
|
471 472 473 474 |
static int acpi_irq_pci_sharing_penalty(int irq) { struct acpi_pci_link *link; int penalty = 0; |
4a6e68bf9
|
475 |
int i; |
103544d86
|
476 477 478 479 480 481 482 483 |
list_for_each_entry(link, &acpi_link_list, list) { /* * If a link is active, penalize its IRQ heavily * so we try to choose a different IRQ. */ if (link->irq.active && link->irq.active == irq) penalty += PIRQ_PENALTY_PCI_USING; |
4a6e68bf9
|
484 485 486 487 488 489 490 491 |
/* * penalize the IRQs PCI might use, but not as severely. */ for (i = 0; i < link->irq.possible_count; i++) if (link->irq.possible[i] == irq) penalty += PIRQ_PENALTY_PCI_POSSIBLE / link->irq.possible_count; |
103544d86
|
492 493 494 495 496 497 498 499 |
} return penalty; } static int acpi_irq_get_penalty(int irq) { int penalty = 0; |
f1caa61df
|
500 501 |
if (irq == sci_irq) penalty += sci_penalty; |
103544d86
|
502 |
|
f7eca374f
|
503 504 |
if (irq < ACPI_MAX_ISA_IRQS) return penalty + acpi_isa_irq_penalty[irq]; |
f1caa61df
|
505 |
return penalty + acpi_irq_pci_sharing_penalty(irq); |
103544d86
|
506 |
} |
487cf917e
|
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
int __init acpi_irq_penalty_init(void) { struct acpi_pci_link *link; int i; /* * Update penalties to facilitate IRQ balancing. */ list_for_each_entry(link, &acpi_link_list, list) { /* * reflect the possible and active irqs in the penalty table -- * useful for breaking ties. */ if (link->irq.possible_count) { int penalty = PIRQ_PENALTY_PCI_POSSIBLE / link->irq.possible_count; for (i = 0; i < link->irq.possible_count; i++) { if (link->irq.possible[i] < ACPI_MAX_ISA_IRQS) acpi_isa_irq_penalty[link->irq. possible[i]] += penalty; } } else if (link->irq.active && (link->irq.active < ACPI_MAX_ISA_IRQS)) { acpi_isa_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_POSSIBLE; } } return 0; } |
32836259f
|
542 |
static int acpi_irq_balance = -1; /* 0: static, 1: balance */ |
1da177e4c
|
543 |
|
4be44fcd3
|
544 |
static int acpi_pci_link_allocate(struct acpi_pci_link *link) |
1da177e4c
|
545 |
{ |
4be44fcd3
|
546 547 |
int irq; int i; |
1da177e4c
|
548 |
|
87bec66b9
|
549 550 551 552 |
if (link->irq.initialized) { if (link->refcnt == 0) /* This means the link is disabled but initialized */ acpi_pci_link_set(link, link->irq.active); |
d550d98d3
|
553 |
return 0; |
87bec66b9
|
554 |
} |
1da177e4c
|
555 556 557 558 559 560 561 562 563 564 565 566 567 |
/* * search for active IRQ in list of possible IRQs. */ for (i = 0; i < link->irq.possible_count; ++i) { if (link->irq.active == link->irq.possible[i]) break; } /* * forget active IRQ that is not in possible list */ if (i == link->irq.possible_count) { if (acpi_strict) |
cece92969
|
568 569 570 |
printk(KERN_WARNING PREFIX "_CRS %d not found" " in _PRS ", link->irq.active); |
1da177e4c
|
571 572 573 574 575 576 |
link->irq.active = 0; } /* * if active found, use it; else pick entry from end of possible list. */ |
1c9ca3a7d
|
577 |
if (link->irq.active) |
1da177e4c
|
578 |
irq = link->irq.active; |
1c9ca3a7d
|
579 |
else |
1da177e4c
|
580 |
irq = link->irq.possible[link->irq.possible_count - 1]; |
1da177e4c
|
581 582 583 584 585 586 587 |
if (acpi_irq_balance || !link->irq.active) { /* * Select the best IRQ. This is done in reverse to promote * the use of IRQs 9, 10, 11, and >15. */ for (i = (link->irq.possible_count - 1); i >= 0; i--) { |
103544d86
|
588 589 |
if (acpi_irq_get_penalty(irq) > acpi_irq_get_penalty(link->irq.possible[i])) |
1da177e4c
|
590 591 592 |
irq = link->irq.possible[i]; } } |
103544d86
|
593 |
if (acpi_irq_get_penalty(irq) >= PIRQ_PENALTY_ISA_ALWAYS) { |
5ebc76035
|
594 595 596 597 598 599 600 |
printk(KERN_ERR PREFIX "No IRQ available for %s [%s]. " "Try pci=noacpi or acpi=off ", acpi_device_name(link->device), acpi_device_bid(link->device)); return -ENODEV; } |
1da177e4c
|
601 602 603 |
/* Attempt to enable the link device at this IRQ. */ if (acpi_pci_link_set(link, irq)) { |
6468463ab
|
604 605 606 |
printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. " "Try pci=noacpi or acpi=off ", |
a6fc67202
|
607 |
acpi_device_name(link->device), |
6468463ab
|
608 |
acpi_device_bid(link->device)); |
d550d98d3
|
609 |
return -ENODEV; |
1da177e4c
|
610 |
} else { |
98756f531
|
611 612 613 |
if (link->irq.active < ACPI_MAX_ISA_IRQS) acpi_isa_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING; |
4d9391557
|
614 615 |
printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d ", |
4be44fcd3
|
616 617 |
acpi_device_name(link->device), acpi_device_bid(link->device), link->irq.active); |
1da177e4c
|
618 619 620 |
} link->irq.initialized = 1; |
d550d98d3
|
621 |
return 0; |
1da177e4c
|
622 623 624 |
} /* |
87bec66b9
|
625 |
* acpi_pci_link_allocate_irq |
1da177e4c
|
626 627 628 |
* success: return IRQ >= 0 * failure: return -1 */ |
1c9ca3a7d
|
629 630 |
int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering, int *polarity, char **name) |
1da177e4c
|
631 |
{ |
c9d624432
|
632 633 634 |
int result; struct acpi_device *device; struct acpi_pci_link *link; |
1da177e4c
|
635 |
|
1da177e4c
|
636 637 |
result = acpi_bus_get_device(handle, &device); if (result) { |
6468463ab
|
638 639 |
printk(KERN_ERR PREFIX "Invalid link device "); |
d550d98d3
|
640 |
return -1; |
1da177e4c
|
641 |
} |
50dd09697
|
642 |
link = acpi_driver_data(device); |
1da177e4c
|
643 |
if (!link) { |
6468463ab
|
644 645 |
printk(KERN_ERR PREFIX "Invalid link context "); |
d550d98d3
|
646 |
return -1; |
1da177e4c
|
647 648 649 650 |
} /* TBD: Support multiple index (IRQ) entries per Link Device */ if (index) { |
6468463ab
|
651 652 |
printk(KERN_ERR PREFIX "Invalid index %d ", index); |
d550d98d3
|
653 |
return -1; |
1da177e4c
|
654 |
} |
36e430951
|
655 |
mutex_lock(&acpi_link_lock); |
87bec66b9
|
656 |
if (acpi_pci_link_allocate(link)) { |
36e430951
|
657 |
mutex_unlock(&acpi_link_lock); |
d550d98d3
|
658 |
return -1; |
87bec66b9
|
659 |
} |
4be44fcd3
|
660 |
|
1da177e4c
|
661 |
if (!link->irq.active) { |
36e430951
|
662 |
mutex_unlock(&acpi_link_lock); |
6468463ab
|
663 664 |
printk(KERN_ERR PREFIX "Link active IRQ is 0! "); |
d550d98d3
|
665 |
return -1; |
1da177e4c
|
666 |
} |
4be44fcd3
|
667 |
link->refcnt++; |
36e430951
|
668 |
mutex_unlock(&acpi_link_lock); |
1da177e4c
|
669 |
|
50eca3eb8
|
670 671 672 673 |
if (triggering) *triggering = link->irq.triggering; if (polarity) *polarity = link->irq.polarity; |
4be44fcd3
|
674 675 |
if (name) *name = acpi_device_bid(link->device); |
87bec66b9
|
676 |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
4be44fcd3
|
677 678 679 |
"Link %s is referenced ", acpi_device_bid(link->device))); |
d550d98d3
|
680 |
return (link->irq.active); |
1da177e4c
|
681 |
} |
87bec66b9
|
682 683 684 685 |
/* * We don't change link's irq information here. After it is reenabled, we * continue use the info */ |
4be44fcd3
|
686 |
int acpi_pci_link_free_irq(acpi_handle handle) |
87bec66b9
|
687 |
{ |
c9d624432
|
688 689 |
struct acpi_device *device; struct acpi_pci_link *link; |
4be44fcd3
|
690 |
acpi_status result; |
87bec66b9
|
691 |
|
87bec66b9
|
692 693 |
result = acpi_bus_get_device(handle, &device); if (result) { |
6468463ab
|
694 695 |
printk(KERN_ERR PREFIX "Invalid link device "); |
d550d98d3
|
696 |
return -1; |
87bec66b9
|
697 |
} |
1da177e4c
|
698 |
|
50dd09697
|
699 |
link = acpi_driver_data(device); |
87bec66b9
|
700 |
if (!link) { |
6468463ab
|
701 702 |
printk(KERN_ERR PREFIX "Invalid link context "); |
d550d98d3
|
703 |
return -1; |
87bec66b9
|
704 |
} |
36e430951
|
705 |
mutex_lock(&acpi_link_lock); |
87bec66b9
|
706 |
if (!link->irq.initialized) { |
36e430951
|
707 |
mutex_unlock(&acpi_link_lock); |
6468463ab
|
708 709 |
printk(KERN_ERR PREFIX "Link isn't initialized "); |
d550d98d3
|
710 |
return -1; |
87bec66b9
|
711 |
} |
ecc21ebe6
|
712 713 714 715 716 717 718 719 720 721 |
#ifdef FUTURE_USE /* * The Link reference count allows us to _DISable an unused link * and suspend time, and set it again on resume. * However, 2.6.12 still has irq_router.resume * which blindly restores the link state. * So we disable the reference count method * to prevent duplicate acpi_pci_link_set() * which would harm some systems */ |
4be44fcd3
|
722 |
link->refcnt--; |
ecc21ebe6
|
723 |
#endif |
87bec66b9
|
724 |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
4be44fcd3
|
725 726 727 |
"Link %s is dereferenced ", acpi_device_bid(link->device))); |
87bec66b9
|
728 |
|
1c9ca3a7d
|
729 |
if (link->refcnt == 0) |
383d7a11c
|
730 |
acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL); |
1c9ca3a7d
|
731 |
|
36e430951
|
732 |
mutex_unlock(&acpi_link_lock); |
d550d98d3
|
733 |
return (link->irq.active); |
87bec66b9
|
734 |
} |
4be44fcd3
|
735 |
|
1da177e4c
|
736 737 738 |
/* -------------------------------------------------------------------------- Driver Interface -------------------------------------------------------------------------- */ |
4daeaf683
|
739 740 |
static int acpi_pci_link_add(struct acpi_device *device, const struct acpi_device_id *not_used) |
1da177e4c
|
741 |
{ |
c9d624432
|
742 743 744 |
int result; struct acpi_pci_link *link; int i; |
4be44fcd3
|
745 |
int found = 0; |
1da177e4c
|
746 |
|
36bcbec7c
|
747 |
link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL); |
1da177e4c
|
748 |
if (!link) |
d550d98d3
|
749 |
return -ENOMEM; |
1da177e4c
|
750 751 |
link->device = device; |
1da177e4c
|
752 753 |
strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); |
db89b4f0d
|
754 |
device->driver_data = link; |
1da177e4c
|
755 |
|
36e430951
|
756 |
mutex_lock(&acpi_link_lock); |
1da177e4c
|
757 758 759 760 761 762 |
result = acpi_pci_link_get_possible(link); if (result) goto end; /* query and set link->irq.active */ acpi_pci_link_get_current(link); |
0dc070bb0
|
763 |
printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device), |
4be44fcd3
|
764 |
acpi_device_bid(device)); |
1da177e4c
|
765 766 |
for (i = 0; i < link->irq.possible_count; i++) { if (link->irq.active == link->irq.possible[i]) { |
be96447e0
|
767 |
printk(KERN_CONT " *%d", link->irq.possible[i]); |
1da177e4c
|
768 |
found = 1; |
4be44fcd3
|
769 |
} else |
be96447e0
|
770 |
printk(KERN_CONT " %d", link->irq.possible[i]); |
1da177e4c
|
771 |
} |
be96447e0
|
772 |
printk(KERN_CONT ")"); |
1da177e4c
|
773 774 |
if (!found) |
be96447e0
|
775 |
printk(KERN_CONT " *%d", link->irq.active); |
1da177e4c
|
776 |
|
4be44fcd3
|
777 |
if (!link->device->status.enabled) |
be96447e0
|
778 |
printk(KERN_CONT ", disabled."); |
1da177e4c
|
779 |
|
be96447e0
|
780 781 |
printk(KERN_CONT " "); |
1da177e4c
|
782 |
|
5f0dccaa8
|
783 |
list_add_tail(&link->list, &acpi_link_list); |
1da177e4c
|
784 |
|
4be44fcd3
|
785 |
end: |
1da177e4c
|
786 |
/* disable all links -- to be activated on use */ |
383d7a11c
|
787 |
acpi_evaluate_object(device->handle, "_DIS", NULL, NULL); |
36e430951
|
788 |
mutex_unlock(&acpi_link_lock); |
1da177e4c
|
789 790 791 |
if (result) kfree(link); |
4daeaf683
|
792 |
return result < 0 ? result : 1; |
1da177e4c
|
793 |
} |
4be44fcd3
|
794 |
static int acpi_pci_link_resume(struct acpi_pci_link *link) |
697a2d63a
|
795 |
{ |
697a2d63a
|
796 |
if (link->refcnt && link->irq.active && link->irq.initialized) |
d550d98d3
|
797 |
return (acpi_pci_link_set(link, link->irq.active)); |
1c9ca3a7d
|
798 799 |
return 0; |
697a2d63a
|
800 |
} |
c3146df2b
|
801 |
static void irqrouter_resume(void) |
1da177e4c
|
802 |
{ |
c9d624432
|
803 |
struct acpi_pci_link *link; |
1da177e4c
|
804 |
|
5f0dccaa8
|
805 |
list_for_each_entry(link, &acpi_link_list, list) { |
697a2d63a
|
806 |
acpi_pci_link_resume(link); |
1da177e4c
|
807 |
} |
1da177e4c
|
808 |
} |
4daeaf683
|
809 |
static void acpi_pci_link_remove(struct acpi_device *device) |
1da177e4c
|
810 |
{ |
c9d624432
|
811 |
struct acpi_pci_link *link; |
1da177e4c
|
812 |
|
50dd09697
|
813 |
link = acpi_driver_data(device); |
1da177e4c
|
814 |
|
36e430951
|
815 |
mutex_lock(&acpi_link_lock); |
5f0dccaa8
|
816 |
list_del(&link->list); |
36e430951
|
817 |
mutex_unlock(&acpi_link_lock); |
1da177e4c
|
818 819 |
kfree(link); |
1da177e4c
|
820 821 822 |
} /* |
5c5087a55
|
823 |
* modify acpi_isa_irq_penalty[] from cmdline |
1da177e4c
|
824 825 826 827 828 829 830 831 |
*/ static int __init acpi_irq_penalty_update(char *str, int used) { int i; for (i = 0; i < 16; i++) { int retval; int irq; |
5c5087a55
|
832 |
int new_penalty; |
1da177e4c
|
833 |
|
4be44fcd3
|
834 |
retval = get_option(&str, &irq); |
1da177e4c
|
835 836 837 |
if (!retval) break; /* no number found */ |
5c5087a55
|
838 839 |
/* see if this is a ISA IRQ */ if ((irq < 0) || (irq >= ACPI_MAX_ISA_IRQS)) |
e24971457
|
840 |
continue; |
1da177e4c
|
841 |
if (used) |
eeaed4bb5
|
842 |
new_penalty = acpi_isa_irq_penalty[irq] + |
5c5087a55
|
843 |
PIRQ_PENALTY_ISA_USED; |
1da177e4c
|
844 |
else |
5c5087a55
|
845 |
new_penalty = 0; |
1da177e4c
|
846 |
|
5c5087a55
|
847 |
acpi_isa_irq_penalty[irq] = new_penalty; |
1da177e4c
|
848 849 850 851 852 853 854 855 856 857 858 859 860 |
if (retval != 2) /* no next number */ break; } return 1; } /* * We'd like PNP to call this routine for the * single ISA_USED value for each legacy device. * But instead it calls us with each POSSIBLE setting. * There is no ISA_POSSIBLE weight, so we simply use * the (small) PCI_USING penalty. */ |
c9c3e457d
|
861 |
void acpi_penalize_isa_irq(int irq, int active) |
1da177e4c
|
862 |
{ |
5c5087a55
|
863 |
if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty))) |
eeaed4bb5
|
864 |
acpi_isa_irq_penalty[irq] += |
54794580f
|
865 |
(active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING); |
1da177e4c
|
866 |
} |
5ebc76035
|
867 868 |
bool acpi_isa_irq_available(int irq) { |
5c5087a55
|
869 |
return irq >= 0 && (irq >= ARRAY_SIZE(acpi_isa_irq_penalty) || |
103544d86
|
870 |
acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS); |
5ebc76035
|
871 |
} |
f1caa61df
|
872 873 874 875 876 877 878 879 880 881 |
void acpi_penalize_sci_irq(int irq, int trigger, int polarity) { sci_irq = irq; if (trigger == ACPI_MADT_TRIGGER_LEVEL && polarity == ACPI_MADT_POLARITY_ACTIVE_LOW) sci_penalty = PIRQ_PENALTY_PCI_USING; else sci_penalty = PIRQ_PENALTY_ISA_ALWAYS; } |
5d0ddfebb
|
882 |
/* |
1da177e4c
|
883 884 885 886 887 888 889 890 |
* Over-ride default table to reserve additional IRQs for use by ISA * e.g. acpi_irq_isa=5 * Useful for telling ACPI how not to interfere with your ISA sound card. */ static int __init acpi_irq_isa(char *str) { return acpi_irq_penalty_update(str, 1); } |
4be44fcd3
|
891 |
|
1da177e4c
|
892 893 894 895 896 897 898 899 900 901 902 |
__setup("acpi_irq_isa=", acpi_irq_isa); /* * Over-ride default table to free additional IRQs for use by PCI * e.g. acpi_irq_pci=7,15 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing. */ static int __init acpi_irq_pci(char *str) { return acpi_irq_penalty_update(str, 0); } |
4be44fcd3
|
903 |
|
1da177e4c
|
904 905 906 907 908 909 910 |
__setup("acpi_irq_pci=", acpi_irq_pci); static int __init acpi_irq_nobalance_set(char *str) { acpi_irq_balance = 0; return 1; } |
4be44fcd3
|
911 |
|
1da177e4c
|
912 |
__setup("acpi_irq_nobalance", acpi_irq_nobalance_set); |
8a383ef0b
|
913 |
static int __init acpi_irq_balance_set(char *str) |
1da177e4c
|
914 915 916 917 |
{ acpi_irq_balance = 1; return 1; } |
1da177e4c
|
918 |
|
4be44fcd3
|
919 |
__setup("acpi_irq_balance", acpi_irq_balance_set); |
1da177e4c
|
920 |
|
c3146df2b
|
921 |
static struct syscore_ops irqrouter_syscore_ops = { |
4be44fcd3
|
922 |
.resume = irqrouter_resume, |
1da177e4c
|
923 |
}; |
4daeaf683
|
924 |
void __init acpi_pci_link_init(void) |
1da177e4c
|
925 |
{ |
1da177e4c
|
926 |
if (acpi_noirq) |
4daeaf683
|
927 |
return; |
1da177e4c
|
928 |
|
32836259f
|
929 930 931 932 933 934 935 |
if (acpi_irq_balance == -1) { /* no command line switch: enable balancing in IOAPIC mode */ if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) acpi_irq_balance = 1; else acpi_irq_balance = 0; } |
4daeaf683
|
936 937 |
register_syscore_ops(&irqrouter_syscore_ops); acpi_scan_add_handler(&pci_link_handler); |
1da177e4c
|
938 |
} |