diff options
author | Dawid Niedzwiecki <dn@semihalf.com> | 2020-10-05 09:56:35 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-13 11:02:03 +0000 |
commit | 44435d3b9c447ad25edaa8aece42f1cff0dd6df9 (patch) | |
tree | 918144099242bc536c026c1948bfdd7084a5c33f | |
parent | f471709ee0bd4f02f62eac6efb25a9656ec70ea9 (diff) | |
download | chrome-ec-44435d3b9c447ad25edaa8aece42f1cff0dd6df9.tar.gz |
core/minute-ia: 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.
The current state of ATOMIC_OP macro is not designed to return such value
so instead of reworking it or writing new custom asm code just use
builtin functions.
The __atomic_* builtins support variables with different sizes so use
them in *_u8 functions as well.
For "and" operation, it compiles to "andb" for u8 and to "andl" for u32.
BUG=b:169151160
BRANCH=none
TEST=buildall
Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: I498ca3dbb14aea6afc2f7a525c530eede7f31fe2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2448497
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | core/minute-ia/atomic.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/core/minute-ia/atomic.h b/core/minute-ia/atomic.h index 598fc5b3ed..f55018d445 100644 --- a/core/minute-ia/atomic.h +++ b/core/minute-ia/atomic.h @@ -11,6 +11,9 @@ #include "common.h" #include "util.h" +typedef int atomic_t; +typedef atomic_t atomic_val_t; + #define ATOMIC_OP(asm_op, a, v) do { \ __asm__ __volatile__ ( \ ASM_LOCK_PREFIX #asm_op " %1, %0\n" \ @@ -43,40 +46,75 @@ static inline void deprecated_atomic_or_u8(uint8_t *addr, uint8_t bits) ATOMIC_OP(or, addr, bits); } +static inline atomic_val_t atomic_or_u8(uint8_t *addr, uint8_t bits) +{ + return __atomic_fetch_or(addr, bits, __ATOMIC_SEQ_CST); +} + static inline void deprecated_atomic_and_u8(uint8_t *addr, uint8_t bits) { ATOMIC_OP(and, addr, bits); } +static inline atomic_val_t atomic_and_u8(uint8_t *addr, uint8_t bits) +{ + return __atomic_fetch_and(addr, bits, __ATOMIC_SEQ_CST); +} + static inline void deprecated_atomic_clear_bits(uint32_t volatile *addr, uint32_t bits) { ATOMIC_OP(andl, addr, ~bits); } +static inline void atomic_clear_bits(atomic_t *addr, atomic_val_t bits) +{ + __atomic_fetch_and(addr, ~bits, __ATOMIC_SEQ_CST); +} + static inline void deprecated_atomic_or(uint32_t volatile *addr, uint32_t bits) { ATOMIC_OP(orl, addr, bits); } +static inline atomic_val_t atomic_or(atomic_t *addr, atomic_val_t bits) +{ + return __atomic_fetch_or(addr, bits, __ATOMIC_SEQ_CST); +} + static inline void deprecated_atomic_add(uint32_t volatile *addr, uint32_t value) { ATOMIC_OP(addl, addr, value); } +static inline atomic_val_t atomic_add(atomic_t *addr, atomic_val_t value) +{ + return __atomic_fetch_add(addr, value, __ATOMIC_SEQ_CST); +} + static inline void deprecated_atomic_and(uint32_t volatile *addr, uint32_t value) { ATOMIC_OP(andl, addr, value); } +static inline atomic_val_t atomic_and(atomic_t *addr, atomic_val_t bits) +{ + return __atomic_fetch_and(addr, bits, __ATOMIC_SEQ_CST); +} + static inline void deprecated_atomic_sub(uint32_t volatile *addr, uint32_t value) { ATOMIC_OP(subl, addr, value); } +static inline atomic_val_t atomic_sub(atomic_t *addr, atomic_val_t value) +{ + return __atomic_fetch_sub(addr, value, __ATOMIC_SEQ_CST); +} + static inline uint32_t deprecated_atomic_read_clear(uint32_t volatile *addr) { int ret = 0; @@ -91,4 +129,9 @@ static inline uint32_t deprecated_atomic_read_clear(uint32_t volatile *addr) return ret; } +static inline atomic_val_t atomic_read_clear(atomic_t *addr) +{ + return __atomic_exchange_n(addr, 0, __ATOMIC_SEQ_CST); +} + #endif /* __CROS_EC_ATOMIC_H */ |