Blame view

include/linux/interrupt.h 13.1 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>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
  #include <linux/hardirq.h>
f037360f2   Al Viro   [PATCH] m68k: thr...
11
  #include <linux/sched.h>
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
12
  #include <linux/irqflags.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
15
  #include <asm/atomic.h>
  #include <asm/ptrace.h>
  #include <asm/system.h>
6e2136161   Thomas Gleixner   [PATCH] irq-flags...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  /*
   * 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.
   *
   * IRQF_DISABLED - keep irqs disabled when calling the action handler
   * 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...
41
42
   * IRQF_PERCPU - Interrupt is per cpu
   * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
d85a60d85   Bernhard Walle   Add IRQF_IRQPOLL ...
43
44
45
   * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is
   *                registered first in an shared interrupt is considered for
   *                performance reasons)
6e2136161   Thomas Gleixner   [PATCH] irq-flags...
46
47
48
49
50
51
   */
  #define IRQF_DISABLED		0x00000020
  #define IRQF_SAMPLE_RANDOM	0x00000040
  #define IRQF_SHARED		0x00000080
  #define IRQF_PROBE_SHARED	0x00000100
  #define IRQF_TIMER		0x00000200
284c66806   Thomas Gleixner   [PATCH] genirq:fi...
52
  #define IRQF_PERCPU		0x00000400
950f4427c   Thomas Gleixner   [PATCH] Add irq f...
53
  #define IRQF_NOBALANCING	0x00000800
d85a60d85   Bernhard Walle   Add IRQF_IRQPOLL ...
54
  #define IRQF_IRQPOLL		0x00001000
6e2136161   Thomas Gleixner   [PATCH] irq-flags...
55
56
  
  /*
0e8638e2a   Thomas Gleixner   Deprecate SA_xxx ...
57
   * Migration helpers. Scheduled for removal in 9/2007
6e2136161   Thomas Gleixner   [PATCH] irq-flags...
58
59
   * Do not use for new code !
   */
0e8638e2a   Thomas Gleixner   Deprecate SA_xxx ...
60
61
62
63
64
  static inline
  unsigned long __deprecated deprecated_irq_flag(unsigned long flag)
  {
  	return flag;
  }
6e2136161   Thomas Gleixner   [PATCH] irq-flags...
65

0e8638e2a   Thomas Gleixner   Deprecate SA_xxx ...
66
67
68
69
70
71
72
73
74
75
76
  #define SA_INTERRUPT		deprecated_irq_flag(IRQF_DISABLED)
  #define SA_SAMPLE_RANDOM	deprecated_irq_flag(IRQF_SAMPLE_RANDOM)
  #define SA_SHIRQ		deprecated_irq_flag(IRQF_SHARED)
  #define SA_PROBEIRQ		deprecated_irq_flag(IRQF_PROBE_SHARED)
  #define SA_PERCPU		deprecated_irq_flag(IRQF_PERCPU)
  
  #define SA_TRIGGER_LOW		deprecated_irq_flag(IRQF_TRIGGER_LOW)
  #define SA_TRIGGER_HIGH		deprecated_irq_flag(IRQF_TRIGGER_HIGH)
  #define SA_TRIGGER_FALLING	deprecated_irq_flag(IRQF_TRIGGER_FALLING)
  #define SA_TRIGGER_RISING	deprecated_irq_flag(IRQF_TRIGGER_RISING)
  #define SA_TRIGGER_MASK		deprecated_irq_flag(IRQF_TRIGGER_MASK)
6e2136161   Thomas Gleixner   [PATCH] irq-flags...
77

7d12e780e   David Howells   IRQ: Maintain reg...
78
  typedef irqreturn_t (*irq_handler_t)(int, void *);
da482792a   David Howells   IRQ: Typedef the ...
79

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
  struct irqaction {
da482792a   David Howells   IRQ: Typedef the ...
81
  	irq_handler_t handler;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
85
86
87
88
89
  	unsigned long flags;
  	cpumask_t mask;
  	const char *name;
  	void *dev_id;
  	struct irqaction *next;
  	int irq;
  	struct proc_dir_entry *dir;
  };
7d12e780e   David Howells   IRQ: Maintain reg...
90
  extern irqreturn_t no_action(int cpl, void *dev_id);
616883df7   Monakhov Dmitriy   IRQ: add __must_c...
91
  extern int __must_check request_irq(unsigned int, irq_handler_t handler,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
  		       unsigned long, const char *, void *);
  extern void free_irq(unsigned int, void *);
0af3678f7   Al Viro   rip some includes...
94
  struct device;
616883df7   Monakhov Dmitriy   IRQ: add __must_c...
95
  extern int __must_check devm_request_irq(struct device *dev, unsigned int irq,
9ac7849e3   Tejun Heo   devres: device re...
96
97
98
  			    irq_handler_t handler, unsigned long irqflags,
  			    const char *devname, void *dev_id);
  extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
d7e9629de   Ingo Molnar   [PATCH] lockdep: ...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  /*
   * 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
116

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
119
  extern void disable_irq_nosync(unsigned int irq);
  extern void disable_irq(unsigned int irq);
  extern void enable_irq(unsigned int irq);
ba9a2331b   Thomas Gleixner   [PATCH] genirq: a...
120

e9ed7e722   Al Viro   take declarations...
121
  #ifdef CONFIG_GENERIC_HARDIRQS
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  /*
   * 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: ...
140
141
142
143
144
145
146
  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: ...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
  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: ...
162
163
164
165
166
167
168
  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...
169
170
171
172
173
174
175
176
177
178
179
180
  /* IRQ wakeup (PM) control: */
  extern int set_irq_wake(unsigned int irq, unsigned int on);
  
  static inline int enable_irq_wake(unsigned int irq)
  {
  	return set_irq_wake(irq, 1);
  }
  
  static inline int disable_irq_wake(unsigned int irq)
  {
  	return set_irq_wake(irq, 0);
  }
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
181
182
183
184
185
186
  #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...
187
  #ifndef CONFIG_LOCKDEP
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
188
  #  define disable_irq_nosync_lockdep(irq)	disable_irq_nosync(irq)
b3e2fd9ce   Roman Zippel   lockdep: Add miss...
189
190
  #  define disable_irq_nosync_lockdep_irqsave(irq, flags) \
  						disable_irq_nosync(irq)
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
191
192
  #  define disable_irq_lockdep(irq)		disable_irq(irq)
  #  define enable_irq_lockdep(irq)		enable_irq(irq)
b3e2fd9ce   Roman Zippel   lockdep: Add miss...
193
194
  #  define enable_irq_lockdep_irqrestore(irq, flags) \
  						enable_irq(irq)
c01d403b2   Ingo Molnar   [PATCH] lockdep: ...
195
196
197
  # endif
  
  #endif /* CONFIG_GENERIC_HARDIRQS */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198

3f74478b5   Andi Kleen   [PATCH] x86-64: S...
199
200
201
202
  #ifndef __ARCH_SET_SOFTIRQ_PENDING
  #define set_softirq_pending(x) (local_softirq_pending() = (x))
  #define or_softirq_pending(x)  (local_softirq_pending() |= (x))
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  /*
   * Temporary defines for UP kernels, until all code gets fixed.
   */
  #ifndef CONFIG_SMP
  static inline void __deprecated cli(void)
  {
  	local_irq_disable();
  }
  static inline void __deprecated sti(void)
  {
  	local_irq_enable();
  }
  static inline void __deprecated save_flags(unsigned long *x)
  {
  	local_save_flags(*x);
  }
ef9ceab28   Andrew Morton   [PATCH] remove se...
219
  #define save_flags(x) save_flags(&x)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
220
221
222
223
224
225
226
227
228
229
230
  static inline void __deprecated restore_flags(unsigned long x)
  {
  	local_irq_restore(x);
  }
  
  static inline void __deprecated save_and_cli(unsigned long *x)
  {
  	local_irq_save(*x);
  }
  #define save_and_cli(x)	save_and_cli(&x)
  #endif /* CONFIG_SMP */
2d3fbbb39   Benjamin Herrenschmidt   Add hard_irq_disa...
231
232
233
234
235
236
237
238
239
  /* 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
240
241
242
243
244
245
246
247
248
249
250
251
  /* 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...
252
  	BLOCK_SOFTIRQ,
c9819f459   Christoph Lameter   [PATCH] sched: us...
253
254
  	TASKLET_SOFTIRQ,
  	SCHED_SOFTIRQ,
54cdfdb47   Thomas Gleixner   [PATCH] hrtimers:...
255
256
257
  #ifdef CONFIG_HIGH_RES_TIMERS
  	HRTIMER_SOFTIRQ,
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
  };
  
  /* 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 *);
  	void	*data;
  };
  
  asmlinkage void do_softirq(void);
  extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
  extern void softirq_init(void);
3f74478b5   Andi Kleen   [PATCH] x86-64: S...
273
  #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
  extern void FASTCALL(raise_softirq_irqoff(unsigned int nr));
  extern void FASTCALL(raise_softirq(unsigned int nr));
  
  
  /* 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.
     * If the tasklet is already scheduled, but its excecution is still not
       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
  
  extern void FASTCALL(__tasklet_schedule(struct tasklet_struct *t));
  
  static inline void tasklet_schedule(struct tasklet_struct *t)
  {
  	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
  		__tasklet_schedule(t);
  }
  
  extern void FASTCALL(__tasklet_hi_schedule(struct tasklet_struct *t));
  
  static inline void tasklet_hi_schedule(struct tasklet_struct *t)
  {
  	if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
  		__tasklet_hi_schedule(t);
  }
  
  
  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);
  
  /*
   * 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...
435
436
437
438
439
440
441
442
  #ifdef CONFIG_PROC_FS
  /* Initialize /proc/irq/ */
  extern void init_irq_proc(void);
  #else
  static inline void init_irq_proc(void)
  {
  }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
443
  #endif