Lines Matching +full:auto +full:- +full:sleep +full:- +full:disabled

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
4 * Copyright (C) 2005-2006 Thomas Gleixner
50 while (irqd_irq_inprogress(&desc->irq_data)) in __synchronize_hardirq()
53 /* Ok, that indicated we're done: double-check carefully. */ in __synchronize_hardirq()
54 raw_spin_lock_irqsave(&desc->lock, flags); in __synchronize_hardirq()
55 inprogress = irqd_irq_inprogress(&desc->irq_data); in __synchronize_hardirq()
70 raw_spin_unlock_irqrestore(&desc->lock, flags); in __synchronize_hardirq()
77 * synchronize_hardirq - wait for pending hard IRQ handlers (on other CPUs)
91 * This function may be called - with care - from IRQ context.
95 * called with interrupts disabled and the target CPU of the interrupt
104 return !atomic_read(&desc->threads_active); in synchronize_hardirq()
118 wait_event(desc->wait_for_threads, !atomic_read(&desc->threads_active)); in __synchronize_irq()
122 * synchronize_irq - wait for pending IRQ handlers (on other CPUs)
129 * Can only be called from preemptible code as it might sleep when
150 if (!desc || !irqd_can_balance(&desc->irq_data) || in __irq_can_set_affinity()
151 !desc->irq_data.chip || !desc->irq_data.chip->irq_set_affinity) in __irq_can_set_affinity()
157 * irq_can_set_affinity - Check if the affinity of a given irq can be set
167 * irq_can_set_affinity_usr - Check if affinity of a irq can be set from user space
178 !irqd_affinity_is_managed(&desc->irq_data); in irq_can_set_affinity_usr()
182 * irq_set_thread_affinity - Notify irq threads to adjust affinity
187 * set_cpus_allowed_ptr() here as we hold desc->lock and this
195 if (action->thread) { in irq_set_thread_affinity()
196 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_set_thread_affinity()
197 wake_up_process(action->thread); in irq_set_thread_affinity()
199 if (action->secondary && action->secondary->thread) { in irq_set_thread_affinity()
200 set_bit(IRQTF_AFFINITY, &action->secondary->thread_flags); in irq_set_thread_affinity()
201 wake_up_process(action->secondary->thread); in irq_set_thread_affinity()
215 chip->name, data->irq); in irq_validate_effective_affinity()
232 if (!chip || !chip->irq_set_affinity) in irq_do_set_affinity()
233 return -EINVAL; in irq_do_set_affinity()
276 ret = chip->irq_set_affinity(data, tmp_mask, force); in irq_do_set_affinity()
278 ret = chip->irq_set_affinity(data, mask, force); in irq_do_set_affinity()
280 ret = -EINVAL; in irq_do_set_affinity()
285 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_do_set_affinity()
310 return -EBUSY; in irq_set_affinity_pending()
324 if (ret == -EBUSY && !force) in irq_try_set_affinity()
347 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_set_affinity_deactivated()
360 if (!chip || !chip->irq_set_affinity) in irq_set_affinity_locked()
361 return -EINVAL; in irq_set_affinity_locked()
373 if (desc->affinity_notify) { in irq_set_affinity_locked()
374 kref_get(&desc->affinity_notify->kref); in irq_set_affinity_locked()
375 if (!schedule_work(&desc->affinity_notify->work)) { in irq_set_affinity_locked()
377 kref_put(&desc->affinity_notify->kref, in irq_set_affinity_locked()
378 desc->affinity_notify->release); in irq_set_affinity_locked()
387 * irq_update_affinity_desc - Update affinity management for an interrupt
394 * There are certain limitations on when it may be used - attempts to use it
397 * managed/non-managed interrupt accounting. In addition, attempts to use it on
414 return -EOPNOTSUPP; in irq_update_affinity_desc()
418 return -EINVAL; in irq_update_affinity_desc()
421 if (irqd_is_started(&desc->irq_data)) { in irq_update_affinity_desc()
422 ret = -EBUSY; in irq_update_affinity_desc()
427 if (irqd_affinity_is_managed(&desc->irq_data)) { in irq_update_affinity_desc()
428 ret = -EBUSY; in irq_update_affinity_desc()
436 activated = irqd_is_activated(&desc->irq_data); in irq_update_affinity_desc()
438 irq_domain_deactivate_irq(&desc->irq_data); in irq_update_affinity_desc()
440 if (affinity->is_managed) { in irq_update_affinity_desc()
441 irqd_set(&desc->irq_data, IRQD_AFFINITY_MANAGED); in irq_update_affinity_desc()
442 irqd_set(&desc->irq_data, IRQD_MANAGED_SHUTDOWN); in irq_update_affinity_desc()
445 cpumask_copy(desc->irq_common_data.affinity, &affinity->mask); in irq_update_affinity_desc()
449 irq_domain_activate_irq(&desc->irq_data, false); in irq_update_affinity_desc()
464 return -EINVAL; in __irq_set_affinity()
466 raw_spin_lock_irqsave(&desc->lock, flags); in __irq_set_affinity()
468 raw_spin_unlock_irqrestore(&desc->lock, flags); in __irq_set_affinity()
473 * irq_set_affinity - Set the irq affinity of a given irq
486 * irq_force_affinity - Force the irq affinity of a given irq
509 return -EINVAL; in __irq_apply_affinity_hint()
510 desc->affinity_hint = m; in __irq_apply_affinity_hint()
522 struct irq_desc *desc = irq_to_desc(notify->irq); in irq_affinity_notify()
529 raw_spin_lock_irqsave(&desc->lock, flags); in irq_affinity_notify()
530 if (irq_move_pending(&desc->irq_data)) in irq_affinity_notify()
533 cpumask_copy(cpumask, desc->irq_common_data.affinity); in irq_affinity_notify()
534 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_affinity_notify()
536 notify->notify(notify, cpumask); in irq_affinity_notify()
540 kref_put(&notify->kref, notify->release); in irq_affinity_notify()
544 * irq_set_affinity_notifier - control notification of IRQ affinity changes
551 * after the IRQ is allocated and must be disabled before the IRQ is
565 return -EINVAL; in irq_set_affinity_notifier()
569 notify->irq = irq; in irq_set_affinity_notifier()
570 kref_init(&notify->kref); in irq_set_affinity_notifier()
571 INIT_WORK(&notify->work, irq_affinity_notify); in irq_set_affinity_notifier()
574 raw_spin_lock_irqsave(&desc->lock, flags); in irq_set_affinity_notifier()
575 old_notify = desc->affinity_notify; in irq_set_affinity_notifier()
576 desc->affinity_notify = notify; in irq_set_affinity_notifier()
577 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_set_affinity_notifier()
580 if (cancel_work_sync(&old_notify->work)) { in irq_set_affinity_notifier()
582 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
584 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
611 if (irqd_affinity_is_managed(&desc->irq_data) || in irq_setup_affinity()
612 irqd_has_set(&desc->irq_data, IRQD_AFFINITY_SET)) { in irq_setup_affinity()
613 if (cpumask_intersects(desc->irq_common_data.affinity, in irq_setup_affinity()
615 set = desc->irq_common_data.affinity; in irq_setup_affinity()
617 irqd_clear(&desc->irq_data, IRQD_AFFINITY_SET); in irq_setup_affinity()
631 ret = irq_do_set_affinity(&desc->irq_data, &mask, false); in irq_setup_affinity()
646 * irq_set_vcpu_affinity - Set vcpu affinity for the interrupt
654 * KVM -> IOMMU -> irq_set_vcpu_affinity().
662 int ret = -ENOSYS; in irq_set_vcpu_affinity()
665 return -EINVAL; in irq_set_vcpu_affinity()
670 if (chip && chip->irq_set_vcpu_affinity) in irq_set_vcpu_affinity()
673 data = data->parent_data; in irq_set_vcpu_affinity()
680 ret = chip->irq_set_vcpu_affinity(data, vcpu_info); in irq_set_vcpu_affinity()
689 if (!desc->depth++) in __disable_irq()
699 return -EINVAL; in __disable_irq_nosync()
706 * disable_irq_nosync - disable an irq without waiting
723 * disable_irq - disable an irq and wait for completion
732 * Can only be called from preemptible code as it might sleep when
745 * disable_hardirq - disables an irq and waits for hardirq completion
759 * This function may be called - with care - from IRQ context.
771 * disable_nmi_nosync - disable an nmi without waiting
787 switch (desc->depth) { in __enable_irq()
794 if (desc->istate & IRQS_SUSPENDED) in __enable_irq()
813 desc->depth--; in __enable_irq()
818 * enable_irq - enable handling of an irq
823 * IRQ line is re-enabled.
826 * desc->irq_data.chip->bus_lock and desc->chip->bus_sync_unlock are NULL !
835 if (WARN(!desc->irq_data.chip, in enable_irq()
846 * enable_nmi - enable handling of an nmi
852 * IRQ line is re-enabled.
862 int ret = -ENXIO; in set_irq_wake_real()
864 if (irq_desc_get_chip(desc)->flags & IRQCHIP_SKIP_SET_WAKE) in set_irq_wake_real()
867 if (desc->irq_data.chip->irq_set_wake) in set_irq_wake_real()
868 ret = desc->irq_data.chip->irq_set_wake(&desc->irq_data, on); in set_irq_wake_real()
874 * irq_set_irq_wake - control irq power management wakeup
879 * disabled by default. Enables and disables must match,
880 * just as they match for non-wakeup mode support.
882 * Wakeup mode lets this IRQ wake the system from sleep
887 * disabled with disable_irq() and still wake the system as
899 return -EINVAL; in irq_set_irq_wake()
903 ret = -EINVAL; in irq_set_irq_wake()
907 /* wakeup-capable irqs can be shared between drivers that in irq_set_irq_wake()
908 * don't need to have the same sleep mode behaviors. in irq_set_irq_wake()
911 if (desc->wake_depth++ == 0) { in irq_set_irq_wake()
914 desc->wake_depth = 0; in irq_set_irq_wake()
916 irqd_set(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
919 if (desc->wake_depth == 0) { in irq_set_irq_wake()
921 } else if (--desc->wake_depth == 0) { in irq_set_irq_wake()
924 desc->wake_depth = 1; in irq_set_irq_wake()
926 irqd_clear(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
951 if (!desc->action || in can_request_irq()
952 irqflags & desc->action->flags & IRQF_SHARED) in can_request_irq()
961 struct irq_chip *chip = desc->irq_data.chip; in __irq_set_trigger()
964 if (!chip || !chip->irq_set_type) { in __irq_set_trigger()
967 * flow-types? in __irq_set_trigger()
971 chip ? (chip->name ? : "unknown") : "unknown"); in __irq_set_trigger()
975 if (chip->flags & IRQCHIP_SET_TYPE_MASKED) { in __irq_set_trigger()
976 if (!irqd_irq_masked(&desc->irq_data)) in __irq_set_trigger()
978 if (!irqd_irq_disabled(&desc->irq_data)) in __irq_set_trigger()
984 ret = chip->irq_set_type(&desc->irq_data, flags); in __irq_set_trigger()
989 irqd_clear(&desc->irq_data, IRQD_TRIGGER_MASK); in __irq_set_trigger()
990 irqd_set(&desc->irq_data, flags); in __irq_set_trigger()
994 flags = irqd_get_trigger_type(&desc->irq_data); in __irq_set_trigger()
996 irqd_clear(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
1000 irqd_set(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
1007 flags, irq_desc_get_irq(desc), chip->irq_set_type); in __irq_set_trigger()
1021 return -EINVAL; in irq_set_parent()
1023 desc->parent_irq = parent_irq; in irq_set_parent()
1066 if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags)) in irq_thread_check_affinity()
1076 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_thread_check_affinity()
1080 raw_spin_lock_irq(&desc->lock); in irq_thread_check_affinity()
1085 if (cpumask_available(desc->irq_common_data.affinity)) { in irq_thread_check_affinity()
1088 m = irq_data_get_effective_affinity_mask(&desc->irq_data); in irq_thread_check_affinity()
1092 raw_spin_unlock_irq(&desc->lock); in irq_thread_check_affinity()
1112 &action->thread_flags)) { in irq_wait_for_interrupt()
1117 return -1; in irq_wait_for_interrupt()
1121 &action->thread_flags)) { in irq_wait_for_interrupt()
1131 * handler finished. unmask if the interrupt has not been disabled and
1137 if (!(desc->istate & IRQS_ONESHOT) || in irq_finalize_oneshot()
1138 action->handler == irq_forced_secondary_handler) in irq_finalize_oneshot()
1142 raw_spin_lock_irq(&desc->lock); in irq_finalize_oneshot()
1154 * versus "desc->threads_oneshot |= action->thread_mask;" in in irq_finalize_oneshot()
1158 if (unlikely(irqd_irq_inprogress(&desc->irq_data))) { in irq_finalize_oneshot()
1159 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1170 if (test_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_finalize_oneshot()
1173 desc->threads_oneshot &= ~action->thread_mask; in irq_finalize_oneshot()
1175 if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) && in irq_finalize_oneshot()
1176 irqd_irq_masked(&desc->irq_data)) in irq_finalize_oneshot()
1180 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1198 ret = action->thread_fn(action->irq, action->dev_id); in irq_forced_thread_fn()
1200 atomic_inc(&desc->threads_handled); in irq_forced_thread_fn()
1211 * preemptible - many of them need to sleep and wait for slow busses to
1219 ret = action->thread_fn(action->irq, action->dev_id); in irq_thread_fn()
1221 atomic_inc(&desc->threads_handled); in irq_thread_fn()
1229 if (atomic_dec_and_test(&desc->threads_active)) in wake_threads_waitq()
1230 wake_up(&desc->wait_for_threads); in wake_threads_waitq()
1239 if (WARN_ON_ONCE(!(current->flags & PF_EXITING))) in irq_thread_dtor()
1245 tsk->comm, tsk->pid, action->irq); in irq_thread_dtor()
1248 desc = irq_to_desc(action->irq); in irq_thread_dtor()
1251 * desc->threads_active and wake possible waiters. in irq_thread_dtor()
1253 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_thread_dtor()
1256 /* Prevent a stale desc->threads_oneshot */ in irq_thread_dtor()
1262 struct irqaction *secondary = action->secondary; in irq_wake_secondary()
1267 raw_spin_lock_irq(&desc->lock); in irq_wake_secondary()
1269 raw_spin_unlock_irq(&desc->lock); in irq_wake_secondary()
1278 set_bit(IRQTF_READY, &action->thread_flags); in irq_thread_set_ready()
1279 wake_up(&desc->wait_for_threads); in irq_thread_set_ready()
1289 if (!action || !action->thread) in wake_up_and_wait_for_irq_thread_ready()
1292 wake_up_process(action->thread); in wake_up_and_wait_for_irq_thread_ready()
1293 wait_event(desc->wait_for_threads, in wake_up_and_wait_for_irq_thread_ready()
1294 test_bit(IRQTF_READY, &action->thread_flags)); in wake_up_and_wait_for_irq_thread_ready()
1304 struct irq_desc *desc = irq_to_desc(action->irq); in irq_thread()
1313 &action->thread_flags)) in irq_thread()
1342 * irq_wake_thread - wake the irq thread for the action identified by dev_id
1356 raw_spin_lock_irqsave(&desc->lock, flags); in irq_wake_thread()
1358 if (action->dev_id == dev_id) { in irq_wake_thread()
1359 if (action->thread) in irq_wake_thread()
1364 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_wake_thread()
1372 if (new->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT)) in irq_setup_forced_threading()
1379 if (new->handler == irq_default_primary_handler) in irq_setup_forced_threading()
1382 new->flags |= IRQF_ONESHOT; in irq_setup_forced_threading()
1389 if (new->handler && new->thread_fn) { in irq_setup_forced_threading()
1391 new->secondary = kzalloc(sizeof(struct irqaction), GFP_KERNEL); in irq_setup_forced_threading()
1392 if (!new->secondary) in irq_setup_forced_threading()
1393 return -ENOMEM; in irq_setup_forced_threading()
1394 new->secondary->handler = irq_forced_secondary_handler; in irq_setup_forced_threading()
1395 new->secondary->thread_fn = new->thread_fn; in irq_setup_forced_threading()
1396 new->secondary->dev_id = new->dev_id; in irq_setup_forced_threading()
1397 new->secondary->irq = new->irq; in irq_setup_forced_threading()
1398 new->secondary->name = new->name; in irq_setup_forced_threading()
1401 set_bit(IRQTF_FORCED_THREAD, &new->thread_flags); in irq_setup_forced_threading()
1402 new->thread_fn = new->handler; in irq_setup_forced_threading()
1403 new->handler = irq_default_primary_handler; in irq_setup_forced_threading()
1409 struct irq_data *d = &desc->irq_data; in irq_request_resources()
1410 struct irq_chip *c = d->chip; in irq_request_resources()
1412 return c->irq_request_resources ? c->irq_request_resources(d) : 0; in irq_request_resources()
1417 struct irq_data *d = &desc->irq_data; in irq_release_resources()
1418 struct irq_chip *c = d->chip; in irq_release_resources()
1420 if (c->irq_release_resources) in irq_release_resources()
1421 c->irq_release_resources(d); in irq_release_resources()
1430 if (d->parent_data) in irq_supports_nmi()
1434 if (d->chip->irq_bus_lock || d->chip->irq_bus_sync_unlock) in irq_supports_nmi()
1437 return d->chip->flags & IRQCHIP_SUPPORTS_NMI; in irq_supports_nmi()
1443 struct irq_chip *c = d->chip; in irq_nmi_setup()
1445 return c->irq_nmi_setup ? c->irq_nmi_setup(d) : -EINVAL; in irq_nmi_setup()
1451 struct irq_chip *c = d->chip; in irq_nmi_teardown()
1453 if (c->irq_nmi_teardown) in irq_nmi_teardown()
1454 c->irq_nmi_teardown(d); in irq_nmi_teardown()
1463 t = kthread_create(irq_thread, new, "irq/%d-%s", irq, in setup_irq_thread()
1464 new->name); in setup_irq_thread()
1466 t = kthread_create(irq_thread, new, "irq/%d-s-%s", irq, in setup_irq_thread()
1467 new->name); in setup_irq_thread()
1478 new->thread = get_task_struct(t); in setup_irq_thread()
1488 set_bit(IRQTF_AFFINITY, &new->thread_flags); in setup_irq_thread()
1493 * Internal function to register an irqaction - typically used to
1498 * desc->request_mutex Provides serialization against a concurrent free_irq()
1500 * desc->lock Provides serialization against hard interrupts
1502 * chip_bus_lock and desc->lock are sufficient for all other management and
1503 * interrupt related functions. desc->request_mutex solely serializes
1514 return -EINVAL; in __setup_irq()
1516 if (desc->irq_data.chip == &no_irq_chip) in __setup_irq()
1517 return -ENOSYS; in __setup_irq()
1518 if (!try_module_get(desc->owner)) in __setup_irq()
1519 return -ENODEV; in __setup_irq()
1521 new->irq = irq; in __setup_irq()
1527 if (!(new->flags & IRQF_TRIGGER_MASK)) in __setup_irq()
1528 new->flags |= irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1536 if (!new->thread_fn) { in __setup_irq()
1537 ret = -EINVAL; in __setup_irq()
1545 new->handler = irq_nested_primary_handler; in __setup_irq()
1559 if (new->thread_fn && !nested) { in __setup_irq()
1563 if (new->secondary) { in __setup_irq()
1564 ret = setup_irq_thread(new->secondary, irq, true); in __setup_irq()
1579 if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) in __setup_irq()
1580 new->flags &= ~IRQF_ONESHOT; in __setup_irq()
1585 * chip bus lock and desc->lock. Also protects against handing out in __setup_irq()
1589 mutex_lock(&desc->request_mutex); in __setup_irq()
1599 if (!desc->action) { in __setup_irq()
1603 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1612 * desc->request_mutex or the optional bus lock. in __setup_irq()
1614 raw_spin_lock_irqsave(&desc->lock, flags); in __setup_irq()
1615 old_ptr = &desc->action; in __setup_irq()
1630 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1631 ret = -EINVAL; in __setup_irq()
1639 if (irqd_trigger_type_was_set(&desc->irq_data)) { in __setup_irq()
1640 oldtype = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1642 oldtype = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1643 irqd_set_trigger_type(&desc->irq_data, oldtype); in __setup_irq()
1646 if (!((old->flags & new->flags) & IRQF_SHARED) || in __setup_irq()
1647 (oldtype != (new->flags & IRQF_TRIGGER_MASK))) in __setup_irq()
1650 if ((old->flags & IRQF_ONESHOT) && in __setup_irq()
1651 (new->flags & IRQF_COND_ONESHOT)) in __setup_irq()
1652 new->flags |= IRQF_ONESHOT; in __setup_irq()
1653 else if ((old->flags ^ new->flags) & IRQF_ONESHOT) in __setup_irq()
1656 /* All handlers must agree on per-cpuness */ in __setup_irq()
1657 if ((old->flags & IRQF_PERCPU) != in __setup_irq()
1658 (new->flags & IRQF_PERCPU)) in __setup_irq()
1664 * Or all existing action->thread_mask bits, in __setup_irq()
1668 thread_mask |= old->thread_mask; in __setup_irq()
1669 old_ptr = &old->next; in __setup_irq()
1680 if (new->flags & IRQF_ONESHOT) { in __setup_irq()
1686 ret = -EBUSY; in __setup_irq()
1691 * desc->thread_active to indicate that the in __setup_irq()
1695 * line have completed desc->threads_active becomes in __setup_irq()
1700 * interrupt handlers, then desc->threads_active is in __setup_irq()
1707 * all existing action->thread_mask bits. in __setup_irq()
1709 new->thread_mask = 1UL << ffz(thread_mask); in __setup_irq()
1711 } else if (new->handler == irq_default_primary_handler && in __setup_irq()
1712 !(desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)) { in __setup_irq()
1729 new->name, irq); in __setup_irq()
1730 ret = -EINVAL; in __setup_irq()
1736 if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1738 new->flags & IRQF_TRIGGER_MASK); in __setup_irq()
1759 desc->istate &= ~(IRQS_AUTODETECT | IRQS_SPURIOUS_DISABLED | \ in __setup_irq()
1761 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); in __setup_irq()
1763 if (new->flags & IRQF_PERCPU) { in __setup_irq()
1764 irqd_set(&desc->irq_data, IRQD_PER_CPU); in __setup_irq()
1766 if (new->flags & IRQF_NO_DEBUG) in __setup_irq()
1773 if (new->flags & IRQF_ONESHOT) in __setup_irq()
1774 desc->istate |= IRQS_ONESHOT; in __setup_irq()
1777 if (new->flags & IRQF_NOBALANCING) { in __setup_irq()
1779 irqd_set(&desc->irq_data, IRQD_NO_BALANCING); in __setup_irq()
1782 if (!(new->flags & IRQF_NO_AUTOEN) && in __setup_irq()
1788 * auto enable. The sharing interrupt might request in __setup_irq()
1789 * it while it's still disabled and then wait for in __setup_irq()
1792 WARN_ON_ONCE(new->flags & IRQF_SHARED); in __setup_irq()
1794 desc->depth = 1; in __setup_irq()
1797 } else if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1798 unsigned int nmsk = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1799 unsigned int omsk = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1812 desc->irq_count = 0; in __setup_irq()
1813 desc->irqs_unhandled = 0; in __setup_irq()
1816 * Check whether we disabled the irq via the spurious handler in __setup_irq()
1819 if (shared && (desc->istate & IRQS_SPURIOUS_DISABLED)) { in __setup_irq()
1820 desc->istate &= ~IRQS_SPURIOUS_DISABLED; in __setup_irq()
1824 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1826 mutex_unlock(&desc->request_mutex); in __setup_irq()
1831 wake_up_and_wait_for_irq_thread_ready(desc, new->secondary); in __setup_irq()
1834 new->dir = NULL; in __setup_irq()
1839 if (!(new->flags & IRQF_PROBE_SHARED)) { in __setup_irq()
1841 irq, new->flags, new->name, old->flags, old->name); in __setup_irq()
1846 ret = -EBUSY; in __setup_irq()
1849 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1851 if (!desc->action) in __setup_irq()
1855 mutex_unlock(&desc->request_mutex); in __setup_irq()
1858 if (new->thread) { in __setup_irq()
1859 struct task_struct *t = new->thread; in __setup_irq()
1861 new->thread = NULL; in __setup_irq()
1864 if (new->secondary && new->secondary->thread) { in __setup_irq()
1865 struct task_struct *t = new->secondary->thread; in __setup_irq()
1867 new->secondary->thread = NULL; in __setup_irq()
1871 module_put(desc->owner); in __setup_irq()
1876 * Internal function to unregister an irqaction - used to free
1881 unsigned irq = desc->irq_data.irq; in __free_irq()
1887 mutex_lock(&desc->request_mutex); in __free_irq()
1889 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1895 action_ptr = &desc->action; in __free_irq()
1900 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_irq()
1901 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1903 mutex_unlock(&desc->request_mutex); in __free_irq()
1907 if (action->dev_id == dev_id) in __free_irq()
1909 action_ptr = &action->next; in __free_irq()
1912 /* Found it - now remove it from the list of entries: */ in __free_irq()
1913 *action_ptr = action->next; in __free_irq()
1918 if (!desc->action) { in __free_irq()
1926 if (WARN_ON_ONCE(desc->affinity_hint)) in __free_irq()
1927 desc->affinity_hint = NULL; in __free_irq()
1930 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1941 * The still held desc->request_mutex() protects against a in __free_irq()
1958 * It's a shared IRQ -- the driver ought to be prepared for an IRQ in __free_irq()
1965 if (action->flags & IRQF_SHARED) { in __free_irq()
1967 action->handler(irq, dev_id); in __free_irq()
1978 if (action->thread) { in __free_irq()
1979 kthread_stop_put(action->thread); in __free_irq()
1980 if (action->secondary && action->secondary->thread) in __free_irq()
1981 kthread_stop_put(action->secondary->thread); in __free_irq()
1985 if (!desc->action) { in __free_irq()
1995 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1996 irq_domain_deactivate_irq(&desc->irq_data); in __free_irq()
1997 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
2004 mutex_unlock(&desc->request_mutex); in __free_irq()
2006 irq_chip_pm_put(&desc->irq_data); in __free_irq()
2007 module_put(desc->owner); in __free_irq()
2008 kfree(action->secondary); in __free_irq()
2013 * free_irq - free an interrupt allocated with request_irq
2018 * interrupt line is no longer in use by any driver it is disabled.
2019 * On a shared IRQ the caller must ensure the interrupt is disabled
2038 if (WARN_ON(desc->affinity_notify)) in free_irq()
2039 desc->affinity_notify = NULL; in free_irq()
2047 devname = action->name; in free_irq()
2053 /* This function must be called with desc->lock held */
2058 desc->istate &= ~IRQS_NMI; in __cleanup_nmi()
2060 if (!WARN_ON(desc->action == NULL)) { in __cleanup_nmi()
2061 irq_pm_remove_action(desc, desc->action); in __cleanup_nmi()
2062 devname = desc->action->name; in __cleanup_nmi()
2063 unregister_handler_proc(irq, desc->action); in __cleanup_nmi()
2065 kfree(desc->action); in __cleanup_nmi()
2066 desc->action = NULL; in __cleanup_nmi()
2074 irq_chip_pm_put(&desc->irq_data); in __cleanup_nmi()
2075 module_put(desc->owner); in __cleanup_nmi()
2093 if (WARN_ON(desc->depth == 0)) in free_nmi()
2096 raw_spin_lock_irqsave(&desc->lock, flags); in free_nmi()
2101 raw_spin_unlock_irqrestore(&desc->lock, flags); in free_nmi()
2107 * request_threaded_irq - allocate an interrupt line
2157 return -ENOTCONN; in request_threaded_irq()
2160 * Sanity-check: shared interrupts must pass in a real dev-ID, in request_threaded_irq()
2165 * Also shared interrupts do not go well with disabling auto enable. in request_threaded_irq()
2166 * The sharing interrupt might request it while it's still disabled in request_threaded_irq()
2176 return -EINVAL; in request_threaded_irq()
2180 return -EINVAL; in request_threaded_irq()
2184 return -EINVAL; in request_threaded_irq()
2188 return -EINVAL; in request_threaded_irq()
2194 return -ENOMEM; in request_threaded_irq()
2196 action->handler = handler; in request_threaded_irq()
2197 action->thread_fn = thread_fn; in request_threaded_irq()
2198 action->flags = irqflags; in request_threaded_irq()
2199 action->name = devname; in request_threaded_irq()
2200 action->dev_id = dev_id; in request_threaded_irq()
2202 retval = irq_chip_pm_get(&desc->irq_data); in request_threaded_irq()
2211 irq_chip_pm_put(&desc->irq_data); in request_threaded_irq()
2212 kfree(action->secondary); in request_threaded_irq()
2219 * It's a shared IRQ -- the driver ought to be prepared for it in request_threaded_irq()
2240 * request_any_context_irq - allocate an interrupt line
2263 return -ENOTCONN; in request_any_context_irq()
2267 return -EINVAL; in request_any_context_irq()
2281 * request_nmi - allocate an interrupt line for NMI delivery
2297 * interrupts and have auto enabling setting disabled.
2315 return -ENOTCONN; in request_nmi()
2319 return -EINVAL; in request_nmi()
2322 return -EINVAL; in request_nmi()
2325 return -EINVAL; in request_nmi()
2334 return -EINVAL; in request_nmi()
2338 return -ENOMEM; in request_nmi()
2340 action->handler = handler; in request_nmi()
2341 action->flags = irqflags | IRQF_NO_THREAD | IRQF_NOBALANCING; in request_nmi()
2342 action->name = name; in request_nmi()
2343 action->dev_id = dev_id; in request_nmi()
2345 retval = irq_chip_pm_get(&desc->irq_data); in request_nmi()
2353 raw_spin_lock_irqsave(&desc->lock, flags); in request_nmi()
2356 desc->istate |= IRQS_NMI; in request_nmi()
2360 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2361 return -EINVAL; in request_nmi()
2364 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2369 irq_chip_pm_put(&desc->irq_data); in request_nmi()
2391 type = irqd_get_trigger_type(&desc->irq_data); in enable_percpu_irq()
2416 * irq_percpu_is_enabled - Check whether the per cpu irq is enabled
2433 is_enabled = cpumask_test_cpu(cpu, desc->percpu_enabled); in irq_percpu_is_enabled()
2473 raw_spin_lock_irqsave(&desc->lock, flags); in __free_percpu_irq()
2475 action = desc->action; in __free_percpu_irq()
2476 if (!action || action->percpu_dev_id != dev_id) { in __free_percpu_irq()
2477 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_percpu_irq()
2481 if (!cpumask_empty(desc->percpu_enabled)) { in __free_percpu_irq()
2483 irq, cpumask_first(desc->percpu_enabled)); in __free_percpu_irq()
2487 /* Found it - now remove it from the list of entries: */ in __free_percpu_irq()
2488 desc->action = NULL; in __free_percpu_irq()
2490 desc->istate &= ~IRQS_NMI; in __free_percpu_irq()
2492 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2496 irq_chip_pm_put(&desc->irq_data); in __free_percpu_irq()
2497 module_put(desc->owner); in __free_percpu_irq()
2501 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2506 * remove_percpu_irq - free a per-cpu interrupt
2517 __free_percpu_irq(irq, act->percpu_dev_id); in remove_percpu_irq()
2521 * free_percpu_irq - free an interrupt allocated with request_percpu_irq
2526 * the interrupt line is not disabled. This must be done on each
2559 * setup_percpu_irq - setup a per-cpu interrupt
2563 * Used to statically setup per-cpu interrupts in the early boot process.
2571 return -EINVAL; in setup_percpu_irq()
2573 retval = irq_chip_pm_get(&desc->irq_data); in setup_percpu_irq()
2580 irq_chip_pm_put(&desc->irq_data); in setup_percpu_irq()
2586 * __request_percpu_irq - allocate a percpu interrupt line
2598 * Dev_id must be globally unique. It is a per-cpu variable, and
2611 return -EINVAL; in __request_percpu_irq()
2616 return -EINVAL; in __request_percpu_irq()
2619 return -EINVAL; in __request_percpu_irq()
2623 return -ENOMEM; in __request_percpu_irq()
2625 action->handler = handler; in __request_percpu_irq()
2626 action->flags = flags | IRQF_PERCPU | IRQF_NO_SUSPEND; in __request_percpu_irq()
2627 action->name = devname; in __request_percpu_irq()
2628 action->percpu_dev_id = dev_id; in __request_percpu_irq()
2630 retval = irq_chip_pm_get(&desc->irq_data); in __request_percpu_irq()
2639 irq_chip_pm_put(&desc->irq_data); in __request_percpu_irq()
2648 * request_percpu_nmi - allocate a percpu interrupt line for NMI delivery
2658 * Dev_id must be globally unique. It is a per-cpu variable, and
2662 * Interrupt lines requested for NMI delivering should have auto enabling
2663 * setting disabled.
2677 return -EINVAL; in request_percpu_nmi()
2685 return -EINVAL; in request_percpu_nmi()
2689 return -EINVAL; in request_percpu_nmi()
2693 return -ENOMEM; in request_percpu_nmi()
2695 action->handler = handler; in request_percpu_nmi()
2696 action->flags = IRQF_PERCPU | IRQF_NO_SUSPEND | IRQF_NO_THREAD in request_percpu_nmi()
2698 action->name = name; in request_percpu_nmi()
2699 action->percpu_dev_id = dev_id; in request_percpu_nmi()
2701 retval = irq_chip_pm_get(&desc->irq_data); in request_percpu_nmi()
2709 raw_spin_lock_irqsave(&desc->lock, flags); in request_percpu_nmi()
2710 desc->istate |= IRQS_NMI; in request_percpu_nmi()
2711 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_percpu_nmi()
2716 irq_chip_pm_put(&desc->irq_data); in request_percpu_nmi()
2724 * prepare_percpu_nmi - performs CPU local setup for NMI delivery
2730 * As a CPU local operation, this should be called from non-preemptible
2747 return -EINVAL; in prepare_percpu_nmi()
2750 KERN_ERR "prepare_percpu_nmi called for a non-NMI interrupt: irq %u\n", in prepare_percpu_nmi()
2752 ret = -EINVAL; in prepare_percpu_nmi()
2768 * teardown_percpu_nmi - undoes NMI setup of IRQ line
2776 * As a CPU local operation, this should be called from non-preemptible
2803 int err = -EINVAL; in __irq_get_irqchip_state()
2808 return -ENODEV; in __irq_get_irqchip_state()
2809 if (chip->irq_get_irqchip_state) in __irq_get_irqchip_state()
2812 data = data->parent_data; in __irq_get_irqchip_state()
2819 err = chip->irq_get_irqchip_state(data, which, state); in __irq_get_irqchip_state()
2824 * irq_get_irqchip_state - returns the irqchip state of a interrupt.
2833 * This function should be called with preemption disabled if the
2834 * interrupt controller has per-cpu registers.
2842 int err = -EINVAL; in irq_get_irqchip_state()
2858 * irq_set_irqchip_state - set the state of a forwarded interrupt.
2866 * This function should be called with migration disabled if the
2867 * interrupt controller has per-cpu registers.
2876 int err = -EINVAL; in irq_set_irqchip_state()
2887 err = -ENODEV; in irq_set_irqchip_state()
2890 if (chip->irq_set_irqchip_state) in irq_set_irqchip_state()
2893 data = data->parent_data; in irq_set_irqchip_state()
2900 err = chip->irq_set_irqchip_state(data, which, val); in irq_set_irqchip_state()
2909 * irq_has_action - Check whether an interrupt is requested
2926 * irq_check_status_bit - Check whether bits in the irq descriptor status are set
2940 res = !!(desc->status_use_accessors & bitmask); in irq_check_status_bit()