1 /* 2 * Generic barrier definitions, originally based on MN10300 definitions. 3 * 4 * It should be possible to use these on really simple architectures, 5 * but it serves more as a starting point for new ports. 6 * 7 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 8 * Written by David Howells (dhowells@redhat.com) 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public Licence 12 * as published by the Free Software Foundation; either version 13 * 2 of the Licence, or (at your option) any later version. 14 */ 15 #ifndef __ASM_GENERIC_BARRIER_H 16 #define __ASM_GENERIC_BARRIER_H 17 18 #ifndef __ASSEMBLY__ 19 20 #include <linux/compiler.h> 21 22 #ifndef nop 23 #define nop() asm volatile ("nop") 24 #endif 25 26 /* 27 * Force strict CPU ordering. And yes, this is required on UP too when we're 28 * talking to devices. 29 * 30 * Fall back to compiler barriers if nothing better is provided. 31 */ 32 33 #ifndef mb 34 #define mb() barrier() 35 #endif 36 37 #ifndef rmb 38 #define rmb() mb() 39 #endif 40 41 #ifndef wmb 42 #define wmb() mb() 43 #endif 44 45 #ifndef dma_rmb 46 #define dma_rmb() rmb() 47 #endif 48 49 #ifndef dma_wmb 50 #define dma_wmb() wmb() 51 #endif 52 53 #ifndef read_barrier_depends 54 #define read_barrier_depends() do { } while (0) 55 #endif 56 57 #ifdef CONFIG_SMP 58 #define smp_mb() mb() 59 #define smp_rmb() rmb() 60 #define smp_wmb() wmb() 61 #define smp_read_barrier_depends() read_barrier_depends() 62 #else 63 #define smp_mb() barrier() 64 #define smp_rmb() barrier() 65 #define smp_wmb() barrier() 66 #define smp_read_barrier_depends() do { } while (0) 67 #endif 68 69 #ifndef set_mb 70 #define set_mb(var, value) do { (var) = (value); mb(); } while (0) 71 #endif 72 73 #ifndef smp_mb__before_atomic 74 #define smp_mb__before_atomic() smp_mb() 75 #endif 76 77 #ifndef smp_mb__after_atomic 78 #define smp_mb__after_atomic() smp_mb() 79 #endif 80 81 #define smp_store_release(p, v) \ 82 do { \ 83 compiletime_assert_atomic_type(*p); \ 84 smp_mb(); \ 85 ACCESS_ONCE(*p) = (v); \ 86 } while (0) 87 88 #define smp_load_acquire(p) \ 89 ({ \ 90 typeof(*p) ___p1 = ACCESS_ONCE(*p); \ 91 compiletime_assert_atomic_type(*p); \ 92 smp_mb(); \ 93 ___p1; \ 94 }) 95 96 #endif /* !__ASSEMBLY__ */ 97 #endif /* __ASM_GENERIC_BARRIER_H */ 98