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
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()
217 if (!chip || !chip->irq_set_affinity) in irq_do_set_affinity()
218 return -EINVAL; in irq_do_set_affinity()
220 ret = chip->irq_set_affinity(data, mask, force); in irq_do_set_affinity()
224 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_do_set_affinity()
249 return -EBUSY; in irq_set_affinity_pending()
263 if (ret == -EBUSY && !force) in irq_try_set_affinity()
275 if (!chip || !chip->irq_set_affinity) in irq_set_affinity_locked()
276 return -EINVAL; in irq_set_affinity_locked()
285 if (desc->affinity_notify) { in irq_set_affinity_locked()
286 kref_get(&desc->affinity_notify->kref); in irq_set_affinity_locked()
287 schedule_work(&desc->affinity_notify->work); in irq_set_affinity_locked()
301 return -EINVAL; in __irq_set_affinity()
303 raw_spin_lock_irqsave(&desc->lock, flags); in __irq_set_affinity()
305 raw_spin_unlock_irqrestore(&desc->lock, flags); in __irq_set_affinity()
315 return -EINVAL; in irq_set_affinity_hint()
316 desc->affinity_hint = m; in irq_set_affinity_hint()
318 /* set the initial affinity to prevent every interrupt being on CPU0 */ in irq_set_affinity_hint()
329 struct irq_desc *desc = irq_to_desc(notify->irq); in irq_affinity_notify()
336 raw_spin_lock_irqsave(&desc->lock, flags); in irq_affinity_notify()
337 if (irq_move_pending(&desc->irq_data)) in irq_affinity_notify()
340 cpumask_copy(cpumask, desc->irq_common_data.affinity); in irq_affinity_notify()
341 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_affinity_notify()
343 notify->notify(notify, cpumask); in irq_affinity_notify()
347 kref_put(¬ify->kref, notify->release); in irq_affinity_notify()
351 * irq_set_affinity_notifier - control notification of IRQ affinity changes
352 * @irq: Interrupt for which to enable/disable notification
371 if (!desc || desc->istate & IRQS_NMI) in irq_set_affinity_notifier()
372 return -EINVAL; in irq_set_affinity_notifier()
376 notify->irq = irq; in irq_set_affinity_notifier()
377 kref_init(¬ify->kref); in irq_set_affinity_notifier()
378 INIT_WORK(¬ify->work, irq_affinity_notify); in irq_set_affinity_notifier()
381 raw_spin_lock_irqsave(&desc->lock, flags); in irq_set_affinity_notifier()
382 old_notify = desc->affinity_notify; in irq_set_affinity_notifier()
383 desc->affinity_notify = notify; in irq_set_affinity_notifier()
384 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_set_affinity_notifier()
387 cancel_work_sync(&old_notify->work); in irq_set_affinity_notifier()
388 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
397 * Generic version of the affinity autoselector.
412 * Preserve the managed affinity setting and a userspace affinity in irq_setup_affinity()
415 if (irqd_affinity_is_managed(&desc->irq_data) || in irq_setup_affinity()
416 irqd_has_set(&desc->irq_data, IRQD_AFFINITY_SET)) { in irq_setup_affinity()
417 if (cpumask_intersects(desc->irq_common_data.affinity, in irq_setup_affinity()
419 set = desc->irq_common_data.affinity; in irq_setup_affinity()
421 irqd_clear(&desc->irq_data, IRQD_AFFINITY_SET); in irq_setup_affinity()
435 ret = irq_do_set_affinity(&desc->irq_data, &mask, false); in irq_setup_affinity()
440 /* Wrapper for ALPHA specific affinity selector magic */
448 * Called when a bogus affinity is set via /proc/irq
456 raw_spin_lock_irqsave(&desc->lock, flags); in irq_select_affinity_usr()
458 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_select_affinity_usr()
464 * irq_set_vcpu_affinity - Set vcpu affinity for the interrupt
465 * @irq: interrupt number to set affinity
470 * affinity for an irq. The vCPU specific data is passed from
472 * KVM -> IOMMU -> irq_set_vcpu_affinity().
480 int ret = -ENOSYS; in irq_set_vcpu_affinity()
483 return -EINVAL; in irq_set_vcpu_affinity()
488 if (chip && chip->irq_set_vcpu_affinity) in irq_set_vcpu_affinity()
491 data = data->parent_data; in irq_set_vcpu_affinity()
498 ret = chip->irq_set_vcpu_affinity(data, vcpu_info); in irq_set_vcpu_affinity()
507 if (!desc->depth++) in __disable_irq()
517 return -EINVAL; in __disable_irq_nosync()
524 * disable_irq_nosync - disable an irq without waiting
525 * @irq: Interrupt to disable
527 * Disable the selected interrupt line. Disables and Enables are
541 * disable_irq - disable an irq and wait for completion
542 * @irq: Interrupt to disable
544 * Disable the selected interrupt line. Enables and Disables are
546 * This function waits for any pending IRQ handlers for this interrupt
550 * This function may be called - with care - from IRQ context.
560 * disable_hardirq - disables an irq and waits for hardirq completion
561 * @irq: Interrupt to disable
563 * Disable the selected interrupt line. Enables and Disables are
566 * interrupt to complete before returning. If you use this function while
569 * When used to optimistically disable an interrupt from atomic context
574 * This function may be called - with care - from IRQ context.
586 * disable_nmi_nosync - disable an nmi without waiting
587 * @irq: Interrupt to disable
589 * Disable the selected interrupt line. Disables and enables are
591 * The interrupt to disable must have been requested through request_nmi.
602 switch (desc->depth) { in __enable_irq()
609 if (desc->istate & IRQS_SUSPENDED) in __enable_irq()
615 * interrupt might be marked NOAUTOEN. So irq_startup() in __enable_irq()
624 desc->depth--; in __enable_irq()
629 * enable_irq - enable handling of an irq
630 * @irq: Interrupt to enable
634 * IRQ line is re-enabled.
637 * desc->irq_data.chip->bus_lock and desc->chip->bus_sync_unlock are NULL !
646 if (WARN(!desc->irq_data.chip, in enable_irq()
657 * enable_nmi - enable handling of an nmi
658 * @irq: Interrupt to enable
660 * The interrupt to enable must have been requested through request_nmi.
663 * IRQ line is re-enabled.
673 int ret = -ENXIO; in set_irq_wake_real()
675 if (irq_desc_get_chip(desc)->flags & IRQCHIP_SKIP_SET_WAKE) in set_irq_wake_real()
678 if (desc->irq_data.chip->irq_set_wake) in set_irq_wake_real()
679 ret = desc->irq_data.chip->irq_set_wake(&desc->irq_data, on); in set_irq_wake_real()
685 * irq_set_irq_wake - control irq power management wakeup
686 * @irq: interrupt to control
691 * just as they match for non-wakeup mode support.
703 return -EINVAL; in irq_set_irq_wake()
706 if (desc->istate & IRQS_NMI) { in irq_set_irq_wake()
707 ret = -EINVAL; in irq_set_irq_wake()
711 /* wakeup-capable irqs can be shared between drivers that in irq_set_irq_wake()
715 if (desc->wake_depth++ == 0) { in irq_set_irq_wake()
718 desc->wake_depth = 0; in irq_set_irq_wake()
720 irqd_set(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
723 if (desc->wake_depth == 0) { in irq_set_irq_wake()
725 } else if (--desc->wake_depth == 0) { in irq_set_irq_wake()
728 desc->wake_depth = 1; in irq_set_irq_wake()
730 irqd_clear(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
755 if (!desc->action || in can_request_irq()
756 irqflags & desc->action->flags & IRQF_SHARED) in can_request_irq()
765 struct irq_chip *chip = desc->irq_data.chip; in __irq_set_trigger()
768 if (!chip || !chip->irq_set_type) { in __irq_set_trigger()
771 * flow-types? in __irq_set_trigger()
775 chip ? (chip->name ? : "unknown") : "unknown"); in __irq_set_trigger()
779 if (chip->flags & IRQCHIP_SET_TYPE_MASKED) { in __irq_set_trigger()
780 if (!irqd_irq_masked(&desc->irq_data)) in __irq_set_trigger()
782 if (!irqd_irq_disabled(&desc->irq_data)) in __irq_set_trigger()
788 ret = chip->irq_set_type(&desc->irq_data, flags); in __irq_set_trigger()
793 irqd_clear(&desc->irq_data, IRQD_TRIGGER_MASK); in __irq_set_trigger()
794 irqd_set(&desc->irq_data, flags); in __irq_set_trigger()
798 flags = irqd_get_trigger_type(&desc->irq_data); in __irq_set_trigger()
800 irqd_clear(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
804 irqd_set(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
811 flags, irq_desc_get_irq(desc), chip->irq_set_type); in __irq_set_trigger()
825 return -EINVAL; in irq_set_parent()
827 desc->parent_irq = parent_irq; in irq_set_parent()
836 * Default primary interrupt handler for threaded interrupts. Is
869 &action->thread_flags)) { in irq_wait_for_interrupt()
874 return -1; in irq_wait_for_interrupt()
878 &action->thread_flags)) { in irq_wait_for_interrupt()
888 * handler finished. unmask if the interrupt has not been disabled and
894 if (!(desc->istate & IRQS_ONESHOT) || in irq_finalize_oneshot()
895 action->handler == irq_forced_secondary_handler) in irq_finalize_oneshot()
899 raw_spin_lock_irq(&desc->lock); in irq_finalize_oneshot()
905 * The thread is faster done than the hard interrupt handler in irq_finalize_oneshot()
907 * interrupt can come in again and masks the line, leaves due in irq_finalize_oneshot()
911 * versus "desc->threads_onehsot |= action->thread_mask;" in in irq_finalize_oneshot()
915 if (unlikely(irqd_irq_inprogress(&desc->irq_data))) { in irq_finalize_oneshot()
916 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
927 if (test_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_finalize_oneshot()
930 desc->threads_oneshot &= ~action->thread_mask; in irq_finalize_oneshot()
932 if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) && in irq_finalize_oneshot()
933 irqd_irq_masked(&desc->irq_data)) in irq_finalize_oneshot()
937 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
943 * Check whether we need to change the affinity of the interrupt thread.
951 if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags)) in irq_thread_check_affinity()
959 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_thread_check_affinity()
963 raw_spin_lock_irq(&desc->lock); in irq_thread_check_affinity()
965 * This code is triggered unconditionally. Check the affinity in irq_thread_check_affinity()
968 if (cpumask_available(desc->irq_common_data.affinity)) { in irq_thread_check_affinity()
971 m = irq_data_get_effective_affinity_mask(&desc->irq_data); in irq_thread_check_affinity()
976 raw_spin_unlock_irq(&desc->lock); in irq_thread_check_affinity()
999 ret = action->thread_fn(action->irq, action->dev_id); in irq_forced_thread_fn()
1001 atomic_inc(&desc->threads_handled); in irq_forced_thread_fn()
1010 * preemtible - many of them need to sleep and wait for slow busses to
1018 ret = action->thread_fn(action->irq, action->dev_id); in irq_thread_fn()
1020 atomic_inc(&desc->threads_handled); in irq_thread_fn()
1028 if (atomic_dec_and_test(&desc->threads_active)) in wake_threads_waitq()
1029 wake_up(&desc->wait_for_threads); in wake_threads_waitq()
1038 if (WARN_ON_ONCE(!(current->flags & PF_EXITING))) in irq_thread_dtor()
1044 tsk->comm, tsk->pid, action->irq); in irq_thread_dtor()
1047 desc = irq_to_desc(action->irq); in irq_thread_dtor()
1050 * desc->threads_active and wake possible waiters. in irq_thread_dtor()
1052 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_thread_dtor()
1055 /* Prevent a stale desc->threads_oneshot */ in irq_thread_dtor()
1061 struct irqaction *secondary = action->secondary; in irq_wake_secondary()
1066 raw_spin_lock_irq(&desc->lock); in irq_wake_secondary()
1068 raw_spin_unlock_irq(&desc->lock); in irq_wake_secondary()
1072 * Interrupt handler thread
1078 struct irq_desc *desc = irq_to_desc(action->irq); in irq_thread()
1083 &action->thread_flags)) in irq_thread()
1116 * irq_wake_thread - wake the irq thread for the action identified by dev_id
1117 * @irq: Interrupt line
1130 raw_spin_lock_irqsave(&desc->lock, flags); in irq_wake_thread()
1132 if (action->dev_id == dev_id) { in irq_wake_thread()
1133 if (action->thread) in irq_wake_thread()
1138 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_wake_thread()
1146 if (new->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT)) in irq_setup_forced_threading()
1153 if (new->handler == irq_default_primary_handler) in irq_setup_forced_threading()
1156 new->flags |= IRQF_ONESHOT; in irq_setup_forced_threading()
1163 if (new->handler && new->thread_fn) { in irq_setup_forced_threading()
1165 new->secondary = kzalloc(sizeof(struct irqaction), GFP_KERNEL); in irq_setup_forced_threading()
1166 if (!new->secondary) in irq_setup_forced_threading()
1167 return -ENOMEM; in irq_setup_forced_threading()
1168 new->secondary->handler = irq_forced_secondary_handler; in irq_setup_forced_threading()
1169 new->secondary->thread_fn = new->thread_fn; in irq_setup_forced_threading()
1170 new->secondary->dev_id = new->dev_id; in irq_setup_forced_threading()
1171 new->secondary->irq = new->irq; in irq_setup_forced_threading()
1172 new->secondary->name = new->name; in irq_setup_forced_threading()
1175 set_bit(IRQTF_FORCED_THREAD, &new->thread_flags); in irq_setup_forced_threading()
1176 new->thread_fn = new->handler; in irq_setup_forced_threading()
1177 new->handler = irq_default_primary_handler; in irq_setup_forced_threading()
1183 struct irq_data *d = &desc->irq_data; in irq_request_resources()
1184 struct irq_chip *c = d->chip; in irq_request_resources()
1186 return c->irq_request_resources ? c->irq_request_resources(d) : 0; in irq_request_resources()
1191 struct irq_data *d = &desc->irq_data; in irq_release_resources()
1192 struct irq_chip *c = d->chip; in irq_release_resources()
1194 if (c->irq_release_resources) in irq_release_resources()
1195 c->irq_release_resources(d); in irq_release_resources()
1204 if (d->parent_data) in irq_supports_nmi()
1208 if (d->chip->irq_bus_lock || d->chip->irq_bus_sync_unlock) in irq_supports_nmi()
1211 return d->chip->flags & IRQCHIP_SUPPORTS_NMI; in irq_supports_nmi()
1217 struct irq_chip *c = d->chip; in irq_nmi_setup()
1219 return c->irq_nmi_setup ? c->irq_nmi_setup(d) : -EINVAL; in irq_nmi_setup()
1225 struct irq_chip *c = d->chip; in irq_nmi_teardown()
1227 if (c->irq_nmi_teardown) in irq_nmi_teardown()
1228 c->irq_nmi_teardown(d); in irq_nmi_teardown()
1240 t = kthread_create(irq_thread, new, "irq/%d-%s", irq, in setup_irq_thread()
1241 new->name); in setup_irq_thread()
1243 t = kthread_create(irq_thread, new, "irq/%d-s-%s", irq, in setup_irq_thread()
1244 new->name); in setup_irq_thread()
1245 param.sched_priority -= 1; in setup_irq_thread()
1255 * the thread dies to avoid that the interrupt code in setup_irq_thread()
1258 new->thread = get_task_struct(t); in setup_irq_thread()
1260 * Tell the thread to set its affinity. This is in setup_irq_thread()
1261 * important for shared interrupt handlers as we do in setup_irq_thread()
1266 * on which the requesting code placed the interrupt. in setup_irq_thread()
1268 set_bit(IRQTF_AFFINITY, &new->thread_flags); in setup_irq_thread()
1273 * Internal function to register an irqaction - typically used to
1278 * desc->request_mutex Provides serialization against a concurrent free_irq()
1280 * desc->lock Provides serialization against hard interrupts
1282 * chip_bus_lock and desc->lock are sufficient for all other management and
1283 * interrupt related functions. desc->request_mutex solely serializes
1294 return -EINVAL; in __setup_irq()
1296 if (desc->irq_data.chip == &no_irq_chip) in __setup_irq()
1297 return -ENOSYS; in __setup_irq()
1298 if (!try_module_get(desc->owner)) in __setup_irq()
1299 return -ENODEV; in __setup_irq()
1301 new->irq = irq; in __setup_irq()
1305 * then use the default for this interrupt. in __setup_irq()
1307 if (!(new->flags & IRQF_TRIGGER_MASK)) in __setup_irq()
1308 new->flags |= irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1311 * Check whether the interrupt nests into another interrupt in __setup_irq()
1316 if (!new->thread_fn) { in __setup_irq()
1317 ret = -EINVAL; in __setup_irq()
1322 * the driver for non nested interrupt handling by the in __setup_irq()
1325 new->handler = irq_nested_primary_handler; in __setup_irq()
1336 * and the interrupt does not nest into another interrupt in __setup_irq()
1339 if (new->thread_fn && !nested) { in __setup_irq()
1343 if (new->secondary) { in __setup_irq()
1344 ret = setup_irq_thread(new->secondary, irq, true); in __setup_irq()
1359 if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) in __setup_irq()
1360 new->flags &= ~IRQF_ONESHOT; in __setup_irq()
1365 * chip bus lock and desc->lock. Also protects against handing out in __setup_irq()
1369 mutex_lock(&desc->request_mutex); in __setup_irq()
1379 if (!desc->action) { in __setup_irq()
1383 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1390 * protected against a concurrent interrupt and any of the other in __setup_irq()
1392 * desc->request_mutex or the optional bus lock. in __setup_irq()
1394 raw_spin_lock_irqsave(&desc->lock, flags); in __setup_irq()
1395 old_ptr = &desc->action; in __setup_irq()
1404 * Interrupt lines used for NMIs cannot be shared. in __setup_irq()
1408 if (desc->istate & IRQS_NMI) { in __setup_irq()
1410 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1411 ret = -EINVAL; in __setup_irq()
1419 if (irqd_trigger_type_was_set(&desc->irq_data)) { in __setup_irq()
1420 oldtype = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1422 oldtype = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1423 irqd_set_trigger_type(&desc->irq_data, oldtype); in __setup_irq()
1426 if (!((old->flags & new->flags) & IRQF_SHARED) || in __setup_irq()
1427 (oldtype != (new->flags & IRQF_TRIGGER_MASK)) || in __setup_irq()
1428 ((old->flags ^ new->flags) & IRQF_ONESHOT)) in __setup_irq()
1431 /* All handlers must agree on per-cpuness */ in __setup_irq()
1432 if ((old->flags & IRQF_PERCPU) != in __setup_irq()
1433 (new->flags & IRQF_PERCPU)) in __setup_irq()
1436 /* add new interrupt at end of irq queue */ in __setup_irq()
1439 * Or all existing action->thread_mask bits, in __setup_irq()
1443 thread_mask |= old->thread_mask; in __setup_irq()
1444 old_ptr = &old->next; in __setup_irq()
1455 if (new->flags & IRQF_ONESHOT) { in __setup_irq()
1461 ret = -EBUSY; in __setup_irq()
1466 * desc->thread_active to indicate that the in __setup_irq()
1469 * completes. When all threads of a shared interrupt in __setup_irq()
1470 * line have completed desc->threads_active becomes in __setup_irq()
1471 * zero and the interrupt line is unmasked. See in __setup_irq()
1475 * interrupt handlers, then desc->threads_active is in __setup_irq()
1482 * all existing action->thread_mask bits. in __setup_irq()
1484 new->thread_mask = 1UL << ffz(thread_mask); in __setup_irq()
1486 } else if (new->handler == irq_default_primary_handler && in __setup_irq()
1487 !(desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)) { in __setup_irq()
1489 * The interrupt was requested with handler = NULL, so in __setup_irq()
1499 * say for sure which type this interrupt really in __setup_irq()
1505 ret = -EINVAL; in __setup_irq()
1510 init_waitqueue_head(&desc->wait_for_threads); in __setup_irq()
1513 if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1515 new->flags & IRQF_TRIGGER_MASK); in __setup_irq()
1522 * Activate the interrupt. That activation must happen in __setup_irq()
1525 * that. enable_irq() of an interrupt requested with in __setup_irq()
1536 desc->istate &= ~(IRQS_AUTODETECT | IRQS_SPURIOUS_DISABLED | \ in __setup_irq()
1538 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); in __setup_irq()
1540 if (new->flags & IRQF_PERCPU) { in __setup_irq()
1541 irqd_set(&desc->irq_data, IRQD_PER_CPU); in __setup_irq()
1545 if (new->flags & IRQF_ONESHOT) in __setup_irq()
1546 desc->istate |= IRQS_ONESHOT; in __setup_irq()
1549 if (new->flags & IRQF_NOBALANCING) { in __setup_irq()
1551 irqd_set(&desc->irq_data, IRQD_NO_BALANCING); in __setup_irq()
1559 * auto enable. The sharing interrupt might request in __setup_irq()
1563 WARN_ON_ONCE(new->flags & IRQF_SHARED); in __setup_irq()
1565 desc->depth = 1; in __setup_irq()
1568 } else if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1569 unsigned int nmsk = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1570 unsigned int omsk = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1583 desc->irq_count = 0; in __setup_irq()
1584 desc->irqs_unhandled = 0; in __setup_irq()
1590 if (shared && (desc->istate & IRQS_SPURIOUS_DISABLED)) { in __setup_irq()
1591 desc->istate &= ~IRQS_SPURIOUS_DISABLED; in __setup_irq()
1595 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1597 mutex_unlock(&desc->request_mutex); in __setup_irq()
1603 * when no hard interrupt wakes the thread up. in __setup_irq()
1605 if (new->thread) in __setup_irq()
1606 wake_up_process(new->thread); in __setup_irq()
1607 if (new->secondary) in __setup_irq()
1608 wake_up_process(new->secondary->thread); in __setup_irq()
1611 new->dir = NULL; in __setup_irq()
1616 if (!(new->flags & IRQF_PROBE_SHARED)) { in __setup_irq()
1618 irq, new->flags, new->name, old->flags, old->name); in __setup_irq()
1623 ret = -EBUSY; in __setup_irq()
1626 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1628 if (!desc->action) in __setup_irq()
1632 mutex_unlock(&desc->request_mutex); in __setup_irq()
1635 if (new->thread) { in __setup_irq()
1636 struct task_struct *t = new->thread; in __setup_irq()
1638 new->thread = NULL; in __setup_irq()
1642 if (new->secondary && new->secondary->thread) { in __setup_irq()
1643 struct task_struct *t = new->secondary->thread; in __setup_irq()
1645 new->secondary->thread = NULL; in __setup_irq()
1650 module_put(desc->owner); in __setup_irq()
1655 * setup_irq - setup an interrupt
1656 * @irq: Interrupt line to setup
1657 * @act: irqaction for the interrupt
1667 return -EINVAL; in setup_irq()
1669 retval = irq_chip_pm_get(&desc->irq_data); in setup_irq()
1676 irq_chip_pm_put(&desc->irq_data); in setup_irq()
1683 * Internal function to unregister an irqaction - used to free
1688 unsigned irq = desc->irq_data.irq; in __free_irq()
1694 mutex_lock(&desc->request_mutex); in __free_irq()
1696 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1702 action_ptr = &desc->action; in __free_irq()
1707 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_irq()
1708 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1710 mutex_unlock(&desc->request_mutex); in __free_irq()
1714 if (action->dev_id == dev_id) in __free_irq()
1716 action_ptr = &action->next; in __free_irq()
1719 /* Found it - now remove it from the list of entries: */ in __free_irq()
1720 *action_ptr = action->next; in __free_irq()
1725 if (!desc->action) { in __free_irq()
1733 if (WARN_ON_ONCE(desc->affinity_hint)) in __free_irq()
1734 desc->affinity_hint = NULL; in __free_irq()
1737 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1748 * The still held desc->request_mutex() protects against a in __free_irq()
1759 * interrupt in flight at the hardware level. in __free_irq()
1765 * It's a shared IRQ -- the driver ought to be prepared for an IRQ in __free_irq()
1772 if (action->flags & IRQF_SHARED) { in __free_irq()
1774 action->handler(irq, dev_id); in __free_irq()
1785 if (action->thread) { in __free_irq()
1786 kthread_stop(action->thread); in __free_irq()
1787 put_task_struct(action->thread); in __free_irq()
1788 if (action->secondary && action->secondary->thread) { in __free_irq()
1789 kthread_stop(action->secondary->thread); in __free_irq()
1790 put_task_struct(action->secondary->thread); in __free_irq()
1795 if (!desc->action) { in __free_irq()
1802 * There is no interrupt on the fly anymore. Deactivate it in __free_irq()
1805 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1806 irq_domain_deactivate_irq(&desc->irq_data); in __free_irq()
1807 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1814 mutex_unlock(&desc->request_mutex); in __free_irq()
1816 irq_chip_pm_put(&desc->irq_data); in __free_irq()
1817 module_put(desc->owner); in __free_irq()
1818 kfree(action->secondary); in __free_irq()
1823 * remove_irq - free an interrupt
1824 * @irq: Interrupt line to free
1825 * @act: irqaction for the interrupt
1834 __free_irq(desc, act->dev_id); in remove_irq()
1839 * free_irq - free an interrupt allocated with request_irq
1840 * @irq: Interrupt line to free
1843 * Remove an interrupt handler. The handler is removed and if the
1844 * interrupt line is no longer in use by any driver it is disabled.
1845 * On a shared IRQ the caller must ensure the interrupt is disabled
1850 * This function must not be called from interrupt context.
1864 if (WARN_ON(desc->affinity_notify)) in free_irq()
1865 desc->affinity_notify = NULL; in free_irq()
1873 devname = action->name; in free_irq()
1879 /* This function must be called with desc->lock held */
1884 desc->istate &= ~IRQS_NMI; in __cleanup_nmi()
1886 if (!WARN_ON(desc->action == NULL)) { in __cleanup_nmi()
1887 irq_pm_remove_action(desc, desc->action); in __cleanup_nmi()
1888 devname = desc->action->name; in __cleanup_nmi()
1889 unregister_handler_proc(irq, desc->action); in __cleanup_nmi()
1891 kfree(desc->action); in __cleanup_nmi()
1892 desc->action = NULL; in __cleanup_nmi()
1900 irq_chip_pm_put(&desc->irq_data); in __cleanup_nmi()
1901 module_put(desc->owner); in __cleanup_nmi()
1912 if (!desc || WARN_ON(!(desc->istate & IRQS_NMI))) in free_nmi()
1919 if (WARN_ON(desc->depth == 0)) in free_nmi()
1922 raw_spin_lock_irqsave(&desc->lock, flags); in free_nmi()
1927 raw_spin_unlock_irqrestore(&desc->lock, flags); in free_nmi()
1933 * request_threaded_irq - allocate an interrupt line
1934 * @irq: Interrupt line to allocate
1941 * @irqflags: Interrupt type flags
1945 * This call allocates interrupt resources and enables the
1946 * interrupt line and IRQ handling. From the point this
1948 * your handler function must clear any interrupt the board
1950 * and to set up the interrupt handler in the right order.
1954 * still called in hard interrupt context and has to check
1955 * whether the interrupt originates from the device. If yes it
1956 * needs to disable the interrupt on the device and return
1965 * If your interrupt is shared you must pass a non NULL dev_id
1966 * as this is required when freeing the interrupt.
1970 * IRQF_SHARED Interrupt is shared
1983 return -ENOTCONN; in request_threaded_irq()
1986 * Sanity-check: shared interrupts must pass in a real dev-ID, in request_threaded_irq()
1988 * which interrupt is which (messes up the interrupt freeing in request_threaded_irq()
1997 return -EINVAL; in request_threaded_irq()
2001 return -EINVAL; in request_threaded_irq()
2005 return -EINVAL; in request_threaded_irq()
2009 return -EINVAL; in request_threaded_irq()
2015 return -ENOMEM; in request_threaded_irq()
2017 action->handler = handler; in request_threaded_irq()
2018 action->thread_fn = thread_fn; in request_threaded_irq()
2019 action->flags = irqflags; in request_threaded_irq()
2020 action->name = devname; in request_threaded_irq()
2021 action->dev_id = dev_id; in request_threaded_irq()
2023 retval = irq_chip_pm_get(&desc->irq_data); in request_threaded_irq()
2032 irq_chip_pm_put(&desc->irq_data); in request_threaded_irq()
2033 kfree(action->secondary); in request_threaded_irq()
2040 * It's a shared IRQ -- the driver ought to be prepared for it in request_threaded_irq()
2061 * request_any_context_irq - allocate an interrupt line
2062 * @irq: Interrupt line to allocate
2065 * @flags: Interrupt type flags
2069 * This call allocates interrupt resources and enables the
2070 * interrupt line and IRQ handling. It selects either a
2084 return -ENOTCONN; in request_any_context_irq()
2088 return -EINVAL; in request_any_context_irq()
2102 * request_nmi - allocate an interrupt line for NMI delivery
2103 * @irq: Interrupt line to allocate
2106 * @irqflags: Interrupt type flags
2110 * This call allocates interrupt resources and enables the
2111 * interrupt line and IRQ handling. It sets up the IRQ line
2114 * An interrupt line delivering NMIs cannot be shared and IRQ handling
2117 * Interrupt lines requested for NMI delivering must produce per cpu
2124 * If the interrupt line cannot be used to deliver NMIs, function
2136 return -ENOTCONN; in request_nmi()
2140 return -EINVAL; in request_nmi()
2143 return -EINVAL; in request_nmi()
2146 return -EINVAL; in request_nmi()
2154 return -EINVAL; in request_nmi()
2158 return -ENOMEM; in request_nmi()
2160 action->handler = handler; in request_nmi()
2161 action->flags = irqflags | IRQF_NO_THREAD | IRQF_NOBALANCING; in request_nmi()
2162 action->name = name; in request_nmi()
2163 action->dev_id = dev_id; in request_nmi()
2165 retval = irq_chip_pm_get(&desc->irq_data); in request_nmi()
2173 raw_spin_lock_irqsave(&desc->lock, flags); in request_nmi()
2176 desc->istate |= IRQS_NMI; in request_nmi()
2180 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2181 return -EINVAL; in request_nmi()
2184 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2189 irq_chip_pm_put(&desc->irq_data); in request_nmi()
2207 * use the default for this interrupt. in enable_percpu_irq()
2211 type = irqd_get_trigger_type(&desc->irq_data); in enable_percpu_irq()
2236 * irq_percpu_is_enabled - Check whether the per cpu irq is enabled
2240 * state of a per cpu interrupt on the current cpu.
2253 is_enabled = cpumask_test_cpu(cpu, desc->percpu_enabled); in irq_percpu_is_enabled()
2293 raw_spin_lock_irqsave(&desc->lock, flags); in __free_percpu_irq()
2295 action = desc->action; in __free_percpu_irq()
2296 if (!action || action->percpu_dev_id != dev_id) { in __free_percpu_irq()
2297 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_percpu_irq()
2301 if (!cpumask_empty(desc->percpu_enabled)) { in __free_percpu_irq()
2303 irq, cpumask_first(desc->percpu_enabled)); in __free_percpu_irq()
2307 /* Found it - now remove it from the list of entries: */ in __free_percpu_irq()
2308 desc->action = NULL; in __free_percpu_irq()
2310 desc->istate &= ~IRQS_NMI; in __free_percpu_irq()
2312 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2316 irq_chip_pm_put(&desc->irq_data); in __free_percpu_irq()
2317 module_put(desc->owner); in __free_percpu_irq()
2321 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2326 * remove_percpu_irq - free a per-cpu interrupt
2327 * @irq: Interrupt line to free
2328 * @act: irqaction for the interrupt
2337 __free_percpu_irq(irq, act->percpu_dev_id); in remove_percpu_irq()
2341 * free_percpu_irq - free an interrupt allocated with request_percpu_irq
2342 * @irq: Interrupt line to free
2345 * Remove a percpu interrupt handler. The handler is removed, but
2346 * the interrupt line is not disabled. This must be done on each
2350 * This function must not be called from interrupt context.
2372 if (WARN_ON(!(desc->istate & IRQS_NMI))) in free_percpu_nmi()
2379 * setup_percpu_irq - setup a per-cpu interrupt
2380 * @irq: Interrupt line to setup
2381 * @act: irqaction for the interrupt
2383 * Used to statically setup per-cpu interrupts in the early boot process.
2391 return -EINVAL; in setup_percpu_irq()
2393 retval = irq_chip_pm_get(&desc->irq_data); in setup_percpu_irq()
2400 irq_chip_pm_put(&desc->irq_data); in setup_percpu_irq()
2406 * __request_percpu_irq - allocate a percpu interrupt line
2407 * @irq: Interrupt line to allocate
2409 * @flags: Interrupt type flags (IRQF_TIMER only)
2413 * This call allocates interrupt resources and enables the
2414 * interrupt on the local CPU. If the interrupt is supposed to be
2418 * Dev_id must be globally unique. It is a per-cpu variable, and
2431 return -EINVAL; in __request_percpu_irq()
2436 return -EINVAL; in __request_percpu_irq()
2439 return -EINVAL; in __request_percpu_irq()
2443 return -ENOMEM; in __request_percpu_irq()
2445 action->handler = handler; in __request_percpu_irq()
2446 action->flags = flags | IRQF_PERCPU | IRQF_NO_SUSPEND; in __request_percpu_irq()
2447 action->name = devname; in __request_percpu_irq()
2448 action->percpu_dev_id = dev_id; in __request_percpu_irq()
2450 retval = irq_chip_pm_get(&desc->irq_data); in __request_percpu_irq()
2459 irq_chip_pm_put(&desc->irq_data); in __request_percpu_irq()
2468 * request_percpu_nmi - allocate a percpu interrupt line for NMI delivery
2469 * @irq: Interrupt line to allocate
2474 * This call allocates interrupt resources for a per CPU NMI. Per CPU NMIs
2478 * Dev_id must be globally unique. It is a per-cpu variable, and
2482 * Interrupt lines requested for NMI delivering should have auto enabling
2485 * If the interrupt line cannot be used to deliver NMIs, function
2497 return -EINVAL; in request_percpu_nmi()
2505 return -EINVAL; in request_percpu_nmi()
2508 if (desc->istate & IRQS_NMI) in request_percpu_nmi()
2509 return -EINVAL; in request_percpu_nmi()
2513 return -ENOMEM; in request_percpu_nmi()
2515 action->handler = handler; in request_percpu_nmi()
2516 action->flags = IRQF_PERCPU | IRQF_NO_SUSPEND | IRQF_NO_THREAD in request_percpu_nmi()
2518 action->name = name; in request_percpu_nmi()
2519 action->percpu_dev_id = dev_id; in request_percpu_nmi()
2521 retval = irq_chip_pm_get(&desc->irq_data); in request_percpu_nmi()
2529 raw_spin_lock_irqsave(&desc->lock, flags); in request_percpu_nmi()
2530 desc->istate |= IRQS_NMI; in request_percpu_nmi()
2531 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_percpu_nmi()
2536 irq_chip_pm_put(&desc->irq_data); in request_percpu_nmi()
2544 * prepare_percpu_nmi - performs CPU local setup for NMI delivery
2545 * @irq: Interrupt line to prepare for NMI delivery
2547 * This call prepares an interrupt line to deliver NMI on the current CPU,
2548 * before that interrupt line gets enabled with enable_percpu_nmi().
2550 * As a CPU local operation, this should be called from non-preemptible
2553 * If the interrupt line cannot be used to deliver NMIs, function
2567 return -EINVAL; in prepare_percpu_nmi()
2569 if (WARN(!(desc->istate & IRQS_NMI), in prepare_percpu_nmi()
2570 KERN_ERR "prepare_percpu_nmi called for a non-NMI interrupt: irq %u\n", in prepare_percpu_nmi()
2572 ret = -EINVAL; in prepare_percpu_nmi()
2588 * teardown_percpu_nmi - undoes NMI setup of IRQ line
2589 * @irq: Interrupt line from which CPU local NMI configuration should be
2596 * As a CPU local operation, this should be called from non-preemptible
2611 if (WARN_ON(!(desc->istate & IRQS_NMI))) in teardown_percpu_nmi()
2623 int err = -EINVAL; in __irq_get_irqchip_state()
2627 if (chip->irq_get_irqchip_state) in __irq_get_irqchip_state()
2630 data = data->parent_data; in __irq_get_irqchip_state()
2637 err = chip->irq_get_irqchip_state(data, which, state); in __irq_get_irqchip_state()
2642 * irq_get_irqchip_state - returns the irqchip state of a interrupt.
2643 * @irq: Interrupt line that is forwarded to a VM
2648 * interrupt, returning into @state the bit corresponding to
2652 * interrupt controller has per-cpu registers.
2660 int err = -EINVAL; in irq_get_irqchip_state()
2676 * irq_set_irqchip_state - set the state of a forwarded interrupt.
2677 * @irq: Interrupt line that is forwarded to a VM
2681 * This call sets the internal irqchip state of an interrupt,
2685 * interrupt controller has per-cpu registers.
2694 int err = -EINVAL; in irq_set_irqchip_state()
2704 if (chip->irq_set_irqchip_state) in irq_set_irqchip_state()
2707 data = data->parent_data; in irq_set_irqchip_state()
2714 err = chip->irq_set_irqchip_state(data, which, val); in irq_set_irqchip_state()