summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnup Patel <[email protected]>2023-12-08 13:54:07 +0530
committerAnup Patel <[email protected]>2023-12-08 14:06:40 +0530
commit88398696c816dfc79d5301180dfe42a5d8c497c9 (patch)
treeda7ea81e4b276e1c2cc1d0cc12dcffd11a3cc335
parent11bf49b44466b821d0936419caf24befab0a61b7 (diff)
lib: sbi: Replace __atomic_op_bit_ord with __atomic intrinsics
Simplify atomic-related bit operations through __atomic intrinsics. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
-rw-r--r--lib/sbi/riscv_atomic.c34
1 files changed, 6 insertions, 28 deletions
diff --git a/lib/sbi/riscv_atomic.c b/lib/sbi/riscv_atomic.c
index 4d14bc56..32cf3f03 100644
--- a/lib/sbi/riscv_atomic.c
+++ b/lib/sbi/riscv_atomic.c
@@ -108,40 +108,18 @@ unsigned long atomic_raw_xchg_ulong(volatile unsigned long *ptr,
return axchg(ptr, newval);
}
-#if (__SIZEOF_POINTER__ == 8)
-#define __AMO(op) "amo" #op ".d"
-#elif (__SIZEOF_POINTER__ == 4)
-#define __AMO(op) "amo" #op ".w"
-#else
-#error "Unexpected __SIZEOF_POINTER__"
-#endif
-
-#define __atomic_op_bit_ord(op, mod, nr, addr, ord) \
- ({ \
- unsigned long __res, __mask; \
- __mask = BIT_MASK(nr); \
- __asm__ __volatile__(__AMO(op) #ord " %0, %2, %1" \
- : "=r"(__res), "+A"(addr[BIT_WORD(nr)]) \
- : "r"(mod(__mask)) \
- : "memory"); \
- __res & __mask ? 1 : 0; \
- })
-
-#define __atomic_op_bit(op, mod, nr, addr) \
- __atomic_op_bit_ord(op, mod, nr, addr, .aqrl)
-
-/* Bitmask modifiers */
-#define __NOP(x) (x)
-#define __NOT(x) (~(x))
-
int atomic_raw_set_bit(int nr, volatile unsigned long *addr)
{
- return __atomic_op_bit(or, __NOP, nr, addr);
+ unsigned long res, mask = BIT_MASK(nr);
+ res = __atomic_fetch_or(&addr[BIT_WORD(nr)], mask, __ATOMIC_RELAXED);
+ return res & mask ? 1 : 0;
}
int atomic_raw_clear_bit(int nr, volatile unsigned long *addr)
{
- return __atomic_op_bit(and, __NOT, nr, addr);
+ unsigned long res, mask = BIT_MASK(nr);
+ res = __atomic_fetch_and(&addr[BIT_WORD(nr)], ~mask, __ATOMIC_RELAXED);
+ return res & mask ? 1 : 0;
}
int atomic_set_bit(int nr, atomic_t *atom)