2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1997, 1998, 1999, 2000, 2001 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 * Copyright (C) 2001 MIPS Technologies, Inc.
10 #ifndef _ASM_HARDIRQ_H
11 #define _ASM_HARDIRQ_H
13 #include <linux/config.h>
14 #include <linux/threads.h>
15 #include <linux/irq.h>
18 unsigned int __softirq_pending;
19 unsigned int __syscall_count;
20 struct task_struct * __ksoftirqd_task; /* waitqueue is too large */
21 } ____cacheline_aligned irq_cpustat_t;
23 #include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
26 * We put the hardirq and softirq counter into the preemption
27 * counter. The bitmask has the following meaning:
29 * - bits 0-7 are the preemption count (max preemption depth: 256)
30 * - bits 8-15 are the softirq count (max # of softirqs: 256)
31 * - bits 16-23 are the hardirq count (max # of hardirqs: 256)
33 * - ( bit 26 is the PREEMPT_ACTIVE flag. )
35 * PREEMPT_MASK: 0x000000ff
36 * SOFTIRQ_MASK: 0x0000ff00
37 * HARDIRQ_MASK: 0x00ff0000
40 #define PREEMPT_BITS 8
41 #define SOFTIRQ_BITS 8
42 #define HARDIRQ_BITS 8
44 #define PREEMPT_SHIFT 0
45 #define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
46 #define HARDIRQ_SHIFT (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
48 #define __MASK(x) ((1UL << (x))-1)
50 #define PREEMPT_MASK (__MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
51 #define HARDIRQ_MASK (__MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
52 #define SOFTIRQ_MASK (__MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
54 #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
55 #define softirq_count() (preempt_count() & SOFTIRQ_MASK)
56 #define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK))
58 #define PREEMPT_OFFSET (1UL << PREEMPT_SHIFT)
59 #define SOFTIRQ_OFFSET (1UL << SOFTIRQ_SHIFT)
60 #define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
63 * The hardirq mask has to be large enough to have
64 * space for potentially all IRQ sources in the system
65 * nesting on a single CPU:
67 #if (1 << HARDIRQ_BITS) < NR_IRQS
68 # error HARDIRQ_BITS is too low!
72 * Are we doing bottom half or hardware interrupt processing?
73 * Are we in a softirq context? Interrupt context?
75 #define in_irq() (hardirq_count())
76 #define in_softirq() (softirq_count())
77 #define in_interrupt() (irq_count())
79 #define hardirq_trylock() (!in_interrupt())
80 #define hardirq_endlock() do { } while (0)
82 #define irq_enter() (preempt_count() += HARDIRQ_OFFSET)
85 # define in_atomic() (preempt_count() != kernel_locked())
86 # define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
88 # define in_atomic() (preempt_count() != 0)
89 # define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
93 preempt_count() -= IRQ_EXIT_OFFSET; \
94 if (!in_interrupt() && softirq_pending(smp_processor_id())) \
96 preempt_enable_no_resched(); \
100 # define synchronize_irq(irq) barrier()
102 extern void synchronize_irq(unsigned int irq);
103 #endif /* CONFIG_SMP */
105 #endif /* _ASM_HARDIRQ_H */