1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef _BLACKFIN_SYSTEM_H
26#define _BLACKFIN_SYSTEM_H
27
28
29
30
31
32extern int irq_flags;
33
34#define local_irq_enable() \
35 __asm__ __volatile__ ( \
36 "sti %0;" \
37 : \
38 : "d" (irq_flags) \
39 )
40
41#define local_irq_disable() \
42 do { \
43 int __tmp_dummy; \
44 __asm__ __volatile__ ( \
45 "cli %0;" \
46 : "=d" (__tmp_dummy) \
47 ); \
48 } while (0)
49
50# define local_irq_save(x) \
51 __asm__ __volatile__ ( \
52 "cli %0;" \
53 : "=&d" (x) \
54 )
55
56#define local_save_flags(x) \
57 __asm__ __volatile__ ( \
58 "cli %0;" \
59 "sti %0;" \
60 : "=d" (x) \
61 )
62
63#define irqs_enabled_from_flags(x) ((x) != 0x1f)
64
65#define local_irq_restore(x) \
66 do { \
67 if (irqs_enabled_from_flags(x)) \
68 local_irq_enable(); \
69 } while (0)
70
71
72
73
74#define nop() asm volatile ("nop;\n\t"::)
75#define mb() asm volatile ("" : : :"memory")
76#define rmb() asm volatile ("" : : :"memory")
77#define wmb() asm volatile ("" : : :"memory")
78#define set_rmb(var, value) do { xchg(&var, value); } while (0)
79#define set_mb(var, value) set_rmb(var, value)
80#define set_wmb(var, value) do { var = value; wmb(); } while (0)
81
82#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
83
84struct __xchg_dummy {
85 unsigned long a[100];
86};
87#define __xg(x) ((volatile struct __xchg_dummy *)(x))
88
89static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
90 int size)
91{
92 unsigned long tmp = 0;
93 unsigned long flags = 0;
94
95 local_irq_save(flags);
96
97 switch (size) {
98 case 1:
99 __asm__ __volatile__
100 ("%0 = b%2 (z);\n\t"
101 "b%2 = %1;\n\t"
102 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
103 break;
104 case 2:
105 __asm__ __volatile__
106 ("%0 = w%2 (z);\n\t"
107 "w%2 = %1;\n\t"
108 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
109 break;
110 case 4:
111 __asm__ __volatile__
112 ("%0 = %2;\n\t"
113 "%2 = %1;\n\t"
114 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
115 break;
116 }
117 local_irq_restore(flags);
118 return tmp;
119}
120
121#endif
122