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