Lines Matching +full:irq +full:- +full:device
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
10 * 1. Support more than one IRQ resource entry per link device (index).
12 * for IRQ management (e.g. start()->_SRS).
28 #include <linux/irq.h>
36 static int acpi_pci_link_add(struct acpi_device *device,
38 static void acpi_pci_link_remove(struct acpi_device *device);
53 * later even the link is disable. Instead, we just repick the active irq
56 u32 active; /* Current IRQ */
68 struct acpi_device *device; member
69 struct acpi_pci_link_irq irq; member
75 static int sci_irq = -1, sci_penalty;
77 /* --------------------------------------------------------------------------
78 PCI Link Device Management
79 -------------------------------------------------------------------------- */
88 acpi_handle handle = link->device->handle; in acpi_pci_link_check_possible()
91 switch (resource->type) { in acpi_pci_link_check_possible()
97 struct acpi_resource_irq *p = &resource->data.irq; in acpi_pci_link_check_possible()
98 if (!p->interrupt_count) { in acpi_pci_link_check_possible()
100 "Blank _PRS IRQ resource\n"); in acpi_pci_link_check_possible()
104 (i < p->interrupt_count in acpi_pci_link_check_possible()
106 if (!p->interrupts[i]) { in acpi_pci_link_check_possible()
108 "Invalid _PRS IRQ %d\n", in acpi_pci_link_check_possible()
109 p->interrupts[i]); in acpi_pci_link_check_possible()
112 link->irq.possible[i] = p->interrupts[i]; in acpi_pci_link_check_possible()
113 link->irq.possible_count++; in acpi_pci_link_check_possible()
115 link->irq.triggering = p->triggering; in acpi_pci_link_check_possible()
116 link->irq.polarity = p->polarity; in acpi_pci_link_check_possible()
117 link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ; in acpi_pci_link_check_possible()
123 &resource->data.extended_irq; in acpi_pci_link_check_possible()
124 if (!p->interrupt_count) { in acpi_pci_link_check_possible()
126 "Blank _PRS EXT IRQ resource\n"); in acpi_pci_link_check_possible()
130 (i < p->interrupt_count in acpi_pci_link_check_possible()
132 if (!p->interrupts[i]) { in acpi_pci_link_check_possible()
134 "Invalid _PRS IRQ %d\n", in acpi_pci_link_check_possible()
135 p->interrupts[i]); in acpi_pci_link_check_possible()
138 link->irq.possible[i] = p->interrupts[i]; in acpi_pci_link_check_possible()
139 link->irq.possible_count++; in acpi_pci_link_check_possible()
141 link->irq.triggering = p->triggering; in acpi_pci_link_check_possible()
142 link->irq.polarity = p->polarity; in acpi_pci_link_check_possible()
143 link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; in acpi_pci_link_check_possible()
147 acpi_handle_debug(handle, "_PRS resource type 0x%x is not IRQ\n", in acpi_pci_link_check_possible()
148 resource->type); in acpi_pci_link_check_possible()
157 acpi_handle handle = link->device->handle; in acpi_pci_link_get_possible()
168 link->irq.possible_count); in acpi_pci_link_get_possible()
176 int *irq = context; in acpi_pci_link_check_current() local
178 switch (resource->type) { in acpi_pci_link_check_current()
184 struct acpi_resource_irq *p = &resource->data.irq; in acpi_pci_link_check_current()
185 if (!p->interrupt_count) { in acpi_pci_link_check_current()
187 * IRQ descriptors may have no IRQ# bits set, in acpi_pci_link_check_current()
190 pr_debug("Blank _CRS IRQ resource\n"); in acpi_pci_link_check_current()
193 *irq = p->interrupts[0]; in acpi_pci_link_check_current()
199 &resource->data.extended_irq; in acpi_pci_link_check_current()
200 if (!p->interrupt_count) { in acpi_pci_link_check_current()
202 * extended IRQ descriptors must in acpi_pci_link_check_current()
203 * return at least 1 IRQ in acpi_pci_link_check_current()
205 pr_debug("Blank _CRS EXT IRQ resource\n"); in acpi_pci_link_check_current()
208 *irq = p->interrupts[0]; in acpi_pci_link_check_current()
213 pr_debug("_CRS resource type 0x%x is not IRQ\n", in acpi_pci_link_check_current()
214 resource->type); in acpi_pci_link_check_current()
222 * Run _CRS and set link->irq.active
225 * 0 - success
226 * !0 - failure
230 acpi_handle handle = link->device->handle; in acpi_pci_link_get_current()
233 int irq = 0; in acpi_pci_link_get_current() local
235 link->irq.active = 0; in acpi_pci_link_get_current()
239 /* Query _STA, set link->device->status */ in acpi_pci_link_get_current()
240 result = acpi_bus_get_status(link->device); in acpi_pci_link_get_current()
246 if (!link->device->status.enabled) { in acpi_pci_link_get_current()
253 * Query and parse _CRS to get the current IRQ assignment. in acpi_pci_link_get_current()
257 acpi_pci_link_check_current, &irq); in acpi_pci_link_get_current()
260 result = -ENODEV; in acpi_pci_link_get_current()
264 if (acpi_strict && !irq) { in acpi_pci_link_get_current()
266 result = -ENODEV; in acpi_pci_link_get_current()
269 link->irq.active = irq; in acpi_pci_link_get_current()
271 acpi_handle_debug(handle, "Link at IRQ %d \n", link->irq.active); in acpi_pci_link_get_current()
277 static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) in acpi_pci_link_set() argument
284 acpi_handle handle = link->device->handle; in acpi_pci_link_set()
288 if (!irq) in acpi_pci_link_set()
289 return -EINVAL; in acpi_pci_link_set()
293 return -ENOMEM; in acpi_pci_link_set()
298 switch (link->irq.resource_type) { in acpi_pci_link_set()
300 resource->res.type = ACPI_RESOURCE_TYPE_IRQ; in acpi_pci_link_set()
301 resource->res.length = sizeof(struct acpi_resource); in acpi_pci_link_set()
302 resource->res.data.irq.triggering = link->irq.triggering; in acpi_pci_link_set()
303 resource->res.data.irq.polarity = in acpi_pci_link_set()
304 link->irq.polarity; in acpi_pci_link_set()
305 if (link->irq.triggering == ACPI_EDGE_SENSITIVE) in acpi_pci_link_set()
306 resource->res.data.irq.shareable = in acpi_pci_link_set()
309 resource->res.data.irq.shareable = ACPI_SHARED; in acpi_pci_link_set()
310 resource->res.data.irq.interrupt_count = 1; in acpi_pci_link_set()
311 resource->res.data.irq.interrupts[0] = irq; in acpi_pci_link_set()
315 resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; in acpi_pci_link_set()
316 resource->res.length = sizeof(struct acpi_resource); in acpi_pci_link_set()
317 resource->res.data.extended_irq.producer_consumer = in acpi_pci_link_set()
319 resource->res.data.extended_irq.triggering = in acpi_pci_link_set()
320 link->irq.triggering; in acpi_pci_link_set()
321 resource->res.data.extended_irq.polarity = in acpi_pci_link_set()
322 link->irq.polarity; in acpi_pci_link_set()
323 if (link->irq.triggering == ACPI_EDGE_SENSITIVE) in acpi_pci_link_set()
324 resource->res.data.extended_irq.shareable = in acpi_pci_link_set()
327 resource->res.data.extended_irq.shareable = ACPI_SHARED; in acpi_pci_link_set()
328 resource->res.data.extended_irq.interrupt_count = 1; in acpi_pci_link_set()
329 resource->res.data.extended_irq.interrupts[0] = irq; in acpi_pci_link_set()
334 link->irq.resource_type); in acpi_pci_link_set()
335 result = -EINVAL; in acpi_pci_link_set()
339 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG; in acpi_pci_link_set()
340 resource->end.length = sizeof(struct acpi_resource); in acpi_pci_link_set()
343 status = acpi_set_current_resources(link->device->handle, &buffer); in acpi_pci_link_set()
348 result = -ENODEV; in acpi_pci_link_set()
352 /* Query _STA, set device->status */ in acpi_pci_link_set()
353 result = acpi_bus_get_status(link->device); in acpi_pci_link_set()
358 if (!link->device->status.enabled) in acpi_pci_link_set()
361 /* Query _CRS, set link->irq.active */ in acpi_pci_link_set()
369 * set link->irq.active in acpi_pci_link_set()
371 if (link->irq.active != irq) { in acpi_pci_link_set()
376 acpi_handle_warn(handle, "BIOS reported IRQ %d, using IRQ %d\n", in acpi_pci_link_set()
377 link->irq.active, irq); in acpi_pci_link_set()
378 link->irq.active = irq; in acpi_pci_link_set()
381 acpi_handle_debug(handle, "Set IRQ %d\n", link->irq.active); in acpi_pci_link_set()
388 /* --------------------------------------------------------------------------
389 PCI Link IRQ Management
390 -------------------------------------------------------------------------- */
399 * if the BIOS doesn't set a Link Device active, ACPI needs to program it
403 * ISA IRQs. Boot params are available to over-ride the default table:
411 * Note that PCI IRQ routers have a list of possible IRQs,
415 * that no device will attach to, vs. a link which may be shared
416 * by multiple active devices -- it is not optimal.
418 * If interrupt performance is that important, get an IO-APIC system
419 * with a pin dedicated to each device. Or for that matter, an MSI
451 static int acpi_irq_pci_sharing_penalty(int irq) in acpi_irq_pci_sharing_penalty() argument
459 * If a link is active, penalize its IRQ heavily in acpi_irq_pci_sharing_penalty()
460 * so we try to choose a different IRQ. in acpi_irq_pci_sharing_penalty()
462 if (link->irq.active && link->irq.active == irq) in acpi_irq_pci_sharing_penalty()
468 for (i = 0; i < link->irq.possible_count; i++) in acpi_irq_pci_sharing_penalty()
469 if (link->irq.possible[i] == irq) in acpi_irq_pci_sharing_penalty()
471 link->irq.possible_count; in acpi_irq_pci_sharing_penalty()
477 static int acpi_irq_get_penalty(int irq) in acpi_irq_get_penalty() argument
481 if (irq == sci_irq) in acpi_irq_get_penalty()
484 if (irq < ACPI_MAX_ISA_IRQS) in acpi_irq_get_penalty()
485 return penalty + acpi_isa_irq_penalty[irq]; in acpi_irq_get_penalty()
487 return penalty + acpi_irq_pci_sharing_penalty(irq); in acpi_irq_get_penalty()
496 * Update penalties to facilitate IRQ balancing. in acpi_irq_penalty_init()
501 * reflect the possible and active irqs in the penalty table -- in acpi_irq_penalty_init()
504 if (link->irq.possible_count) { in acpi_irq_penalty_init()
507 link->irq.possible_count; in acpi_irq_penalty_init()
509 for (i = 0; i < link->irq.possible_count; i++) { in acpi_irq_penalty_init()
510 if (link->irq.possible[i] < ACPI_MAX_ISA_IRQS) in acpi_irq_penalty_init()
511 acpi_isa_irq_penalty[link->irq. in acpi_irq_penalty_init()
516 } else if (link->irq.active && in acpi_irq_penalty_init()
517 (link->irq.active < ACPI_MAX_ISA_IRQS)) { in acpi_irq_penalty_init()
518 acpi_isa_irq_penalty[link->irq.active] += in acpi_irq_penalty_init()
526 static int acpi_irq_balance = -1; /* 0: static, 1: balance */
530 acpi_handle handle = link->device->handle; in acpi_pci_link_allocate()
531 int irq; in acpi_pci_link_allocate() local
534 if (link->irq.initialized) { in acpi_pci_link_allocate()
535 if (link->refcnt == 0) in acpi_pci_link_allocate()
537 acpi_pci_link_set(link, link->irq.active); in acpi_pci_link_allocate()
542 * search for active IRQ in list of possible IRQs. in acpi_pci_link_allocate()
544 for (i = 0; i < link->irq.possible_count; ++i) { in acpi_pci_link_allocate()
545 if (link->irq.active == link->irq.possible[i]) in acpi_pci_link_allocate()
549 * forget active IRQ that is not in possible list in acpi_pci_link_allocate()
551 if (i == link->irq.possible_count) { in acpi_pci_link_allocate()
554 link->irq.active); in acpi_pci_link_allocate()
555 link->irq.active = 0; in acpi_pci_link_allocate()
561 if (link->irq.active) in acpi_pci_link_allocate()
562 irq = link->irq.active; in acpi_pci_link_allocate()
564 irq = link->irq.possible[link->irq.possible_count - 1]; in acpi_pci_link_allocate()
566 if (acpi_irq_balance || !link->irq.active) { in acpi_pci_link_allocate()
568 * Select the best IRQ. This is done in reverse to promote in acpi_pci_link_allocate()
571 for (i = (link->irq.possible_count - 1); i >= 0; i--) { in acpi_pci_link_allocate()
572 if (acpi_irq_get_penalty(irq) > in acpi_pci_link_allocate()
573 acpi_irq_get_penalty(link->irq.possible[i])) in acpi_pci_link_allocate()
574 irq = link->irq.possible[i]; in acpi_pci_link_allocate()
577 if (acpi_irq_get_penalty(irq) >= PIRQ_PENALTY_ISA_ALWAYS) { in acpi_pci_link_allocate()
579 "No IRQ available. Try pci=noacpi or acpi=off\n"); in acpi_pci_link_allocate()
580 return -ENODEV; in acpi_pci_link_allocate()
583 /* Attempt to enable the link device at this IRQ. */ in acpi_pci_link_allocate()
584 if (acpi_pci_link_set(link, irq)) { in acpi_pci_link_allocate()
586 "Unable to set IRQ. Try pci=noacpi or acpi=off\n"); in acpi_pci_link_allocate()
587 return -ENODEV; in acpi_pci_link_allocate()
589 if (link->irq.active < ACPI_MAX_ISA_IRQS) in acpi_pci_link_allocate()
590 acpi_isa_irq_penalty[link->irq.active] += in acpi_pci_link_allocate()
593 acpi_handle_info(handle, "Enabled at IRQ %d\n", in acpi_pci_link_allocate()
594 link->irq.active); in acpi_pci_link_allocate()
597 link->irq.initialized = 1; in acpi_pci_link_allocate()
603 * success: return IRQ >= 0
604 * failure: return -1
609 struct acpi_device *device = acpi_fetch_acpi_dev(handle); in acpi_pci_link_allocate_irq() local
612 if (!device) { in acpi_pci_link_allocate_irq()
613 acpi_handle_err(handle, "Invalid link device\n"); in acpi_pci_link_allocate_irq()
614 return -1; in acpi_pci_link_allocate_irq()
617 link = acpi_driver_data(device); in acpi_pci_link_allocate_irq()
620 return -1; in acpi_pci_link_allocate_irq()
623 /* TBD: Support multiple index (IRQ) entries per Link Device */ in acpi_pci_link_allocate_irq()
626 return -1; in acpi_pci_link_allocate_irq()
632 return -1; in acpi_pci_link_allocate_irq()
635 if (!link->irq.active) { in acpi_pci_link_allocate_irq()
637 acpi_handle_err(handle, "Link active IRQ is 0!\n"); in acpi_pci_link_allocate_irq()
638 return -1; in acpi_pci_link_allocate_irq()
640 link->refcnt++; in acpi_pci_link_allocate_irq()
644 *triggering = link->irq.triggering; in acpi_pci_link_allocate_irq()
646 *polarity = link->irq.polarity; in acpi_pci_link_allocate_irq()
648 *name = acpi_device_bid(link->device); in acpi_pci_link_allocate_irq()
650 return link->irq.active; in acpi_pci_link_allocate_irq()
654 * We don't change link's irq information here. After it is reenabled, we
659 struct acpi_device *device = acpi_fetch_acpi_dev(handle); in acpi_pci_link_free_irq() local
662 if (!device) { in acpi_pci_link_free_irq()
663 acpi_handle_err(handle, "Invalid link device\n"); in acpi_pci_link_free_irq()
664 return -1; in acpi_pci_link_free_irq()
667 link = acpi_driver_data(device); in acpi_pci_link_free_irq()
670 return -1; in acpi_pci_link_free_irq()
674 if (!link->irq.initialized) { in acpi_pci_link_free_irq()
677 return -1; in acpi_pci_link_free_irq()
689 link->refcnt--; in acpi_pci_link_free_irq()
693 if (link->refcnt == 0) in acpi_pci_link_free_irq()
694 acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL); in acpi_pci_link_free_irq()
697 return link->irq.active; in acpi_pci_link_free_irq()
700 /* --------------------------------------------------------------------------
702 -------------------------------------------------------------------------- */
704 static int acpi_pci_link_add(struct acpi_device *device, in acpi_pci_link_add() argument
707 acpi_handle handle = device->handle; in acpi_pci_link_add()
714 return -ENOMEM; in acpi_pci_link_add()
716 link->device = device; in acpi_pci_link_add()
717 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); in acpi_pci_link_add()
718 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); in acpi_pci_link_add()
719 device->driver_data = link; in acpi_pci_link_add()
726 /* query and set link->irq.active */ in acpi_pci_link_add()
729 pr_info("Interrupt link %s configured for IRQ %d\n", in acpi_pci_link_add()
730 acpi_device_bid(device), link->irq.active); in acpi_pci_link_add()
732 for (i = 0; i < link->irq.possible_count; i++) { in acpi_pci_link_add()
733 if (link->irq.active != link->irq.possible[i]) in acpi_pci_link_add()
734 acpi_handle_debug(handle, "Possible IRQ %d\n", in acpi_pci_link_add()
735 link->irq.possible[i]); in acpi_pci_link_add()
738 if (!link->device->status.enabled) in acpi_pci_link_add()
739 pr_info("Interrupt link %s disabled\n", acpi_device_bid(device)); in acpi_pci_link_add()
741 list_add_tail(&link->list, &acpi_link_list); in acpi_pci_link_add()
744 /* disable all links -- to be activated on use */ in acpi_pci_link_add()
751 acpi_dev_clear_dependencies(device); in acpi_pci_link_add()
758 if (link->refcnt && link->irq.active && link->irq.initialized) in acpi_pci_link_resume()
759 return (acpi_pci_link_set(link, link->irq.active)); in acpi_pci_link_resume()
773 static void acpi_pci_link_remove(struct acpi_device *device) in acpi_pci_link_remove() argument
777 link = acpi_driver_data(device); in acpi_pci_link_remove()
780 list_del(&link->list); in acpi_pci_link_remove()
795 int irq; in acpi_irq_penalty_update() local
798 retval = get_option(&str, &irq); in acpi_irq_penalty_update()
803 /* see if this is a ISA IRQ */ in acpi_irq_penalty_update()
804 if ((irq < 0) || (irq >= ACPI_MAX_ISA_IRQS)) in acpi_irq_penalty_update()
808 new_penalty = acpi_isa_irq_penalty[irq] + in acpi_irq_penalty_update()
813 acpi_isa_irq_penalty[irq] = new_penalty; in acpi_irq_penalty_update()
822 * single ISA_USED value for each legacy device.
827 void acpi_penalize_isa_irq(int irq, int active) in acpi_penalize_isa_irq() argument
829 if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty))) in acpi_penalize_isa_irq()
830 acpi_isa_irq_penalty[irq] += in acpi_penalize_isa_irq()
834 bool acpi_isa_irq_available(int irq) in acpi_isa_irq_available() argument
836 return irq >= 0 && (irq >= ARRAY_SIZE(acpi_isa_irq_penalty) || in acpi_isa_irq_available()
837 acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS); in acpi_isa_irq_available()
840 void acpi_penalize_sci_irq(int irq, int trigger, int polarity) in acpi_penalize_sci_irq() argument
842 sci_irq = irq; in acpi_penalize_sci_irq()
852 * Over-ride default table to reserve additional IRQs for use by ISA
864 * Over-ride default table to free additional IRQs for use by PCI
866 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
900 if (acpi_irq_balance == -1) { in acpi_pci_link_init()