]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* interrupt.h */ |
2 | #ifndef _LINUX_INTERRUPT_H | |
3 | #define _LINUX_INTERRUPT_H | |
4 | ||
1da177e4 LT |
5 | #include <linux/kernel.h> |
6 | #include <linux/linkage.h> | |
7 | #include <linux/bitops.h> | |
8 | #include <linux/preempt.h> | |
9 | #include <linux/cpumask.h> | |
908dcecd | 10 | #include <linux/irqreturn.h> |
dd3a1db9 | 11 | #include <linux/irqnr.h> |
1da177e4 | 12 | #include <linux/hardirq.h> |
de30a2b3 | 13 | #include <linux/irqflags.h> |
54514a70 DM |
14 | #include <linux/smp.h> |
15 | #include <linux/percpu.h> | |
9ba5f005 | 16 | #include <linux/hrtimer.h> |
cd7eab44 BH |
17 | #include <linux/kref.h> |
18 | #include <linux/workqueue.h> | |
0ebb26e7 | 19 | |
1da177e4 LT |
20 | #include <asm/atomic.h> |
21 | #include <asm/ptrace.h> | |
22 | #include <asm/system.h> | |
2bf2160d | 23 | #include <trace/events/irq.h> |
1da177e4 | 24 | |
6e213616 TG |
25 | /* |
26 | * These correspond to the IORESOURCE_IRQ_* defines in | |
27 | * linux/ioport.h to select the interrupt line behaviour. When | |
28 | * requesting an interrupt without specifying a IRQF_TRIGGER, the | |
29 | * setting should be assumed to be "as already configured", which | |
30 | * may be as per machine or firmware initialisation. | |
31 | */ | |
32 | #define IRQF_TRIGGER_NONE 0x00000000 | |
33 | #define IRQF_TRIGGER_RISING 0x00000001 | |
34 | #define IRQF_TRIGGER_FALLING 0x00000002 | |
35 | #define IRQF_TRIGGER_HIGH 0x00000004 | |
36 | #define IRQF_TRIGGER_LOW 0x00000008 | |
37 | #define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \ | |
38 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING) | |
39 | #define IRQF_TRIGGER_PROBE 0x00000010 | |
40 | ||
41 | /* | |
42 | * These flags used only by the kernel as part of the | |
43 | * irq handling routines. | |
44 | * | |
6932bf37 TG |
45 | * IRQF_DISABLED - keep irqs disabled when calling the action handler. |
46 | * DEPRECATED. This flag is a NOOP and scheduled to be removed | |
6e213616 TG |
47 | * IRQF_SAMPLE_RANDOM - irq is used to feed the random generator |
48 | * IRQF_SHARED - allow sharing the irq among several devices | |
49 | * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur | |
50 | * IRQF_TIMER - Flag to mark this interrupt as timer interrupt | |
950f4427 TG |
51 | * IRQF_PERCPU - Interrupt is per cpu |
52 | * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing | |
d85a60d8 BW |
53 | * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is |
54 | * registered first in an shared interrupt is considered for | |
55 | * performance reasons) | |
b25c340c TG |
56 | * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler finished. |
57 | * Used by threaded interrupts which need to keep the | |
58 | * irq line disabled until the threaded handler has been run. | |
685fd0b4 | 59 | * IRQF_NO_SUSPEND - Do not disable this IRQ during suspend |
dc5f219e | 60 | * IRQF_FORCE_RESUME - Force enable it on resume even if IRQF_NO_SUSPEND is set |
6e213616 TG |
61 | */ |
62 | #define IRQF_DISABLED 0x00000020 | |
63 | #define IRQF_SAMPLE_RANDOM 0x00000040 | |
64 | #define IRQF_SHARED 0x00000080 | |
65 | #define IRQF_PROBE_SHARED 0x00000100 | |
685fd0b4 | 66 | #define __IRQF_TIMER 0x00000200 |
284c6680 | 67 | #define IRQF_PERCPU 0x00000400 |
950f4427 | 68 | #define IRQF_NOBALANCING 0x00000800 |
d85a60d8 | 69 | #define IRQF_IRQPOLL 0x00001000 |
b25c340c | 70 | #define IRQF_ONESHOT 0x00002000 |
685fd0b4 | 71 | #define IRQF_NO_SUSPEND 0x00004000 |
dc5f219e | 72 | #define IRQF_FORCE_RESUME 0x00008000 |
685fd0b4 IC |
73 | |
74 | #define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND) | |
6e213616 | 75 | |
3aa551c9 TG |
76 | /* |
77 | * Bits used by threaded handlers: | |
78 | * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run | |
79 | * IRQTF_DIED - handler thread died | |
f48fe81e | 80 | * IRQTF_WARNED - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed |
591d2fb0 | 81 | * IRQTF_AFFINITY - irq thread is requested to adjust affinity |
3aa551c9 TG |
82 | */ |
83 | enum { | |
84 | IRQTF_RUNTHREAD, | |
85 | IRQTF_DIED, | |
f48fe81e | 86 | IRQTF_WARNED, |
591d2fb0 | 87 | IRQTF_AFFINITY, |
3aa551c9 TG |
88 | }; |
89 | ||
b4e6b097 | 90 | /* |
ae731f8d MZ |
91 | * These values can be returned by request_any_context_irq() and |
92 | * describe the context the interrupt will be run in. | |
93 | * | |
94 | * IRQC_IS_HARDIRQ - interrupt runs in hardirq context | |
95 | * IRQC_IS_NESTED - interrupt runs in a nested threaded context | |
96 | */ | |
97 | enum { | |
98 | IRQC_IS_HARDIRQ = 0, | |
99 | IRQC_IS_NESTED, | |
100 | }; | |
101 | ||
7d12e780 | 102 | typedef irqreturn_t (*irq_handler_t)(int, void *); |
da482792 | 103 | |
a9d0a1a3 TG |
104 | /** |
105 | * struct irqaction - per interrupt action descriptor | |
106 | * @handler: interrupt handler function | |
107 | * @flags: flags (see IRQF_* above) | |
a9d0a1a3 TG |
108 | * @name: name of the device |
109 | * @dev_id: cookie to identify the device | |
110 | * @next: pointer to the next irqaction for shared interrupts | |
111 | * @irq: interrupt number | |
112 | * @dir: pointer to the proc/irq/NN/name entry | |
3aa551c9 TG |
113 | * @thread_fn: interupt handler function for threaded interrupts |
114 | * @thread: thread pointer for threaded interrupts | |
115 | * @thread_flags: flags related to @thread | |
a9d0a1a3 | 116 | */ |
1da177e4 | 117 | struct irqaction { |
da482792 | 118 | irq_handler_t handler; |
1da177e4 | 119 | unsigned long flags; |
1da177e4 LT |
120 | void *dev_id; |
121 | struct irqaction *next; | |
122 | int irq; | |
3aa551c9 TG |
123 | irq_handler_t thread_fn; |
124 | struct task_struct *thread; | |
125 | unsigned long thread_flags; | |
f6cd2477 ED |
126 | const char *name; |
127 | struct proc_dir_entry *dir; | |
128 | } ____cacheline_internodealigned_in_smp; | |
1da177e4 | 129 | |
7d12e780 | 130 | extern irqreturn_t no_action(int cpl, void *dev_id); |
3aa551c9 | 131 | |
3a38148f | 132 | #ifdef CONFIG_GENERIC_HARDIRQS |
3aa551c9 TG |
133 | extern int __must_check |
134 | request_threaded_irq(unsigned int irq, irq_handler_t handler, | |
135 | irq_handler_t thread_fn, | |
136 | unsigned long flags, const char *name, void *dev); | |
137 | ||
138 | static inline int __must_check | |
139 | request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, | |
140 | const char *name, void *dev) | |
141 | { | |
142 | return request_threaded_irq(irq, handler, NULL, flags, name, dev); | |
143 | } | |
144 | ||
ae731f8d MZ |
145 | extern int __must_check |
146 | request_any_context_irq(unsigned int irq, irq_handler_t handler, | |
147 | unsigned long flags, const char *name, void *dev_id); | |
148 | ||
3aa551c9 TG |
149 | extern void exit_irq_thread(void); |
150 | #else | |
3a38148f TG |
151 | |
152 | extern int __must_check | |
153 | request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, | |
154 | const char *name, void *dev); | |
155 | ||
de18836e TG |
156 | /* |
157 | * Special function to avoid ifdeffery in kernel/irq/devres.c which | |
158 | * gets magically built by GENERIC_HARDIRQS=n architectures (sparc, | |
159 | * m68k). I really love these $@%#!* obvious Makefile references: | |
160 | * ../../../kernel/irq/devres.o | |
161 | */ | |
162 | static inline int __must_check | |
163 | request_threaded_irq(unsigned int irq, irq_handler_t handler, | |
164 | irq_handler_t thread_fn, | |
165 | unsigned long flags, const char *name, void *dev) | |
166 | { | |
167 | return request_irq(irq, handler, flags, name, dev); | |
168 | } | |
169 | ||
ae731f8d MZ |
170 | static inline int __must_check |
171 | request_any_context_irq(unsigned int irq, irq_handler_t handler, | |
172 | unsigned long flags, const char *name, void *dev_id) | |
173 | { | |
174 | return request_irq(irq, handler, flags, name, dev_id); | |
175 | } | |
176 | ||
3aa551c9 TG |
177 | static inline void exit_irq_thread(void) { } |
178 | #endif | |
179 | ||
1da177e4 LT |
180 | extern void free_irq(unsigned int, void *); |
181 | ||
0af3678f AV |
182 | struct device; |
183 | ||
935bd5b9 AV |
184 | extern int __must_check |
185 | devm_request_threaded_irq(struct device *dev, unsigned int irq, | |
186 | irq_handler_t handler, irq_handler_t thread_fn, | |
187 | unsigned long irqflags, const char *devname, | |
188 | void *dev_id); | |
189 | ||
190 | static inline int __must_check | |
191 | devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler, | |
192 | unsigned long irqflags, const char *devname, void *dev_id) | |
193 | { | |
194 | return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags, | |
195 | devname, dev_id); | |
196 | } | |
197 | ||
9ac7849e TH |
198 | extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id); |
199 | ||
d7e9629d IM |
200 | /* |
201 | * On lockdep we dont want to enable hardirqs in hardirq | |
202 | * context. Use local_irq_enable_in_hardirq() to annotate | |
203 | * kernel code that has to do this nevertheless (pretty much | |
204 | * the only valid case is for old/broken hardware that is | |
205 | * insanely slow). | |
206 | * | |
207 | * NOTE: in theory this might break fragile code that relies | |
208 | * on hardirq delivery - in practice we dont seem to have such | |
209 | * places left. So the only effect should be slightly increased | |
210 | * irqs-off latencies. | |
211 | */ | |
212 | #ifdef CONFIG_LOCKDEP | |
213 | # define local_irq_enable_in_hardirq() do { } while (0) | |
214 | #else | |
215 | # define local_irq_enable_in_hardirq() local_irq_enable() | |
216 | #endif | |
1da177e4 | 217 | |
1da177e4 LT |
218 | extern void disable_irq_nosync(unsigned int irq); |
219 | extern void disable_irq(unsigned int irq); | |
220 | extern void enable_irq(unsigned int irq); | |
ba9a2331 | 221 | |
0a0c5168 | 222 | /* The following three functions are for the core kernel use only. */ |
5818a6e2 | 223 | #ifdef CONFIG_GENERIC_HARDIRQS |
0a0c5168 RW |
224 | extern void suspend_device_irqs(void); |
225 | extern void resume_device_irqs(void); | |
226 | #ifdef CONFIG_PM_SLEEP | |
227 | extern int check_wakeup_irqs(void); | |
228 | #else | |
229 | static inline int check_wakeup_irqs(void) { return 0; } | |
230 | #endif | |
5818a6e2 HC |
231 | #else |
232 | static inline void suspend_device_irqs(void) { }; | |
233 | static inline void resume_device_irqs(void) { }; | |
234 | static inline int check_wakeup_irqs(void) { return 0; } | |
0a0c5168 RW |
235 | #endif |
236 | ||
d7b90689 RK |
237 | #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS) |
238 | ||
d036e67b | 239 | extern cpumask_var_t irq_default_affinity; |
18404756 | 240 | |
0de26520 | 241 | extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask); |
d7b90689 | 242 | extern int irq_can_set_affinity(unsigned int irq); |
18404756 | 243 | extern int irq_select_affinity(unsigned int irq); |
d7b90689 | 244 | |
e7a297b0 | 245 | extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m); |
cd7eab44 BH |
246 | |
247 | /** | |
248 | * struct irq_affinity_notify - context for notification of IRQ affinity changes | |
249 | * @irq: Interrupt to which notification applies | |
250 | * @kref: Reference count, for internal use | |
251 | * @work: Work item, for internal use | |
252 | * @notify: Function to be called on change. This will be | |
253 | * called in process context. | |
254 | * @release: Function to be called on release. This will be | |
255 | * called in process context. Once registered, the | |
256 | * structure must only be freed when this function is | |
257 | * called or later. | |
258 | */ | |
259 | struct irq_affinity_notify { | |
260 | unsigned int irq; | |
261 | struct kref kref; | |
262 | struct work_struct work; | |
263 | void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask); | |
264 | void (*release)(struct kref *ref); | |
265 | }; | |
266 | ||
267 | extern int | |
268 | irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify); | |
269 | ||
270 | static inline void irq_run_affinity_notifiers(void) | |
271 | { | |
272 | flush_scheduled_work(); | |
273 | } | |
274 | ||
d7b90689 RK |
275 | #else /* CONFIG_SMP */ |
276 | ||
0de26520 | 277 | static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m) |
d7b90689 RK |
278 | { |
279 | return -EINVAL; | |
280 | } | |
281 | ||
282 | static inline int irq_can_set_affinity(unsigned int irq) | |
283 | { | |
284 | return 0; | |
285 | } | |
286 | ||
18404756 MK |
287 | static inline int irq_select_affinity(unsigned int irq) { return 0; } |
288 | ||
e7a297b0 | 289 | static inline int irq_set_affinity_hint(unsigned int irq, |
cd7eab44 | 290 | const struct cpumask *m) |
e7a297b0 PWJ |
291 | { |
292 | return -EINVAL; | |
293 | } | |
d7b90689 RK |
294 | #endif /* CONFIG_SMP && CONFIG_GENERIC_HARDIRQS */ |
295 | ||
e9ed7e72 | 296 | #ifdef CONFIG_GENERIC_HARDIRQS |
c01d403b IM |
297 | /* |
298 | * Special lockdep variants of irq disabling/enabling. | |
299 | * These should be used for locking constructs that | |
300 | * know that a particular irq context which is disabled, | |
301 | * and which is the only irq-context user of a lock, | |
302 | * that it's safe to take the lock in the irq-disabled | |
303 | * section without disabling hardirqs. | |
304 | * | |
305 | * On !CONFIG_LOCKDEP they are equivalent to the normal | |
306 | * irq disable/enable methods. | |
307 | */ | |
308 | static inline void disable_irq_nosync_lockdep(unsigned int irq) | |
309 | { | |
310 | disable_irq_nosync(irq); | |
311 | #ifdef CONFIG_LOCKDEP | |
312 | local_irq_disable(); | |
313 | #endif | |
314 | } | |
315 | ||
e8106b94 AV |
316 | static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags) |
317 | { | |
318 | disable_irq_nosync(irq); | |
319 | #ifdef CONFIG_LOCKDEP | |
320 | local_irq_save(*flags); | |
321 | #endif | |
322 | } | |
323 | ||
c01d403b IM |
324 | static inline void disable_irq_lockdep(unsigned int irq) |
325 | { | |
326 | disable_irq(irq); | |
327 | #ifdef CONFIG_LOCKDEP | |
328 | local_irq_disable(); | |
329 | #endif | |
330 | } | |
331 | ||
332 | static inline void enable_irq_lockdep(unsigned int irq) | |
333 | { | |
334 | #ifdef CONFIG_LOCKDEP | |
335 | local_irq_enable(); | |
336 | #endif | |
337 | enable_irq(irq); | |
338 | } | |
339 | ||
e8106b94 AV |
340 | static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags) |
341 | { | |
342 | #ifdef CONFIG_LOCKDEP | |
343 | local_irq_restore(*flags); | |
344 | #endif | |
345 | enable_irq(irq); | |
346 | } | |
347 | ||
ba9a2331 TG |
348 | /* IRQ wakeup (PM) control: */ |
349 | extern int set_irq_wake(unsigned int irq, unsigned int on); | |
350 | ||
351 | static inline int enable_irq_wake(unsigned int irq) | |
352 | { | |
353 | return set_irq_wake(irq, 1); | |
354 | } | |
355 | ||
356 | static inline int disable_irq_wake(unsigned int irq) | |
357 | { | |
358 | return set_irq_wake(irq, 0); | |
359 | } | |
360 | ||
c01d403b IM |
361 | #else /* !CONFIG_GENERIC_HARDIRQS */ |
362 | /* | |
363 | * NOTE: non-genirq architectures, if they want to support the lock | |
364 | * validator need to define the methods below in their asm/irq.h | |
365 | * files, under an #ifdef CONFIG_LOCKDEP section. | |
366 | */ | |
b3e2fd9c | 367 | #ifndef CONFIG_LOCKDEP |
c01d403b | 368 | # define disable_irq_nosync_lockdep(irq) disable_irq_nosync(irq) |
b3e2fd9c RZ |
369 | # define disable_irq_nosync_lockdep_irqsave(irq, flags) \ |
370 | disable_irq_nosync(irq) | |
c01d403b IM |
371 | # define disable_irq_lockdep(irq) disable_irq(irq) |
372 | # define enable_irq_lockdep(irq) enable_irq(irq) | |
b3e2fd9c RZ |
373 | # define enable_irq_lockdep_irqrestore(irq, flags) \ |
374 | enable_irq(irq) | |
c01d403b IM |
375 | # endif |
376 | ||
aa5346a2 GL |
377 | static inline int enable_irq_wake(unsigned int irq) |
378 | { | |
379 | return 0; | |
380 | } | |
381 | ||
382 | static inline int disable_irq_wake(unsigned int irq) | |
383 | { | |
384 | return 0; | |
385 | } | |
c01d403b | 386 | #endif /* CONFIG_GENERIC_HARDIRQS */ |
1da177e4 | 387 | |
3f74478b AK |
388 | #ifndef __ARCH_SET_SOFTIRQ_PENDING |
389 | #define set_softirq_pending(x) (local_softirq_pending() = (x)) | |
390 | #define or_softirq_pending(x) (local_softirq_pending() |= (x)) | |
391 | #endif | |
392 | ||
2d3fbbb3 BH |
393 | /* Some architectures might implement lazy enabling/disabling of |
394 | * interrupts. In some cases, such as stop_machine, we might want | |
395 | * to ensure that after a local_irq_disable(), interrupts have | |
396 | * really been disabled in hardware. Such architectures need to | |
397 | * implement the following hook. | |
398 | */ | |
399 | #ifndef hard_irq_disable | |
400 | #define hard_irq_disable() do { } while(0) | |
401 | #endif | |
402 | ||
1da177e4 LT |
403 | /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high |
404 | frequency threaded job scheduling. For almost all the purposes | |
405 | tasklets are more than enough. F.e. all serial device BHs et | |
406 | al. should be converted to tasklets, not to softirqs. | |
407 | */ | |
408 | ||
409 | enum | |
410 | { | |
411 | HI_SOFTIRQ=0, | |
412 | TIMER_SOFTIRQ, | |
413 | NET_TX_SOFTIRQ, | |
414 | NET_RX_SOFTIRQ, | |
ff856bad | 415 | BLOCK_SOFTIRQ, |
5e605b64 | 416 | BLOCK_IOPOLL_SOFTIRQ, |
c9819f45 CL |
417 | TASKLET_SOFTIRQ, |
418 | SCHED_SOFTIRQ, | |
a6037b61 PZ |
419 | HRTIMER_SOFTIRQ, |
420 | RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */ | |
978b0116 AD |
421 | |
422 | NR_SOFTIRQS | |
1da177e4 LT |
423 | }; |
424 | ||
5d592b44 JB |
425 | /* map softirq index to softirq name. update 'softirq_to_name' in |
426 | * kernel/softirq.c when adding a new softirq. | |
427 | */ | |
428 | extern char *softirq_to_name[NR_SOFTIRQS]; | |
429 | ||
1da177e4 LT |
430 | /* softirq mask and active fields moved to irq_cpustat_t in |
431 | * asm/hardirq.h to get better cache usage. KAO | |
432 | */ | |
433 | ||
434 | struct softirq_action | |
435 | { | |
436 | void (*action)(struct softirq_action *); | |
1da177e4 LT |
437 | }; |
438 | ||
439 | asmlinkage void do_softirq(void); | |
eb0f1c44 | 440 | asmlinkage void __do_softirq(void); |
962cf36c | 441 | extern void open_softirq(int nr, void (*action)(struct softirq_action *)); |
1da177e4 | 442 | extern void softirq_init(void); |
2bf2160d LJ |
443 | static inline void __raise_softirq_irqoff(unsigned int nr) |
444 | { | |
f4bc6bb2 | 445 | trace_softirq_raise(nr); |
2bf2160d LJ |
446 | or_softirq_pending(1UL << nr); |
447 | } | |
448 | ||
b3c97528 HH |
449 | extern void raise_softirq_irqoff(unsigned int nr); |
450 | extern void raise_softirq(unsigned int nr); | |
1da177e4 | 451 | |
54514a70 DM |
452 | /* This is the worklist that queues up per-cpu softirq work. |
453 | * | |
454 | * send_remote_sendirq() adds work to these lists, and | |
455 | * the softirq handler itself dequeues from them. The queues | |
456 | * are protected by disabling local cpu interrupts and they must | |
457 | * only be accessed by the local cpu that they are for. | |
458 | */ | |
459 | DECLARE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list); | |
460 | ||
461 | /* Try to send a softirq to a remote cpu. If this cannot be done, the | |
462 | * work will be queued to the local cpu. | |
463 | */ | |
464 | extern void send_remote_softirq(struct call_single_data *cp, int cpu, int softirq); | |
465 | ||
466 | /* Like send_remote_softirq(), but the caller must disable local cpu interrupts | |
467 | * and compute the current cpu, passed in as 'this_cpu'. | |
468 | */ | |
469 | extern void __send_remote_softirq(struct call_single_data *cp, int cpu, | |
470 | int this_cpu, int softirq); | |
1da177e4 LT |
471 | |
472 | /* Tasklets --- multithreaded analogue of BHs. | |
473 | ||
474 | Main feature differing them of generic softirqs: tasklet | |
475 | is running only on one CPU simultaneously. | |
476 | ||
477 | Main feature differing them of BHs: different tasklets | |
478 | may be run simultaneously on different CPUs. | |
479 | ||
480 | Properties: | |
481 | * If tasklet_schedule() is called, then tasklet is guaranteed | |
482 | to be executed on some cpu at least once after this. | |
483 | * If the tasklet is already scheduled, but its excecution is still not | |
484 | started, it will be executed only once. | |
485 | * If this tasklet is already running on another CPU (or schedule is called | |
486 | from tasklet itself), it is rescheduled for later. | |
487 | * Tasklet is strictly serialized wrt itself, but not | |
488 | wrt another tasklets. If client needs some intertask synchronization, | |
489 | he makes it with spinlocks. | |
490 | */ | |
491 | ||
492 | struct tasklet_struct | |
493 | { | |
494 | struct tasklet_struct *next; | |
495 | unsigned long state; | |
496 | atomic_t count; | |
497 | void (*func)(unsigned long); | |
498 | unsigned long data; | |
499 | }; | |
500 | ||
501 | #define DECLARE_TASKLET(name, func, data) \ | |
502 | struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data } | |
503 | ||
504 | #define DECLARE_TASKLET_DISABLED(name, func, data) \ | |
505 | struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data } | |
506 | ||
507 | ||
508 | enum | |
509 | { | |
510 | TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */ | |
511 | TASKLET_STATE_RUN /* Tasklet is running (SMP only) */ | |
512 | }; | |
513 | ||
514 | #ifdef CONFIG_SMP | |
515 | static inline int tasklet_trylock(struct tasklet_struct *t) | |
516 | { | |
517 | return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state); | |
518 | } | |
519 | ||
520 | static inline void tasklet_unlock(struct tasklet_struct *t) | |
521 | { | |
522 | smp_mb__before_clear_bit(); | |
523 | clear_bit(TASKLET_STATE_RUN, &(t)->state); | |
524 | } | |
525 | ||
526 | static inline void tasklet_unlock_wait(struct tasklet_struct *t) | |
527 | { | |
528 | while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); } | |
529 | } | |
530 | #else | |
531 | #define tasklet_trylock(t) 1 | |
532 | #define tasklet_unlock_wait(t) do { } while (0) | |
533 | #define tasklet_unlock(t) do { } while (0) | |
534 | #endif | |
535 | ||
b3c97528 | 536 | extern void __tasklet_schedule(struct tasklet_struct *t); |
1da177e4 LT |
537 | |
538 | static inline void tasklet_schedule(struct tasklet_struct *t) | |
539 | { | |
540 | if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) | |
541 | __tasklet_schedule(t); | |
542 | } | |
543 | ||
b3c97528 | 544 | extern void __tasklet_hi_schedule(struct tasklet_struct *t); |
1da177e4 LT |
545 | |
546 | static inline void tasklet_hi_schedule(struct tasklet_struct *t) | |
547 | { | |
548 | if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) | |
549 | __tasklet_hi_schedule(t); | |
550 | } | |
551 | ||
7c692cba VN |
552 | extern void __tasklet_hi_schedule_first(struct tasklet_struct *t); |
553 | ||
554 | /* | |
555 | * This version avoids touching any other tasklets. Needed for kmemcheck | |
556 | * in order not to take any page faults while enqueueing this tasklet; | |
557 | * consider VERY carefully whether you really need this or | |
558 | * tasklet_hi_schedule()... | |
559 | */ | |
560 | static inline void tasklet_hi_schedule_first(struct tasklet_struct *t) | |
561 | { | |
562 | if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) | |
563 | __tasklet_hi_schedule_first(t); | |
564 | } | |
565 | ||
1da177e4 LT |
566 | |
567 | static inline void tasklet_disable_nosync(struct tasklet_struct *t) | |
568 | { | |
569 | atomic_inc(&t->count); | |
570 | smp_mb__after_atomic_inc(); | |
571 | } | |
572 | ||
573 | static inline void tasklet_disable(struct tasklet_struct *t) | |
574 | { | |
575 | tasklet_disable_nosync(t); | |
576 | tasklet_unlock_wait(t); | |
577 | smp_mb(); | |
578 | } | |
579 | ||
580 | static inline void tasklet_enable(struct tasklet_struct *t) | |
581 | { | |
582 | smp_mb__before_atomic_dec(); | |
583 | atomic_dec(&t->count); | |
584 | } | |
585 | ||
586 | static inline void tasklet_hi_enable(struct tasklet_struct *t) | |
587 | { | |
588 | smp_mb__before_atomic_dec(); | |
589 | atomic_dec(&t->count); | |
590 | } | |
591 | ||
592 | extern void tasklet_kill(struct tasklet_struct *t); | |
593 | extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu); | |
594 | extern void tasklet_init(struct tasklet_struct *t, | |
595 | void (*func)(unsigned long), unsigned long data); | |
596 | ||
9ba5f005 PZ |
597 | struct tasklet_hrtimer { |
598 | struct hrtimer timer; | |
599 | struct tasklet_struct tasklet; | |
600 | enum hrtimer_restart (*function)(struct hrtimer *); | |
601 | }; | |
602 | ||
603 | extern void | |
604 | tasklet_hrtimer_init(struct tasklet_hrtimer *ttimer, | |
605 | enum hrtimer_restart (*function)(struct hrtimer *), | |
606 | clockid_t which_clock, enum hrtimer_mode mode); | |
607 | ||
608 | static inline | |
609 | int tasklet_hrtimer_start(struct tasklet_hrtimer *ttimer, ktime_t time, | |
610 | const enum hrtimer_mode mode) | |
611 | { | |
612 | return hrtimer_start(&ttimer->timer, time, mode); | |
613 | } | |
614 | ||
615 | static inline | |
616 | void tasklet_hrtimer_cancel(struct tasklet_hrtimer *ttimer) | |
617 | { | |
618 | hrtimer_cancel(&ttimer->timer); | |
619 | tasklet_kill(&ttimer->tasklet); | |
620 | } | |
621 | ||
1da177e4 LT |
622 | /* |
623 | * Autoprobing for irqs: | |
624 | * | |
625 | * probe_irq_on() and probe_irq_off() provide robust primitives | |
626 | * for accurate IRQ probing during kernel initialization. They are | |
627 | * reasonably simple to use, are not "fooled" by spurious interrupts, | |
628 | * and, unlike other attempts at IRQ probing, they do not get hung on | |
629 | * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards). | |
630 | * | |
631 | * For reasonably foolproof probing, use them as follows: | |
632 | * | |
633 | * 1. clear and/or mask the device's internal interrupt. | |
634 | * 2. sti(); | |
635 | * 3. irqs = probe_irq_on(); // "take over" all unassigned idle IRQs | |
636 | * 4. enable the device and cause it to trigger an interrupt. | |
637 | * 5. wait for the device to interrupt, using non-intrusive polling or a delay. | |
638 | * 6. irq = probe_irq_off(irqs); // get IRQ number, 0=none, negative=multiple | |
639 | * 7. service the device to clear its pending interrupt. | |
640 | * 8. loop again if paranoia is required. | |
641 | * | |
642 | * probe_irq_on() returns a mask of allocated irq's. | |
643 | * | |
644 | * probe_irq_off() takes the mask as a parameter, | |
645 | * and returns the irq number which occurred, | |
646 | * or zero if none occurred, or a negative irq number | |
647 | * if more than one irq occurred. | |
648 | */ | |
649 | ||
650 | #if defined(CONFIG_GENERIC_HARDIRQS) && !defined(CONFIG_GENERIC_IRQ_PROBE) | |
651 | static inline unsigned long probe_irq_on(void) | |
652 | { | |
653 | return 0; | |
654 | } | |
655 | static inline int probe_irq_off(unsigned long val) | |
656 | { | |
657 | return 0; | |
658 | } | |
659 | static inline unsigned int probe_irq_mask(unsigned long val) | |
660 | { | |
661 | return 0; | |
662 | } | |
663 | #else | |
664 | extern unsigned long probe_irq_on(void); /* returns 0 on failure */ | |
665 | extern int probe_irq_off(unsigned long); /* returns 0 or negative on failure */ | |
666 | extern unsigned int probe_irq_mask(unsigned long); /* returns mask of ISA interrupts */ | |
667 | #endif | |
668 | ||
6168a702 AM |
669 | #ifdef CONFIG_PROC_FS |
670 | /* Initialize /proc/irq/ */ | |
671 | extern void init_irq_proc(void); | |
672 | #else | |
673 | static inline void init_irq_proc(void) | |
674 | { | |
675 | } | |
676 | #endif | |
677 | ||
d43c36dc | 678 | struct seq_file; |
f74596d0 AB |
679 | int show_interrupts(struct seq_file *p, void *v); |
680 | ||
43a25632 | 681 | extern int early_irq_init(void); |
4a046d17 | 682 | extern int arch_probe_nr_irqs(void); |
43a25632 | 683 | extern int arch_early_irq_init(void); |
43a25632 | 684 | |
1da177e4 | 685 | #endif |