Blame view

include/linux/interrupt.h 20.8 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  /* interrupt.h */
  #ifndef _LINUX_INTERRUPT_H
  #define _LINUX_INTERRUPT_H
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
  #include <linux/kernel.h>
  #include <linux/linkage.h>
  #include <linux/bitops.h>
  #include <linux/preempt.h>
  #include <linux/cpumask.h>
908dcecda   Jan Beulich   [PATCH] adjust ha...
9
  #include <linux/irqreturn.h>
dd3a1db90   Thomas Gleixner   genirq: improve i...
10
  #include <linux/irqnr.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
  #include <linux/hardirq.h>
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
12
  #include <linux/irqflags.h>
54514a70a   David S. Miller   softirq: Add supp...
13
14
  #include <linux/smp.h>
  #include <linux/percpu.h>
9ba5f005c   Peter Zijlstra   softirq: introduc...
15
  #include <linux/hrtimer.h>
cd7eab44e   Ben Hutchings   genirq: Add IRQ a...
16
17
  #include <linux/kref.h>
  #include <linux/workqueue.h>
0ebb26e7a   Ingo Molnar   sparse irqs: hand...
18

60063497a   Arun Sharma   atomic: use <linu...
19
  #include <linux/atomic.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
  #include <asm/ptrace.h>
  #include <asm/system.h>
2bf2160d8   Lai Jiangshan   irq: Add tracepoi...
22
  #include <trace/events/irq.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23

6e2136161   Thomas Gleixner   [PATCH] irq-flags...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  /*
   * These correspond to the IORESOURCE_IRQ_* defines in
   * linux/ioport.h to select the interrupt line behaviour.  When
   * requesting an interrupt without specifying a IRQF_TRIGGER, the
   * setting should be assumed to be "as already configured", which
   * may be as per machine or firmware initialisation.
   */
  #define IRQF_TRIGGER_NONE	0x00000000
  #define IRQF_TRIGGER_RISING	0x00000001
  #define IRQF_TRIGGER_FALLING	0x00000002
  #define IRQF_TRIGGER_HIGH	0x00000004
  #define IRQF_TRIGGER_LOW	0x00000008
  #define IRQF_TRIGGER_MASK	(IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
  				 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
  #define IRQF_TRIGGER_PROBE	0x00000010
  
  /*
   * These flags used only by the kernel as part of the
   * irq handling routines.
   *
6932bf37b   Thomas Gleixner   genirq: Remove IR...
44
45
   * IRQF_DISABLED - keep irqs disabled when calling the action handler.
   *                 DEPRECATED. This flag is a NOOP and scheduled to be removed
6e2136161   Thomas Gleixner   [PATCH] irq-flags...
46
47
48
49
   * IRQF_SAMPLE_RANDOM - irq is used to feed the random generator
   * IRQF_SHARED - allow sharing the irq among several devices
   * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur
   * IRQF_TIMER - Flag to mark this interrupt as timer interrupt
950f4427c   Thomas Gleixner   [PATCH] Add irq f...
50
51
   * IRQF_PERCPU - Interrupt is per cpu
   * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
d85a60d85   Bernhard Walle   Add IRQF_IRQPOLL ...
52
53
54
   * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is
   *                registered first in an shared interrupt is considered for
   *                performance reasons)
b25c340c1   Thomas Gleixner   genirq: Add onesh...
55
56
57
   * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler finished.
   *                Used by threaded interrupts which need to keep the
   *                irq line disabled until the threaded handler has been run.
685fd0b4e   Ian Campbell   irq: Add new IRQ ...
58
   * IRQF_NO_SUSPEND - Do not disable this IRQ during suspend
dc5f219e8   Thomas Gleixner   genirq: Add IRQF_...
59
   * IRQF_FORCE_RESUME - Force enable it on resume even if IRQF_NO_SUSPEND is set
0c4602ff8   Thomas Gleixner   genirq: Add IRQF_...
60
   * IRQF_NO_THREAD - Interrupt cannot be threaded
9bab0b7fb   Ian Campbell   genirq: Add IRQF_...
61
62
   * IRQF_EARLY_RESUME - Resume IRQ early during syscore instead of at device
   *                resume time.
6e2136161   Thomas Gleixner   [PATCH] irq-flags...
63
64
65
66
67
   */
  #define IRQF_DISABLED		0x00000020
  #define IRQF_SAMPLE_RANDOM	0x00000040
  #define IRQF_SHARED		0x00000080
  #define IRQF_PROBE_SHARED	0x00000100
685fd0b4e   Ian Campbell   irq: Add new IRQ ...
68
  #define __IRQF_TIMER		0x00000200
284c66806   Thomas Gleixner   [PATCH] genirq:fi...
69
  #define IRQF_PERCPU		0x00000400
950f4427c   Thomas Gleixner   [PATCH] Add irq f...
70
  #define IRQF_NOBALANCING	0x00000800
d85a60d85   Bernhard Walle   Add IRQF_IRQPOLL ...
71
  #define IRQF_IRQPOLL		0x00001000
b25c340c1   Thomas Gleixner   genirq: Add onesh...
72
  #define IRQF_ONESHOT		0x00002000
685fd0b4e   Ian Campbell   irq: Add new IRQ ...
73
  #define IRQF_NO_SUSPEND		0x00004000
dc5f219e8   Thomas Gleixner   genirq: Add IRQF_...
74
  #define IRQF_FORCE_RESUME	0x00008000
0c4602ff8   Thomas Gleixner   genirq: Add IRQF_...
75
  #define IRQF_NO_THREAD		0x00010000
9bab0b7fb   Ian Campbell   genirq: Add IRQF_...
76
  #define IRQF_EARLY_RESUME	0x00020000
685fd0b4e   Ian Campbell   irq: Add new IRQ ...
77

0c4602ff8   Thomas Gleixner   genirq: Add IRQF_...
78
  #define IRQF_TIMER		(__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
3aa551c9b   Thomas Gleixner   genirq: add threa...
79

b4e6b0973   Randy Dunlap   interrupt.h: fix ...
80
  /*
ae731f8d0   Marc Zyngier   genirq: Introduce...
81
82
83
84
85
86
87
88
89
90
   * These values can be returned by request_any_context_irq() and
   * describe the context the interrupt will be run in.
   *
   * IRQC_IS_HARDIRQ - interrupt runs in hardirq context
   * IRQC_IS_NESTED - interrupt runs in a nested threaded context
   */
  enum {
  	IRQC_IS_HARDIRQ	= 0,
  	IRQC_IS_NESTED,
  };
7d12e780e   David Howells   IRQ: Maintain reg...
91
  typedef irqreturn_t (*irq_handler_t)(int, void *);
da482792a   David Howells   IRQ: Typedef the ...
92

a9d0a1a38   Thomas Gleixner   genirq: add doc t...
93
94
95
96
  /**
   * struct irqaction - per interrupt action descriptor
   * @handler:	interrupt handler function
   * @flags:	flags (see IRQF_* above)
a9d0a1a38   Thomas Gleixner   genirq: add doc t...
97
98
   * @name:	name of the device
   * @dev_id:	cookie to identify the device
31d9d9b6d   Marc Zyngier   genirq: Add suppo...
99
   * @percpu_dev_id:	cookie to identify the device
a9d0a1a38   Thomas Gleixner   genirq: add doc t...
100
101
102
   * @next:	pointer to the next irqaction for shared interrupts
   * @irq:	interrupt number
   * @dir:	pointer to the proc/irq/NN/name entry
25985edce   Lucas De Marchi   Fix common misspe...
103
   * @thread_fn:	interrupt handler function for threaded interrupts
3aa551c9b   Thomas Gleixner   genirq: add threa...
104
105
   * @thread:	thread pointer for threaded interrupts
   * @thread_flags:	flags related to @thread
b5faba21a   Thomas Gleixner   genirq: Prepare t...
106
   * @thread_mask:	bitmask for keeping track of @thread activity
a9d0a1a38   Thomas Gleixner   genirq: add doc t...
107
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108
  struct irqaction {
31d9d9b6d   Marc Zyngier   genirq: Add suppo...
109
110
111
112
113
114
115
116
117
118
119
120
  	irq_handler_t		handler;
  	unsigned long		flags;
  	void			*dev_id;
  	void __percpu		*percpu_dev_id;
  	struct irqaction	*next;
  	int			irq;
  	irq_handler_t		thread_fn;
  	struct task_struct	*thread;
  	unsigned long		thread_flags;
  	unsigned long		thread_mask;
  	const char		*name;
  	struct proc_dir_entry	*dir;
f6cd24777   Eric Dumazet   irq: Better struc...
121
  } ____cacheline_internodealigned_in_smp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122

7d12e780e   David Howells   IRQ: Maintain reg...
123
  extern irqreturn_t no_action(int cpl, void *dev_id);
3aa551c9b   Thomas Gleixner   genirq: add threa...
124

3a38148f0   Thomas Gleixner   genirq: provide o...
125
  #ifdef CONFIG_GENERIC_HARDIRQS
3aa551c9b   Thomas Gleixner   genirq: add threa...
126
127
128
129
130
131
132
133
134
135
136
  extern int __must_check
  request_threaded_irq(unsigned int irq, irq_handler_t handler,
  		     irq_handler_t thread_fn,
  		     unsigned long flags, const char *name, void *dev);
  
  static inline int __must_check
  request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
  	    const char *name, void *dev)
  {
  	return request_threaded_irq(irq, handler, NULL, flags, name, dev);
  }
ae731f8d0   Marc Zyngier   genirq: Introduce...
137
138
139
  extern int __must_check
  request_any_context_irq(unsigned int irq, irq_handler_t handler,
  			unsigned long flags, const char *name, void *dev_id);
31d9d9b6d   Marc Zyngier   genirq: Add suppo...
140
141
142
  extern int __must_check
  request_percpu_irq(unsigned int irq, irq_handler_t handler,
  		   const char *devname, void __percpu *percpu_dev_id);
3aa551c9b   Thomas Gleixner   genirq: add threa...
143
144
  extern void exit_irq_thread(void);
  #else
3a38148f0   Thomas Gleixner   genirq: provide o...
145
146
147
148
  
  extern int __must_check
  request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
  	    const char *name, void *dev);
de18836e4   Thomas Gleixner   genirq: fix devre...
149
150
151
152
153
154
155
156
157
158
159
160
161
  /*
   * Special function to avoid ifdeffery in kernel/irq/devres.c which
   * gets magically built by GENERIC_HARDIRQS=n architectures (sparc,
   * m68k). I really love these $@%#!* obvious Makefile references:
   * ../../../kernel/irq/devres.o
   */
  static inline int __must_check
  request_threaded_irq(unsigned int irq, irq_handler_t handler,
  		     irq_handler_t thread_fn,
  		     unsigned long flags, const char *name, void *dev)
  {
  	return request_irq(irq, handler, flags, name, dev);
  }
ae731f8d0   Marc Zyngier   genirq: Introduce...
162
163
164
165
166
167
  static inline int __must_check
  request_any_context_irq(unsigned int irq, irq_handler_t handler,
  			unsigned long flags, const char *name, void *dev_id)
  {
  	return request_irq(irq, handler, flags, name, dev_id);
  }
31d9d9b6d   Marc Zyngier   genirq: Add suppo...
168
169
170
171
172
173
  static inline int __must_check
  request_percpu_irq(unsigned int irq, irq_handler_t handler,
  		   const char *devname, void __percpu *percpu_dev_id)
  {
  	return request_irq(irq, handler, 0, devname, percpu_dev_id);
  }
3aa551c9b   Thomas Gleixner   genirq: add threa...
174
175
  static inline void exit_irq_thread(void) { }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
  extern void free_irq(unsigned int, void *);
31d9d9b6d   Marc Zyngier   genirq: Add suppo...
177
  extern void free_percpu_irq(unsigned int, void __percpu *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178

0af3678f7   Al Viro   rip some includes...
179
  struct device;
935bd5b97   Arjan van de Ven   genirq: add suppo...
180
181
182
183
184
185
186
187
188
189
190
191
192
  extern int __must_check
  devm_request_threaded_irq(struct device *dev, unsigned int irq,
  			  irq_handler_t handler, irq_handler_t thread_fn,
  			  unsigned long irqflags, const char *devname,
  			  void *dev_id);
  
  static inline int __must_check
  devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
  		 unsigned long irqflags, const char *devname, void *dev_id)
  {
  	return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
  					 devname, dev_id);
  }
9ac7849e3   Tejun Heo   devres: device re...
193
  extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
d7e9629de   Ingo Molnar   [PATCH] lockdep: ...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  /*
   * On lockdep we dont want to enable hardirqs in hardirq
   * context. Use local_irq_enable_in_hardirq() to annotate
   * kernel code that has to do this nevertheless (pretty much
   * the only valid case is for old/broken hardware that is
   * insanely slow).
   *
   * NOTE: in theory this might break fragile code that relies
   * on hardirq delivery - in practice we dont seem to have such
   * places left. So the only effect should be slightly increased
   * irqs-off latencies.
   */
  #ifdef CONFIG_LOCKDEP
  # define local_irq_enable_in_hardirq()	do { } while (0)
  #else
  # define local_irq_enable_in_hardirq()	local_irq_enable()
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
212
213
  extern void disable_irq_nosync(unsigned int irq);
  extern void disable_irq(unsigned int irq);
31d9d9b6d   Marc Zyngier   genirq: Add suppo...
214
  extern void disable_percpu_irq(unsigned int irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
215
  extern void enable_irq(unsigned int irq);
1e7c5fd29   Marc Zyngier   genirq: percpu: a...
216
  extern void enable_percpu_irq(unsigned int irq, unsigned int type);
ba9a2331b   Thomas Gleixner   [PATCH] genirq: a...
217

0a0c5168d   Rafael J. Wysocki   PM: Introduce fun...
218
  /* The following three functions are for the core kernel use only. */
5818a6e25   Heiko Carstens   PM: Add empty sus...
219
  #ifdef CONFIG_GENERIC_HARDIRQS
0a0c5168d   Rafael J. Wysocki   PM: Introduce fun...
220
221
222
223
224
225
226
  extern void suspend_device_irqs(void);
  extern void resume_device_irqs(void);
  #ifdef CONFIG_PM_SLEEP
  extern int check_wakeup_irqs(void);
  #else
  static inline int check_wakeup_irqs(void) { return 0; }
  #endif
5818a6e25   Heiko Carstens   PM: Add empty sus...
227
228
229
230
  #else
  static inline void suspend_device_irqs(void) { };
  static inline void resume_device_irqs(void) { };
  static inline int check_wakeup_irqs(void) { return 0; }
0a0c5168d   Rafael J. Wysocki   PM: Introduce fun...
231
  #endif
d7b906897   Russell King   [S390] genirq/clo...
232
  #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS)
d036e67b4   Rusty Russell   cpumask: convert ...
233
  extern cpumask_var_t irq_default_affinity;
184047567   Max Krasnyansky   genirq: Expose de...
234

0de26520c   Rusty Russell   cpumask: make irq...
235
  extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask);
d7b906897   Russell King   [S390] genirq/clo...
236
  extern int irq_can_set_affinity(unsigned int irq);
184047567   Max Krasnyansky   genirq: Expose de...
237
  extern int irq_select_affinity(unsigned int irq);
d7b906897   Russell King   [S390] genirq/clo...
238

e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
239
  extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m);
cd7eab44e   Ben Hutchings   genirq: Add IRQ a...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
  
  /**
   * struct irq_affinity_notify - context for notification of IRQ affinity changes
   * @irq:		Interrupt to which notification applies
   * @kref:		Reference count, for internal use
   * @work:		Work item, for internal use
   * @notify:		Function to be called on change.  This will be
   *			called in process context.
   * @release:		Function to be called on release.  This will be
   *			called in process context.  Once registered, the
   *			structure must only be freed when this function is
   *			called or later.
   */
  struct irq_affinity_notify {
  	unsigned int irq;
  	struct kref kref;
  	struct work_struct work;
  	void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask);
  	void (*release)(struct kref *ref);
  };
  
  extern int
  irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify);
  
  static inline void irq_run_affinity_notifiers(void)
  {
  	flush_scheduled_work();
  }
d7b906897   Russell King   [S390] genirq/clo...
268
  #else /* CONFIG_SMP */
0de26520c   Rusty Russell   cpumask: make irq...
269
  static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m)
d7b906897   Russell King   [S390] genirq/clo...
270
271
272
273
274
275
276
277
  {
  	return -EINVAL;
  }
  
  static inline int irq_can_set_affinity(unsigned int irq)
  {
  	return 0;
  }
184047567   Max Krasnyansky   genirq: Expose de...
278
  static inline int irq_select_affinity(unsigned int irq)  { return 0; }
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
279
  static inline int irq_set_affinity_hint(unsigned int irq,
cd7eab44e   Ben Hutchings   genirq: Add IRQ a...
280
  					const struct cpumask *m)
e7a297b0d   Peter P Waskiewicz Jr   genirq: Add CPU m...
281
282
283
  {
  	return -EINVAL;
  }
d7b906897   Russell King   [S390] genirq/clo...
284
  #endif /* CONFIG_SMP && CONFIG_GENERIC_HARDIRQS */
e9ed7e722   Al Viro   take declarations...
285
  #ifdef CONFIG_GENERIC_HARDIRQS
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
  /*
   * Special lockdep variants of irq disabling/enabling.
   * These should be used for locking constructs that
   * know that a particular irq context which is disabled,
   * and which is the only irq-context user of a lock,
   * that it's safe to take the lock in the irq-disabled
   * section without disabling hardirqs.
   *
   * On !CONFIG_LOCKDEP they are equivalent to the normal
   * irq disable/enable methods.
   */
  static inline void disable_irq_nosync_lockdep(unsigned int irq)
  {
  	disable_irq_nosync(irq);
  #ifdef CONFIG_LOCKDEP
  	local_irq_disable();
  #endif
  }
e8106b941   Arjan van de Ven   [PATCH] lockdep: ...
304
305
306
307
308
309
310
  static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags)
  {
  	disable_irq_nosync(irq);
  #ifdef CONFIG_LOCKDEP
  	local_irq_save(*flags);
  #endif
  }
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
  static inline void disable_irq_lockdep(unsigned int irq)
  {
  	disable_irq(irq);
  #ifdef CONFIG_LOCKDEP
  	local_irq_disable();
  #endif
  }
  
  static inline void enable_irq_lockdep(unsigned int irq)
  {
  #ifdef CONFIG_LOCKDEP
  	local_irq_enable();
  #endif
  	enable_irq(irq);
  }
e8106b941   Arjan van de Ven   [PATCH] lockdep: ...
326
327
328
329
330
331
332
  static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags)
  {
  #ifdef CONFIG_LOCKDEP
  	local_irq_restore(*flags);
  #endif
  	enable_irq(irq);
  }
ba9a2331b   Thomas Gleixner   [PATCH] genirq: a...
333
  /* IRQ wakeup (PM) control: */
a0cd9ca2b   Thomas Gleixner   genirq: Namespace...
334
  extern int irq_set_irq_wake(unsigned int irq, unsigned int on);
ba9a2331b   Thomas Gleixner   [PATCH] genirq: a...
335
336
  static inline int enable_irq_wake(unsigned int irq)
  {
a0cd9ca2b   Thomas Gleixner   genirq: Namespace...
337
  	return irq_set_irq_wake(irq, 1);
ba9a2331b   Thomas Gleixner   [PATCH] genirq: a...
338
339
340
341
  }
  
  static inline int disable_irq_wake(unsigned int irq)
  {
a0cd9ca2b   Thomas Gleixner   genirq: Namespace...
342
  	return irq_set_irq_wake(irq, 0);
ba9a2331b   Thomas Gleixner   [PATCH] genirq: a...
343
  }
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
344
345
346
347
348
349
  #else /* !CONFIG_GENERIC_HARDIRQS */
  /*
   * NOTE: non-genirq architectures, if they want to support the lock
   * validator need to define the methods below in their asm/irq.h
   * files, under an #ifdef CONFIG_LOCKDEP section.
   */
b3e2fd9ce   Roman Zippel   lockdep: Add miss...
350
  #ifndef CONFIG_LOCKDEP
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
351
  #  define disable_irq_nosync_lockdep(irq)	disable_irq_nosync(irq)
b3e2fd9ce   Roman Zippel   lockdep: Add miss...
352
353
  #  define disable_irq_nosync_lockdep_irqsave(irq, flags) \
  						disable_irq_nosync(irq)
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
354
355
  #  define disable_irq_lockdep(irq)		disable_irq(irq)
  #  define enable_irq_lockdep(irq)		enable_irq(irq)
b3e2fd9ce   Roman Zippel   lockdep: Add miss...
356
357
  #  define enable_irq_lockdep_irqrestore(irq, flags) \
  						enable_irq(irq)
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
358
  # endif
aa5346a21   Guennadi Liakhovetski   provide stubs for...
359
360
361
362
363
364
365
366
367
  static inline int enable_irq_wake(unsigned int irq)
  {
  	return 0;
  }
  
  static inline int disable_irq_wake(unsigned int irq)
  {
  	return 0;
  }
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
368
  #endif /* CONFIG_GENERIC_HARDIRQS */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369

8d32a307e   Thomas Gleixner   genirq: Provide f...
370
371
372
373
374
375
  
  #ifdef CONFIG_IRQ_FORCED_THREADING
  extern bool force_irqthreads;
  #else
  #define force_irqthreads	(0)
  #endif
3f74478b5   Andi Kleen   [PATCH] x86-64: S...
376
377
378
379
  #ifndef __ARCH_SET_SOFTIRQ_PENDING
  #define set_softirq_pending(x) (local_softirq_pending() = (x))
  #define or_softirq_pending(x)  (local_softirq_pending() |= (x))
  #endif
2d3fbbb39   Benjamin Herrenschmidt   Add hard_irq_disa...
380
381
382
383
384
385
386
387
388
  /* Some architectures might implement lazy enabling/disabling of
   * interrupts. In some cases, such as stop_machine, we might want
   * to ensure that after a local_irq_disable(), interrupts have
   * really been disabled in hardware. Such architectures need to
   * implement the following hook.
   */
  #ifndef hard_irq_disable
  #define hard_irq_disable()	do { } while(0)
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
389
390
391
392
393
394
395
396
397
398
399
400
  /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
     frequency threaded job scheduling. For almost all the purposes
     tasklets are more than enough. F.e. all serial device BHs et
     al. should be converted to tasklets, not to softirqs.
   */
  
  enum
  {
  	HI_SOFTIRQ=0,
  	TIMER_SOFTIRQ,
  	NET_TX_SOFTIRQ,
  	NET_RX_SOFTIRQ,
ff856bad6   Jens Axboe   [BLOCK] ll_rw_blk...
401
  	BLOCK_SOFTIRQ,
5e605b64a   Jens Axboe   block: add blk-io...
402
  	BLOCK_IOPOLL_SOFTIRQ,
c9819f459   Christoph Lameter   [PATCH] sched: us...
403
404
  	TASKLET_SOFTIRQ,
  	SCHED_SOFTIRQ,
a6037b61c   Peter Zijlstra   hrtimer: fix recu...
405
  	HRTIMER_SOFTIRQ,
09223371d   Shaohua Li   rcu: Use softirq ...
406
  	RCU_SOFTIRQ,    /* Preferable RCU should always be the last softirq */
978b0116c   Alexey Dobriyan   softirq: allocate...
407
408
  
  	NR_SOFTIRQS
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
  };
5d592b44b   Jason Baron   tracing: tracepoi...
410
411
412
413
  /* map softirq index to softirq name. update 'softirq_to_name' in
   * kernel/softirq.c when adding a new softirq.
   */
  extern char *softirq_to_name[NR_SOFTIRQS];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
414
415
416
417
418
419
420
  /* softirq mask and active fields moved to irq_cpustat_t in
   * asm/hardirq.h to get better cache usage.  KAO
   */
  
  struct softirq_action
  {
  	void	(*action)(struct softirq_action *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
421
422
423
  };
  
  asmlinkage void do_softirq(void);
eb0f1c442   Adrian Bunk   proper __do_softi...
424
  asmlinkage void __do_softirq(void);
962cf36c5   Carlos R. Mafra   Remove argument f...
425
  extern void open_softirq(int nr, void (*action)(struct softirq_action *));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
426
  extern void softirq_init(void);
2bf2160d8   Lai Jiangshan   irq: Add tracepoi...
427
428
  static inline void __raise_softirq_irqoff(unsigned int nr)
  {
f4bc6bb2d   Thomas Gleixner   tracing: Cleanup ...
429
  	trace_softirq_raise(nr);
2bf2160d8   Lai Jiangshan   irq: Add tracepoi...
430
431
  	or_softirq_pending(1UL << nr);
  }
b3c975286   Harvey Harrison   include/linux: Re...
432
433
  extern void raise_softirq_irqoff(unsigned int nr);
  extern void raise_softirq(unsigned int nr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
434

54514a70a   David S. Miller   softirq: Add supp...
435
436
437
438
439
440
441
442
  /* This is the worklist that queues up per-cpu softirq work.
   *
   * send_remote_sendirq() adds work to these lists, and
   * the softirq handler itself dequeues from them.  The queues
   * are protected by disabling local cpu interrupts and they must
   * only be accessed by the local cpu that they are for.
   */
  DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list);
4dd53d891   Venkatesh Pallipadi   softirqs: Free up...
443
444
445
446
447
448
  DECLARE_PER_CPU(struct task_struct *, ksoftirqd);
  
  static inline struct task_struct *this_cpu_ksoftirqd(void)
  {
  	return this_cpu_read(ksoftirqd);
  }
54514a70a   David S. Miller   softirq: Add supp...
449
450
451
452
453
454
455
456
457
458
  /* Try to send a softirq to a remote cpu.  If this cannot be done, the
   * work will be queued to the local cpu.
   */
  extern void send_remote_softirq(struct call_single_data *cp, int cpu, int softirq);
  
  /* Like send_remote_softirq(), but the caller must disable local cpu interrupts
   * and compute the current cpu, passed in as 'this_cpu'.
   */
  extern void __send_remote_softirq(struct call_single_data *cp, int cpu,
  				  int this_cpu, int softirq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
459
460
461
462
463
464
465
466
467
468
469
470
  
  /* Tasklets --- multithreaded analogue of BHs.
  
     Main feature differing them of generic softirqs: tasklet
     is running only on one CPU simultaneously.
  
     Main feature differing them of BHs: different tasklets
     may be run simultaneously on different CPUs.
  
     Properties:
     * If tasklet_schedule() is called, then tasklet is guaranteed
       to be executed on some cpu at least once after this.
25985edce   Lucas De Marchi   Fix common misspe...
471
     * If the tasklet is already scheduled, but its execution is still not
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
       started, it will be executed only once.
     * If this tasklet is already running on another CPU (or schedule is called
       from tasklet itself), it is rescheduled for later.
     * Tasklet is strictly serialized wrt itself, but not
       wrt another tasklets. If client needs some intertask synchronization,
       he makes it with spinlocks.
   */
  
  struct tasklet_struct
  {
  	struct tasklet_struct *next;
  	unsigned long state;
  	atomic_t count;
  	void (*func)(unsigned long);
  	unsigned long data;
  };
  
  #define DECLARE_TASKLET(name, func, data) \
  struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
  
  #define DECLARE_TASKLET_DISABLED(name, func, data) \
  struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
  
  
  enum
  {
  	TASKLET_STATE_SCHED,	/* Tasklet is scheduled for execution */
  	TASKLET_STATE_RUN	/* Tasklet is running (SMP only) */
  };
  
  #ifdef CONFIG_SMP
  static inline int tasklet_trylock(struct tasklet_struct *t)
  {
  	return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
  }
  
  static inline void tasklet_unlock(struct tasklet_struct *t)
  {
  	smp_mb__before_clear_bit(); 
  	clear_bit(TASKLET_STATE_RUN, &(t)->state);
  }
  
  static inline void tasklet_unlock_wait(struct tasklet_struct *t)
  {
  	while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
  }
  #else
  #define tasklet_trylock(t) 1
  #define tasklet_unlock_wait(t) do { } while (0)
  #define tasklet_unlock(t) do { } while (0)
  #endif
b3c975286   Harvey Harrison   include/linux: Re...
523
  extern void __tasklet_schedule(struct tasklet_struct *t);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
524
525
526
527
528
529
  
  static inline void tasklet_schedule(struct tasklet_struct *t)
  {
  	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
  		__tasklet_schedule(t);
  }
b3c975286   Harvey Harrison   include/linux: Re...
530
  extern void __tasklet_hi_schedule(struct tasklet_struct *t);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
531
532
533
534
535
536
  
  static inline void tasklet_hi_schedule(struct tasklet_struct *t)
  {
  	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
  		__tasklet_hi_schedule(t);
  }
7c692cbad   Vegard Nossum   tasklets: new tas...
537
538
539
540
541
542
543
544
545
546
547
548
549
  extern void __tasklet_hi_schedule_first(struct tasklet_struct *t);
  
  /*
   * This version avoids touching any other tasklets. Needed for kmemcheck
   * in order not to take any page faults while enqueueing this tasklet;
   * consider VERY carefully whether you really need this or
   * tasklet_hi_schedule()...
   */
  static inline void tasklet_hi_schedule_first(struct tasklet_struct *t)
  {
  	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
  		__tasklet_hi_schedule_first(t);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
  
  static inline void tasklet_disable_nosync(struct tasklet_struct *t)
  {
  	atomic_inc(&t->count);
  	smp_mb__after_atomic_inc();
  }
  
  static inline void tasklet_disable(struct tasklet_struct *t)
  {
  	tasklet_disable_nosync(t);
  	tasklet_unlock_wait(t);
  	smp_mb();
  }
  
  static inline void tasklet_enable(struct tasklet_struct *t)
  {
  	smp_mb__before_atomic_dec();
  	atomic_dec(&t->count);
  }
  
  static inline void tasklet_hi_enable(struct tasklet_struct *t)
  {
  	smp_mb__before_atomic_dec();
  	atomic_dec(&t->count);
  }
  
  extern void tasklet_kill(struct tasklet_struct *t);
  extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
  extern void tasklet_init(struct tasklet_struct *t,
  			 void (*func)(unsigned long), unsigned long data);
9ba5f005c   Peter Zijlstra   softirq: introduc...
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
  struct tasklet_hrtimer {
  	struct hrtimer		timer;
  	struct tasklet_struct	tasklet;
  	enum hrtimer_restart	(*function)(struct hrtimer *);
  };
  
  extern void
  tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer,
  		     enum hrtimer_restart (*function)(struct hrtimer *),
  		     clockid_t which_clock, enum hrtimer_mode mode);
  
  static inline
  int tasklet_hrtimer_start(struct tasklet_hrtimer *ttimer, ktime_t time,
  			  const enum hrtimer_mode mode)
  {
  	return hrtimer_start(&ttimer->timer, time, mode);
  }
  
  static inline
  void tasklet_hrtimer_cancel(struct tasklet_hrtimer *ttimer)
  {
  	hrtimer_cancel(&ttimer->timer);
  	tasklet_kill(&ttimer->tasklet);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
  /*
   * Autoprobing for irqs:
   *
   * probe_irq_on() and probe_irq_off() provide robust primitives
   * for accurate IRQ probing during kernel initialization.  They are
   * reasonably simple to use, are not "fooled" by spurious interrupts,
   * and, unlike other attempts at IRQ probing, they do not get hung on
   * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
   *
   * For reasonably foolproof probing, use them as follows:
   *
   * 1. clear and/or mask the device's internal interrupt.
   * 2. sti();
   * 3. irqs = probe_irq_on();      // "take over" all unassigned idle IRQs
   * 4. enable the device and cause it to trigger an interrupt.
   * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
   * 6. irq = probe_irq_off(irqs);  // get IRQ number, 0=none, negative=multiple
   * 7. service the device to clear its pending interrupt.
   * 8. loop again if paranoia is required.
   *
   * probe_irq_on() returns a mask of allocated irq's.
   *
   * probe_irq_off() takes the mask as a parameter,
   * and returns the irq number which occurred,
   * or zero if none occurred, or a negative irq number
   * if more than one irq occurred.
   */
  
  #if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE) 
  static inline unsigned long probe_irq_on(void)
  {
  	return 0;
  }
  static inline int probe_irq_off(unsigned long val)
  {
  	return 0;
  }
  static inline unsigned int probe_irq_mask(unsigned long val)
  {
  	return 0;
  }
  #else
  extern unsigned long probe_irq_on(void);	/* returns 0 on failure */
  extern int probe_irq_off(unsigned long);	/* returns 0 or negative on failure */
  extern unsigned int probe_irq_mask(unsigned long);	/* returns mask of ISA interrupts */
  #endif
6168a702a   Andrew Morton   [PATCH] Declare i...
650
651
652
653
654
655
656
657
  #ifdef CONFIG_PROC_FS
  /* Initialize /proc/irq/ */
  extern void init_irq_proc(void);
  #else
  static inline void init_irq_proc(void)
  {
  }
  #endif
d43c36dc6   Alexey Dobriyan   headers: remove s...
658
  struct seq_file;
f74596d07   Adrian Bunk   proper show_inter...
659
  int show_interrupts(struct seq_file *p, void *v);
c78b9b65f   Thomas Gleixner   genirq: Implement...
660
  int arch_show_interrupts(struct seq_file *p, int prec);
f74596d07   Adrian Bunk   proper show_inter...
661

43a256322   Yinghai Lu   sparseirq: move _...
662
  extern int early_irq_init(void);
4a046d175   Yinghai Lu   x86: arch_probe_n...
663
  extern int arch_probe_nr_irqs(void);
43a256322   Yinghai Lu   sparseirq: move _...
664
  extern int arch_early_irq_init(void);
43a256322   Yinghai Lu   sparseirq: move _...
665

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
666
  #endif