mm: make wait_on_page_writeback() wait for multiple pending writebacks
[linux/fpc-iii.git] / include / asm-generic / barrier.h
blob640f09479bdf7984799d7ecdf40d7da17d83e26c
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Generic barrier definitions.
5 * It should be possible to use these on really simple architectures,
6 * but it serves more as a starting point for new ports.
8 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
9 * Written by David Howells (dhowells@redhat.com)
11 #ifndef __ASM_GENERIC_BARRIER_H
12 #define __ASM_GENERIC_BARRIER_H
14 #ifndef __ASSEMBLY__
16 #include <linux/compiler.h>
17 #include <asm/rwonce.h>
19 #ifndef nop
20 #define nop() asm volatile ("nop")
21 #endif
24 * Force strict CPU ordering. And yes, this is required on UP too when we're
25 * talking to devices.
27 * Fall back to compiler barriers if nothing better is provided.
30 #ifndef mb
31 #define mb() barrier()
32 #endif
34 #ifndef rmb
35 #define rmb() mb()
36 #endif
38 #ifndef wmb
39 #define wmb() mb()
40 #endif
42 #ifndef dma_rmb
43 #define dma_rmb() rmb()
44 #endif
46 #ifndef dma_wmb
47 #define dma_wmb() wmb()
48 #endif
50 #ifndef __smp_mb
51 #define __smp_mb() mb()
52 #endif
54 #ifndef __smp_rmb
55 #define __smp_rmb() rmb()
56 #endif
58 #ifndef __smp_wmb
59 #define __smp_wmb() wmb()
60 #endif
62 #ifdef CONFIG_SMP
64 #ifndef smp_mb
65 #define smp_mb() __smp_mb()
66 #endif
68 #ifndef smp_rmb
69 #define smp_rmb() __smp_rmb()
70 #endif
72 #ifndef smp_wmb
73 #define smp_wmb() __smp_wmb()
74 #endif
76 #else /* !CONFIG_SMP */
78 #ifndef smp_mb
79 #define smp_mb() barrier()
80 #endif
82 #ifndef smp_rmb
83 #define smp_rmb() barrier()
84 #endif
86 #ifndef smp_wmb
87 #define smp_wmb() barrier()
88 #endif
90 #endif /* CONFIG_SMP */
92 #ifndef __smp_store_mb
93 #define __smp_store_mb(var, value) do { WRITE_ONCE(var, value); __smp_mb(); } while (0)
94 #endif
96 #ifndef __smp_mb__before_atomic
97 #define __smp_mb__before_atomic() __smp_mb()
98 #endif
100 #ifndef __smp_mb__after_atomic
101 #define __smp_mb__after_atomic() __smp_mb()
102 #endif
104 #ifndef __smp_store_release
105 #define __smp_store_release(p, v) \
106 do { \
107 compiletime_assert_atomic_type(*p); \
108 __smp_mb(); \
109 WRITE_ONCE(*p, v); \
110 } while (0)
111 #endif
113 #ifndef __smp_load_acquire
114 #define __smp_load_acquire(p) \
115 ({ \
116 __unqual_scalar_typeof(*p) ___p1 = READ_ONCE(*p); \
117 compiletime_assert_atomic_type(*p); \
118 __smp_mb(); \
119 (typeof(*p))___p1; \
121 #endif
123 #ifdef CONFIG_SMP
125 #ifndef smp_store_mb
126 #define smp_store_mb(var, value) __smp_store_mb(var, value)
127 #endif
129 #ifndef smp_mb__before_atomic
130 #define smp_mb__before_atomic() __smp_mb__before_atomic()
131 #endif
133 #ifndef smp_mb__after_atomic
134 #define smp_mb__after_atomic() __smp_mb__after_atomic()
135 #endif
137 #ifndef smp_store_release
138 #define smp_store_release(p, v) __smp_store_release(p, v)
139 #endif
141 #ifndef smp_load_acquire
142 #define smp_load_acquire(p) __smp_load_acquire(p)
143 #endif
145 #else /* !CONFIG_SMP */
147 #ifndef smp_store_mb
148 #define smp_store_mb(var, value) do { WRITE_ONCE(var, value); barrier(); } while (0)
149 #endif
151 #ifndef smp_mb__before_atomic
152 #define smp_mb__before_atomic() barrier()
153 #endif
155 #ifndef smp_mb__after_atomic
156 #define smp_mb__after_atomic() barrier()
157 #endif
159 #ifndef smp_store_release
160 #define smp_store_release(p, v) \
161 do { \
162 compiletime_assert_atomic_type(*p); \
163 barrier(); \
164 WRITE_ONCE(*p, v); \
165 } while (0)
166 #endif
168 #ifndef smp_load_acquire
169 #define smp_load_acquire(p) \
170 ({ \
171 __unqual_scalar_typeof(*p) ___p1 = READ_ONCE(*p); \
172 compiletime_assert_atomic_type(*p); \
173 barrier(); \
174 (typeof(*p))___p1; \
176 #endif
178 #endif /* CONFIG_SMP */
180 /* Barriers for virtual machine guests when talking to an SMP host */
181 #define virt_mb() __smp_mb()
182 #define virt_rmb() __smp_rmb()
183 #define virt_wmb() __smp_wmb()
184 #define virt_store_mb(var, value) __smp_store_mb(var, value)
185 #define virt_mb__before_atomic() __smp_mb__before_atomic()
186 #define virt_mb__after_atomic() __smp_mb__after_atomic()
187 #define virt_store_release(p, v) __smp_store_release(p, v)
188 #define virt_load_acquire(p) __smp_load_acquire(p)
191 * smp_acquire__after_ctrl_dep() - Provide ACQUIRE ordering after a control dependency
193 * A control dependency provides a LOAD->STORE order, the additional RMB
194 * provides LOAD->LOAD order, together they provide LOAD->{LOAD,STORE} order,
195 * aka. (load)-ACQUIRE.
197 * Architectures that do not do load speculation can have this be barrier().
199 #ifndef smp_acquire__after_ctrl_dep
200 #define smp_acquire__after_ctrl_dep() smp_rmb()
201 #endif
204 * smp_cond_load_relaxed() - (Spin) wait for cond with no ordering guarantees
205 * @ptr: pointer to the variable to wait on
206 * @cond: boolean expression to wait for
208 * Equivalent to using READ_ONCE() on the condition variable.
210 * Due to C lacking lambda expressions we load the value of *ptr into a
211 * pre-named variable @VAL to be used in @cond.
213 #ifndef smp_cond_load_relaxed
214 #define smp_cond_load_relaxed(ptr, cond_expr) ({ \
215 typeof(ptr) __PTR = (ptr); \
216 __unqual_scalar_typeof(*ptr) VAL; \
217 for (;;) { \
218 VAL = READ_ONCE(*__PTR); \
219 if (cond_expr) \
220 break; \
221 cpu_relax(); \
223 (typeof(*ptr))VAL; \
225 #endif
228 * smp_cond_load_acquire() - (Spin) wait for cond with ACQUIRE ordering
229 * @ptr: pointer to the variable to wait on
230 * @cond: boolean expression to wait for
232 * Equivalent to using smp_load_acquire() on the condition variable but employs
233 * the control dependency of the wait to reduce the barrier on many platforms.
235 #ifndef smp_cond_load_acquire
236 #define smp_cond_load_acquire(ptr, cond_expr) ({ \
237 __unqual_scalar_typeof(*ptr) _val; \
238 _val = smp_cond_load_relaxed(ptr, cond_expr); \
239 smp_acquire__after_ctrl_dep(); \
240 (typeof(*ptr))_val; \
242 #endif
245 * pmem_wmb() ensures that all stores for which the modification
246 * are written to persistent storage by preceding instructions have
247 * updated persistent storage before any data access or data transfer
248 * caused by subsequent instructions is initiated.
250 #ifndef pmem_wmb
251 #define pmem_wmb() wmb()
252 #endif
254 #endif /* !__ASSEMBLY__ */
255 #endif /* __ASM_GENERIC_BARRIER_H */