Lines Matching +full:interrupt +full:- +full:affinity
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>
51 while (irqd_irq_inprogress(&desc->irq_data)) in __synchronize_hardirq()
54 /* Ok, that indicated we're done: double-check carefully. */ in __synchronize_hardirq()
55 raw_spin_lock_irqsave(&desc->lock, flags); in __synchronize_hardirq()
56 inprogress = irqd_irq_inprogress(&desc->irq_data); in __synchronize_hardirq()
71 raw_spin_unlock_irqrestore(&desc->lock, flags); in __synchronize_hardirq()
78 * synchronize_hardirq - wait for pending hard IRQ handlers (on other CPUs)
79 * @irq: interrupt number to wait for
82 * interrupt to complete before returning. If you use this
92 * This function may be called - with care - from IRQ context.
94 * It does not check whether there is an interrupt in flight at the
96 * called with interrupts disabled and the target CPU of the interrupt
105 return !atomic_read(&desc->threads_active); in synchronize_hardirq()
113 * synchronize_irq - wait for pending IRQ handlers (on other CPUs)
114 * @irq: interrupt number to wait for
116 * This function waits for any pending IRQ handlers for this interrupt
121 * an interrupt thread is associated to @irq.
124 * that the interrupt is not pending in any CPU and waiting for
138 wait_event(desc->wait_for_threads, in synchronize_irq()
139 !atomic_read(&desc->threads_active)); in synchronize_irq()
149 if (!desc || !irqd_can_balance(&desc->irq_data) || in __irq_can_set_affinity()
150 !desc->irq_data.chip || !desc->irq_data.chip->irq_set_affinity) in __irq_can_set_affinity()
156 * irq_can_set_affinity - Check if the affinity of a given irq can be set
157 * @irq: Interrupt to check
166 * irq_can_set_affinity_usr - Check if affinity of a irq can be set from user space
167 * @irq: Interrupt to check
177 !irqd_affinity_is_managed(&desc->irq_data); in irq_can_set_affinity_usr()
181 * irq_set_thread_affinity - Notify irq threads to adjust affinity
184 * We just set IRQTF_AFFINITY and delegate the affinity setting
185 * to the interrupt thread itself. We can not call
186 * set_cpus_allowed_ptr() here as we hold desc->lock and this
187 * code can be called from hard interrupt context.
194 if (action->thread) in irq_set_thread_affinity()
195 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_set_thread_affinity()
206 pr_warn_once("irq_chip %s did not update eff. affinity mask of irq %u\n", in irq_validate_effective_affinity()
207 chip->name, data->irq); in irq_validate_effective_affinity()
228 if (!chip || !chip->irq_set_affinity) in irq_do_set_affinity()
229 return -EINVAL; in irq_do_set_affinity()
232 * If this is a managed interrupt and housekeeping is enabled on in irq_do_set_affinity()
233 * it check whether the requested affinity mask intersects with in irq_do_set_affinity()
236 * the affinity setter from routing the interrupt to an isolated in irq_do_set_affinity()
245 * If all housekeeping CPUs in the affinity mask are offline, the in irq_do_set_affinity()
246 * interrupt will be migrated by the CPU hotplug code once a in irq_do_set_affinity()
247 * housekeeping CPU which belongs to the affinity mask comes in irq_do_set_affinity()
265 ret = chip->irq_set_affinity(data, prog_mask, force); in irq_do_set_affinity()
268 ret = chip->irq_set_affinity(data, mask, force); in irq_do_set_affinity()
273 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_do_set_affinity()
298 return -EBUSY; in irq_set_affinity_pending()
312 if (ret == -EBUSY && !force) in irq_try_set_affinity()
323 * Handle irq chips which can handle affinity only in activated in irq_set_affinity_deactivated()
326 * If the interrupt is not yet activated, just store the affinity in irq_set_affinity_deactivated()
328 * driver has to make sure anyway that the interrupt is in a in irq_set_affinity_deactivated()
335 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_set_affinity_deactivated()
348 if (!chip || !chip->irq_set_affinity) in irq_set_affinity_locked()
349 return -EINVAL; in irq_set_affinity_locked()
361 if (desc->affinity_notify) { in irq_set_affinity_locked()
362 kref_get(&desc->affinity_notify->kref); in irq_set_affinity_locked()
363 if (!schedule_work(&desc->affinity_notify->work)) { in irq_set_affinity_locked()
365 kref_put(&desc->affinity_notify->kref, in irq_set_affinity_locked()
366 desc->affinity_notify->release); in irq_set_affinity_locked()
381 return -EINVAL; in __irq_set_affinity()
383 raw_spin_lock_irqsave(&desc->lock, flags); in __irq_set_affinity()
385 raw_spin_unlock_irqrestore(&desc->lock, flags); in __irq_set_affinity()
395 return -EINVAL; in irq_set_affinity_hint()
396 desc->affinity_hint = m; in irq_set_affinity_hint()
398 /* set the initial affinity to prevent every interrupt being on CPU0 */ in irq_set_affinity_hint()
409 struct irq_desc *desc = irq_to_desc(notify->irq); in irq_affinity_notify()
416 raw_spin_lock_irqsave(&desc->lock, flags); in irq_affinity_notify()
417 if (irq_move_pending(&desc->irq_data)) in irq_affinity_notify()
420 cpumask_copy(cpumask, desc->irq_common_data.affinity); in irq_affinity_notify()
421 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_affinity_notify()
423 notify->notify(notify, cpumask); in irq_affinity_notify()
427 kref_put(¬ify->kref, notify->release); in irq_affinity_notify()
431 * irq_set_affinity_notifier - control notification of IRQ affinity changes
432 * @irq: Interrupt for which to enable/disable notification
451 if (!desc || desc->istate & IRQS_NMI) in irq_set_affinity_notifier()
452 return -EINVAL; in irq_set_affinity_notifier()
456 notify->irq = irq; in irq_set_affinity_notifier()
457 kref_init(¬ify->kref); in irq_set_affinity_notifier()
458 INIT_WORK(¬ify->work, irq_affinity_notify); in irq_set_affinity_notifier()
461 raw_spin_lock_irqsave(&desc->lock, flags); in irq_set_affinity_notifier()
462 old_notify = desc->affinity_notify; in irq_set_affinity_notifier()
463 desc->affinity_notify = notify; in irq_set_affinity_notifier()
464 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_set_affinity_notifier()
467 if (cancel_work_sync(&old_notify->work)) { in irq_set_affinity_notifier()
469 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
471 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
480 * Generic version of the affinity autoselector.
495 * Preserve the managed affinity setting and a userspace affinity in irq_setup_affinity()
498 if (irqd_affinity_is_managed(&desc->irq_data) || in irq_setup_affinity()
499 irqd_has_set(&desc->irq_data, IRQD_AFFINITY_SET)) { in irq_setup_affinity()
500 if (cpumask_intersects(desc->irq_common_data.affinity, in irq_setup_affinity()
502 set = desc->irq_common_data.affinity; in irq_setup_affinity()
504 irqd_clear(&desc->irq_data, IRQD_AFFINITY_SET); in irq_setup_affinity()
518 ret = irq_do_set_affinity(&desc->irq_data, &mask, false); in irq_setup_affinity()
523 /* Wrapper for ALPHA specific affinity selector magic */
533 * irq_set_vcpu_affinity - Set vcpu affinity for the interrupt
534 * @irq: interrupt number to set affinity
539 * affinity for an irq. The vCPU specific data is passed from
541 * KVM -> IOMMU -> irq_set_vcpu_affinity().
549 int ret = -ENOSYS; in irq_set_vcpu_affinity()
552 return -EINVAL; in irq_set_vcpu_affinity()
557 if (chip && chip->irq_set_vcpu_affinity) in irq_set_vcpu_affinity()
560 data = data->parent_data; in irq_set_vcpu_affinity()
567 ret = chip->irq_set_vcpu_affinity(data, vcpu_info); in irq_set_vcpu_affinity()
576 if (!desc->depth++) in __disable_irq()
586 return -EINVAL; in __disable_irq_nosync()
593 * disable_irq_nosync - disable an irq without waiting
594 * @irq: Interrupt to disable
596 * Disable the selected interrupt line. Disables and Enables are
610 * disable_irq - disable an irq and wait for completion
611 * @irq: Interrupt to disable
613 * Disable the selected interrupt line. Enables and Disables are
615 * This function waits for any pending IRQ handlers for this interrupt
619 * This function may be called - with care - from IRQ context.
629 * disable_hardirq - disables an irq and waits for hardirq completion
630 * @irq: Interrupt to disable
632 * Disable the selected interrupt line. Enables and Disables are
635 * interrupt to complete before returning. If you use this function while
638 * When used to optimistically disable an interrupt from atomic context
643 * This function may be called - with care - from IRQ context.
655 * disable_nmi_nosync - disable an nmi without waiting
656 * @irq: Interrupt to disable
658 * Disable the selected interrupt line. Disables and enables are
660 * The interrupt to disable must have been requested through request_nmi.
671 switch (desc->depth) { in __enable_irq()
678 if (desc->istate & IRQS_SUSPENDED) in __enable_irq()
684 * interrupt might be marked NOAUTOEN. So irq_startup() in __enable_irq()
693 desc->depth--; in __enable_irq()
698 * enable_irq - enable handling of an irq
699 * @irq: Interrupt to enable
703 * IRQ line is re-enabled.
706 * desc->irq_data.chip->bus_lock and desc->chip->bus_sync_unlock are NULL !
715 if (WARN(!desc->irq_data.chip, in enable_irq()
726 * enable_nmi - enable handling of an nmi
727 * @irq: Interrupt to enable
729 * The interrupt to enable must have been requested through request_nmi.
732 * IRQ line is re-enabled.
742 int ret = -ENXIO; in set_irq_wake_real()
744 if (irq_desc_get_chip(desc)->flags & IRQCHIP_SKIP_SET_WAKE) in set_irq_wake_real()
747 if (desc->irq_data.chip->irq_set_wake) in set_irq_wake_real()
748 ret = desc->irq_data.chip->irq_set_wake(&desc->irq_data, on); in set_irq_wake_real()
754 * irq_set_irq_wake - control irq power management wakeup
755 * @irq: interrupt to control
760 * just as they match for non-wakeup mode support.
779 return -EINVAL; in irq_set_irq_wake()
782 if (desc->istate & IRQS_NMI) { in irq_set_irq_wake()
783 ret = -EINVAL; in irq_set_irq_wake()
787 /* wakeup-capable irqs can be shared between drivers that in irq_set_irq_wake()
791 if (desc->wake_depth++ == 0) { in irq_set_irq_wake()
794 desc->wake_depth = 0; in irq_set_irq_wake()
796 irqd_set(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
799 if (desc->wake_depth == 0) { in irq_set_irq_wake()
801 } else if (--desc->wake_depth == 0) { in irq_set_irq_wake()
804 desc->wake_depth = 1; in irq_set_irq_wake()
806 irqd_clear(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
831 if (!desc->action || in can_request_irq()
832 irqflags & desc->action->flags & IRQF_SHARED) in can_request_irq()
841 struct irq_chip *chip = desc->irq_data.chip; in __irq_set_trigger()
844 if (!chip || !chip->irq_set_type) { in __irq_set_trigger()
847 * flow-types? in __irq_set_trigger()
851 chip ? (chip->name ? : "unknown") : "unknown"); in __irq_set_trigger()
855 if (chip->flags & IRQCHIP_SET_TYPE_MASKED) { in __irq_set_trigger()
856 if (!irqd_irq_masked(&desc->irq_data)) in __irq_set_trigger()
858 if (!irqd_irq_disabled(&desc->irq_data)) in __irq_set_trigger()
864 ret = chip->irq_set_type(&desc->irq_data, flags); in __irq_set_trigger()
869 irqd_clear(&desc->irq_data, IRQD_TRIGGER_MASK); in __irq_set_trigger()
870 irqd_set(&desc->irq_data, flags); in __irq_set_trigger()
874 flags = irqd_get_trigger_type(&desc->irq_data); in __irq_set_trigger()
876 irqd_clear(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
880 irqd_set(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
887 flags, irq_desc_get_irq(desc), chip->irq_set_type); in __irq_set_trigger()
901 return -EINVAL; in irq_set_parent()
903 desc->parent_irq = parent_irq; in irq_set_parent()
912 * Default primary interrupt handler for threaded interrupts. Is
945 &action->thread_flags)) { in irq_wait_for_interrupt()
950 return -1; in irq_wait_for_interrupt()
954 &action->thread_flags)) { in irq_wait_for_interrupt()
964 * handler finished. unmask if the interrupt has not been disabled and
970 if (!(desc->istate & IRQS_ONESHOT) || in irq_finalize_oneshot()
971 action->handler == irq_forced_secondary_handler) in irq_finalize_oneshot()
975 raw_spin_lock_irq(&desc->lock); in irq_finalize_oneshot()
981 * The thread is faster done than the hard interrupt handler in irq_finalize_oneshot()
983 * interrupt can come in again and masks the line, leaves due in irq_finalize_oneshot()
987 * versus "desc->threads_onehsot |= action->thread_mask;" in in irq_finalize_oneshot()
991 if (unlikely(irqd_irq_inprogress(&desc->irq_data))) { in irq_finalize_oneshot()
992 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1003 if (test_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_finalize_oneshot()
1006 desc->threads_oneshot &= ~action->thread_mask; in irq_finalize_oneshot()
1008 if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) && in irq_finalize_oneshot()
1009 irqd_irq_masked(&desc->irq_data)) in irq_finalize_oneshot()
1013 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1019 * Check whether we need to change the affinity of the interrupt thread.
1027 if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags)) in irq_thread_check_affinity()
1035 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_thread_check_affinity()
1039 raw_spin_lock_irq(&desc->lock); in irq_thread_check_affinity()
1041 * This code is triggered unconditionally. Check the affinity in irq_thread_check_affinity()
1044 if (cpumask_available(desc->irq_common_data.affinity)) { in irq_thread_check_affinity()
1047 m = irq_data_get_effective_affinity_mask(&desc->irq_data); in irq_thread_check_affinity()
1052 raw_spin_unlock_irq(&desc->lock); in irq_thread_check_affinity()
1075 ret = action->thread_fn(action->irq, action->dev_id); in irq_forced_thread_fn()
1077 atomic_inc(&desc->threads_handled); in irq_forced_thread_fn()
1086 * preemtible - many of them need to sleep and wait for slow busses to
1094 ret = action->thread_fn(action->irq, action->dev_id); in irq_thread_fn()
1096 atomic_inc(&desc->threads_handled); in irq_thread_fn()
1104 if (atomic_dec_and_test(&desc->threads_active)) in wake_threads_waitq()
1105 wake_up(&desc->wait_for_threads); in wake_threads_waitq()
1114 if (WARN_ON_ONCE(!(current->flags & PF_EXITING))) in irq_thread_dtor()
1120 tsk->comm, tsk->pid, action->irq); in irq_thread_dtor()
1123 desc = irq_to_desc(action->irq); in irq_thread_dtor()
1126 * desc->threads_active and wake possible waiters. in irq_thread_dtor()
1128 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_thread_dtor()
1131 /* Prevent a stale desc->threads_oneshot */ in irq_thread_dtor()
1137 struct irqaction *secondary = action->secondary; in irq_wake_secondary()
1142 raw_spin_lock_irq(&desc->lock); in irq_wake_secondary()
1144 raw_spin_unlock_irq(&desc->lock); in irq_wake_secondary()
1148 * Interrupt handler thread
1154 struct irq_desc *desc = irq_to_desc(action->irq); in irq_thread()
1159 &action->thread_flags)) in irq_thread()
1192 * irq_wake_thread - wake the irq thread for the action identified by dev_id
1193 * @irq: Interrupt line
1206 raw_spin_lock_irqsave(&desc->lock, flags); in irq_wake_thread()
1208 if (action->dev_id == dev_id) { in irq_wake_thread()
1209 if (action->thread) in irq_wake_thread()
1214 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_wake_thread()
1222 if (new->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT)) in irq_setup_forced_threading()
1229 if (new->handler == irq_default_primary_handler) in irq_setup_forced_threading()
1232 new->flags |= IRQF_ONESHOT; in irq_setup_forced_threading()
1239 if (new->handler && new->thread_fn) { in irq_setup_forced_threading()
1241 new->secondary = kzalloc(sizeof(struct irqaction), GFP_KERNEL); in irq_setup_forced_threading()
1242 if (!new->secondary) in irq_setup_forced_threading()
1243 return -ENOMEM; in irq_setup_forced_threading()
1244 new->secondary->handler = irq_forced_secondary_handler; in irq_setup_forced_threading()
1245 new->secondary->thread_fn = new->thread_fn; in irq_setup_forced_threading()
1246 new->secondary->dev_id = new->dev_id; in irq_setup_forced_threading()
1247 new->secondary->irq = new->irq; in irq_setup_forced_threading()
1248 new->secondary->name = new->name; in irq_setup_forced_threading()
1251 set_bit(IRQTF_FORCED_THREAD, &new->thread_flags); in irq_setup_forced_threading()
1252 new->thread_fn = new->handler; in irq_setup_forced_threading()
1253 new->handler = irq_default_primary_handler; in irq_setup_forced_threading()
1259 struct irq_data *d = &desc->irq_data; in irq_request_resources()
1260 struct irq_chip *c = d->chip; in irq_request_resources()
1262 return c->irq_request_resources ? c->irq_request_resources(d) : 0; in irq_request_resources()
1267 struct irq_data *d = &desc->irq_data; in irq_release_resources()
1268 struct irq_chip *c = d->chip; in irq_release_resources()
1270 if (c->irq_release_resources) in irq_release_resources()
1271 c->irq_release_resources(d); in irq_release_resources()
1280 if (d->parent_data) in irq_supports_nmi()
1284 if (d->chip->irq_bus_lock || d->chip->irq_bus_sync_unlock) in irq_supports_nmi()
1287 return d->chip->flags & IRQCHIP_SUPPORTS_NMI; in irq_supports_nmi()
1293 struct irq_chip *c = d->chip; in irq_nmi_setup()
1295 return c->irq_nmi_setup ? c->irq_nmi_setup(d) : -EINVAL; in irq_nmi_setup()
1301 struct irq_chip *c = d->chip; in irq_nmi_teardown()
1303 if (c->irq_nmi_teardown) in irq_nmi_teardown()
1304 c->irq_nmi_teardown(d); in irq_nmi_teardown()
1313 t = kthread_create(irq_thread, new, "irq/%d-%s", irq, in setup_irq_thread()
1314 new->name); in setup_irq_thread()
1316 t = kthread_create(irq_thread, new, "irq/%d-s-%s", irq, in setup_irq_thread()
1317 new->name); in setup_irq_thread()
1327 * the thread dies to avoid that the interrupt code in setup_irq_thread()
1330 new->thread = get_task_struct(t); in setup_irq_thread()
1332 * Tell the thread to set its affinity. This is in setup_irq_thread()
1333 * important for shared interrupt handlers as we do in setup_irq_thread()
1338 * on which the requesting code placed the interrupt. in setup_irq_thread()
1340 set_bit(IRQTF_AFFINITY, &new->thread_flags); in setup_irq_thread()
1345 * Internal function to register an irqaction - typically used to
1350 * desc->request_mutex Provides serialization against a concurrent free_irq()
1352 * desc->lock Provides serialization against hard interrupts
1354 * chip_bus_lock and desc->lock are sufficient for all other management and
1355 * interrupt related functions. desc->request_mutex solely serializes
1366 return -EINVAL; in __setup_irq()
1368 if (desc->irq_data.chip == &no_irq_chip) in __setup_irq()
1369 return -ENOSYS; in __setup_irq()
1370 if (!try_module_get(desc->owner)) in __setup_irq()
1371 return -ENODEV; in __setup_irq()
1373 new->irq = irq; in __setup_irq()
1377 * then use the default for this interrupt. in __setup_irq()
1379 if (!(new->flags & IRQF_TRIGGER_MASK)) in __setup_irq()
1380 new->flags |= irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1383 * Check whether the interrupt nests into another interrupt in __setup_irq()
1388 if (!new->thread_fn) { in __setup_irq()
1389 ret = -EINVAL; in __setup_irq()
1394 * the driver for non nested interrupt handling by the in __setup_irq()
1397 new->handler = irq_nested_primary_handler; in __setup_irq()
1408 * and the interrupt does not nest into another interrupt in __setup_irq()
1411 if (new->thread_fn && !nested) { in __setup_irq()
1415 if (new->secondary) { in __setup_irq()
1416 ret = setup_irq_thread(new->secondary, irq, true); in __setup_irq()
1431 if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) in __setup_irq()
1432 new->flags &= ~IRQF_ONESHOT; in __setup_irq()
1437 * chip bus lock and desc->lock. Also protects against handing out in __setup_irq()
1441 mutex_lock(&desc->request_mutex); in __setup_irq()
1451 if (!desc->action) { in __setup_irq()
1455 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1462 * protected against a concurrent interrupt and any of the other in __setup_irq()
1464 * desc->request_mutex or the optional bus lock. in __setup_irq()
1466 raw_spin_lock_irqsave(&desc->lock, flags); in __setup_irq()
1467 old_ptr = &desc->action; in __setup_irq()
1476 * Interrupt lines used for NMIs cannot be shared. in __setup_irq()
1480 if (desc->istate & IRQS_NMI) { in __setup_irq()
1482 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1483 ret = -EINVAL; in __setup_irq()
1491 if (irqd_trigger_type_was_set(&desc->irq_data)) { in __setup_irq()
1492 oldtype = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1494 oldtype = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1495 irqd_set_trigger_type(&desc->irq_data, oldtype); in __setup_irq()
1498 if (!((old->flags & new->flags) & IRQF_SHARED) || in __setup_irq()
1499 (oldtype != (new->flags & IRQF_TRIGGER_MASK)) || in __setup_irq()
1500 ((old->flags ^ new->flags) & IRQF_ONESHOT)) in __setup_irq()
1503 /* All handlers must agree on per-cpuness */ in __setup_irq()
1504 if ((old->flags & IRQF_PERCPU) != in __setup_irq()
1505 (new->flags & IRQF_PERCPU)) in __setup_irq()
1508 /* add new interrupt at end of irq queue */ in __setup_irq()
1511 * Or all existing action->thread_mask bits, in __setup_irq()
1515 thread_mask |= old->thread_mask; in __setup_irq()
1516 old_ptr = &old->next; in __setup_irq()
1527 if (new->flags & IRQF_ONESHOT) { in __setup_irq()
1533 ret = -EBUSY; in __setup_irq()
1538 * desc->thread_active to indicate that the in __setup_irq()
1541 * completes. When all threads of a shared interrupt in __setup_irq()
1542 * line have completed desc->threads_active becomes in __setup_irq()
1543 * zero and the interrupt line is unmasked. See in __setup_irq()
1547 * interrupt handlers, then desc->threads_active is in __setup_irq()
1554 * all existing action->thread_mask bits. in __setup_irq()
1556 new->thread_mask = 1UL << ffz(thread_mask); in __setup_irq()
1558 } else if (new->handler == irq_default_primary_handler && in __setup_irq()
1559 !(desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)) { in __setup_irq()
1561 * The interrupt was requested with handler = NULL, so in __setup_irq()
1571 * say for sure which type this interrupt really in __setup_irq()
1576 new->name, irq); in __setup_irq()
1577 ret = -EINVAL; in __setup_irq()
1582 init_waitqueue_head(&desc->wait_for_threads); in __setup_irq()
1585 if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1587 new->flags & IRQF_TRIGGER_MASK); in __setup_irq()
1594 * Activate the interrupt. That activation must happen in __setup_irq()
1597 * that. enable_irq() of an interrupt requested with in __setup_irq()
1608 desc->istate &= ~(IRQS_AUTODETECT | IRQS_SPURIOUS_DISABLED | \ in __setup_irq()
1610 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); in __setup_irq()
1612 if (new->flags & IRQF_PERCPU) { in __setup_irq()
1613 irqd_set(&desc->irq_data, IRQD_PER_CPU); in __setup_irq()
1617 if (new->flags & IRQF_ONESHOT) in __setup_irq()
1618 desc->istate |= IRQS_ONESHOT; in __setup_irq()
1621 if (new->flags & IRQF_NOBALANCING) { in __setup_irq()
1623 irqd_set(&desc->irq_data, IRQD_NO_BALANCING); in __setup_irq()
1631 * auto enable. The sharing interrupt might request in __setup_irq()
1635 WARN_ON_ONCE(new->flags & IRQF_SHARED); in __setup_irq()
1637 desc->depth = 1; in __setup_irq()
1640 } else if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1641 unsigned int nmsk = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1642 unsigned int omsk = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1655 desc->irq_count = 0; in __setup_irq()
1656 desc->irqs_unhandled = 0; in __setup_irq()
1662 if (shared && (desc->istate & IRQS_SPURIOUS_DISABLED)) { in __setup_irq()
1663 desc->istate &= ~IRQS_SPURIOUS_DISABLED; in __setup_irq()
1667 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1669 mutex_unlock(&desc->request_mutex); in __setup_irq()
1675 * when no hard interrupt wakes the thread up. in __setup_irq()
1677 if (new->thread) in __setup_irq()
1678 wake_up_process(new->thread); in __setup_irq()
1679 if (new->secondary) in __setup_irq()
1680 wake_up_process(new->secondary->thread); in __setup_irq()
1683 new->dir = NULL; in __setup_irq()
1688 if (!(new->flags & IRQF_PROBE_SHARED)) { in __setup_irq()
1690 irq, new->flags, new->name, old->flags, old->name); in __setup_irq()
1695 ret = -EBUSY; in __setup_irq()
1698 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1700 if (!desc->action) in __setup_irq()
1704 mutex_unlock(&desc->request_mutex); in __setup_irq()
1707 if (new->thread) { in __setup_irq()
1708 struct task_struct *t = new->thread; in __setup_irq()
1710 new->thread = NULL; in __setup_irq()
1714 if (new->secondary && new->secondary->thread) { in __setup_irq()
1715 struct task_struct *t = new->secondary->thread; in __setup_irq()
1717 new->secondary->thread = NULL; in __setup_irq()
1722 module_put(desc->owner); in __setup_irq()
1727 * Internal function to unregister an irqaction - used to free
1732 unsigned irq = desc->irq_data.irq; in __free_irq()
1738 mutex_lock(&desc->request_mutex); in __free_irq()
1740 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1746 action_ptr = &desc->action; in __free_irq()
1751 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_irq()
1752 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1754 mutex_unlock(&desc->request_mutex); in __free_irq()
1758 if (action->dev_id == dev_id) in __free_irq()
1760 action_ptr = &action->next; in __free_irq()
1763 /* Found it - now remove it from the list of entries: */ in __free_irq()
1764 *action_ptr = action->next; in __free_irq()
1769 if (!desc->action) { in __free_irq()
1777 if (WARN_ON_ONCE(desc->affinity_hint)) in __free_irq()
1778 desc->affinity_hint = NULL; in __free_irq()
1781 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1792 * The still held desc->request_mutex() protects against a in __free_irq()
1803 * interrupt in flight at the hardware level. in __free_irq()
1809 * It's a shared IRQ -- the driver ought to be prepared for an IRQ in __free_irq()
1816 if (action->flags & IRQF_SHARED) { in __free_irq()
1818 action->handler(irq, dev_id); in __free_irq()
1829 if (action->thread) { in __free_irq()
1830 kthread_stop(action->thread); in __free_irq()
1831 put_task_struct(action->thread); in __free_irq()
1832 if (action->secondary && action->secondary->thread) { in __free_irq()
1833 kthread_stop(action->secondary->thread); in __free_irq()
1834 put_task_struct(action->secondary->thread); in __free_irq()
1839 if (!desc->action) { in __free_irq()
1846 * There is no interrupt on the fly anymore. Deactivate it in __free_irq()
1849 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1850 irq_domain_deactivate_irq(&desc->irq_data); in __free_irq()
1851 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1858 mutex_unlock(&desc->request_mutex); in __free_irq()
1860 irq_chip_pm_put(&desc->irq_data); in __free_irq()
1861 module_put(desc->owner); in __free_irq()
1862 kfree(action->secondary); in __free_irq()
1867 * free_irq - free an interrupt allocated with request_irq
1868 * @irq: Interrupt line to free
1871 * Remove an interrupt handler. The handler is removed and if the
1872 * interrupt line is no longer in use by any driver it is disabled.
1873 * On a shared IRQ the caller must ensure the interrupt is disabled
1878 * This function must not be called from interrupt context.
1892 if (WARN_ON(desc->affinity_notify)) in free_irq()
1893 desc->affinity_notify = NULL; in free_irq()
1901 devname = action->name; in free_irq()
1907 /* This function must be called with desc->lock held */
1912 desc->istate &= ~IRQS_NMI; in __cleanup_nmi()
1914 if (!WARN_ON(desc->action == NULL)) { in __cleanup_nmi()
1915 irq_pm_remove_action(desc, desc->action); in __cleanup_nmi()
1916 devname = desc->action->name; in __cleanup_nmi()
1917 unregister_handler_proc(irq, desc->action); in __cleanup_nmi()
1919 kfree(desc->action); in __cleanup_nmi()
1920 desc->action = NULL; in __cleanup_nmi()
1928 irq_chip_pm_put(&desc->irq_data); in __cleanup_nmi()
1929 module_put(desc->owner); in __cleanup_nmi()
1940 if (!desc || WARN_ON(!(desc->istate & IRQS_NMI))) in free_nmi()
1947 if (WARN_ON(desc->depth == 0)) in free_nmi()
1950 raw_spin_lock_irqsave(&desc->lock, flags); in free_nmi()
1955 raw_spin_unlock_irqrestore(&desc->lock, flags); in free_nmi()
1961 * request_threaded_irq - allocate an interrupt line
1962 * @irq: Interrupt line to allocate
1969 * @irqflags: Interrupt type flags
1973 * This call allocates interrupt resources and enables the
1974 * interrupt line and IRQ handling. From the point this
1976 * your handler function must clear any interrupt the board
1978 * and to set up the interrupt handler in the right order.
1982 * still called in hard interrupt context and has to check
1983 * whether the interrupt originates from the device. If yes it
1984 * needs to disable the interrupt on the device and return
1993 * If your interrupt is shared you must pass a non NULL dev_id
1994 * as this is required when freeing the interrupt.
1998 * IRQF_SHARED Interrupt is shared
2011 return -ENOTCONN; in request_threaded_irq()
2014 * Sanity-check: shared interrupts must pass in a real dev-ID, in request_threaded_irq()
2016 * which interrupt is which (messes up the interrupt freeing in request_threaded_irq()
2025 return -EINVAL; in request_threaded_irq()
2029 return -EINVAL; in request_threaded_irq()
2033 return -EINVAL; in request_threaded_irq()
2037 return -EINVAL; in request_threaded_irq()
2043 return -ENOMEM; in request_threaded_irq()
2045 action->handler = handler; in request_threaded_irq()
2046 action->thread_fn = thread_fn; in request_threaded_irq()
2047 action->flags = irqflags; in request_threaded_irq()
2048 action->name = devname; in request_threaded_irq()
2049 action->dev_id = dev_id; in request_threaded_irq()
2051 retval = irq_chip_pm_get(&desc->irq_data); in request_threaded_irq()
2060 irq_chip_pm_put(&desc->irq_data); in request_threaded_irq()
2061 kfree(action->secondary); in request_threaded_irq()
2068 * It's a shared IRQ -- the driver ought to be prepared for it in request_threaded_irq()
2089 * request_any_context_irq - allocate an interrupt line
2090 * @irq: Interrupt line to allocate
2093 * @flags: Interrupt type flags
2097 * This call allocates interrupt resources and enables the
2098 * interrupt line and IRQ handling. It selects either a
2112 return -ENOTCONN; in request_any_context_irq()
2116 return -EINVAL; in request_any_context_irq()
2130 * request_nmi - allocate an interrupt line for NMI delivery
2131 * @irq: Interrupt line to allocate
2134 * @irqflags: Interrupt type flags
2138 * This call allocates interrupt resources and enables the
2139 * interrupt line and IRQ handling. It sets up the IRQ line
2142 * An interrupt line delivering NMIs cannot be shared and IRQ handling
2145 * Interrupt lines requested for NMI delivering must produce per cpu
2152 * If the interrupt line cannot be used to deliver NMIs, function
2164 return -ENOTCONN; in request_nmi()
2168 return -EINVAL; in request_nmi()
2171 return -EINVAL; in request_nmi()
2174 return -EINVAL; in request_nmi()
2182 return -EINVAL; in request_nmi()
2186 return -ENOMEM; in request_nmi()
2188 action->handler = handler; in request_nmi()
2189 action->flags = irqflags | IRQF_NO_THREAD | IRQF_NOBALANCING; in request_nmi()
2190 action->name = name; in request_nmi()
2191 action->dev_id = dev_id; in request_nmi()
2193 retval = irq_chip_pm_get(&desc->irq_data); in request_nmi()
2201 raw_spin_lock_irqsave(&desc->lock, flags); in request_nmi()
2204 desc->istate |= IRQS_NMI; in request_nmi()
2208 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2209 return -EINVAL; in request_nmi()
2212 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2217 irq_chip_pm_put(&desc->irq_data); in request_nmi()
2235 * use the default for this interrupt. in enable_percpu_irq()
2239 type = irqd_get_trigger_type(&desc->irq_data); in enable_percpu_irq()
2264 * irq_percpu_is_enabled - Check whether the per cpu irq is enabled
2268 * state of a per cpu interrupt on the current cpu.
2281 is_enabled = cpumask_test_cpu(cpu, desc->percpu_enabled); in irq_percpu_is_enabled()
2321 raw_spin_lock_irqsave(&desc->lock, flags); in __free_percpu_irq()
2323 action = desc->action; in __free_percpu_irq()
2324 if (!action || action->percpu_dev_id != dev_id) { in __free_percpu_irq()
2325 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_percpu_irq()
2329 if (!cpumask_empty(desc->percpu_enabled)) { in __free_percpu_irq()
2331 irq, cpumask_first(desc->percpu_enabled)); in __free_percpu_irq()
2335 /* Found it - now remove it from the list of entries: */ in __free_percpu_irq()
2336 desc->action = NULL; in __free_percpu_irq()
2338 desc->istate &= ~IRQS_NMI; in __free_percpu_irq()
2340 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2344 irq_chip_pm_put(&desc->irq_data); in __free_percpu_irq()
2345 module_put(desc->owner); in __free_percpu_irq()
2349 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2354 * remove_percpu_irq - free a per-cpu interrupt
2355 * @irq: Interrupt line to free
2356 * @act: irqaction for the interrupt
2365 __free_percpu_irq(irq, act->percpu_dev_id); in remove_percpu_irq()
2369 * free_percpu_irq - free an interrupt allocated with request_percpu_irq
2370 * @irq: Interrupt line to free
2373 * Remove a percpu interrupt handler. The handler is removed, but
2374 * the interrupt line is not disabled. This must be done on each
2378 * This function must not be called from interrupt context.
2400 if (WARN_ON(!(desc->istate & IRQS_NMI))) in free_percpu_nmi()
2407 * setup_percpu_irq - setup a per-cpu interrupt
2408 * @irq: Interrupt line to setup
2409 * @act: irqaction for the interrupt
2411 * Used to statically setup per-cpu interrupts in the early boot process.
2419 return -EINVAL; in setup_percpu_irq()
2421 retval = irq_chip_pm_get(&desc->irq_data); in setup_percpu_irq()
2428 irq_chip_pm_put(&desc->irq_data); in setup_percpu_irq()
2434 * __request_percpu_irq - allocate a percpu interrupt line
2435 * @irq: Interrupt line to allocate
2437 * @flags: Interrupt type flags (IRQF_TIMER only)
2441 * This call allocates interrupt resources and enables the
2442 * interrupt on the local CPU. If the interrupt is supposed to be
2446 * Dev_id must be globally unique. It is a per-cpu variable, and
2459 return -EINVAL; in __request_percpu_irq()
2464 return -EINVAL; in __request_percpu_irq()
2467 return -EINVAL; in __request_percpu_irq()
2471 return -ENOMEM; in __request_percpu_irq()
2473 action->handler = handler; in __request_percpu_irq()
2474 action->flags = flags | IRQF_PERCPU | IRQF_NO_SUSPEND; in __request_percpu_irq()
2475 action->name = devname; in __request_percpu_irq()
2476 action->percpu_dev_id = dev_id; in __request_percpu_irq()
2478 retval = irq_chip_pm_get(&desc->irq_data); in __request_percpu_irq()
2487 irq_chip_pm_put(&desc->irq_data); in __request_percpu_irq()
2496 * request_percpu_nmi - allocate a percpu interrupt line for NMI delivery
2497 * @irq: Interrupt line to allocate
2502 * This call allocates interrupt resources for a per CPU NMI. Per CPU NMIs
2506 * Dev_id must be globally unique. It is a per-cpu variable, and
2510 * Interrupt lines requested for NMI delivering should have auto enabling
2513 * If the interrupt line cannot be used to deliver NMIs, function
2525 return -EINVAL; in request_percpu_nmi()
2533 return -EINVAL; in request_percpu_nmi()
2536 if (desc->istate & IRQS_NMI) in request_percpu_nmi()
2537 return -EINVAL; in request_percpu_nmi()
2541 return -ENOMEM; in request_percpu_nmi()
2543 action->handler = handler; in request_percpu_nmi()
2544 action->flags = IRQF_PERCPU | IRQF_NO_SUSPEND | IRQF_NO_THREAD in request_percpu_nmi()
2546 action->name = name; in request_percpu_nmi()
2547 action->percpu_dev_id = dev_id; in request_percpu_nmi()
2549 retval = irq_chip_pm_get(&desc->irq_data); in request_percpu_nmi()
2557 raw_spin_lock_irqsave(&desc->lock, flags); in request_percpu_nmi()
2558 desc->istate |= IRQS_NMI; in request_percpu_nmi()
2559 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_percpu_nmi()
2564 irq_chip_pm_put(&desc->irq_data); in request_percpu_nmi()
2572 * prepare_percpu_nmi - performs CPU local setup for NMI delivery
2573 * @irq: Interrupt line to prepare for NMI delivery
2575 * This call prepares an interrupt line to deliver NMI on the current CPU,
2576 * before that interrupt line gets enabled with enable_percpu_nmi().
2578 * As a CPU local operation, this should be called from non-preemptible
2581 * If the interrupt line cannot be used to deliver NMIs, function
2595 return -EINVAL; in prepare_percpu_nmi()
2597 if (WARN(!(desc->istate & IRQS_NMI), in prepare_percpu_nmi()
2598 KERN_ERR "prepare_percpu_nmi called for a non-NMI interrupt: irq %u\n", in prepare_percpu_nmi()
2600 ret = -EINVAL; in prepare_percpu_nmi()
2616 * teardown_percpu_nmi - undoes NMI setup of IRQ line
2617 * @irq: Interrupt line from which CPU local NMI configuration should be
2624 * As a CPU local operation, this should be called from non-preemptible
2639 if (WARN_ON(!(desc->istate & IRQS_NMI))) in teardown_percpu_nmi()
2651 int err = -EINVAL; in __irq_get_irqchip_state()
2656 return -ENODEV; in __irq_get_irqchip_state()
2657 if (chip->irq_get_irqchip_state) in __irq_get_irqchip_state()
2660 data = data->parent_data; in __irq_get_irqchip_state()
2667 err = chip->irq_get_irqchip_state(data, which, state); in __irq_get_irqchip_state()
2672 * irq_get_irqchip_state - returns the irqchip state of a interrupt.
2673 * @irq: Interrupt line that is forwarded to a VM
2678 * interrupt, returning into @state the bit corresponding to
2682 * interrupt controller has per-cpu registers.
2690 int err = -EINVAL; in irq_get_irqchip_state()
2706 * irq_set_irqchip_state - set the state of a forwarded interrupt.
2707 * @irq: Interrupt line that is forwarded to a VM
2711 * This call sets the internal irqchip state of an interrupt,
2715 * interrupt controller has per-cpu registers.
2724 int err = -EINVAL; in irq_set_irqchip_state()
2735 err = -ENODEV; in irq_set_irqchip_state()
2738 if (chip->irq_set_irqchip_state) in irq_set_irqchip_state()
2741 data = data->parent_data; in irq_set_irqchip_state()
2748 err = chip->irq_set_irqchip_state(data, which, val); in irq_set_irqchip_state()