blob: f1b64b25606089933a7ff80156d620f79fe38dcf [file] [log] [blame]
David Howellsdf9ee292010-10-07 14:08:55 +01001/* 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#ifdef CONFIG_MN10300_TTYSM
27#define MN10300_CLI_LEVEL EPSW_IM_2
28#else
29#define MN10300_CLI_LEVEL EPSW_IM_1
30#endif
31
32#ifndef __ASSEMBLY__
33
34static inline unsigned long arch_local_save_flags(void)
35{
36 unsigned long flags;
37
38 asm volatile("mov epsw,%0" : "=d"(flags));
39 return flags;
40}
41
42static inline void arch_local_irq_disable(void)
43{
44 asm volatile(
45 " and %0,epsw \n"
46 " or %1,epsw \n"
47 " nop \n"
48 " nop \n"
49 " nop \n"
50 :
51 : "i"(~EPSW_IM), "i"(EPSW_IE | MN10300_CLI_LEVEL)
52 : "memory");
53}
54
55static inline unsigned long arch_local_irq_save(void)
56{
57 unsigned long flags;
58
59 flags = arch_local_save_flags();
60 arch_local_irq_disable();
61 return flags;
62}
63
64/*
65 * we make sure arch_irq_enable() doesn't cause priority inversion
66 */
67extern unsigned long __mn10300_irq_enabled_epsw;
68
69static inline void arch_local_irq_enable(void)
70{
71 unsigned long tmp;
72
73 asm volatile(
74 " mov epsw,%0 \n"
75 " and %1,%0 \n"
76 " or %2,%0 \n"
77 " mov %0,epsw \n"
78 : "=&d"(tmp)
79 : "i"(~EPSW_IM), "r"(__mn10300_irq_enabled_epsw)
80 : "memory");
81}
82
83static inline void arch_local_irq_restore(unsigned long flags)
84{
85 asm volatile(
86 " mov %0,epsw \n"
87 " nop \n"
88 " nop \n"
89 " nop \n"
90 :
91 : "d"(flags)
92 : "memory", "cc");
93}
94
95static inline bool arch_irqs_disabled_flags(unsigned long flags)
96{
97 return (flags & EPSW_IM) <= MN10300_CLI_LEVEL;
98}
99
100static inline bool arch_irqs_disabled(void)
101{
102 return arch_irqs_disabled_flags(arch_local_save_flags());
103}
104
105/*
106 * Hook to save power by halting the CPU
107 * - called from the idle loop
108 * - must reenable interrupts (which takes three instruction cycles to complete)
109 */
110static inline void arch_safe_halt(void)
111{
112 asm volatile(
113 " or %0,epsw \n"
114 " nop \n"
115 " nop \n"
116 " bset %2,(%1) \n"
117 :
118 : "i"(EPSW_IE|EPSW_IM), "n"(&CPUM), "i"(CPUM_SLEEP)
119 : "cc");
120}
121
Akira Takeuchi9f200d32010-10-27 17:28:37 +0100122static inline void arch_local_cli(void)
123{
124 asm volatile(
125 " and %0,epsw \n"
126 " nop \n"
127 " nop \n"
128 " nop \n"
129 :
130 : "i"(~EPSW_IE)
131 : "memory"
132 );
133}
134
135static inline unsigned long arch_local_cli_save(void)
136{
137 unsigned long flags = arch_local_save_flags();
138 arch_local_cli();
139 return flags;
140}
141
142static inline void arch_local_sti(void)
143{
144 asm volatile(
145 " or %0,epsw \n"
146 :
147 : "i"(EPSW_IE)
148 : "memory");
149}
150
151static inline void arch_local_change_intr_mask_level(unsigned long level)
152{
153 asm volatile(
154 " and %0,epsw \n"
155 " or %1,epsw \n"
156 :
157 : "i"(~EPSW_IM), "i"(EPSW_IE | level)
158 : "cc", "memory");
159}
160
161#else /* !__ASSEMBLY__ */
162
163#define LOCAL_SAVE_FLAGS(reg) \
164 mov epsw,reg
165
166#define LOCAL_IRQ_DISABLE \
167 and ~EPSW_IM,epsw; \
168 or EPSW_IE|MN10300_CLI_LEVEL,epsw; \
169 nop; \
170 nop; \
171 nop
172
173#define LOCAL_IRQ_ENABLE \
174 or EPSW_IE|EPSW_IM_7,epsw
175
176#define LOCAL_IRQ_RESTORE(reg) \
177 mov reg,epsw
178
179#define LOCAL_CLI_SAVE(reg) \
180 mov epsw,reg; \
181 and ~EPSW_IE,epsw; \
182 nop; \
183 nop; \
184 nop
185
186#define LOCAL_CLI \
187 and ~EPSW_IE,epsw; \
188 nop; \
189 nop; \
190 nop
191
192#define LOCAL_STI \
193 or EPSW_IE,epsw
194
195#define LOCAL_CHANGE_INTR_MASK_LEVEL(level) \
196 and ~EPSW_IM,epsw; \
197 or EPSW_IE|(level),epsw
198
David Howellsdf9ee292010-10-07 14:08:55 +0100199#endif /* __ASSEMBLY__ */
200#endif /* _ASM_IRQFLAGS_H */