blob: 624f9679f4b0abb3e41da2c7ec23c4a7625196e3 [file] [log] [blame]
Catalin Marinas10b663a2012-03-05 11:49:34 +00001/*
2 * Based on arch/arm/include/asm/barrier.h
3 *
4 * Copyright (C) 2012 ARM Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifndef __ASM_BARRIER_H
19#define __ASM_BARRIER_H
20
21#ifndef __ASSEMBLY__
22
23#define sev() asm volatile("sev" : : : "memory")
24#define wfe() asm volatile("wfe" : : : "memory")
25#define wfi() asm volatile("wfi" : : : "memory")
26
27#define isb() asm volatile("isb" : : : "memory")
Will Deacon493e6872014-05-02 16:24:11 +010028#define dmb(opt) asm volatile("dmb " #opt : : : "memory")
29#define dsb(opt) asm volatile("dsb " #opt : : : "memory")
Catalin Marinas10b663a2012-03-05 11:49:34 +000030
Will Deacon98f76852014-05-02 16:24:10 +010031#define mb() dsb(sy)
Will Deacon493e6872014-05-02 16:24:11 +010032#define rmb() dsb(ld)
33#define wmb() dsb(st)
Catalin Marinas10b663a2012-03-05 11:49:34 +000034
Alexander Duyck1077fa32014-12-11 15:02:06 -080035#define dma_rmb() dmb(oshld)
36#define dma_wmb() dmb(oshst)
37
Will Deacon493e6872014-05-02 16:24:11 +010038#define smp_mb() dmb(ish)
39#define smp_rmb() dmb(ishld)
40#define smp_wmb() dmb(ishst)
Peter Zijlstra47933ad2013-11-06 14:57:36 +010041
42#define smp_store_release(p, v) \
43do { \
44 compiletime_assert_atomic_type(*p); \
45 switch (sizeof(*p)) { \
Andre Przywara878a84d2015-04-20 11:14:19 +010046 case 1: \
47 asm volatile ("stlrb %w1, %0" \
48 : "=Q" (*p) : "r" (v) : "memory"); \
49 break; \
50 case 2: \
51 asm volatile ("stlrh %w1, %0" \
52 : "=Q" (*p) : "r" (v) : "memory"); \
53 break; \
Peter Zijlstra47933ad2013-11-06 14:57:36 +010054 case 4: \
55 asm volatile ("stlr %w1, %0" \
56 : "=Q" (*p) : "r" (v) : "memory"); \
57 break; \
58 case 8: \
59 asm volatile ("stlr %1, %0" \
60 : "=Q" (*p) : "r" (v) : "memory"); \
61 break; \
62 } \
63} while (0)
64
65#define smp_load_acquire(p) \
66({ \
67 typeof(*p) ___p1; \
68 compiletime_assert_atomic_type(*p); \
69 switch (sizeof(*p)) { \
Andre Przywara878a84d2015-04-20 11:14:19 +010070 case 1: \
71 asm volatile ("ldarb %w0, %1" \
72 : "=r" (___p1) : "Q" (*p) : "memory"); \
73 break; \
74 case 2: \
75 asm volatile ("ldarh %w0, %1" \
76 : "=r" (___p1) : "Q" (*p) : "memory"); \
77 break; \
Peter Zijlstra47933ad2013-11-06 14:57:36 +010078 case 4: \
79 asm volatile ("ldar %w0, %1" \
80 : "=r" (___p1) : "Q" (*p) : "memory"); \
81 break; \
82 case 8: \
83 asm volatile ("ldar %0, %1" \
84 : "=r" (___p1) : "Q" (*p) : "memory"); \
85 break; \
86 } \
87 ___p1; \
88})
89
Catalin Marinas10b663a2012-03-05 11:49:34 +000090#define read_barrier_depends() do { } while(0)
91#define smp_read_barrier_depends() do { } while(0)
92
Peter Zijlstrab92b8b32015-05-12 10:51:55 +020093#define smp_store_mb(var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0)
Catalin Marinas10b663a2012-03-05 11:49:34 +000094#define nop() asm volatile("nop");
95
Peter Zijlstra87154662014-03-13 19:00:37 +010096#define smp_mb__before_atomic() smp_mb()
97#define smp_mb__after_atomic() smp_mb()
98
Catalin Marinas10b663a2012-03-05 11:49:34 +000099#endif /* __ASSEMBLY__ */
100
101#endif /* __ASM_BARRIER_H */