]> git.sur5r.net Git - u-boot/blob - arch/nds32/include/asm/system.h
nds32/lib: add generic funcs in NDS32 lib
[u-boot] / arch / nds32 / include / asm / system.h
1 /*
2  * Copyright (C) 2011 Andes Technology Corporation
3  * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #ifndef __ASM_NDS_SYSTEM_H
25 #define __ASM_NDS_SYSTEM_H
26
27 /*
28  * Interrupt configuring macros.
29  */
30
31 extern int irq_flags;
32
33 #define local_irq_enable() \
34         __asm__ __volatile__ ( \
35                 "mfsr   %0, $psw\n\t" \
36                 "andi   %0, %0, 0x1\n\t" \
37                 "setgie.e\n\t" \
38                 : \
39                 : "r" (irq_flags) \
40         )
41
42 #define local_irq_disable() \
43         do { \
44                 int __tmp_dummy; \
45                 __asm__ __volatile__ ( \
46                         "mfsr   %0, $psw\n\t" \
47                         "andi   %0, %0, 0x1\n\t" \
48                         "setgie.d\n\t" \
49                         "dsb\n\t" \
50                         : "=r" (__tmp_dummy) \
51                 ); \
52         } while (0)
53
54 #define local_irq_save(x) \
55         __asm__ __volatile__ ( \
56                 "mfsr   %0, $psw\n\t" \
57                 "andi   %0, %0, 0x1\n\t" \
58                 "setgie.d\n\t" \
59                 "dsb\n\t" \
60                 : "=&r" (x) \
61         )
62
63 #define local_save_flags(x) \
64         __asm__ __volatile__ ( \
65                 "mfsr   %0, $psw\n\t" \
66                 "andi   %0, %0, 0x1\n\t" \
67                 "setgie.e\n\t" \
68                 "setgie.d\n\t" \
69                 : "=r" (x) \
70         )
71
72 #define irqs_enabled_from_flags(x) ((x) != 0x1f)
73
74 #define local_irq_restore(x) \
75         do { \
76                 if (irqs_enabled_from_flags(x)) \
77                         local_irq_enable(); \
78         } while (0)
79
80 /*
81  * Force strict CPU ordering.
82  */
83 #define nop()                   asm volatile ("nop;\n\t" : : )
84 #define mb()                    asm volatile (""   : : : "memory")
85 #define rmb()                   asm volatile (""   : : : "memory")
86 #define wmb()                   asm volatile (""   : : : "memory")
87
88 #endif  /* __ASM_NDS_SYSTEM_H */