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()
223 if (!chip || !chip->irq_set_affinity) in irq_do_set_affinity()
224 return -EINVAL; in irq_do_set_affinity()
228 * If this is a managed interrupt and housekeeping is enabled on in irq_do_set_affinity()
229 * it check whether the requested affinity mask intersects with in irq_do_set_affinity()
232 * the affinity setter from routing the interrupt to an isolated in irq_do_set_affinity()
241 * If all housekeeping CPUs in the affinity mask are offline, the in irq_do_set_affinity()
242 * interrupt will be migrated by the CPU hotplug code once a in irq_do_set_affinity()
243 * housekeeping CPU which belongs to the affinity mask comes in irq_do_set_affinity()
263 * unless we are being asked to force the affinity (in which in irq_do_set_affinity()
268 ret = chip->irq_set_affinity(data, &tmp_mask, force); in irq_do_set_affinity()
270 ret = chip->irq_set_affinity(data, mask, force); in irq_do_set_affinity()
272 ret = -EINVAL; in irq_do_set_affinity()
279 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_do_set_affinity()
304 return -EBUSY; in irq_set_affinity_pending()
318 if (ret == -EBUSY && !force) in irq_try_set_affinity()
329 * Handle irq chips which can handle affinity only in activated in irq_set_affinity_deactivated()
332 * If the interrupt is not yet activated, just store the affinity in irq_set_affinity_deactivated()
334 * driver has to make sure anyway that the interrupt is in a in irq_set_affinity_deactivated()
341 cpumask_copy(desc->irq_common_data.affinity, mask); in irq_set_affinity_deactivated()
354 if (!chip || !chip->irq_set_affinity) in irq_set_affinity_locked()
355 return -EINVAL; in irq_set_affinity_locked()
367 if (desc->affinity_notify) { in irq_set_affinity_locked()
368 kref_get(&desc->affinity_notify->kref); in irq_set_affinity_locked()
369 if (!schedule_work(&desc->affinity_notify->work)) { in irq_set_affinity_locked()
371 kref_put(&desc->affinity_notify->kref, in irq_set_affinity_locked()
372 desc->affinity_notify->release); in irq_set_affinity_locked()
381 * irq_update_affinity_desc - Update affinity management for an interrupt
382 * @irq: The interrupt number to update
383 * @affinity: Pointer to the affinity descriptor
385 * This interface can be used to configure the affinity management of
388 * There are certain limitations on when it may be used - attempts to use it
391 * managed/non-managed interrupt accounting. In addition, attempts to use it on
392 * an interrupt which is already started or which has already been configured
396 struct irq_affinity_desc *affinity) in irq_update_affinity_desc() argument
408 return -EOPNOTSUPP; in irq_update_affinity_desc()
412 return -EINVAL; in irq_update_affinity_desc()
414 /* Requires the interrupt to be shut down */ in irq_update_affinity_desc()
415 if (irqd_is_started(&desc->irq_data)) { in irq_update_affinity_desc()
416 ret = -EBUSY; in irq_update_affinity_desc()
421 if (irqd_affinity_is_managed(&desc->irq_data)) { in irq_update_affinity_desc()
422 ret = -EBUSY; in irq_update_affinity_desc()
427 * Deactivate the interrupt. That's required to undo in irq_update_affinity_desc()
430 activated = irqd_is_activated(&desc->irq_data); in irq_update_affinity_desc()
432 irq_domain_deactivate_irq(&desc->irq_data); in irq_update_affinity_desc()
434 if (affinity->is_managed) { in irq_update_affinity_desc()
435 irqd_set(&desc->irq_data, IRQD_AFFINITY_MANAGED); in irq_update_affinity_desc()
436 irqd_set(&desc->irq_data, IRQD_MANAGED_SHUTDOWN); in irq_update_affinity_desc()
439 cpumask_copy(desc->irq_common_data.affinity, &affinity->mask); in irq_update_affinity_desc()
443 irq_domain_activate_irq(&desc->irq_data, false); in irq_update_affinity_desc()
458 return -EINVAL; in __irq_set_affinity()
460 raw_spin_lock_irqsave(&desc->lock, flags); in __irq_set_affinity()
462 raw_spin_unlock_irqrestore(&desc->lock, flags); in __irq_set_affinity()
467 * irq_set_affinity - Set the irq affinity of a given irq
468 * @irq: Interrupt to set affinity
480 * irq_force_affinity - Force the irq affinity of a given irq
481 * @irq: Interrupt to set affinity
503 return -EINVAL; in __irq_apply_affinity_hint()
504 desc->affinity_hint = m; in __irq_apply_affinity_hint()
516 struct irq_desc *desc = irq_to_desc(notify->irq); in irq_affinity_notify()
523 raw_spin_lock_irqsave(&desc->lock, flags); in irq_affinity_notify()
524 if (irq_move_pending(&desc->irq_data)) in irq_affinity_notify()
527 cpumask_copy(cpumask, desc->irq_common_data.affinity); in irq_affinity_notify()
528 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_affinity_notify()
530 notify->notify(notify, cpumask); in irq_affinity_notify()
534 kref_put(&notify->kref, notify->release); in irq_affinity_notify()
538 * irq_set_affinity_notifier - control notification of IRQ affinity changes
539 * @irq: Interrupt for which to enable/disable notification
558 if (!desc || desc->istate & IRQS_NMI) in irq_set_affinity_notifier()
559 return -EINVAL; in irq_set_affinity_notifier()
563 notify->irq = irq; in irq_set_affinity_notifier()
564 kref_init(&notify->kref); in irq_set_affinity_notifier()
565 INIT_WORK(&notify->work, irq_affinity_notify); in irq_set_affinity_notifier()
568 raw_spin_lock_irqsave(&desc->lock, flags); in irq_set_affinity_notifier()
569 old_notify = desc->affinity_notify; in irq_set_affinity_notifier()
570 desc->affinity_notify = notify; in irq_set_affinity_notifier()
571 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_set_affinity_notifier()
574 if (cancel_work_sync(&old_notify->work)) { in irq_set_affinity_notifier()
576 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
578 kref_put(&old_notify->kref, old_notify->release); in irq_set_affinity_notifier()
587 * Generic version of the affinity autoselector.
602 * Preserve the managed affinity setting and a userspace affinity in irq_setup_affinity()
605 if (irqd_affinity_is_managed(&desc->irq_data) || in irq_setup_affinity()
606 irqd_has_set(&desc->irq_data, IRQD_AFFINITY_SET)) { in irq_setup_affinity()
607 if (cpumask_intersects(desc->irq_common_data.affinity, in irq_setup_affinity()
609 set = desc->irq_common_data.affinity; in irq_setup_affinity()
611 irqd_clear(&desc->irq_data, IRQD_AFFINITY_SET); in irq_setup_affinity()
625 ret = irq_do_set_affinity(&desc->irq_data, &mask, false); in irq_setup_affinity()
630 /* Wrapper for ALPHA specific affinity selector magic */
640 * irq_set_vcpu_affinity - Set vcpu affinity for the interrupt
641 * @irq: interrupt number to set affinity
646 * affinity for an irq. The vCPU specific data is passed from
648 * KVM -> IOMMU -> irq_set_vcpu_affinity().
656 int ret = -ENOSYS; in irq_set_vcpu_affinity()
659 return -EINVAL; in irq_set_vcpu_affinity()
664 if (chip && chip->irq_set_vcpu_affinity) in irq_set_vcpu_affinity()
667 data = data->parent_data; in irq_set_vcpu_affinity()
674 ret = chip->irq_set_vcpu_affinity(data, vcpu_info); in irq_set_vcpu_affinity()
683 if (!desc->depth++) in __disable_irq()
693 return -EINVAL; in __disable_irq_nosync()
700 * disable_irq_nosync - disable an irq without waiting
701 * @irq: Interrupt to disable
703 * Disable the selected interrupt line. Disables and Enables are
717 * disable_irq - disable an irq and wait for completion
718 * @irq: Interrupt to disable
720 * Disable the selected interrupt line. Enables and Disables are
722 * This function waits for any pending IRQ handlers for this interrupt
726 * This function may be called - with care - from IRQ context.
736 * disable_hardirq - disables an irq and waits for hardirq completion
737 * @irq: Interrupt to disable
739 * Disable the selected interrupt line. Enables and Disables are
742 * interrupt to complete before returning. If you use this function while
745 * When used to optimistically disable an interrupt from atomic context
750 * This function may be called - with care - from IRQ context.
762 * disable_nmi_nosync - disable an nmi without waiting
763 * @irq: Interrupt to disable
765 * Disable the selected interrupt line. Disables and enables are
767 * The interrupt to disable must have been requested through request_nmi.
778 switch (desc->depth) { in __enable_irq()
785 if (desc->istate & IRQS_SUSPENDED) in __enable_irq()
791 * interrupt might be marked NOAUTOEN. So irq_startup() in __enable_irq()
800 desc->depth--; in __enable_irq()
805 * enable_irq - enable handling of an irq
806 * @irq: Interrupt to enable
810 * IRQ line is re-enabled.
813 * desc->irq_data.chip->bus_lock and desc->chip->bus_sync_unlock are NULL !
822 if (WARN(!desc->irq_data.chip, in enable_irq()
833 * enable_nmi - enable handling of an nmi
834 * @irq: Interrupt to enable
836 * The interrupt to enable must have been requested through request_nmi.
839 * IRQ line is re-enabled.
849 int ret = -ENXIO; in set_irq_wake_real()
851 if (irq_desc_get_chip(desc)->flags & IRQCHIP_SKIP_SET_WAKE) in set_irq_wake_real()
854 if (desc->irq_data.chip->irq_set_wake) in set_irq_wake_real()
855 ret = desc->irq_data.chip->irq_set_wake(&desc->irq_data, on); in set_irq_wake_real()
861 * irq_set_irq_wake - control irq power management wakeup
862 * @irq: interrupt to control
867 * just as they match for non-wakeup mode support.
886 return -EINVAL; in irq_set_irq_wake()
889 if (desc->istate & IRQS_NMI) { in irq_set_irq_wake()
890 ret = -EINVAL; in irq_set_irq_wake()
894 /* wakeup-capable irqs can be shared between drivers that in irq_set_irq_wake()
898 if (desc->wake_depth++ == 0) { in irq_set_irq_wake()
901 desc->wake_depth = 0; in irq_set_irq_wake()
903 irqd_set(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
906 if (desc->wake_depth == 0) { in irq_set_irq_wake()
908 } else if (--desc->wake_depth == 0) { in irq_set_irq_wake()
911 desc->wake_depth = 1; in irq_set_irq_wake()
913 irqd_clear(&desc->irq_data, IRQD_WAKEUP_STATE); in irq_set_irq_wake()
938 if (!desc->action || in can_request_irq()
939 irqflags & desc->action->flags & IRQF_SHARED) in can_request_irq()
948 struct irq_chip *chip = desc->irq_data.chip; in __irq_set_trigger()
951 if (!chip || !chip->irq_set_type) { in __irq_set_trigger()
954 * flow-types? in __irq_set_trigger()
958 chip ? (chip->name ? : "unknown") : "unknown"); in __irq_set_trigger()
962 if (chip->flags & IRQCHIP_SET_TYPE_MASKED) { in __irq_set_trigger()
963 if (!irqd_irq_masked(&desc->irq_data)) in __irq_set_trigger()
965 if (!irqd_irq_disabled(&desc->irq_data)) in __irq_set_trigger()
971 ret = chip->irq_set_type(&desc->irq_data, flags); in __irq_set_trigger()
976 irqd_clear(&desc->irq_data, IRQD_TRIGGER_MASK); in __irq_set_trigger()
977 irqd_set(&desc->irq_data, flags); in __irq_set_trigger()
981 flags = irqd_get_trigger_type(&desc->irq_data); in __irq_set_trigger()
983 irqd_clear(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
987 irqd_set(&desc->irq_data, IRQD_LEVEL); in __irq_set_trigger()
994 flags, irq_desc_get_irq(desc), chip->irq_set_type); in __irq_set_trigger()
1008 return -EINVAL; in irq_set_parent()
1010 desc->parent_irq = parent_irq; in irq_set_parent()
1019 * Default primary interrupt handler for threaded interrupts. Is
1052 &action->thread_flags)) { in irq_wait_for_interrupt()
1057 return -1; in irq_wait_for_interrupt()
1061 &action->thread_flags)) { in irq_wait_for_interrupt()
1071 * handler finished. unmask if the interrupt has not been disabled and
1077 if (!(desc->istate & IRQS_ONESHOT) || in irq_finalize_oneshot()
1078 action->handler == irq_forced_secondary_handler) in irq_finalize_oneshot()
1082 raw_spin_lock_irq(&desc->lock); in irq_finalize_oneshot()
1088 * The thread is faster done than the hard interrupt handler in irq_finalize_oneshot()
1090 * interrupt can come in again and masks the line, leaves due in irq_finalize_oneshot()
1094 * versus "desc->threads_oneshot |= action->thread_mask;" in in irq_finalize_oneshot()
1098 if (unlikely(irqd_irq_inprogress(&desc->irq_data))) { in irq_finalize_oneshot()
1099 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1110 if (test_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_finalize_oneshot()
1113 desc->threads_oneshot &= ~action->thread_mask; in irq_finalize_oneshot()
1115 if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) && in irq_finalize_oneshot()
1116 irqd_irq_masked(&desc->irq_data)) in irq_finalize_oneshot()
1120 raw_spin_unlock_irq(&desc->lock); in irq_finalize_oneshot()
1126 * Check whether we need to change the affinity of the interrupt thread.
1134 if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags)) in irq_thread_check_affinity()
1142 set_bit(IRQTF_AFFINITY, &action->thread_flags); in irq_thread_check_affinity()
1146 raw_spin_lock_irq(&desc->lock); in irq_thread_check_affinity()
1148 * This code is triggered unconditionally. Check the affinity in irq_thread_check_affinity()
1151 if (cpumask_available(desc->irq_common_data.affinity)) { in irq_thread_check_affinity()
1154 m = irq_data_get_effective_affinity_mask(&desc->irq_data); in irq_thread_check_affinity()
1159 raw_spin_unlock_irq(&desc->lock); in irq_thread_check_affinity()
1184 ret = action->thread_fn(action->irq, action->dev_id); in irq_forced_thread_fn()
1186 atomic_inc(&desc->threads_handled); in irq_forced_thread_fn()
1197 * preemptible - many of them need to sleep and wait for slow busses to
1205 ret = action->thread_fn(action->irq, action->dev_id); in irq_thread_fn()
1207 atomic_inc(&desc->threads_handled); in irq_thread_fn()
1215 if (atomic_dec_and_test(&desc->threads_active)) in wake_threads_waitq()
1216 wake_up(&desc->wait_for_threads); in wake_threads_waitq()
1225 if (WARN_ON_ONCE(!(current->flags & PF_EXITING))) in irq_thread_dtor()
1231 tsk->comm, tsk->pid, action->irq); in irq_thread_dtor()
1234 desc = irq_to_desc(action->irq); in irq_thread_dtor()
1237 * desc->threads_active and wake possible waiters. in irq_thread_dtor()
1239 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags)) in irq_thread_dtor()
1242 /* Prevent a stale desc->threads_oneshot */ in irq_thread_dtor()
1248 struct irqaction *secondary = action->secondary; in irq_wake_secondary()
1253 raw_spin_lock_irq(&desc->lock); in irq_wake_secondary()
1255 raw_spin_unlock_irq(&desc->lock); in irq_wake_secondary()
1259 * Internal function to notify that a interrupt thread is ready.
1264 set_bit(IRQTF_READY, &action->thread_flags); in irq_thread_set_ready()
1265 wake_up(&desc->wait_for_threads); in irq_thread_set_ready()
1269 * Internal function to wake up a interrupt thread and wait until it is
1275 if (!action || !action->thread) in wake_up_and_wait_for_irq_thread_ready()
1278 wake_up_process(action->thread); in wake_up_and_wait_for_irq_thread_ready()
1279 wait_event(desc->wait_for_threads, in wake_up_and_wait_for_irq_thread_ready()
1280 test_bit(IRQTF_READY, &action->thread_flags)); in wake_up_and_wait_for_irq_thread_ready()
1284 * Interrupt handler thread
1290 struct irq_desc *desc = irq_to_desc(action->irq); in irq_thread()
1299 &action->thread_flags)) in irq_thread()
1332 * irq_wake_thread - wake the irq thread for the action identified by dev_id
1333 * @irq: Interrupt line
1346 raw_spin_lock_irqsave(&desc->lock, flags); in irq_wake_thread()
1348 if (action->dev_id == dev_id) { in irq_wake_thread()
1349 if (action->thread) in irq_wake_thread()
1354 raw_spin_unlock_irqrestore(&desc->lock, flags); in irq_wake_thread()
1362 if (new->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT)) in irq_setup_forced_threading()
1369 if (new->handler == irq_default_primary_handler) in irq_setup_forced_threading()
1372 new->flags |= IRQF_ONESHOT; in irq_setup_forced_threading()
1379 if (new->handler && new->thread_fn) { in irq_setup_forced_threading()
1381 new->secondary = kzalloc(sizeof(struct irqaction), GFP_KERNEL); in irq_setup_forced_threading()
1382 if (!new->secondary) in irq_setup_forced_threading()
1383 return -ENOMEM; in irq_setup_forced_threading()
1384 new->secondary->handler = irq_forced_secondary_handler; in irq_setup_forced_threading()
1385 new->secondary->thread_fn = new->thread_fn; in irq_setup_forced_threading()
1386 new->secondary->dev_id = new->dev_id; in irq_setup_forced_threading()
1387 new->secondary->irq = new->irq; in irq_setup_forced_threading()
1388 new->secondary->name = new->name; in irq_setup_forced_threading()
1391 set_bit(IRQTF_FORCED_THREAD, &new->thread_flags); in irq_setup_forced_threading()
1392 new->thread_fn = new->handler; in irq_setup_forced_threading()
1393 new->handler = irq_default_primary_handler; in irq_setup_forced_threading()
1399 struct irq_data *d = &desc->irq_data; in irq_request_resources()
1400 struct irq_chip *c = d->chip; in irq_request_resources()
1402 return c->irq_request_resources ? c->irq_request_resources(d) : 0; in irq_request_resources()
1407 struct irq_data *d = &desc->irq_data; in irq_release_resources()
1408 struct irq_chip *c = d->chip; in irq_release_resources()
1410 if (c->irq_release_resources) in irq_release_resources()
1411 c->irq_release_resources(d); in irq_release_resources()
1420 if (d->parent_data) in irq_supports_nmi()
1424 if (d->chip->irq_bus_lock || d->chip->irq_bus_sync_unlock) in irq_supports_nmi()
1427 return d->chip->flags & IRQCHIP_SUPPORTS_NMI; in irq_supports_nmi()
1433 struct irq_chip *c = d->chip; in irq_nmi_setup()
1435 return c->irq_nmi_setup ? c->irq_nmi_setup(d) : -EINVAL; in irq_nmi_setup()
1441 struct irq_chip *c = d->chip; in irq_nmi_teardown()
1443 if (c->irq_nmi_teardown) in irq_nmi_teardown()
1444 c->irq_nmi_teardown(d); in irq_nmi_teardown()
1453 t = kthread_create(irq_thread, new, "irq/%d-%s", irq, in setup_irq_thread()
1454 new->name); in setup_irq_thread()
1456 t = kthread_create(irq_thread, new, "irq/%d-s-%s", irq, in setup_irq_thread()
1457 new->name); in setup_irq_thread()
1465 * the thread dies to avoid that the interrupt code in setup_irq_thread()
1468 new->thread = get_task_struct(t); in setup_irq_thread()
1470 * Tell the thread to set its affinity. This is in setup_irq_thread()
1471 * important for shared interrupt handlers as we do in setup_irq_thread()
1476 * on which the requesting code placed the interrupt. in setup_irq_thread()
1478 set_bit(IRQTF_AFFINITY, &new->thread_flags); in setup_irq_thread()
1483 * Internal function to register an irqaction - typically used to
1488 * desc->request_mutex Provides serialization against a concurrent free_irq()
1490 * desc->lock Provides serialization against hard interrupts
1492 * chip_bus_lock and desc->lock are sufficient for all other management and
1493 * interrupt related functions. desc->request_mutex solely serializes
1504 return -EINVAL; in __setup_irq()
1506 if (desc->irq_data.chip == &no_irq_chip) in __setup_irq()
1507 return -ENOSYS; in __setup_irq()
1508 if (!try_module_get(desc->owner)) in __setup_irq()
1509 return -ENODEV; in __setup_irq()
1511 new->irq = irq; in __setup_irq()
1515 * then use the default for this interrupt. in __setup_irq()
1517 if (!(new->flags & IRQF_TRIGGER_MASK)) in __setup_irq()
1518 new->flags |= irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1521 * Check whether the interrupt nests into another interrupt in __setup_irq()
1526 if (!new->thread_fn) { in __setup_irq()
1527 ret = -EINVAL; in __setup_irq()
1532 * the driver for non nested interrupt handling by the in __setup_irq()
1535 new->handler = irq_nested_primary_handler; in __setup_irq()
1546 * and the interrupt does not nest into another interrupt in __setup_irq()
1549 if (new->thread_fn && !nested) { in __setup_irq()
1553 if (new->secondary) { in __setup_irq()
1554 ret = setup_irq_thread(new->secondary, irq, true); in __setup_irq()
1569 if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) in __setup_irq()
1570 new->flags &= ~IRQF_ONESHOT; in __setup_irq()
1575 * chip bus lock and desc->lock. Also protects against handing out in __setup_irq()
1579 mutex_lock(&desc->request_mutex); in __setup_irq()
1589 if (!desc->action) { in __setup_irq()
1593 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1600 * protected against a concurrent interrupt and any of the other in __setup_irq()
1602 * desc->request_mutex or the optional bus lock. in __setup_irq()
1604 raw_spin_lock_irqsave(&desc->lock, flags); in __setup_irq()
1605 old_ptr = &desc->action; in __setup_irq()
1614 * Interrupt lines used for NMIs cannot be shared. in __setup_irq()
1618 if (desc->istate & IRQS_NMI) { in __setup_irq()
1620 new->name, irq, desc->irq_data.chip->name); in __setup_irq()
1621 ret = -EINVAL; in __setup_irq()
1629 if (irqd_trigger_type_was_set(&desc->irq_data)) { in __setup_irq()
1630 oldtype = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1632 oldtype = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1633 irqd_set_trigger_type(&desc->irq_data, oldtype); in __setup_irq()
1636 if (!((old->flags & new->flags) & IRQF_SHARED) || in __setup_irq()
1637 (oldtype != (new->flags & IRQF_TRIGGER_MASK)) || in __setup_irq()
1638 ((old->flags ^ new->flags) & IRQF_ONESHOT)) in __setup_irq()
1641 /* All handlers must agree on per-cpuness */ in __setup_irq()
1642 if ((old->flags & IRQF_PERCPU) != in __setup_irq()
1643 (new->flags & IRQF_PERCPU)) in __setup_irq()
1646 /* add new interrupt at end of irq queue */ in __setup_irq()
1649 * Or all existing action->thread_mask bits, in __setup_irq()
1653 thread_mask |= old->thread_mask; in __setup_irq()
1654 old_ptr = &old->next; in __setup_irq()
1665 if (new->flags & IRQF_ONESHOT) { in __setup_irq()
1671 ret = -EBUSY; in __setup_irq()
1676 * desc->thread_active to indicate that the in __setup_irq()
1679 * completes. When all threads of a shared interrupt in __setup_irq()
1680 * line have completed desc->threads_active becomes in __setup_irq()
1681 * zero and the interrupt line is unmasked. See in __setup_irq()
1685 * interrupt handlers, then desc->threads_active is in __setup_irq()
1692 * all existing action->thread_mask bits. in __setup_irq()
1694 new->thread_mask = 1UL << ffz(thread_mask); in __setup_irq()
1696 } else if (new->handler == irq_default_primary_handler && in __setup_irq()
1697 !(desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)) { in __setup_irq()
1699 * The interrupt was requested with handler = NULL, so in __setup_irq()
1709 * say for sure which type this interrupt really in __setup_irq()
1714 new->name, irq); in __setup_irq()
1715 ret = -EINVAL; in __setup_irq()
1721 if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1723 new->flags & IRQF_TRIGGER_MASK); in __setup_irq()
1730 * Activate the interrupt. That activation must happen in __setup_irq()
1733 * that. enable_irq() of an interrupt requested with in __setup_irq()
1744 desc->istate &= ~(IRQS_AUTODETECT | IRQS_SPURIOUS_DISABLED | \ in __setup_irq()
1746 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS); in __setup_irq()
1748 if (new->flags & IRQF_PERCPU) { in __setup_irq()
1749 irqd_set(&desc->irq_data, IRQD_PER_CPU); in __setup_irq()
1751 if (new->flags & IRQF_NO_DEBUG) in __setup_irq()
1758 if (new->flags & IRQF_ONESHOT) in __setup_irq()
1759 desc->istate |= IRQS_ONESHOT; in __setup_irq()
1762 if (new->flags & IRQF_NOBALANCING) { in __setup_irq()
1764 irqd_set(&desc->irq_data, IRQD_NO_BALANCING); in __setup_irq()
1767 if (!(new->flags & IRQF_NO_AUTOEN) && in __setup_irq()
1773 * auto enable. The sharing interrupt might request in __setup_irq()
1777 WARN_ON_ONCE(new->flags & IRQF_SHARED); in __setup_irq()
1779 desc->depth = 1; in __setup_irq()
1782 } else if (new->flags & IRQF_TRIGGER_MASK) { in __setup_irq()
1783 unsigned int nmsk = new->flags & IRQF_TRIGGER_MASK; in __setup_irq()
1784 unsigned int omsk = irqd_get_trigger_type(&desc->irq_data); in __setup_irq()
1797 desc->irq_count = 0; in __setup_irq()
1798 desc->irqs_unhandled = 0; in __setup_irq()
1804 if (shared && (desc->istate & IRQS_SPURIOUS_DISABLED)) { in __setup_irq()
1805 desc->istate &= ~IRQS_SPURIOUS_DISABLED; in __setup_irq()
1809 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1811 mutex_unlock(&desc->request_mutex); in __setup_irq()
1816 wake_up_and_wait_for_irq_thread_ready(desc, new->secondary); in __setup_irq()
1819 new->dir = NULL; in __setup_irq()
1824 if (!(new->flags & IRQF_PROBE_SHARED)) { in __setup_irq()
1826 irq, new->flags, new->name, old->flags, old->name); in __setup_irq()
1831 ret = -EBUSY; in __setup_irq()
1834 raw_spin_unlock_irqrestore(&desc->lock, flags); in __setup_irq()
1836 if (!desc->action) in __setup_irq()
1840 mutex_unlock(&desc->request_mutex); in __setup_irq()
1843 if (new->thread) { in __setup_irq()
1844 struct task_struct *t = new->thread; in __setup_irq()
1846 new->thread = NULL; in __setup_irq()
1850 if (new->secondary && new->secondary->thread) { in __setup_irq()
1851 struct task_struct *t = new->secondary->thread; in __setup_irq()
1853 new->secondary->thread = NULL; in __setup_irq()
1858 module_put(desc->owner); in __setup_irq()
1863 * Internal function to unregister an irqaction - used to free
1868 unsigned irq = desc->irq_data.irq; in __free_irq()
1874 mutex_lock(&desc->request_mutex); in __free_irq()
1876 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1882 action_ptr = &desc->action; in __free_irq()
1887 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_irq()
1888 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1890 mutex_unlock(&desc->request_mutex); in __free_irq()
1894 if (action->dev_id == dev_id) in __free_irq()
1896 action_ptr = &action->next; in __free_irq()
1899 /* Found it - now remove it from the list of entries: */ in __free_irq()
1900 *action_ptr = action->next; in __free_irq()
1905 if (!desc->action) { in __free_irq()
1913 if (WARN_ON_ONCE(desc->affinity_hint)) in __free_irq()
1914 desc->affinity_hint = NULL; in __free_irq()
1917 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1928 * The still held desc->request_mutex() protects against a in __free_irq()
1939 * interrupt in flight at the hardware level. in __free_irq()
1945 * It's a shared IRQ -- the driver ought to be prepared for an IRQ in __free_irq()
1952 if (action->flags & IRQF_SHARED) { in __free_irq()
1954 action->handler(irq, dev_id); in __free_irq()
1965 if (action->thread) { in __free_irq()
1966 kthread_stop(action->thread); in __free_irq()
1967 put_task_struct(action->thread); in __free_irq()
1968 if (action->secondary && action->secondary->thread) { in __free_irq()
1969 kthread_stop(action->secondary->thread); in __free_irq()
1970 put_task_struct(action->secondary->thread); in __free_irq()
1975 if (!desc->action) { in __free_irq()
1982 * There is no interrupt on the fly anymore. Deactivate it in __free_irq()
1985 raw_spin_lock_irqsave(&desc->lock, flags); in __free_irq()
1986 irq_domain_deactivate_irq(&desc->irq_data); in __free_irq()
1987 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_irq()
1994 mutex_unlock(&desc->request_mutex); in __free_irq()
1996 irq_chip_pm_put(&desc->irq_data); in __free_irq()
1997 module_put(desc->owner); in __free_irq()
1998 kfree(action->secondary); in __free_irq()
2003 * free_irq - free an interrupt allocated with request_irq
2004 * @irq: Interrupt line to free
2007 * Remove an interrupt handler. The handler is removed and if the
2008 * interrupt line is no longer in use by any driver it is disabled.
2009 * On a shared IRQ the caller must ensure the interrupt is disabled
2014 * This function must not be called from interrupt context.
2028 if (WARN_ON(desc->affinity_notify)) in free_irq()
2029 desc->affinity_notify = NULL; in free_irq()
2037 devname = action->name; in free_irq()
2043 /* This function must be called with desc->lock held */
2048 desc->istate &= ~IRQS_NMI; in __cleanup_nmi()
2050 if (!WARN_ON(desc->action == NULL)) { in __cleanup_nmi()
2051 irq_pm_remove_action(desc, desc->action); in __cleanup_nmi()
2052 devname = desc->action->name; in __cleanup_nmi()
2053 unregister_handler_proc(irq, desc->action); in __cleanup_nmi()
2055 kfree(desc->action); in __cleanup_nmi()
2056 desc->action = NULL; in __cleanup_nmi()
2064 irq_chip_pm_put(&desc->irq_data); in __cleanup_nmi()
2065 module_put(desc->owner); in __cleanup_nmi()
2076 if (!desc || WARN_ON(!(desc->istate & IRQS_NMI))) in free_nmi()
2083 if (WARN_ON(desc->depth == 0)) in free_nmi()
2086 raw_spin_lock_irqsave(&desc->lock, flags); in free_nmi()
2091 raw_spin_unlock_irqrestore(&desc->lock, flags); in free_nmi()
2097 * request_threaded_irq - allocate an interrupt line
2098 * @irq: Interrupt line to allocate
2105 * @irqflags: Interrupt type flags
2109 * This call allocates interrupt resources and enables the
2110 * interrupt line and IRQ handling. From the point this
2112 * your handler function must clear any interrupt the board
2114 * and to set up the interrupt handler in the right order.
2118 * still called in hard interrupt context and has to check
2119 * whether the interrupt originates from the device. If yes it
2120 * needs to disable the interrupt on the device and return
2129 * If your interrupt is shared you must pass a non NULL dev_id
2130 * as this is required when freeing the interrupt.
2134 * IRQF_SHARED Interrupt is shared
2136 * IRQF_ONESHOT Run thread_fn with interrupt line masked
2147 return -ENOTCONN; in request_threaded_irq()
2150 * Sanity-check: shared interrupts must pass in a real dev-ID, in request_threaded_irq()
2152 * which interrupt is which (messes up the interrupt freeing in request_threaded_irq()
2156 * The sharing interrupt might request it while it's still disabled in request_threaded_irq()
2166 return -EINVAL; in request_threaded_irq()
2170 return -EINVAL; in request_threaded_irq()
2174 return -EINVAL; in request_threaded_irq()
2178 return -EINVAL; in request_threaded_irq()
2184 return -ENOMEM; in request_threaded_irq()
2186 action->handler = handler; in request_threaded_irq()
2187 action->thread_fn = thread_fn; in request_threaded_irq()
2188 action->flags = irqflags; in request_threaded_irq()
2189 action->name = devname; in request_threaded_irq()
2190 action->dev_id = dev_id; in request_threaded_irq()
2192 retval = irq_chip_pm_get(&desc->irq_data); in request_threaded_irq()
2201 irq_chip_pm_put(&desc->irq_data); in request_threaded_irq()
2202 kfree(action->secondary); in request_threaded_irq()
2209 * It's a shared IRQ -- the driver ought to be prepared for it in request_threaded_irq()
2230 * request_any_context_irq - allocate an interrupt line
2231 * @irq: Interrupt line to allocate
2234 * @flags: Interrupt type flags
2238 * This call allocates interrupt resources and enables the
2239 * interrupt line and IRQ handling. It selects either a
2253 return -ENOTCONN; in request_any_context_irq()
2257 return -EINVAL; in request_any_context_irq()
2271 * request_nmi - allocate an interrupt line for NMI delivery
2272 * @irq: Interrupt line to allocate
2275 * @irqflags: Interrupt type flags
2279 * This call allocates interrupt resources and enables the
2280 * interrupt line and IRQ handling. It sets up the IRQ line
2283 * An interrupt line delivering NMIs cannot be shared and IRQ handling
2286 * Interrupt lines requested for NMI delivering must produce per cpu
2293 * If the interrupt line cannot be used to deliver NMIs, function
2305 return -ENOTCONN; in request_nmi()
2309 return -EINVAL; in request_nmi()
2312 return -EINVAL; in request_nmi()
2315 return -EINVAL; in request_nmi()
2324 return -EINVAL; in request_nmi()
2328 return -ENOMEM; in request_nmi()
2330 action->handler = handler; in request_nmi()
2331 action->flags = irqflags | IRQF_NO_THREAD | IRQF_NOBALANCING; in request_nmi()
2332 action->name = name; in request_nmi()
2333 action->dev_id = dev_id; in request_nmi()
2335 retval = irq_chip_pm_get(&desc->irq_data); in request_nmi()
2343 raw_spin_lock_irqsave(&desc->lock, flags); in request_nmi()
2346 desc->istate |= IRQS_NMI; in request_nmi()
2350 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2351 return -EINVAL; in request_nmi()
2354 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_nmi()
2359 irq_chip_pm_put(&desc->irq_data); in request_nmi()
2377 * use the default for this interrupt. in enable_percpu_irq()
2381 type = irqd_get_trigger_type(&desc->irq_data); in enable_percpu_irq()
2406 * irq_percpu_is_enabled - Check whether the per cpu irq is enabled
2410 * state of a per cpu interrupt on the current cpu.
2423 is_enabled = cpumask_test_cpu(cpu, desc->percpu_enabled); in irq_percpu_is_enabled()
2463 raw_spin_lock_irqsave(&desc->lock, flags); in __free_percpu_irq()
2465 action = desc->action; in __free_percpu_irq()
2466 if (!action || action->percpu_dev_id != dev_id) { in __free_percpu_irq()
2467 WARN(1, "Trying to free already-free IRQ %d\n", irq); in __free_percpu_irq()
2471 if (!cpumask_empty(desc->percpu_enabled)) { in __free_percpu_irq()
2473 irq, cpumask_first(desc->percpu_enabled)); in __free_percpu_irq()
2477 /* Found it - now remove it from the list of entries: */ in __free_percpu_irq()
2478 desc->action = NULL; in __free_percpu_irq()
2480 desc->istate &= ~IRQS_NMI; in __free_percpu_irq()
2482 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2486 irq_chip_pm_put(&desc->irq_data); in __free_percpu_irq()
2487 module_put(desc->owner); in __free_percpu_irq()
2491 raw_spin_unlock_irqrestore(&desc->lock, flags); in __free_percpu_irq()
2496 * remove_percpu_irq - free a per-cpu interrupt
2497 * @irq: Interrupt line to free
2498 * @act: irqaction for the interrupt
2507 __free_percpu_irq(irq, act->percpu_dev_id); in remove_percpu_irq()
2511 * free_percpu_irq - free an interrupt allocated with request_percpu_irq
2512 * @irq: Interrupt line to free
2515 * Remove a percpu interrupt handler. The handler is removed, but
2516 * the interrupt line is not disabled. This must be done on each
2520 * This function must not be called from interrupt context.
2542 if (WARN_ON(!(desc->istate & IRQS_NMI))) in free_percpu_nmi()
2549 * setup_percpu_irq - setup a per-cpu interrupt
2550 * @irq: Interrupt line to setup
2551 * @act: irqaction for the interrupt
2553 * Used to statically setup per-cpu interrupts in the early boot process.
2561 return -EINVAL; in setup_percpu_irq()
2563 retval = irq_chip_pm_get(&desc->irq_data); in setup_percpu_irq()
2570 irq_chip_pm_put(&desc->irq_data); in setup_percpu_irq()
2576 * __request_percpu_irq - allocate a percpu interrupt line
2577 * @irq: Interrupt line to allocate
2579 * @flags: Interrupt type flags (IRQF_TIMER only)
2583 * This call allocates interrupt resources and enables the
2584 * interrupt on the local CPU. If the interrupt is supposed to be
2588 * Dev_id must be globally unique. It is a per-cpu variable, and
2601 return -EINVAL; in __request_percpu_irq()
2606 return -EINVAL; in __request_percpu_irq()
2609 return -EINVAL; in __request_percpu_irq()
2613 return -ENOMEM; in __request_percpu_irq()
2615 action->handler = handler; in __request_percpu_irq()
2616 action->flags = flags | IRQF_PERCPU | IRQF_NO_SUSPEND; in __request_percpu_irq()
2617 action->name = devname; in __request_percpu_irq()
2618 action->percpu_dev_id = dev_id; in __request_percpu_irq()
2620 retval = irq_chip_pm_get(&desc->irq_data); in __request_percpu_irq()
2629 irq_chip_pm_put(&desc->irq_data); in __request_percpu_irq()
2638 * request_percpu_nmi - allocate a percpu interrupt line for NMI delivery
2639 * @irq: Interrupt line to allocate
2644 * This call allocates interrupt resources for a per CPU NMI. Per CPU NMIs
2648 * Dev_id must be globally unique. It is a per-cpu variable, and
2652 * Interrupt lines requested for NMI delivering should have auto enabling
2655 * If the interrupt line cannot be used to deliver NMIs, function
2667 return -EINVAL; in request_percpu_nmi()
2675 return -EINVAL; in request_percpu_nmi()
2678 if (desc->istate & IRQS_NMI) in request_percpu_nmi()
2679 return -EINVAL; in request_percpu_nmi()
2683 return -ENOMEM; in request_percpu_nmi()
2685 action->handler = handler; in request_percpu_nmi()
2686 action->flags = IRQF_PERCPU | IRQF_NO_SUSPEND | IRQF_NO_THREAD in request_percpu_nmi()
2688 action->name = name; in request_percpu_nmi()
2689 action->percpu_dev_id = dev_id; in request_percpu_nmi()
2691 retval = irq_chip_pm_get(&desc->irq_data); in request_percpu_nmi()
2699 raw_spin_lock_irqsave(&desc->lock, flags); in request_percpu_nmi()
2700 desc->istate |= IRQS_NMI; in request_percpu_nmi()
2701 raw_spin_unlock_irqrestore(&desc->lock, flags); in request_percpu_nmi()
2706 irq_chip_pm_put(&desc->irq_data); in request_percpu_nmi()
2714 * prepare_percpu_nmi - performs CPU local setup for NMI delivery
2715 * @irq: Interrupt line to prepare for NMI delivery
2717 * This call prepares an interrupt line to deliver NMI on the current CPU,
2718 * before that interrupt line gets enabled with enable_percpu_nmi().
2720 * As a CPU local operation, this should be called from non-preemptible
2723 * If the interrupt line cannot be used to deliver NMIs, function
2737 return -EINVAL; in prepare_percpu_nmi()
2739 if (WARN(!(desc->istate & IRQS_NMI), in prepare_percpu_nmi()
2740 KERN_ERR "prepare_percpu_nmi called for a non-NMI interrupt: irq %u\n", in prepare_percpu_nmi()
2742 ret = -EINVAL; in prepare_percpu_nmi()
2758 * teardown_percpu_nmi - undoes NMI setup of IRQ line
2759 * @irq: Interrupt line from which CPU local NMI configuration should be
2766 * As a CPU local operation, this should be called from non-preemptible
2781 if (WARN_ON(!(desc->istate & IRQS_NMI))) in teardown_percpu_nmi()
2793 int err = -EINVAL; in __irq_get_irqchip_state()
2798 return -ENODEV; in __irq_get_irqchip_state()
2799 if (chip->irq_get_irqchip_state) in __irq_get_irqchip_state()
2802 data = data->parent_data; in __irq_get_irqchip_state()
2809 err = chip->irq_get_irqchip_state(data, which, state); in __irq_get_irqchip_state()
2814 * irq_get_irqchip_state - returns the irqchip state of a interrupt.
2815 * @irq: Interrupt line that is forwarded to a VM
2820 * interrupt, returning into @state the bit corresponding to
2824 * interrupt controller has per-cpu registers.
2832 int err = -EINVAL; in irq_get_irqchip_state()
2848 * irq_set_irqchip_state - set the state of a forwarded interrupt.
2849 * @irq: Interrupt line that is forwarded to a VM
2853 * This call sets the internal irqchip state of an interrupt,
2857 * interrupt controller has per-cpu registers.
2866 int err = -EINVAL; in irq_set_irqchip_state()
2877 err = -ENODEV; in irq_set_irqchip_state()
2880 if (chip->irq_set_irqchip_state) in irq_set_irqchip_state()
2883 data = data->parent_data; in irq_set_irqchip_state()
2890 err = chip->irq_set_irqchip_state(data, which, val); in irq_set_irqchip_state()
2899 * irq_has_action - Check whether an interrupt is requested
2916 * irq_check_status_bit - Check whether bits in the irq descriptor status are set
2930 res = !!(desc->status_use_accessors & bitmask); in irq_check_status_bit()