summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDawid Niedzwiecki <dn@semihalf.com>2022-03-04 11:47:37 +0100
committerCommit Bot <commit-bot@chromium.org>2022-03-09 09:49:29 +0000
commitc755fffea0e2e05733e61ea254d820612e869b7a (patch)
tree6c92d6c062de5d1d9ac16f576d34023588ee9b46 /core
parent3f1fe1e185c05c8037576466d246945be385973d (diff)
downloadchrome-ec-c755fffea0e2e05733e61ea254d820612e869b7a.tar.gz
atomic: add atomic_and function
Add atomic_and functions for all cores. The functions will be used for more complex atomic operations for bits manipulating that will be merged in a following CL. BRANCH=none BUG=b:208435177 TEST=make buildall Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I659ee8214206750fbe8af4df21672d8cbfc59278 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3500418 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Dawid Niedzwiecki <dawidn@google.com>
Diffstat (limited to 'core')
-rw-r--r--core/cortex-m/atomic.h5
-rw-r--r--core/cortex-m0/atomic.h5
-rw-r--r--core/host/atomic.h5
-rw-r--r--core/nds32/atomic.h12
-rw-r--r--core/riscv-rv32i/atomic.h5
5 files changed, 32 insertions, 0 deletions
diff --git a/core/cortex-m/atomic.h b/core/cortex-m/atomic.h
index ce183465e8..a09f5cc8be 100644
--- a/core/cortex-m/atomic.h
+++ b/core/cortex-m/atomic.h
@@ -36,4 +36,9 @@ static inline atomic_val_t atomic_clear(atomic_t *addr)
return __atomic_exchange_n(addr, 0, __ATOMIC_SEQ_CST);
}
+static inline atomic_val_t atomic_and(atomic_t *addr, atomic_val_t bits)
+{
+ return __atomic_fetch_and(addr, bits, __ATOMIC_SEQ_CST);
+}
+
#endif /* __CROS_EC_ATOMIC_H */
diff --git a/core/cortex-m0/atomic.h b/core/cortex-m0/atomic.h
index aef4d2a0a6..7ec856ed62 100644
--- a/core/cortex-m0/atomic.h
+++ b/core/cortex-m0/atomic.h
@@ -69,4 +69,9 @@ static inline atomic_val_t atomic_clear(atomic_t *addr)
return ret;
}
+static inline atomic_val_t atomic_and(atomic_t *addr, atomic_val_t bits)
+{
+ return ATOMIC_OP(ands, addr, bits);
+}
+
#endif /* __CROS_EC_ATOMIC_H */
diff --git a/core/host/atomic.h b/core/host/atomic.h
index 175b743d05..a8d6882d0e 100644
--- a/core/host/atomic.h
+++ b/core/host/atomic.h
@@ -35,4 +35,9 @@ static inline atomic_val_t atomic_clear(atomic_t *addr)
{
return __atomic_exchange_n(addr, 0, __ATOMIC_SEQ_CST);
}
+
+static inline atomic_val_t atomic_and(atomic_t *addr, atomic_val_t bits)
+{
+ return __atomic_fetch_and(addr, bits, __ATOMIC_SEQ_CST);
+}
#endif /* __CROS_EC_ATOMIC_H */
diff --git a/core/nds32/atomic.h b/core/nds32/atomic.h
index f50deaaba3..592834faae 100644
--- a/core/nds32/atomic.h
+++ b/core/nds32/atomic.h
@@ -73,4 +73,16 @@ static inline atomic_val_t atomic_clear(atomic_t *addr)
return ret;
}
+static inline atomic_val_t atomic_and(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;
+}
+
#endif /* __CROS_EC_ATOMIC_H */
diff --git a/core/riscv-rv32i/atomic.h b/core/riscv-rv32i/atomic.h
index 91658e8065..4d6114cd53 100644
--- a/core/riscv-rv32i/atomic.h
+++ b/core/riscv-rv32i/atomic.h
@@ -48,4 +48,9 @@ static inline atomic_val_t atomic_read_sub(atomic_t *addr, atomic_val_t value)
return __atomic_fetch_sub(addr, value, __ATOMIC_SEQ_CST);
}
+static inline atomic_val_t atomic_and(atomic_t *addr, atomic_val_t bits)
+{
+ return __atomic_fetch_and(addr, bits, __ATOMIC_SEQ_CST);
+}
+
#endif /* __CROS_EC_ATOMIC_H */