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()
118 wait_event(desc->wait_for_threads, !atomic_read(&desc->threads_active)); in __synchronize_irq()
122 * synchronize_irq - wait for pending IRQ handlers (on other CPUs)
123 * @irq: interrupt number to wait for
125 * This function waits for any pending IRQ handlers for this interrupt
130 * an interrupt thread is associated to @irq.
133 * that the interrupt is not pending in any CPU and waiting for
150 if (!desc || !irqd_can_balance(&desc->irq_data) || in __irq_can_set_affinity()
151 !desc->irq_data.chip || !desc->irq_data.chip->irq_set_affinity) in __irq_can_set_affinity()
157 * irq_can_set_affinity - Check if the affinity of a given irq can be set
158 * @irq: Interrupt to check
167 * irq_can_set_affinity_usr - Check if affinity of a irq can be set from user space
168 * @irq: Interrupt to check
178 !irqd_affinity_is_managed(&desc->irq_data); in irq_can_set_affinity_usr()
182 * irq_set_thread_affinity - Notify irq threads to adjust affinity
183 * @desc: irq descriptor which has affinity changed
185 * We just set IRQTF_AFFINITY and delegate the affinity setting
186 * to the interrupt thread itself. We can not call
187 * set_cpus_allowed_ptr() here as we hold desc->lock and this
188 * code can be called from hard interrupt context.
195 if (action->thread) { in irq_set_thread_affinity()
196 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_set_thread_affinity()
197 wake_up_process(action->thread); in irq_set_thread_affinity()
199 if (action->secondary && action->secondary->thread) { in irq_set_thread_affinity()
200 set_bit(IRQTF_AFFINITY, &action->secondary->thread_flags); in irq_set_thread_affinity()
201 wake_up_process(action->secondary->thread); in irq_set_thread_affinity()
214 pr_warn_once("irq_chip %s did not update eff. affinity mask of irq %u\n", in irq_validate_effective_affinity()
215 chip->name, data->irq); in irq_validate_effective_affinity()
232 if (!chip || !chip->irq_set_affinity) in irq_do_set_affinity()
233 return -EINVAL; in irq_do_set_affinity()
236 * If this is a managed interrupt and housekeeping is enabled on in irq_do_set_affinity()
237 * it check whether the requested affinity mask intersects with in irq_do_set_affinity()
240 * the affinity setter from routing the interrupt to an isolated in irq_do_set_affinity()
249 * If all housekeeping CPUs in the affinity mask are offline, the in irq_do_set_affinity()
250 * interrupt will be migrated by the CPU hotplug code once a in irq_do_set_affinity()
251 * housekeeping CPU which belongs to the affinity mask comes in irq_do_set_affinity()
271 * unless we are being asked to force the affinity (in which in irq_do_set_affinity()
276 ret = chip->irq_set_affinity(data, tmp_mask, force); in irq_do_set_affinity()
278 ret = chip->irq_set_affinity(data, mask, force); in irq_do_set_affinity()
280 ret = -EINVAL; in irq_do_set_affinity()
285 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_do_set_affinity()
310 return -EBUSY; in irq_set_affinity_pending()
324 if (ret == -EBUSY && !force) in irq_try_set_affinity()
335 * Handle irq chips which can handle affinity only in activated in irq_set_affinity_deactivated()
338 * If the interrupt is not yet activated, just store the affinity in irq_set_affinity_deactivated()
340 * driver has to make sure anyway that the interrupt is in a in irq_set_affinity_deactivated()
347 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_set_affinity_deactivated()
360 if (!chip || !chip->irq_set_affinity) in irq_set_affinity_locked()
361 return -EINVAL; in irq_set_affinity_locked()
373 if (desc->affinity_notify) { in irq_set_affinity_locked()
374 kref_get(&desc->affinity_notify->kref); in irq_set_affinity_locked()
375 if (!schedule_work(&desc->affinity_notify->work)) { in irq_set_affinity_locked()
377 kref_put(&desc->affinity_notify->kref, in irq_set_affinity_locked()
378 desc->affinity_notify->release); in irq_set_affinity_locked()
387 * irq_update_affinity_desc - Update affinity management for an interrupt
388 * @irq: The interrupt number to update
389 * @affinity: Pointer to the affinity descriptor
391 * This interface can be used to configure the affinity management of
394 * There are certain limitations on when it may be used - attempts to use it
397 * managed/non-managed interrupt accounting. In addition, attempts to use it on
398 * an interrupt which is already started or which has already been configured
402 struct irq_affinity_desc *affinity) in irq_update_affinity_desc() argument
414 return -EOPNOTSUPP; in irq_update_affinity_desc()
418 return -EINVAL; in irq_update_affinity_desc()
420 /* Requires the interrupt to be shut down */ in irq_update_affinity_desc()
421 if (irqd_is_started(&desc->irq_data)) { in irq_update_affinity_desc()
422 ret = -EBUSY; in irq_update_affinity_desc()
427 if (irqd_affinity_is_managed(&desc->irq_data)) { in irq_update_affinity_desc()
428 ret = -EBUSY; in irq_update_affinity_desc()
433 * Deactivate the interrupt. That's required to undo in irq_update_affinity_desc()
436 activated = irqd_is_activated(&desc->irq_data); in irq_update_affinity_desc()
438 irq_domain_deactivate_irq(&desc->irq_data); in irq_update_affinity_desc()
440 if (affinity->is_managed) { in irq_update_affinity_desc()
441 irqd_set(&desc->irq_data, IRQD_AFFINITY_MANAGED); in irq_update_affinity_desc()
442 irqd_set(&desc->irq_data, IRQD_MANAGED_SHUTDOWN); in irq_update_affinity_desc()
445 cpumask_copy(desc->irq_common_data.affinity, &affinity->mask); in irq_update_affinity_desc()
449 irq_domain_activate_irq(&desc->irq_data, false); in irq_update_affinity_desc()
464 return -EINVAL; in __irq_set_affinity()
466 raw_spin_lock_irqsave(&desc->lock, flags); in __irq_set_affinity()
468 raw_spin_unlock_irqrestore(&desc->lock, flags); in __irq_set_affinity()
473 * irq_set_affinity - Set the irq affinity of a given irq
474 * @irq: Interrupt to set affinity
486 * irq_force_affinity - Force the irq affinity of a given irq
487 * @irq: Interrupt to set affinity
509 return -EINVAL; in __irq_apply_affinity_hint()
510 desc->affinity_hint = m; in __irq_apply_affinity_hint()
522 struct irq_desc *desc = irq_to_desc(notify->irq); in irq_affinity_notify()
529 raw_spin_lock_irqsave(&desc->lock, flags); in irq_affinity_notify()
530 if (irq_move_pending(&desc->irq_data)) in irq_affinity_notify()
533 cpumask_copy(cpumask, desc->irq_common_data.affinity); in irq_affinity_notify()
534 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_affinity_notify()
536 notify->notify(notify, cpumask); in irq_affinity_notify()
540 kref_put(¬ify->kref, notify->release); in irq_affinity_notify()
544 * irq_set_affinity_notifier - control notification of IRQ affinity changes
545 * @irq: Interrupt for which to enable/disable notification
565 return -EINVAL; in irq_set_affinity_notifier()
569 notify->irq = irq; in irq_set_affinity_notifier()
570 kref_init(¬ify->kref); in irq_set_affinity_notifier()
571 INIT_WORK(¬ify->work, irq_affinity_notify); in irq_set_affinity_notifier()
574 raw_spin_lock_irqsave(&desc->lock, flags); in irq_set_affinity_notifier()
575 old_notify = desc->affinity_notify; in irq_set_affinity_notifier()
576 desc->affinity_notify = notify; in irq_set_affinity_notifier()
577 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_set_affinity_notifier()
580 if (cancel_work_sync(&old_notify->work)) { in irq_set_affinity_notifier()
582 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
584 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
593 * Generic version of the affinity autoselector.
608 * Preserve the managed affinity setting and a userspace affinity in irq_setup_affinity()
611 if (irqd_affinity_is_managed(&desc->irq_data) || in irq_setup_affinity()
612 irqd_has_set(&desc->irq_data, IRQD_AFFINITY_SET)) { in irq_setup_affinity()
613 if (cpumask_intersects(desc->irq_common_data.affinity, in irq_setup_affinity()
615 set = desc->irq_common_data.affinity; in irq_setup_affinity()
617 irqd_clear(&desc->irq_data, IRQD_AFFINITY_SET); in irq_setup_affinity()
631 ret = irq_do_set_affinity(&desc->irq_data, &mask, false); in irq_setup_affinity()
636 /* Wrapper for ALPHA specific affinity selector magic */
646 * irq_set_vcpu_affinity - Set vcpu affinity for the interrupt
647 * @irq: interrupt number to set affinity
652 * affinity for an irq. The vCPU specific data is passed from
654 * KVM -> IOMMU -> irq_set_vcpu_affinity().
662 int ret = -ENOSYS; in irq_set_vcpu_affinity()
665 return -EINVAL; in irq_set_vcpu_affinity()
670 if (chip && chip->irq_set_vcpu_affinity) in irq_set_vcpu_affinity()
673 data = data->parent_data; in irq_set_vcpu_affinity()
680 ret = chip->irq_set_vcpu_affinity(data, vcpu_info); in irq_set_vcpu_affinity()
689 if (!desc->depth++) in __disable_irq()
699 return -EINVAL; in __disable_irq_nosync()
706 * disable_irq_nosync - disable an irq without waiting
707 * @irq: Interrupt to disable
709 * Disable the selected interrupt line. Disables and Enables are
723 * disable_irq - disable an irq and wait for completion
724 * @irq: Interrupt to disable
726 * Disable the selected interrupt line. Enables and Disables are
728 * This function waits for any pending IRQ handlers for this interrupt
733 * an interrupt thread is associated to @irq.
745 * disable_hardirq - disables an irq and waits for hardirq completion
746 * @irq: Interrupt to disable
748 * Disable the selected interrupt line. Enables and Disables are
751 * interrupt to complete before returning. If you use this function while
754 * When used to optimistically disable an interrupt from atomic context
759 * This function may be called - with care - from IRQ context.
771 * disable_nmi_nosync - disable an nmi without waiting
772 * @irq: Interrupt to disable
774 * Disable the selected interrupt line. Disables and enables are
776 * The interrupt to disable must have been requested through request_nmi.
787 switch (desc->depth) { in __enable_irq()
794 if (desc->istate & IRQS_SUSPENDED) in __enable_irq()
800 * interrupt might be marked NOAUTOEN so irq_startup() in __enable_irq()
803 * a managed and shutdown interrupt from the S3 resume in __enable_irq()
813 desc->depth--; in __enable_irq()
818 * enable_irq - enable handling of an irq
819 * @irq: Interrupt to enable
823 * IRQ line is re-enabled.
826 * desc->irq_data.chip->bus_lock and desc->chip->bus_sync_unlock are NULL !
835 if (WARN(!desc->irq_data.chip, in enable_irq()
846 * enable_nmi - enable handling of an nmi
847 * @irq: Interrupt to enable
849 * The interrupt to enable must have been requested through request_nmi.
852 * IRQ line is re-enabled.
862 int ret = -ENXIO; in set_irq_wake_real()
864 if (irq_desc_get_chip(desc)->flags & IRQCHIP_SKIP_SET_WAKE) in set_irq_wake_real()
867 if (desc->irq_data.chip->irq_set_wake) in set_irq_wake_real()
868 ret = desc->irq_data.chip->irq_set_wake(&desc->irq_data, on); in set_irq_wake_real()
874 * irq_set_irq_wake - control irq power management wakeup
875 * @irq: interrupt to control
880 * just as they match for non-wakeup mode support.
899 return -EINVAL; in irq_set_irq_wake()
903 ret = -EINVAL; in irq_set_irq_wake()
907 /* wakeup-capable irqs can be shared between drivers that in irq_set_irq_wake()
911 if (desc->wake_depth++ == 0) { in irq_set_irq_wake()
914 desc->wake_depth = 0; in irq_set_irq_wake()
916 irqd_set(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
919 if (desc->wake_depth == 0) { in irq_set_irq_wake()
921 } else if (--desc->wake_depth == 0) { in irq_set_irq_wake()
924 desc->wake_depth = 1; in irq_set_irq_wake()
926 irqd_clear(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
951 if (!desc->action || in can_request_irq()
952 irqflags & desc->action->flags & IRQF_SHARED) in can_request_irq()
961 struct irq_chip *chip = desc->irq_data.chip; in __irq_set_trigger()
964 if (!chip || !chip->irq_set_type) { in __irq_set_trigger()
967 * flow-types? in __irq_set_trigger()
971 chip ? (chip->name ? : "unknown") : "unknown"); in __irq_set_trigger()
975 if (chip->flags & IRQCHIP_SET_TYPE_MASKED) { in __irq_set_trigger()
976 if (!irqd_irq_masked(&desc->irq_data)) in __irq_set_trigger()
978 if (!irqd_irq_disabled(&desc->irq_data)) in __irq_set_trigger()
984 ret = chip->irq_set_type(&desc->irq_data, flags); in __irq_set_trigger()
989 irqd_clear(&desc->irq_data, IRQD_TRIGGER_MASK); in __irq_set_trigger()
990 irqd_set(&desc->irq_data, flags); in __irq_set_trigger()
994 flags = irqd_get_trigger_type(&desc->irq_data); in __irq_set_trigger()
996 irqd_clear(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
1000 irqd_set(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
1007 flags, irq_desc_get_irq(desc), chip->irq_set_type); in __irq_set_trigger()
1021 return -EINVAL; in irq_set_parent()
1023 desc->parent_irq = parent_irq; in irq_set_parent()
1032 * Default primary interrupt handler for threaded interrupts. Is
1059 * Check whether we need to change the affinity of the interrupt thread.
1066 if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags)) in irq_thread_check_affinity()
1076 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_thread_check_affinity()
1080 raw_spin_lock_irq(&desc->lock); in irq_thread_check_affinity()
1082 * This code is triggered unconditionally. Check the affinity in irq_thread_check_affinity()
1085 if (cpumask_available(desc->irq_common_data.affinity)) { in irq_thread_check_affinity()
1088 m = irq_data_get_effective_affinity_mask(&desc->irq_data); in irq_thread_check_affinity()
1092 raw_spin_unlock_irq(&desc->lock); in irq_thread_check_affinity()
1112 &action->thread_flags)) { in irq_wait_for_interrupt()
1117 return -1; in irq_wait_for_interrupt()
1121 &action->thread_flags)) { in irq_wait_for_interrupt()
1131 * handler finished. unmask if the interrupt has not been disabled and
1137 if (!(desc->istate & IRQS_ONESHOT) || in irq_finalize_oneshot()
1138 action->handler == irq_forced_secondary_handler) in irq_finalize_oneshot()
1142 raw_spin_lock_irq(&desc->lock); in irq_finalize_oneshot()
1148 * The thread is faster done than the hard interrupt handler in irq_finalize_oneshot()
1150 * interrupt can come in again and masks the line, leaves due in irq_finalize_oneshot()
1154 * versus "desc->threads_oneshot |= action->thread_mask;" in in irq_finalize_oneshot()
1158 if (unlikely(irqd_irq_inprogress(&desc->irq_data))) { in irq_finalize_oneshot()
1159 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1170 if (test_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_finalize_oneshot()
1173 desc->threads_oneshot &= ~action->thread_mask; in irq_finalize_oneshot()
1175 if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) && in irq_finalize_oneshot()
1176 irqd_irq_masked(&desc->irq_data)) in irq_finalize_oneshot()
1180 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1186 * preemptible - many of them need to sleep and wait for slow busses to
1191 irqreturn_t ret = action->thread_fn(action->irq, action->dev_id); in irq_thread_fn()
1194 atomic_inc(&desc->threads_handled); in irq_thread_fn()
1222 if (atomic_dec_and_test(&desc->threads_active)) in wake_threads_waitq()
1223 wake_up(&desc->wait_for_threads); in wake_threads_waitq()
1232 if (WARN_ON_ONCE(!(current->flags & PF_EXITING))) in irq_thread_dtor()
1238 tsk->comm, tsk->pid, action->irq); in irq_thread_dtor()
1241 desc = irq_to_desc(action->irq); in irq_thread_dtor()
1244 * desc->threads_active and wake possible waiters. in irq_thread_dtor()
1246 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_thread_dtor()
1249 /* Prevent a stale desc->threads_oneshot */ in irq_thread_dtor()
1255 struct irqaction *secondary = action->secondary; in irq_wake_secondary()
1260 raw_spin_lock_irq(&desc->lock); in irq_wake_secondary()
1262 raw_spin_unlock_irq(&desc->lock); in irq_wake_secondary()
1266 * Internal function to notify that a interrupt thread is ready.
1271 set_bit(IRQTF_READY, &action->thread_flags); in irq_thread_set_ready()
1272 wake_up(&desc->wait_for_threads); in irq_thread_set_ready()
1276 * Internal function to wake up a interrupt thread and wait until it is
1282 if (!action || !action->thread) in wake_up_and_wait_for_irq_thread_ready()
1285 wake_up_process(action->thread); in wake_up_and_wait_for_irq_thread_ready()
1286 wait_event(desc->wait_for_threads, in wake_up_and_wait_for_irq_thread_ready()
1287 test_bit(IRQTF_READY, &action->thread_flags)); in wake_up_and_wait_for_irq_thread_ready()
1291 * Interrupt handler thread
1297 struct irq_desc *desc = irq_to_desc(action->irq); in irq_thread()
1306 &action->thread_flags)) in irq_thread()
1335 * irq_wake_thread - wake the irq thread for the action identified by dev_id
1336 * @irq: Interrupt line
1349 raw_spin_lock_irqsave(&desc->lock, flags); in irq_wake_thread()
1351 if (action->dev_id == dev_id) { in irq_wake_thread()
1352 if (action->thread) in irq_wake_thread()
1357 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_wake_thread()
1365 if (new->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT)) in irq_setup_forced_threading()
1372 if (new->handler == irq_default_primary_handler) in irq_setup_forced_threading()
1375 new->flags |= IRQF_ONESHOT; in irq_setup_forced_threading()
1382 if (new->handler && new->thread_fn) { in irq_setup_forced_threading()
1384 new->secondary = kzalloc(sizeof(struct irqaction), GFP_KERNEL); in irq_setup_forced_threading()
1385 if (!new->secondary) in irq_setup_forced_threading()
1386 return -ENOMEM; in irq_setup_forced_threading()
1387 new->secondary->handler = irq_forced_secondary_handler; in irq_setup_forced_threading()
1388 new->secondary->thread_fn = new->thread_fn; in irq_setup_forced_threading()
1389 new->secondary->dev_id = new->dev_id; in irq_setup_forced_threading()
1390 new->secondary->irq = new->irq; in irq_setup_forced_threading()
1391 new->secondary->name = new->name; in irq_setup_forced_threading()
1394 set_bit(IRQTF_FORCED_THREAD, &new->thread_flags); in irq_setup_forced_threading()
1395 new->thread_fn = new->handler; in irq_setup_forced_threading()
1396 new->handler = irq_default_primary_handler; in irq_setup_forced_threading()
1402 struct irq_data *d = &desc->irq_data; in irq_request_resources()
1403 struct irq_chip *c = d->chip; in irq_request_resources()
1405 return c->irq_request_resources ? c->irq_request_resources(d) : 0; in irq_request_resources()
1410 struct irq_data *d = &desc->irq_data; in irq_release_resources()
1411 struct irq_chip *c = d->chip; in irq_release_resources()
1413 if (c->irq_release_resources) in irq_release_resources()
1414 c->irq_release_resources(d); in irq_release_resources()
1423 if (d->parent_data) in irq_supports_nmi()
1427 if (d->chip->irq_bus_lock || d->chip->irq_bus_sync_unlock) in irq_supports_nmi()
1430 return d->chip->flags & IRQCHIP_SUPPORTS_NMI; in irq_supports_nmi()
1436 struct irq_chip *c = d->chip; in irq_nmi_setup()
1438 return c->irq_nmi_setup ? c->irq_nmi_setup(d) : -EINVAL; in irq_nmi_setup()
1444 struct irq_chip *c = d->chip; in irq_nmi_teardown()
1446 if (c->irq_nmi_teardown) in irq_nmi_teardown()
1447 c->irq_nmi_teardown(d); in irq_nmi_teardown()
1456 t = kthread_create(irq_thread, new, "irq/%d-%s", irq, in setup_irq_thread()
1457 new->name); in setup_irq_thread()
1459 t = kthread_create(irq_thread, new, "irq/%d-s-%s", irq, in setup_irq_thread()
1460 new->name); in setup_irq_thread()
1468 * the thread dies to avoid that the interrupt code in setup_irq_thread()
1471 new->thread = get_task_struct(t); in setup_irq_thread()
1473 * Tell the thread to set its affinity. This is in setup_irq_thread()
1474 * important for shared interrupt handlers as we do in setup_irq_thread()
1479 * on which the requesting code placed the interrupt. in setup_irq_thread()
1481 set_bit(IRQTF_AFFINITY, &new->thread_flags); in setup_irq_thread()
1486 * Internal function to register an irqaction - typically used to
1491 * desc->request_mutex Provides serialization against a concurrent free_irq()
1493 * desc->lock Provides serialization against hard interrupts
1495 * chip_bus_lock and desc->lock are sufficient for all other management and
1496 * interrupt related functions. desc->request_mutex solely serializes
1507 return -EINVAL; in __setup_irq()
1509 if (desc->irq_data.chip == &no_irq_chip) in __setup_irq()
1510 return -ENOSYS; in __setup_irq()
1511 if (!try_module_get(desc->owner)) in __setup_irq()
1512 return -ENODEV; in __setup_irq()
1514 new->irq = irq; in __setup_irq()
1518 * then use the default for this interrupt. in __setup_irq()
1520 if (!(new->flags & IRQF_TRIGGER_MASK)) in __setup_irq()
1521 new->flags |= irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1524 * Check whether the interrupt nests into another interrupt in __setup_irq()
1529 if (!new->thread_fn) { in __setup_irq()
1530 ret = -EINVAL; in __setup_irq()
1535 * the driver for non nested interrupt handling by the in __setup_irq()
1538 new->handler = irq_nested_primary_handler; in __setup_irq()
1549 * and the interrupt does not nest into another interrupt in __setup_irq()
1552 if (new->thread_fn && !nested) { in __setup_irq()
1556 if (new->secondary) { in __setup_irq()
1557 ret = setup_irq_thread(new->secondary, irq, true); in __setup_irq()
1572 if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) in __setup_irq()
1573 new->flags &= ~IRQF_ONESHOT; in __setup_irq()
1578 * chip bus lock and desc->lock. Also protects against handing out in __setup_irq()
1582 mutex_lock(&desc->request_mutex); in __setup_irq()
1592 if (!desc->action) { in __setup_irq()
1596 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1603 * protected against a concurrent interrupt and any of the other in __setup_irq()
1605 * desc->request_mutex or the optional bus lock. in __setup_irq()
1607 raw_spin_lock_irqsave(&desc->lock, flags); in __setup_irq()
1608 old_ptr = &desc->action; in __setup_irq()
1617 * Interrupt lines used for NMIs cannot be shared. in __setup_irq()
1623 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1624 ret = -EINVAL; in __setup_irq()
1632 if (irqd_trigger_type_was_set(&desc->irq_data)) { in __setup_irq()
1633 oldtype = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1635 oldtype = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1636 irqd_set_trigger_type(&desc->irq_data, oldtype); in __setup_irq()
1639 if (!((old->flags & new->flags) & IRQF_SHARED) || in __setup_irq()
1640 (oldtype != (new->flags & IRQF_TRIGGER_MASK))) in __setup_irq()
1643 if ((old->flags & IRQF_ONESHOT) && in __setup_irq()
1644 (new->flags & IRQF_COND_ONESHOT)) in __setup_irq()
1645 new->flags |= IRQF_ONESHOT; in __setup_irq()
1646 else if ((old->flags ^ new->flags) & IRQF_ONESHOT) in __setup_irq()
1649 /* All handlers must agree on per-cpuness */ in __setup_irq()
1650 if ((old->flags & IRQF_PERCPU) != in __setup_irq()
1651 (new->flags & IRQF_PERCPU)) in __setup_irq()
1654 /* add new interrupt at end of irq queue */ in __setup_irq()
1657 * Or all existing action->thread_mask bits, in __setup_irq()
1661 thread_mask |= old->thread_mask; in __setup_irq()
1662 old_ptr = &old->next; in __setup_irq()
1673 if (new->flags & IRQF_ONESHOT) { in __setup_irq()
1679 ret = -EBUSY; in __setup_irq()
1684 * desc->thread_active to indicate that the in __setup_irq()
1687 * completes. When all threads of a shared interrupt in __setup_irq()
1688 * line have completed desc->threads_active becomes in __setup_irq()
1689 * zero and the interrupt line is unmasked. See in __setup_irq()
1693 * interrupt handlers, then desc->threads_active is in __setup_irq()
1700 * all existing action->thread_mask bits. in __setup_irq()
1702 new->thread_mask = 1UL << ffz(thread_mask); in __setup_irq()
1704 } else if (new->handler == irq_default_primary_handler && in __setup_irq()
1705 !(desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)) { in __setup_irq()
1707 * The interrupt was requested with handler = NULL, so in __setup_irq()
1717 * say for sure which type this interrupt really in __setup_irq()
1722 new->name, irq); in __setup_irq()
1723 ret = -EINVAL; in __setup_irq()
1729 if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1731 new->flags & IRQF_TRIGGER_MASK); in __setup_irq()
1738 * Activate the interrupt. That activation must happen in __setup_irq()
1741 * that. enable_irq() of an interrupt requested with in __setup_irq()
1752 desc->istate &= ~(IRQS_AUTODETECT | IRQS_SPURIOUS_DISABLED | \ in __setup_irq()
1754 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); in __setup_irq()
1756 if (new->flags & IRQF_PERCPU) { in __setup_irq()
1757 irqd_set(&desc->irq_data, IRQD_PER_CPU); in __setup_irq()
1759 if (new->flags & IRQF_NO_DEBUG) in __setup_irq()
1766 if (new->flags & IRQF_ONESHOT) in __setup_irq()
1767 desc->istate |= IRQS_ONESHOT; in __setup_irq()
1770 if (new->flags & IRQF_NOBALANCING) { in __setup_irq()
1772 irqd_set(&desc->irq_data, IRQD_NO_BALANCING); in __setup_irq()
1775 if (!(new->flags & IRQF_NO_AUTOEN) && in __setup_irq()
1781 * auto enable. The sharing interrupt might request in __setup_irq()
1785 WARN_ON_ONCE(new->flags & IRQF_SHARED); in __setup_irq()
1787 desc->depth = 1; in __setup_irq()
1790 } else if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1791 unsigned int nmsk = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1792 unsigned int omsk = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1805 desc->irq_count = 0; in __setup_irq()
1806 desc->irqs_unhandled = 0; in __setup_irq()
1812 if (shared && (desc->istate & IRQS_SPURIOUS_DISABLED)) { in __setup_irq()
1813 desc->istate &= ~IRQS_SPURIOUS_DISABLED; in __setup_irq()
1817 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1819 mutex_unlock(&desc->request_mutex); in __setup_irq()
1824 wake_up_and_wait_for_irq_thread_ready(desc, new->secondary); in __setup_irq()
1827 new->dir = NULL; in __setup_irq()
1832 if (!(new->flags & IRQF_PROBE_SHARED)) { in __setup_irq()
1834 irq, new->flags, new->name, old->flags, old->name); in __setup_irq()
1839 ret = -EBUSY; in __setup_irq()
1842 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1844 if (!desc->action) in __setup_irq()
1848 mutex_unlock(&desc->request_mutex); in __setup_irq()
1851 if (new->thread) { in __setup_irq()
1852 struct task_struct *t = new->thread; in __setup_irq()
1854 new->thread = NULL; in __setup_irq()
1857 if (new->secondary && new->secondary->thread) { in __setup_irq()
1858 struct task_struct *t = new->secondary->thread; in __setup_irq()
1860 new->secondary->thread = NULL; in __setup_irq()
1864 module_put(desc->owner); in __setup_irq()
1869 * Internal function to unregister an irqaction - used to free
1874 unsigned irq = desc->irq_data.irq; in __free_irq()
1880 mutex_lock(&desc->request_mutex); in __free_irq()
1882 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1888 action_ptr = &desc->action; in __free_irq()
1893 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_irq()
1894 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1896 mutex_unlock(&desc->request_mutex); in __free_irq()
1900 if (action->dev_id == dev_id) in __free_irq()
1902 action_ptr = &action->next; in __free_irq()
1905 /* Found it - now remove it from the list of entries: */ in __free_irq()
1906 *action_ptr = action->next; in __free_irq()
1911 if (!desc->action) { in __free_irq()
1919 if (WARN_ON_ONCE(desc->affinity_hint)) in __free_irq()
1920 desc->affinity_hint = NULL; in __free_irq()
1923 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1934 * The still held desc->request_mutex() protects against a in __free_irq()
1945 * interrupt in flight at the hardware level. in __free_irq()
1951 * It's a shared IRQ -- the driver ought to be prepared for an IRQ in __free_irq()
1958 if (action->flags & IRQF_SHARED) { in __free_irq()
1960 action->handler(irq, dev_id); in __free_irq()
1971 if (action->thread) { in __free_irq()
1972 kthread_stop_put(action->thread); in __free_irq()
1973 if (action->secondary && action->secondary->thread) in __free_irq()
1974 kthread_stop_put(action->secondary->thread); in __free_irq()
1978 if (!desc->action) { in __free_irq()
1985 * There is no interrupt on the fly anymore. Deactivate it in __free_irq()
1988 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1989 irq_domain_deactivate_irq(&desc->irq_data); in __free_irq()
1990 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1997 mutex_unlock(&desc->request_mutex); in __free_irq()
1999 irq_chip_pm_put(&desc->irq_data); in __free_irq()
2000 module_put(desc->owner); in __free_irq()
2001 kfree(action->secondary); in __free_irq()
2006 * free_irq - free an interrupt allocated with request_irq
2007 * @irq: Interrupt line to free
2010 * Remove an interrupt handler. The handler is removed and if the
2011 * interrupt line is no longer in use by any driver it is disabled.
2012 * On a shared IRQ the caller must ensure the interrupt is disabled
2017 * This function must not be called from interrupt context.
2031 if (WARN_ON(desc->affinity_notify)) in free_irq()
2032 desc->affinity_notify = NULL; in free_irq()
2040 devname = action->name; in free_irq()
2046 /* This function must be called with desc->lock held */
2051 desc->istate &= ~IRQS_NMI; in __cleanup_nmi()
2053 if (!WARN_ON(desc->action == NULL)) { in __cleanup_nmi()
2054 irq_pm_remove_action(desc, desc->action); in __cleanup_nmi()
2055 devname = desc->action->name; in __cleanup_nmi()
2056 unregister_handler_proc(irq, desc->action); in __cleanup_nmi()
2058 kfree(desc->action); in __cleanup_nmi()
2059 desc->action = NULL; in __cleanup_nmi()
2067 irq_chip_pm_put(&desc->irq_data); in __cleanup_nmi()
2068 module_put(desc->owner); in __cleanup_nmi()
2086 if (WARN_ON(desc->depth == 0)) in free_nmi()
2089 raw_spin_lock_irqsave(&desc->lock, flags); in free_nmi()
2094 raw_spin_unlock_irqrestore(&desc->lock, flags); in free_nmi()
2100 * request_threaded_irq - allocate an interrupt line
2101 * @irq: Interrupt line to allocate
2108 * @irqflags: Interrupt type flags
2112 * This call allocates interrupt resources and enables the
2113 * interrupt line and IRQ handling. From the point this
2115 * your handler function must clear any interrupt the board
2117 * and to set up the interrupt handler in the right order.
2121 * still called in hard interrupt context and has to check
2122 * whether the interrupt originates from the device. If yes it
2123 * needs to disable the interrupt on the device and return
2132 * If your interrupt is shared you must pass a non NULL dev_id
2133 * as this is required when freeing the interrupt.
2137 * IRQF_SHARED Interrupt is shared
2139 * IRQF_ONESHOT Run thread_fn with interrupt line masked
2150 return -ENOTCONN; in request_threaded_irq()
2153 * Sanity-check: shared interrupts must pass in a real dev-ID, in request_threaded_irq()
2155 * which interrupt is which (messes up the interrupt freeing in request_threaded_irq()
2159 * The sharing interrupt might request it while it's still disabled in request_threaded_irq()
2169 return -EINVAL; in request_threaded_irq()
2173 return -EINVAL; in request_threaded_irq()
2177 return -EINVAL; in request_threaded_irq()
2181 return -EINVAL; in request_threaded_irq()
2187 return -ENOMEM; in request_threaded_irq()
2189 action->handler = handler; in request_threaded_irq()
2190 action->thread_fn = thread_fn; in request_threaded_irq()
2191 action->flags = irqflags; in request_threaded_irq()
2192 action->name = devname; in request_threaded_irq()
2193 action->dev_id = dev_id; in request_threaded_irq()
2195 retval = irq_chip_pm_get(&desc->irq_data); in request_threaded_irq()
2204 irq_chip_pm_put(&desc->irq_data); in request_threaded_irq()
2205 kfree(action->secondary); in request_threaded_irq()
2212 * It's a shared IRQ -- the driver ought to be prepared for it in request_threaded_irq()
2233 * request_any_context_irq - allocate an interrupt line
2234 * @irq: Interrupt line to allocate
2237 * @flags: Interrupt type flags
2241 * This call allocates interrupt resources and enables the
2242 * interrupt line and IRQ handling. It selects either a
2256 return -ENOTCONN; in request_any_context_irq()
2260 return -EINVAL; in request_any_context_irq()
2274 * request_nmi - allocate an interrupt line for NMI delivery
2275 * @irq: Interrupt line to allocate
2278 * @irqflags: Interrupt type flags
2282 * This call allocates interrupt resources and enables the
2283 * interrupt line and IRQ handling. It sets up the IRQ line
2286 * An interrupt line delivering NMIs cannot be shared and IRQ handling
2289 * Interrupt lines requested for NMI delivering must produce per cpu
2296 * If the interrupt line cannot be used to deliver NMIs, function
2308 return -ENOTCONN; in request_nmi()
2312 return -EINVAL; in request_nmi()
2315 return -EINVAL; in request_nmi()
2318 return -EINVAL; in request_nmi()
2327 return -EINVAL; in request_nmi()
2331 return -ENOMEM; in request_nmi()
2333 action->handler = handler; in request_nmi()
2334 action->flags = irqflags | IRQF_NO_THREAD | IRQF_NOBALANCING; in request_nmi()
2335 action->name = name; in request_nmi()
2336 action->dev_id = dev_id; in request_nmi()
2338 retval = irq_chip_pm_get(&desc->irq_data); in request_nmi()
2346 raw_spin_lock_irqsave(&desc->lock, flags); in request_nmi()
2349 desc->istate |= IRQS_NMI; in request_nmi()
2353 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2354 return -EINVAL; in request_nmi()
2357 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2362 irq_chip_pm_put(&desc->irq_data); in request_nmi()
2380 * use the default for this interrupt. in enable_percpu_irq()
2384 type = irqd_get_trigger_type(&desc->irq_data); in enable_percpu_irq()
2409 * irq_percpu_is_enabled - Check whether the per cpu irq is enabled
2413 * state of a per cpu interrupt on the current cpu.
2426 is_enabled = cpumask_test_cpu(cpu, desc->percpu_enabled); in irq_percpu_is_enabled()
2466 raw_spin_lock_irqsave(&desc->lock, flags); in __free_percpu_irq()
2468 action = desc->action; in __free_percpu_irq()
2469 if (!action || action->percpu_dev_id != dev_id) { in __free_percpu_irq()
2470 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_percpu_irq()
2474 if (!cpumask_empty(desc->percpu_enabled)) { in __free_percpu_irq()
2476 irq, cpumask_first(desc->percpu_enabled)); in __free_percpu_irq()
2480 /* Found it - now remove it from the list of entries: */ in __free_percpu_irq()
2481 desc->action = NULL; in __free_percpu_irq()
2483 desc->istate &= ~IRQS_NMI; in __free_percpu_irq()
2485 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2489 irq_chip_pm_put(&desc->irq_data); in __free_percpu_irq()
2490 module_put(desc->owner); in __free_percpu_irq()
2494 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2499 * remove_percpu_irq - free a per-cpu interrupt
2500 * @irq: Interrupt line to free
2501 * @act: irqaction for the interrupt
2510 __free_percpu_irq(irq, act->percpu_dev_id); in remove_percpu_irq()
2514 * free_percpu_irq - free an interrupt allocated with request_percpu_irq
2515 * @irq: Interrupt line to free
2518 * Remove a percpu interrupt handler. The handler is removed, but
2519 * the interrupt line is not disabled. This must be done on each
2523 * This function must not be called from interrupt context.
2552 * setup_percpu_irq - setup a per-cpu interrupt
2553 * @irq: Interrupt line to setup
2554 * @act: irqaction for the interrupt
2556 * Used to statically setup per-cpu interrupts in the early boot process.
2564 return -EINVAL; in setup_percpu_irq()
2566 retval = irq_chip_pm_get(&desc->irq_data); in setup_percpu_irq()
2573 irq_chip_pm_put(&desc->irq_data); in setup_percpu_irq()
2579 * __request_percpu_irq - allocate a percpu interrupt line
2580 * @irq: Interrupt line to allocate
2582 * @flags: Interrupt type flags (IRQF_TIMER only)
2586 * This call allocates interrupt resources and enables the
2587 * interrupt on the local CPU. If the interrupt is supposed to be
2591 * Dev_id must be globally unique. It is a per-cpu variable, and
2604 return -EINVAL; in __request_percpu_irq()
2609 return -EINVAL; in __request_percpu_irq()
2612 return -EINVAL; in __request_percpu_irq()
2616 return -ENOMEM; in __request_percpu_irq()
2618 action->handler = handler; in __request_percpu_irq()
2619 action->flags = flags | IRQF_PERCPU | IRQF_NO_SUSPEND; in __request_percpu_irq()
2620 action->name = devname; in __request_percpu_irq()
2621 action->percpu_dev_id = dev_id; in __request_percpu_irq()
2623 retval = irq_chip_pm_get(&desc->irq_data); in __request_percpu_irq()
2632 irq_chip_pm_put(&desc->irq_data); in __request_percpu_irq()
2641 * request_percpu_nmi - allocate a percpu interrupt line for NMI delivery
2642 * @irq: Interrupt line to allocate
2647 * This call allocates interrupt resources for a per CPU NMI. Per CPU NMIs
2651 * Dev_id must be globally unique. It is a per-cpu variable, and
2655 * Interrupt lines requested for NMI delivering should have auto enabling
2658 * If the interrupt line cannot be used to deliver NMIs, function
2670 return -EINVAL; in request_percpu_nmi()
2678 return -EINVAL; in request_percpu_nmi()
2682 return -EINVAL; in request_percpu_nmi()
2686 return -ENOMEM; in request_percpu_nmi()
2688 action->handler = handler; in request_percpu_nmi()
2689 action->flags = IRQF_PERCPU | IRQF_NO_SUSPEND | IRQF_NO_THREAD in request_percpu_nmi()
2691 action->name = name; in request_percpu_nmi()
2692 action->percpu_dev_id = dev_id; in request_percpu_nmi()
2694 retval = irq_chip_pm_get(&desc->irq_data); in request_percpu_nmi()
2702 raw_spin_lock_irqsave(&desc->lock, flags); in request_percpu_nmi()
2703 desc->istate |= IRQS_NMI; in request_percpu_nmi()
2704 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_percpu_nmi()
2709 irq_chip_pm_put(&desc->irq_data); in request_percpu_nmi()
2717 * prepare_percpu_nmi - performs CPU local setup for NMI delivery
2718 * @irq: Interrupt line to prepare for NMI delivery
2720 * This call prepares an interrupt line to deliver NMI on the current CPU,
2721 * before that interrupt line gets enabled with enable_percpu_nmi().
2723 * As a CPU local operation, this should be called from non-preemptible
2726 * If the interrupt line cannot be used to deliver NMIs, function
2740 return -EINVAL; in prepare_percpu_nmi()
2743 KERN_ERR "prepare_percpu_nmi called for a non-NMI interrupt: irq %u\n", in prepare_percpu_nmi()
2745 ret = -EINVAL; in prepare_percpu_nmi()
2761 * teardown_percpu_nmi - undoes NMI setup of IRQ line
2762 * @irq: Interrupt line from which CPU local NMI configuration should be
2769 * As a CPU local operation, this should be called from non-preemptible
2796 int err = -EINVAL; in __irq_get_irqchip_state()
2801 return -ENODEV; in __irq_get_irqchip_state()
2802 if (chip->irq_get_irqchip_state) in __irq_get_irqchip_state()
2805 data = data->parent_data; in __irq_get_irqchip_state()
2812 err = chip->irq_get_irqchip_state(data, which, state); in __irq_get_irqchip_state()
2817 * irq_get_irqchip_state - returns the irqchip state of a interrupt.
2818 * @irq: Interrupt line that is forwarded to a VM
2823 * interrupt, returning into @state the bit corresponding to
2827 * interrupt controller has per-cpu registers.
2835 int err = -EINVAL; in irq_get_irqchip_state()
2851 * irq_set_irqchip_state - set the state of a forwarded interrupt.
2852 * @irq: Interrupt line that is forwarded to a VM
2856 * This call sets the internal irqchip state of an interrupt,
2860 * interrupt controller has per-cpu registers.
2869 int err = -EINVAL; in irq_set_irqchip_state()
2880 err = -ENODEV; in irq_set_irqchip_state()
2883 if (chip->irq_set_irqchip_state) in irq_set_irqchip_state()
2886 data = data->parent_data; in irq_set_irqchip_state()
2893 err = chip->irq_set_irqchip_state(data, which, val); in irq_set_irqchip_state()
2902 * irq_has_action - Check whether an interrupt is requested
2919 * irq_check_status_bit - Check whether bits in the irq descriptor status are set
2933 res = !!(desc->status_use_accessors & bitmask); in irq_check_status_bit()