diff options
author | Dawid Niedzwiecki <dn@semihalf.com> | 2020-10-01 12:38:03 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-20 14:35:05 +0000 |
commit | e3c5c920b15ce9e7695afa02fa02d874c7819e8e (patch) | |
tree | 7f580a065b69a5331cf2a5f8a155ab5bb25a25dd /core | |
parent | fd29287d25499ec96215cd1ac6a412425a303474 (diff) | |
download | chrome-ec-e3c5c920b15ce9e7695afa02fa02d874c7819e8e.tar.gz |
core/nds32: add Zephyr compatible atomic functions
Add atomic functions with prototypes equal to the ones in Zephyr.
It is done as a part of porting to Zephyr, the next step is to use in
the code atomic_* instead of deprecated_atomic_*.
Some atomic functions in Zephyr return a value e.g. atomic_add - it
returns the value of the variable before the add operation.
Adjust the atomic functions' code to support that.
GCC builtin functions are not used, because those functions are not
available for nds32.
BUG=b:169151160
BRANCH=none
TEST=buildall
Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: I9e181d3c64117b30a08179f84c16162ab70b25fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2444992
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Dino Li <Dino.Li@ite.com.tw>
Diffstat (limited to 'core')
-rw-r--r-- | core/nds32/atomic.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/core/nds32/atomic.h b/core/nds32/atomic.h index d93d1e7b06..ae33b39986 100644 --- a/core/nds32/atomic.h +++ b/core/nds32/atomic.h @@ -12,6 +12,9 @@ #include "cpu.h" #include "task.h" +typedef int atomic_t; +typedef atomic_t atomic_val_t; + /* * The atomic_* functions are marked as deprecated as a part of the process of * transaction to Zephyr compatible atomic functions. These prefixes will be @@ -27,6 +30,15 @@ static inline void deprecated_atomic_clear_bits(uint32_t volatile *addr, set_int_mask(int_mask); } +static inline void atomic_clear_bits(atomic_t *addr, atomic_val_t bits) +{ + atomic_t volatile *ptr = addr; + uint32_t int_mask = read_clear_int_mask(); + + *ptr &= ~bits; + set_int_mask(int_mask); +} + static inline void deprecated_atomic_or(uint32_t volatile *addr, uint32_t bits) { uint32_t int_mask = read_clear_int_mask(); @@ -35,6 +47,18 @@ static inline void deprecated_atomic_or(uint32_t volatile *addr, uint32_t bits) set_int_mask(int_mask); } +static inline atomic_val_t atomic_or(atomic_t *addr, atomic_val_t bits) +{ + atomic_val_t ret; + atomic_t volatile *ptr = addr; + uint32_t int_mask = read_clear_int_mask(); + + ret = *ptr; + *ptr |= bits; + set_int_mask(int_mask); + return ret; +} + static inline void deprecated_atomic_add(uint32_t volatile *addr, uint32_t value) { @@ -44,6 +68,18 @@ static inline void deprecated_atomic_add(uint32_t volatile *addr, set_int_mask(int_mask); } +static inline atomic_val_t atomic_add(atomic_t *addr, atomic_val_t value) +{ + atomic_val_t ret; + atomic_t volatile *ptr = addr; + uint32_t int_mask = read_clear_int_mask(); + + ret = *ptr; + *ptr += value; + set_int_mask(int_mask); + return ret; +} + static inline void deprecated_atomic_sub(uint32_t volatile *addr, uint32_t value) { @@ -53,6 +89,18 @@ static inline void deprecated_atomic_sub(uint32_t volatile *addr, set_int_mask(int_mask); } +static inline atomic_val_t atomic_sub(atomic_t *addr, atomic_val_t value) +{ + atomic_val_t ret; + atomic_t volatile *ptr = addr; + uint32_t int_mask = read_clear_int_mask(); + + ret = *ptr; + *ptr -= value; + set_int_mask(int_mask); + return ret; +} + static inline uint32_t deprecated_atomic_read_clear(uint32_t volatile *addr) { uint32_t val; @@ -63,4 +111,17 @@ static inline uint32_t deprecated_atomic_read_clear(uint32_t volatile *addr) set_int_mask(int_mask); return val; } + +static inline atomic_val_t atomic_read_clear(atomic_t *addr) +{ + atomic_val_t ret; + atomic_t volatile *ptr = addr; + uint32_t int_mask = read_clear_int_mask(); + + ret = *ptr; + *ptr = 0; + set_int_mask(int_mask); + return ret; +} + #endif /* __CROS_EC_ATOMIC_H */ |