atomic.h 844 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_ATOMIC_H
  3. #define __ASM_SH_ATOMIC_H
  4. #if defined(CONFIG_CPU_J2)
  5. #include <asm-generic/atomic.h>
  6. #else
  7. /*
  8. * Atomic operations that C can't guarantee us. Useful for
  9. * resource counting etc..
  10. *
  11. */
  12. #include <linux/compiler.h>
  13. #include <linux/types.h>
  14. #include <asm/cmpxchg.h>
  15. #include <asm/barrier.h>
  16. #define ATOMIC_INIT(i) { (i) }
  17. #define atomic_read(v) READ_ONCE((v)->counter)
  18. #define atomic_set(v,i) WRITE_ONCE((v)->counter, (i))
  19. #if defined(CONFIG_GUSA_RB)
  20. #include <asm/atomic-grb.h>
  21. #elif defined(CONFIG_CPU_SH4A)
  22. #include <asm/atomic-llsc.h>
  23. #else
  24. #include <asm/atomic-irq.h>
  25. #endif
  26. #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
  27. #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
  28. #endif /* CONFIG_CPU_J2 */
  29. #endif /* __ASM_SH_ATOMIC_H */