Catalin Marinas | 10b663a | 2012-03-05 11:49:34 +0000 | [diff] [blame] | 1 | /* |
| 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 Deacon | 493e687 | 2014-05-02 16:24:11 +0100 | [diff] [blame] | 28 | #define dmb(opt) asm volatile("dmb " #opt : : : "memory") |
| 29 | #define dsb(opt) asm volatile("dsb " #opt : : : "memory") |
Catalin Marinas | 10b663a | 2012-03-05 11:49:34 +0000 | [diff] [blame] | 30 | |
Will Deacon | 98f7685 | 2014-05-02 16:24:10 +0100 | [diff] [blame] | 31 | #define mb() dsb(sy) |
Will Deacon | 493e687 | 2014-05-02 16:24:11 +0100 | [diff] [blame] | 32 | #define rmb() dsb(ld) |
| 33 | #define wmb() dsb(st) |
Catalin Marinas | 10b663a | 2012-03-05 11:49:34 +0000 | [diff] [blame] | 34 | |
Alexander Duyck | 1077fa3 | 2014-12-11 15:02:06 -0800 | [diff] [blame] | 35 | #define dma_rmb() dmb(oshld) |
| 36 | #define dma_wmb() dmb(oshst) |
| 37 | |
Catalin Marinas | 10b663a | 2012-03-05 11:49:34 +0000 | [diff] [blame] | 38 | #ifndef CONFIG_SMP |
| 39 | #define smp_mb() barrier() |
| 40 | #define smp_rmb() barrier() |
| 41 | #define smp_wmb() barrier() |
Peter Zijlstra | 47933ad | 2013-11-06 14:57:36 +0100 | [diff] [blame] | 42 | |
| 43 | #define smp_store_release(p, v) \ |
| 44 | do { \ |
| 45 | compiletime_assert_atomic_type(*p); \ |
Will Deacon | be6209a | 2014-05-02 16:24:12 +0100 | [diff] [blame] | 46 | barrier(); \ |
Peter Zijlstra | 47933ad | 2013-11-06 14:57:36 +0100 | [diff] [blame] | 47 | ACCESS_ONCE(*p) = (v); \ |
| 48 | } while (0) |
| 49 | |
| 50 | #define smp_load_acquire(p) \ |
| 51 | ({ \ |
| 52 | typeof(*p) ___p1 = ACCESS_ONCE(*p); \ |
| 53 | compiletime_assert_atomic_type(*p); \ |
Will Deacon | be6209a | 2014-05-02 16:24:12 +0100 | [diff] [blame] | 54 | barrier(); \ |
Peter Zijlstra | 47933ad | 2013-11-06 14:57:36 +0100 | [diff] [blame] | 55 | ___p1; \ |
| 56 | }) |
| 57 | |
Catalin Marinas | 10b663a | 2012-03-05 11:49:34 +0000 | [diff] [blame] | 58 | #else |
Peter Zijlstra | 47933ad | 2013-11-06 14:57:36 +0100 | [diff] [blame] | 59 | |
Will Deacon | 493e687 | 2014-05-02 16:24:11 +0100 | [diff] [blame] | 60 | #define smp_mb() dmb(ish) |
| 61 | #define smp_rmb() dmb(ishld) |
| 62 | #define smp_wmb() dmb(ishst) |
Peter Zijlstra | 47933ad | 2013-11-06 14:57:36 +0100 | [diff] [blame] | 63 | |
| 64 | #define smp_store_release(p, v) \ |
| 65 | do { \ |
| 66 | compiletime_assert_atomic_type(*p); \ |
| 67 | switch (sizeof(*p)) { \ |
| 68 | case 4: \ |
| 69 | asm volatile ("stlr %w1, %0" \ |
| 70 | : "=Q" (*p) : "r" (v) : "memory"); \ |
| 71 | break; \ |
| 72 | case 8: \ |
| 73 | asm volatile ("stlr %1, %0" \ |
| 74 | : "=Q" (*p) : "r" (v) : "memory"); \ |
| 75 | break; \ |
| 76 | } \ |
| 77 | } while (0) |
| 78 | |
| 79 | #define smp_load_acquire(p) \ |
| 80 | ({ \ |
| 81 | typeof(*p) ___p1; \ |
| 82 | compiletime_assert_atomic_type(*p); \ |
| 83 | switch (sizeof(*p)) { \ |
| 84 | case 4: \ |
| 85 | asm volatile ("ldar %w0, %1" \ |
| 86 | : "=r" (___p1) : "Q" (*p) : "memory"); \ |
| 87 | break; \ |
| 88 | case 8: \ |
| 89 | asm volatile ("ldar %0, %1" \ |
| 90 | : "=r" (___p1) : "Q" (*p) : "memory"); \ |
| 91 | break; \ |
| 92 | } \ |
| 93 | ___p1; \ |
| 94 | }) |
| 95 | |
Catalin Marinas | 10b663a | 2012-03-05 11:49:34 +0000 | [diff] [blame] | 96 | #endif |
| 97 | |
| 98 | #define read_barrier_depends() do { } while(0) |
| 99 | #define smp_read_barrier_depends() do { } while(0) |
| 100 | |
| 101 | #define set_mb(var, value) do { var = value; smp_mb(); } while (0) |
| 102 | #define nop() asm volatile("nop"); |
| 103 | |
Peter Zijlstra | 8715466 | 2014-03-13 19:00:37 +0100 | [diff] [blame] | 104 | #define smp_mb__before_atomic() smp_mb() |
| 105 | #define smp_mb__after_atomic() smp_mb() |
| 106 | |
Catalin Marinas | 10b663a | 2012-03-05 11:49:34 +0000 | [diff] [blame] | 107 | #endif /* __ASSEMBLY__ */ |
| 108 | |
| 109 | #endif /* __ASM_BARRIER_H */ |