xref: /rk3399_rockchip-uboot/arch/xtensa/include/asm/atomic.h (revision c978b52410016b0ab5a213f235596340af8d45f7)
1*c978b524SChris Zankel /*
2*c978b524SChris Zankel  * Copyright (C) 2016 Cadence Design Systems Inc.
3*c978b524SChris Zankel  *
4*c978b524SChris Zankel  * SPDX-License-Identifier:	GPL-2.0+
5*c978b524SChris Zankel  */
6*c978b524SChris Zankel 
7*c978b524SChris Zankel #ifndef _XTENSA_ATOMIC_H
8*c978b524SChris Zankel #define _XTENSA_ATOMIC_H
9*c978b524SChris Zankel 
10*c978b524SChris Zankel #include <asm/system.h>
11*c978b524SChris Zankel 
12*c978b524SChris Zankel typedef struct { volatile int counter; } atomic_t;
13*c978b524SChris Zankel 
14*c978b524SChris Zankel #define ATOMIC_INIT(i)	{ (i) }
15*c978b524SChris Zankel 
16*c978b524SChris Zankel #define atomic_read(v)		((v)->counter)
17*c978b524SChris Zankel #define atomic_set(v, i)	((v)->counter = (i))
18*c978b524SChris Zankel 
atomic_add(int i,atomic_t * v)19*c978b524SChris Zankel static inline void atomic_add(int i, atomic_t *v)
20*c978b524SChris Zankel {
21*c978b524SChris Zankel 	unsigned long flags;
22*c978b524SChris Zankel 
23*c978b524SChris Zankel 	local_irq_save(flags);
24*c978b524SChris Zankel 	v->counter += i;
25*c978b524SChris Zankel 	local_irq_restore(flags);
26*c978b524SChris Zankel }
27*c978b524SChris Zankel 
atomic_sub(int i,atomic_t * v)28*c978b524SChris Zankel static inline void atomic_sub(int i, atomic_t *v)
29*c978b524SChris Zankel {
30*c978b524SChris Zankel 	unsigned long flags;
31*c978b524SChris Zankel 
32*c978b524SChris Zankel 	local_irq_save(flags);
33*c978b524SChris Zankel 	v->counter -= i;
34*c978b524SChris Zankel 	local_irq_restore(flags);
35*c978b524SChris Zankel }
36*c978b524SChris Zankel 
atomic_inc(atomic_t * v)37*c978b524SChris Zankel static inline void atomic_inc(atomic_t *v)
38*c978b524SChris Zankel {
39*c978b524SChris Zankel 	unsigned long flags;
40*c978b524SChris Zankel 
41*c978b524SChris Zankel 	local_irq_save(flags);
42*c978b524SChris Zankel 	++v->counter;
43*c978b524SChris Zankel 	local_irq_restore(flags);
44*c978b524SChris Zankel }
45*c978b524SChris Zankel 
atomic_dec(atomic_t * v)46*c978b524SChris Zankel static inline void atomic_dec(atomic_t *v)
47*c978b524SChris Zankel {
48*c978b524SChris Zankel 	unsigned long flags;
49*c978b524SChris Zankel 
50*c978b524SChris Zankel 	local_irq_save(flags);
51*c978b524SChris Zankel 	--v->counter;
52*c978b524SChris Zankel 	local_irq_restore(flags);
53*c978b524SChris Zankel }
54*c978b524SChris Zankel 
55*c978b524SChris Zankel #endif
56