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 | |
Masahiro Yamada | 520319d | 2016-06-21 02:32:25 +0100 | [diff] [blame] | 47 | #if defined(CONFIG_ARM_DMA_MEM_BUFFERABLE) || defined(CONFIG_SMP) |
Russell King | f813090 | 2015-06-01 23:44:46 +0100 | [diff] [blame] | 48 | #define mb() __arm_heavy_mb() |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 49 | #define rmb() dsb() |
Russell King | f813090 | 2015-06-01 23:44:46 +0100 | [diff] [blame] | 50 | #define wmb() __arm_heavy_mb(st) |
Alexander Duyck | 1077fa3 | 2014-12-11 15:02:06 -0800 | [diff] [blame] | 51 | #define dma_rmb() dmb(osh) |
| 52 | #define dma_wmb() dmb(oshst) |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 53 | #else |
Rob Herring | 48aa820f | 2012-08-21 12:26:24 +0200 | [diff] [blame] | 54 | #define mb() barrier() |
| 55 | #define rmb() barrier() |
| 56 | #define wmb() barrier() |
Alexander Duyck | 1077fa3 | 2014-12-11 15:02:06 -0800 | [diff] [blame] | 57 | #define dma_rmb() barrier() |
| 58 | #define dma_wmb() barrier() |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 59 | #endif |
| 60 | |
Michael S. Tsirkin | 2b1f3de | 2015-12-27 15:04:42 +0200 | [diff] [blame] | 61 | #define __smp_mb() dmb(ish) |
| 62 | #define __smp_rmb() __smp_mb() |
| 63 | #define __smp_wmb() dmb(ishst) |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 64 | |
Michael S. Tsirkin | 335390d | 2015-12-21 09:22:18 +0200 | [diff] [blame] | 65 | #include <asm-generic/barrier.h> |
Peter Zijlstra | 030d017 | 2014-03-12 17:11:00 +0100 | [diff] [blame] | 66 | |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 67 | #endif /* !__ASSEMBLY__ */ |
| 68 | #endif /* __ASM_BARRIER_H */ |