3939 */
4040#define atomic_set (v ,i ) (((v)->counter) = (i))
4141
42- /**
43- * atomic_add_return - add integer to atomic variable and return it
44- * @i: integer value to add
45- * @v: pointer of type atomic_t
46- *
47- * Atomically adds @i to @v and return (@i + @v).
48- */
49- static __inline__ int atomic_add_return (int i , atomic_t * v )
50- {
51- unsigned long flags ;
52- int result ;
53-
54- local_irq_save (flags );
55- __asm__ __volatile__ (
56- "# atomic_add_return \n\t"
57- DCACHE_CLEAR ("%0" , "r4" , "%1" )
58- M32R_LOCK " %0, @%1; \n\t"
59- "add %0, %2; \n\t"
60- M32R_UNLOCK " %0, @%1; \n\t"
61- : "= & r " (result)
62- : " r " (&v->counter), " r " (i)
63- : " memory "
6442#ifdef CONFIG_CHIP_M32700_TS1
65- , "r4"
66- #endif /* CONFIG_CHIP_M32700_TS1 */
67- );
68- local_irq_restore (flags );
69-
70- return result ;
43+ #define __ATOMIC_CLOBBER , "r4"
44+ #else
45+ #define __ATOMIC_CLOBBER
46+ #endif
47+
48+ #define ATOMIC_OP (op ) \
49+ static __inline__ void atomic_##op(int i, atomic_t *v) \
50+ { \
51+ unsigned long flags; \
52+ int result; \
53+ \
54+ local_irq_save(flags); \
55+ __asm__ __volatile__ ( \
56+ "# atomic_" #op " \n\t" \
57+ DCACHE_CLEAR("%0", "r4", "%1") \
58+ M32R_LOCK" %0, @%1; \n\t" \
59+ #op " %0, %2; \n\t" \
60+ M32R_UNLOCK" %0, @%1; \n\t" \
61+ : "=&r" (result) \
62+ : "r" (&v->counter), "r" (i) \
63+ : "memory" \
64+ __ATOMIC_CLOBBER \
65+ ); \
66+ local_irq_restore(flags); \
67+ } \
68+
69+ #define ATOMIC_OP_RETURN (op ) \
70+ static __inline__ int atomic_##op##_return(int i, atomic_t *v) \
71+ { \
72+ unsigned long flags; \
73+ int result; \
74+ \
75+ local_irq_save(flags); \
76+ __asm__ __volatile__ ( \
77+ "# atomic_" #op "_return \n\t" \
78+ DCACHE_CLEAR("%0", "r4", "%1") \
79+ M32R_LOCK" %0, @%1; \n\t" \
80+ #op " %0, %2; \n\t" \
81+ M32R_UNLOCK" %0, @%1; \n\t" \
82+ : "=&r" (result) \
83+ : "r" (&v->counter), "r" (i) \
84+ : "memory" \
85+ __ATOMIC_CLOBBER \
86+ ); \
87+ local_irq_restore(flags); \
88+ \
89+ return result; \
7190}
7291
73- /**
74- * atomic_sub_return - subtract integer from atomic variable and return it
75- * @i: integer value to subtract
76- * @v: pointer of type atomic_t
77- *
78- * Atomically subtracts @i from @v and return (@v - @i).
79- */
80- static __inline__ int atomic_sub_return (int i , atomic_t * v )
81- {
82- unsigned long flags ;
83- int result ;
84-
85- local_irq_save (flags );
86- __asm__ __volatile__ (
87- "# atomic_sub_return \n\t"
88- DCACHE_CLEAR ("%0" , "r4" , "%1" )
89- M32R_LOCK " %0, @%1; \n\t"
90- "sub %0, %2; \n\t"
91- M32R_UNLOCK " %0, @%1; \n\t"
92- : "= & r " (result)
93- : " r " (&v->counter), " r " (i)
94- : " memory "
95- #ifdef CONFIG_CHIP_M32700_TS1
96- , "r4"
97- #endif /* CONFIG_CHIP_M32700_TS1 */
98- );
99- local_irq_restore (flags );
100-
101- return result ;
102- }
92+ #define ATOMIC_OPS (op ) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
10393
104- /**
105- * atomic_add - add integer to atomic variable
106- * @i: integer value to add
107- * @v: pointer of type atomic_t
108- *
109- * Atomically adds @i to @v.
110- */
111- #define atomic_add (i ,v ) ((void) atomic_add_return((i), (v)))
94+ ATOMIC_OPS (add )
95+ ATOMIC_OPS (sub )
11296
113- /**
114- * atomic_sub - subtract the atomic variable
115- * @i: integer value to subtract
116- * @v: pointer of type atomic_t
117- *
118- * Atomically subtracts @i from @v.
119- */
120- #define atomic_sub (i ,v ) ((void) atomic_sub_return((i), (v)))
97+ #undef ATOMIC_OPS
98+ #undef ATOMIC_OP_RETURN
99+ #undef ATOMIC_OP
121100
122101/**
123102 * atomic_sub_and_test - subtract value from variable and test result
@@ -151,9 +130,7 @@ static __inline__ int atomic_inc_return(atomic_t *v)
151130 : "= & r " (result)
152131 : " r " (&v->counter)
153132 : " memory "
154- #ifdef CONFIG_CHIP_M32700_TS1
155- , "r4"
156- #endif /* CONFIG_CHIP_M32700_TS1 */
133+ __ATOMIC_CLOBBER
157134 );
158135 local_irq_restore (flags );
159136
@@ -181,9 +158,7 @@ static __inline__ int atomic_dec_return(atomic_t *v)
181158 : "= & r " (result)
182159 : " r " (&v->counter)
183160 : " memory "
184- #ifdef CONFIG_CHIP_M32700_TS1
185- , "r4"
186- #endif /* CONFIG_CHIP_M32700_TS1 */
161+ __ATOMIC_CLOBBER
187162 );
188163 local_irq_restore (flags );
189164
@@ -280,9 +255,7 @@ static __inline__ void atomic_clear_mask(unsigned long mask, atomic_t *addr)
280255 : "= & r " (tmp)
281256 : " r " (addr), " r " (~mask)
282257 : " memory "
283- #ifdef CONFIG_CHIP_M32700_TS1
284- , "r5"
285- #endif /* CONFIG_CHIP_M32700_TS1 */
258+ __ATOMIC_CLOBBER
286259 );
287260 local_irq_restore (flags );
288261}
@@ -302,9 +275,7 @@ static __inline__ void atomic_set_mask(unsigned long mask, atomic_t *addr)
302275 : "= & r " (tmp)
303276 : " r " (addr), " r " (mask)
304277 : " memory "
305- #ifdef CONFIG_CHIP_M32700_TS1
306- , "r5"
307- #endif /* CONFIG_CHIP_M32700_TS1 */
278+ __ATOMIC_CLOBBER
308279 );
309280 local_irq_restore (flags );
310281}
0 commit comments