riscv_atomic.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #ifndef __RISCV_ATOMIC_H__
  10. #define __RISCV_ATOMIC_H__
  11. typedef struct {
  12. volatile long counter;
  13. } atomic_t;
  14. #define ATOMIC_INIT(_lptr, val) (_lptr)->counter = (val)
  15. #define ATOMIC_INITIALIZER(val) \
  16. { \
  17. .counter = (val), \
  18. }
  19. long atomic_read(atomic_t *atom);
  20. void atomic_write(atomic_t *atom, long value);
  21. long atomic_add_return(atomic_t *atom, long value);
  22. long atomic_sub_return(atomic_t *atom, long value);
  23. long arch_atomic_cmpxchg(atomic_t *atom, long oldval, long newval);
  24. long arch_atomic_xchg(atomic_t *atom, long newval);
  25. unsigned int atomic_raw_xchg_uint(volatile unsigned int *ptr,
  26. unsigned int newval);
  27. /**
  28. * Set a bit in an atomic variable and return the new value.
  29. * @nr : Bit to set.
  30. * @atom: atomic variable to modify
  31. */
  32. int atomic_set_bit(int nr, atomic_t *atom);
  33. /**
  34. * Clear a bit in an atomic variable and return the new value.
  35. * @nr : Bit to set.
  36. * @atom: atomic variable to modify
  37. */
  38. int atomic_clear_bit(int nr, atomic_t *atom);
  39. /**
  40. * Set a bit in any address and return the new value .
  41. * @nr : Bit to set.
  42. * @addr: Address to modify
  43. */
  44. int atomic_raw_set_bit(int nr, volatile unsigned long *addr);
  45. /**
  46. * Clear a bit in any address and return the new value .
  47. * @nr : Bit to set.
  48. * @addr: Address to modify
  49. */
  50. int atomic_raw_clear_bit(int nr, volatile unsigned long *addr);
  51. #endif