atomic.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_GENERIC_BITOPS_ATOMIC_H_
  3. #define _ASM_GENERIC_BITOPS_ATOMIC_H_
  4. #include <linux/atomic.h>
  5. #include <linux/compiler.h>
  6. #include <asm/barrier.h>
  7. /*
  8. * Implementation of atomic bitops using atomic-fetch ops.
  9. * See Documentation/atomic_bitops.txt for details.
  10. */
  11. static __always_inline void
  12. arch_set_bit(unsigned int nr, volatile unsigned long *p)
  13. {
  14. p += BIT_WORD(nr);
  15. arch_atomic_long_or(BIT_MASK(nr), (atomic_long_t *)p);
  16. }
  17. static __always_inline void
  18. arch_clear_bit(unsigned int nr, volatile unsigned long *p)
  19. {
  20. p += BIT_WORD(nr);
  21. arch_atomic_long_andnot(BIT_MASK(nr), (atomic_long_t *)p);
  22. }
  23. static __always_inline void
  24. arch_change_bit(unsigned int nr, volatile unsigned long *p)
  25. {
  26. p += BIT_WORD(nr);
  27. arch_atomic_long_xor(BIT_MASK(nr), (atomic_long_t *)p);
  28. }
  29. static __always_inline int
  30. arch_test_and_set_bit(unsigned int nr, volatile unsigned long *p)
  31. {
  32. long old;
  33. unsigned long mask = BIT_MASK(nr);
  34. p += BIT_WORD(nr);
  35. old = arch_atomic_long_fetch_or(mask, (atomic_long_t *)p);
  36. return !!(old & mask);
  37. }
  38. static __always_inline int
  39. arch_test_and_clear_bit(unsigned int nr, volatile unsigned long *p)
  40. {
  41. long old;
  42. unsigned long mask = BIT_MASK(nr);
  43. p += BIT_WORD(nr);
  44. old = arch_atomic_long_fetch_andnot(mask, (atomic_long_t *)p);
  45. return !!(old & mask);
  46. }
  47. static __always_inline int
  48. arch_test_and_change_bit(unsigned int nr, volatile unsigned long *p)
  49. {
  50. long old;
  51. unsigned long mask = BIT_MASK(nr);
  52. p += BIT_WORD(nr);
  53. old = arch_atomic_long_fetch_xor(mask, (atomic_long_t *)p);
  54. return !!(old & mask);
  55. }
  56. #include <asm-generic/bitops/instrumented-atomic.h>
  57. #endif /* _ASM_GENERIC_BITOPS_ATOMIC_H */