blob: bfa1ea45b4cdb893ee9814e077c9fafdda3daff8 [file] [log] [blame]
Sam Ravnborga439fe52008-07-27 23:00:59 +02001/*
2 * include/asm/irqflags.h
3 *
4 * IRQ flags handling
5 *
6 * This file gets included from lowlevel asm headers too, to provide
7 * wrapped versions of the local_irq_*() APIs, based on the
8 * raw_local_irq_*() functions from the lowlevel headers.
9 */
10#ifndef _ASM_IRQFLAGS_H
11#define _ASM_IRQFLAGS_H
12
David S. Millerb4f43722008-11-23 21:55:29 -080013#include <asm/pil.h>
14
Sam Ravnborga439fe52008-07-27 23:00:59 +020015#ifndef __ASSEMBLY__
16
17static inline unsigned long __raw_local_save_flags(void)
18{
19 unsigned long flags;
20
21 __asm__ __volatile__(
22 "rdpr %%pil, %0"
23 : "=r" (flags)
24 );
25
26 return flags;
27}
28
29#define raw_local_save_flags(flags) \
30 do { (flags) = __raw_local_save_flags(); } while (0)
31
32static inline void raw_local_irq_restore(unsigned long flags)
33{
34 __asm__ __volatile__(
35 "wrpr %0, %%pil"
36 : /* no output */
37 : "r" (flags)
38 : "memory"
39 );
40}
41
42static inline void raw_local_irq_disable(void)
43{
44 __asm__ __volatile__(
David S. Millerb4f43722008-11-23 21:55:29 -080045 "wrpr %0, %%pil"
Sam Ravnborga439fe52008-07-27 23:00:59 +020046 : /* no outputs */
David S. Millerb4f43722008-11-23 21:55:29 -080047 : "i" (PIL_NORMAL_MAX)
Sam Ravnborga439fe52008-07-27 23:00:59 +020048 : "memory"
49 );
50}
51
52static inline void raw_local_irq_enable(void)
53{
54 __asm__ __volatile__(
55 "wrpr 0, %%pil"
56 : /* no outputs */
57 : /* no inputs */
58 : "memory"
59 );
60}
61
62static inline int raw_irqs_disabled_flags(unsigned long flags)
63{
64 return (flags > 0);
65}
66
67static inline int raw_irqs_disabled(void)
68{
69 unsigned long flags = __raw_local_save_flags();
70
71 return raw_irqs_disabled_flags(flags);
72}
73
74/*
75 * For spinlocks, etc:
76 */
77static inline unsigned long __raw_local_irq_save(void)
78{
David S. Miller0c25e9e2010-04-12 22:21:52 -070079 unsigned long flags, tmp;
Sam Ravnborga439fe52008-07-27 23:00:59 +020080
David S. Miller0c25e9e2010-04-12 22:21:52 -070081 /* Disable interrupts to PIL_NORMAL_MAX unless we already
82 * are using PIL_NMI, in which case PIL_NMI is retained.
David S. Millerc011f802010-04-13 01:50:43 -070083 *
84 * The only values we ever program into the %pil are 0,
85 * PIL_NORMAL_MAX and PIL_NMI.
86 *
87 * Since PIL_NMI is the largest %pil value and all bits are
88 * set in it (0xf), it doesn't matter what PIL_NORMAL_MAX
89 * actually is.
David S. Miller0c25e9e2010-04-12 22:21:52 -070090 */
91 __asm__ __volatile__(
92 "rdpr %%pil, %0\n\t"
93 "or %0, %2, %1\n\t"
94 "wrpr %1, 0x0, %%pil"
95 : "=r" (flags), "=r" (tmp)
96 : "i" (PIL_NORMAL_MAX)
97 : "memory"
98 );
Sam Ravnborga439fe52008-07-27 23:00:59 +020099
100 return flags;
101}
102
103#define raw_local_irq_save(flags) \
104 do { (flags) = __raw_local_irq_save(); } while (0)
105
106#endif /* (__ASSEMBLY__) */
107
108#endif /* !(_ASM_IRQFLAGS_H) */