11da177e4SLinus Torvalds /* interrupt.h */ 21da177e4SLinus Torvalds #ifndef _LINUX_INTERRUPT_H 31da177e4SLinus Torvalds #define _LINUX_INTERRUPT_H 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds #include <linux/kernel.h> 61da177e4SLinus Torvalds #include <linux/linkage.h> 71da177e4SLinus Torvalds #include <linux/bitops.h> 81da177e4SLinus Torvalds #include <linux/preempt.h> 91da177e4SLinus Torvalds #include <linux/cpumask.h> 10908dcecdSJan Beulich #include <linux/irqreturn.h> 11dd3a1db9SThomas Gleixner #include <linux/irqnr.h> 121da177e4SLinus Torvalds #include <linux/hardirq.h> 13de30a2b3SIngo Molnar #include <linux/irqflags.h> 1454514a70SDavid S. Miller #include <linux/smp.h> 1554514a70SDavid S. Miller #include <linux/percpu.h> 169ba5f005SPeter Zijlstra #include <linux/hrtimer.h> 170ebb26e7SIngo Molnar 181da177e4SLinus Torvalds #include <asm/atomic.h> 191da177e4SLinus Torvalds #include <asm/ptrace.h> 201da177e4SLinus Torvalds #include <asm/system.h> 211da177e4SLinus Torvalds 226e213616SThomas Gleixner /* 236e213616SThomas Gleixner * These correspond to the IORESOURCE_IRQ_* defines in 246e213616SThomas Gleixner * linux/ioport.h to select the interrupt line behaviour. When 256e213616SThomas Gleixner * requesting an interrupt without specifying a IRQF_TRIGGER, the 266e213616SThomas Gleixner * setting should be assumed to be "as already configured", which 276e213616SThomas Gleixner * may be as per machine or firmware initialisation. 286e213616SThomas Gleixner */ 296e213616SThomas Gleixner #define IRQF_TRIGGER_NONE 0x00000000 306e213616SThomas Gleixner #define IRQF_TRIGGER_RISING 0x00000001 316e213616SThomas Gleixner #define IRQF_TRIGGER_FALLING 0x00000002 326e213616SThomas Gleixner #define IRQF_TRIGGER_HIGH 0x00000004 336e213616SThomas Gleixner #define IRQF_TRIGGER_LOW 0x00000008 346e213616SThomas Gleixner #define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \ 356e213616SThomas Gleixner IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING) 366e213616SThomas Gleixner #define IRQF_TRIGGER_PROBE 0x00000010 376e213616SThomas Gleixner 386e213616SThomas Gleixner /* 396e213616SThomas Gleixner * These flags used only by the kernel as part of the 406e213616SThomas Gleixner * irq handling routines. 416e213616SThomas Gleixner * 42*6932bf37SThomas Gleixner * IRQF_DISABLED - keep irqs disabled when calling the action handler. 43*6932bf37SThomas Gleixner * DEPRECATED. This flag is a NOOP and scheduled to be removed 446e213616SThomas Gleixner * IRQF_SAMPLE_RANDOM - irq is used to feed the random generator 456e213616SThomas Gleixner * IRQF_SHARED - allow sharing the irq among several devices 466e213616SThomas Gleixner * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur 476e213616SThomas Gleixner * IRQF_TIMER - Flag to mark this interrupt as timer interrupt 48950f4427SThomas Gleixner * IRQF_PERCPU - Interrupt is per cpu 49950f4427SThomas Gleixner * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing 50d85a60d8SBernhard Walle * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is 51d85a60d8SBernhard Walle * registered first in an shared interrupt is considered for 52d85a60d8SBernhard Walle * performance reasons) 53b25c340cSThomas Gleixner * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler finished. 54b25c340cSThomas Gleixner * Used by threaded interrupts which need to keep the 55b25c340cSThomas Gleixner * irq line disabled until the threaded handler has been run. 566e213616SThomas Gleixner */ 576e213616SThomas Gleixner #define IRQF_DISABLED 0x00000020 586e213616SThomas Gleixner #define IRQF_SAMPLE_RANDOM 0x00000040 596e213616SThomas Gleixner #define IRQF_SHARED 0x00000080 606e213616SThomas Gleixner #define IRQF_PROBE_SHARED 0x00000100 616e213616SThomas Gleixner #define IRQF_TIMER 0x00000200 62284c6680SThomas Gleixner #define IRQF_PERCPU 0x00000400 63950f4427SThomas Gleixner #define IRQF_NOBALANCING 0x00000800 64d85a60d8SBernhard Walle #define IRQF_IRQPOLL 0x00001000 65b25c340cSThomas Gleixner #define IRQF_ONESHOT 0x00002000 666e213616SThomas Gleixner 673aa551c9SThomas Gleixner /* 683aa551c9SThomas Gleixner * Bits used by threaded handlers: 693aa551c9SThomas Gleixner * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run 703aa551c9SThomas Gleixner * IRQTF_DIED - handler thread died 71f48fe81eSThomas Gleixner * IRQTF_WARNED - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed 72591d2fb0SThomas Gleixner * IRQTF_AFFINITY - irq thread is requested to adjust affinity 733aa551c9SThomas Gleixner */ 743aa551c9SThomas Gleixner enum { 753aa551c9SThomas Gleixner IRQTF_RUNTHREAD, 763aa551c9SThomas Gleixner IRQTF_DIED, 77f48fe81eSThomas Gleixner IRQTF_WARNED, 78591d2fb0SThomas Gleixner IRQTF_AFFINITY, 793aa551c9SThomas Gleixner }; 803aa551c9SThomas Gleixner 81ae731f8dSMarc Zyngier /** 82ae731f8dSMarc Zyngier * These values can be returned by request_any_context_irq() and 83ae731f8dSMarc Zyngier * describe the context the interrupt will be run in. 84ae731f8dSMarc Zyngier * 85ae731f8dSMarc Zyngier * IRQC_IS_HARDIRQ - interrupt runs in hardirq context 86ae731f8dSMarc Zyngier * IRQC_IS_NESTED - interrupt runs in a nested threaded context 87ae731f8dSMarc Zyngier */ 88ae731f8dSMarc Zyngier enum { 89ae731f8dSMarc Zyngier IRQC_IS_HARDIRQ = 0, 90ae731f8dSMarc Zyngier IRQC_IS_NESTED, 91ae731f8dSMarc Zyngier }; 92ae731f8dSMarc Zyngier 937d12e780SDavid Howells typedef irqreturn_t (*irq_handler_t)(int, void *); 94da482792SDavid Howells 95a9d0a1a3SThomas Gleixner /** 96a9d0a1a3SThomas Gleixner * struct irqaction - per interrupt action descriptor 97a9d0a1a3SThomas Gleixner * @handler: interrupt handler function 98a9d0a1a3SThomas Gleixner * @flags: flags (see IRQF_* above) 99a9d0a1a3SThomas Gleixner * @name: name of the device 100a9d0a1a3SThomas Gleixner * @dev_id: cookie to identify the device 101a9d0a1a3SThomas Gleixner * @next: pointer to the next irqaction for shared interrupts 102a9d0a1a3SThomas Gleixner * @irq: interrupt number 103a9d0a1a3SThomas Gleixner * @dir: pointer to the proc/irq/NN/name entry 1043aa551c9SThomas Gleixner * @thread_fn: interupt handler function for threaded interrupts 1053aa551c9SThomas Gleixner * @thread: thread pointer for threaded interrupts 1063aa551c9SThomas Gleixner * @thread_flags: flags related to @thread 107a9d0a1a3SThomas Gleixner */ 1081da177e4SLinus Torvalds struct irqaction { 109da482792SDavid Howells irq_handler_t handler; 1101da177e4SLinus Torvalds unsigned long flags; 1111da177e4SLinus Torvalds const char *name; 1121da177e4SLinus Torvalds void *dev_id; 1131da177e4SLinus Torvalds struct irqaction *next; 1141da177e4SLinus Torvalds int irq; 1151da177e4SLinus Torvalds struct proc_dir_entry *dir; 1163aa551c9SThomas Gleixner irq_handler_t thread_fn; 1173aa551c9SThomas Gleixner struct task_struct *thread; 1183aa551c9SThomas Gleixner unsigned long thread_flags; 1191da177e4SLinus Torvalds }; 1201da177e4SLinus Torvalds 1217d12e780SDavid Howells extern irqreturn_t no_action(int cpl, void *dev_id); 1223aa551c9SThomas Gleixner 1233a38148fSThomas Gleixner #ifdef CONFIG_GENERIC_HARDIRQS 1243aa551c9SThomas Gleixner extern int __must_check 1253aa551c9SThomas Gleixner request_threaded_irq(unsigned int irq, irq_handler_t handler, 1263aa551c9SThomas Gleixner irq_handler_t thread_fn, 1273aa551c9SThomas Gleixner unsigned long flags, const char *name, void *dev); 1283aa551c9SThomas Gleixner 1293aa551c9SThomas Gleixner static inline int __must_check 1303aa551c9SThomas Gleixner request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, 1313aa551c9SThomas Gleixner const char *name, void *dev) 1323aa551c9SThomas Gleixner { 1333aa551c9SThomas Gleixner return request_threaded_irq(irq, handler, NULL, flags, name, dev); 1343aa551c9SThomas Gleixner } 1353aa551c9SThomas Gleixner 136ae731f8dSMarc Zyngier extern int __must_check 137ae731f8dSMarc Zyngier request_any_context_irq(unsigned int irq, irq_handler_t handler, 138ae731f8dSMarc Zyngier unsigned long flags, const char *name, void *dev_id); 139ae731f8dSMarc Zyngier 1403aa551c9SThomas Gleixner extern void exit_irq_thread(void); 1413aa551c9SThomas Gleixner #else 1423a38148fSThomas Gleixner 1433a38148fSThomas Gleixner extern int __must_check 1443a38148fSThomas Gleixner request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, 1453a38148fSThomas Gleixner const char *name, void *dev); 1463a38148fSThomas Gleixner 147de18836eSThomas Gleixner /* 148de18836eSThomas Gleixner * Special function to avoid ifdeffery in kernel/irq/devres.c which 149de18836eSThomas Gleixner * gets magically built by GENERIC_HARDIRQS=n architectures (sparc, 150de18836eSThomas Gleixner * m68k). I really love these $@%#!* obvious Makefile references: 151de18836eSThomas Gleixner * ../../../kernel/irq/devres.o 152de18836eSThomas Gleixner */ 153de18836eSThomas Gleixner static inline int __must_check 154de18836eSThomas Gleixner request_threaded_irq(unsigned int irq, irq_handler_t handler, 155de18836eSThomas Gleixner irq_handler_t thread_fn, 156de18836eSThomas Gleixner unsigned long flags, const char *name, void *dev) 157de18836eSThomas Gleixner { 158de18836eSThomas Gleixner return request_irq(irq, handler, flags, name, dev); 159de18836eSThomas Gleixner } 160de18836eSThomas Gleixner 161ae731f8dSMarc Zyngier static inline int __must_check 162ae731f8dSMarc Zyngier request_any_context_irq(unsigned int irq, irq_handler_t handler, 163ae731f8dSMarc Zyngier unsigned long flags, const char *name, void *dev_id) 164ae731f8dSMarc Zyngier { 165ae731f8dSMarc Zyngier return request_irq(irq, handler, flags, name, dev_id); 166ae731f8dSMarc Zyngier } 167ae731f8dSMarc Zyngier 1683aa551c9SThomas Gleixner static inline void exit_irq_thread(void) { } 1693aa551c9SThomas Gleixner #endif 1703aa551c9SThomas Gleixner 1711da177e4SLinus Torvalds extern void free_irq(unsigned int, void *); 1721da177e4SLinus Torvalds 1730af3678fSAl Viro struct device; 1740af3678fSAl Viro 175935bd5b9SArjan van de Ven extern int __must_check 176935bd5b9SArjan van de Ven devm_request_threaded_irq(struct device *dev, unsigned int irq, 177935bd5b9SArjan van de Ven irq_handler_t handler, irq_handler_t thread_fn, 178935bd5b9SArjan van de Ven unsigned long irqflags, const char *devname, 179935bd5b9SArjan van de Ven void *dev_id); 180935bd5b9SArjan van de Ven 181935bd5b9SArjan van de Ven static inline int __must_check 182935bd5b9SArjan van de Ven devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler, 183935bd5b9SArjan van de Ven unsigned long irqflags, const char *devname, void *dev_id) 184935bd5b9SArjan van de Ven { 185935bd5b9SArjan van de Ven return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags, 186935bd5b9SArjan van de Ven devname, dev_id); 187935bd5b9SArjan van de Ven } 188935bd5b9SArjan van de Ven 1899ac7849eSTejun Heo extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id); 1909ac7849eSTejun Heo 191d7e9629dSIngo Molnar /* 192d7e9629dSIngo Molnar * On lockdep we dont want to enable hardirqs in hardirq 193d7e9629dSIngo Molnar * context. Use local_irq_enable_in_hardirq() to annotate 194d7e9629dSIngo Molnar * kernel code that has to do this nevertheless (pretty much 195d7e9629dSIngo Molnar * the only valid case is for old/broken hardware that is 196d7e9629dSIngo Molnar * insanely slow). 197d7e9629dSIngo Molnar * 198d7e9629dSIngo Molnar * NOTE: in theory this might break fragile code that relies 199d7e9629dSIngo Molnar * on hardirq delivery - in practice we dont seem to have such 200d7e9629dSIngo Molnar * places left. So the only effect should be slightly increased 201d7e9629dSIngo Molnar * irqs-off latencies. 202d7e9629dSIngo Molnar */ 203d7e9629dSIngo Molnar #ifdef CONFIG_LOCKDEP 204d7e9629dSIngo Molnar # define local_irq_enable_in_hardirq() do { } while (0) 205d7e9629dSIngo Molnar #else 206d7e9629dSIngo Molnar # define local_irq_enable_in_hardirq() local_irq_enable() 207d7e9629dSIngo Molnar #endif 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds extern void disable_irq_nosync(unsigned int irq); 2101da177e4SLinus Torvalds extern void disable_irq(unsigned int irq); 2111da177e4SLinus Torvalds extern void enable_irq(unsigned int irq); 212ba9a2331SThomas Gleixner 2130a0c5168SRafael J. Wysocki /* The following three functions are for the core kernel use only. */ 2145818a6e2SHeiko Carstens #ifdef CONFIG_GENERIC_HARDIRQS 2150a0c5168SRafael J. Wysocki extern void suspend_device_irqs(void); 2160a0c5168SRafael J. Wysocki extern void resume_device_irqs(void); 2170a0c5168SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP 2180a0c5168SRafael J. Wysocki extern int check_wakeup_irqs(void); 2190a0c5168SRafael J. Wysocki #else 2200a0c5168SRafael J. Wysocki static inline int check_wakeup_irqs(void) { return 0; } 2210a0c5168SRafael J. Wysocki #endif 2225818a6e2SHeiko Carstens #else 2235818a6e2SHeiko Carstens static inline void suspend_device_irqs(void) { }; 2245818a6e2SHeiko Carstens static inline void resume_device_irqs(void) { }; 2255818a6e2SHeiko Carstens static inline int check_wakeup_irqs(void) { return 0; } 2265818a6e2SHeiko Carstens #endif 2270a0c5168SRafael J. Wysocki 228d7b90689SRussell King #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS) 229d7b90689SRussell King 230d036e67bSRusty Russell extern cpumask_var_t irq_default_affinity; 23118404756SMax Krasnyansky 2320de26520SRusty Russell extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask); 233d7b90689SRussell King extern int irq_can_set_affinity(unsigned int irq); 23418404756SMax Krasnyansky extern int irq_select_affinity(unsigned int irq); 235d7b90689SRussell King 236d7b90689SRussell King #else /* CONFIG_SMP */ 237d7b90689SRussell King 2380de26520SRusty Russell static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m) 239d7b90689SRussell King { 240d7b90689SRussell King return -EINVAL; 241d7b90689SRussell King } 242d7b90689SRussell King 243d7b90689SRussell King static inline int irq_can_set_affinity(unsigned int irq) 244d7b90689SRussell King { 245d7b90689SRussell King return 0; 246d7b90689SRussell King } 247d7b90689SRussell King 24818404756SMax Krasnyansky static inline int irq_select_affinity(unsigned int irq) { return 0; } 24918404756SMax Krasnyansky 250d7b90689SRussell King #endif /* CONFIG_SMP && CONFIG_GENERIC_HARDIRQS */ 251d7b90689SRussell King 252e9ed7e72SAl Viro #ifdef CONFIG_GENERIC_HARDIRQS 253c01d403bSIngo Molnar /* 254c01d403bSIngo Molnar * Special lockdep variants of irq disabling/enabling. 255c01d403bSIngo Molnar * These should be used for locking constructs that 256c01d403bSIngo Molnar * know that a particular irq context which is disabled, 257c01d403bSIngo Molnar * and which is the only irq-context user of a lock, 258c01d403bSIngo Molnar * that it's safe to take the lock in the irq-disabled 259c01d403bSIngo Molnar * section without disabling hardirqs. 260c01d403bSIngo Molnar * 261c01d403bSIngo Molnar * On !CONFIG_LOCKDEP they are equivalent to the normal 262c01d403bSIngo Molnar * irq disable/enable methods. 263c01d403bSIngo Molnar */ 264c01d403bSIngo Molnar static inline void disable_irq_nosync_lockdep(unsigned int irq) 265c01d403bSIngo Molnar { 266c01d403bSIngo Molnar disable_irq_nosync(irq); 267c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP 268c01d403bSIngo Molnar local_irq_disable(); 269c01d403bSIngo Molnar #endif 270c01d403bSIngo Molnar } 271c01d403bSIngo Molnar 272e8106b94SArjan van de Ven static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags) 273e8106b94SArjan van de Ven { 274e8106b94SArjan van de Ven disable_irq_nosync(irq); 275e8106b94SArjan van de Ven #ifdef CONFIG_LOCKDEP 276e8106b94SArjan van de Ven local_irq_save(*flags); 277e8106b94SArjan van de Ven #endif 278e8106b94SArjan van de Ven } 279e8106b94SArjan van de Ven 280c01d403bSIngo Molnar static inline void disable_irq_lockdep(unsigned int irq) 281c01d403bSIngo Molnar { 282c01d403bSIngo Molnar disable_irq(irq); 283c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP 284c01d403bSIngo Molnar local_irq_disable(); 285c01d403bSIngo Molnar #endif 286c01d403bSIngo Molnar } 287c01d403bSIngo Molnar 288c01d403bSIngo Molnar static inline void enable_irq_lockdep(unsigned int irq) 289c01d403bSIngo Molnar { 290c01d403bSIngo Molnar #ifdef CONFIG_LOCKDEP 291c01d403bSIngo Molnar local_irq_enable(); 292c01d403bSIngo Molnar #endif 293c01d403bSIngo Molnar enable_irq(irq); 294c01d403bSIngo Molnar } 295c01d403bSIngo Molnar 296e8106b94SArjan van de Ven static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags) 297e8106b94SArjan van de Ven { 298e8106b94SArjan van de Ven #ifdef CONFIG_LOCKDEP 299e8106b94SArjan van de Ven local_irq_restore(*flags); 300e8106b94SArjan van de Ven #endif 301e8106b94SArjan van de Ven enable_irq(irq); 302e8106b94SArjan van de Ven } 303e8106b94SArjan van de Ven 304ba9a2331SThomas Gleixner /* IRQ wakeup (PM) control: */ 305ba9a2331SThomas Gleixner extern int set_irq_wake(unsigned int irq, unsigned int on); 306ba9a2331SThomas Gleixner 307ba9a2331SThomas Gleixner static inline int enable_irq_wake(unsigned int irq) 308ba9a2331SThomas Gleixner { 309ba9a2331SThomas Gleixner return set_irq_wake(irq, 1); 310ba9a2331SThomas Gleixner } 311ba9a2331SThomas Gleixner 312ba9a2331SThomas Gleixner static inline int disable_irq_wake(unsigned int irq) 313ba9a2331SThomas Gleixner { 314ba9a2331SThomas Gleixner return set_irq_wake(irq, 0); 315ba9a2331SThomas Gleixner } 316ba9a2331SThomas Gleixner 317c01d403bSIngo Molnar #else /* !CONFIG_GENERIC_HARDIRQS */ 318c01d403bSIngo Molnar /* 319c01d403bSIngo Molnar * NOTE: non-genirq architectures, if they want to support the lock 320c01d403bSIngo Molnar * validator need to define the methods below in their asm/irq.h 321c01d403bSIngo Molnar * files, under an #ifdef CONFIG_LOCKDEP section. 322c01d403bSIngo Molnar */ 323c01d403bSIngo Molnar #ifndef CONFIG_LOCKDEP 324c01d403bSIngo Molnar # define disable_irq_nosync_lockdep(irq) disable_irq_nosync(irq) 325b3e2fd9cSRoman Zippel # define disable_irq_nosync_lockdep_irqsave(irq, flags) \ 326b3e2fd9cSRoman Zippel disable_irq_nosync(irq) 327c01d403bSIngo Molnar # define disable_irq_lockdep(irq) disable_irq(irq) 328c01d403bSIngo Molnar # define enable_irq_lockdep(irq) enable_irq(irq) 329b3e2fd9cSRoman Zippel # define enable_irq_lockdep_irqrestore(irq, flags) \ 330b3e2fd9cSRoman Zippel enable_irq(irq) 3311da177e4SLinus Torvalds # endif 3321da177e4SLinus Torvalds 333aa5346a2SGuennadi Liakhovetski static inline int enable_irq_wake(unsigned int irq) 334aa5346a2SGuennadi Liakhovetski { 335aa5346a2SGuennadi Liakhovetski return 0; 336aa5346a2SGuennadi Liakhovetski } 337aa5346a2SGuennadi Liakhovetski 338aa5346a2SGuennadi Liakhovetski static inline int disable_irq_wake(unsigned int irq) 339aa5346a2SGuennadi Liakhovetski { 340aa5346a2SGuennadi Liakhovetski return 0; 341aa5346a2SGuennadi Liakhovetski } 342c01d403bSIngo Molnar #endif /* CONFIG_GENERIC_HARDIRQS */ 343c01d403bSIngo Molnar 3443f74478bSAndi Kleen #ifndef __ARCH_SET_SOFTIRQ_PENDING 3453f74478bSAndi Kleen #define set_softirq_pending(x) (local_softirq_pending() = (x)) 3463f74478bSAndi Kleen #define or_softirq_pending(x) (local_softirq_pending() |= (x)) 3473f74478bSAndi Kleen #endif 3483f74478bSAndi Kleen 3492d3fbbb3SBenjamin Herrenschmidt /* Some architectures might implement lazy enabling/disabling of 3502d3fbbb3SBenjamin Herrenschmidt * interrupts. In some cases, such as stop_machine, we might want 3512d3fbbb3SBenjamin Herrenschmidt * to ensure that after a local_irq_disable(), interrupts have 3522d3fbbb3SBenjamin Herrenschmidt * really been disabled in hardware. Such architectures need to 3532d3fbbb3SBenjamin Herrenschmidt * implement the following hook. 3542d3fbbb3SBenjamin Herrenschmidt */ 3552d3fbbb3SBenjamin Herrenschmidt #ifndef hard_irq_disable 3562d3fbbb3SBenjamin Herrenschmidt #define hard_irq_disable() do { } while(0) 3572d3fbbb3SBenjamin Herrenschmidt #endif 3582d3fbbb3SBenjamin Herrenschmidt 3591da177e4SLinus Torvalds /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high 3601da177e4SLinus Torvalds frequency threaded job scheduling. For almost all the purposes 3611da177e4SLinus Torvalds tasklets are more than enough. F.e. all serial device BHs et 3621da177e4SLinus Torvalds al. should be converted to tasklets, not to softirqs. 3631da177e4SLinus Torvalds */ 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds enum 3661da177e4SLinus Torvalds { 3671da177e4SLinus Torvalds HI_SOFTIRQ=0, 3681da177e4SLinus Torvalds TIMER_SOFTIRQ, 3691da177e4SLinus Torvalds NET_TX_SOFTIRQ, 3701da177e4SLinus Torvalds NET_RX_SOFTIRQ, 371ff856badSJens Axboe BLOCK_SOFTIRQ, 3725e605b64SJens Axboe BLOCK_IOPOLL_SOFTIRQ, 373c9819f45SChristoph Lameter TASKLET_SOFTIRQ, 374c9819f45SChristoph Lameter SCHED_SOFTIRQ, 375a6037b61SPeter Zijlstra HRTIMER_SOFTIRQ, 376c2d727aaSDipankar Sarma RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */ 377978b0116SAlexey Dobriyan 378978b0116SAlexey Dobriyan NR_SOFTIRQS 3791da177e4SLinus Torvalds }; 3801da177e4SLinus Torvalds 3815d592b44SJason Baron /* map softirq index to softirq name. update 'softirq_to_name' in 3825d592b44SJason Baron * kernel/softirq.c when adding a new softirq. 3835d592b44SJason Baron */ 3845d592b44SJason Baron extern char *softirq_to_name[NR_SOFTIRQS]; 3855d592b44SJason Baron 3861da177e4SLinus Torvalds /* softirq mask and active fields moved to irq_cpustat_t in 3871da177e4SLinus Torvalds * asm/hardirq.h to get better cache usage. KAO 3881da177e4SLinus Torvalds */ 3891da177e4SLinus Torvalds 3901da177e4SLinus Torvalds struct softirq_action 3911da177e4SLinus Torvalds { 3921da177e4SLinus Torvalds void (*action)(struct softirq_action *); 3931da177e4SLinus Torvalds }; 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds asmlinkage void do_softirq(void); 396eb0f1c44SAdrian Bunk asmlinkage void __do_softirq(void); 397962cf36cSCarlos R. Mafra extern void open_softirq(int nr, void (*action)(struct softirq_action *)); 3981da177e4SLinus Torvalds extern void softirq_init(void); 3993f74478bSAndi Kleen #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0) 400b3c97528SHarvey Harrison extern void raise_softirq_irqoff(unsigned int nr); 401b3c97528SHarvey Harrison extern void raise_softirq(unsigned int nr); 4027f1e2ca9SPeter Zijlstra extern void wakeup_softirqd(void); 4031da177e4SLinus Torvalds 40454514a70SDavid S. Miller /* This is the worklist that queues up per-cpu softirq work. 40554514a70SDavid S. Miller * 40654514a70SDavid S. Miller * send_remote_sendirq() adds work to these lists, and 40754514a70SDavid S. Miller * the softirq handler itself dequeues from them. The queues 40854514a70SDavid S. Miller * are protected by disabling local cpu interrupts and they must 40954514a70SDavid S. Miller * only be accessed by the local cpu that they are for. 41054514a70SDavid S. Miller */ 41154514a70SDavid S. Miller DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list); 41254514a70SDavid S. Miller 41354514a70SDavid S. Miller /* Try to send a softirq to a remote cpu. If this cannot be done, the 41454514a70SDavid S. Miller * work will be queued to the local cpu. 41554514a70SDavid S. Miller */ 41654514a70SDavid S. Miller extern void send_remote_softirq(struct call_single_data *cp, int cpu, int softirq); 41754514a70SDavid S. Miller 41854514a70SDavid S. Miller /* Like send_remote_softirq(), but the caller must disable local cpu interrupts 41954514a70SDavid S. Miller * and compute the current cpu, passed in as 'this_cpu'. 42054514a70SDavid S. Miller */ 42154514a70SDavid S. Miller extern void __send_remote_softirq(struct call_single_data *cp, int cpu, 42254514a70SDavid S. Miller int this_cpu, int softirq); 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds /* Tasklets --- multithreaded analogue of BHs. 4251da177e4SLinus Torvalds 4261da177e4SLinus Torvalds Main feature differing them of generic softirqs: tasklet 4271da177e4SLinus Torvalds is running only on one CPU simultaneously. 4281da177e4SLinus Torvalds 4291da177e4SLinus Torvalds Main feature differing them of BHs: different tasklets 4301da177e4SLinus Torvalds may be run simultaneously on different CPUs. 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds Properties: 4331da177e4SLinus Torvalds * If tasklet_schedule() is called, then tasklet is guaranteed 4341da177e4SLinus Torvalds to be executed on some cpu at least once after this. 4351da177e4SLinus Torvalds * If the tasklet is already scheduled, but its excecution is still not 4361da177e4SLinus Torvalds started, it will be executed only once. 4371da177e4SLinus Torvalds * If this tasklet is already running on another CPU (or schedule is called 4381da177e4SLinus Torvalds from tasklet itself), it is rescheduled for later. 4391da177e4SLinus Torvalds * Tasklet is strictly serialized wrt itself, but not 4401da177e4SLinus Torvalds wrt another tasklets. If client needs some intertask synchronization, 4411da177e4SLinus Torvalds he makes it with spinlocks. 4421da177e4SLinus Torvalds */ 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvalds struct tasklet_struct 4451da177e4SLinus Torvalds { 4461da177e4SLinus Torvalds struct tasklet_struct *next; 4471da177e4SLinus Torvalds unsigned long state; 4481da177e4SLinus Torvalds atomic_t count; 4491da177e4SLinus Torvalds void (*func)(unsigned long); 4501da177e4SLinus Torvalds unsigned long data; 4511da177e4SLinus Torvalds }; 4521da177e4SLinus Torvalds 4531da177e4SLinus Torvalds #define DECLARE_TASKLET(name, func, data) \ 4541da177e4SLinus Torvalds struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data } 4551da177e4SLinus Torvalds 4561da177e4SLinus Torvalds #define DECLARE_TASKLET_DISABLED(name, func, data) \ 4571da177e4SLinus Torvalds struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data } 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds enum 4611da177e4SLinus Torvalds { 4621da177e4SLinus Torvalds TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */ 4631da177e4SLinus Torvalds TASKLET_STATE_RUN /* Tasklet is running (SMP only) */ 4641da177e4SLinus Torvalds }; 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds #ifdef CONFIG_SMP 4671da177e4SLinus Torvalds static inline int tasklet_trylock(struct tasklet_struct *t) 4681da177e4SLinus Torvalds { 4691da177e4SLinus Torvalds return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state); 4701da177e4SLinus Torvalds } 4711da177e4SLinus Torvalds 4721da177e4SLinus Torvalds static inline void tasklet_unlock(struct tasklet_struct *t) 4731da177e4SLinus Torvalds { 4741da177e4SLinus Torvalds smp_mb__before_clear_bit(); 4751da177e4SLinus Torvalds clear_bit(TASKLET_STATE_RUN, &(t)->state); 4761da177e4SLinus Torvalds } 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds static inline void tasklet_unlock_wait(struct tasklet_struct *t) 4791da177e4SLinus Torvalds { 4801da177e4SLinus Torvalds while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); } 4811da177e4SLinus Torvalds } 4821da177e4SLinus Torvalds #else 4831da177e4SLinus Torvalds #define tasklet_trylock(t) 1 4841da177e4SLinus Torvalds #define tasklet_unlock_wait(t) do { } while (0) 4851da177e4SLinus Torvalds #define tasklet_unlock(t) do { } while (0) 4861da177e4SLinus Torvalds #endif 4871da177e4SLinus Torvalds 488b3c97528SHarvey Harrison extern void __tasklet_schedule(struct tasklet_struct *t); 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds static inline void tasklet_schedule(struct tasklet_struct *t) 4911da177e4SLinus Torvalds { 4921da177e4SLinus Torvalds if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) 4931da177e4SLinus Torvalds __tasklet_schedule(t); 4941da177e4SLinus Torvalds } 4951da177e4SLinus Torvalds 496b3c97528SHarvey Harrison extern void __tasklet_hi_schedule(struct tasklet_struct *t); 4971da177e4SLinus Torvalds 4981da177e4SLinus Torvalds static inline void tasklet_hi_schedule(struct tasklet_struct *t) 4991da177e4SLinus Torvalds { 5001da177e4SLinus Torvalds if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) 5011da177e4SLinus Torvalds __tasklet_hi_schedule(t); 5021da177e4SLinus Torvalds } 5031da177e4SLinus Torvalds 5047c692cbaSVegard Nossum extern void __tasklet_hi_schedule_first(struct tasklet_struct *t); 5057c692cbaSVegard Nossum 5067c692cbaSVegard Nossum /* 5077c692cbaSVegard Nossum * This version avoids touching any other tasklets. Needed for kmemcheck 5087c692cbaSVegard Nossum * in order not to take any page faults while enqueueing this tasklet; 5097c692cbaSVegard Nossum * consider VERY carefully whether you really need this or 5107c692cbaSVegard Nossum * tasklet_hi_schedule()... 5117c692cbaSVegard Nossum */ 5127c692cbaSVegard Nossum static inline void tasklet_hi_schedule_first(struct tasklet_struct *t) 5137c692cbaSVegard Nossum { 5147c692cbaSVegard Nossum if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) 5157c692cbaSVegard Nossum __tasklet_hi_schedule_first(t); 5167c692cbaSVegard Nossum } 5177c692cbaSVegard Nossum 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds static inline void tasklet_disable_nosync(struct tasklet_struct *t) 5201da177e4SLinus Torvalds { 5211da177e4SLinus Torvalds atomic_inc(&t->count); 5221da177e4SLinus Torvalds smp_mb__after_atomic_inc(); 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds static inline void tasklet_disable(struct tasklet_struct *t) 5261da177e4SLinus Torvalds { 5271da177e4SLinus Torvalds tasklet_disable_nosync(t); 5281da177e4SLinus Torvalds tasklet_unlock_wait(t); 5291da177e4SLinus Torvalds smp_mb(); 5301da177e4SLinus Torvalds } 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds static inline void tasklet_enable(struct tasklet_struct *t) 5331da177e4SLinus Torvalds { 5341da177e4SLinus Torvalds smp_mb__before_atomic_dec(); 5351da177e4SLinus Torvalds atomic_dec(&t->count); 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds static inline void tasklet_hi_enable(struct tasklet_struct *t) 5391da177e4SLinus Torvalds { 5401da177e4SLinus Torvalds smp_mb__before_atomic_dec(); 5411da177e4SLinus Torvalds atomic_dec(&t->count); 5421da177e4SLinus Torvalds } 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds extern void tasklet_kill(struct tasklet_struct *t); 5451da177e4SLinus Torvalds extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu); 5461da177e4SLinus Torvalds extern void tasklet_init(struct tasklet_struct *t, 5471da177e4SLinus Torvalds void (*func)(unsigned long), unsigned long data); 5481da177e4SLinus Torvalds 5499ba5f005SPeter Zijlstra struct tasklet_hrtimer { 5509ba5f005SPeter Zijlstra struct hrtimer timer; 5519ba5f005SPeter Zijlstra struct tasklet_struct tasklet; 5529ba5f005SPeter Zijlstra enum hrtimer_restart (*function)(struct hrtimer *); 5539ba5f005SPeter Zijlstra }; 5549ba5f005SPeter Zijlstra 5559ba5f005SPeter Zijlstra extern void 5569ba5f005SPeter Zijlstra tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer, 5579ba5f005SPeter Zijlstra enum hrtimer_restart (*function)(struct hrtimer *), 5589ba5f005SPeter Zijlstra clockid_t which_clock, enum hrtimer_mode mode); 5599ba5f005SPeter Zijlstra 5609ba5f005SPeter Zijlstra static inline 5619ba5f005SPeter Zijlstra int tasklet_hrtimer_start(struct tasklet_hrtimer *ttimer, ktime_t time, 5629ba5f005SPeter Zijlstra const enum hrtimer_mode mode) 5639ba5f005SPeter Zijlstra { 5649ba5f005SPeter Zijlstra return hrtimer_start(&ttimer->timer, time, mode); 5659ba5f005SPeter Zijlstra } 5669ba5f005SPeter Zijlstra 5679ba5f005SPeter Zijlstra static inline 5689ba5f005SPeter Zijlstra void tasklet_hrtimer_cancel(struct tasklet_hrtimer *ttimer) 5699ba5f005SPeter Zijlstra { 5709ba5f005SPeter Zijlstra hrtimer_cancel(&ttimer->timer); 5719ba5f005SPeter Zijlstra tasklet_kill(&ttimer->tasklet); 5729ba5f005SPeter Zijlstra } 5739ba5f005SPeter Zijlstra 5741da177e4SLinus Torvalds /* 5751da177e4SLinus Torvalds * Autoprobing for irqs: 5761da177e4SLinus Torvalds * 5771da177e4SLinus Torvalds * probe_irq_on() and probe_irq_off() provide robust primitives 5781da177e4SLinus Torvalds * for accurate IRQ probing during kernel initialization. They are 5791da177e4SLinus Torvalds * reasonably simple to use, are not "fooled" by spurious interrupts, 5801da177e4SLinus Torvalds * and, unlike other attempts at IRQ probing, they do not get hung on 5811da177e4SLinus Torvalds * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards). 5821da177e4SLinus Torvalds * 5831da177e4SLinus Torvalds * For reasonably foolproof probing, use them as follows: 5841da177e4SLinus Torvalds * 5851da177e4SLinus Torvalds * 1. clear and/or mask the device's internal interrupt. 5861da177e4SLinus Torvalds * 2. sti(); 5871da177e4SLinus Torvalds * 3. irqs = probe_irq_on(); // "take over" all unassigned idle IRQs 5881da177e4SLinus Torvalds * 4. enable the device and cause it to trigger an interrupt. 5891da177e4SLinus Torvalds * 5. wait for the device to interrupt, using non-intrusive polling or a delay. 5901da177e4SLinus Torvalds * 6. irq = probe_irq_off(irqs); // get IRQ number, 0=none, negative=multiple 5911da177e4SLinus Torvalds * 7. service the device to clear its pending interrupt. 5921da177e4SLinus Torvalds * 8. loop again if paranoia is required. 5931da177e4SLinus Torvalds * 5941da177e4SLinus Torvalds * probe_irq_on() returns a mask of allocated irq's. 5951da177e4SLinus Torvalds * 5961da177e4SLinus Torvalds * probe_irq_off() takes the mask as a parameter, 5971da177e4SLinus Torvalds * and returns the irq number which occurred, 5981da177e4SLinus Torvalds * or zero if none occurred, or a negative irq number 5991da177e4SLinus Torvalds * if more than one irq occurred. 6001da177e4SLinus Torvalds */ 6011da177e4SLinus Torvalds 6021da177e4SLinus Torvalds #if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE) 6031da177e4SLinus Torvalds static inline unsigned long probe_irq_on(void) 6041da177e4SLinus Torvalds { 6051da177e4SLinus Torvalds return 0; 6061da177e4SLinus Torvalds } 6071da177e4SLinus Torvalds static inline int probe_irq_off(unsigned long val) 6081da177e4SLinus Torvalds { 6091da177e4SLinus Torvalds return 0; 6101da177e4SLinus Torvalds } 6111da177e4SLinus Torvalds static inline unsigned int probe_irq_mask(unsigned long val) 6121da177e4SLinus Torvalds { 6131da177e4SLinus Torvalds return 0; 6141da177e4SLinus Torvalds } 6151da177e4SLinus Torvalds #else 6161da177e4SLinus Torvalds extern unsigned long probe_irq_on(void); /* returns 0 on failure */ 6171da177e4SLinus Torvalds extern int probe_irq_off(unsigned long); /* returns 0 or negative on failure */ 6181da177e4SLinus Torvalds extern unsigned int probe_irq_mask(unsigned long); /* returns mask of ISA interrupts */ 6191da177e4SLinus Torvalds #endif 6201da177e4SLinus Torvalds 6216168a702SAndrew Morton #ifdef CONFIG_PROC_FS 6226168a702SAndrew Morton /* Initialize /proc/irq/ */ 6236168a702SAndrew Morton extern void init_irq_proc(void); 6246168a702SAndrew Morton #else 6256168a702SAndrew Morton static inline void init_irq_proc(void) 6266168a702SAndrew Morton { 6276168a702SAndrew Morton } 6286168a702SAndrew Morton #endif 6296168a702SAndrew Morton 630d43c36dcSAlexey Dobriyan struct seq_file; 631f74596d0SAdrian Bunk int show_interrupts(struct seq_file *p, void *v); 632f74596d0SAdrian Bunk 63343a25632SYinghai Lu struct irq_desc; 63443a25632SYinghai Lu 63543a25632SYinghai Lu extern int early_irq_init(void); 6364a046d17SYinghai Lu extern int arch_probe_nr_irqs(void); 63743a25632SYinghai Lu extern int arch_early_irq_init(void); 63885ac16d0SYinghai Lu extern int arch_init_chip_data(struct irq_desc *desc, int node); 63943a25632SYinghai Lu 6401da177e4SLinus Torvalds #endif 641