dup2: Fix return value with oldfd == newfd and invalid fd
[linux-2.6/mini2440.git] / drivers / acpi / pci_link.c
blob16e0f9d3d17cb49a25cf76f68e04ff9042ece566
1 /*
2 * pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
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>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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).
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 #include <linux/mutex.h>
43 #include <acpi/acpi_bus.h>
44 #include <acpi/acpi_drivers.h>
46 #define _COMPONENT ACPI_PCI_COMPONENT
47 ACPI_MODULE_NAME("pci_link");
48 #define ACPI_PCI_LINK_CLASS "pci_irq_routing"
49 #define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
50 #define ACPI_PCI_LINK_FILE_INFO "info"
51 #define ACPI_PCI_LINK_FILE_STATUS "state"
52 #define ACPI_PCI_LINK_MAX_POSSIBLE 16
54 static int acpi_pci_link_add(struct acpi_device *device);
55 static int acpi_pci_link_remove(struct acpi_device *device, int type);
57 static struct acpi_device_id link_device_ids[] = {
58 {"PNP0C0F", 0},
59 {"", 0},
61 MODULE_DEVICE_TABLE(acpi, link_device_ids);
63 static struct acpi_driver acpi_pci_link_driver = {
64 .name = "pci_link",
65 .class = ACPI_PCI_LINK_CLASS,
66 .ids = link_device_ids,
67 .ops = {
68 .add = acpi_pci_link_add,
69 .remove = acpi_pci_link_remove,
74 * If a link is initialized, we never change its active and initialized
75 * later even the link is disable. Instead, we just repick the active irq
77 struct acpi_pci_link_irq {
78 u8 active; /* Current IRQ */
79 u8 triggering; /* All IRQs */
80 u8 polarity; /* All IRQs */
81 u8 resource_type;
82 u8 possible_count;
83 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
84 u8 initialized:1;
85 u8 reserved:7;
88 struct acpi_pci_link {
89 struct list_head list;
90 struct acpi_device *device;
91 struct acpi_pci_link_irq irq;
92 int refcnt;
95 static LIST_HEAD(acpi_link_list);
96 static DEFINE_MUTEX(acpi_link_lock);
98 /* --------------------------------------------------------------------------
99 PCI Link Device Management
100 -------------------------------------------------------------------------- */
103 * set context (link) possible list from resource list
105 static acpi_status acpi_pci_link_check_possible(struct acpi_resource *resource,
106 void *context)
108 struct acpi_pci_link *link = context;
109 u32 i;
111 switch (resource->type) {
112 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
113 case ACPI_RESOURCE_TYPE_END_TAG:
114 return AE_OK;
115 case ACPI_RESOURCE_TYPE_IRQ:
117 struct acpi_resource_irq *p = &resource->data.irq;
118 if (!p || !p->interrupt_count) {
119 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
120 "Blank _PRS IRQ resource\n"));
121 return AE_OK;
123 for (i = 0;
124 (i < p->interrupt_count
125 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
126 if (!p->interrupts[i]) {
127 printk(KERN_WARNING PREFIX
128 "Invalid _PRS IRQ %d\n",
129 p->interrupts[i]);
130 continue;
132 link->irq.possible[i] = p->interrupts[i];
133 link->irq.possible_count++;
135 link->irq.triggering = p->triggering;
136 link->irq.polarity = p->polarity;
137 link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ;
138 break;
140 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
142 struct acpi_resource_extended_irq *p =
143 &resource->data.extended_irq;
144 if (!p || !p->interrupt_count) {
145 printk(KERN_WARNING PREFIX
146 "Blank _PRS EXT IRQ resource\n");
147 return AE_OK;
149 for (i = 0;
150 (i < p->interrupt_count
151 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
152 if (!p->interrupts[i]) {
153 printk(KERN_WARNING PREFIX
154 "Invalid _PRS IRQ %d\n",
155 p->interrupts[i]);
156 continue;
158 link->irq.possible[i] = p->interrupts[i];
159 link->irq.possible_count++;
161 link->irq.triggering = p->triggering;
162 link->irq.polarity = p->polarity;
163 link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
164 break;
166 default:
167 printk(KERN_ERR PREFIX "_PRS resource type 0x%x isn't an IRQ\n",
168 resource->type);
169 return AE_OK;
172 return AE_CTRL_TERMINATE;
175 static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
177 acpi_status status;
179 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
180 acpi_pci_link_check_possible, link);
181 if (ACPI_FAILURE(status)) {
182 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
183 return -ENODEV;
186 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
187 "Found %d possible IRQs\n",
188 link->irq.possible_count));
190 return 0;
193 static acpi_status acpi_pci_link_check_current(struct acpi_resource *resource,
194 void *context)
196 int *irq = context;
198 switch (resource->type) {
199 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
200 case ACPI_RESOURCE_TYPE_END_TAG:
201 return AE_OK;
202 case ACPI_RESOURCE_TYPE_IRQ:
204 struct acpi_resource_irq *p = &resource->data.irq;
205 if (!p || !p->interrupt_count) {
207 * IRQ descriptors may have no IRQ# bits set,
208 * particularly those those w/ _STA disabled
210 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
211 "Blank _CRS IRQ resource\n"));
212 return AE_OK;
214 *irq = p->interrupts[0];
215 break;
217 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
219 struct acpi_resource_extended_irq *p =
220 &resource->data.extended_irq;
221 if (!p || !p->interrupt_count) {
223 * extended IRQ descriptors must
224 * return at least 1 IRQ
226 printk(KERN_WARNING PREFIX
227 "Blank _CRS EXT IRQ resource\n");
228 return AE_OK;
230 *irq = p->interrupts[0];
231 break;
233 break;
234 default:
235 printk(KERN_ERR PREFIX "_CRS resource type 0x%x isn't an IRQ\n",
236 resource->type);
237 return AE_OK;
240 return AE_CTRL_TERMINATE;
244 * Run _CRS and set link->irq.active
246 * return value:
247 * 0 - success
248 * !0 - failure
250 static int acpi_pci_link_get_current(struct acpi_pci_link *link)
252 int result = 0;
253 acpi_status status;
254 int irq = 0;
256 link->irq.active = 0;
258 /* in practice, status disabled is meaningless, ignore it */
259 if (acpi_strict) {
260 /* Query _STA, set link->device->status */
261 result = acpi_bus_get_status(link->device);
262 if (result) {
263 printk(KERN_ERR PREFIX "Unable to read status\n");
264 goto end;
267 if (!link->device->status.enabled) {
268 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n"));
269 return 0;
274 * Query and parse _CRS to get the current IRQ assignment.
277 status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
278 acpi_pci_link_check_current, &irq);
279 if (ACPI_FAILURE(status)) {
280 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
281 result = -ENODEV;
282 goto end;
285 if (acpi_strict && !irq) {
286 printk(KERN_ERR PREFIX "_CRS returned 0\n");
287 result = -ENODEV;
290 link->irq.active = irq;
292 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active));
294 end:
295 return result;
298 static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
300 int result;
301 acpi_status status;
302 struct {
303 struct acpi_resource res;
304 struct acpi_resource end;
305 } *resource;
306 struct acpi_buffer buffer = { 0, NULL };
308 if (!irq)
309 return -EINVAL;
311 resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
312 if (!resource)
313 return -ENOMEM;
315 buffer.length = sizeof(*resource) + 1;
316 buffer.pointer = resource;
318 switch (link->irq.resource_type) {
319 case ACPI_RESOURCE_TYPE_IRQ:
320 resource->res.type = ACPI_RESOURCE_TYPE_IRQ;
321 resource->res.length = sizeof(struct acpi_resource);
322 resource->res.data.irq.triggering = link->irq.triggering;
323 resource->res.data.irq.polarity =
324 link->irq.polarity;
325 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
326 resource->res.data.irq.sharable =
327 ACPI_EXCLUSIVE;
328 else
329 resource->res.data.irq.sharable = ACPI_SHARED;
330 resource->res.data.irq.interrupt_count = 1;
331 resource->res.data.irq.interrupts[0] = irq;
332 break;
334 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
335 resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
336 resource->res.length = sizeof(struct acpi_resource);
337 resource->res.data.extended_irq.producer_consumer =
338 ACPI_CONSUMER;
339 resource->res.data.extended_irq.triggering =
340 link->irq.triggering;
341 resource->res.data.extended_irq.polarity =
342 link->irq.polarity;
343 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
344 resource->res.data.irq.sharable =
345 ACPI_EXCLUSIVE;
346 else
347 resource->res.data.irq.sharable = ACPI_SHARED;
348 resource->res.data.extended_irq.interrupt_count = 1;
349 resource->res.data.extended_irq.interrupts[0] = irq;
350 /* ignore resource_source, it's optional */
351 break;
352 default:
353 printk(KERN_ERR PREFIX "Invalid Resource_type %d\n", link->irq.resource_type);
354 result = -EINVAL;
355 goto end;
358 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
360 /* Attempt to set the resource */
361 status = acpi_set_current_resources(link->device->handle, &buffer);
363 /* check for total failure */
364 if (ACPI_FAILURE(status)) {
365 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS"));
366 result = -ENODEV;
367 goto end;
370 /* Query _STA, set device->status */
371 result = acpi_bus_get_status(link->device);
372 if (result) {
373 printk(KERN_ERR PREFIX "Unable to read status\n");
374 goto end;
376 if (!link->device->status.enabled) {
377 printk(KERN_WARNING PREFIX
378 "%s [%s] disabled and referenced, BIOS bug\n",
379 acpi_device_name(link->device),
380 acpi_device_bid(link->device));
383 /* Query _CRS, set link->irq.active */
384 result = acpi_pci_link_get_current(link);
385 if (result) {
386 goto end;
390 * Is current setting not what we set?
391 * set link->irq.active
393 if (link->irq.active != irq) {
395 * policy: when _CRS doesn't return what we just _SRS
396 * assume _SRS worked and override _CRS value.
398 printk(KERN_WARNING PREFIX
399 "%s [%s] BIOS reported IRQ %d, using IRQ %d\n",
400 acpi_device_name(link->device),
401 acpi_device_bid(link->device), link->irq.active, irq);
402 link->irq.active = irq;
405 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active));
407 end:
408 kfree(resource);
409 return result;
412 /* --------------------------------------------------------------------------
413 PCI Link IRQ Management
414 -------------------------------------------------------------------------- */
417 * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt
418 * Link Devices to move the PIRQs around to minimize sharing.
420 * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs
421 * that the BIOS has already set to active. This is necessary because
422 * ACPI has no automatic means of knowing what ISA IRQs are used. Note that
423 * if the BIOS doesn't set a Link Device active, ACPI needs to program it
424 * even if acpi_irq_nobalance is set.
426 * A tables of penalties avoids directing PCI interrupts to well known
427 * ISA IRQs. Boot params are available to over-ride the default table:
429 * List interrupts that are free for PCI use.
430 * acpi_irq_pci=n[,m]
432 * List interrupts that should not be used for PCI:
433 * acpi_irq_isa=n[,m]
435 * Note that PCI IRQ routers have a list of possible IRQs,
436 * which may not include the IRQs this table says are available.
438 * Since this heuristic can't tell the difference between a link
439 * that no device will attach to, vs. a link which may be shared
440 * by multiple active devices -- it is not optimal.
442 * If interrupt performance is that important, get an IO-APIC system
443 * with a pin dedicated to each device. Or for that matter, an MSI
444 * enabled system.
447 #define ACPI_MAX_IRQS 256
448 #define ACPI_MAX_ISA_IRQ 16
450 #define PIRQ_PENALTY_PCI_AVAILABLE (0)
451 #define PIRQ_PENALTY_PCI_POSSIBLE (16*16)
452 #define PIRQ_PENALTY_PCI_USING (16*16*16)
453 #define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16)
454 #define PIRQ_PENALTY_ISA_USED (16*16*16*16*16)
455 #define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16)
457 static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
458 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */
459 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */
460 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */
461 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */
462 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */
463 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */
464 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */
465 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */
466 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */
467 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */
468 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */
469 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */
470 PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */
471 PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */
472 PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */
473 PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */
474 /* >IRQ15 */
477 int __init acpi_irq_penalty_init(void)
479 struct acpi_pci_link *link;
480 int i;
483 * Update penalties to facilitate IRQ balancing.
485 list_for_each_entry(link, &acpi_link_list, list) {
488 * reflect the possible and active irqs in the penalty table --
489 * useful for breaking ties.
491 if (link->irq.possible_count) {
492 int penalty =
493 PIRQ_PENALTY_PCI_POSSIBLE /
494 link->irq.possible_count;
496 for (i = 0; i < link->irq.possible_count; i++) {
497 if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ)
498 acpi_irq_penalty[link->irq.
499 possible[i]] +=
500 penalty;
503 } else if (link->irq.active) {
504 acpi_irq_penalty[link->irq.active] +=
505 PIRQ_PENALTY_PCI_POSSIBLE;
508 /* Add a penalty for the SCI */
509 acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING;
510 return 0;
513 static int acpi_irq_balance = -1; /* 0: static, 1: balance */
515 static int acpi_pci_link_allocate(struct acpi_pci_link *link)
517 int irq;
518 int i;
520 if (link->irq.initialized) {
521 if (link->refcnt == 0)
522 /* This means the link is disabled but initialized */
523 acpi_pci_link_set(link, link->irq.active);
524 return 0;
528 * search for active IRQ in list of possible IRQs.
530 for (i = 0; i < link->irq.possible_count; ++i) {
531 if (link->irq.active == link->irq.possible[i])
532 break;
535 * forget active IRQ that is not in possible list
537 if (i == link->irq.possible_count) {
538 if (acpi_strict)
539 printk(KERN_WARNING PREFIX "_CRS %d not found"
540 " in _PRS\n", link->irq.active);
541 link->irq.active = 0;
545 * if active found, use it; else pick entry from end of possible list.
547 if (link->irq.active)
548 irq = link->irq.active;
549 else
550 irq = link->irq.possible[link->irq.possible_count - 1];
552 if (acpi_irq_balance || !link->irq.active) {
554 * Select the best IRQ. This is done in reverse to promote
555 * the use of IRQs 9, 10, 11, and >15.
557 for (i = (link->irq.possible_count - 1); i >= 0; i--) {
558 if (acpi_irq_penalty[irq] >
559 acpi_irq_penalty[link->irq.possible[i]])
560 irq = link->irq.possible[i];
564 /* Attempt to enable the link device at this IRQ. */
565 if (acpi_pci_link_set(link, irq)) {
566 printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. "
567 "Try pci=noacpi or acpi=off\n",
568 acpi_device_name(link->device),
569 acpi_device_bid(link->device));
570 return -ENODEV;
571 } else {
572 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
573 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
574 acpi_device_name(link->device),
575 acpi_device_bid(link->device), link->irq.active);
578 link->irq.initialized = 1;
579 return 0;
583 * acpi_pci_link_allocate_irq
584 * success: return IRQ >= 0
585 * failure: return -1
587 int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
588 int *polarity, char **name)
590 int result;
591 struct acpi_device *device;
592 struct acpi_pci_link *link;
594 result = acpi_bus_get_device(handle, &device);
595 if (result) {
596 printk(KERN_ERR PREFIX "Invalid link device\n");
597 return -1;
600 link = acpi_driver_data(device);
601 if (!link) {
602 printk(KERN_ERR PREFIX "Invalid link context\n");
603 return -1;
606 /* TBD: Support multiple index (IRQ) entries per Link Device */
607 if (index) {
608 printk(KERN_ERR PREFIX "Invalid index %d\n", index);
609 return -1;
612 mutex_lock(&acpi_link_lock);
613 if (acpi_pci_link_allocate(link)) {
614 mutex_unlock(&acpi_link_lock);
615 return -1;
618 if (!link->irq.active) {
619 mutex_unlock(&acpi_link_lock);
620 printk(KERN_ERR PREFIX "Link active IRQ is 0!\n");
621 return -1;
623 link->refcnt++;
624 mutex_unlock(&acpi_link_lock);
626 if (triggering)
627 *triggering = link->irq.triggering;
628 if (polarity)
629 *polarity = link->irq.polarity;
630 if (name)
631 *name = acpi_device_bid(link->device);
632 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
633 "Link %s is referenced\n",
634 acpi_device_bid(link->device)));
635 return (link->irq.active);
639 * We don't change link's irq information here. After it is reenabled, we
640 * continue use the info
642 int acpi_pci_link_free_irq(acpi_handle handle)
644 struct acpi_device *device;
645 struct acpi_pci_link *link;
646 acpi_status result;
648 result = acpi_bus_get_device(handle, &device);
649 if (result) {
650 printk(KERN_ERR PREFIX "Invalid link device\n");
651 return -1;
654 link = acpi_driver_data(device);
655 if (!link) {
656 printk(KERN_ERR PREFIX "Invalid link context\n");
657 return -1;
660 mutex_lock(&acpi_link_lock);
661 if (!link->irq.initialized) {
662 mutex_unlock(&acpi_link_lock);
663 printk(KERN_ERR PREFIX "Link isn't initialized\n");
664 return -1;
666 #ifdef FUTURE_USE
668 * The Link reference count allows us to _DISable an unused link
669 * and suspend time, and set it again on resume.
670 * However, 2.6.12 still has irq_router.resume
671 * which blindly restores the link state.
672 * So we disable the reference count method
673 * to prevent duplicate acpi_pci_link_set()
674 * which would harm some systems
676 link->refcnt--;
677 #endif
678 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
679 "Link %s is dereferenced\n",
680 acpi_device_bid(link->device)));
682 if (link->refcnt == 0)
683 acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL);
685 mutex_unlock(&acpi_link_lock);
686 return (link->irq.active);
689 /* --------------------------------------------------------------------------
690 Driver Interface
691 -------------------------------------------------------------------------- */
693 static int acpi_pci_link_add(struct acpi_device *device)
695 int result;
696 struct acpi_pci_link *link;
697 int i;
698 int found = 0;
700 link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
701 if (!link)
702 return -ENOMEM;
704 link->device = device;
705 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
706 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
707 device->driver_data = link;
709 mutex_lock(&acpi_link_lock);
710 result = acpi_pci_link_get_possible(link);
711 if (result)
712 goto end;
714 /* query and set link->irq.active */
715 acpi_pci_link_get_current(link);
717 printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device),
718 acpi_device_bid(device));
719 for (i = 0; i < link->irq.possible_count; i++) {
720 if (link->irq.active == link->irq.possible[i]) {
721 printk(" *%d", link->irq.possible[i]);
722 found = 1;
723 } else
724 printk(" %d", link->irq.possible[i]);
727 printk(")");
729 if (!found)
730 printk(" *%d", link->irq.active);
732 if (!link->device->status.enabled)
733 printk(", disabled.");
735 printk("\n");
737 list_add_tail(&link->list, &acpi_link_list);
739 end:
740 /* disable all links -- to be activated on use */
741 acpi_evaluate_object(device->handle, "_DIS", NULL, NULL);
742 mutex_unlock(&acpi_link_lock);
744 if (result)
745 kfree(link);
747 return result;
750 static int acpi_pci_link_resume(struct acpi_pci_link *link)
752 if (link->refcnt && link->irq.active && link->irq.initialized)
753 return (acpi_pci_link_set(link, link->irq.active));
755 return 0;
758 static int irqrouter_resume(struct sys_device *dev)
760 struct acpi_pci_link *link;
762 list_for_each_entry(link, &acpi_link_list, list) {
763 acpi_pci_link_resume(link);
765 return 0;
768 static int acpi_pci_link_remove(struct acpi_device *device, int type)
770 struct acpi_pci_link *link;
772 link = acpi_driver_data(device);
774 mutex_lock(&acpi_link_lock);
775 list_del(&link->list);
776 mutex_unlock(&acpi_link_lock);
778 kfree(link);
779 return 0;
783 * modify acpi_irq_penalty[] from cmdline
785 static int __init acpi_irq_penalty_update(char *str, int used)
787 int i;
789 for (i = 0; i < 16; i++) {
790 int retval;
791 int irq;
793 retval = get_option(&str, &irq);
795 if (!retval)
796 break; /* no number found */
798 if (irq < 0)
799 continue;
801 if (irq >= ARRAY_SIZE(acpi_irq_penalty))
802 continue;
804 if (used)
805 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
806 else
807 acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE;
809 if (retval != 2) /* no next number */
810 break;
812 return 1;
816 * We'd like PNP to call this routine for the
817 * single ISA_USED value for each legacy device.
818 * But instead it calls us with each POSSIBLE setting.
819 * There is no ISA_POSSIBLE weight, so we simply use
820 * the (small) PCI_USING penalty.
822 void acpi_penalize_isa_irq(int irq, int active)
824 if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) {
825 if (active)
826 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
827 else
828 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
833 * Over-ride default table to reserve additional IRQs for use by ISA
834 * e.g. acpi_irq_isa=5
835 * Useful for telling ACPI how not to interfere with your ISA sound card.
837 static int __init acpi_irq_isa(char *str)
839 return acpi_irq_penalty_update(str, 1);
842 __setup("acpi_irq_isa=", acpi_irq_isa);
845 * Over-ride default table to free additional IRQs for use by PCI
846 * e.g. acpi_irq_pci=7,15
847 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
849 static int __init acpi_irq_pci(char *str)
851 return acpi_irq_penalty_update(str, 0);
854 __setup("acpi_irq_pci=", acpi_irq_pci);
856 static int __init acpi_irq_nobalance_set(char *str)
858 acpi_irq_balance = 0;
859 return 1;
862 __setup("acpi_irq_nobalance", acpi_irq_nobalance_set);
864 static int __init acpi_irq_balance_set(char *str)
866 acpi_irq_balance = 1;
867 return 1;
870 __setup("acpi_irq_balance", acpi_irq_balance_set);
872 /* FIXME: we will remove this interface after all drivers call pci_disable_device */
873 static struct sysdev_class irqrouter_sysdev_class = {
874 .name = "irqrouter",
875 .resume = irqrouter_resume,
878 static struct sys_device device_irqrouter = {
879 .id = 0,
880 .cls = &irqrouter_sysdev_class,
883 static int __init irqrouter_init_sysfs(void)
885 int error;
887 if (acpi_disabled || acpi_noirq)
888 return 0;
890 error = sysdev_class_register(&irqrouter_sysdev_class);
891 if (!error)
892 error = sysdev_register(&device_irqrouter);
894 return error;
897 device_initcall(irqrouter_init_sysfs);
899 static int __init acpi_pci_link_init(void)
901 if (acpi_noirq)
902 return 0;
904 if (acpi_irq_balance == -1) {
905 /* no command line switch: enable balancing in IOAPIC mode */
906 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
907 acpi_irq_balance = 1;
908 else
909 acpi_irq_balance = 0;
912 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
913 return -ENODEV;
915 return 0;
918 subsys_initcall(acpi_pci_link_init);