2019-06-03 05:44:50 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2012-03-05 11:49:34 +00:00
|
|
|
/*
|
|
|
|
* Based on arch/arm/include/asm/barrier.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_BARRIER_H
|
|
|
|
#define __ASM_BARRIER_H
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
2019-04-09 11:13:13 +00:00
|
|
|
#include <linux/kasan-checks.h>
|
|
|
|
|
2016-09-06 15:40:23 +00:00
|
|
|
#define __nops(n) ".rept " #n "\nnop\n.endr\n"
|
|
|
|
#define nops(n) asm volatile(__nops(n))
|
|
|
|
|
2012-03-05 11:49:34 +00:00
|
|
|
#define sev() asm volatile("sev" : : : "memory")
|
|
|
|
#define wfe() asm volatile("wfe" : : : "memory")
|
|
|
|
#define wfi() asm volatile("wfi" : : : "memory")
|
|
|
|
|
|
|
|
#define isb() asm volatile("isb" : : : "memory")
|
2014-05-02 15:24:11 +00:00
|
|
|
#define dmb(opt) asm volatile("dmb " #opt : : : "memory")
|
|
|
|
#define dsb(opt) asm volatile("dsb " #opt : : : "memory")
|
2012-03-05 11:49:34 +00:00
|
|
|
|
2017-09-20 15:48:33 +00:00
|
|
|
#define psb_csync() asm volatile("hint #17" : : : "memory")
|
2018-02-05 15:34:16 +00:00
|
|
|
#define csdb() asm volatile("hint #20" : : : "memory")
|
2017-09-20 15:48:33 +00:00
|
|
|
|
2018-06-14 10:21:34 +00:00
|
|
|
#define spec_bar() asm volatile(ALTERNATIVE("dsb nsh\nisb\n", \
|
|
|
|
SB_BARRIER_INSN"nop\n", \
|
|
|
|
ARM64_HAS_SB))
|
|
|
|
|
2019-10-02 09:06:12 +00:00
|
|
|
#ifdef CONFIG_ARM64_PSEUDO_NMI
|
|
|
|
#define pmr_sync() \
|
|
|
|
do { \
|
|
|
|
extern struct static_key_false gic_pmr_sync; \
|
|
|
|
\
|
|
|
|
if (static_branch_unlikely(&gic_pmr_sync)) \
|
|
|
|
dsb(sy); \
|
|
|
|
} while(0)
|
|
|
|
#else
|
|
|
|
#define pmr_sync() do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-02 15:24:10 +00:00
|
|
|
#define mb() dsb(sy)
|
2014-05-02 15:24:11 +00:00
|
|
|
#define rmb() dsb(ld)
|
|
|
|
#define wmb() dsb(st)
|
2012-03-05 11:49:34 +00:00
|
|
|
|
2020-09-28 08:32:02 +00:00
|
|
|
#define dma_mb() dmb(osh)
|
2014-12-11 23:02:06 +00:00
|
|
|
#define dma_rmb() dmb(oshld)
|
|
|
|
#define dma_wmb() dmb(oshst)
|
|
|
|
|
2018-02-05 15:34:17 +00:00
|
|
|
/*
|
|
|
|
* Generate a mask for array_index__nospec() that is ~0UL when 0 <= idx < sz
|
|
|
|
* and 0 otherwise.
|
|
|
|
*/
|
|
|
|
#define array_index_mask_nospec array_index_mask_nospec
|
|
|
|
static inline unsigned long array_index_mask_nospec(unsigned long idx,
|
|
|
|
unsigned long sz)
|
|
|
|
{
|
|
|
|
unsigned long mask;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" cmp %1, %2\n"
|
|
|
|
" sbc %0, xzr, xzr\n"
|
|
|
|
: "=r" (mask)
|
|
|
|
: "r" (idx), "Ir" (sz)
|
|
|
|
: "cc");
|
|
|
|
|
|
|
|
csdb();
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2015-12-27 13:04:42 +00:00
|
|
|
#define __smp_mb() dmb(ish)
|
|
|
|
#define __smp_rmb() dmb(ishld)
|
|
|
|
#define __smp_wmb() dmb(ishst)
|
2013-11-06 13:57:36 +00:00
|
|
|
|
2017-05-03 15:09:34 +00:00
|
|
|
#define __smp_store_release(p, v) \
|
2013-11-06 13:57:36 +00:00
|
|
|
do { \
|
2019-04-09 11:13:13 +00:00
|
|
|
typeof(p) __p = (p); \
|
2019-12-19 17:11:43 +00:00
|
|
|
union { __unqual_scalar_typeof(*p) __val; char __c[1]; } __u = \
|
|
|
|
{ .__val = (__force __unqual_scalar_typeof(*p)) (v) }; \
|
2013-11-06 13:57:36 +00:00
|
|
|
compiletime_assert_atomic_type(*p); \
|
2019-04-09 11:13:13 +00:00
|
|
|
kasan_check_write(__p, sizeof(*p)); \
|
2013-11-06 13:57:36 +00:00
|
|
|
switch (sizeof(*p)) { \
|
2015-04-20 10:14:19 +00:00
|
|
|
case 1: \
|
|
|
|
asm volatile ("stlrb %w1, %0" \
|
2019-04-09 11:13:13 +00:00
|
|
|
: "=Q" (*__p) \
|
2017-05-03 15:09:34 +00:00
|
|
|
: "r" (*(__u8 *)__u.__c) \
|
|
|
|
: "memory"); \
|
2015-04-20 10:14:19 +00:00
|
|
|
break; \
|
|
|
|
case 2: \
|
|
|
|
asm volatile ("stlrh %w1, %0" \
|
2019-04-09 11:13:13 +00:00
|
|
|
: "=Q" (*__p) \
|
2017-05-03 15:09:34 +00:00
|
|
|
: "r" (*(__u16 *)__u.__c) \
|
|
|
|
: "memory"); \
|
2015-04-20 10:14:19 +00:00
|
|
|
break; \
|
2013-11-06 13:57:36 +00:00
|
|
|
case 4: \
|
|
|
|
asm volatile ("stlr %w1, %0" \
|
2019-04-09 11:13:13 +00:00
|
|
|
: "=Q" (*__p) \
|
2017-05-03 15:09:34 +00:00
|
|
|
: "r" (*(__u32 *)__u.__c) \
|
|
|
|
: "memory"); \
|
2013-11-06 13:57:36 +00:00
|
|
|
break; \
|
|
|
|
case 8: \
|
|
|
|
asm volatile ("stlr %1, %0" \
|
2019-04-09 11:13:13 +00:00
|
|
|
: "=Q" (*__p) \
|
2017-05-03 15:09:34 +00:00
|
|
|
: "r" (*(__u64 *)__u.__c) \
|
|
|
|
: "memory"); \
|
2013-11-06 13:57:36 +00:00
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2015-12-27 13:04:42 +00:00
|
|
|
#define __smp_load_acquire(p) \
|
2013-11-06 13:57:36 +00:00
|
|
|
({ \
|
2019-12-19 17:11:43 +00:00
|
|
|
union { __unqual_scalar_typeof(*p) __val; char __c[1]; } __u; \
|
2019-04-09 11:13:13 +00:00
|
|
|
typeof(p) __p = (p); \
|
2013-11-06 13:57:36 +00:00
|
|
|
compiletime_assert_atomic_type(*p); \
|
2019-04-09 11:13:13 +00:00
|
|
|
kasan_check_read(__p, sizeof(*p)); \
|
2013-11-06 13:57:36 +00:00
|
|
|
switch (sizeof(*p)) { \
|
2015-04-20 10:14:19 +00:00
|
|
|
case 1: \
|
|
|
|
asm volatile ("ldarb %w0, %1" \
|
2015-11-18 10:13:08 +00:00
|
|
|
: "=r" (*(__u8 *)__u.__c) \
|
2019-04-09 11:13:13 +00:00
|
|
|
: "Q" (*__p) : "memory"); \
|
2015-04-20 10:14:19 +00:00
|
|
|
break; \
|
|
|
|
case 2: \
|
|
|
|
asm volatile ("ldarh %w0, %1" \
|
2015-11-18 10:13:08 +00:00
|
|
|
: "=r" (*(__u16 *)__u.__c) \
|
2019-04-09 11:13:13 +00:00
|
|
|
: "Q" (*__p) : "memory"); \
|
2015-04-20 10:14:19 +00:00
|
|
|
break; \
|
2013-11-06 13:57:36 +00:00
|
|
|
case 4: \
|
|
|
|
asm volatile ("ldar %w0, %1" \
|
2015-11-18 10:13:08 +00:00
|
|
|
: "=r" (*(__u32 *)__u.__c) \
|
2019-04-09 11:13:13 +00:00
|
|
|
: "Q" (*__p) : "memory"); \
|
2013-11-06 13:57:36 +00:00
|
|
|
break; \
|
|
|
|
case 8: \
|
|
|
|
asm volatile ("ldar %0, %1" \
|
2015-11-18 10:13:08 +00:00
|
|
|
: "=r" (*(__u64 *)__u.__c) \
|
2019-04-09 11:13:13 +00:00
|
|
|
: "Q" (*__p) : "memory"); \
|
2013-11-06 13:57:36 +00:00
|
|
|
break; \
|
|
|
|
} \
|
2019-12-19 17:11:43 +00:00
|
|
|
(typeof(*p))__u.__val; \
|
2013-11-06 13:57:36 +00:00
|
|
|
})
|
|
|
|
|
2018-01-31 15:55:24 +00:00
|
|
|
#define smp_cond_load_relaxed(ptr, cond_expr) \
|
|
|
|
({ \
|
|
|
|
typeof(ptr) __PTR = (ptr); \
|
2019-12-19 17:11:43 +00:00
|
|
|
__unqual_scalar_typeof(*ptr) VAL; \
|
2018-01-31 15:55:24 +00:00
|
|
|
for (;;) { \
|
|
|
|
VAL = READ_ONCE(*__PTR); \
|
|
|
|
if (cond_expr) \
|
|
|
|
break; \
|
|
|
|
__cmpwait_relaxed(__PTR, VAL); \
|
|
|
|
} \
|
2019-12-19 17:11:43 +00:00
|
|
|
(typeof(*ptr))VAL; \
|
2018-01-31 15:55:24 +00:00
|
|
|
})
|
|
|
|
|
2016-06-27 17:43:54 +00:00
|
|
|
#define smp_cond_load_acquire(ptr, cond_expr) \
|
|
|
|
({ \
|
|
|
|
typeof(ptr) __PTR = (ptr); \
|
2019-12-19 17:11:43 +00:00
|
|
|
__unqual_scalar_typeof(*ptr) VAL; \
|
2016-06-27 17:43:54 +00:00
|
|
|
for (;;) { \
|
|
|
|
VAL = smp_load_acquire(__PTR); \
|
|
|
|
if (cond_expr) \
|
|
|
|
break; \
|
|
|
|
__cmpwait_relaxed(__PTR, VAL); \
|
|
|
|
} \
|
2019-12-19 17:11:43 +00:00
|
|
|
(typeof(*ptr))VAL; \
|
2016-06-27 17:43:54 +00:00
|
|
|
})
|
|
|
|
|
2015-12-21 07:22:18 +00:00
|
|
|
#include <asm-generic/barrier.h>
|
2014-03-13 18:00:37 +00:00
|
|
|
|
2012-03-05 11:49:34 +00:00
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
|
|
|
|
#endif /* __ASM_BARRIER_H */
|