Lines Matching +full:shared +full:- +full:interrupt

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
4 * Copyright (C) 2005-2006 Thomas Gleixner
15 #include <linux/interrupt.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
88 * This function may be called - with care - from IRQ context.
90 * It does not check whether there is an interrupt in flight at the
92 * with interrupts disabled and the target CPU of the interrupt is the
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
127 * an interrupt thread is associated to @irq.
130 * that the interrupt is not pending in any CPU and waiting for
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
164 * irq_can_set_affinity_usr - Check if affinity of a irq can be set from user space
165 * @irq: Interrupt to check
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
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()
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()
233 * If this is a managed interrupt and housekeeping is enabled on in irq_do_set_affinity()
237 * the affinity setter from routing the interrupt to an isolated in irq_do_set_affinity()
247 * interrupt will be migrated by the CPU hotplug code once a 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()
335 * If the interrupt is not yet activated, just store the affinity in irq_set_affinity_deactivated()
337 * driver has to make sure anyway that the interrupt is in a 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
391 * There are certain limitations on when it may be used - attempts to use it
394 * managed/non-managed interrupt accounting. In addition, attempts to use it on
395 * an interrupt which is already started or which has already been configured
405 return -EOPNOTSUPP; in irq_update_affinity_desc()
411 /* Requires the interrupt to be shut down */ 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()
419 * Deactivate the interrupt. That's required to undo 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()
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
467 * irq_force_affinity - Force the irq affinity of a given irq
468 * @irq: Interrupt to set affinity
485 int ret = -EINVAL; in __irq_apply_affinity_hint()
488 scoped_irqdesc->affinity_hint = m; 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
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
628 * example code path is as below: KVM -> IOMMU -> 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()
666 return -EINVAL; in __disable_irq_nosync()
670 * disable_irq_nosync - disable an irq without waiting
671 * @irq: Interrupt to disable
673 * Disable the selected interrupt line. Disables and Enables are
687 * disable_irq - disable an irq and wait for completion
688 * @irq: Interrupt to disable
690 * Disable the selected interrupt line. Enables and Disables are nested.
692 * This function waits for any pending IRQ handlers for this interrupt to
697 * interrupt thread is associated to @irq.
709 * disable_hardirq - disables an irq and waits for hardirq completion
710 * @irq: Interrupt to disable
712 * Disable the selected interrupt line. Enables and Disables are nested.
714 * This function waits for any pending hard IRQ handlers for this interrupt
718 * When used to optimistically disable an interrupt from atomic context the
723 * This function may be called - with care - from IRQ context.
734 * disable_nmi_nosync - disable an nmi without waiting
735 * @irq: Interrupt to disable
737 * Disable the selected interrupt line. Disables and enables are nested.
739 * The interrupt to disable must have been requested through request_nmi.
750 switch (desc->depth) { in __enable_irq()
757 if (desc->istate & IRQS_SUSPENDED) in __enable_irq()
763 * interrupt might be marked NOAUTOEN so irq_startup() in __enable_irq()
766 * a managed and shutdown interrupt from the S3 resume 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.
788 * desc->irq_data.chip->bus_lock and desc->chip->bus_sync_unlock are NULL !
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
806 * The interrupt to enable must have been requested through request_nmi.
808 * disable, processing of interrupts on this IRQ line is re-enabled.
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.
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()
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()
872 } else if (--desc->wake_depth == 0) { 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()
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()
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()
952 flags, irq_desc_get_irq(desc), chip->irq_set_type); in __irq_set_trigger()
963 scoped_irqdesc->parent_irq = parent_irq; in irq_set_parent()
966 return -EINVAL; in irq_set_parent()
972 * Default primary interrupt handler for threaded interrupts. Is
999 * Check whether we need to change the affinity of the interrupt thread.
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()
1071 * handler finished. unmask if the interrupt has not been disabled and
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()
1088 * The thread is faster done than the hard interrupt handler in irq_finalize_oneshot()
1090 * interrupt can come in again and masks the line, leaves due in irq_finalize_oneshot()
1093 * This also serializes the state of shared oneshot handlers 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()
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()
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()
1205 * Internal function to notify that a interrupt thread is ready.
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()
1230 * Interrupt handler thread
1236 struct irq_desc *desc = irq_to_desc(action->irq); in irq_thread()
1245 &action->thread_flags)) in irq_thread()
1274 * irq_wake_thread - wake the irq thread for the action identified by dev_id
1275 * @irq: Interrupt line
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()
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()
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()
1404 * the thread dies to avoid that the interrupt code in setup_irq_thread()
1407 new->thread = get_task_struct(t); in setup_irq_thread()
1410 * important for shared interrupt handlers as we do in setup_irq_thread()
1415 * on which the requesting code placed the interrupt. 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
1440 int ret, nested, shared = 0; in __setup_irq() local
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()
1454 * then use the default for this interrupt. 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()
1460 * Check whether the interrupt nests into another interrupt in __setup_irq()
1465 if (!new->thread_fn) { in __setup_irq()
1466 ret = -EINVAL; in __setup_irq()
1471 * the driver for non nested interrupt handling by the in __setup_irq()
1474 new->handler = irq_nested_primary_handler; in __setup_irq()
1485 * and the interrupt does not nest into another interrupt in __setup_irq()
1488 if (new->thread_fn && !nested) { in __setup_irq()
1492 if (new->secondary) { in __setup_irq()
1493 ret = setup_irq_thread(new->secondary, irq, true); 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()
1532 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1539 * protected against a concurrent interrupt and any of the other 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()
1553 * Interrupt lines used for NMIs cannot be shared. 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()
1597 thread_mask |= old->thread_mask; in __setup_irq()
1598 old_ptr = &old->next; in __setup_irq()
1601 shared = 1; 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()
1623 * completes. When all threads of a shared interrupt in __setup_irq()
1624 * line have completed desc->threads_active becomes in __setup_irq()
1625 * zero and the interrupt line is unmasked. See in __setup_irq()
1629 * interrupt handlers, then desc->threads_active is 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()
1643 * The interrupt was requested with handler = NULL, so in __setup_irq()
1653 * say for sure which type this interrupt really in __setup_irq()
1658 new->name, irq); in __setup_irq()
1659 ret = -EINVAL; in __setup_irq()
1663 if (!shared) { in __setup_irq()
1665 if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1667 new->flags & IRQF_TRIGGER_MASK); in __setup_irq()
1674 * Activate the interrupt. That activation must happen in __setup_irq()
1677 * that. enable_irq() of an interrupt requested with 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()
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()
1716 * Shared interrupts do not go well with disabling in __setup_irq()
1717 * auto enable. The sharing interrupt might request 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()
1741 desc->irq_count = 0; in __setup_irq()
1742 desc->irqs_unhandled = 0; 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()
1763 new->dir = NULL; in __setup_irq()
1768 if (!(new->flags & IRQF_PROBE_SHARED)) { 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()
1816 mutex_lock(&desc->request_mutex); in __free_irq()
1818 raw_spin_lock_irqsave(&desc->lock, flags); 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()
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()
1870 * The still held desc->request_mutex() protects against a in __free_irq()
1881 * interrupt in flight at the hardware level. in __free_irq()
1887 * It's a shared IRQ -- the driver ought to be prepared for an IRQ 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()
1921 * There is no interrupt on the fly anymore. Deactivate it 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
1945 * Remove an interrupt handler. The handler is removed and if the interrupt
1946 * line is no longer in use by any driver it is disabled. On a shared IRQ
1947 * the caller must ensure the interrupt is disabled on the card it drives
1951 * This function must not be called from interrupt context.
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 */
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()
2018 if (WARN_ON(desc->depth == 0)) in free_nmi()
2021 guard(raw_spinlock_irqsave)(&desc->lock); in free_nmi()
2027 * request_threaded_irq - allocate an interrupt line
2028 * @irq: Interrupt line to allocate
2035 * @irqflags: Interrupt type flags
2039 * This call allocates interrupt resources and enables the interrupt line
2041 * may be invoked. Since your handler function must clear any interrupt the
2043 * set up the interrupt handler in the right order.
2047 * interrupt context and has to check whether the interrupt originates from
2048 * the device. If yes it needs to disable the interrupt on the device and
2050 * @thread_fn. This split handler design is necessary to support shared
2057 * If your interrupt is shared you must pass a non NULL dev_id as this is
2058 * required when freeing the interrupt.
2062 * IRQF_SHARED Interrupt is shared
2064 * IRQF_ONESHOT Run thread_fn with interrupt line masked
2075 return -ENOTCONN; in request_threaded_irq()
2078 * Sanity-check: shared interrupts must pass in a real dev-ID, in request_threaded_irq()
2080 * which interrupt is which (messes up the interrupt freeing in request_threaded_irq()
2083 * Also shared interrupts do not go well with disabling auto enable. in request_threaded_irq()
2084 * The sharing interrupt might request it while it's still disabled in request_threaded_irq()
2087 * Also IRQF_COND_SUSPEND only makes sense for shared interrupts and in request_threaded_irq()
2094 return -EINVAL; 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()
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()
2158 * request_any_context_irq - allocate an interrupt line
2159 * @irq: Interrupt line to allocate
2162 * @flags: Interrupt type flags
2166 * This call allocates interrupt resources and enables the interrupt line
2180 return -ENOTCONN; in request_any_context_irq()
2184 return -EINVAL; in request_any_context_irq()
2198 * request_nmi - allocate an interrupt line for NMI delivery
2199 * @irq: Interrupt line to allocate
2202 * @irqflags: Interrupt type flags
2206 * This call allocates interrupt resources and enables the interrupt line
2209 * An interrupt line delivering NMIs cannot be shared and IRQ handling
2212 * Interrupt lines requested for NMI delivering must produce per cpu
2219 * If the interrupt line cannot be used to deliver NMIs, function will fail
2230 return -ENOTCONN; in request_nmi()
2232 /* NMI cannot be shared, used for Polling */ in request_nmi()
2234 return -EINVAL; in request_nmi()
2237 return -EINVAL; in request_nmi()
2240 return -EINVAL; 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()
2268 scoped_guard(raw_spinlock_irqsave, &desc->lock) { in request_nmi()
2270 desc->istate |= IRQS_NMI; in request_nmi()
2274 return -EINVAL; in request_nmi()
2280 irq_chip_pm_put(&desc->irq_data); in request_nmi()
2294 * use the default for this interrupt. in enable_percpu_irq()
2298 type = irqd_get_trigger_type(&desc->irq_data); in enable_percpu_irq()
2317 * irq_percpu_is_enabled - Check whether the per cpu irq is enabled
2321 * state of a per cpu interrupt on the current cpu.
2326 return cpumask_test_cpu(smp_processor_id(), scoped_irqdesc->percpu_enabled); in irq_percpu_is_enabled()
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()
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()
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
2385 * Remove a percpu interrupt handler. The handler is removed, but the
2386 * interrupt line is not disabled. This must be done on each CPU before
2390 * This function must not be called from interrupt context.
2419 * setup_percpu_irq - setup a per-cpu interrupt
2420 * @irq: Interrupt line to setup
2421 * @act: irqaction for the interrupt
2423 * Used to statically setup per-cpu interrupts in the early boot process.
2431 return -EINVAL; in setup_percpu_irq()
2433 retval = irq_chip_pm_get(&desc->irq_data); 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
2449 * @flags: Interrupt type flags (IRQF_TIMER only)
2453 * This call allocates interrupt resources and enables the interrupt on the
2454 * local CPU. If the interrupt is supposed to be enabled on other CPUs, it
2457 * @dev_id must be globally unique. It is a per-cpu variable, and
2470 return -EINVAL; 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()
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
2513 * This call allocates interrupt resources for a per CPU NMI. Per CPU NMIs
2517 * @dev_id must be globally unique. It is a per-cpu variable, and the
2521 * Interrupt lines requested for NMI delivering should have auto enabling
2524 * If the interrupt line cannot be used to deliver NMIs, function
2535 return -EINVAL; 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()
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
2583 * This call prepares an interrupt line to deliver NMI on the current CPU,
2584 * before that interrupt line gets enabled with enable_percpu_nmi().
2586 * As a CPU local operation, this should be called from non-preemptible
2589 * If the interrupt line cannot be used to deliver NMIs, function will fail
2594 int ret = -EINVAL; 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()
2611 * teardown_percpu_nmi - undoes NMI setup of IRQ line
2612 * @irq: Interrupt line from which CPU local NMI configuration should be removed
2617 * As a CPU local operation, this should be called from non-preemptible
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
2660 * This call snapshots the internal irqchip state of an interrupt,
2663 * This function should be called with preemption disabled if the interrupt
2664 * controller has per-cpu registers.
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
2683 * This call sets the internal irqchip state of an interrupt, depending on
2686 * This function should be called with migration disabled if the interrupt
2687 * controller has per-cpu registers.
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
2732 * irq_check_status_bit - Check whether bits in the irq descriptor status are set
2746 res = !!(desc->status_use_accessors & bitmask); in irq_check_status_bit()