xref: /openbmc/linux/arch/nios2/include/asm/irqflags.h (revision f27ffc75)
1f27ffc75SLey Foon Tan /*
2f27ffc75SLey Foon Tan  * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
3f27ffc75SLey Foon Tan  *
4f27ffc75SLey Foon Tan  * This program is free software; you can redistribute it and/or modify
5f27ffc75SLey Foon Tan  * it under the terms of the GNU General Public License as published by
6f27ffc75SLey Foon Tan  * the Free Software Foundation; either version 2 of the License, or
7f27ffc75SLey Foon Tan  * (at your option) any later version.
8f27ffc75SLey Foon Tan  *
9f27ffc75SLey Foon Tan  * This program is distributed in the hope that it will be useful,
10f27ffc75SLey Foon Tan  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11f27ffc75SLey Foon Tan  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12f27ffc75SLey Foon Tan  * GNU General Public License for more details.
13f27ffc75SLey Foon Tan  *
14f27ffc75SLey Foon Tan  * You should have received a copy of the GNU General Public License
15f27ffc75SLey Foon Tan  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16f27ffc75SLey Foon Tan  *
17f27ffc75SLey Foon Tan  */
18f27ffc75SLey Foon Tan #ifndef _ASM_IRQFLAGS_H
19f27ffc75SLey Foon Tan #define _ASM_IRQFLAGS_H
20f27ffc75SLey Foon Tan 
21f27ffc75SLey Foon Tan #include <asm/registers.h>
22f27ffc75SLey Foon Tan 
23f27ffc75SLey Foon Tan static inline unsigned long arch_local_save_flags(void)
24f27ffc75SLey Foon Tan {
25f27ffc75SLey Foon Tan 	return RDCTL(CTL_STATUS);
26f27ffc75SLey Foon Tan }
27f27ffc75SLey Foon Tan 
28f27ffc75SLey Foon Tan /*
29f27ffc75SLey Foon Tan  * This will restore ALL status register flags, not only the interrupt
30f27ffc75SLey Foon Tan  * mask flag.
31f27ffc75SLey Foon Tan  */
32f27ffc75SLey Foon Tan static inline void arch_local_irq_restore(unsigned long flags)
33f27ffc75SLey Foon Tan {
34f27ffc75SLey Foon Tan 	WRCTL(CTL_STATUS, flags);
35f27ffc75SLey Foon Tan }
36f27ffc75SLey Foon Tan 
37f27ffc75SLey Foon Tan static inline void arch_local_irq_disable(void)
38f27ffc75SLey Foon Tan {
39f27ffc75SLey Foon Tan 	unsigned long flags;
40f27ffc75SLey Foon Tan 
41f27ffc75SLey Foon Tan 	flags = arch_local_save_flags();
42f27ffc75SLey Foon Tan 	arch_local_irq_restore(flags & ~STATUS_PIE);
43f27ffc75SLey Foon Tan }
44f27ffc75SLey Foon Tan 
45f27ffc75SLey Foon Tan static inline void arch_local_irq_enable(void)
46f27ffc75SLey Foon Tan {
47f27ffc75SLey Foon Tan 	unsigned long flags;
48f27ffc75SLey Foon Tan 
49f27ffc75SLey Foon Tan 	flags = arch_local_save_flags();
50f27ffc75SLey Foon Tan 	arch_local_irq_restore(flags | STATUS_PIE);
51f27ffc75SLey Foon Tan }
52f27ffc75SLey Foon Tan 
53f27ffc75SLey Foon Tan static inline int arch_irqs_disabled_flags(unsigned long flags)
54f27ffc75SLey Foon Tan {
55f27ffc75SLey Foon Tan 	return (flags & STATUS_PIE) == 0;
56f27ffc75SLey Foon Tan }
57f27ffc75SLey Foon Tan 
58f27ffc75SLey Foon Tan static inline int arch_irqs_disabled(void)
59f27ffc75SLey Foon Tan {
60f27ffc75SLey Foon Tan 	return arch_irqs_disabled_flags(arch_local_save_flags());
61f27ffc75SLey Foon Tan }
62f27ffc75SLey Foon Tan 
63f27ffc75SLey Foon Tan static inline unsigned long arch_local_irq_save(void)
64f27ffc75SLey Foon Tan {
65f27ffc75SLey Foon Tan 	unsigned long flags;
66f27ffc75SLey Foon Tan 
67f27ffc75SLey Foon Tan 	flags = arch_local_save_flags();
68f27ffc75SLey Foon Tan 	arch_local_irq_restore(flags & ~STATUS_PIE);
69f27ffc75SLey Foon Tan 	return flags;
70f27ffc75SLey Foon Tan }
71f27ffc75SLey Foon Tan 
72f27ffc75SLey Foon Tan #endif /* _ASM_IRQFLAGS_H */
73