Lines Matching +full:irq +full:- +full:can +full:- +full:wake

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
4 * Copyright (C) 2005-2006 Thomas Gleixner
6 * This file contains driver APIs to the irq subsystem.
11 #include <linux/irq.h>
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 guard(raw_spinlock_irqsave)(&desc->lock); in __synchronize_hardirq()
55 inprogress = irqd_irq_inprogress(&desc->irq_data); in __synchronize_hardirq()
75 * synchronize_hardirq - wait for pending hard IRQ handlers (on other CPUs)
76 * @irq: interrupt number to wait for
78 * This function waits for any pending hard IRQ handlers for this interrupt
80 * resource the IRQ handler may need you will deadlock. It does not take
88 * This function may be called - with care - from IRQ context.
95 bool synchronize_hardirq(unsigned int irq) in synchronize_hardirq() argument
97 struct irq_desc *desc = irq_to_desc(irq); in synchronize_hardirq()
101 return !atomic_read(&desc->threads_active); in synchronize_hardirq()
115 wait_event(desc->wait_for_threads, !atomic_read(&desc->threads_active)); in __synchronize_irq()
119 * synchronize_irq - wait for pending IRQ handlers (on other CPUs)
120 * @irq: interrupt number to wait for
122 * This function waits for any pending IRQ handlers for this interrupt to
124 * resource the IRQ handler may need you will deadlock.
126 * Can only be called from preemptible code as it might sleep when
127 * an interrupt thread is associated to @irq.
129 * It optionally makes sure (when the irq chip supports that method)
133 void synchronize_irq(unsigned int irq) in synchronize_irq() argument
135 struct irq_desc *desc = irq_to_desc(irq); in synchronize_irq()
147 if (!desc || !irqd_can_balance(&desc->irq_data) || in __irq_can_set_affinity()
148 !desc->irq_data.chip || !desc->irq_data.chip->irq_set_affinity) in __irq_can_set_affinity()
154 * irq_can_set_affinity - Check if the affinity of a given irq can be set
155 * @irq: Interrupt to check
158 int irq_can_set_affinity(unsigned int irq) in irq_can_set_affinity() argument
160 return __irq_can_set_affinity(irq_to_desc(irq)); in irq_can_set_affinity()
164 * irq_can_set_affinity_usr - Check if affinity of a irq can be set from user space
165 * @irq: Interrupt to check
170 bool irq_can_set_affinity_usr(unsigned int irq) in irq_can_set_affinity_usr() argument
172 struct irq_desc *desc = irq_to_desc(irq); in irq_can_set_affinity_usr()
175 !irqd_affinity_is_managed(&desc->irq_data); in irq_can_set_affinity_usr()
179 * irq_set_thread_affinity - Notify irq threads to adjust affinity
180 * @desc: irq descriptor which has affinity changed
183 * interrupt thread itself. We can not call set_cpus_allowed_ptr() here as
184 * we hold desc->lock and this code can be called from hard interrupt
192 if (action->thread) { in irq_set_thread_affinity()
193 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_set_thread_affinity()
194 wake_up_process(action->thread); in irq_set_thread_affinity()
196 if (action->secondary && action->secondary->thread) { in irq_set_thread_affinity()
197 set_bit(IRQTF_AFFINITY, &action->secondary->thread_flags); in irq_set_thread_affinity()
198 wake_up_process(action->secondary->thread); in irq_set_thread_affinity()
211 pr_warn_once("irq_chip %s did not update eff. affinity mask of irq %u\n", in irq_validate_effective_affinity()
212 chip->name, data->irq); in irq_validate_effective_affinity()
229 if (!chip || !chip->irq_set_affinity) in irq_do_set_affinity()
230 return -EINVAL; in irq_do_set_affinity()
273 ret = chip->irq_set_affinity(data, tmp_mask, force); in irq_do_set_affinity()
275 ret = chip->irq_set_affinity(data, mask, force); in irq_do_set_affinity()
277 ret = -EINVAL; in irq_do_set_affinity()
282 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_do_set_affinity()
307 return -EBUSY; in irq_set_affinity_pending()
321 if (ret == -EBUSY && !force) in irq_try_set_affinity()
332 * Handle irq chips which can handle affinity only in activated in irq_set_affinity_deactivated()
344 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_set_affinity_deactivated()
357 if (!chip || !chip->irq_set_affinity) in irq_set_affinity_locked()
358 return -EINVAL; in irq_set_affinity_locked()
370 if (desc->affinity_notify) { in irq_set_affinity_locked()
371 kref_get(&desc->affinity_notify->kref); in irq_set_affinity_locked()
372 if (!schedule_work(&desc->affinity_notify->work)) { in irq_set_affinity_locked()
374 kref_put(&desc->affinity_notify->kref, in irq_set_affinity_locked()
375 desc->affinity_notify->release); in irq_set_affinity_locked()
384 * irq_update_affinity_desc - Update affinity management for an interrupt
385 * @irq: The interrupt number to update
388 * This interface can be used to configure the affinity management of
391 * There are certain limitations on when it may be used - attempts to use it
392 * for when the kernel is configured for generic IRQ reservation mode (in
394 * managed/non-managed interrupt accounting. In addition, attempts to use it on
398 int irq_update_affinity_desc(unsigned int irq, struct irq_affinity_desc *affinity) in irq_update_affinity_desc() argument
405 return -EOPNOTSUPP; in irq_update_affinity_desc()
407 scoped_irqdesc_get_and_buslock(irq, 0) { in irq_update_affinity_desc()
412 if (irqd_is_started(&desc->irq_data)) in irq_update_affinity_desc()
413 return -EBUSY; in irq_update_affinity_desc()
416 if (irqd_affinity_is_managed(&desc->irq_data)) in irq_update_affinity_desc()
417 return -EBUSY; in irq_update_affinity_desc()
422 activated = irqd_is_activated(&desc->irq_data); in irq_update_affinity_desc()
424 irq_domain_deactivate_irq(&desc->irq_data); in irq_update_affinity_desc()
426 if (affinity->is_managed) { in irq_update_affinity_desc()
427 irqd_set(&desc->irq_data, IRQD_AFFINITY_MANAGED); in irq_update_affinity_desc()
428 irqd_set(&desc->irq_data, IRQD_MANAGED_SHUTDOWN); in irq_update_affinity_desc()
431 cpumask_copy(desc->irq_common_data.affinity, &affinity->mask); in irq_update_affinity_desc()
435 irq_domain_activate_irq(&desc->irq_data, false); in irq_update_affinity_desc()
438 return -EINVAL; in irq_update_affinity_desc()
441 static int __irq_set_affinity(unsigned int irq, const struct cpumask *mask, in __irq_set_affinity() argument
444 struct irq_desc *desc = irq_to_desc(irq); in __irq_set_affinity()
447 return -EINVAL; in __irq_set_affinity()
449 guard(raw_spinlock_irqsave)(&desc->lock); in __irq_set_affinity()
454 * irq_set_affinity - Set the irq affinity of a given irq
455 * @irq: Interrupt to set affinity
460 int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask) in irq_set_affinity() argument
462 return __irq_set_affinity(irq, cpumask, false); in irq_set_affinity()
467 * irq_force_affinity - Force the irq affinity of a given irq
468 * @irq: Interrupt to set affinity
477 int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask) in irq_force_affinity() argument
479 return __irq_set_affinity(irq, cpumask, true); in irq_force_affinity()
483 int __irq_apply_affinity_hint(unsigned int irq, const struct cpumask *m, bool setaffinity) in __irq_apply_affinity_hint() argument
485 int ret = -EINVAL; in __irq_apply_affinity_hint()
487 scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_GLOBAL) { in __irq_apply_affinity_hint()
488 scoped_irqdesc->affinity_hint = m; in __irq_apply_affinity_hint()
493 __irq_set_affinity(irq, m, false); in __irq_apply_affinity_hint()
501 struct irq_desc *desc = irq_to_desc(notify->irq); in irq_affinity_notify()
507 scoped_guard(raw_spinlock_irqsave, &desc->lock) { in irq_affinity_notify()
508 if (irq_move_pending(&desc->irq_data)) in irq_affinity_notify()
511 cpumask_copy(cpumask, desc->irq_common_data.affinity); in irq_affinity_notify()
514 notify->notify(notify, cpumask); in irq_affinity_notify()
518 kref_put(&notify->kref, notify->release); in irq_affinity_notify()
522 * irq_set_affinity_notifier - control notification of IRQ affinity changes
523 * @irq: Interrupt for which to enable/disable notification
529 * after the IRQ is allocated and must be disabled before the IRQ is freed
532 int irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) in irq_set_affinity_notifier() argument
534 struct irq_desc *desc = irq_to_desc(irq); in irq_set_affinity_notifier()
541 return -EINVAL; in irq_set_affinity_notifier()
545 notify->irq = irq; in irq_set_affinity_notifier()
546 kref_init(&notify->kref); in irq_set_affinity_notifier()
547 INIT_WORK(&notify->work, irq_affinity_notify); in irq_set_affinity_notifier()
550 scoped_guard(raw_spinlock_irqsave, &desc->lock) { in irq_set_affinity_notifier()
551 old_notify = desc->affinity_notify; in irq_set_affinity_notifier()
552 desc->affinity_notify = notify; in irq_set_affinity_notifier()
556 if (cancel_work_sync(&old_notify->work)) { in irq_set_affinity_notifier()
558 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
560 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
588 if (irqd_affinity_is_managed(&desc->irq_data) || in irq_setup_affinity()
589 irqd_has_set(&desc->irq_data, IRQD_AFFINITY_SET)) { in irq_setup_affinity()
590 if (cpumask_intersects(desc->irq_common_data.affinity, in irq_setup_affinity()
592 set = desc->irq_common_data.affinity; in irq_setup_affinity()
594 irqd_clear(&desc->irq_data, IRQD_AFFINITY_SET); in irq_setup_affinity()
608 return irq_do_set_affinity(&desc->irq_data, &mask, false); in irq_setup_affinity()
621 * irq_set_vcpu_affinity - Set vcpu affinity for the interrupt
622 * @irq: interrupt number to set affinity
627 * an irq. The vCPU specific data is passed from outside, such as KVM. One
628 * example code path is as below: KVM -> IOMMU -> irq_set_vcpu_affinity().
630 int irq_set_vcpu_affinity(unsigned int irq, void *vcpu_info) in irq_set_vcpu_affinity() argument
632 scoped_irqdesc_get_and_lock(irq, 0) { in irq_set_vcpu_affinity()
640 if (chip && chip->irq_set_vcpu_affinity) in irq_set_vcpu_affinity()
647 return -ENOSYS; in irq_set_vcpu_affinity()
648 return chip->irq_set_vcpu_affinity(data, vcpu_info); in irq_set_vcpu_affinity()
650 return -EINVAL; in irq_set_vcpu_affinity()
656 if (!desc->depth++) in __disable_irq()
660 static int __disable_irq_nosync(unsigned int irq) in __disable_irq_nosync() argument
662 scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) { in __disable_irq_nosync()
666 return -EINVAL; in __disable_irq_nosync()
670 * disable_irq_nosync - disable an irq without waiting
671 * @irq: Interrupt to disable
676 * instances of the IRQ handler have completed before returning.
678 * This function may be called from IRQ context.
680 void disable_irq_nosync(unsigned int irq) in disable_irq_nosync() argument
682 __disable_irq_nosync(irq); in disable_irq_nosync()
687 * disable_irq - disable an irq and wait for completion
688 * @irq: Interrupt to disable
692 * This function waits for any pending IRQ handlers for this interrupt to
694 * resource the IRQ handler may need you will deadlock.
696 * Can only be called from preemptible code as it might sleep when an
697 * interrupt thread is associated to @irq.
700 void disable_irq(unsigned int irq) in disable_irq() argument
703 if (!__disable_irq_nosync(irq)) in disable_irq()
704 synchronize_irq(irq); in disable_irq()
709 * disable_hardirq - disables an irq and waits for hardirq completion
710 * @irq: Interrupt to disable
714 * This function waits for any pending hard IRQ handlers for this interrupt
716 * resource the hard IRQ handler may need you will deadlock.
723 * This function may be called - with care - from IRQ context.
725 bool disable_hardirq(unsigned int irq) in disable_hardirq() argument
727 if (!__disable_irq_nosync(irq)) in disable_hardirq()
728 return synchronize_hardirq(irq); in disable_hardirq()
734 * disable_nmi_nosync - disable an nmi without waiting
735 * @irq: Interrupt to disable
741 * instances of the IRQ handler have completed before returning.
743 void disable_nmi_nosync(unsigned int irq) in disable_nmi_nosync() argument
745 disable_irq_nosync(irq); in disable_nmi_nosync()
750 switch (desc->depth) { in __enable_irq()
753 WARN(1, KERN_WARNING "Unbalanced enable for IRQ %d\n", in __enable_irq()
757 if (desc->istate & IRQS_SUSPENDED) in __enable_irq()
759 /* Prevent probing on this irq: */ in __enable_irq()
776 desc->depth--; in __enable_irq()
781 * enable_irq - enable handling of an irq
782 * @irq: Interrupt to enable
785 * last disable, processing of interrupts on this IRQ line is re-enabled.
787 * This function may be called from IRQ context only when
788 * desc->irq_data.chip->bus_lock and desc->chip->bus_sync_unlock are NULL !
790 void enable_irq(unsigned int irq) in enable_irq() argument
792 scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) { in enable_irq()
795 if (WARN(!desc->irq_data.chip, "enable_irq before setup/request_irq: irq %u\n", irq)) in enable_irq()
803 * enable_nmi - enable handling of an nmi
804 * @irq: Interrupt to enable
808 * disable, processing of interrupts on this IRQ line is re-enabled.
810 void enable_nmi(unsigned int irq) in enable_nmi() argument
812 enable_irq(irq); in enable_nmi()
815 static int set_irq_wake_real(unsigned int irq, unsigned int on) in set_irq_wake_real() argument
817 struct irq_desc *desc = irq_to_desc(irq); in set_irq_wake_real()
818 int ret = -ENXIO; in set_irq_wake_real()
820 if (irq_desc_get_chip(desc)->flags & IRQCHIP_SKIP_SET_WAKE) in set_irq_wake_real()
823 if (desc->irq_data.chip->irq_set_wake) in set_irq_wake_real()
824 ret = desc->irq_data.chip->irq_set_wake(&desc->irq_data, on); in set_irq_wake_real()
830 * irq_set_irq_wake - control irq power management wakeup
831 * @irq: interrupt to control
836 * non-wakeup mode support.
838 * Wakeup mode lets this IRQ wake the system from sleep states like
841 * Note: irq enable/disable state is completely orthogonal to the
842 * enable/disable state of irq wake. An irq can be disabled with
843 * disable_irq() and still wake the system as long as the irq has wake
844 * enabled. If this does not hold, then the underlying irq chip and the
847 int irq_set_irq_wake(unsigned int irq, unsigned int on) in irq_set_irq_wake() argument
849 scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) { in irq_set_irq_wake()
853 /* Don't use NMIs as wake up interrupts please */ in irq_set_irq_wake()
855 return -EINVAL; in irq_set_irq_wake()
858 * wakeup-capable irqs can be shared between drivers that in irq_set_irq_wake()
862 if (desc->wake_depth++ == 0) { in irq_set_irq_wake()
863 ret = set_irq_wake_real(irq, on); in irq_set_irq_wake()
865 desc->wake_depth = 0; in irq_set_irq_wake()
867 irqd_set(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
870 if (desc->wake_depth == 0) { in irq_set_irq_wake()
871 WARN(1, "Unbalanced IRQ %d wake disable\n", irq); in irq_set_irq_wake()
872 } else if (--desc->wake_depth == 0) { in irq_set_irq_wake()
873 ret = set_irq_wake_real(irq, on); in irq_set_irq_wake()
875 desc->wake_depth = 1; in irq_set_irq_wake()
877 irqd_clear(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
882 return -EINVAL; in irq_set_irq_wake()
888 * particular irq has been exclusively allocated or is available
891 bool can_request_irq(unsigned int irq, unsigned long irqflags) in can_request_irq() argument
893 scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_GLOBAL) { in can_request_irq()
897 if (!desc->action || irqflags & desc->action->flags & IRQF_SHARED) in can_request_irq()
906 struct irq_chip *chip = desc->irq_data.chip; in __irq_set_trigger()
909 if (!chip || !chip->irq_set_type) { in __irq_set_trigger()
912 * flow-types? in __irq_set_trigger()
914 pr_debug("No set_type function for IRQ %d (%s)\n", in __irq_set_trigger()
916 chip ? (chip->name ? : "unknown") : "unknown"); in __irq_set_trigger()
920 if (chip->flags & IRQCHIP_SET_TYPE_MASKED) { in __irq_set_trigger()
921 if (!irqd_irq_masked(&desc->irq_data)) in __irq_set_trigger()
923 if (!irqd_irq_disabled(&desc->irq_data)) in __irq_set_trigger()
929 ret = chip->irq_set_type(&desc->irq_data, flags); in __irq_set_trigger()
934 irqd_clear(&desc->irq_data, IRQD_TRIGGER_MASK); in __irq_set_trigger()
935 irqd_set(&desc->irq_data, flags); in __irq_set_trigger()
939 flags = irqd_get_trigger_type(&desc->irq_data); in __irq_set_trigger()
941 irqd_clear(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
945 irqd_set(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
951 pr_err("Setting trigger mode %lu for irq %u failed (%pS)\n", in __irq_set_trigger()
952 flags, irq_desc_get_irq(desc), chip->irq_set_type); in __irq_set_trigger()
960 int irq_set_parent(int irq, int parent_irq) in irq_set_parent() argument
962 scoped_irqdesc_get_and_lock(irq, 0) { in irq_set_parent()
963 scoped_irqdesc->parent_irq = parent_irq; in irq_set_parent()
966 return -EINVAL; in irq_set_parent()
976 static irqreturn_t irq_default_primary_handler(int irq, void *dev_id) in irq_default_primary_handler() argument
985 static irqreturn_t irq_nested_primary_handler(int irq, void *dev_id) in irq_nested_primary_handler() argument
987 WARN(1, "Primary handler called for nested irq %d\n", irq); in irq_nested_primary_handler()
991 static irqreturn_t irq_forced_secondary_handler(int irq, void *dev_id) in irq_forced_secondary_handler() argument
993 WARN(1, "Secondary action handler called for irq %d\n", irq); in irq_forced_secondary_handler()
1006 if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags)) in irq_thread_check_affinity()
1016 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_thread_check_affinity()
1020 scoped_guard(raw_spinlock_irq, &desc->lock) { in irq_thread_check_affinity()
1025 if (cpumask_available(desc->irq_common_data.affinity)) { in irq_thread_check_affinity()
1028 m = irq_data_get_effective_affinity_mask(&desc->irq_data); in irq_thread_check_affinity()
1052 &action->thread_flags)) { in irq_wait_for_interrupt()
1057 return -1; in irq_wait_for_interrupt()
1061 &action->thread_flags)) { in irq_wait_for_interrupt()
1070 * Oneshot interrupts keep the irq line masked until the threaded
1077 if (!(desc->istate & IRQS_ONESHOT) || in irq_finalize_oneshot()
1078 action->handler == irq_forced_secondary_handler) in irq_finalize_oneshot()
1082 raw_spin_lock_irq(&desc->lock); in irq_finalize_oneshot()
1089 * on the other CPU. If we unmask the irq line then the in irq_finalize_oneshot()
1090 * interrupt can come in again and masks the line, leaves due in irq_finalize_oneshot()
1091 * to IRQS_INPROGRESS and the irq line is masked forever. in irq_finalize_oneshot()
1094 * versus "desc->threads_oneshot |= action->thread_mask;" in in irq_finalize_oneshot()
1098 if (unlikely(irqd_irq_inprogress(&desc->irq_data))) { in irq_finalize_oneshot()
1099 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1110 if (test_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_finalize_oneshot()
1113 desc->threads_oneshot &= ~action->thread_mask; in irq_finalize_oneshot()
1115 if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) && in irq_finalize_oneshot()
1116 irqd_irq_masked(&desc->irq_data)) in irq_finalize_oneshot()
1120 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1126 * preemptible - many of them need to sleep and wait for slow busses to
1131 irqreturn_t ret = action->thread_fn(action->irq, action->dev_id); in irq_thread_fn()
1134 atomic_inc(&desc->threads_handled); in irq_thread_fn()
1142 * interrupts rely on the implicit bh/preempt disable of the hard irq
1162 if (atomic_dec_and_test(&desc->threads_active)) in wake_threads_waitq()
1163 wake_up(&desc->wait_for_threads); in wake_threads_waitq()
1172 if (WARN_ON_ONCE(!(current->flags & PF_EXITING))) in irq_thread_dtor()
1177 pr_err("exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n", in irq_thread_dtor()
1178 tsk->comm, tsk->pid, action->irq); in irq_thread_dtor()
1181 desc = irq_to_desc(action->irq); in irq_thread_dtor()
1184 * desc->threads_active and wake possible waiters. in irq_thread_dtor()
1186 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_thread_dtor()
1189 /* Prevent a stale desc->threads_oneshot */ in irq_thread_dtor()
1195 struct irqaction *secondary = action->secondary; in irq_wake_secondary()
1200 guard(raw_spinlock_irq)(&desc->lock); in irq_wake_secondary()
1210 set_bit(IRQTF_READY, &action->thread_flags); in irq_thread_set_ready()
1211 wake_up(&desc->wait_for_threads); in irq_thread_set_ready()
1215 * Internal function to wake up a interrupt thread and wait until it is
1221 if (!action || !action->thread) in wake_up_and_wait_for_irq_thread_ready()
1224 wake_up_process(action->thread); in wake_up_and_wait_for_irq_thread_ready()
1225 wait_event(desc->wait_for_threads, in wake_up_and_wait_for_irq_thread_ready()
1226 test_bit(IRQTF_READY, &action->thread_flags)); in wake_up_and_wait_for_irq_thread_ready()
1236 struct irq_desc *desc = irq_to_desc(action->irq); in irq_thread()
1245 &action->thread_flags)) in irq_thread()
1267 * oneshot mask bit can be set. in irq_thread()
1274 * irq_wake_thread - wake the irq thread for the action identified by dev_id
1275 * @irq: Interrupt line
1278 void irq_wake_thread(unsigned int irq, void *dev_id) in irq_wake_thread() argument
1280 struct irq_desc *desc = irq_to_desc(irq); in irq_wake_thread()
1286 guard(raw_spinlock_irqsave)(&desc->lock); in irq_wake_thread()
1288 if (action->dev_id == dev_id) { in irq_wake_thread()
1289 if (action->thread) in irq_wake_thread()
1301 if (new->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT)) in irq_setup_forced_threading()
1308 if (new->handler == irq_default_primary_handler) in irq_setup_forced_threading()
1311 new->flags |= IRQF_ONESHOT; in irq_setup_forced_threading()
1318 if (new->handler && new->thread_fn) { in irq_setup_forced_threading()
1320 new->secondary = kzalloc(sizeof(struct irqaction), GFP_KERNEL); in irq_setup_forced_threading()
1321 if (!new->secondary) in irq_setup_forced_threading()
1322 return -ENOMEM; in irq_setup_forced_threading()
1323 new->secondary->handler = irq_forced_secondary_handler; in irq_setup_forced_threading()
1324 new->secondary->thread_fn = new->thread_fn; in irq_setup_forced_threading()
1325 new->secondary->dev_id = new->dev_id; in irq_setup_forced_threading()
1326 new->secondary->irq = new->irq; in irq_setup_forced_threading()
1327 new->secondary->name = new->name; in irq_setup_forced_threading()
1330 set_bit(IRQTF_FORCED_THREAD, &new->thread_flags); in irq_setup_forced_threading()
1331 new->thread_fn = new->handler; in irq_setup_forced_threading()
1332 new->handler = irq_default_primary_handler; in irq_setup_forced_threading()
1338 struct irq_data *d = &desc->irq_data; in irq_request_resources()
1339 struct irq_chip *c = d->chip; in irq_request_resources()
1341 return c->irq_request_resources ? c->irq_request_resources(d) : 0; in irq_request_resources()
1346 struct irq_data *d = &desc->irq_data; in irq_release_resources()
1347 struct irq_chip *c = d->chip; in irq_release_resources()
1349 if (c->irq_release_resources) in irq_release_resources()
1350 c->irq_release_resources(d); in irq_release_resources()
1358 /* Only IRQs directly managed by the root irqchip can be set as NMI */ in irq_supports_nmi()
1359 if (d->parent_data) in irq_supports_nmi()
1363 if (d->chip->irq_bus_lock || d->chip->irq_bus_sync_unlock) in irq_supports_nmi()
1366 return d->chip->flags & IRQCHIP_SUPPORTS_NMI; in irq_supports_nmi()
1372 struct irq_chip *c = d->chip; in irq_nmi_setup()
1374 return c->irq_nmi_setup ? c->irq_nmi_setup(d) : -EINVAL; in irq_nmi_setup()
1380 struct irq_chip *c = d->chip; in irq_nmi_teardown()
1382 if (c->irq_nmi_teardown) in irq_nmi_teardown()
1383 c->irq_nmi_teardown(d); in irq_nmi_teardown()
1387 setup_irq_thread(struct irqaction *new, unsigned int irq, bool secondary) in setup_irq_thread() argument
1392 t = kthread_create(irq_thread, new, "irq/%d-%s", irq, in setup_irq_thread()
1393 new->name); in setup_irq_thread()
1395 t = kthread_create(irq_thread, new, "irq/%d-s-%s", irq, in setup_irq_thread()
1396 new->name); in setup_irq_thread()
1407 new->thread = get_task_struct(t); in setup_irq_thread()
1417 set_bit(IRQTF_AFFINITY, &new->thread_flags); in setup_irq_thread()
1422 * Internal function to register an irqaction - typically used to
1427 * desc->request_mutex Provides serialization against a concurrent free_irq()
1429 * desc->lock Provides serialization against hard interrupts
1431 * chip_bus_lock and desc->lock are sufficient for all other management and
1432 * interrupt related functions. desc->request_mutex solely serializes
1436 __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) in __setup_irq() argument
1443 return -EINVAL; in __setup_irq()
1445 if (desc->irq_data.chip == &no_irq_chip) in __setup_irq()
1446 return -ENOSYS; in __setup_irq()
1447 if (!try_module_get(desc->owner)) in __setup_irq()
1448 return -ENODEV; in __setup_irq()
1450 new->irq = irq; in __setup_irq()
1456 if (!(new->flags & IRQF_TRIGGER_MASK)) in __setup_irq()
1457 new->flags |= irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1465 if (!new->thread_fn) { in __setup_irq()
1466 ret = -EINVAL; in __setup_irq()
1474 new->handler = irq_nested_primary_handler; in __setup_irq()
1488 if (new->thread_fn && !nested) { in __setup_irq()
1489 ret = setup_irq_thread(new, irq, false); in __setup_irq()
1492 if (new->secondary) { in __setup_irq()
1493 ret = setup_irq_thread(new->secondary, irq, true); in __setup_irq()
1501 * underlying irq chip implementation, so a request for a in __setup_irq()
1502 * threaded irq without a primary hard irq context handler in __setup_irq()
1503 * requires the ONESHOT flag to be set. Some irq chips like in __setup_irq()
1505 * chip flags, so we can avoid the unmask dance at the end of in __setup_irq()
1508 if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) in __setup_irq()
1509 new->flags &= ~IRQF_ONESHOT; in __setup_irq()
1514 * chip bus lock and desc->lock. Also protects against handing out in __setup_irq()
1518 mutex_lock(&desc->request_mutex); in __setup_irq()
1528 if (!desc->action) { in __setup_irq()
1531 pr_err("Failed to request resources for %s (irq %d) on irqchip %s\n", in __setup_irq()
1532 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1541 * desc->request_mutex or the optional bus lock. in __setup_irq()
1543 raw_spin_lock_irqsave(&desc->lock, flags); in __setup_irq()
1544 old_ptr = &desc->action; in __setup_irq()
1548 * Can't share interrupts unless both agree to and are in __setup_irq()
1558 pr_err("Invalid attempt to share NMI for %s (irq %d) on irqchip %s.\n", in __setup_irq()
1559 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1560 ret = -EINVAL; in __setup_irq()
1568 if (irqd_trigger_type_was_set(&desc->irq_data)) { in __setup_irq()
1569 oldtype = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1571 oldtype = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1572 irqd_set_trigger_type(&desc->irq_data, oldtype); in __setup_irq()
1575 if (!((old->flags & new->flags) & IRQF_SHARED) || in __setup_irq()
1576 (oldtype != (new->flags & IRQF_TRIGGER_MASK))) in __setup_irq()
1579 if ((old->flags & IRQF_ONESHOT) && in __setup_irq()
1580 (new->flags & IRQF_COND_ONESHOT)) in __setup_irq()
1581 new->flags |= IRQF_ONESHOT; in __setup_irq()
1582 else if ((old->flags ^ new->flags) & IRQF_ONESHOT) in __setup_irq()
1585 /* All handlers must agree on per-cpuness */ in __setup_irq()
1586 if ((old->flags & IRQF_PERCPU) != in __setup_irq()
1587 (new->flags & IRQF_PERCPU)) in __setup_irq()
1590 /* add new interrupt at end of irq queue */ in __setup_irq()
1593 * Or all existing action->thread_mask bits, in __setup_irq()
1594 * so we can find the next zero bit for this in __setup_irq()
1597 thread_mask |= old->thread_mask; in __setup_irq()
1598 old_ptr = &old->next; in __setup_irq()
1606 * !ONESHOT irqs the thread mask is 0 so we can avoid a in __setup_irq()
1609 if (new->flags & IRQF_ONESHOT) { in __setup_irq()
1615 ret = -EBUSY; in __setup_irq()
1620 * desc->thread_active to indicate that the in __setup_irq()
1624 * line have completed desc->threads_active becomes in __setup_irq()
1628 * If no thread is woken by primary (hard irq context) in __setup_irq()
1629 * interrupt handlers, then desc->threads_active is in __setup_irq()
1630 * also checked for zero to unmask the irq line in the in __setup_irq()
1631 * affected hard irq flow handlers in __setup_irq()
1636 * all existing action->thread_mask bits. in __setup_irq()
1638 new->thread_mask = 1UL << ffz(thread_mask); in __setup_irq()
1640 } else if (new->handler == irq_default_primary_handler && in __setup_irq()
1641 !(desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)) { in __setup_irq()
1648 * the irq lines is reenabled, but the device still in __setup_irq()
1649 * has the level irq asserted. Rinse and repeat.... in __setup_irq()
1652 * it safe and reject unconditionally because we can't in __setup_irq()
1655 * underlying chip implementation can override them. in __setup_irq()
1657 pr_err("Threaded irq requested with handler=NULL and !ONESHOT for %s (irq %d)\n", in __setup_irq()
1658 new->name, irq); in __setup_irq()
1659 ret = -EINVAL; in __setup_irq()
1665 if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1667 new->flags & IRQF_TRIGGER_MASK); in __setup_irq()
1675 * independently of IRQ_NOAUTOEN. request_irq() can fail in __setup_irq()
1688 desc->istate &= ~(IRQS_AUTODETECT | IRQS_SPURIOUS_DISABLED | \ in __setup_irq()
1690 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); in __setup_irq()
1692 if (new->flags & IRQF_PERCPU) { in __setup_irq()
1693 irqd_set(&desc->irq_data, IRQD_PER_CPU); in __setup_irq()
1695 if (new->flags & IRQF_NO_DEBUG) in __setup_irq()
1702 if (new->flags & IRQF_ONESHOT) in __setup_irq()
1703 desc->istate |= IRQS_ONESHOT; in __setup_irq()
1705 /* Exclude IRQ from balancing if requested */ in __setup_irq()
1706 if (new->flags & IRQF_NOBALANCING) { in __setup_irq()
1708 irqd_set(&desc->irq_data, IRQD_NO_BALANCING); in __setup_irq()
1711 if (!(new->flags & IRQF_NO_AUTOEN) && in __setup_irq()
1721 WARN_ON_ONCE(new->flags & IRQF_SHARED); in __setup_irq()
1723 desc->depth = 1; in __setup_irq()
1726 } else if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1727 unsigned int nmsk = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1728 unsigned int omsk = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1732 pr_warn("irq %d uses trigger mode %u; requested %u\n", in __setup_irq()
1733 irq, omsk, nmsk); in __setup_irq()
1740 /* Reset broken irq detection when installing new handler */ in __setup_irq()
1741 desc->irq_count = 0; in __setup_irq()
1742 desc->irqs_unhandled = 0; in __setup_irq()
1745 * Check whether we disabled the irq via the spurious handler in __setup_irq()
1748 if (shared && (desc->istate & IRQS_SPURIOUS_DISABLED)) { in __setup_irq()
1749 desc->istate &= ~IRQS_SPURIOUS_DISABLED; in __setup_irq()
1753 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1755 mutex_unlock(&desc->request_mutex); in __setup_irq()
1760 wake_up_and_wait_for_irq_thread_ready(desc, new->secondary); in __setup_irq()
1762 register_irq_proc(irq, desc); in __setup_irq()
1763 new->dir = NULL; in __setup_irq()
1764 register_handler_proc(irq, new); in __setup_irq()
1768 if (!(new->flags & IRQF_PROBE_SHARED)) { in __setup_irq()
1769 pr_err("Flags mismatch irq %d. %08x (%s) vs. %08x (%s)\n", in __setup_irq()
1770 irq, new->flags, new->name, old->flags, old->name); in __setup_irq()
1775 ret = -EBUSY; in __setup_irq()
1778 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1780 if (!desc->action) in __setup_irq()
1784 mutex_unlock(&desc->request_mutex); in __setup_irq()
1787 if (new->thread) { in __setup_irq()
1788 struct task_struct *t = new->thread; in __setup_irq()
1790 new->thread = NULL; in __setup_irq()
1793 if (new->secondary && new->secondary->thread) { in __setup_irq()
1794 struct task_struct *t = new->secondary->thread; in __setup_irq()
1796 new->secondary->thread = NULL; in __setup_irq()
1800 module_put(desc->owner); in __setup_irq()
1805 * Internal function to unregister an irqaction - used to free
1810 unsigned irq = desc->irq_data.irq; in __free_irq() local
1814 WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq); in __free_irq()
1816 mutex_lock(&desc->request_mutex); in __free_irq()
1818 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1821 * There can be multiple actions per IRQ descriptor, find the right in __free_irq()
1824 action_ptr = &desc->action; in __free_irq()
1829 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_irq()
1830 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1832 mutex_unlock(&desc->request_mutex); in __free_irq()
1836 if (action->dev_id == dev_id) in __free_irq()
1838 action_ptr = &action->next; in __free_irq()
1841 /* Found it - now remove it from the list of entries: */ in __free_irq()
1842 *action_ptr = action->next; in __free_irq()
1846 /* If this was the last handler, shut down the IRQ line: */ in __free_irq()
1847 if (!desc->action) { in __free_irq()
1855 if (WARN_ON_ONCE(desc->affinity_hint)) in __free_irq()
1856 desc->affinity_hint = NULL; in __free_irq()
1859 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1862 * callbacks above are synced out to the irq chips which hang in __free_irq()
1865 * Aside of that the bus_lock can also be taken from the threaded in __free_irq()
1870 * The still held desc->request_mutex() protects against a in __free_irq()
1871 * concurrent request_irq() of this irq so the release of resources in __free_irq()
1876 unregister_handler_proc(irq, action); in __free_irq()
1887 * It's a shared IRQ -- the driver ought to be prepared for an IRQ in __free_irq()
1892 * 'real' IRQ doesn't run in parallel with our fake. ) in __free_irq()
1894 if (action->flags & IRQF_SHARED) { in __free_irq()
1896 action->handler(irq, dev_id); in __free_irq()
1907 if (action->thread) { in __free_irq()
1908 kthread_stop_put(action->thread); in __free_irq()
1909 if (action->secondary && action->secondary->thread) in __free_irq()
1910 kthread_stop_put(action->secondary->thread); in __free_irq()
1914 if (!desc->action) { in __free_irq()
1924 scoped_guard(raw_spinlock_irqsave, &desc->lock) in __free_irq()
1925 irq_domain_deactivate_irq(&desc->irq_data); in __free_irq()
1932 mutex_unlock(&desc->request_mutex); in __free_irq()
1934 irq_chip_pm_put(&desc->irq_data); in __free_irq()
1935 module_put(desc->owner); in __free_irq()
1936 kfree(action->secondary); in __free_irq()
1941 * free_irq - free an interrupt allocated with request_irq
1942 * @irq: Interrupt line to free
1946 * line is no longer in use by any driver it is disabled. On a shared IRQ
1949 * executing interrupts for this IRQ have completed.
1955 const void *free_irq(unsigned int irq, void *dev_id) in free_irq() argument
1957 struct irq_desc *desc = irq_to_desc(irq); in free_irq()
1965 if (WARN_ON(desc->affinity_notify)) in free_irq()
1966 desc->affinity_notify = NULL; in free_irq()
1974 devname = action->name; in free_irq()
1980 /* This function must be called with desc->lock held */
1981 static const void *__cleanup_nmi(unsigned int irq, struct irq_desc *desc) in __cleanup_nmi() argument
1985 desc->istate &= ~IRQS_NMI; in __cleanup_nmi()
1987 if (!WARN_ON(desc->action == NULL)) { in __cleanup_nmi()
1988 irq_pm_remove_action(desc, desc->action); in __cleanup_nmi()
1989 devname = desc->action->name; in __cleanup_nmi()
1990 unregister_handler_proc(irq, desc->action); in __cleanup_nmi()
1992 kfree(desc->action); in __cleanup_nmi()
1993 desc->action = NULL; in __cleanup_nmi()
2001 irq_chip_pm_put(&desc->irq_data); in __cleanup_nmi()
2002 module_put(desc->owner); in __cleanup_nmi()
2007 const void *free_nmi(unsigned int irq, void *dev_id) in free_nmi() argument
2009 struct irq_desc *desc = irq_to_desc(irq); in free_nmi()
2018 if (WARN_ON(desc->depth == 0)) in free_nmi()
2019 disable_nmi_nosync(irq); in free_nmi()
2021 guard(raw_spinlock_irqsave)(&desc->lock); in free_nmi()
2023 return __cleanup_nmi(irq, desc); in free_nmi()
2027 * request_threaded_irq - allocate an interrupt line
2028 * @irq: Interrupt line to allocate
2029 * @handler: Function to be called when the IRQ occurs.
2033 * @thread_fn: Function called from the irq handler thread
2034 * If NULL, no irq thread is created
2040 * and IRQ handling. From the point this call is made your handler function
2045 * If you want to set up a threaded irq handler for your device then you
2049 * return IRQ_WAKE_THREAD which will wake up the handler thread and run
2066 int request_threaded_irq(unsigned int irq, irq_handler_t handler, in request_threaded_irq() argument
2074 if (irq == IRQ_NOTCONNECTED) in request_threaded_irq()
2075 return -ENOTCONN; in request_threaded_irq()
2078 * Sanity-check: shared interrupts must pass in a real dev-ID, in request_threaded_irq()
2094 return -EINVAL; in request_threaded_irq()
2096 desc = irq_to_desc(irq); in request_threaded_irq()
2098 return -EINVAL; in request_threaded_irq()
2102 return -EINVAL; in request_threaded_irq()
2106 return -EINVAL; in request_threaded_irq()
2112 return -ENOMEM; in request_threaded_irq()
2114 action->handler = handler; in request_threaded_irq()
2115 action->thread_fn = thread_fn; in request_threaded_irq()
2116 action->flags = irqflags; in request_threaded_irq()
2117 action->name = devname; in request_threaded_irq()
2118 action->dev_id = dev_id; in request_threaded_irq()
2120 retval = irq_chip_pm_get(&desc->irq_data); in request_threaded_irq()
2126 retval = __setup_irq(irq, desc, action); in request_threaded_irq()
2129 irq_chip_pm_put(&desc->irq_data); in request_threaded_irq()
2130 kfree(action->secondary); in request_threaded_irq()
2137 * It's a shared IRQ -- the driver ought to be prepared for it in request_threaded_irq()
2139 * We disable the irq to make sure that a 'real' IRQ doesn't in request_threaded_irq()
2144 disable_irq(irq); in request_threaded_irq()
2147 handler(irq, dev_id); in request_threaded_irq()
2150 enable_irq(irq); in request_threaded_irq()
2158 * request_any_context_irq - allocate an interrupt line
2159 * @irq: Interrupt line to allocate
2160 * @handler: Function to be called when the IRQ occurs.
2167 * and IRQ handling. It selects either a hardirq or threaded handling
2173 int request_any_context_irq(unsigned int irq, irq_handler_t handler, in request_any_context_irq() argument
2179 if (irq == IRQ_NOTCONNECTED) in request_any_context_irq()
2180 return -ENOTCONN; in request_any_context_irq()
2182 desc = irq_to_desc(irq); in request_any_context_irq()
2184 return -EINVAL; in request_any_context_irq()
2187 ret = request_threaded_irq(irq, NULL, handler, in request_any_context_irq()
2192 ret = request_irq(irq, handler, flags, name, dev_id); in request_any_context_irq()
2198 * request_nmi - allocate an interrupt line for NMI delivery
2199 * @irq: Interrupt line to allocate
2200 * @handler: Function to be called when the IRQ occurs.
2207 * and IRQ handling. It sets up the IRQ line to be handled as an NMI.
2209 * An interrupt line delivering NMIs cannot be shared and IRQ handling
2222 int request_nmi(unsigned int irq, irq_handler_t handler, in request_nmi() argument
2229 if (irq == IRQ_NOTCONNECTED) in request_nmi()
2230 return -ENOTCONN; in request_nmi()
2234 return -EINVAL; in request_nmi()
2237 return -EINVAL; in request_nmi()
2240 return -EINVAL; in request_nmi()
2242 desc = irq_to_desc(irq); in request_nmi()
2249 return -EINVAL; in request_nmi()
2253 return -ENOMEM; in request_nmi()
2255 action->handler = handler; in request_nmi()
2256 action->flags = irqflags | IRQF_NO_THREAD | IRQF_NOBALANCING; in request_nmi()
2257 action->name = name; in request_nmi()
2258 action->dev_id = dev_id; in request_nmi()
2260 retval = irq_chip_pm_get(&desc->irq_data); in request_nmi()
2264 retval = __setup_irq(irq, desc, action); in request_nmi()
2268 scoped_guard(raw_spinlock_irqsave, &desc->lock) { in request_nmi()
2270 desc->istate |= IRQS_NMI; in request_nmi()
2273 __cleanup_nmi(irq, desc); in request_nmi()
2274 return -EINVAL; in request_nmi()
2280 irq_chip_pm_put(&desc->irq_data); in request_nmi()
2287 void enable_percpu_irq(unsigned int irq, unsigned int type) in enable_percpu_irq() argument
2289 scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_PERCPU) { in enable_percpu_irq()
2298 type = irqd_get_trigger_type(&desc->irq_data); in enable_percpu_irq()
2302 WARN(1, "failed to set type for IRQ%d\n", irq); in enable_percpu_irq()
2311 void enable_percpu_nmi(unsigned int irq, unsigned int type) in enable_percpu_nmi() argument
2313 enable_percpu_irq(irq, type); in enable_percpu_nmi()
2317 * irq_percpu_is_enabled - Check whether the per cpu irq is enabled
2318 * @irq: Linux irq number to check for
2323 bool irq_percpu_is_enabled(unsigned int irq) in irq_percpu_is_enabled() argument
2325 scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_PERCPU) in irq_percpu_is_enabled()
2326 return cpumask_test_cpu(smp_processor_id(), scoped_irqdesc->percpu_enabled); in irq_percpu_is_enabled()
2331 void disable_percpu_irq(unsigned int irq) in disable_percpu_irq() argument
2333 scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_PERCPU) in disable_percpu_irq()
2338 void disable_percpu_nmi(unsigned int irq) in disable_percpu_nmi() argument
2340 disable_percpu_irq(irq); in disable_percpu_nmi()
2346 static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_id) in __free_percpu_irq() argument
2348 struct irq_desc *desc = irq_to_desc(irq); in __free_percpu_irq()
2351 WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq); in __free_percpu_irq()
2356 scoped_guard(raw_spinlock_irqsave, &desc->lock) { in __free_percpu_irq()
2357 action = desc->action; in __free_percpu_irq()
2358 if (!action || action->percpu_dev_id != dev_id) { in __free_percpu_irq()
2359 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_percpu_irq()
2363 if (!cpumask_empty(desc->percpu_enabled)) { in __free_percpu_irq()
2364 WARN(1, "percpu IRQ %d still enabled on CPU%d!\n", in __free_percpu_irq()
2365 irq, cpumask_first(desc->percpu_enabled)); in __free_percpu_irq()
2369 /* Found it - now remove it from the list of entries: */ in __free_percpu_irq()
2370 desc->action = NULL; in __free_percpu_irq()
2371 desc->istate &= ~IRQS_NMI; in __free_percpu_irq()
2374 unregister_handler_proc(irq, action); in __free_percpu_irq()
2375 irq_chip_pm_put(&desc->irq_data); in __free_percpu_irq()
2376 module_put(desc->owner); in __free_percpu_irq()
2381 * free_percpu_irq - free an interrupt allocated with request_percpu_irq
2382 * @irq: Interrupt line to free
2388 * interrupts for this IRQ have completed.
2392 void free_percpu_irq(unsigned int irq, void __percpu *dev_id) in free_percpu_irq() argument
2394 struct irq_desc *desc = irq_to_desc(irq); in free_percpu_irq()
2400 kfree(__free_percpu_irq(irq, dev_id)); in free_percpu_irq()
2405 void free_percpu_nmi(unsigned int irq, void __percpu *dev_id) in free_percpu_nmi() argument
2407 struct irq_desc *desc = irq_to_desc(irq); in free_percpu_nmi()
2415 kfree(__free_percpu_irq(irq, dev_id)); in free_percpu_nmi()
2419 * setup_percpu_irq - setup a per-cpu interrupt
2420 * @irq: Interrupt line to setup
2423 * Used to statically setup per-cpu interrupts in the early boot process.
2425 int setup_percpu_irq(unsigned int irq, struct irqaction *act) in setup_percpu_irq() argument
2427 struct irq_desc *desc = irq_to_desc(irq); in setup_percpu_irq()
2431 return -EINVAL; in setup_percpu_irq()
2433 retval = irq_chip_pm_get(&desc->irq_data); in setup_percpu_irq()
2437 retval = __setup_irq(irq, desc, act); in setup_percpu_irq()
2440 irq_chip_pm_put(&desc->irq_data); in setup_percpu_irq()
2446 * __request_percpu_irq - allocate a percpu interrupt line
2447 * @irq: Interrupt line to allocate
2448 * @handler: Function to be called when the IRQ occurs.
2457 * @dev_id must be globally unique. It is a per-cpu variable, and
2461 int __request_percpu_irq(unsigned int irq, irq_handler_t handler, in __request_percpu_irq() argument
2470 return -EINVAL; in __request_percpu_irq()
2472 desc = irq_to_desc(irq); in __request_percpu_irq()
2475 return -EINVAL; in __request_percpu_irq()
2478 return -EINVAL; in __request_percpu_irq()
2482 return -ENOMEM; in __request_percpu_irq()
2484 action->handler = handler; in __request_percpu_irq()
2485 action->flags = flags | IRQF_PERCPU | IRQF_NO_SUSPEND; in __request_percpu_irq()
2486 action->name = devname; in __request_percpu_irq()
2487 action->percpu_dev_id = dev_id; in __request_percpu_irq()
2489 retval = irq_chip_pm_get(&desc->irq_data); in __request_percpu_irq()
2495 retval = __setup_irq(irq, desc, action); in __request_percpu_irq()
2498 irq_chip_pm_put(&desc->irq_data); in __request_percpu_irq()
2507 * request_percpu_nmi - allocate a percpu interrupt line for NMI delivery
2508 * @irq: Interrupt line to allocate
2509 * @handler: Function to be called when the IRQ occurs.
2517 * @dev_id must be globally unique. It is a per-cpu variable, and the
2527 int request_percpu_nmi(unsigned int irq, irq_handler_t handler, in request_percpu_nmi() argument
2535 return -EINVAL; in request_percpu_nmi()
2537 desc = irq_to_desc(irq); in request_percpu_nmi()
2543 return -EINVAL; in request_percpu_nmi()
2547 return -EINVAL; in request_percpu_nmi()
2551 return -ENOMEM; in request_percpu_nmi()
2553 action->handler = handler; in request_percpu_nmi()
2554 action->flags = IRQF_PERCPU | IRQF_NO_SUSPEND | IRQF_NO_THREAD in request_percpu_nmi()
2556 action->name = name; in request_percpu_nmi()
2557 action->percpu_dev_id = dev_id; in request_percpu_nmi()
2559 retval = irq_chip_pm_get(&desc->irq_data); in request_percpu_nmi()
2563 retval = __setup_irq(irq, desc, action); in request_percpu_nmi()
2567 scoped_guard(raw_spinlock_irqsave, &desc->lock) in request_percpu_nmi()
2568 desc->istate |= IRQS_NMI; in request_percpu_nmi()
2572 irq_chip_pm_put(&desc->irq_data); in request_percpu_nmi()
2580 * prepare_percpu_nmi - performs CPU local setup for NMI delivery
2581 * @irq: Interrupt line to prepare for NMI delivery
2586 * As a CPU local operation, this should be called from non-preemptible
2592 int prepare_percpu_nmi(unsigned int irq) in prepare_percpu_nmi() argument
2594 int ret = -EINVAL; in prepare_percpu_nmi()
2598 scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_PERCPU) { in prepare_percpu_nmi()
2600 "prepare_percpu_nmi called for a non-NMI interrupt: irq %u\n", irq)) in prepare_percpu_nmi()
2601 return -EINVAL; in prepare_percpu_nmi()
2605 pr_err("Failed to setup NMI delivery: irq %u\n", irq); in prepare_percpu_nmi()
2611 * teardown_percpu_nmi - undoes NMI setup of IRQ line
2612 * @irq: Interrupt line from which CPU local NMI configuration should be removed
2616 * IRQ line should not be enabled for the current CPU.
2617 * As a CPU local operation, this should be called from non-preemptible
2620 void teardown_percpu_nmi(unsigned int irq) in teardown_percpu_nmi() argument
2624 scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_PERCPU) { in teardown_percpu_nmi()
2634 int err = -EINVAL; in __irq_get_irqchip_state()
2639 return -ENODEV; in __irq_get_irqchip_state()
2640 if (chip->irq_get_irqchip_state) in __irq_get_irqchip_state()
2643 data = data->parent_data; in __irq_get_irqchip_state()
2650 err = chip->irq_get_irqchip_state(data, which, state); in __irq_get_irqchip_state()
2655 * irq_get_irqchip_state - returns the irqchip state of a interrupt.
2656 * @irq: Interrupt line that is forwarded to a VM
2664 * controller has per-cpu registers.
2666 int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which, bool *state) in irq_get_irqchip_state() argument
2668 scoped_irqdesc_get_and_buslock(irq, 0) { in irq_get_irqchip_state()
2673 return -EINVAL; in irq_get_irqchip_state()
2678 * irq_set_irqchip_state - set the state of a forwarded interrupt.
2679 * @irq: Interrupt line that is forwarded to a VM
2687 * controller has per-cpu registers.
2689 int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which, bool val) in irq_set_irqchip_state() argument
2691 scoped_irqdesc_get_and_buslock(irq, 0) { in irq_set_irqchip_state()
2699 return -ENODEV; in irq_set_irqchip_state()
2701 if (chip->irq_set_irqchip_state) in irq_set_irqchip_state()
2708 return chip->irq_set_irqchip_state(data, which, val); in irq_set_irqchip_state()
2710 return -EINVAL; in irq_set_irqchip_state()
2715 * irq_has_action - Check whether an interrupt is requested
2716 * @irq: The linux irq number
2720 bool irq_has_action(unsigned int irq) in irq_has_action() argument
2725 res = irq_desc_has_action(irq_to_desc(irq)); in irq_has_action()
2732 * irq_check_status_bit - Check whether bits in the irq descriptor status are set
2733 * @irq: The linux irq number
2738 bool irq_check_status_bit(unsigned int irq, unsigned int bitmask) in irq_check_status_bit() argument
2744 desc = irq_to_desc(irq); in irq_check_status_bit()
2746 res = !!(desc->status_use_accessors & bitmask); in irq_check_status_bit()