linux/include/asm-generic/barrier.h
<<
>>
Prefs
   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 gmb
  46#define gmb()   do { } while (0)
  47#define barrier_nospec() gmb()
  48#endif
  49
  50#ifndef dma_rmb
  51#define dma_rmb()       rmb()
  52#endif
  53
  54#ifndef dma_wmb
  55#define dma_wmb()       wmb()
  56#endif
  57
  58#ifndef read_barrier_depends
  59#define read_barrier_depends()          do { } while (0)
  60#endif
  61
  62#ifdef CONFIG_SMP
  63
  64#ifndef smp_mb
  65#define smp_mb()        mb()
  66#endif
  67
  68#ifndef smp_rmb
  69#define smp_rmb()       rmb()
  70#endif
  71
  72#ifndef smp_wmb
  73#define smp_wmb()       wmb()
  74#endif
  75
  76#ifndef smp_read_barrier_depends
  77#define smp_read_barrier_depends()      read_barrier_depends()
  78#endif
  79
  80#else
  81#ifndef smp_mb
  82#define smp_mb()        barrier()
  83#endif
  84
  85#ifndef smp_rmb
  86#define smp_rmb()       barrier()
  87#endif
  88
  89#ifndef smp_wmb
  90#define smp_wmb()       barrier()
  91#endif
  92
  93#ifndef smp_read_barrier_depends
  94#define smp_read_barrier_depends()      do { } while (0)
  95#endif
  96
  97#endif
  98
  99#ifndef set_mb
 100#define set_mb(var, value)  do { (var) = (value); mb(); } while (0)
 101#endif
 102
 103#ifndef smp_mb__before_atomic
 104#define smp_mb__before_atomic() smp_mb()
 105#endif
 106
 107#ifndef smp_mb__after_atomic
 108#define smp_mb__after_atomic()  smp_mb()
 109#endif
 110
 111#ifndef smp_store_release
 112#define smp_store_release(p, v)                                         \
 113do {                                                                    \
 114        compiletime_assert_atomic_type(*p);                             \
 115        smp_mb();                                                       \
 116        ACCESS_ONCE(*p) = (v);                                          \
 117} while (0)
 118#endif
 119
 120#ifndef smp_load_acquire
 121#define smp_load_acquire(p)                                             \
 122({                                                                      \
 123        typeof(*p) ___p1 = ACCESS_ONCE(*p);                             \
 124        compiletime_assert_atomic_type(*p);                             \
 125        smp_mb();                                                       \
 126        ___p1;                                                          \
 127})
 128#endif
 129
 130#endif /* !__ASSEMBLY__ */
 131#endif /* __ASM_GENERIC_BARRIER_H */
 132