11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * IRQ subsystem internal functions and variables: 3dbec07baSThomas Gleixner * 4dbec07baSThomas Gleixner * Do not ever include this file from anything else than 5dbec07baSThomas Gleixner * kernel/irq/. Do not even think about using any information outside 6dbec07baSThomas Gleixner * of this file for your non core code. 71da177e4SLinus Torvalds */ 8e144710bSThomas Gleixner #include <linux/irqdesc.h> 9*8f945a33SThomas Gleixner #include <linux/kernel_stat.h> 101da177e4SLinus Torvalds 11c1ee6264SThomas Gleixner #ifdef CONFIG_SPARSE_IRQ 12c1ee6264SThomas Gleixner # define IRQ_BITMAP_BITS (NR_IRQS + 8196) 13c1ee6264SThomas Gleixner #else 14c1ee6264SThomas Gleixner # define IRQ_BITMAP_BITS NR_IRQS 15c1ee6264SThomas Gleixner #endif 16c1ee6264SThomas Gleixner 17dbec07baSThomas Gleixner #define istate core_internal_state__do_not_mess_with_it 18dbec07baSThomas Gleixner 192329abfaSRusty Russell extern bool noirqdebug; 201da177e4SLinus Torvalds 211535dfacSThomas Gleixner /* 221535dfacSThomas Gleixner * Bits used by threaded handlers: 231535dfacSThomas Gleixner * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run 241535dfacSThomas Gleixner * IRQTF_WARNED - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed 251535dfacSThomas Gleixner * IRQTF_AFFINITY - irq thread is requested to adjust affinity 268d32a307SThomas Gleixner * IRQTF_FORCED_THREAD - irq action is force threaded 271535dfacSThomas Gleixner */ 281535dfacSThomas Gleixner enum { 291535dfacSThomas Gleixner IRQTF_RUNTHREAD, 301535dfacSThomas Gleixner IRQTF_WARNED, 311535dfacSThomas Gleixner IRQTF_AFFINITY, 328d32a307SThomas Gleixner IRQTF_FORCED_THREAD, 331535dfacSThomas Gleixner }; 341535dfacSThomas Gleixner 35bd062e76SThomas Gleixner /* 36bd062e76SThomas Gleixner * Bit masks for desc->state 37bd062e76SThomas Gleixner * 38bd062e76SThomas Gleixner * IRQS_AUTODETECT - autodetection in progress 397acdd53eSThomas Gleixner * IRQS_SPURIOUS_DISABLED - was disabled due to spurious interrupt 407acdd53eSThomas Gleixner * detection 416954b75bSThomas Gleixner * IRQS_POLL_INPROGRESS - polling in progress 423d67baecSThomas Gleixner * IRQS_ONESHOT - irq is not unmasked in primary handler 43163ef309SThomas Gleixner * IRQS_REPLAY - irq is replayed 44163ef309SThomas Gleixner * IRQS_WAITING - irq is waiting 452a0d6fb3SThomas Gleixner * IRQS_PENDING - irq is pending and replayed later 46c531e836SThomas Gleixner * IRQS_SUSPENDED - irq is suspended 47bd062e76SThomas Gleixner */ 48bd062e76SThomas Gleixner enum { 49bd062e76SThomas Gleixner IRQS_AUTODETECT = 0x00000001, 507acdd53eSThomas Gleixner IRQS_SPURIOUS_DISABLED = 0x00000002, 516954b75bSThomas Gleixner IRQS_POLL_INPROGRESS = 0x00000008, 523d67baecSThomas Gleixner IRQS_ONESHOT = 0x00000020, 53163ef309SThomas Gleixner IRQS_REPLAY = 0x00000040, 54163ef309SThomas Gleixner IRQS_WAITING = 0x00000080, 552a0d6fb3SThomas Gleixner IRQS_PENDING = 0x00000200, 56c531e836SThomas Gleixner IRQS_SUSPENDED = 0x00000800, 57bd062e76SThomas Gleixner }; 58bd062e76SThomas Gleixner 591ce6068dSThomas Gleixner #include "debug.h" 601ce6068dSThomas Gleixner #include "settings.h" 611ce6068dSThomas Gleixner 62a77c4635SThomas Gleixner #define irq_data_to_desc(data) container_of(data, struct irq_desc, irq_data) 63a77c4635SThomas Gleixner 640c5d1eb7SDavid Brownell extern int __irq_set_trigger(struct irq_desc *desc, unsigned int irq, 650c5d1eb7SDavid Brownell unsigned long flags); 660a0c5168SRafael J. Wysocki extern void __disable_irq(struct irq_desc *desc, unsigned int irq, bool susp); 670a0c5168SRafael J. Wysocki extern void __enable_irq(struct irq_desc *desc, unsigned int irq, bool resume); 680c5d1eb7SDavid Brownell 69b4bc724eSThomas Gleixner extern int irq_startup(struct irq_desc *desc, bool resend); 7046999238SThomas Gleixner extern void irq_shutdown(struct irq_desc *desc); 7187923470SThomas Gleixner extern void irq_enable(struct irq_desc *desc); 7287923470SThomas Gleixner extern void irq_disable(struct irq_desc *desc); 7331d9d9b6SMarc Zyngier extern void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu); 7431d9d9b6SMarc Zyngier extern void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu); 75d4d5e089SThomas Gleixner extern void mask_irq(struct irq_desc *desc); 76d4d5e089SThomas Gleixner extern void unmask_irq(struct irq_desc *desc); 7746999238SThomas Gleixner 7885ac16d0SYinghai Lu extern void init_kstat_irqs(struct irq_desc *desc, int node, int nr); 790fa0ebbfSMike Travis 804912609fSThomas Gleixner irqreturn_t handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action); 814912609fSThomas Gleixner irqreturn_t handle_irq_event(struct irq_desc *desc); 824912609fSThomas Gleixner 83e144710bSThomas Gleixner /* Resending of interrupts :*/ 84e144710bSThomas Gleixner void check_irq_resend(struct irq_desc *desc, unsigned int irq); 85fe200ae4SThomas Gleixner bool irq_wait_for_poll(struct irq_desc *desc); 86a92444c6SThomas Gleixner void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action); 87e144710bSThomas Gleixner 881da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 892c6927a3SYinghai Lu extern void register_irq_proc(unsigned int irq, struct irq_desc *desc); 9013bfe99eSThomas Gleixner extern void unregister_irq_proc(unsigned int irq, struct irq_desc *desc); 911da177e4SLinus Torvalds extern void register_handler_proc(unsigned int irq, struct irqaction *action); 921da177e4SLinus Torvalds extern void unregister_handler_proc(unsigned int irq, struct irqaction *action); 931da177e4SLinus Torvalds #else 942c6927a3SYinghai Lu static inline void register_irq_proc(unsigned int irq, struct irq_desc *desc) { } 9513bfe99eSThomas Gleixner static inline void unregister_irq_proc(unsigned int irq, struct irq_desc *desc) { } 961da177e4SLinus Torvalds static inline void register_handler_proc(unsigned int irq, 971da177e4SLinus Torvalds struct irqaction *action) { } 981da177e4SLinus Torvalds static inline void unregister_handler_proc(unsigned int irq, 991da177e4SLinus Torvalds struct irqaction *action) { } 1001da177e4SLinus Torvalds #endif 1011da177e4SLinus Torvalds 1023b8249e7SThomas Gleixner extern int irq_select_affinity_usr(unsigned int irq, struct cpumask *mask); 103f6d87f4bSThomas Gleixner 104591d2fb0SThomas Gleixner extern void irq_set_thread_affinity(struct irq_desc *desc); 10557b150ccSYinghai Lu 106818b0f3bSJiang Liu extern int irq_do_set_affinity(struct irq_data *data, 107818b0f3bSJiang Liu const struct cpumask *dest, bool force); 108818b0f3bSJiang Liu 10970aedd24SThomas Gleixner /* Inline functions for support of irq chips on slow busses */ 1103876ec9eSThomas Gleixner static inline void chip_bus_lock(struct irq_desc *desc) 11170aedd24SThomas Gleixner { 1123876ec9eSThomas Gleixner if (unlikely(desc->irq_data.chip->irq_bus_lock)) 1133876ec9eSThomas Gleixner desc->irq_data.chip->irq_bus_lock(&desc->irq_data); 11470aedd24SThomas Gleixner } 11570aedd24SThomas Gleixner 1163876ec9eSThomas Gleixner static inline void chip_bus_sync_unlock(struct irq_desc *desc) 11770aedd24SThomas Gleixner { 1183876ec9eSThomas Gleixner if (unlikely(desc->irq_data.chip->irq_bus_sync_unlock)) 1193876ec9eSThomas Gleixner desc->irq_data.chip->irq_bus_sync_unlock(&desc->irq_data); 12070aedd24SThomas Gleixner } 12170aedd24SThomas Gleixner 12231d9d9b6SMarc Zyngier #define _IRQ_DESC_CHECK (1 << 0) 12331d9d9b6SMarc Zyngier #define _IRQ_DESC_PERCPU (1 << 1) 12431d9d9b6SMarc Zyngier 12531d9d9b6SMarc Zyngier #define IRQ_GET_DESC_CHECK_GLOBAL (_IRQ_DESC_CHECK) 12631d9d9b6SMarc Zyngier #define IRQ_GET_DESC_CHECK_PERCPU (_IRQ_DESC_CHECK | _IRQ_DESC_PERCPU) 12731d9d9b6SMarc Zyngier 128d5eb4ad2SThomas Gleixner struct irq_desc * 12931d9d9b6SMarc Zyngier __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus, 13031d9d9b6SMarc Zyngier unsigned int check); 131d5eb4ad2SThomas Gleixner void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus); 132d5eb4ad2SThomas Gleixner 133d5eb4ad2SThomas Gleixner static inline struct irq_desc * 13431d9d9b6SMarc Zyngier irq_get_desc_buslock(unsigned int irq, unsigned long *flags, unsigned int check) 135d5eb4ad2SThomas Gleixner { 13631d9d9b6SMarc Zyngier return __irq_get_desc_lock(irq, flags, true, check); 137d5eb4ad2SThomas Gleixner } 138d5eb4ad2SThomas Gleixner 139d5eb4ad2SThomas Gleixner static inline void 140d5eb4ad2SThomas Gleixner irq_put_desc_busunlock(struct irq_desc *desc, unsigned long flags) 141d5eb4ad2SThomas Gleixner { 142d5eb4ad2SThomas Gleixner __irq_put_desc_unlock(desc, flags, true); 143d5eb4ad2SThomas Gleixner } 144d5eb4ad2SThomas Gleixner 145d5eb4ad2SThomas Gleixner static inline struct irq_desc * 14631d9d9b6SMarc Zyngier irq_get_desc_lock(unsigned int irq, unsigned long *flags, unsigned int check) 147d5eb4ad2SThomas Gleixner { 14831d9d9b6SMarc Zyngier return __irq_get_desc_lock(irq, flags, false, check); 149d5eb4ad2SThomas Gleixner } 150d5eb4ad2SThomas Gleixner 151d5eb4ad2SThomas Gleixner static inline void 152d5eb4ad2SThomas Gleixner irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags) 153d5eb4ad2SThomas Gleixner { 154d5eb4ad2SThomas Gleixner __irq_put_desc_unlock(desc, flags, false); 155d5eb4ad2SThomas Gleixner } 156d5eb4ad2SThomas Gleixner 15743f77759SIngo Molnar /* 158f230b6d5SThomas Gleixner * Manipulation functions for irq_data.state 159f230b6d5SThomas Gleixner */ 160f230b6d5SThomas Gleixner static inline void irqd_set_move_pending(struct irq_data *d) 161f230b6d5SThomas Gleixner { 162f230b6d5SThomas Gleixner d->state_use_accessors |= IRQD_SETAFFINITY_PENDING; 163f230b6d5SThomas Gleixner } 164f230b6d5SThomas Gleixner 165f230b6d5SThomas Gleixner static inline void irqd_clr_move_pending(struct irq_data *d) 166f230b6d5SThomas Gleixner { 167f230b6d5SThomas Gleixner d->state_use_accessors &= ~IRQD_SETAFFINITY_PENDING; 168f230b6d5SThomas Gleixner } 169a005677bSThomas Gleixner 170a005677bSThomas Gleixner static inline void irqd_clear(struct irq_data *d, unsigned int mask) 171a005677bSThomas Gleixner { 172a005677bSThomas Gleixner d->state_use_accessors &= ~mask; 173a005677bSThomas Gleixner } 174a005677bSThomas Gleixner 175a005677bSThomas Gleixner static inline void irqd_set(struct irq_data *d, unsigned int mask) 176a005677bSThomas Gleixner { 177a005677bSThomas Gleixner d->state_use_accessors |= mask; 178a005677bSThomas Gleixner } 179a005677bSThomas Gleixner 1802bdd1055SThomas Gleixner static inline bool irqd_has_set(struct irq_data *d, unsigned int mask) 1812bdd1055SThomas Gleixner { 1822bdd1055SThomas Gleixner return d->state_use_accessors & mask; 1832bdd1055SThomas Gleixner } 184*8f945a33SThomas Gleixner 185*8f945a33SThomas Gleixner static inline void kstat_incr_irqs_this_cpu(unsigned int irq, struct irq_desc *desc) 186*8f945a33SThomas Gleixner { 187*8f945a33SThomas Gleixner __this_cpu_inc(*desc->kstat_irqs); 188*8f945a33SThomas Gleixner __this_cpu_inc(kstat.irqs_sum); 189*8f945a33SThomas Gleixner } 190