Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
| openrisc: | TODO |
| parisc: | TODO |
| powerpc: | TODO |
| riscv: | TODO |
| riscv: | ok |
| s390: | ok |
| sh: | TODO |
| sparc: | TODO |
Expand Down
1 change: 1 addition & 0 deletions arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ config RISCV
select HAVE_ARCH_VMAP_STACK if MMU && 64BIT
select HAVE_ASM_MODVERSIONS
select HAVE_BUILDTIME_MCOUNT_SORT
select HAVE_CMPXCHG_LOCAL
select HAVE_CONTEXT_TRACKING_USER
select HAVE_DEBUG_KMEMLEAK
select HAVE_DMA_CONTIGUOUS if MMU
Expand Down
49 changes: 49 additions & 0 deletions arch/riscv/include/asm/percpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _ASM_RISCV_PERCPU_H
#define _ASM_RISCV_PERCPU_H

#include <linux/preempt.h>

#include <asm/cmpxchg.h>

#define _protect_cmpxchg_local(pcp, o, n) \
({ \
typeof(pcp) *__ptr; \
typeof(pcp) __pcpu_old = (o); \
typeof(pcp) __pcpu_new = (n); \
typeof(*raw_cpu_ptr(&(pcp))) __ret; \
preempt_disable_notrace(); \
__ptr = raw_cpu_ptr(&(pcp)); \
__ret = cmpxchg_local(__ptr, __pcpu_old, __pcpu_new); \
preempt_enable_notrace(); \
__ret; \
})

#define this_cpu_cmpxchg_4(pcp, o, n) _protect_cmpxchg_local(pcp, o, n)

#ifdef CONFIG_64BIT
#define this_cpu_cmpxchg_8(pcp, o, n) _protect_cmpxchg_local(pcp, o, n)
#define this_cpu_cmpxchg64(pcp, o, n) this_cpu_cmpxchg_8(pcp, o, n)

#if defined(CONFIG_RISCV_ISA_ZACAS) && defined(CONFIG_TOOLCHAIN_HAS_ZACAS)
#define _protect_cmpxchg128_local(pcp, o, n) \
({ \
typeof(pcp) *__ptr; \
typeof(pcp) __pcpu_old = (o); \
typeof(pcp) __pcpu_new = (n); \
typeof(pcp) __ret; \
preempt_disable_notrace(); \
__ptr = raw_cpu_ptr(&(pcp)); \
__ret = cmpxchg128_local(__ptr, __pcpu_old, __pcpu_new); \
preempt_enable_notrace(); \
__ret; \
})

#define this_cpu_cmpxchg128(pcp, o, n) \
_protect_cmpxchg128_local(pcp, o, n)
#endif
#endif

#include <asm-generic/percpu.h>

#endif /* _ASM_RISCV_PERCPU_H */
Loading