MN10300: Make various interrupt priority settings configurable
[pandora-kernel.git] / arch / mn10300 / include / asm / irqflags.h
1 /* MN10300 IRQ flag handling
2  *
3  * Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public Licence
8  * as published by the Free Software Foundation; either version
9  * 2 of the Licence, or (at your option) any later version.
10  */
11
12 #ifndef _ASM_IRQFLAGS_H
13 #define _ASM_IRQFLAGS_H
14
15 #include <asm/cpu-regs.h>
16
17 /*
18  * interrupt control
19  * - "disabled": run in IM1/2
20  *   - level 0 - GDB stub
21  *   - level 1 - virtual serial DMA (if present)
22  *   - level 5 - normal interrupt priority
23  *   - level 6 - timer interrupt
24  * - "enabled":  run in IM7
25  */
26 #define MN10300_CLI_LEVEL       (CONFIG_LINUX_CLI_LEVEL << EPSW_IM_SHIFT)
27
28 #ifndef __ASSEMBLY__
29
30 static inline unsigned long arch_local_save_flags(void)
31 {
32         unsigned long flags;
33
34         asm volatile("mov epsw,%0" : "=d"(flags));
35         return flags;
36 }
37
38 static inline void arch_local_irq_disable(void)
39 {
40         asm volatile(
41                 "       and %0,epsw     \n"
42                 "       or %1,epsw      \n"
43                 "       nop             \n"
44                 "       nop             \n"
45                 "       nop             \n"
46                 :
47                 : "i"(~EPSW_IM), "i"(EPSW_IE | MN10300_CLI_LEVEL)
48                 : "memory");
49 }
50
51 static inline unsigned long arch_local_irq_save(void)
52 {
53         unsigned long flags;
54
55         flags = arch_local_save_flags();
56         arch_local_irq_disable();
57         return flags;
58 }
59
60 /*
61  * we make sure arch_irq_enable() doesn't cause priority inversion
62  */
63 extern unsigned long __mn10300_irq_enabled_epsw;
64
65 static inline void arch_local_irq_enable(void)
66 {
67         unsigned long tmp;
68
69         asm volatile(
70                 "       mov     epsw,%0         \n"
71                 "       and     %1,%0           \n"
72                 "       or      %2,%0           \n"
73                 "       mov     %0,epsw         \n"
74                 : "=&d"(tmp)
75                 : "i"(~EPSW_IM), "r"(__mn10300_irq_enabled_epsw)
76                 : "memory");
77 }
78
79 static inline void arch_local_irq_restore(unsigned long flags)
80 {
81         asm volatile(
82                 "       mov %0,epsw     \n"
83                 "       nop             \n"
84                 "       nop             \n"
85                 "       nop             \n"
86                 :
87                 : "d"(flags)
88                 : "memory", "cc");
89 }
90
91 static inline bool arch_irqs_disabled_flags(unsigned long flags)
92 {
93         return (flags & (EPSW_IE | EPSW_IM)) != (EPSW_IE | EPSW_IM_7);
94 }
95
96 static inline bool arch_irqs_disabled(void)
97 {
98         return arch_irqs_disabled_flags(arch_local_save_flags());
99 }
100
101 /*
102  * Hook to save power by halting the CPU
103  * - called from the idle loop
104  * - must reenable interrupts (which takes three instruction cycles to complete)
105  */
106 static inline void arch_safe_halt(void)
107 {
108         asm volatile(
109                 "       or      %0,epsw \n"
110                 "       nop             \n"
111                 "       nop             \n"
112                 "       bset    %2,(%1) \n"
113                 :
114                 : "i"(EPSW_IE|EPSW_IM), "n"(&CPUM), "i"(CPUM_SLEEP)
115                 : "cc");
116 }
117
118 static inline void arch_local_cli(void)
119 {
120         asm volatile(
121                 "       and     %0,epsw         \n"
122                 "       nop                     \n"
123                 "       nop                     \n"
124                 "       nop                     \n"
125                 :
126                 : "i"(~EPSW_IE)
127                 : "memory"
128                 );
129 }
130
131 static inline unsigned long arch_local_cli_save(void)
132 {
133         unsigned long flags = arch_local_save_flags();
134         arch_local_cli();
135         return flags;
136 }
137
138 static inline void arch_local_sti(void)
139 {
140         asm volatile(
141                 "       or      %0,epsw         \n"
142                 :
143                 : "i"(EPSW_IE)
144                 : "memory");
145 }
146
147 static inline void arch_local_change_intr_mask_level(unsigned long level)
148 {
149         asm volatile(
150                 "       and     %0,epsw         \n"
151                 "       or      %1,epsw         \n"
152                 :
153                 : "i"(~EPSW_IM), "i"(EPSW_IE | level)
154                 : "cc", "memory");
155 }
156
157 #else /* !__ASSEMBLY__ */
158
159 #define LOCAL_SAVE_FLAGS(reg)                   \
160         mov     epsw,reg
161
162 #define LOCAL_IRQ_DISABLE                               \
163         and     ~EPSW_IM,epsw;                          \
164         or      EPSW_IE|MN10300_CLI_LEVEL,epsw;         \
165         nop;                                            \
166         nop;                                            \
167         nop
168
169 #define LOCAL_IRQ_ENABLE                \
170         or      EPSW_IE|EPSW_IM_7,epsw
171
172 #define LOCAL_IRQ_RESTORE(reg)  \
173         mov     reg,epsw
174
175 #define LOCAL_CLI_SAVE(reg)     \
176         mov     epsw,reg;       \
177         and     ~EPSW_IE,epsw;  \
178         nop;                    \
179         nop;                    \
180         nop
181
182 #define LOCAL_CLI               \
183         and     ~EPSW_IE,epsw;  \
184         nop;                    \
185         nop;                    \
186         nop
187
188 #define LOCAL_STI               \
189         or      EPSW_IE,epsw
190
191 #define LOCAL_CHANGE_INTR_MASK_LEVEL(level)     \
192         and     ~EPSW_IM,epsw;                  \
193         or      EPSW_IE|(level),epsw
194
195 #endif /* __ASSEMBLY__ */
196 #endif /* _ASM_IRQFLAGS_H */