14dbdc9a5SMichal Simek /*
24dbdc9a5SMichal Simek  * Copyright (C) 2006 Atmark Techno, Inc.
34dbdc9a5SMichal Simek  *
44dbdc9a5SMichal Simek  * This file is subject to the terms and conditions of the GNU General Public
54dbdc9a5SMichal Simek  * License. See the file "COPYING" in the main directory of this archive
64dbdc9a5SMichal Simek  * for more details.
74dbdc9a5SMichal Simek  */
84dbdc9a5SMichal Simek 
94dbdc9a5SMichal Simek #ifndef _ASM_MICROBLAZE_IRQFLAGS_H
104dbdc9a5SMichal Simek #define _ASM_MICROBLAZE_IRQFLAGS_H
114dbdc9a5SMichal Simek 
12df9ee292SDavid Howells #include <linux/types.h>
13a3cd613bSMichal Simek #include <asm/registers.h>
144dbdc9a5SMichal Simek 
1512dfc73eSMichal Simek #if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR
164dbdc9a5SMichal Simek 
17df9ee292SDavid Howells static inline unsigned long arch_local_irq_save(void)
184dbdc9a5SMichal Simek {
194dbdc9a5SMichal Simek 	unsigned long flags;
20df9ee292SDavid Howells 	asm volatile("	msrclr %0, %1	\n"
21df9ee292SDavid Howells 		     "	nop		\n"
22df9ee292SDavid Howells 		     : "=r"(flags)
23df9ee292SDavid Howells 		     : "i"(MSR_IE)
24df9ee292SDavid Howells 		     : "memory");
25a3cd613bSMichal Simek 	return flags;
264dbdc9a5SMichal Simek }
274dbdc9a5SMichal Simek 
28df9ee292SDavid Howells static inline void arch_local_irq_disable(void)
29df9ee292SDavid Howells {
30df9ee292SDavid Howells 	/* this uses r0 without declaring it - is that correct? */
31df9ee292SDavid Howells 	asm volatile("	msrclr r0, %0	\n"
32df9ee292SDavid Howells 		     "	nop		\n"
33df9ee292SDavid Howells 		     :
34df9ee292SDavid Howells 		     : "i"(MSR_IE)
35df9ee292SDavid Howells 		     : "memory");
36df9ee292SDavid Howells }
37df9ee292SDavid Howells 
38df9ee292SDavid Howells static inline void arch_local_irq_enable(void)
39df9ee292SDavid Howells {
40df9ee292SDavid Howells 	/* this uses r0 without declaring it - is that correct? */
41df9ee292SDavid Howells 	asm volatile("	msrset	r0, %0	\n"
42df9ee292SDavid Howells 		     "	nop		\n"
43df9ee292SDavid Howells 		     :
44df9ee292SDavid Howells 		     : "i"(MSR_IE)
45df9ee292SDavid Howells 		     : "memory");
46df9ee292SDavid Howells }
47df9ee292SDavid Howells 
48df9ee292SDavid Howells #else /* !CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR */
49df9ee292SDavid Howells 
50df9ee292SDavid Howells static inline unsigned long arch_local_irq_save(void)
51df9ee292SDavid Howells {
52df9ee292SDavid Howells 	unsigned long flags, tmp;
53df9ee292SDavid Howells 	asm volatile ("	mfs	%0, rmsr	\n"
54df9ee292SDavid Howells 		      "	nop			\n"
55df9ee292SDavid Howells 		      "	andi	%1, %0, %2	\n"
56df9ee292SDavid Howells 		      "	mts	rmsr, %1	\n"
57df9ee292SDavid Howells 		      "	nop			\n"
58df9ee292SDavid Howells 		      : "=r"(flags), "=r"(tmp)
59df9ee292SDavid Howells 		      : "i"(~MSR_IE)
60df9ee292SDavid Howells 		      : "memory");
61df9ee292SDavid Howells 	return flags;
62df9ee292SDavid Howells }
63df9ee292SDavid Howells 
64df9ee292SDavid Howells static inline void arch_local_irq_disable(void)
65df9ee292SDavid Howells {
66df9ee292SDavid Howells 	unsigned long tmp;
67df9ee292SDavid Howells 	asm volatile("	mfs	%0, rmsr	\n"
68df9ee292SDavid Howells 		     "	nop			\n"
69df9ee292SDavid Howells 		     "	andi	%0, %0, %1	\n"
70df9ee292SDavid Howells 		     "	mts	rmsr, %0	\n"
71df9ee292SDavid Howells 		     "	nop			\n"
72df9ee292SDavid Howells 		     : "=r"(tmp)
73df9ee292SDavid Howells 		     : "i"(~MSR_IE)
74df9ee292SDavid Howells 		     : "memory");
75df9ee292SDavid Howells }
76df9ee292SDavid Howells 
77df9ee292SDavid Howells static inline void arch_local_irq_enable(void)
78df9ee292SDavid Howells {
79df9ee292SDavid Howells 	unsigned long tmp;
80df9ee292SDavid Howells 	asm volatile("	mfs	%0, rmsr	\n"
81df9ee292SDavid Howells 		     "	nop			\n"
82df9ee292SDavid Howells 		     "	ori	%0, %0, %1	\n"
83df9ee292SDavid Howells 		     "	mts	rmsr, %0	\n"
84df9ee292SDavid Howells 		     "	nop			\n"
85df9ee292SDavid Howells 		     : "=r"(tmp)
86df9ee292SDavid Howells 		     : "i"(MSR_IE)
87df9ee292SDavid Howells 		     : "memory");
88df9ee292SDavid Howells }
89df9ee292SDavid Howells 
90df9ee292SDavid Howells #endif /* CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR */
91df9ee292SDavid Howells 
92df9ee292SDavid Howells static inline unsigned long arch_local_save_flags(void)
93df9ee292SDavid Howells {
94df9ee292SDavid Howells 	unsigned long flags;
95df9ee292SDavid Howells 	asm volatile("	mfs	%0, rmsr	\n"
96df9ee292SDavid Howells 		     "	nop			\n"
97df9ee292SDavid Howells 		     : "=r"(flags)
98df9ee292SDavid Howells 		     :
99df9ee292SDavid Howells 		     : "memory");
100df9ee292SDavid Howells 	return flags;
101df9ee292SDavid Howells }
102df9ee292SDavid Howells 
103df9ee292SDavid Howells static inline void arch_local_irq_restore(unsigned long flags)
104df9ee292SDavid Howells {
105df9ee292SDavid Howells 	asm volatile("	mts	rmsr, %0	\n"
106df9ee292SDavid Howells 		     "	nop			\n"
107df9ee292SDavid Howells 		     :
108df9ee292SDavid Howells 		     : "r"(flags)
109df9ee292SDavid Howells 		     : "memory");
110df9ee292SDavid Howells }
111df9ee292SDavid Howells 
112df9ee292SDavid Howells static inline bool arch_irqs_disabled_flags(unsigned long flags)
113df9ee292SDavid Howells {
114df9ee292SDavid Howells 	return (flags & MSR_IE) == 0;
115df9ee292SDavid Howells }
116df9ee292SDavid Howells 
117df9ee292SDavid Howells static inline bool arch_irqs_disabled(void)
118df9ee292SDavid Howells {
119df9ee292SDavid Howells 	return arch_irqs_disabled_flags(arch_local_save_flags());
120df9ee292SDavid Howells }
1214dbdc9a5SMichal Simek 
1224dbdc9a5SMichal Simek #endif /* _ASM_MICROBLAZE_IRQFLAGS_H */
123