blob: b1d4332b5cf0f22e2bf6f2fabf6aadb0b41f1680 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef LINUX_HARDIRQ_H
2#define LINUX_HARDIRQ_H
3
Randy Dunlap67bc4eb2005-07-12 13:58:36 -07004#include <linux/preempt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/smp_lock.h>
6#include <asm/hardirq.h>
7#include <asm/system.h>
8
9/*
10 * We put the hardirq and softirq counter into the preemption
11 * counter. The bitmask has the following meaning:
12 *
13 * - bits 0-7 are the preemption count (max preemption depth: 256)
14 * - bits 8-15 are the softirq count (max # of softirqs: 256)
15 *
16 * The hardirq count can be overridden per architecture, the default is:
17 *
18 * - bits 16-27 are the hardirq count (max # of hardirqs: 4096)
19 * - ( bit 28 is the PREEMPT_ACTIVE flag. )
20 *
21 * PREEMPT_MASK: 0x000000ff
22 * SOFTIRQ_MASK: 0x0000ff00
23 * HARDIRQ_MASK: 0x0fff0000
24 */
25#define PREEMPT_BITS 8
26#define SOFTIRQ_BITS 8
27
28#ifndef HARDIRQ_BITS
29#define HARDIRQ_BITS 12
30/*
31 * The hardirq mask has to be large enough to have space for potentially
32 * all IRQ sources in the system nesting on a single CPU.
33 */
34#if (1 << HARDIRQ_BITS) < NR_IRQS
35# error HARDIRQ_BITS is too low!
36#endif
37#endif
38
39#define PREEMPT_SHIFT 0
40#define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
41#define HARDIRQ_SHIFT (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
42
43#define __IRQ_MASK(x) ((1UL << (x))-1)
44
45#define PREEMPT_MASK (__IRQ_MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define SOFTIRQ_MASK (__IRQ_MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
Paolo 'Blaisorblade' Giarrusso8f28e8f2005-05-28 15:52:02 -070047#define HARDIRQ_MASK (__IRQ_MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define PREEMPT_OFFSET (1UL << PREEMPT_SHIFT)
50#define SOFTIRQ_OFFSET (1UL << SOFTIRQ_SHIFT)
51#define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
52
Paolo 'Blaisorblade' Giarrusso8f28e8f2005-05-28 15:52:02 -070053#if PREEMPT_ACTIVE < (1 << (HARDIRQ_SHIFT + HARDIRQ_BITS))
54#error PREEMPT_ACTIVE is too low!
55#endif
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define hardirq_count() (preempt_count() & HARDIRQ_MASK)
58#define softirq_count() (preempt_count() & SOFTIRQ_MASK)
59#define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK))
60
61/*
62 * Are we doing bottom half or hardware interrupt processing?
63 * Are we in a softirq context? Interrupt context?
64 */
65#define in_irq() (hardirq_count())
66#define in_softirq() (softirq_count())
67#define in_interrupt() (irq_count())
68
69#if defined(CONFIG_PREEMPT) && !defined(CONFIG_PREEMPT_BKL)
70# define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != kernel_locked())
71#else
72# define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != 0)
73#endif
74
75#ifdef CONFIG_PREEMPT
76# define preemptible() (preempt_count() == 0 && !irqs_disabled())
77# define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
78#else
79# define preemptible() 0
80# define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
81#endif
82
83#ifdef CONFIG_SMP
84extern void synchronize_irq(unsigned int irq);
85#else
86# define synchronize_irq(irq) barrier()
87#endif
88
Al Virof0373602005-11-13 16:06:57 -080089struct task_struct;
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#ifndef CONFIG_VIRT_CPU_ACCOUNTING
Linus Torvalds1da177e2005-04-16 15:20:36 -070092static inline void account_system_vtime(struct task_struct *tsk)
93{
94}
95#endif
96
Ingo Molnarde30a2b2006-07-03 00:24:42 -070097/*
98 * It is safe to do non-atomic ops on ->hardirq_context,
99 * because NMI handlers may not preempt and the ops are
100 * always balanced, so the interrupted value of ->hardirq_context
101 * will always be restored.
102 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#define irq_enter() \
104 do { \
105 account_system_vtime(current); \
106 add_preempt_count(HARDIRQ_OFFSET); \
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700107 trace_hardirq_enter(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 } while (0)
109
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700110/*
111 * Exit irq context without processing softirqs:
112 */
113#define __irq_exit() \
114 do { \
115 trace_hardirq_exit(); \
116 account_system_vtime(current); \
117 sub_preempt_count(HARDIRQ_OFFSET); \
118 } while (0)
119
120/*
121 * Exit irq context and process softirqs if needed:
122 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123extern void irq_exit(void);
124
Ingo Molnarde30a2b2006-07-03 00:24:42 -0700125#define nmi_enter() irq_enter()
126#define nmi_exit() __irq_exit()
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#endif /* LINUX_HARDIRQ_H */