[ACPI] Merge acpi-2.6.12 branch into 2.6.13-rc3
[linux-2.6.22.y-op.git] / drivers / acpi / pci_link.c
blob26aa3829f1def0fe1d6dde66eac3bdd9cc645165
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>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/acpi_drivers.h>
46 #define _COMPONENT ACPI_PCI_COMPONENT
47 ACPI_MODULE_NAME ("pci_link")
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"
56 #define ACPI_PCI_LINK_MAX_POSSIBLE 16
58 static int acpi_pci_link_add (struct acpi_device *device);
59 static int acpi_pci_link_remove (struct acpi_device *device, int type);
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,
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
75 struct acpi_pci_link_irq {
76 u8 active; /* Current IRQ */
77 u8 edge_level; /* All IRQs */
78 u8 active_high_low; /* All IRQs */
79 u8 resource_type;
80 u8 possible_count;
81 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
82 u8 initialized:1;
83 u8 reserved:7;
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;
91 int refcnt;
94 static struct {
95 int count;
96 struct list_head entries;
97 } acpi_link;
98 DECLARE_MUTEX(acpi_link_lock);
101 /* --------------------------------------------------------------------------
102 PCI Link Device Management
103 -------------------------------------------------------------------------- */
106 * set context (link) possible list from resource list
108 static acpi_status
109 acpi_pci_link_check_possible (
110 struct acpi_resource *resource,
111 void *context)
113 struct acpi_pci_link *link = (struct acpi_pci_link *) context;
114 u32 i = 0;
116 ACPI_FUNCTION_TRACE("acpi_pci_link_check_possible");
118 switch (resource->id) {
119 case ACPI_RSTYPE_START_DPF:
120 return_ACPI_STATUS(AE_OK);
121 case ACPI_RSTYPE_IRQ:
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);
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;
133 link->irq.possible[i] = p->interrupts[i];
134 link->irq.possible_count++;
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;
141 case ACPI_RSTYPE_EXT_IRQ:
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);
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;
154 link->irq.possible[i] = p->interrupts[i];
155 link->irq.possible_count++;
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;
162 default:
163 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
164 "Resource is not an IRQ entry\n"));
165 return_ACPI_STATUS(AE_OK);
168 return_ACPI_STATUS(AE_CTRL_TERMINATE);
172 static int
173 acpi_pci_link_get_possible (
174 struct acpi_pci_link *link)
176 acpi_status status;
178 ACPI_FUNCTION_TRACE("acpi_pci_link_get_possible");
180 if (!link)
181 return_VALUE(-EINVAL);
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);
190 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
191 "Found %d possible IRQs\n", link->irq.possible_count));
193 return_VALUE(0);
197 static acpi_status
198 acpi_pci_link_check_current (
199 struct acpi_resource *resource,
200 void *context)
202 int *irq = (int *) context;
204 ACPI_FUNCTION_TRACE("acpi_pci_link_check_current");
206 switch (resource->id) {
207 case ACPI_RSTYPE_IRQ:
209 struct acpi_resource_irq *p = &resource->data.irq;
210 if (!p || !p->number_of_interrupts) {
212 * IRQ descriptors may have no IRQ# bits set,
213 * particularly those those w/ _STA disabled
215 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
216 "Blank IRQ resource\n"));
217 return_ACPI_STATUS(AE_OK);
219 *irq = p->interrupts[0];
220 break;
222 case ACPI_RSTYPE_EXT_IRQ:
224 struct acpi_resource_ext_irq *p = &resource->data.extended_irq;
225 if (!p || !p->number_of_interrupts) {
227 * extended IRQ descriptors must
228 * return at least 1 IRQ
230 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
231 "Blank EXT IRQ resource\n"));
232 return_ACPI_STATUS(AE_OK);
234 *irq = p->interrupts[0];
235 break;
237 default:
238 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
239 "Resource isn't an IRQ\n"));
240 return_ACPI_STATUS(AE_OK);
242 return_ACPI_STATUS(AE_CTRL_TERMINATE);
246 * Run _CRS and set link->irq.active
248 * return value:
249 * 0 - success
250 * !0 - failure
252 static int
253 acpi_pci_link_get_current (
254 struct acpi_pci_link *link)
256 int result = 0;
257 acpi_status status = AE_OK;
258 int irq = 0;
260 ACPI_FUNCTION_TRACE("acpi_pci_link_get_current");
262 if (!link || !link->handle)
263 return_VALUE(-EINVAL);
265 link->irq.active = 0;
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;
276 if (!link->device->status.enabled) {
277 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n"));
278 return_VALUE(0);
283 * Query and parse _CRS to get the current IRQ assignment.
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;
294 if (acpi_strict && !irq) {
295 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "_CRS returned 0\n"));
296 result = -ENODEV;
299 link->irq.active = irq;
301 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active));
303 end:
304 return_VALUE(result);
307 static int
308 acpi_pci_link_set (
309 struct acpi_pci_link *link,
310 int irq)
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};
320 ACPI_FUNCTION_TRACE("acpi_pci_link_set");
322 if (!link || !irq)
323 return_VALUE(-EINVAL);
325 resource = kmalloc( sizeof(*resource)+1, GFP_KERNEL);
326 if(!resource)
327 return_VALUE(-ENOMEM);
329 memset(resource, 0, sizeof(*resource)+1);
330 buffer.length = sizeof(*resource) +1;
331 buffer.pointer = resource;
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;
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;
367 resource->end.id = ACPI_RSTYPE_END_TAG;
369 /* Attempt to set the resource */
370 status = acpi_set_current_resources(link->handle, &buffer);
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;
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;
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));
392 /* Query _CRS, set link->irq.active */
393 result = acpi_pci_link_get_current(link);
394 if (result) {
395 goto end;
399 * Is current setting not what we set?
400 * set link->irq.active
402 if (link->irq.active != irq) {
404 * policy: when _CRS doesn't return what we just _SRS
405 * assume _SRS worked and override _CRS value.
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;
415 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active));
417 end:
418 kfree(resource);
419 return_VALUE(result);
423 /* --------------------------------------------------------------------------
424 PCI Link IRQ Management
425 -------------------------------------------------------------------------- */
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.
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.
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:
440 * List interrupts that are free for PCI use.
441 * acpi_irq_pci=n[,m]
443 * List interrupts that should not be used for PCI:
444 * acpi_irq_isa=n[,m]
446 * Note that PCI IRQ routers have a list of possible IRQs,
447 * which may not include the IRQs this table says are available.
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.
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.
458 #define ACPI_MAX_IRQS 256
459 #define ACPI_MAX_ISA_IRQ 16
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)
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 */
488 int __init
489 acpi_irq_penalty_init(void)
491 struct list_head *node = NULL;
492 struct acpi_pci_link *link = NULL;
493 int i = 0;
495 ACPI_FUNCTION_TRACE("acpi_irq_penalty_init");
498 * Update penalties to facilitate IRQ balancing.
500 list_for_each(node, &acpi_link.entries) {
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;
509 * reflect the possible and active irqs in the penalty table --
510 * useful for breaking ties.
512 if (link->irq.possible_count) {
513 int penalty = PIRQ_PENALTY_PCI_POSSIBLE / link->irq.possible_count;
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;
520 } else if (link->irq.active) {
521 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_POSSIBLE;
524 /* Add a penalty for the SCI */
525 acpi_irq_penalty[acpi_fadt.sci_int] += PIRQ_PENALTY_PCI_USING;
527 return_VALUE(0);
530 static int acpi_irq_balance; /* 0: static, 1: balance */
532 static int acpi_pci_link_allocate(
533 struct acpi_pci_link *link)
535 int irq;
536 int i;
538 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate");
540 if (link->irq.initialized) {
541 if (link->refcnt == 0)
542 /* This means the link is disabled but initialized */
543 acpi_pci_link_set(link, link->irq.active);
544 return_VALUE(0);
548 * search for active IRQ in list of possible IRQs.
550 for (i = 0; i < link->irq.possible_count; ++i) {
551 if (link->irq.active == link->irq.possible[i])
552 break;
555 * forget active IRQ that is not in possible list
557 if (i == link->irq.possible_count) {
558 if (acpi_strict)
559 printk(KERN_WARNING PREFIX "_CRS %d not found"
560 " in _PRS\n", link->irq.active);
561 link->irq.active = 0;
565 * if active found, use it; else pick entry from end of possible list.
567 if (link->irq.active) {
568 irq = link->irq.active;
569 } else {
570 irq = link->irq.possible[link->irq.possible_count - 1];
573 if (acpi_irq_balance || !link->irq.active) {
575 * Select the best IRQ. This is done in reverse to promote
576 * the use of IRQs 9, 10, 11, and >15.
578 for (i = (link->irq.possible_count - 1); i >= 0; i--) {
579 if (acpi_irq_penalty[irq] > acpi_irq_penalty[link->irq.possible[i]])
580 irq = link->irq.possible[i];
584 /* Attempt to enable the link device at this IRQ. */
585 if (acpi_pci_link_set(link, irq)) {
586 printk(PREFIX "Unable to set IRQ for %s [%s] (likely buggy ACPI BIOS).\n"
587 "Try pci=noacpi or acpi=off\n",
588 acpi_device_name(link->device),
589 acpi_device_bid(link->device));
590 return_VALUE(-ENODEV);
591 } else {
592 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
593 printk(PREFIX "%s [%s] enabled at IRQ %d\n",
594 acpi_device_name(link->device),
595 acpi_device_bid(link->device), link->irq.active);
598 link->irq.initialized = 1;
600 return_VALUE(0);
604 * acpi_pci_link_allocate_irq
605 * success: return IRQ >= 0
606 * failure: return -1
610 acpi_pci_link_allocate_irq (
611 acpi_handle handle,
612 int index,
613 int *edge_level,
614 int *active_high_low,
615 char **name)
617 int result = 0;
618 struct acpi_device *device = NULL;
619 struct acpi_pci_link *link = NULL;
621 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate_irq");
623 result = acpi_bus_get_device(handle, &device);
624 if (result) {
625 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link device\n"));
626 return_VALUE(-1);
629 link = (struct acpi_pci_link *) acpi_driver_data(device);
630 if (!link) {
631 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n"));
632 return_VALUE(-1);
635 /* TBD: Support multiple index (IRQ) entries per Link Device */
636 if (index) {
637 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid index %d\n", index));
638 return_VALUE(-1);
641 down(&acpi_link_lock);
642 if (acpi_pci_link_allocate(link)) {
643 up(&acpi_link_lock);
644 return_VALUE(-1);
647 if (!link->irq.active) {
648 up(&acpi_link_lock);
649 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link active IRQ is 0!\n"));
650 return_VALUE(-1);
652 link->refcnt ++;
653 up(&acpi_link_lock);
655 if (edge_level) *edge_level = link->irq.edge_level;
656 if (active_high_low) *active_high_low = link->irq.active_high_low;
657 if (name) *name = acpi_device_bid(link->device);
658 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
659 "Link %s is referenced\n", acpi_device_bid(link->device)));
660 return_VALUE(link->irq.active);
664 * We don't change link's irq information here. After it is reenabled, we
665 * continue use the info
668 acpi_pci_link_free_irq(acpi_handle handle)
670 struct acpi_device *device = NULL;
671 struct acpi_pci_link *link = NULL;
672 acpi_status result;
674 ACPI_FUNCTION_TRACE("acpi_pci_link_free_irq");
676 result = acpi_bus_get_device(handle, &device);
677 if (result) {
678 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link device\n"));
679 return_VALUE(-1);
682 link = (struct acpi_pci_link *) acpi_driver_data(device);
683 if (!link) {
684 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n"));
685 return_VALUE(-1);
688 down(&acpi_link_lock);
689 if (!link->irq.initialized) {
690 up(&acpi_link_lock);
691 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link isn't initialized\n"));
692 return_VALUE(-1);
695 #ifdef FUTURE_USE
697 * The Link reference count allows us to _DISable an unused link
698 * and suspend time, and set it again on resume.
699 * However, 2.6.12 still has irq_router.resume
700 * which blindly restores the link state.
701 * So we disable the reference count method
702 * to prevent duplicate acpi_pci_link_set()
703 * which would harm some systems
705 link->refcnt --;
706 #endif
707 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
708 "Link %s is dereferenced\n", acpi_device_bid(link->device)));
710 if (link->refcnt == 0) {
711 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL);
713 up(&acpi_link_lock);
714 return_VALUE(link->irq.active);
716 /* --------------------------------------------------------------------------
717 Driver Interface
718 -------------------------------------------------------------------------- */
720 static int
721 acpi_pci_link_add (
722 struct acpi_device *device)
724 int result = 0;
725 struct acpi_pci_link *link = NULL;
726 int i = 0;
727 int found = 0;
729 ACPI_FUNCTION_TRACE("acpi_pci_link_add");
731 if (!device)
732 return_VALUE(-EINVAL);
734 link = kmalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
735 if (!link)
736 return_VALUE(-ENOMEM);
737 memset(link, 0, sizeof(struct acpi_pci_link));
739 link->device = device;
740 link->handle = device->handle;
741 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
742 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
743 acpi_driver_data(device) = link;
745 down(&acpi_link_lock);
746 result = acpi_pci_link_get_possible(link);
747 if (result)
748 goto end;
750 /* query and set link->irq.active */
751 acpi_pci_link_get_current(link);
753 printk(PREFIX "%s [%s] (IRQs", acpi_device_name(device),
754 acpi_device_bid(device));
755 for (i = 0; i < link->irq.possible_count; i++) {
756 if (link->irq.active == link->irq.possible[i]) {
757 printk(" *%d", link->irq.possible[i]);
758 found = 1;
760 else
761 printk(" %d", link->irq.possible[i]);
764 printk(")");
766 if (!found)
767 printk(" *%d", link->irq.active);
769 if(!link->device->status.enabled)
770 printk(", disabled.");
772 printk("\n");
774 /* TBD: Acquire/release lock */
775 list_add_tail(&link->node, &acpi_link.entries);
776 acpi_link.count++;
778 end:
779 /* disable all links -- to be activated on use */
780 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL);
781 up(&acpi_link_lock);
783 if (result)
784 kfree(link);
786 return_VALUE(result);
789 static int
790 acpi_pci_link_resume(
791 struct acpi_pci_link *link)
793 ACPI_FUNCTION_TRACE("acpi_pci_link_resume");
795 if (link->refcnt && link->irq.active && link->irq.initialized)
796 return_VALUE(acpi_pci_link_set(link, link->irq.active));
797 else
798 return_VALUE(0);
802 * FIXME: this is a workaround to avoid nasty warning. It will be removed
803 * after every device calls pci_disable_device in .resume.
805 int acpi_in_resume;
806 static int
807 irqrouter_resume(struct sys_device *dev)
809 struct list_head *node = NULL;
810 struct acpi_pci_link *link = NULL;
812 ACPI_FUNCTION_TRACE("irqrouter_resume");
814 acpi_in_resume = 1;
815 list_for_each(node, &acpi_link.entries) {
816 link = list_entry(node, struct acpi_pci_link, node);
817 if (!link) {
818 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
819 "Invalid link context\n"));
820 continue;
822 acpi_pci_link_resume(link);
824 acpi_in_resume = 0;
825 return_VALUE(0);
829 static int
830 acpi_pci_link_remove (
831 struct acpi_device *device,
832 int type)
834 struct acpi_pci_link *link = NULL;
836 ACPI_FUNCTION_TRACE("acpi_pci_link_remove");
838 if (!device || !acpi_driver_data(device))
839 return_VALUE(-EINVAL);
841 link = (struct acpi_pci_link *) acpi_driver_data(device);
843 down(&acpi_link_lock);
844 list_del(&link->node);
845 up(&acpi_link_lock);
847 kfree(link);
849 return_VALUE(0);
853 * modify acpi_irq_penalty[] from cmdline
855 static int __init acpi_irq_penalty_update(char *str, int used)
857 int i;
859 for (i = 0; i < 16; i++) {
860 int retval;
861 int irq;
863 retval = get_option(&str,&irq);
865 if (!retval)
866 break; /* no number found */
868 if (irq < 0)
869 continue;
871 if (irq >= ACPI_MAX_IRQS)
872 continue;
874 if (used)
875 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
876 else
877 acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE;
879 if (retval != 2) /* no next number */
880 break;
882 return 1;
886 * We'd like PNP to call this routine for the
887 * single ISA_USED value for each legacy device.
888 * But instead it calls us with each POSSIBLE setting.
889 * There is no ISA_POSSIBLE weight, so we simply use
890 * the (small) PCI_USING penalty.
892 void acpi_penalize_isa_irq(int irq, int active)
894 if (active)
895 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
896 else
897 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
901 * Over-ride default table to reserve additional IRQs for use by ISA
902 * e.g. acpi_irq_isa=5
903 * Useful for telling ACPI how not to interfere with your ISA sound card.
905 static int __init acpi_irq_isa(char *str)
907 return acpi_irq_penalty_update(str, 1);
909 __setup("acpi_irq_isa=", acpi_irq_isa);
912 * Over-ride default table to free additional IRQs for use by PCI
913 * e.g. acpi_irq_pci=7,15
914 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
916 static int __init acpi_irq_pci(char *str)
918 return acpi_irq_penalty_update(str, 0);
920 __setup("acpi_irq_pci=", acpi_irq_pci);
922 static int __init acpi_irq_nobalance_set(char *str)
924 acpi_irq_balance = 0;
925 return 1;
927 __setup("acpi_irq_nobalance", acpi_irq_nobalance_set);
929 int __init acpi_irq_balance_set(char *str)
931 acpi_irq_balance = 1;
932 return 1;
934 __setup("acpi_irq_balance", acpi_irq_balance_set);
937 /* FIXME: we will remove this interface after all drivers call pci_disable_device */
938 static struct sysdev_class irqrouter_sysdev_class = {
939 set_kset_name("irqrouter"),
940 .resume = irqrouter_resume,
944 static struct sys_device device_irqrouter = {
945 .id = 0,
946 .cls = &irqrouter_sysdev_class,
950 static int __init irqrouter_init_sysfs(void)
952 int error;
954 ACPI_FUNCTION_TRACE("irqrouter_init_sysfs");
956 if (acpi_disabled || acpi_noirq)
957 return_VALUE(0);
959 error = sysdev_class_register(&irqrouter_sysdev_class);
960 if (!error)
961 error = sysdev_register(&device_irqrouter);
963 return_VALUE(error);
966 device_initcall(irqrouter_init_sysfs);
969 static int __init acpi_pci_link_init (void)
971 ACPI_FUNCTION_TRACE("acpi_pci_link_init");
973 if (acpi_noirq)
974 return_VALUE(0);
976 acpi_link.count = 0;
977 INIT_LIST_HEAD(&acpi_link.entries);
979 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
980 return_VALUE(-ENODEV);
982 return_VALUE(0);
985 subsys_initcall(acpi_pci_link_init);