barrier.h 2.5 KB
Newer Older
G
Guo Ren 已提交
1 2 3 4 5 6 7 8 9
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __ASM_CSKY_BARRIER_H
#define __ASM_CSKY_BARRIER_H

#ifndef __ASSEMBLY__

#define nop()	asm volatile ("nop\n":::"memory")

G
Guo Ren 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#ifdef CONFIG_SMP

/*
 * bar.brwarws: ordering barrier for all load/store instructions
 *              before/after
 *
 * |31|30 26|25 21|20 16|15  10|9   5|4           0|
 *  1  10000 00000 00000 100001	00001 0 bw br aw ar
 *
 * b: before
 * a: after
 * r: read
 * w: write
 *
 * Here are all combinations:
 *
 * bar.brw
 * bar.br
 * bar.bw
 * bar.arw
 * bar.ar
 * bar.aw
 * bar.brwarw
 * bar.brarw
 * bar.bwarw
 * bar.brwar
 * bar.brwaw
 * bar.brar
 * bar.bwaw
 */
40 41 42 43
#define FULL_FENCE		".long 0x842fc000\n"
#define ACQUIRE_FENCE		".long 0x8427c000\n"
#define RELEASE_FENCE		".long 0x842ec000\n"

G
Guo Ren 已提交
44 45 46 47 48 49
#define __bar_brw()	asm volatile (".long 0x842cc000\n":::"memory")
#define __bar_br()	asm volatile (".long 0x8424c000\n":::"memory")
#define __bar_bw()	asm volatile (".long 0x8428c000\n":::"memory")
#define __bar_arw()	asm volatile (".long 0x8423c000\n":::"memory")
#define __bar_ar()	asm volatile (".long 0x8421c000\n":::"memory")
#define __bar_aw()	asm volatile (".long 0x8422c000\n":::"memory")
50 51
#define __bar_brwarw()	asm volatile (FULL_FENCE:::"memory")
#define __bar_brarw()	asm volatile (ACQUIRE_FENCE:::"memory")
G
Guo Ren 已提交
52 53
#define __bar_bwarw()	asm volatile (".long 0x842bc000\n":::"memory")
#define __bar_brwar()	asm volatile (".long 0x842dc000\n":::"memory")
54
#define __bar_brwaw()	asm volatile (RELEASE_FENCE:::"memory")
G
Guo Ren 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67
#define __bar_brar()	asm volatile (".long 0x8425c000\n":::"memory")
#define __bar_brar()	asm volatile (".long 0x8425c000\n":::"memory")
#define __bar_bwaw()	asm volatile (".long 0x842ac000\n":::"memory")

#define __smp_mb()	__bar_brwarw()
#define __smp_rmb()	__bar_brar()
#define __smp_wmb()	__bar_bwaw()

#define __smp_acquire_fence()	__bar_brarw()
#define __smp_release_fence()	__bar_brwaw()

#endif /* CONFIG_SMP */

G
Guo Ren 已提交
68
/*
69
 * sync:        completion barrier, all sync.xx instructions
J
Junlin Yang 已提交
70
 *              guarantee the last response received by bus transaction
71 72 73 74
 *              made by ld/st instructions before sync.s
 * sync.s:      inherit from sync, but also shareable to other cores
 * sync.i:      inherit from sync, but also flush cpu pipeline
 * sync.is:     the same with sync.i + sync.s
G
Guo Ren 已提交
75
 */
G
Guo Ren 已提交
76
#define mb()		asm volatile ("sync\n":::"memory")
G
Guo Ren 已提交
77 78

#ifdef CONFIG_CPU_HAS_CACHEV2
G
Guo Ren 已提交
79 80 81 82
/*
 * Using three sync.is to prevent speculative PTW
 */
#define sync_is()	asm volatile ("sync.is\nsync.is\nsync.is\n":::"memory")
G
Guo Ren 已提交
83 84 85 86 87 88
#endif

#include <asm-generic/barrier.h>

#endif /* __ASSEMBLY__ */
#endif /* __ASM_CSKY_BARRIER_H */