2 * linux/kernel/irq/chip.c
4 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
7 * This file contains the core interrupt handling code, for irq-chip
10 * Detailed information is available in Documentation/DocBook/genericirq
13 #include <linux/irq.h>
14 #include <linux/msi.h>
15 #include <linux/module.h>
16 #include <linux/interrupt.h>
17 #include <linux/kernel_stat.h>
18 #include <linux/irqdomain.h>
20 #include <trace/events/irq.h>
22 #include "internals.h"
24 static irqreturn_t bad_chained_irq(int irq, void *dev_id)
26 WARN_ONCE(1, "Chained irq %d should not call an action\n", irq);
31 * Chained handlers should never call action on their IRQ. This default
32 * action will emit warning if such thing happens.
34 struct irqaction chained_action = {
35 .handler = bad_chained_irq,
39 * irq_set_chip - set the irq chip for an irq
41 * @chip: pointer to irq chip description structure
43 int irq_set_chip(unsigned int irq, struct irq_chip *chip)
46 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
54 desc->irq_data.chip = chip;
55 irq_put_desc_unlock(desc, flags);
57 * For !CONFIG_SPARSE_IRQ make the irq show up in
63 EXPORT_SYMBOL(irq_set_chip);
66 * irq_set_type - set the irq trigger type for an irq
68 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
70 int irq_set_irq_type(unsigned int irq, unsigned int type)
73 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
79 ret = __irq_set_trigger(desc, type);
80 irq_put_desc_busunlock(desc, flags);
83 EXPORT_SYMBOL(irq_set_irq_type);
86 * irq_set_handler_data - set irq handler data for an irq
87 * @irq: Interrupt number
88 * @data: Pointer to interrupt specific data
90 * Set the hardware irq controller data for an irq
92 int irq_set_handler_data(unsigned int irq, void *data)
95 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
99 desc->irq_common_data.handler_data = data;
100 irq_put_desc_unlock(desc, flags);
103 EXPORT_SYMBOL(irq_set_handler_data);
106 * irq_set_msi_desc_off - set MSI descriptor data for an irq at offset
107 * @irq_base: Interrupt number base
108 * @irq_offset: Interrupt number offset
109 * @entry: Pointer to MSI descriptor data
111 * Set the MSI descriptor entry for an irq at offset
113 int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset,
114 struct msi_desc *entry)
117 struct irq_desc *desc = irq_get_desc_lock(irq_base + irq_offset, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
121 desc->irq_common_data.msi_desc = entry;
122 if (entry && !irq_offset)
123 entry->irq = irq_base;
124 irq_put_desc_unlock(desc, flags);
129 * irq_set_msi_desc - set MSI descriptor data for an irq
130 * @irq: Interrupt number
131 * @entry: Pointer to MSI descriptor data
133 * Set the MSI descriptor entry for an irq
135 int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
137 return irq_set_msi_desc_off(irq, 0, entry);
141 * irq_set_chip_data - set irq chip data for an irq
142 * @irq: Interrupt number
143 * @data: Pointer to chip specific data
145 * Set the hardware irq chip data for an irq
147 int irq_set_chip_data(unsigned int irq, void *data)
150 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
154 desc->irq_data.chip_data = data;
155 irq_put_desc_unlock(desc, flags);
158 EXPORT_SYMBOL(irq_set_chip_data);
160 struct irq_data *irq_get_irq_data(unsigned int irq)
162 struct irq_desc *desc = irq_to_desc(irq);
164 return desc ? &desc->irq_data : NULL;
166 EXPORT_SYMBOL_GPL(irq_get_irq_data);
168 static void irq_state_clr_disabled(struct irq_desc *desc)
170 irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED);
173 static void irq_state_set_disabled(struct irq_desc *desc)
175 irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
178 static void irq_state_clr_masked(struct irq_desc *desc)
180 irqd_clear(&desc->irq_data, IRQD_IRQ_MASKED);
183 static void irq_state_set_masked(struct irq_desc *desc)
185 irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
188 static void irq_state_clr_started(struct irq_desc *desc)
190 irqd_clear(&desc->irq_data, IRQD_IRQ_STARTED);
193 static void irq_state_set_started(struct irq_desc *desc)
195 irqd_set(&desc->irq_data, IRQD_IRQ_STARTED);
206 __irq_startup_managed(struct irq_desc *desc, struct cpumask *aff, bool force)
208 struct irq_data *d = irq_desc_get_irq_data(desc);
210 if (!irqd_affinity_is_managed(d))
211 return IRQ_STARTUP_NORMAL;
213 irqd_clr_managed_shutdown(d);
215 if (cpumask_any_and(aff, cpu_online_mask) > nr_cpu_ids) {
217 * Catch code which fiddles with enable_irq() on a managed
218 * and potentially shutdown IRQ. Chained interrupt
219 * installment or irq auto probing should not happen on
220 * managed irqs either. Emit a warning, break the affinity
221 * and start it up as a normal interrupt.
223 if (WARN_ON_ONCE(force))
224 return IRQ_STARTUP_NORMAL;
226 * The interrupt was requested, but there is no online CPU
227 * in it's affinity mask. Put it into managed shutdown
228 * state and let the cpu hotplug mechanism start it up once
229 * a CPU in the mask becomes available.
231 irqd_set_managed_shutdown(d);
232 return IRQ_STARTUP_ABORT;
234 return IRQ_STARTUP_MANAGED;
238 __irq_startup_managed(struct irq_desc *desc, struct cpumask *aff, bool force)
240 return IRQ_STARTUP_NORMAL;
244 static int __irq_startup(struct irq_desc *desc)
246 struct irq_data *d = irq_desc_get_irq_data(desc);
249 irq_domain_activate_irq(d);
250 if (d->chip->irq_startup) {
251 ret = d->chip->irq_startup(d);
252 irq_state_clr_disabled(desc);
253 irq_state_clr_masked(desc);
257 irq_state_set_started(desc);
261 int irq_startup(struct irq_desc *desc, bool resend, bool force)
263 struct irq_data *d = irq_desc_get_irq_data(desc);
264 struct cpumask *aff = irq_data_get_affinity_mask(d);
269 if (irqd_is_started(d)) {
272 switch (__irq_startup_managed(desc, aff, force)) {
273 case IRQ_STARTUP_NORMAL:
274 ret = __irq_startup(desc);
275 irq_setup_affinity(desc);
277 case IRQ_STARTUP_MANAGED:
278 ret = __irq_startup(desc);
279 irq_set_affinity_locked(d, aff, false);
281 case IRQ_STARTUP_ABORT:
286 check_irq_resend(desc);
291 static void __irq_disable(struct irq_desc *desc, bool mask);
293 void irq_shutdown(struct irq_desc *desc)
295 if (irqd_is_started(&desc->irq_data)) {
297 if (desc->irq_data.chip->irq_shutdown) {
298 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
299 irq_state_set_disabled(desc);
300 irq_state_set_masked(desc);
302 __irq_disable(desc, true);
304 irq_state_clr_started(desc);
307 * This must be called even if the interrupt was never started up,
308 * because the activation can happen before the interrupt is
309 * available for request/startup. It has it's own state tracking so
310 * it's safe to call it unconditionally.
312 irq_domain_deactivate_irq(&desc->irq_data);
315 void irq_enable(struct irq_desc *desc)
317 irq_state_clr_disabled(desc);
318 if (desc->irq_data.chip->irq_enable)
319 desc->irq_data.chip->irq_enable(&desc->irq_data);
321 desc->irq_data.chip->irq_unmask(&desc->irq_data);
322 irq_state_clr_masked(desc);
325 static void __irq_disable(struct irq_desc *desc, bool mask)
327 irq_state_set_disabled(desc);
328 if (desc->irq_data.chip->irq_disable) {
329 desc->irq_data.chip->irq_disable(&desc->irq_data);
330 irq_state_set_masked(desc);
337 * irq_disable - Mark interrupt disabled
338 * @desc: irq descriptor which should be disabled
340 * If the chip does not implement the irq_disable callback, we
341 * use a lazy disable approach. That means we mark the interrupt
342 * disabled, but leave the hardware unmasked. That's an
343 * optimization because we avoid the hardware access for the
344 * common case where no interrupt happens after we marked it
345 * disabled. If an interrupt happens, then the interrupt flow
346 * handler masks the line at the hardware level and marks it
349 * If the interrupt chip does not implement the irq_disable callback,
350 * a driver can disable the lazy approach for a particular irq line by
351 * calling 'irq_set_status_flags(irq, IRQ_DISABLE_UNLAZY)'. This can
352 * be used for devices which cannot disable the interrupt at the
353 * device level under certain circumstances and have to use
354 * disable_irq[_nosync] instead.
356 void irq_disable(struct irq_desc *desc)
358 __irq_disable(desc, irq_settings_disable_unlazy(desc));
361 void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu)
363 if (desc->irq_data.chip->irq_enable)
364 desc->irq_data.chip->irq_enable(&desc->irq_data);
366 desc->irq_data.chip->irq_unmask(&desc->irq_data);
367 cpumask_set_cpu(cpu, desc->percpu_enabled);
370 void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu)
372 if (desc->irq_data.chip->irq_disable)
373 desc->irq_data.chip->irq_disable(&desc->irq_data);
375 desc->irq_data.chip->irq_mask(&desc->irq_data);
376 cpumask_clear_cpu(cpu, desc->percpu_enabled);
379 static inline void mask_ack_irq(struct irq_desc *desc)
381 if (desc->irq_data.chip->irq_mask_ack)
382 desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
384 desc->irq_data.chip->irq_mask(&desc->irq_data);
385 if (desc->irq_data.chip->irq_ack)
386 desc->irq_data.chip->irq_ack(&desc->irq_data);
388 irq_state_set_masked(desc);
391 void mask_irq(struct irq_desc *desc)
393 if (desc->irq_data.chip->irq_mask) {
394 desc->irq_data.chip->irq_mask(&desc->irq_data);
395 irq_state_set_masked(desc);
399 void unmask_irq(struct irq_desc *desc)
401 if (desc->irq_data.chip->irq_unmask) {
402 desc->irq_data.chip->irq_unmask(&desc->irq_data);
403 irq_state_clr_masked(desc);
407 void unmask_threaded_irq(struct irq_desc *desc)
409 struct irq_chip *chip = desc->irq_data.chip;
411 if (chip->flags & IRQCHIP_EOI_THREADED)
412 chip->irq_eoi(&desc->irq_data);
414 if (chip->irq_unmask) {
415 chip->irq_unmask(&desc->irq_data);
416 irq_state_clr_masked(desc);
421 * handle_nested_irq - Handle a nested irq from a irq thread
422 * @irq: the interrupt number
424 * Handle interrupts which are nested into a threaded interrupt
425 * handler. The handler function is called inside the calling
428 void handle_nested_irq(unsigned int irq)
430 struct irq_desc *desc = irq_to_desc(irq);
431 struct irqaction *action;
432 irqreturn_t action_ret;
436 raw_spin_lock_irq(&desc->lock);
438 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
440 action = desc->action;
441 if (unlikely(!action || irqd_irq_disabled(&desc->irq_data))) {
442 desc->istate |= IRQS_PENDING;
446 kstat_incr_irqs_this_cpu(desc);
447 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
448 raw_spin_unlock_irq(&desc->lock);
450 action_ret = IRQ_NONE;
451 for_each_action_of_desc(desc, action)
452 action_ret |= action->thread_fn(action->irq, action->dev_id);
455 note_interrupt(desc, action_ret);
457 raw_spin_lock_irq(&desc->lock);
458 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
461 raw_spin_unlock_irq(&desc->lock);
463 EXPORT_SYMBOL_GPL(handle_nested_irq);
465 static bool irq_check_poll(struct irq_desc *desc)
467 if (!(desc->istate & IRQS_POLL_INPROGRESS))
469 return irq_wait_for_poll(desc);
472 static bool irq_may_run(struct irq_desc *desc)
474 unsigned int mask = IRQD_IRQ_INPROGRESS | IRQD_WAKEUP_ARMED;
477 * If the interrupt is not in progress and is not an armed
478 * wakeup interrupt, proceed.
480 if (!irqd_has_set(&desc->irq_data, mask))
484 * If the interrupt is an armed wakeup source, mark it pending
485 * and suspended, disable it and notify the pm core about the
488 if (irq_pm_check_wakeup(desc))
492 * Handle a potential concurrent poll on a different core.
494 return irq_check_poll(desc);
498 * handle_simple_irq - Simple and software-decoded IRQs.
499 * @desc: the interrupt description structure for this irq
501 * Simple interrupts are either sent from a demultiplexing interrupt
502 * handler or come from hardware, where no interrupt hardware control
505 * Note: The caller is expected to handle the ack, clear, mask and
506 * unmask issues if necessary.
508 void handle_simple_irq(struct irq_desc *desc)
510 raw_spin_lock(&desc->lock);
512 if (!irq_may_run(desc))
515 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
517 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
518 desc->istate |= IRQS_PENDING;
522 kstat_incr_irqs_this_cpu(desc);
523 handle_irq_event(desc);
526 raw_spin_unlock(&desc->lock);
528 EXPORT_SYMBOL_GPL(handle_simple_irq);
531 * handle_untracked_irq - Simple and software-decoded IRQs.
532 * @desc: the interrupt description structure for this irq
534 * Untracked interrupts are sent from a demultiplexing interrupt
535 * handler when the demultiplexer does not know which device it its
536 * multiplexed irq domain generated the interrupt. IRQ's handled
537 * through here are not subjected to stats tracking, randomness, or
538 * spurious interrupt detection.
540 * Note: Like handle_simple_irq, the caller is expected to handle
541 * the ack, clear, mask and unmask issues if necessary.
543 void handle_untracked_irq(struct irq_desc *desc)
545 unsigned int flags = 0;
547 raw_spin_lock(&desc->lock);
549 if (!irq_may_run(desc))
552 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
554 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
555 desc->istate |= IRQS_PENDING;
559 desc->istate &= ~IRQS_PENDING;
560 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
561 raw_spin_unlock(&desc->lock);
563 __handle_irq_event_percpu(desc, &flags);
565 raw_spin_lock(&desc->lock);
566 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
569 raw_spin_unlock(&desc->lock);
571 EXPORT_SYMBOL_GPL(handle_untracked_irq);
574 * Called unconditionally from handle_level_irq() and only for oneshot
575 * interrupts from handle_fasteoi_irq()
577 static void cond_unmask_irq(struct irq_desc *desc)
580 * We need to unmask in the following cases:
581 * - Standard level irq (IRQF_ONESHOT is not set)
582 * - Oneshot irq which did not wake the thread (caused by a
583 * spurious interrupt or a primary handler handling it
586 if (!irqd_irq_disabled(&desc->irq_data) &&
587 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot)
592 * handle_level_irq - Level type irq handler
593 * @desc: the interrupt description structure for this irq
595 * Level type interrupts are active as long as the hardware line has
596 * the active level. This may require to mask the interrupt and unmask
597 * it after the associated handler has acknowledged the device, so the
598 * interrupt line is back to inactive.
600 void handle_level_irq(struct irq_desc *desc)
602 raw_spin_lock(&desc->lock);
605 if (!irq_may_run(desc))
608 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
611 * If its disabled or no action available
612 * keep it masked and get out of here
614 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
615 desc->istate |= IRQS_PENDING;
619 kstat_incr_irqs_this_cpu(desc);
620 handle_irq_event(desc);
622 cond_unmask_irq(desc);
625 raw_spin_unlock(&desc->lock);
627 EXPORT_SYMBOL_GPL(handle_level_irq);
629 #ifdef CONFIG_IRQ_PREFLOW_FASTEOI
630 static inline void preflow_handler(struct irq_desc *desc)
632 if (desc->preflow_handler)
633 desc->preflow_handler(&desc->irq_data);
636 static inline void preflow_handler(struct irq_desc *desc) { }
639 static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip)
641 if (!(desc->istate & IRQS_ONESHOT)) {
642 chip->irq_eoi(&desc->irq_data);
646 * We need to unmask in the following cases:
647 * - Oneshot irq which did not wake the thread (caused by a
648 * spurious interrupt or a primary handler handling it
651 if (!irqd_irq_disabled(&desc->irq_data) &&
652 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) {
653 chip->irq_eoi(&desc->irq_data);
655 } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) {
656 chip->irq_eoi(&desc->irq_data);
661 * handle_fasteoi_irq - irq handler for transparent controllers
662 * @desc: the interrupt description structure for this irq
664 * Only a single callback will be issued to the chip: an ->eoi()
665 * call when the interrupt has been serviced. This enables support
666 * for modern forms of interrupt handlers, which handle the flow
667 * details in hardware, transparently.
669 void handle_fasteoi_irq(struct irq_desc *desc)
671 struct irq_chip *chip = desc->irq_data.chip;
673 raw_spin_lock(&desc->lock);
675 if (!irq_may_run(desc))
678 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
681 * If its disabled or no action available
682 * then mask it and get out of here:
684 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
685 desc->istate |= IRQS_PENDING;
690 kstat_incr_irqs_this_cpu(desc);
691 if (desc->istate & IRQS_ONESHOT)
694 preflow_handler(desc);
695 handle_irq_event(desc);
697 cond_unmask_eoi_irq(desc, chip);
699 raw_spin_unlock(&desc->lock);
702 if (!(chip->flags & IRQCHIP_EOI_IF_HANDLED))
703 chip->irq_eoi(&desc->irq_data);
704 raw_spin_unlock(&desc->lock);
706 EXPORT_SYMBOL_GPL(handle_fasteoi_irq);
709 * handle_edge_irq - edge type IRQ handler
710 * @desc: the interrupt description structure for this irq
712 * Interrupt occures on the falling and/or rising edge of a hardware
713 * signal. The occurrence is latched into the irq controller hardware
714 * and must be acked in order to be reenabled. After the ack another
715 * interrupt can happen on the same source even before the first one
716 * is handled by the associated event handler. If this happens it
717 * might be necessary to disable (mask) the interrupt depending on the
718 * controller hardware. This requires to reenable the interrupt inside
719 * of the loop which handles the interrupts which have arrived while
720 * the handler was running. If all pending interrupts are handled, the
723 void handle_edge_irq(struct irq_desc *desc)
725 raw_spin_lock(&desc->lock);
727 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
729 if (!irq_may_run(desc)) {
730 desc->istate |= IRQS_PENDING;
736 * If its disabled or no action available then mask it and get
739 if (irqd_irq_disabled(&desc->irq_data) || !desc->action) {
740 desc->istate |= IRQS_PENDING;
745 kstat_incr_irqs_this_cpu(desc);
747 /* Start handling the irq */
748 desc->irq_data.chip->irq_ack(&desc->irq_data);
751 if (unlikely(!desc->action)) {
757 * When another irq arrived while we were handling
758 * one, we could have masked the irq.
759 * Renable it, if it was not disabled in meantime.
761 if (unlikely(desc->istate & IRQS_PENDING)) {
762 if (!irqd_irq_disabled(&desc->irq_data) &&
763 irqd_irq_masked(&desc->irq_data))
767 handle_irq_event(desc);
769 } while ((desc->istate & IRQS_PENDING) &&
770 !irqd_irq_disabled(&desc->irq_data));
773 raw_spin_unlock(&desc->lock);
775 EXPORT_SYMBOL(handle_edge_irq);
777 #ifdef CONFIG_IRQ_EDGE_EOI_HANDLER
779 * handle_edge_eoi_irq - edge eoi type IRQ handler
780 * @desc: the interrupt description structure for this irq
782 * Similar as the above handle_edge_irq, but using eoi and w/o the
785 void handle_edge_eoi_irq(struct irq_desc *desc)
787 struct irq_chip *chip = irq_desc_get_chip(desc);
789 raw_spin_lock(&desc->lock);
791 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
793 if (!irq_may_run(desc)) {
794 desc->istate |= IRQS_PENDING;
799 * If its disabled or no action available then mask it and get
802 if (irqd_irq_disabled(&desc->irq_data) || !desc->action) {
803 desc->istate |= IRQS_PENDING;
807 kstat_incr_irqs_this_cpu(desc);
810 if (unlikely(!desc->action))
813 handle_irq_event(desc);
815 } while ((desc->istate & IRQS_PENDING) &&
816 !irqd_irq_disabled(&desc->irq_data));
819 chip->irq_eoi(&desc->irq_data);
820 raw_spin_unlock(&desc->lock);
825 * handle_percpu_irq - Per CPU local irq handler
826 * @desc: the interrupt description structure for this irq
828 * Per CPU interrupts on SMP machines without locking requirements
830 void handle_percpu_irq(struct irq_desc *desc)
832 struct irq_chip *chip = irq_desc_get_chip(desc);
834 kstat_incr_irqs_this_cpu(desc);
837 chip->irq_ack(&desc->irq_data);
839 handle_irq_event_percpu(desc);
842 chip->irq_eoi(&desc->irq_data);
846 * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids
847 * @desc: the interrupt description structure for this irq
849 * Per CPU interrupts on SMP machines without locking requirements. Same as
850 * handle_percpu_irq() above but with the following extras:
852 * action->percpu_dev_id is a pointer to percpu variables which
853 * contain the real device id for the cpu on which this handler is
856 void handle_percpu_devid_irq(struct irq_desc *desc)
858 struct irq_chip *chip = irq_desc_get_chip(desc);
859 struct irqaction *action = desc->action;
860 unsigned int irq = irq_desc_get_irq(desc);
863 kstat_incr_irqs_this_cpu(desc);
866 chip->irq_ack(&desc->irq_data);
868 if (likely(action)) {
869 trace_irq_handler_entry(irq, action);
870 res = action->handler(irq, raw_cpu_ptr(action->percpu_dev_id));
871 trace_irq_handler_exit(irq, action, res);
873 unsigned int cpu = smp_processor_id();
874 bool enabled = cpumask_test_cpu(cpu, desc->percpu_enabled);
877 irq_percpu_disable(desc, cpu);
879 pr_err_once("Spurious%s percpu IRQ%u on CPU%u\n",
880 enabled ? " and unmasked" : "", irq, cpu);
884 chip->irq_eoi(&desc->irq_data);
888 __irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle,
889 int is_chained, const char *name)
892 handle = handle_bad_irq;
894 struct irq_data *irq_data = &desc->irq_data;
895 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
897 * With hierarchical domains we might run into a
898 * situation where the outermost chip is not yet set
899 * up, but the inner chips are there. Instead of
900 * bailing we install the handler, but obviously we
901 * cannot enable/startup the interrupt at this point.
904 if (irq_data->chip != &no_irq_chip)
907 * Bail out if the outer chip is not set up
908 * and the interrrupt supposed to be started
911 if (WARN_ON(is_chained))
914 irq_data = irq_data->parent_data;
917 if (WARN_ON(!irq_data || irq_data->chip == &no_irq_chip))
922 if (handle == handle_bad_irq) {
923 if (desc->irq_data.chip != &no_irq_chip)
925 irq_state_set_disabled(desc);
930 desc->handle_irq = handle;
933 if (handle != handle_bad_irq && is_chained) {
934 unsigned int type = irqd_get_trigger_type(&desc->irq_data);
937 * We're about to start this interrupt immediately,
938 * hence the need to set the trigger configuration.
939 * But the .set_type callback may have overridden the
940 * flow handler, ignoring that we're dealing with a
941 * chained interrupt. Reset it immediately because we
944 if (type != IRQ_TYPE_NONE) {
945 __irq_set_trigger(desc, type);
946 desc->handle_irq = handle;
949 irq_settings_set_noprobe(desc);
950 irq_settings_set_norequest(desc);
951 irq_settings_set_nothread(desc);
952 desc->action = &chained_action;
953 irq_startup(desc, IRQ_RESEND, IRQ_START_FORCE);
958 __irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
962 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);
967 __irq_do_set_handler(desc, handle, is_chained, name);
968 irq_put_desc_busunlock(desc, flags);
970 EXPORT_SYMBOL_GPL(__irq_set_handler);
973 irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle,
977 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);
982 desc->irq_common_data.handler_data = data;
983 __irq_do_set_handler(desc, handle, 1, NULL);
985 irq_put_desc_busunlock(desc, flags);
987 EXPORT_SYMBOL_GPL(irq_set_chained_handler_and_data);
990 irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
991 irq_flow_handler_t handle, const char *name)
993 irq_set_chip(irq, chip);
994 __irq_set_handler(irq, handle, 0, name);
996 EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name);
998 void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
1000 unsigned long flags;
1001 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
1007 * Warn when a driver sets the no autoenable flag on an already
1010 WARN_ON_ONCE(!desc->depth && (set & _IRQ_NOAUTOEN));
1012 irq_settings_clr_and_set(desc, clr, set);
1014 irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU |
1015 IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT);
1016 if (irq_settings_has_no_balance_set(desc))
1017 irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
1018 if (irq_settings_is_per_cpu(desc))
1019 irqd_set(&desc->irq_data, IRQD_PER_CPU);
1020 if (irq_settings_can_move_pcntxt(desc))
1021 irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT);
1022 if (irq_settings_is_level(desc))
1023 irqd_set(&desc->irq_data, IRQD_LEVEL);
1025 irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc));
1027 irq_put_desc_unlock(desc, flags);
1029 EXPORT_SYMBOL_GPL(irq_modify_status);
1032 * irq_cpu_online - Invoke all irq_cpu_online functions.
1034 * Iterate through all irqs and invoke the chip.irq_cpu_online()
1037 void irq_cpu_online(void)
1039 struct irq_desc *desc;
1040 struct irq_chip *chip;
1041 unsigned long flags;
1044 for_each_active_irq(irq) {
1045 desc = irq_to_desc(irq);
1049 raw_spin_lock_irqsave(&desc->lock, flags);
1051 chip = irq_data_get_irq_chip(&desc->irq_data);
1052 if (chip && chip->irq_cpu_online &&
1053 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
1054 !irqd_irq_disabled(&desc->irq_data)))
1055 chip->irq_cpu_online(&desc->irq_data);
1057 raw_spin_unlock_irqrestore(&desc->lock, flags);
1062 * irq_cpu_offline - Invoke all irq_cpu_offline functions.
1064 * Iterate through all irqs and invoke the chip.irq_cpu_offline()
1067 void irq_cpu_offline(void)
1069 struct irq_desc *desc;
1070 struct irq_chip *chip;
1071 unsigned long flags;
1074 for_each_active_irq(irq) {
1075 desc = irq_to_desc(irq);
1079 raw_spin_lock_irqsave(&desc->lock, flags);
1081 chip = irq_data_get_irq_chip(&desc->irq_data);
1082 if (chip && chip->irq_cpu_offline &&
1083 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
1084 !irqd_irq_disabled(&desc->irq_data)))
1085 chip->irq_cpu_offline(&desc->irq_data);
1087 raw_spin_unlock_irqrestore(&desc->lock, flags);
1091 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
1093 * irq_chip_enable_parent - Enable the parent interrupt (defaults to unmask if
1095 * @data: Pointer to interrupt specific data
1097 void irq_chip_enable_parent(struct irq_data *data)
1099 data = data->parent_data;
1100 if (data->chip->irq_enable)
1101 data->chip->irq_enable(data);
1103 data->chip->irq_unmask(data);
1107 * irq_chip_disable_parent - Disable the parent interrupt (defaults to mask if
1109 * @data: Pointer to interrupt specific data
1111 void irq_chip_disable_parent(struct irq_data *data)
1113 data = data->parent_data;
1114 if (data->chip->irq_disable)
1115 data->chip->irq_disable(data);
1117 data->chip->irq_mask(data);
1121 * irq_chip_ack_parent - Acknowledge the parent interrupt
1122 * @data: Pointer to interrupt specific data
1124 void irq_chip_ack_parent(struct irq_data *data)
1126 data = data->parent_data;
1127 data->chip->irq_ack(data);
1129 EXPORT_SYMBOL_GPL(irq_chip_ack_parent);
1132 * irq_chip_mask_parent - Mask the parent interrupt
1133 * @data: Pointer to interrupt specific data
1135 void irq_chip_mask_parent(struct irq_data *data)
1137 data = data->parent_data;
1138 data->chip->irq_mask(data);
1140 EXPORT_SYMBOL_GPL(irq_chip_mask_parent);
1143 * irq_chip_unmask_parent - Unmask the parent interrupt
1144 * @data: Pointer to interrupt specific data
1146 void irq_chip_unmask_parent(struct irq_data *data)
1148 data = data->parent_data;
1149 data->chip->irq_unmask(data);
1151 EXPORT_SYMBOL_GPL(irq_chip_unmask_parent);
1154 * irq_chip_eoi_parent - Invoke EOI on the parent interrupt
1155 * @data: Pointer to interrupt specific data
1157 void irq_chip_eoi_parent(struct irq_data *data)
1159 data = data->parent_data;
1160 data->chip->irq_eoi(data);
1162 EXPORT_SYMBOL_GPL(irq_chip_eoi_parent);
1165 * irq_chip_set_affinity_parent - Set affinity on the parent interrupt
1166 * @data: Pointer to interrupt specific data
1167 * @dest: The affinity mask to set
1168 * @force: Flag to enforce setting (disable online checks)
1170 * Conditinal, as the underlying parent chip might not implement it.
1172 int irq_chip_set_affinity_parent(struct irq_data *data,
1173 const struct cpumask *dest, bool force)
1175 data = data->parent_data;
1176 if (data->chip->irq_set_affinity)
1177 return data->chip->irq_set_affinity(data, dest, force);
1183 * irq_chip_set_type_parent - Set IRQ type on the parent interrupt
1184 * @data: Pointer to interrupt specific data
1185 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
1187 * Conditional, as the underlying parent chip might not implement it.
1189 int irq_chip_set_type_parent(struct irq_data *data, unsigned int type)
1191 data = data->parent_data;
1193 if (data->chip->irq_set_type)
1194 return data->chip->irq_set_type(data, type);
1198 EXPORT_SYMBOL_GPL(irq_chip_set_type_parent);
1201 * irq_chip_retrigger_hierarchy - Retrigger an interrupt in hardware
1202 * @data: Pointer to interrupt specific data
1204 * Iterate through the domain hierarchy of the interrupt and check
1205 * whether a hw retrigger function exists. If yes, invoke it.
1207 int irq_chip_retrigger_hierarchy(struct irq_data *data)
1209 for (data = data->parent_data; data; data = data->parent_data)
1210 if (data->chip && data->chip->irq_retrigger)
1211 return data->chip->irq_retrigger(data);
1217 * irq_chip_set_vcpu_affinity_parent - Set vcpu affinity on the parent interrupt
1218 * @data: Pointer to interrupt specific data
1219 * @vcpu_info: The vcpu affinity information
1221 int irq_chip_set_vcpu_affinity_parent(struct irq_data *data, void *vcpu_info)
1223 data = data->parent_data;
1224 if (data->chip->irq_set_vcpu_affinity)
1225 return data->chip->irq_set_vcpu_affinity(data, vcpu_info);
1231 * irq_chip_set_wake_parent - Set/reset wake-up on the parent interrupt
1232 * @data: Pointer to interrupt specific data
1233 * @on: Whether to set or reset the wake-up capability of this irq
1235 * Conditional, as the underlying parent chip might not implement it.
1237 int irq_chip_set_wake_parent(struct irq_data *data, unsigned int on)
1239 data = data->parent_data;
1240 if (data->chip->irq_set_wake)
1241 return data->chip->irq_set_wake(data, on);
1248 * irq_chip_compose_msi_msg - Componse msi message for a irq chip
1249 * @data: Pointer to interrupt specific data
1250 * @msg: Pointer to the MSI message
1252 * For hierarchical domains we find the first chip in the hierarchy
1253 * which implements the irq_compose_msi_msg callback. For non
1254 * hierarchical we use the top level chip.
1256 int irq_chip_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
1258 struct irq_data *pos = NULL;
1260 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
1261 for (; data; data = data->parent_data)
1263 if (data->chip && data->chip->irq_compose_msi_msg)
1268 pos->chip->irq_compose_msi_msg(pos, msg);
1274 * irq_chip_pm_get - Enable power for an IRQ chip
1275 * @data: Pointer to interrupt specific data
1277 * Enable the power to the IRQ chip referenced by the interrupt data
1280 int irq_chip_pm_get(struct irq_data *data)
1284 if (IS_ENABLED(CONFIG_PM) && data->chip->parent_device) {
1285 retval = pm_runtime_get_sync(data->chip->parent_device);
1287 pm_runtime_put_noidle(data->chip->parent_device);
1296 * irq_chip_pm_put - Disable power for an IRQ chip
1297 * @data: Pointer to interrupt specific data
1299 * Disable the power to the IRQ chip referenced by the interrupt data
1300 * structure, belongs. Note that power will only be disabled, once this
1301 * function has been called for all IRQs that have called irq_chip_pm_get().
1303 int irq_chip_pm_put(struct irq_data *data)
1307 if (IS_ENABLED(CONFIG_PM) && data->chip->parent_device)
1308 retval = pm_runtime_put(data->chip->parent_device);
1310 return (retval < 0) ? retval : 0;