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 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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>
40 #include <linux/pci.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/acpi_drivers.h>
45 #define _COMPONENT ACPI_PCI_COMPONENT
46 ACPI_MODULE_NAME("pci_link")
47 #define ACPI_PCI_LINK_CLASS "pci_irq_routing"
48 #define ACPI_PCI_LINK_HID "PNP0C0F"
49 #define ACPI_PCI_LINK_DRIVER_NAME "ACPI PCI Interrupt Link Driver"
50 #define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
51 #define ACPI_PCI_LINK_FILE_INFO "info"
52 #define ACPI_PCI_LINK_FILE_STATUS "state"
53 #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_driver acpi_pci_link_driver
= {
58 .name
= ACPI_PCI_LINK_DRIVER_NAME
,
59 .class = ACPI_PCI_LINK_CLASS
,
60 .ids
= ACPI_PCI_LINK_HID
,
62 .add
= acpi_pci_link_add
,
63 .remove
= acpi_pci_link_remove
,
68 * If a link is initialized, we never change its active and initialized
69 * later even the link is disable. Instead, we just repick the active irq
71 struct acpi_pci_link_irq
{
72 u8 active
; /* Current IRQ */
73 u8 edge_level
; /* All IRQs */
74 u8 active_high_low
; /* All IRQs */
77 u8 possible
[ACPI_PCI_LINK_MAX_POSSIBLE
];
82 struct acpi_pci_link
{
83 struct list_head node
;
84 struct acpi_device
*device
;
86 struct acpi_pci_link_irq irq
;
92 struct list_head entries
;
94 DECLARE_MUTEX(acpi_link_lock
);
96 /* --------------------------------------------------------------------------
97 PCI Link Device Management
98 -------------------------------------------------------------------------- */
101 * set context (link) possible list from resource list
104 acpi_pci_link_check_possible(struct acpi_resource
*resource
, void *context
)
106 struct acpi_pci_link
*link
= (struct acpi_pci_link
*)context
;
109 ACPI_FUNCTION_TRACE("acpi_pci_link_check_possible");
111 switch (resource
->id
) {
112 case ACPI_RSTYPE_START_DPF
:
113 return_ACPI_STATUS(AE_OK
);
114 case ACPI_RSTYPE_IRQ
:
116 struct acpi_resource_irq
*p
= &resource
->data
.irq
;
117 if (!p
|| !p
->number_of_interrupts
) {
118 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
119 "Blank IRQ resource\n"));
120 return_ACPI_STATUS(AE_OK
);
123 (i
< p
->number_of_interrupts
124 && i
< ACPI_PCI_LINK_MAX_POSSIBLE
); i
++) {
125 if (!p
->interrupts
[i
]) {
126 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
131 link
->irq
.possible
[i
] = p
->interrupts
[i
];
132 link
->irq
.possible_count
++;
134 link
->irq
.edge_level
= p
->edge_level
;
135 link
->irq
.active_high_low
= p
->active_high_low
;
136 link
->irq
.resource_type
= ACPI_RSTYPE_IRQ
;
139 case ACPI_RSTYPE_EXT_IRQ
:
141 struct acpi_resource_ext_irq
*p
=
142 &resource
->data
.extended_irq
;
143 if (!p
|| !p
->number_of_interrupts
) {
144 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
145 "Blank EXT IRQ resource\n"));
146 return_ACPI_STATUS(AE_OK
);
149 (i
< p
->number_of_interrupts
150 && i
< ACPI_PCI_LINK_MAX_POSSIBLE
); i
++) {
151 if (!p
->interrupts
[i
]) {
152 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
157 link
->irq
.possible
[i
] = p
->interrupts
[i
];
158 link
->irq
.possible_count
++;
160 link
->irq
.edge_level
= p
->edge_level
;
161 link
->irq
.active_high_low
= p
->active_high_low
;
162 link
->irq
.resource_type
= ACPI_RSTYPE_EXT_IRQ
;
166 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
167 "Resource is not an IRQ entry\n"));
168 return_ACPI_STATUS(AE_OK
);
171 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
174 static int acpi_pci_link_get_possible(struct acpi_pci_link
*link
)
178 ACPI_FUNCTION_TRACE("acpi_pci_link_get_possible");
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",
192 link
->irq
.possible_count
));
198 acpi_pci_link_check_current(struct acpi_resource
*resource
, void *context
)
200 int *irq
= (int *)context
;
202 ACPI_FUNCTION_TRACE("acpi_pci_link_check_current");
204 switch (resource
->id
) {
205 case ACPI_RSTYPE_IRQ
:
207 struct acpi_resource_irq
*p
= &resource
->data
.irq
;
208 if (!p
|| !p
->number_of_interrupts
) {
210 * IRQ descriptors may have no IRQ# bits set,
211 * particularly those those w/ _STA disabled
213 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
214 "Blank IRQ resource\n"));
215 return_ACPI_STATUS(AE_OK
);
217 *irq
= p
->interrupts
[0];
220 case ACPI_RSTYPE_EXT_IRQ
:
222 struct acpi_resource_ext_irq
*p
=
223 &resource
->data
.extended_irq
;
224 if (!p
|| !p
->number_of_interrupts
) {
226 * extended IRQ descriptors must
227 * return at least 1 IRQ
229 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
230 "Blank EXT IRQ resource\n"));
231 return_ACPI_STATUS(AE_OK
);
233 *irq
= p
->interrupts
[0];
237 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Resource isn't an IRQ\n"));
238 return_ACPI_STATUS(AE_OK
);
240 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
244 * Run _CRS and set link->irq.active
250 static int acpi_pci_link_get_current(struct acpi_pci_link
*link
)
253 acpi_status status
= AE_OK
;
256 ACPI_FUNCTION_TRACE("acpi_pci_link_get_current");
258 if (!link
|| !link
->handle
)
259 return_VALUE(-EINVAL
);
261 link
->irq
.active
= 0;
263 /* in practice, status disabled is meaningless, ignore it */
265 /* Query _STA, set link->device->status */
266 result
= acpi_bus_get_status(link
->device
);
268 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
269 "Unable to read status\n"));
273 if (!link
->device
->status
.enabled
) {
274 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Link disabled\n"));
280 * Query and parse _CRS to get the current IRQ assignment.
283 status
= acpi_walk_resources(link
->handle
, METHOD_NAME__CRS
,
284 acpi_pci_link_check_current
, &irq
);
285 if (ACPI_FAILURE(status
)) {
286 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error evaluating _CRS\n"));
291 if (acpi_strict
&& !irq
) {
292 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "_CRS returned 0\n"));
296 link
->irq
.active
= irq
;
298 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Link at IRQ %d \n", link
->irq
.active
));
301 return_VALUE(result
);
304 static int acpi_pci_link_set(struct acpi_pci_link
*link
, int irq
)
307 acpi_status status
= AE_OK
;
309 struct acpi_resource res
;
310 struct acpi_resource end
;
312 struct acpi_buffer buffer
= { 0, NULL
};
314 ACPI_FUNCTION_TRACE("acpi_pci_link_set");
317 return_VALUE(-EINVAL
);
319 resource
= kmalloc(sizeof(*resource
) + 1, GFP_KERNEL
);
321 return_VALUE(-ENOMEM
);
323 memset(resource
, 0, sizeof(*resource
) + 1);
324 buffer
.length
= sizeof(*resource
) + 1;
325 buffer
.pointer
= resource
;
327 switch (link
->irq
.resource_type
) {
328 case ACPI_RSTYPE_IRQ
:
329 resource
->res
.id
= ACPI_RSTYPE_IRQ
;
330 resource
->res
.length
= sizeof(struct acpi_resource
);
331 resource
->res
.data
.irq
.edge_level
= link
->irq
.edge_level
;
332 resource
->res
.data
.irq
.active_high_low
=
333 link
->irq
.active_high_low
;
334 if (link
->irq
.edge_level
== ACPI_EDGE_SENSITIVE
)
335 resource
->res
.data
.irq
.shared_exclusive
=
338 resource
->res
.data
.irq
.shared_exclusive
= ACPI_SHARED
;
339 resource
->res
.data
.irq
.number_of_interrupts
= 1;
340 resource
->res
.data
.irq
.interrupts
[0] = irq
;
343 case ACPI_RSTYPE_EXT_IRQ
:
344 resource
->res
.id
= ACPI_RSTYPE_EXT_IRQ
;
345 resource
->res
.length
= sizeof(struct acpi_resource
);
346 resource
->res
.data
.extended_irq
.producer_consumer
=
348 resource
->res
.data
.extended_irq
.edge_level
=
349 link
->irq
.edge_level
;
350 resource
->res
.data
.extended_irq
.active_high_low
=
351 link
->irq
.active_high_low
;
352 if (link
->irq
.edge_level
== ACPI_EDGE_SENSITIVE
)
353 resource
->res
.data
.irq
.shared_exclusive
=
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 */
362 printk("ACPI BUG: resource_type %d\n", link
->irq
.resource_type
);
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"));
379 /* Query _STA, set device->status */
380 result
= acpi_bus_get_status(link
->device
);
382 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Unable to read status\n"));
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
);
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
), link
->irq
.active
, irq
);
411 link
->irq
.active
= irq
;
414 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Set IRQ %d\n", link
->irq
.active
));
418 return_VALUE(result
);
421 /* --------------------------------------------------------------------------
422 PCI Link IRQ Management
423 -------------------------------------------------------------------------- */
426 * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt
427 * Link Devices to move the PIRQs around to minimize sharing.
429 * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs
430 * that the BIOS has already set to active. This is necessary because
431 * ACPI has no automatic means of knowing what ISA IRQs are used. Note that
432 * if the BIOS doesn't set a Link Device active, ACPI needs to program it
433 * even if acpi_irq_nobalance is set.
435 * A tables of penalties avoids directing PCI interrupts to well known
436 * ISA IRQs. Boot params are available to over-ride the default table:
438 * List interrupts that are free for PCI use.
441 * List interrupts that should not be used for PCI:
444 * Note that PCI IRQ routers have a list of possible IRQs,
445 * which may not include the IRQs this table says are available.
447 * Since this heuristic can't tell the difference between a link
448 * that no device will attach to, vs. a link which may be shared
449 * by multiple active devices -- it is not optimal.
451 * If interrupt performance is that important, get an IO-APIC system
452 * with a pin dedicated to each device. Or for that matter, an MSI
456 #define ACPI_MAX_IRQS 256
457 #define ACPI_MAX_ISA_IRQ 16
459 #define PIRQ_PENALTY_PCI_AVAILABLE (0)
460 #define PIRQ_PENALTY_PCI_POSSIBLE (16*16)
461 #define PIRQ_PENALTY_PCI_USING (16*16*16)
462 #define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16)
463 #define PIRQ_PENALTY_ISA_USED (16*16*16*16*16)
464 #define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16)
466 static int acpi_irq_penalty
[ACPI_MAX_IRQS
] = {
467 PIRQ_PENALTY_ISA_ALWAYS
, /* IRQ0 timer */
468 PIRQ_PENALTY_ISA_ALWAYS
, /* IRQ1 keyboard */
469 PIRQ_PENALTY_ISA_ALWAYS
, /* IRQ2 cascade */
470 PIRQ_PENALTY_ISA_TYPICAL
, /* IRQ3 serial */
471 PIRQ_PENALTY_ISA_TYPICAL
, /* IRQ4 serial */
472 PIRQ_PENALTY_ISA_TYPICAL
, /* IRQ5 sometimes SoundBlaster */
473 PIRQ_PENALTY_ISA_TYPICAL
, /* IRQ6 */
474 PIRQ_PENALTY_ISA_TYPICAL
, /* IRQ7 parallel, spurious */
475 PIRQ_PENALTY_ISA_TYPICAL
, /* IRQ8 rtc, sometimes */
476 PIRQ_PENALTY_PCI_AVAILABLE
, /* IRQ9 PCI, often acpi */
477 PIRQ_PENALTY_PCI_AVAILABLE
, /* IRQ10 PCI */
478 PIRQ_PENALTY_PCI_AVAILABLE
, /* IRQ11 PCI */
479 PIRQ_PENALTY_ISA_USED
, /* IRQ12 mouse */
480 PIRQ_PENALTY_ISA_USED
, /* IRQ13 fpe, sometimes */
481 PIRQ_PENALTY_ISA_USED
, /* IRQ14 ide0 */
482 PIRQ_PENALTY_ISA_USED
, /* IRQ15 ide1 */
486 int __init
acpi_irq_penalty_init(void)
488 struct list_head
*node
= NULL
;
489 struct acpi_pci_link
*link
= NULL
;
492 ACPI_FUNCTION_TRACE("acpi_irq_penalty_init");
495 * Update penalties to facilitate IRQ balancing.
497 list_for_each(node
, &acpi_link
.entries
) {
499 link
= list_entry(node
, struct acpi_pci_link
, node
);
501 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
502 "Invalid link context\n"));
507 * reflect the possible and active irqs in the penalty table --
508 * useful for breaking ties.
510 if (link
->irq
.possible_count
) {
512 PIRQ_PENALTY_PCI_POSSIBLE
/
513 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
.
522 } else if (link
->irq
.active
) {
523 acpi_irq_penalty
[link
->irq
.active
] +=
524 PIRQ_PENALTY_PCI_POSSIBLE
;
527 /* Add a penalty for the SCI */
528 acpi_irq_penalty
[acpi_fadt
.sci_int
] += PIRQ_PENALTY_PCI_USING
;
533 static int acpi_irq_balance
; /* 0: static, 1: balance */
535 static int acpi_pci_link_allocate(struct acpi_pci_link
*link
)
540 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate");
542 if (link
->irq
.initialized
) {
543 if (link
->refcnt
== 0)
544 /* This means the link is disabled but initialized */
545 acpi_pci_link_set(link
, link
->irq
.active
);
550 * search for active IRQ in list of possible IRQs.
552 for (i
= 0; i
< link
->irq
.possible_count
; ++i
) {
553 if (link
->irq
.active
== link
->irq
.possible
[i
])
557 * forget active IRQ that is not in possible list
559 if (i
== link
->irq
.possible_count
) {
561 printk(KERN_WARNING PREFIX
"_CRS %d not found"
562 " in _PRS\n", link
->irq
.active
);
563 link
->irq
.active
= 0;
567 * if active found, use it; else pick entry from end of possible list.
569 if (link
->irq
.active
) {
570 irq
= link
->irq
.active
;
572 irq
= link
->irq
.possible
[link
->irq
.possible_count
- 1];
575 if (acpi_irq_balance
|| !link
->irq
.active
) {
577 * Select the best IRQ. This is done in reverse to promote
578 * the use of IRQs 9, 10, 11, and >15.
580 for (i
= (link
->irq
.possible_count
- 1); i
>= 0; i
--) {
581 if (acpi_irq_penalty
[irq
] >
582 acpi_irq_penalty
[link
->irq
.possible
[i
]])
583 irq
= link
->irq
.possible
[i
];
587 /* Attempt to enable the link device at this IRQ. */
588 if (acpi_pci_link_set(link
, irq
)) {
590 "Unable to set IRQ for %s [%s] (likely buggy ACPI BIOS).\n"
591 "Try pci=noacpi or acpi=off\n",
592 acpi_device_name(link
->device
),
593 acpi_device_bid(link
->device
));
594 return_VALUE(-ENODEV
);
596 acpi_irq_penalty
[link
->irq
.active
] += PIRQ_PENALTY_PCI_USING
;
597 printk(PREFIX
"%s [%s] enabled at IRQ %d\n",
598 acpi_device_name(link
->device
),
599 acpi_device_bid(link
->device
), link
->irq
.active
);
602 link
->irq
.initialized
= 1;
608 * acpi_pci_link_allocate_irq
609 * success: return IRQ >= 0
614 acpi_pci_link_allocate_irq(acpi_handle handle
,
616 int *edge_level
, int *active_high_low
, char **name
)
619 struct acpi_device
*device
= NULL
;
620 struct acpi_pci_link
*link
= NULL
;
622 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate_irq");
624 result
= acpi_bus_get_device(handle
, &device
);
626 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Invalid link device\n"));
630 link
= (struct acpi_pci_link
*)acpi_driver_data(device
);
632 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Invalid link context\n"));
636 /* TBD: Support multiple index (IRQ) entries per Link Device */
638 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Invalid index %d\n", index
));
642 down(&acpi_link_lock
);
643 if (acpi_pci_link_allocate(link
)) {
648 if (!link
->irq
.active
) {
650 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Link active IRQ is 0!\n"));
657 *edge_level
= link
->irq
.edge_level
;
659 *active_high_low
= link
->irq
.active_high_low
;
661 *name
= acpi_device_bid(link
->device
);
662 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
663 "Link %s is referenced\n",
664 acpi_device_bid(link
->device
)));
665 return_VALUE(link
->irq
.active
);
669 * We don't change link's irq information here. After it is reenabled, we
670 * continue use the info
672 int acpi_pci_link_free_irq(acpi_handle handle
)
674 struct acpi_device
*device
= NULL
;
675 struct acpi_pci_link
*link
= NULL
;
678 ACPI_FUNCTION_TRACE("acpi_pci_link_free_irq");
680 result
= acpi_bus_get_device(handle
, &device
);
682 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Invalid link device\n"));
686 link
= (struct acpi_pci_link
*)acpi_driver_data(device
);
688 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Invalid link context\n"));
692 down(&acpi_link_lock
);
693 if (!link
->irq
.initialized
) {
695 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Link isn't initialized\n"));
700 * The Link reference count allows us to _DISable an unused link
701 * and suspend time, and set it again on resume.
702 * However, 2.6.12 still has irq_router.resume
703 * which blindly restores the link state.
704 * So we disable the reference count method
705 * to prevent duplicate acpi_pci_link_set()
706 * which would harm some systems
710 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
711 "Link %s is dereferenced\n",
712 acpi_device_bid(link
->device
)));
714 if (link
->refcnt
== 0) {
715 acpi_ut_evaluate_object(link
->handle
, "_DIS", 0, NULL
);
718 return_VALUE(link
->irq
.active
);
721 /* --------------------------------------------------------------------------
723 -------------------------------------------------------------------------- */
725 static int acpi_pci_link_add(struct acpi_device
*device
)
728 struct acpi_pci_link
*link
= NULL
;
732 ACPI_FUNCTION_TRACE("acpi_pci_link_add");
735 return_VALUE(-EINVAL
);
737 link
= kmalloc(sizeof(struct acpi_pci_link
), GFP_KERNEL
);
739 return_VALUE(-ENOMEM
);
740 memset(link
, 0, sizeof(struct acpi_pci_link
));
742 link
->device
= device
;
743 link
->handle
= device
->handle
;
744 strcpy(acpi_device_name(device
), ACPI_PCI_LINK_DEVICE_NAME
);
745 strcpy(acpi_device_class(device
), ACPI_PCI_LINK_CLASS
);
746 acpi_driver_data(device
) = link
;
748 down(&acpi_link_lock
);
749 result
= acpi_pci_link_get_possible(link
);
753 /* query and set link->irq.active */
754 acpi_pci_link_get_current(link
);
756 printk(PREFIX
"%s [%s] (IRQs", acpi_device_name(device
),
757 acpi_device_bid(device
));
758 for (i
= 0; i
< link
->irq
.possible_count
; i
++) {
759 if (link
->irq
.active
== link
->irq
.possible
[i
]) {
760 printk(" *%d", link
->irq
.possible
[i
]);
763 printk(" %d", link
->irq
.possible
[i
]);
769 printk(" *%d", link
->irq
.active
);
771 if (!link
->device
->status
.enabled
)
772 printk(", disabled.");
776 /* TBD: Acquire/release lock */
777 list_add_tail(&link
->node
, &acpi_link
.entries
);
781 /* disable all links -- to be activated on use */
782 acpi_ut_evaluate_object(link
->handle
, "_DIS", 0, NULL
);
788 return_VALUE(result
);
791 static int acpi_pci_link_resume(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
));
802 * FIXME: this is a workaround to avoid nasty warning. It will be removed
803 * after every device calls pci_disable_device in .resume.
806 static int irqrouter_resume(struct sys_device
*dev
)
808 struct list_head
*node
= NULL
;
809 struct acpi_pci_link
*link
= NULL
;
811 ACPI_FUNCTION_TRACE("irqrouter_resume");
814 list_for_each(node
, &acpi_link
.entries
) {
815 link
= list_entry(node
, struct acpi_pci_link
, node
);
817 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
818 "Invalid link context\n"));
821 acpi_pci_link_resume(link
);
827 static int acpi_pci_link_remove(struct acpi_device
*device
, int type
)
829 struct acpi_pci_link
*link
= NULL
;
831 ACPI_FUNCTION_TRACE("acpi_pci_link_remove");
833 if (!device
|| !acpi_driver_data(device
))
834 return_VALUE(-EINVAL
);
836 link
= (struct acpi_pci_link
*)acpi_driver_data(device
);
838 down(&acpi_link_lock
);
839 list_del(&link
->node
);
848 * modify acpi_irq_penalty[] from cmdline
850 static int __init
acpi_irq_penalty_update(char *str
, int used
)
854 for (i
= 0; i
< 16; i
++) {
858 retval
= get_option(&str
, &irq
);
861 break; /* no number found */
866 if (irq
>= ACPI_MAX_IRQS
)
870 acpi_irq_penalty
[irq
] += PIRQ_PENALTY_ISA_USED
;
872 acpi_irq_penalty
[irq
] = PIRQ_PENALTY_PCI_AVAILABLE
;
874 if (retval
!= 2) /* no next number */
881 * We'd like PNP to call this routine for the
882 * single ISA_USED value for each legacy device.
883 * But instead it calls us with each POSSIBLE setting.
884 * There is no ISA_POSSIBLE weight, so we simply use
885 * the (small) PCI_USING penalty.
887 void acpi_penalize_isa_irq(int irq
, int active
)
890 acpi_irq_penalty
[irq
] += PIRQ_PENALTY_ISA_USED
;
892 acpi_irq_penalty
[irq
] += PIRQ_PENALTY_PCI_USING
;
896 * Over-ride default table to reserve additional IRQs for use by ISA
897 * e.g. acpi_irq_isa=5
898 * Useful for telling ACPI how not to interfere with your ISA sound card.
900 static int __init
acpi_irq_isa(char *str
)
902 return acpi_irq_penalty_update(str
, 1);
905 __setup("acpi_irq_isa=", acpi_irq_isa
);
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.
912 static int __init
acpi_irq_pci(char *str
)
914 return acpi_irq_penalty_update(str
, 0);
917 __setup("acpi_irq_pci=", acpi_irq_pci
);
919 static int __init
acpi_irq_nobalance_set(char *str
)
921 acpi_irq_balance
= 0;
925 __setup("acpi_irq_nobalance", acpi_irq_nobalance_set
);
927 int __init
acpi_irq_balance_set(char *str
)
929 acpi_irq_balance
= 1;
933 __setup("acpi_irq_balance", acpi_irq_balance_set
);
935 /* FIXME: we will remove this interface after all drivers call pci_disable_device */
936 static struct sysdev_class irqrouter_sysdev_class
= {
937 set_kset_name("irqrouter"),
938 .resume
= irqrouter_resume
,
941 static struct sys_device device_irqrouter
= {
943 .cls
= &irqrouter_sysdev_class
,
946 static int __init
irqrouter_init_sysfs(void)
950 ACPI_FUNCTION_TRACE("irqrouter_init_sysfs");
952 if (acpi_disabled
|| acpi_noirq
)
955 error
= sysdev_class_register(&irqrouter_sysdev_class
);
957 error
= sysdev_register(&device_irqrouter
);
962 device_initcall(irqrouter_init_sysfs
);
964 static int __init
acpi_pci_link_init(void)
966 ACPI_FUNCTION_TRACE("acpi_pci_link_init");
972 INIT_LIST_HEAD(&acpi_link
.entries
);
974 if (acpi_bus_register_driver(&acpi_pci_link_driver
) < 0)
975 return_VALUE(-ENODEV
);
980 subsys_initcall(acpi_pci_link_init
);