atomic_ext.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <asm/barrier.h>
  3. #include <asm/rwonce.h>
  4. #include <linux/atomic.h>
  5. __rust_helper s8 rust_helper_atomic_i8_read(s8 *ptr)
  6. {
  7. return READ_ONCE(*ptr);
  8. }
  9. __rust_helper s8 rust_helper_atomic_i8_read_acquire(s8 *ptr)
  10. {
  11. return smp_load_acquire(ptr);
  12. }
  13. __rust_helper s16 rust_helper_atomic_i16_read(s16 *ptr)
  14. {
  15. return READ_ONCE(*ptr);
  16. }
  17. __rust_helper s16 rust_helper_atomic_i16_read_acquire(s16 *ptr)
  18. {
  19. return smp_load_acquire(ptr);
  20. }
  21. __rust_helper void rust_helper_atomic_i8_set(s8 *ptr, s8 val)
  22. {
  23. WRITE_ONCE(*ptr, val);
  24. }
  25. __rust_helper void rust_helper_atomic_i8_set_release(s8 *ptr, s8 val)
  26. {
  27. smp_store_release(ptr, val);
  28. }
  29. __rust_helper void rust_helper_atomic_i16_set(s16 *ptr, s16 val)
  30. {
  31. WRITE_ONCE(*ptr, val);
  32. }
  33. __rust_helper void rust_helper_atomic_i16_set_release(s16 *ptr, s16 val)
  34. {
  35. smp_store_release(ptr, val);
  36. }
  37. /*
  38. * xchg helpers depend on ARCH_SUPPORTS_ATOMIC_RMW and on the
  39. * architecture provding xchg() support for i8 and i16.
  40. *
  41. * The architectures that currently support Rust (x86_64, armv7,
  42. * arm64, riscv, and loongarch) satisfy these requirements.
  43. */
  44. __rust_helper s8 rust_helper_atomic_i8_xchg(s8 *ptr, s8 new)
  45. {
  46. return xchg(ptr, new);
  47. }
  48. __rust_helper s16 rust_helper_atomic_i16_xchg(s16 *ptr, s16 new)
  49. {
  50. return xchg(ptr, new);
  51. }
  52. __rust_helper s8 rust_helper_atomic_i8_xchg_acquire(s8 *ptr, s8 new)
  53. {
  54. return xchg_acquire(ptr, new);
  55. }
  56. __rust_helper s16 rust_helper_atomic_i16_xchg_acquire(s16 *ptr, s16 new)
  57. {
  58. return xchg_acquire(ptr, new);
  59. }
  60. __rust_helper s8 rust_helper_atomic_i8_xchg_release(s8 *ptr, s8 new)
  61. {
  62. return xchg_release(ptr, new);
  63. }
  64. __rust_helper s16 rust_helper_atomic_i16_xchg_release(s16 *ptr, s16 new)
  65. {
  66. return xchg_release(ptr, new);
  67. }
  68. __rust_helper s8 rust_helper_atomic_i8_xchg_relaxed(s8 *ptr, s8 new)
  69. {
  70. return xchg_relaxed(ptr, new);
  71. }
  72. __rust_helper s16 rust_helper_atomic_i16_xchg_relaxed(s16 *ptr, s16 new)
  73. {
  74. return xchg_relaxed(ptr, new);
  75. }
  76. /*
  77. * try_cmpxchg helpers depend on ARCH_SUPPORTS_ATOMIC_RMW and on the
  78. * architecture provding try_cmpxchg() support for i8 and i16.
  79. *
  80. * The architectures that currently support Rust (x86_64, armv7,
  81. * arm64, riscv, and loongarch) satisfy these requirements.
  82. */
  83. __rust_helper bool rust_helper_atomic_i8_try_cmpxchg(s8 *ptr, s8 *old, s8 new)
  84. {
  85. return try_cmpxchg(ptr, old, new);
  86. }
  87. __rust_helper bool rust_helper_atomic_i16_try_cmpxchg(s16 *ptr, s16 *old, s16 new)
  88. {
  89. return try_cmpxchg(ptr, old, new);
  90. }
  91. __rust_helper bool rust_helper_atomic_i8_try_cmpxchg_acquire(s8 *ptr, s8 *old, s8 new)
  92. {
  93. return try_cmpxchg_acquire(ptr, old, new);
  94. }
  95. __rust_helper bool rust_helper_atomic_i16_try_cmpxchg_acquire(s16 *ptr, s16 *old, s16 new)
  96. {
  97. return try_cmpxchg_acquire(ptr, old, new);
  98. }
  99. __rust_helper bool rust_helper_atomic_i8_try_cmpxchg_release(s8 *ptr, s8 *old, s8 new)
  100. {
  101. return try_cmpxchg_release(ptr, old, new);
  102. }
  103. __rust_helper bool rust_helper_atomic_i16_try_cmpxchg_release(s16 *ptr, s16 *old, s16 new)
  104. {
  105. return try_cmpxchg_release(ptr, old, new);
  106. }
  107. __rust_helper bool rust_helper_atomic_i8_try_cmpxchg_relaxed(s8 *ptr, s8 *old, s8 new)
  108. {
  109. return try_cmpxchg_relaxed(ptr, old, new);
  110. }
  111. __rust_helper bool rust_helper_atomic_i16_try_cmpxchg_relaxed(s16 *ptr, s16 *old, s16 new)
  112. {
  113. return try_cmpxchg_relaxed(ptr, old, new);
  114. }