David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 1 | #ifndef __ASM_BARRIER_H |
| 2 | #define __ASM_BARRIER_H |
| 3 | |
| 4 | #ifndef __ASSEMBLY__ |
| 5 | |
| 6 | #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t"); |
| 7 | |
| 8 | #if __LINUX_ARM_ARCH__ >= 7 || \ |
| 9 | (__LINUX_ARM_ARCH__ == 6 && defined(CONFIG_CPU_32v6K)) |
| 10 | #define sev() __asm__ __volatile__ ("sev" : : : "memory") |
| 11 | #define wfe() __asm__ __volatile__ ("wfe" : : : "memory") |
| 12 | #define wfi() __asm__ __volatile__ ("wfi" : : : "memory") |
| 13 | #endif |
| 14 | |
| 15 | #if __LINUX_ARM_ARCH__ >= 7 |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 16 | #define isb(option) __asm__ __volatile__ ("isb " #option : : : "memory") |
| 17 | #define dsb(option) __asm__ __volatile__ ("dsb " #option : : : "memory") |
| 18 | #define dmb(option) __asm__ __volatile__ ("dmb " #option : : : "memory") |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 19 | #elif defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ == 6 |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 20 | #define isb(x) __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \ |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 21 | : : "r" (0) : "memory") |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 22 | #define dsb(x) __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \ |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 23 | : : "r" (0) : "memory") |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 24 | #define dmb(x) __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \ |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 25 | : : "r" (0) : "memory") |
| 26 | #elif defined(CONFIG_CPU_FA526) |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 27 | #define isb(x) __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \ |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 28 | : : "r" (0) : "memory") |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 29 | #define dsb(x) __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \ |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 30 | : : "r" (0) : "memory") |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 31 | #define dmb(x) __asm__ __volatile__ ("" : : : "memory") |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 32 | #else |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 33 | #define isb(x) __asm__ __volatile__ ("" : : : "memory") |
| 34 | #define dsb(x) __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \ |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 35 | : : "r" (0) : "memory") |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 36 | #define dmb(x) __asm__ __volatile__ ("" : : : "memory") |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 37 | #endif |
| 38 | |
Russell King | f813090 | 2015-06-01 23:44:46 +0100 | [diff] [blame] | 39 | #ifdef CONFIG_ARM_HEAVY_MB |
Russell King | 4e1f8a6 | 2015-06-03 13:10:16 +0100 | [diff] [blame^] | 40 | extern void (*soc_mb)(void); |
Russell King | f813090 | 2015-06-01 23:44:46 +0100 | [diff] [blame] | 41 | extern void arm_heavy_mb(void); |
| 42 | #define __arm_heavy_mb(x...) do { dsb(x); arm_heavy_mb(); } while (0) |
| 43 | #else |
| 44 | #define __arm_heavy_mb(x...) dsb(x) |
| 45 | #endif |
| 46 | |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 47 | #ifdef CONFIG_ARCH_HAS_BARRIERS |
| 48 | #include <mach/barriers.h> |
| 49 | #elif defined(CONFIG_ARM_DMA_MEM_BUFFERABLE) || defined(CONFIG_SMP) |
Russell King | f813090 | 2015-06-01 23:44:46 +0100 | [diff] [blame] | 50 | #define mb() __arm_heavy_mb() |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 51 | #define rmb() dsb() |
Russell King | f813090 | 2015-06-01 23:44:46 +0100 | [diff] [blame] | 52 | #define wmb() __arm_heavy_mb(st) |
Alexander Duyck | 1077fa3 | 2014-12-11 15:02:06 -0800 | [diff] [blame] | 53 | #define dma_rmb() dmb(osh) |
| 54 | #define dma_wmb() dmb(oshst) |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 55 | #else |
Rob Herring | 48aa820f | 2012-08-21 12:26:24 +0200 | [diff] [blame] | 56 | #define mb() barrier() |
| 57 | #define rmb() barrier() |
| 58 | #define wmb() barrier() |
Alexander Duyck | 1077fa3 | 2014-12-11 15:02:06 -0800 | [diff] [blame] | 59 | #define dma_rmb() barrier() |
| 60 | #define dma_wmb() barrier() |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 61 | #endif |
| 62 | |
| 63 | #ifndef CONFIG_SMP |
| 64 | #define smp_mb() barrier() |
| 65 | #define smp_rmb() barrier() |
| 66 | #define smp_wmb() barrier() |
| 67 | #else |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 68 | #define smp_mb() dmb(ish) |
| 69 | #define smp_rmb() smp_mb() |
| 70 | #define smp_wmb() dmb(ishst) |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 71 | #endif |
| 72 | |
Peter Zijlstra | 47933ad | 2013-11-06 14:57:36 +0100 | [diff] [blame] | 73 | #define smp_store_release(p, v) \ |
| 74 | do { \ |
| 75 | compiletime_assert_atomic_type(*p); \ |
| 76 | smp_mb(); \ |
| 77 | ACCESS_ONCE(*p) = (v); \ |
| 78 | } while (0) |
| 79 | |
| 80 | #define smp_load_acquire(p) \ |
| 81 | ({ \ |
| 82 | typeof(*p) ___p1 = ACCESS_ONCE(*p); \ |
| 83 | compiletime_assert_atomic_type(*p); \ |
| 84 | smp_mb(); \ |
| 85 | ___p1; \ |
| 86 | }) |
| 87 | |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 88 | #define read_barrier_depends() do { } while(0) |
| 89 | #define smp_read_barrier_depends() do { } while(0) |
| 90 | |
Peter Zijlstra | b92b8b3 | 2015-05-12 10:51:55 +0200 | [diff] [blame] | 91 | #define smp_store_mb(var, value) do { WRITE_ONCE(var, value); smp_mb(); } while (0) |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 92 | |
Peter Zijlstra | 030d017 | 2014-03-12 17:11:00 +0100 | [diff] [blame] | 93 | #define smp_mb__before_atomic() smp_mb() |
| 94 | #define smp_mb__after_atomic() smp_mb() |
| 95 | |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 96 | #endif /* !__ASSEMBLY__ */ |
| 97 | #endif /* __ASM_BARRIER_H */ |