riscv_atomic.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 atomic_cmpxchg(atomic_t *atom, long oldval, long newval);
  24. long atomic_xchg(atomic_t *atom, long newval);
  25. unsigned int atomic_raw_xchg_uint(volatile unsigned int *ptr,
  26. unsigned int newval);
  27. unsigned long atomic_raw_xchg_ulong(volatile unsigned long *ptr,
  28. unsigned long newval);
  29. /**
  30. * Set a bit in an atomic variable and return the new value.
  31. * @nr : Bit to set.
  32. * @atom: atomic variable to modify
  33. */
  34. int atomic_set_bit(int nr, atomic_t *atom);
  35. /**
  36. * Clear a bit in an atomic variable and return the new value.
  37. * @nr : Bit to set.
  38. * @atom: atomic variable to modify
  39. */
  40. int atomic_clear_bit(int nr, atomic_t *atom);
  41. /**
  42. * Set a bit in any address and return the new value .
  43. * @nr : Bit to set.
  44. * @addr: Address to modify
  45. */
  46. int atomic_raw_set_bit(int nr, volatile unsigned long *addr);
  47. /**
  48. * Clear a bit in any address and return the new value .
  49. * @nr : Bit to set.
  50. * @addr: Address to modify
  51. */
  52. int atomic_raw_clear_bit(int nr, volatile unsigned long *addr);
  53. #endif