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> 98f945a33SThomas Gleixner #include <linux/kernel_stat.h> 10be45beb2SJon Hunter #include <linux/pm_runtime.h> 111da177e4SLinus Torvalds 12c1ee6264SThomas Gleixner #ifdef CONFIG_SPARSE_IRQ 13c1ee6264SThomas Gleixner # define IRQ_BITMAP_BITS (NR_IRQS + 8196) 14c1ee6264SThomas Gleixner #else 15c1ee6264SThomas Gleixner # define IRQ_BITMAP_BITS NR_IRQS 16c1ee6264SThomas Gleixner #endif 17c1ee6264SThomas Gleixner 18dbec07baSThomas Gleixner #define istate core_internal_state__do_not_mess_with_it 19dbec07baSThomas Gleixner 202329abfaSRusty Russell extern bool noirqdebug; 211da177e4SLinus Torvalds 22e509bd7dSMika Westerberg extern struct irqaction chained_action; 23e509bd7dSMika Westerberg 241535dfacSThomas Gleixner /* 251535dfacSThomas Gleixner * Bits used by threaded handlers: 261535dfacSThomas Gleixner * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run 271535dfacSThomas Gleixner * IRQTF_WARNED - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed 281535dfacSThomas Gleixner * IRQTF_AFFINITY - irq thread is requested to adjust affinity 298d32a307SThomas Gleixner * IRQTF_FORCED_THREAD - irq action is force threaded 301535dfacSThomas Gleixner */ 311535dfacSThomas Gleixner enum { 321535dfacSThomas Gleixner IRQTF_RUNTHREAD, 331535dfacSThomas Gleixner IRQTF_WARNED, 341535dfacSThomas Gleixner IRQTF_AFFINITY, 358d32a307SThomas Gleixner IRQTF_FORCED_THREAD, 361535dfacSThomas Gleixner }; 371535dfacSThomas Gleixner 38bd062e76SThomas Gleixner /* 39a257954bSJiang Liu * Bit masks for desc->core_internal_state__do_not_mess_with_it 40bd062e76SThomas Gleixner * 41bd062e76SThomas Gleixner * IRQS_AUTODETECT - autodetection in progress 427acdd53eSThomas Gleixner * IRQS_SPURIOUS_DISABLED - was disabled due to spurious interrupt 437acdd53eSThomas Gleixner * detection 446954b75bSThomas Gleixner * IRQS_POLL_INPROGRESS - polling in progress 453d67baecSThomas Gleixner * IRQS_ONESHOT - irq is not unmasked in primary handler 46163ef309SThomas Gleixner * IRQS_REPLAY - irq is replayed 47163ef309SThomas Gleixner * IRQS_WAITING - irq is waiting 482a0d6fb3SThomas Gleixner * IRQS_PENDING - irq is pending and replayed later 49c531e836SThomas Gleixner * IRQS_SUSPENDED - irq is suspended 50bd062e76SThomas Gleixner */ 51bd062e76SThomas Gleixner enum { 52bd062e76SThomas Gleixner IRQS_AUTODETECT = 0x00000001, 537acdd53eSThomas Gleixner IRQS_SPURIOUS_DISABLED = 0x00000002, 546954b75bSThomas Gleixner IRQS_POLL_INPROGRESS = 0x00000008, 553d67baecSThomas Gleixner IRQS_ONESHOT = 0x00000020, 56163ef309SThomas Gleixner IRQS_REPLAY = 0x00000040, 57163ef309SThomas Gleixner IRQS_WAITING = 0x00000080, 582a0d6fb3SThomas Gleixner IRQS_PENDING = 0x00000200, 59c531e836SThomas Gleixner IRQS_SUSPENDED = 0x00000800, 60bd062e76SThomas Gleixner }; 61bd062e76SThomas Gleixner 621ce6068dSThomas Gleixner #include "debug.h" 631ce6068dSThomas Gleixner #include "settings.h" 641ce6068dSThomas Gleixner 65a1ff541aSJiang Liu extern int __irq_set_trigger(struct irq_desc *desc, unsigned long flags); 6679ff1cdaSJiang Liu extern void __disable_irq(struct irq_desc *desc); 6779ff1cdaSJiang Liu extern void __enable_irq(struct irq_desc *desc); 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); 77328a4978SThomas Gleixner extern void unmask_threaded_irq(struct irq_desc *desc); 7846999238SThomas Gleixner 79f63b6a05SThomas Gleixner #ifdef CONFIG_SPARSE_IRQ 80f63b6a05SThomas Gleixner static inline void irq_mark_irq(unsigned int irq) { } 81f63b6a05SThomas Gleixner #else 82f63b6a05SThomas Gleixner extern void irq_mark_irq(unsigned int irq); 83f63b6a05SThomas Gleixner #endif 84f63b6a05SThomas Gleixner 8585ac16d0SYinghai Lu extern void init_kstat_irqs(struct irq_desc *desc, int node, int nr); 860fa0ebbfSMike Travis 87edd14cfeSKeith Busch irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc, unsigned int *flags); 8871f64340SHuang Shijie irqreturn_t handle_irq_event_percpu(struct irq_desc *desc); 894912609fSThomas Gleixner irqreturn_t handle_irq_event(struct irq_desc *desc); 904912609fSThomas Gleixner 91e144710bSThomas Gleixner /* Resending of interrupts :*/ 920798abebSJiang Liu void check_irq_resend(struct irq_desc *desc); 93fe200ae4SThomas Gleixner bool irq_wait_for_poll(struct irq_desc *desc); 94a92444c6SThomas Gleixner void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action); 95e144710bSThomas Gleixner 961da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 972c6927a3SYinghai Lu extern void register_irq_proc(unsigned int irq, struct irq_desc *desc); 9813bfe99eSThomas Gleixner extern void unregister_irq_proc(unsigned int irq, struct irq_desc *desc); 991da177e4SLinus Torvalds extern void register_handler_proc(unsigned int irq, struct irqaction *action); 1001da177e4SLinus Torvalds extern void unregister_handler_proc(unsigned int irq, struct irqaction *action); 1011da177e4SLinus Torvalds #else 1022c6927a3SYinghai Lu static inline void register_irq_proc(unsigned int irq, struct irq_desc *desc) { } 10313bfe99eSThomas Gleixner static inline void unregister_irq_proc(unsigned int irq, struct irq_desc *desc) { } 1041da177e4SLinus Torvalds static inline void register_handler_proc(unsigned int irq, 1051da177e4SLinus Torvalds struct irqaction *action) { } 1061da177e4SLinus Torvalds static inline void unregister_handler_proc(unsigned int irq, 1071da177e4SLinus Torvalds struct irqaction *action) { } 1081da177e4SLinus Torvalds #endif 1091da177e4SLinus Torvalds 1109c255583SThomas Gleixner extern bool irq_can_set_affinity_usr(unsigned int irq); 1119c255583SThomas Gleixner 1123b8249e7SThomas Gleixner extern int irq_select_affinity_usr(unsigned int irq, struct cpumask *mask); 113f6d87f4bSThomas Gleixner 114591d2fb0SThomas Gleixner extern void irq_set_thread_affinity(struct irq_desc *desc); 11557b150ccSYinghai Lu 116818b0f3bSJiang Liu extern int irq_do_set_affinity(struct irq_data *data, 117818b0f3bSJiang Liu const struct cpumask *dest, bool force); 118818b0f3bSJiang Liu 11970aedd24SThomas Gleixner /* Inline functions for support of irq chips on slow busses */ 1203876ec9eSThomas Gleixner static inline void chip_bus_lock(struct irq_desc *desc) 12170aedd24SThomas Gleixner { 1223876ec9eSThomas Gleixner if (unlikely(desc->irq_data.chip->irq_bus_lock)) 1233876ec9eSThomas Gleixner desc->irq_data.chip->irq_bus_lock(&desc->irq_data); 12470aedd24SThomas Gleixner } 12570aedd24SThomas Gleixner 1263876ec9eSThomas Gleixner static inline void chip_bus_sync_unlock(struct irq_desc *desc) 12770aedd24SThomas Gleixner { 1283876ec9eSThomas Gleixner if (unlikely(desc->irq_data.chip->irq_bus_sync_unlock)) 1293876ec9eSThomas Gleixner desc->irq_data.chip->irq_bus_sync_unlock(&desc->irq_data); 13070aedd24SThomas Gleixner } 13170aedd24SThomas Gleixner 13231d9d9b6SMarc Zyngier #define _IRQ_DESC_CHECK (1 << 0) 13331d9d9b6SMarc Zyngier #define _IRQ_DESC_PERCPU (1 << 1) 13431d9d9b6SMarc Zyngier 13531d9d9b6SMarc Zyngier #define IRQ_GET_DESC_CHECK_GLOBAL (_IRQ_DESC_CHECK) 13631d9d9b6SMarc Zyngier #define IRQ_GET_DESC_CHECK_PERCPU (_IRQ_DESC_CHECK | _IRQ_DESC_PERCPU) 13731d9d9b6SMarc Zyngier 138f944b5a7SDaniel Lezcano #define for_each_action_of_desc(desc, act) \ 139f944b5a7SDaniel Lezcano for (act = desc->act; act; act = act->next) 140f944b5a7SDaniel Lezcano 141d5eb4ad2SThomas Gleixner struct irq_desc * 14231d9d9b6SMarc Zyngier __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus, 14331d9d9b6SMarc Zyngier unsigned int check); 144d5eb4ad2SThomas Gleixner void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus); 145d5eb4ad2SThomas Gleixner 146d5eb4ad2SThomas Gleixner static inline struct irq_desc * 14731d9d9b6SMarc Zyngier irq_get_desc_buslock(unsigned int irq, unsigned long *flags, unsigned int check) 148d5eb4ad2SThomas Gleixner { 14931d9d9b6SMarc Zyngier return __irq_get_desc_lock(irq, flags, true, check); 150d5eb4ad2SThomas Gleixner } 151d5eb4ad2SThomas Gleixner 152d5eb4ad2SThomas Gleixner static inline void 153d5eb4ad2SThomas Gleixner irq_put_desc_busunlock(struct irq_desc *desc, unsigned long flags) 154d5eb4ad2SThomas Gleixner { 155d5eb4ad2SThomas Gleixner __irq_put_desc_unlock(desc, flags, true); 156d5eb4ad2SThomas Gleixner } 157d5eb4ad2SThomas Gleixner 158d5eb4ad2SThomas Gleixner static inline struct irq_desc * 15931d9d9b6SMarc Zyngier irq_get_desc_lock(unsigned int irq, unsigned long *flags, unsigned int check) 160d5eb4ad2SThomas Gleixner { 16131d9d9b6SMarc Zyngier return __irq_get_desc_lock(irq, flags, false, check); 162d5eb4ad2SThomas Gleixner } 163d5eb4ad2SThomas Gleixner 164d5eb4ad2SThomas Gleixner static inline void 165d5eb4ad2SThomas Gleixner irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags) 166d5eb4ad2SThomas Gleixner { 167d5eb4ad2SThomas Gleixner __irq_put_desc_unlock(desc, flags, false); 168d5eb4ad2SThomas Gleixner } 169d5eb4ad2SThomas Gleixner 170b354286eSBoqun Feng #define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors) 171b354286eSBoqun Feng 172*087cdfb6SThomas Gleixner static inline unsigned int irqd_get(struct irq_data *d) 173*087cdfb6SThomas Gleixner { 174*087cdfb6SThomas Gleixner return __irqd_to_state(d); 175*087cdfb6SThomas Gleixner } 176*087cdfb6SThomas Gleixner 17743f77759SIngo Molnar /* 178f230b6d5SThomas Gleixner * Manipulation functions for irq_data.state 179f230b6d5SThomas Gleixner */ 180f230b6d5SThomas Gleixner static inline void irqd_set_move_pending(struct irq_data *d) 181f230b6d5SThomas Gleixner { 1820d0b4c86SJiang Liu __irqd_to_state(d) |= IRQD_SETAFFINITY_PENDING; 183f230b6d5SThomas Gleixner } 184f230b6d5SThomas Gleixner 185f230b6d5SThomas Gleixner static inline void irqd_clr_move_pending(struct irq_data *d) 186f230b6d5SThomas Gleixner { 1870d0b4c86SJiang Liu __irqd_to_state(d) &= ~IRQD_SETAFFINITY_PENDING; 188f230b6d5SThomas Gleixner } 189a005677bSThomas Gleixner 190a005677bSThomas Gleixner static inline void irqd_clear(struct irq_data *d, unsigned int mask) 191a005677bSThomas Gleixner { 1920d0b4c86SJiang Liu __irqd_to_state(d) &= ~mask; 193a005677bSThomas Gleixner } 194a005677bSThomas Gleixner 195a005677bSThomas Gleixner static inline void irqd_set(struct irq_data *d, unsigned int mask) 196a005677bSThomas Gleixner { 1970d0b4c86SJiang Liu __irqd_to_state(d) |= mask; 198a005677bSThomas Gleixner } 199a005677bSThomas Gleixner 2002bdd1055SThomas Gleixner static inline bool irqd_has_set(struct irq_data *d, unsigned int mask) 2012bdd1055SThomas Gleixner { 2020d0b4c86SJiang Liu return __irqd_to_state(d) & mask; 2032bdd1055SThomas Gleixner } 2048f945a33SThomas Gleixner 205b354286eSBoqun Feng #undef __irqd_to_state 206b354286eSBoqun Feng 207b51bf95cSJiang Liu static inline void kstat_incr_irqs_this_cpu(struct irq_desc *desc) 2088f945a33SThomas Gleixner { 2098f945a33SThomas Gleixner __this_cpu_inc(*desc->kstat_irqs); 2108f945a33SThomas Gleixner __this_cpu_inc(kstat.irqs_sum); 2118f945a33SThomas Gleixner } 212cab303beSThomas Gleixner 2136783011bSJiang Liu static inline int irq_desc_get_node(struct irq_desc *desc) 2146783011bSJiang Liu { 215449e9caeSJiang Liu return irq_common_data_get_node(&desc->irq_common_data); 2166783011bSJiang Liu } 2176783011bSJiang Liu 2184717f133SGrygorii Strashko static inline int irq_desc_is_chained(struct irq_desc *desc) 2194717f133SGrygorii Strashko { 2204717f133SGrygorii Strashko return (desc->action && desc->action == &chained_action); 2214717f133SGrygorii Strashko } 2224717f133SGrygorii Strashko 223cab303beSThomas Gleixner #ifdef CONFIG_PM_SLEEP 2249ce7a258SThomas Gleixner bool irq_pm_check_wakeup(struct irq_desc *desc); 225cab303beSThomas Gleixner void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action); 226cab303beSThomas Gleixner void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action); 227cab303beSThomas Gleixner #else 2289ce7a258SThomas Gleixner static inline bool irq_pm_check_wakeup(struct irq_desc *desc) { return false; } 229cab303beSThomas Gleixner static inline void 230cab303beSThomas Gleixner irq_pm_install_action(struct irq_desc *desc, struct irqaction *action) { } 231cab303beSThomas Gleixner static inline void 232cab303beSThomas Gleixner irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action) { } 233cab303beSThomas Gleixner #endif 234f1602039SBartosz Golaszewski 235f1602039SBartosz Golaszewski #ifdef CONFIG_GENERIC_IRQ_CHIP 236f1602039SBartosz Golaszewski void irq_init_generic_chip(struct irq_chip_generic *gc, const char *name, 237f1602039SBartosz Golaszewski int num_ct, unsigned int irq_base, 238f1602039SBartosz Golaszewski void __iomem *reg_base, irq_flow_handler_t handler); 239f1602039SBartosz Golaszewski #else 240f1602039SBartosz Golaszewski static inline void 241f1602039SBartosz Golaszewski irq_init_generic_chip(struct irq_chip_generic *gc, const char *name, 242f1602039SBartosz Golaszewski int num_ct, unsigned int irq_base, 243f1602039SBartosz Golaszewski void __iomem *reg_base, irq_flow_handler_t handler) { } 244f1602039SBartosz Golaszewski #endif /* CONFIG_GENERIC_IRQ_CHIP */ 245*087cdfb6SThomas Gleixner 246*087cdfb6SThomas Gleixner #ifdef CONFIG_GENERIC_IRQ_DEBUGFS 247*087cdfb6SThomas Gleixner void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *desc); 248*087cdfb6SThomas Gleixner void irq_remove_debugfs_entry(struct irq_desc *desc); 249*087cdfb6SThomas Gleixner # ifdef CONFIG_IRQ_DOMAIN 250*087cdfb6SThomas Gleixner void irq_domain_debugfs_init(struct dentry *root); 251*087cdfb6SThomas Gleixner # else 252*087cdfb6SThomas Gleixner static inline void irq_domain_debugfs_init(struct dentry *root); 253*087cdfb6SThomas Gleixner # endif 254*087cdfb6SThomas Gleixner #else /* CONFIG_GENERIC_IRQ_DEBUGFS */ 255*087cdfb6SThomas Gleixner static inline void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *d) 256*087cdfb6SThomas Gleixner { 257*087cdfb6SThomas Gleixner } 258*087cdfb6SThomas Gleixner static inline void irq_remove_debugfs_entry(struct irq_desc *d) 259*087cdfb6SThomas Gleixner { 260*087cdfb6SThomas Gleixner } 261*087cdfb6SThomas Gleixner #endif /* CONFIG_GENERIC_IRQ_DEBUGFS */ 262