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>
50 while (irqd_irq_inprogress(&desc->irq_data)) in __synchronize_hardirq()
53 /* Ok, that indicated we're done: double-check carefully. */ in __synchronize_hardirq()
54 raw_spin_lock_irqsave(&desc->lock, flags); in __synchronize_hardirq()
55 inprogress = irqd_irq_inprogress(&desc->irq_data); in __synchronize_hardirq()
70 raw_spin_unlock_irqrestore(&desc->lock, flags); in __synchronize_hardirq()
77 * synchronize_hardirq - wait for pending hard IRQ handlers (on other CPUs)
78 * @irq: interrupt number to wait for
81 * interrupt to complete before returning. If you use this
91 * This function may be called - with care - from IRQ context.
93 * It does not check whether there is an interrupt in flight at the
95 * called with interrupts disabled and the target CPU of the interrupt
104 return !atomic_read(&desc->threads_active); in synchronize_hardirq()
112 * synchronize_irq - wait for pending IRQ handlers (on other CPUs)
113 * @irq: interrupt number to wait for
115 * This function waits for any pending IRQ handlers for this interrupt
120 * an interrupt thread is associated to @irq.
123 * that the interrupt is not pending in any CPU and waiting for
137 wait_event(desc->wait_for_threads, in synchronize_irq()
138 !atomic_read(&desc->threads_active)); in synchronize_irq()
148 if (!desc || !irqd_can_balance(&desc->irq_data) || in __irq_can_set_affinity()
149 !desc->irq_data.chip || !desc->irq_data.chip->irq_set_affinity) in __irq_can_set_affinity()
155 * irq_can_set_affinity - Check if the affinity of a given irq can be set
156 * @irq: Interrupt to check
165 * irq_can_set_affinity_usr - Check if affinity of a irq can be set from user space
166 * @irq: Interrupt to check
176 !irqd_affinity_is_managed(&desc->irq_data); in irq_can_set_affinity_usr()
180 * irq_set_thread_affinity - Notify irq threads to adjust affinity
181 * @desc: irq descriptor which has affinity changed
183 * We just set IRQTF_AFFINITY and delegate the affinity setting
184 * to the interrupt thread itself. We can not call
185 * set_cpus_allowed_ptr() here as we hold desc->lock and this
186 * code can be called from hard interrupt context.
193 if (action->thread) in irq_set_thread_affinity()
194 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_set_thread_affinity()
205 pr_warn_once("irq_chip %s did not update eff. affinity mask of irq %u\n", in irq_validate_effective_affinity()
206 chip->name, data->irq); in irq_validate_effective_affinity()
227 if (!chip || !chip->irq_set_affinity) in irq_do_set_affinity()
228 return -EINVAL; in irq_do_set_affinity()
231 * If this is a managed interrupt and housekeeping is enabled on in irq_do_set_affinity()
232 * it check whether the requested affinity mask intersects with in irq_do_set_affinity()
235 * the affinity setter from routing the interrupt to an isolated in irq_do_set_affinity()
244 * If all housekeeping CPUs in the affinity mask are offline, the in irq_do_set_affinity()
245 * interrupt will be migrated by the CPU hotplug code once a in irq_do_set_affinity()
246 * housekeeping CPU which belongs to the affinity mask comes in irq_do_set_affinity()
264 ret = chip->irq_set_affinity(data, prog_mask, force); in irq_do_set_affinity()
267 ret = chip->irq_set_affinity(data, mask, force); in irq_do_set_affinity()
272 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_do_set_affinity()
297 return -EBUSY; in irq_set_affinity_pending()
311 if (ret == -EBUSY && !force) in irq_try_set_affinity()
322 * Handle irq chips which can handle affinity only in activated in irq_set_affinity_deactivated()
325 * If the interrupt is not yet activated, just store the affinity in irq_set_affinity_deactivated()
327 * driver has to make sure anyway that the interrupt is in a in irq_set_affinity_deactivated()
334 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_set_affinity_deactivated()
347 if (!chip || !chip->irq_set_affinity) in irq_set_affinity_locked()
348 return -EINVAL; in irq_set_affinity_locked()
360 if (desc->affinity_notify) { in irq_set_affinity_locked()
361 kref_get(&desc->affinity_notify->kref); in irq_set_affinity_locked()
362 if (!schedule_work(&desc->affinity_notify->work)) { in irq_set_affinity_locked()
364 kref_put(&desc->affinity_notify->kref, in irq_set_affinity_locked()
365 desc->affinity_notify->release); in irq_set_affinity_locked()
374 * irq_update_affinity_desc - Update affinity management for an interrupt
375 * @irq: The interrupt number to update
376 * @affinity: Pointer to the affinity descriptor
378 * This interface can be used to configure the affinity management of
381 * There are certain limitations on when it may be used - attempts to use it
384 * managed/non-managed interrupt accounting. In addition, attempts to use it on
385 * an interrupt which is already started or which has already been configured
389 struct irq_affinity_desc *affinity) in irq_update_affinity_desc() argument
401 return -EOPNOTSUPP; in irq_update_affinity_desc()
405 return -EINVAL; in irq_update_affinity_desc()
407 /* Requires the interrupt to be shut down */ in irq_update_affinity_desc()
408 if (irqd_is_started(&desc->irq_data)) { in irq_update_affinity_desc()
409 ret = -EBUSY; in irq_update_affinity_desc()
414 if (irqd_affinity_is_managed(&desc->irq_data)) { in irq_update_affinity_desc()
415 ret = -EBUSY; in irq_update_affinity_desc()
420 * Deactivate the interrupt. That's required to undo in irq_update_affinity_desc()
423 activated = irqd_is_activated(&desc->irq_data); in irq_update_affinity_desc()
425 irq_domain_deactivate_irq(&desc->irq_data); in irq_update_affinity_desc()
427 if (affinity->is_managed) { in irq_update_affinity_desc()
428 irqd_set(&desc->irq_data, IRQD_AFFINITY_MANAGED); in irq_update_affinity_desc()
429 irqd_set(&desc->irq_data, IRQD_MANAGED_SHUTDOWN); in irq_update_affinity_desc()
432 cpumask_copy(desc->irq_common_data.affinity, &affinity->mask); in irq_update_affinity_desc()
436 irq_domain_activate_irq(&desc->irq_data, false); in irq_update_affinity_desc()
451 return -EINVAL; in __irq_set_affinity()
453 raw_spin_lock_irqsave(&desc->lock, flags); in __irq_set_affinity()
455 raw_spin_unlock_irqrestore(&desc->lock, flags); in __irq_set_affinity()
460 * irq_set_affinity - Set the irq affinity of a given irq
461 * @irq: Interrupt to set affinity
473 * irq_force_affinity - Force the irq affinity of a given irq
474 * @irq: Interrupt to set affinity
495 return -EINVAL; in irq_set_affinity_hint()
496 desc->affinity_hint = m; in irq_set_affinity_hint()
498 /* set the initial affinity to prevent every interrupt being on CPU0 */ in irq_set_affinity_hint()
509 struct irq_desc *desc = irq_to_desc(notify->irq); in irq_affinity_notify()
516 raw_spin_lock_irqsave(&desc->lock, flags); in irq_affinity_notify()
517 if (irq_move_pending(&desc->irq_data)) in irq_affinity_notify()
520 cpumask_copy(cpumask, desc->irq_common_data.affinity); in irq_affinity_notify()
521 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_affinity_notify()
523 notify->notify(notify, cpumask); in irq_affinity_notify()
527 kref_put(¬ify->kref, notify->release); in irq_affinity_notify()
531 * irq_set_affinity_notifier - control notification of IRQ affinity changes
532 * @irq: Interrupt for which to enable/disable notification
551 if (!desc || desc->istate & IRQS_NMI) in irq_set_affinity_notifier()
552 return -EINVAL; in irq_set_affinity_notifier()
556 notify->irq = irq; in irq_set_affinity_notifier()
557 kref_init(¬ify->kref); in irq_set_affinity_notifier()
558 INIT_WORK(¬ify->work, irq_affinity_notify); in irq_set_affinity_notifier()
561 raw_spin_lock_irqsave(&desc->lock, flags); in irq_set_affinity_notifier()
562 old_notify = desc->affinity_notify; in irq_set_affinity_notifier()
563 desc->affinity_notify = notify; in irq_set_affinity_notifier()
564 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_set_affinity_notifier()
567 if (cancel_work_sync(&old_notify->work)) { in irq_set_affinity_notifier()
569 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
571 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
580 * Generic version of the affinity autoselector.
595 * Preserve the managed affinity setting and a userspace affinity in irq_setup_affinity()
598 if (irqd_affinity_is_managed(&desc->irq_data) || in irq_setup_affinity()
599 irqd_has_set(&desc->irq_data, IRQD_AFFINITY_SET)) { in irq_setup_affinity()
600 if (cpumask_intersects(desc->irq_common_data.affinity, in irq_setup_affinity()
602 set = desc->irq_common_data.affinity; in irq_setup_affinity()
604 irqd_clear(&desc->irq_data, IRQD_AFFINITY_SET); in irq_setup_affinity()
618 ret = irq_do_set_affinity(&desc->irq_data, &mask, false); in irq_setup_affinity()
623 /* Wrapper for ALPHA specific affinity selector magic */
633 * irq_set_vcpu_affinity - Set vcpu affinity for the interrupt
634 * @irq: interrupt number to set affinity
639 * affinity for an irq. The vCPU specific data is passed from
641 * KVM -> IOMMU -> irq_set_vcpu_affinity().
649 int ret = -ENOSYS; in irq_set_vcpu_affinity()
652 return -EINVAL; in irq_set_vcpu_affinity()
657 if (chip && chip->irq_set_vcpu_affinity) in irq_set_vcpu_affinity()
660 data = data->parent_data; in irq_set_vcpu_affinity()
667 ret = chip->irq_set_vcpu_affinity(data, vcpu_info); in irq_set_vcpu_affinity()
676 if (!desc->depth++) in __disable_irq()
686 return -EINVAL; in __disable_irq_nosync()
693 * disable_irq_nosync - disable an irq without waiting
694 * @irq: Interrupt to disable
696 * Disable the selected interrupt line. Disables and Enables are
710 * disable_irq - disable an irq and wait for completion
711 * @irq: Interrupt to disable
713 * Disable the selected interrupt line. Enables and Disables are
715 * This function waits for any pending IRQ handlers for this interrupt
719 * This function may be called - with care - from IRQ context.
729 * disable_hardirq - disables an irq and waits for hardirq completion
730 * @irq: Interrupt to disable
732 * Disable the selected interrupt line. Enables and Disables are
735 * interrupt to complete before returning. If you use this function while
738 * When used to optimistically disable an interrupt from atomic context
743 * This function may be called - with care - from IRQ context.
755 * disable_nmi_nosync - disable an nmi without waiting
756 * @irq: Interrupt to disable
758 * Disable the selected interrupt line. Disables and enables are
760 * The interrupt to disable must have been requested through request_nmi.
771 switch (desc->depth) { in __enable_irq()
778 if (desc->istate & IRQS_SUSPENDED) in __enable_irq()
784 * interrupt might be marked NOAUTOEN. So irq_startup() in __enable_irq()
793 desc->depth--; in __enable_irq()
798 * enable_irq - enable handling of an irq
799 * @irq: Interrupt to enable
803 * IRQ line is re-enabled.
806 * desc->irq_data.chip->bus_lock and desc->chip->bus_sync_unlock are NULL !
815 if (WARN(!desc->irq_data.chip, in enable_irq()
826 * enable_nmi - enable handling of an nmi
827 * @irq: Interrupt to enable
829 * The interrupt to enable must have been requested through request_nmi.
832 * IRQ line is re-enabled.
842 int ret = -ENXIO; in set_irq_wake_real()
844 if (irq_desc_get_chip(desc)->flags & IRQCHIP_SKIP_SET_WAKE) in set_irq_wake_real()
847 if (desc->irq_data.chip->irq_set_wake) in set_irq_wake_real()
848 ret = desc->irq_data.chip->irq_set_wake(&desc->irq_data, on); in set_irq_wake_real()
854 * irq_set_irq_wake - control irq power management wakeup
855 * @irq: interrupt to control
860 * just as they match for non-wakeup mode support.
879 return -EINVAL; in irq_set_irq_wake()
882 if (desc->istate & IRQS_NMI) { in irq_set_irq_wake()
883 ret = -EINVAL; in irq_set_irq_wake()
887 /* wakeup-capable irqs can be shared between drivers that in irq_set_irq_wake()
891 if (desc->wake_depth++ == 0) { in irq_set_irq_wake()
894 desc->wake_depth = 0; in irq_set_irq_wake()
896 irqd_set(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
899 if (desc->wake_depth == 0) { in irq_set_irq_wake()
901 } else if (--desc->wake_depth == 0) { in irq_set_irq_wake()
904 desc->wake_depth = 1; in irq_set_irq_wake()
906 irqd_clear(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
931 if (!desc->action || in can_request_irq()
932 irqflags & desc->action->flags & IRQF_SHARED) in can_request_irq()
941 struct irq_chip *chip = desc->irq_data.chip; in __irq_set_trigger()
944 if (!chip || !chip->irq_set_type) { in __irq_set_trigger()
947 * flow-types? in __irq_set_trigger()
951 chip ? (chip->name ? : "unknown") : "unknown"); in __irq_set_trigger()
955 if (chip->flags & IRQCHIP_SET_TYPE_MASKED) { in __irq_set_trigger()
956 if (!irqd_irq_masked(&desc->irq_data)) in __irq_set_trigger()
958 if (!irqd_irq_disabled(&desc->irq_data)) in __irq_set_trigger()
964 ret = chip->irq_set_type(&desc->irq_data, flags); in __irq_set_trigger()
969 irqd_clear(&desc->irq_data, IRQD_TRIGGER_MASK); in __irq_set_trigger()
970 irqd_set(&desc->irq_data, flags); in __irq_set_trigger()
974 flags = irqd_get_trigger_type(&desc->irq_data); in __irq_set_trigger()
976 irqd_clear(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
980 irqd_set(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
987 flags, irq_desc_get_irq(desc), chip->irq_set_type); in __irq_set_trigger()
1001 return -EINVAL; in irq_set_parent()
1003 desc->parent_irq = parent_irq; in irq_set_parent()
1012 * Default primary interrupt handler for threaded interrupts. Is
1045 &action->thread_flags)) { in irq_wait_for_interrupt()
1050 return -1; in irq_wait_for_interrupt()
1054 &action->thread_flags)) { in irq_wait_for_interrupt()
1064 * handler finished. unmask if the interrupt has not been disabled and
1070 if (!(desc->istate & IRQS_ONESHOT) || in irq_finalize_oneshot()
1071 action->handler == irq_forced_secondary_handler) in irq_finalize_oneshot()
1075 raw_spin_lock_irq(&desc->lock); in irq_finalize_oneshot()
1081 * The thread is faster done than the hard interrupt handler in irq_finalize_oneshot()
1083 * interrupt can come in again and masks the line, leaves due in irq_finalize_oneshot()
1087 * versus "desc->threads_oneshot |= action->thread_mask;" in in irq_finalize_oneshot()
1091 if (unlikely(irqd_irq_inprogress(&desc->irq_data))) { in irq_finalize_oneshot()
1092 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1103 if (test_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_finalize_oneshot()
1106 desc->threads_oneshot &= ~action->thread_mask; in irq_finalize_oneshot()
1108 if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) && in irq_finalize_oneshot()
1109 irqd_irq_masked(&desc->irq_data)) in irq_finalize_oneshot()
1113 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1119 * Check whether we need to change the affinity of the interrupt thread.
1127 if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags)) in irq_thread_check_affinity()
1135 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_thread_check_affinity()
1139 raw_spin_lock_irq(&desc->lock); in irq_thread_check_affinity()
1141 * This code is triggered unconditionally. Check the affinity in irq_thread_check_affinity()
1144 if (cpumask_available(desc->irq_common_data.affinity)) { in irq_thread_check_affinity()
1147 m = irq_data_get_effective_affinity_mask(&desc->irq_data); in irq_thread_check_affinity()
1152 raw_spin_unlock_irq(&desc->lock); in irq_thread_check_affinity()
1177 ret = action->thread_fn(action->irq, action->dev_id); in irq_forced_thread_fn()
1179 atomic_inc(&desc->threads_handled); in irq_forced_thread_fn()
1190 * preemptible - many of them need to sleep and wait for slow busses to
1198 ret = action->thread_fn(action->irq, action->dev_id); in irq_thread_fn()
1200 atomic_inc(&desc->threads_handled); in irq_thread_fn()
1208 if (atomic_dec_and_test(&desc->threads_active)) in wake_threads_waitq()
1209 wake_up(&desc->wait_for_threads); in wake_threads_waitq()
1218 if (WARN_ON_ONCE(!(current->flags & PF_EXITING))) in irq_thread_dtor()
1224 tsk->comm, tsk->pid, action->irq); in irq_thread_dtor()
1227 desc = irq_to_desc(action->irq); in irq_thread_dtor()
1230 * desc->threads_active and wake possible waiters. in irq_thread_dtor()
1232 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_thread_dtor()
1235 /* Prevent a stale desc->threads_oneshot */ in irq_thread_dtor()
1241 struct irqaction *secondary = action->secondary; in irq_wake_secondary()
1246 raw_spin_lock_irq(&desc->lock); in irq_wake_secondary()
1248 raw_spin_unlock_irq(&desc->lock); in irq_wake_secondary()
1252 * Interrupt handler thread
1258 struct irq_desc *desc = irq_to_desc(action->irq); in irq_thread()
1263 &action->thread_flags)) in irq_thread()
1296 * irq_wake_thread - wake the irq thread for the action identified by dev_id
1297 * @irq: Interrupt line
1310 raw_spin_lock_irqsave(&desc->lock, flags); in irq_wake_thread()
1312 if (action->dev_id == dev_id) { in irq_wake_thread()
1313 if (action->thread) in irq_wake_thread()
1318 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_wake_thread()
1326 if (new->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT)) in irq_setup_forced_threading()
1333 if (new->handler == irq_default_primary_handler) in irq_setup_forced_threading()
1336 new->flags |= IRQF_ONESHOT; in irq_setup_forced_threading()
1343 if (new->handler && new->thread_fn) { in irq_setup_forced_threading()
1345 new->secondary = kzalloc(sizeof(struct irqaction), GFP_KERNEL); in irq_setup_forced_threading()
1346 if (!new->secondary) in irq_setup_forced_threading()
1347 return -ENOMEM; in irq_setup_forced_threading()
1348 new->secondary->handler = irq_forced_secondary_handler; in irq_setup_forced_threading()
1349 new->secondary->thread_fn = new->thread_fn; in irq_setup_forced_threading()
1350 new->secondary->dev_id = new->dev_id; in irq_setup_forced_threading()
1351 new->secondary->irq = new->irq; in irq_setup_forced_threading()
1352 new->secondary->name = new->name; in irq_setup_forced_threading()
1355 set_bit(IRQTF_FORCED_THREAD, &new->thread_flags); in irq_setup_forced_threading()
1356 new->thread_fn = new->handler; in irq_setup_forced_threading()
1357 new->handler = irq_default_primary_handler; in irq_setup_forced_threading()
1363 struct irq_data *d = &desc->irq_data; in irq_request_resources()
1364 struct irq_chip *c = d->chip; in irq_request_resources()
1366 return c->irq_request_resources ? c->irq_request_resources(d) : 0; in irq_request_resources()
1371 struct irq_data *d = &desc->irq_data; in irq_release_resources()
1372 struct irq_chip *c = d->chip; in irq_release_resources()
1374 if (c->irq_release_resources) in irq_release_resources()
1375 c->irq_release_resources(d); in irq_release_resources()
1384 if (d->parent_data) in irq_supports_nmi()
1388 if (d->chip->irq_bus_lock || d->chip->irq_bus_sync_unlock) in irq_supports_nmi()
1391 return d->chip->flags & IRQCHIP_SUPPORTS_NMI; in irq_supports_nmi()
1397 struct irq_chip *c = d->chip; in irq_nmi_setup()
1399 return c->irq_nmi_setup ? c->irq_nmi_setup(d) : -EINVAL; in irq_nmi_setup()
1405 struct irq_chip *c = d->chip; in irq_nmi_teardown()
1407 if (c->irq_nmi_teardown) in irq_nmi_teardown()
1408 c->irq_nmi_teardown(d); in irq_nmi_teardown()
1417 t = kthread_create(irq_thread, new, "irq/%d-%s", irq, in setup_irq_thread()
1418 new->name); in setup_irq_thread()
1420 t = kthread_create(irq_thread, new, "irq/%d-s-%s", irq, in setup_irq_thread()
1421 new->name); in setup_irq_thread()
1431 * the thread dies to avoid that the interrupt code in setup_irq_thread()
1434 new->thread = get_task_struct(t); in setup_irq_thread()
1436 * Tell the thread to set its affinity. This is in setup_irq_thread()
1437 * important for shared interrupt handlers as we do in setup_irq_thread()
1442 * on which the requesting code placed the interrupt. in setup_irq_thread()
1444 set_bit(IRQTF_AFFINITY, &new->thread_flags); in setup_irq_thread()
1449 * Internal function to register an irqaction - typically used to
1454 * desc->request_mutex Provides serialization against a concurrent free_irq()
1456 * desc->lock Provides serialization against hard interrupts
1458 * chip_bus_lock and desc->lock are sufficient for all other management and
1459 * interrupt related functions. desc->request_mutex solely serializes
1470 return -EINVAL; in __setup_irq()
1472 if (desc->irq_data.chip == &no_irq_chip) in __setup_irq()
1473 return -ENOSYS; in __setup_irq()
1474 if (!try_module_get(desc->owner)) in __setup_irq()
1475 return -ENODEV; in __setup_irq()
1477 new->irq = irq; in __setup_irq()
1481 * then use the default for this interrupt. in __setup_irq()
1483 if (!(new->flags & IRQF_TRIGGER_MASK)) in __setup_irq()
1484 new->flags |= irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1487 * Check whether the interrupt nests into another interrupt in __setup_irq()
1492 if (!new->thread_fn) { in __setup_irq()
1493 ret = -EINVAL; in __setup_irq()
1498 * the driver for non nested interrupt handling by the in __setup_irq()
1501 new->handler = irq_nested_primary_handler; in __setup_irq()
1512 * and the interrupt does not nest into another interrupt in __setup_irq()
1515 if (new->thread_fn && !nested) { in __setup_irq()
1519 if (new->secondary) { in __setup_irq()
1520 ret = setup_irq_thread(new->secondary, irq, true); in __setup_irq()
1535 if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) in __setup_irq()
1536 new->flags &= ~IRQF_ONESHOT; in __setup_irq()
1541 * chip bus lock and desc->lock. Also protects against handing out in __setup_irq()
1545 mutex_lock(&desc->request_mutex); in __setup_irq()
1555 if (!desc->action) { in __setup_irq()
1559 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1566 * protected against a concurrent interrupt and any of the other in __setup_irq()
1568 * desc->request_mutex or the optional bus lock. in __setup_irq()
1570 raw_spin_lock_irqsave(&desc->lock, flags); in __setup_irq()
1571 old_ptr = &desc->action; in __setup_irq()
1580 * Interrupt lines used for NMIs cannot be shared. in __setup_irq()
1584 if (desc->istate & IRQS_NMI) { in __setup_irq()
1586 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1587 ret = -EINVAL; in __setup_irq()
1595 if (irqd_trigger_type_was_set(&desc->irq_data)) { in __setup_irq()
1596 oldtype = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1598 oldtype = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1599 irqd_set_trigger_type(&desc->irq_data, oldtype); in __setup_irq()
1602 if (!((old->flags & new->flags) & IRQF_SHARED) || in __setup_irq()
1603 (oldtype != (new->flags & IRQF_TRIGGER_MASK)) || in __setup_irq()
1604 ((old->flags ^ new->flags) & IRQF_ONESHOT)) in __setup_irq()
1607 /* All handlers must agree on per-cpuness */ in __setup_irq()
1608 if ((old->flags & IRQF_PERCPU) != in __setup_irq()
1609 (new->flags & IRQF_PERCPU)) in __setup_irq()
1612 /* add new interrupt at end of irq queue */ in __setup_irq()
1615 * Or all existing action->thread_mask bits, in __setup_irq()
1619 thread_mask |= old->thread_mask; in __setup_irq()
1620 old_ptr = &old->next; in __setup_irq()
1631 if (new->flags & IRQF_ONESHOT) { in __setup_irq()
1637 ret = -EBUSY; in __setup_irq()
1642 * desc->thread_active to indicate that the in __setup_irq()
1645 * completes. When all threads of a shared interrupt in __setup_irq()
1646 * line have completed desc->threads_active becomes in __setup_irq()
1647 * zero and the interrupt line is unmasked. See in __setup_irq()
1651 * interrupt handlers, then desc->threads_active is in __setup_irq()
1658 * all existing action->thread_mask bits. in __setup_irq()
1660 new->thread_mask = 1UL << ffz(thread_mask); in __setup_irq()
1662 } else if (new->handler == irq_default_primary_handler && in __setup_irq()
1663 !(desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)) { in __setup_irq()
1665 * The interrupt was requested with handler = NULL, so in __setup_irq()
1675 * say for sure which type this interrupt really in __setup_irq()
1680 new->name, irq); in __setup_irq()
1681 ret = -EINVAL; in __setup_irq()
1686 init_waitqueue_head(&desc->wait_for_threads); in __setup_irq()
1689 if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1691 new->flags & IRQF_TRIGGER_MASK); in __setup_irq()
1698 * Activate the interrupt. That activation must happen in __setup_irq()
1701 * that. enable_irq() of an interrupt requested with in __setup_irq()
1712 desc->istate &= ~(IRQS_AUTODETECT | IRQS_SPURIOUS_DISABLED | \ in __setup_irq()
1714 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); in __setup_irq()
1716 if (new->flags & IRQF_PERCPU) { in __setup_irq()
1717 irqd_set(&desc->irq_data, IRQD_PER_CPU); in __setup_irq()
1719 if (new->flags & IRQF_NO_DEBUG) in __setup_irq()
1726 if (new->flags & IRQF_ONESHOT) in __setup_irq()
1727 desc->istate |= IRQS_ONESHOT; in __setup_irq()
1730 if (new->flags & IRQF_NOBALANCING) { in __setup_irq()
1732 irqd_set(&desc->irq_data, IRQD_NO_BALANCING); in __setup_irq()
1735 if (!(new->flags & IRQF_NO_AUTOEN) && in __setup_irq()
1741 * auto enable. The sharing interrupt might request in __setup_irq()
1745 WARN_ON_ONCE(new->flags & IRQF_SHARED); in __setup_irq()
1747 desc->depth = 1; in __setup_irq()
1750 } else if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1751 unsigned int nmsk = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1752 unsigned int omsk = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1765 desc->irq_count = 0; in __setup_irq()
1766 desc->irqs_unhandled = 0; in __setup_irq()
1772 if (shared && (desc->istate & IRQS_SPURIOUS_DISABLED)) { in __setup_irq()
1773 desc->istate &= ~IRQS_SPURIOUS_DISABLED; in __setup_irq()
1777 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1779 mutex_unlock(&desc->request_mutex); in __setup_irq()
1785 * when no hard interrupt wakes the thread up. in __setup_irq()
1787 if (new->thread) in __setup_irq()
1788 wake_up_process(new->thread); in __setup_irq()
1789 if (new->secondary) in __setup_irq()
1790 wake_up_process(new->secondary->thread); in __setup_irq()
1793 new->dir = NULL; in __setup_irq()
1798 if (!(new->flags & IRQF_PROBE_SHARED)) { in __setup_irq()
1800 irq, new->flags, new->name, old->flags, old->name); in __setup_irq()
1805 ret = -EBUSY; in __setup_irq()
1808 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1810 if (!desc->action) in __setup_irq()
1814 mutex_unlock(&desc->request_mutex); in __setup_irq()
1817 if (new->thread) { in __setup_irq()
1818 struct task_struct *t = new->thread; in __setup_irq()
1820 new->thread = NULL; in __setup_irq()
1824 if (new->secondary && new->secondary->thread) { in __setup_irq()
1825 struct task_struct *t = new->secondary->thread; in __setup_irq()
1827 new->secondary->thread = NULL; in __setup_irq()
1832 module_put(desc->owner); in __setup_irq()
1837 * Internal function to unregister an irqaction - used to free
1842 unsigned irq = desc->irq_data.irq; in __free_irq()
1848 mutex_lock(&desc->request_mutex); in __free_irq()
1850 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1856 action_ptr = &desc->action; in __free_irq()
1861 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_irq()
1862 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1864 mutex_unlock(&desc->request_mutex); in __free_irq()
1868 if (action->dev_id == dev_id) in __free_irq()
1870 action_ptr = &action->next; in __free_irq()
1873 /* Found it - now remove it from the list of entries: */ in __free_irq()
1874 *action_ptr = action->next; in __free_irq()
1879 if (!desc->action) { in __free_irq()
1887 if (WARN_ON_ONCE(desc->affinity_hint)) in __free_irq()
1888 desc->affinity_hint = NULL; in __free_irq()
1891 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1902 * The still held desc->request_mutex() protects against a in __free_irq()
1913 * interrupt in flight at the hardware level. in __free_irq()
1919 * It's a shared IRQ -- the driver ought to be prepared for an IRQ in __free_irq()
1926 if (action->flags & IRQF_SHARED) { in __free_irq()
1928 action->handler(irq, dev_id); in __free_irq()
1939 if (action->thread) { in __free_irq()
1940 kthread_stop(action->thread); in __free_irq()
1941 put_task_struct(action->thread); in __free_irq()
1942 if (action->secondary && action->secondary->thread) { in __free_irq()
1943 kthread_stop(action->secondary->thread); in __free_irq()
1944 put_task_struct(action->secondary->thread); in __free_irq()
1949 if (!desc->action) { in __free_irq()
1956 * There is no interrupt on the fly anymore. Deactivate it in __free_irq()
1959 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1960 irq_domain_deactivate_irq(&desc->irq_data); in __free_irq()
1961 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1968 mutex_unlock(&desc->request_mutex); in __free_irq()
1970 irq_chip_pm_put(&desc->irq_data); in __free_irq()
1971 module_put(desc->owner); in __free_irq()
1972 kfree(action->secondary); in __free_irq()
1977 * free_irq - free an interrupt allocated with request_irq
1978 * @irq: Interrupt line to free
1981 * Remove an interrupt handler. The handler is removed and if the
1982 * interrupt line is no longer in use by any driver it is disabled.
1983 * On a shared IRQ the caller must ensure the interrupt is disabled
1988 * This function must not be called from interrupt context.
2002 if (WARN_ON(desc->affinity_notify)) in free_irq()
2003 desc->affinity_notify = NULL; in free_irq()
2011 devname = action->name; in free_irq()
2017 /* This function must be called with desc->lock held */
2022 desc->istate &= ~IRQS_NMI; in __cleanup_nmi()
2024 if (!WARN_ON(desc->action == NULL)) { in __cleanup_nmi()
2025 irq_pm_remove_action(desc, desc->action); in __cleanup_nmi()
2026 devname = desc->action->name; in __cleanup_nmi()
2027 unregister_handler_proc(irq, desc->action); in __cleanup_nmi()
2029 kfree(desc->action); in __cleanup_nmi()
2030 desc->action = NULL; in __cleanup_nmi()
2038 irq_chip_pm_put(&desc->irq_data); in __cleanup_nmi()
2039 module_put(desc->owner); in __cleanup_nmi()
2050 if (!desc || WARN_ON(!(desc->istate & IRQS_NMI))) in free_nmi()
2057 if (WARN_ON(desc->depth == 0)) in free_nmi()
2060 raw_spin_lock_irqsave(&desc->lock, flags); in free_nmi()
2065 raw_spin_unlock_irqrestore(&desc->lock, flags); in free_nmi()
2071 * request_threaded_irq - allocate an interrupt line
2072 * @irq: Interrupt line to allocate
2079 * @irqflags: Interrupt type flags
2083 * This call allocates interrupt resources and enables the
2084 * interrupt line and IRQ handling. From the point this
2086 * your handler function must clear any interrupt the board
2088 * and to set up the interrupt handler in the right order.
2092 * still called in hard interrupt context and has to check
2093 * whether the interrupt originates from the device. If yes it
2094 * needs to disable the interrupt on the device and return
2103 * If your interrupt is shared you must pass a non NULL dev_id
2104 * as this is required when freeing the interrupt.
2108 * IRQF_SHARED Interrupt is shared
2110 * IRQF_ONESHOT Run thread_fn with interrupt line masked
2121 return -ENOTCONN; in request_threaded_irq()
2124 * Sanity-check: shared interrupts must pass in a real dev-ID, in request_threaded_irq()
2126 * which interrupt is which (messes up the interrupt freeing in request_threaded_irq()
2130 * The sharing interrupt might request it while it's still disabled in request_threaded_irq()
2140 return -EINVAL; in request_threaded_irq()
2144 return -EINVAL; in request_threaded_irq()
2148 return -EINVAL; in request_threaded_irq()
2152 return -EINVAL; in request_threaded_irq()
2158 return -ENOMEM; in request_threaded_irq()
2160 action->handler = handler; in request_threaded_irq()
2161 action->thread_fn = thread_fn; in request_threaded_irq()
2162 action->flags = irqflags; in request_threaded_irq()
2163 action->name = devname; in request_threaded_irq()
2164 action->dev_id = dev_id; in request_threaded_irq()
2166 retval = irq_chip_pm_get(&desc->irq_data); in request_threaded_irq()
2175 irq_chip_pm_put(&desc->irq_data); in request_threaded_irq()
2176 kfree(action->secondary); in request_threaded_irq()
2183 * It's a shared IRQ -- the driver ought to be prepared for it in request_threaded_irq()
2204 * request_any_context_irq - allocate an interrupt line
2205 * @irq: Interrupt line to allocate
2208 * @flags: Interrupt type flags
2212 * This call allocates interrupt resources and enables the
2213 * interrupt line and IRQ handling. It selects either a
2227 return -ENOTCONN; in request_any_context_irq()
2231 return -EINVAL; in request_any_context_irq()
2245 * request_nmi - allocate an interrupt line for NMI delivery
2246 * @irq: Interrupt line to allocate
2249 * @irqflags: Interrupt type flags
2253 * This call allocates interrupt resources and enables the
2254 * interrupt line and IRQ handling. It sets up the IRQ line
2257 * An interrupt line delivering NMIs cannot be shared and IRQ handling
2260 * Interrupt lines requested for NMI delivering must produce per cpu
2267 * If the interrupt line cannot be used to deliver NMIs, function
2279 return -ENOTCONN; in request_nmi()
2283 return -EINVAL; in request_nmi()
2286 return -EINVAL; in request_nmi()
2289 return -EINVAL; in request_nmi()
2298 return -EINVAL; in request_nmi()
2302 return -ENOMEM; in request_nmi()
2304 action->handler = handler; in request_nmi()
2305 action->flags = irqflags | IRQF_NO_THREAD | IRQF_NOBALANCING; in request_nmi()
2306 action->name = name; in request_nmi()
2307 action->dev_id = dev_id; in request_nmi()
2309 retval = irq_chip_pm_get(&desc->irq_data); in request_nmi()
2317 raw_spin_lock_irqsave(&desc->lock, flags); in request_nmi()
2320 desc->istate |= IRQS_NMI; in request_nmi()
2324 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2325 return -EINVAL; in request_nmi()
2328 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2333 irq_chip_pm_put(&desc->irq_data); in request_nmi()
2351 * use the default for this interrupt. in enable_percpu_irq()
2355 type = irqd_get_trigger_type(&desc->irq_data); in enable_percpu_irq()
2380 * irq_percpu_is_enabled - Check whether the per cpu irq is enabled
2384 * state of a per cpu interrupt on the current cpu.
2397 is_enabled = cpumask_test_cpu(cpu, desc->percpu_enabled); in irq_percpu_is_enabled()
2437 raw_spin_lock_irqsave(&desc->lock, flags); in __free_percpu_irq()
2439 action = desc->action; in __free_percpu_irq()
2440 if (!action || action->percpu_dev_id != dev_id) { in __free_percpu_irq()
2441 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_percpu_irq()
2445 if (!cpumask_empty(desc->percpu_enabled)) { in __free_percpu_irq()
2447 irq, cpumask_first(desc->percpu_enabled)); in __free_percpu_irq()
2451 /* Found it - now remove it from the list of entries: */ in __free_percpu_irq()
2452 desc->action = NULL; in __free_percpu_irq()
2454 desc->istate &= ~IRQS_NMI; in __free_percpu_irq()
2456 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2460 irq_chip_pm_put(&desc->irq_data); in __free_percpu_irq()
2461 module_put(desc->owner); in __free_percpu_irq()
2465 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2470 * remove_percpu_irq - free a per-cpu interrupt
2471 * @irq: Interrupt line to free
2472 * @act: irqaction for the interrupt
2481 __free_percpu_irq(irq, act->percpu_dev_id); in remove_percpu_irq()
2485 * free_percpu_irq - free an interrupt allocated with request_percpu_irq
2486 * @irq: Interrupt line to free
2489 * Remove a percpu interrupt handler. The handler is removed, but
2490 * the interrupt line is not disabled. This must be done on each
2494 * This function must not be called from interrupt context.
2516 if (WARN_ON(!(desc->istate & IRQS_NMI))) in free_percpu_nmi()
2523 * setup_percpu_irq - setup a per-cpu interrupt
2524 * @irq: Interrupt line to setup
2525 * @act: irqaction for the interrupt
2527 * Used to statically setup per-cpu interrupts in the early boot process.
2535 return -EINVAL; in setup_percpu_irq()
2537 retval = irq_chip_pm_get(&desc->irq_data); in setup_percpu_irq()
2544 irq_chip_pm_put(&desc->irq_data); in setup_percpu_irq()
2550 * __request_percpu_irq - allocate a percpu interrupt line
2551 * @irq: Interrupt line to allocate
2553 * @flags: Interrupt type flags (IRQF_TIMER only)
2557 * This call allocates interrupt resources and enables the
2558 * interrupt on the local CPU. If the interrupt is supposed to be
2562 * Dev_id must be globally unique. It is a per-cpu variable, and
2575 return -EINVAL; in __request_percpu_irq()
2580 return -EINVAL; in __request_percpu_irq()
2583 return -EINVAL; in __request_percpu_irq()
2587 return -ENOMEM; in __request_percpu_irq()
2589 action->handler = handler; in __request_percpu_irq()
2590 action->flags = flags | IRQF_PERCPU | IRQF_NO_SUSPEND; in __request_percpu_irq()
2591 action->name = devname; in __request_percpu_irq()
2592 action->percpu_dev_id = dev_id; in __request_percpu_irq()
2594 retval = irq_chip_pm_get(&desc->irq_data); in __request_percpu_irq()
2603 irq_chip_pm_put(&desc->irq_data); in __request_percpu_irq()
2612 * request_percpu_nmi - allocate a percpu interrupt line for NMI delivery
2613 * @irq: Interrupt line to allocate
2618 * This call allocates interrupt resources for a per CPU NMI. Per CPU NMIs
2622 * Dev_id must be globally unique. It is a per-cpu variable, and
2626 * Interrupt lines requested for NMI delivering should have auto enabling
2629 * If the interrupt line cannot be used to deliver NMIs, function
2641 return -EINVAL; in request_percpu_nmi()
2649 return -EINVAL; in request_percpu_nmi()
2652 if (desc->istate & IRQS_NMI) in request_percpu_nmi()
2653 return -EINVAL; in request_percpu_nmi()
2657 return -ENOMEM; in request_percpu_nmi()
2659 action->handler = handler; in request_percpu_nmi()
2660 action->flags = IRQF_PERCPU | IRQF_NO_SUSPEND | IRQF_NO_THREAD in request_percpu_nmi()
2662 action->name = name; in request_percpu_nmi()
2663 action->percpu_dev_id = dev_id; in request_percpu_nmi()
2665 retval = irq_chip_pm_get(&desc->irq_data); in request_percpu_nmi()
2673 raw_spin_lock_irqsave(&desc->lock, flags); in request_percpu_nmi()
2674 desc->istate |= IRQS_NMI; in request_percpu_nmi()
2675 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_percpu_nmi()
2680 irq_chip_pm_put(&desc->irq_data); in request_percpu_nmi()
2688 * prepare_percpu_nmi - performs CPU local setup for NMI delivery
2689 * @irq: Interrupt line to prepare for NMI delivery
2691 * This call prepares an interrupt line to deliver NMI on the current CPU,
2692 * before that interrupt line gets enabled with enable_percpu_nmi().
2694 * As a CPU local operation, this should be called from non-preemptible
2697 * If the interrupt line cannot be used to deliver NMIs, function
2711 return -EINVAL; in prepare_percpu_nmi()
2713 if (WARN(!(desc->istate & IRQS_NMI), in prepare_percpu_nmi()
2714 KERN_ERR "prepare_percpu_nmi called for a non-NMI interrupt: irq %u\n", in prepare_percpu_nmi()
2716 ret = -EINVAL; in prepare_percpu_nmi()
2732 * teardown_percpu_nmi - undoes NMI setup of IRQ line
2733 * @irq: Interrupt line from which CPU local NMI configuration should be
2740 * As a CPU local operation, this should be called from non-preemptible
2755 if (WARN_ON(!(desc->istate & IRQS_NMI))) in teardown_percpu_nmi()
2767 int err = -EINVAL; in __irq_get_irqchip_state()
2772 return -ENODEV; in __irq_get_irqchip_state()
2773 if (chip->irq_get_irqchip_state) in __irq_get_irqchip_state()
2776 data = data->parent_data; in __irq_get_irqchip_state()
2783 err = chip->irq_get_irqchip_state(data, which, state); in __irq_get_irqchip_state()
2788 * irq_get_irqchip_state - returns the irqchip state of a interrupt.
2789 * @irq: Interrupt line that is forwarded to a VM
2794 * interrupt, returning into @state the bit corresponding to
2798 * interrupt controller has per-cpu registers.
2806 int err = -EINVAL; in irq_get_irqchip_state()
2822 * irq_set_irqchip_state - set the state of a forwarded interrupt.
2823 * @irq: Interrupt line that is forwarded to a VM
2827 * This call sets the internal irqchip state of an interrupt,
2831 * interrupt controller has per-cpu registers.
2840 int err = -EINVAL; in irq_set_irqchip_state()
2851 err = -ENODEV; in irq_set_irqchip_state()
2854 if (chip->irq_set_irqchip_state) in irq_set_irqchip_state()
2857 data = data->parent_data; in irq_set_irqchip_state()
2864 err = chip->irq_set_irqchip_state(data, which, val); in irq_set_irqchip_state()
2873 * irq_has_action - Check whether an interrupt is requested
2890 * irq_check_status_bit - Check whether bits in the irq descriptor status are set
2904 res = !!(desc->status_use_accessors & bitmask); in irq_check_status_bit()