blob: 1402fa855388985282ff05e157b3388e85114d92 [file] [log] [blame]
Peter Zijlstra93ea02b2013-11-06 14:57:36 +01001/*
2 * Generic barrier definitions, originally based on MN10300 definitions.
David Howells885df912012-03-28 18:30:03 +01003 *
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
Peter Zijlstra93ea02b2013-11-06 14:57:36 +010020#include <linux/compiler.h>
21
22#ifndef nop
23#define nop() asm volatile ("nop")
24#endif
David Howells885df912012-03-28 18:30:03 +010025
26/*
Peter Zijlstra93ea02b2013-11-06 14:57:36 +010027 * Force strict CPU ordering. And yes, this is required on UP too when we're
28 * talking to devices.
David Howells885df912012-03-28 18:30:03 +010029 *
Peter Zijlstra93ea02b2013-11-06 14:57:36 +010030 * Fall back to compiler barriers if nothing better is provided.
David Howells885df912012-03-28 18:30:03 +010031 */
32
Peter Zijlstra93ea02b2013-11-06 14:57:36 +010033#ifndef mb
34#define mb() barrier()
35#endif
36
37#ifndef rmb
David Howells885df912012-03-28 18:30:03 +010038#define rmb() mb()
Peter Zijlstra93ea02b2013-11-06 14:57:36 +010039#endif
40
41#ifndef wmb
42#define wmb() mb()
43#endif
44
45#ifndef read_barrier_depends
46#define read_barrier_depends() do { } while (0)
47#endif
David Howells885df912012-03-28 18:30:03 +010048
49#ifdef CONFIG_SMP
50#define smp_mb() mb()
51#define smp_rmb() rmb()
52#define smp_wmb() wmb()
Peter Zijlstra93ea02b2013-11-06 14:57:36 +010053#define smp_read_barrier_depends() read_barrier_depends()
David Howells885df912012-03-28 18:30:03 +010054#else
55#define smp_mb() barrier()
56#define smp_rmb() barrier()
57#define smp_wmb() barrier()
Peter Zijlstra93ea02b2013-11-06 14:57:36 +010058#define smp_read_barrier_depends() do { } while (0)
David Howells885df912012-03-28 18:30:03 +010059#endif
60
Peter Zijlstra93ea02b2013-11-06 14:57:36 +010061#ifndef set_mb
62#define set_mb(var, value) do { (var) = (value); mb(); } while (0)
63#endif
David Howells885df912012-03-28 18:30:03 +010064
Peter Zijlstrafebdbfe2014-02-06 18:16:07 +010065#ifndef smp_mb__before_atomic
66#define smp_mb__before_atomic() smp_mb()
67#endif
68
69#ifndef smp_mb__after_atomic
70#define smp_mb__after_atomic() smp_mb()
71#endif
72
Peter Zijlstra47933ad2013-11-06 14:57:36 +010073#define smp_store_release(p, v) \
74do { \
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 Howells885df912012-03-28 18:30:03 +010088#endif /* !__ASSEMBLY__ */
89#endif /* __ASM_GENERIC_BARRIER_H */