qdf_atomic.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Copyright (c) 2014-2020 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /**
  20. * DOC: qdf_atomic.h
  21. * This file provides OS abstraction for atomic APIs.
  22. */
  23. #ifndef _QDF_ATOMIC_H
  24. #define _QDF_ATOMIC_H
  25. #include <i_qdf_atomic.h>
  26. /**
  27. * typedef qdf_atomic_t - atomic type of variable
  28. *
  29. * Use this when you want a simple resource counter etc. which is atomic
  30. * across multiple CPU's. These maybe slower than usual counters on some
  31. * platforms/OS'es, so use them with caution.
  32. */
  33. typedef __qdf_atomic_t qdf_atomic_t;
  34. /**
  35. * qdf_atomic_init() - initialize an atomic type variable
  36. * @v: A pointer to an opaque atomic variable
  37. *
  38. * Return: None
  39. */
  40. static inline QDF_STATUS qdf_atomic_init(qdf_atomic_t *v)
  41. {
  42. return __qdf_atomic_init(v);
  43. }
  44. /**
  45. * qdf_atomic_read() - read the value of an atomic variable
  46. * @v: A pointer to an opaque atomic variable
  47. *
  48. * Return: The current value of the variable
  49. */
  50. static inline int32_t qdf_atomic_read(qdf_atomic_t *v)
  51. {
  52. return __qdf_atomic_read(v);
  53. }
  54. /**
  55. * qdf_atomic_inc() - increment the value of an atomic variable
  56. * @v: A pointer to an opaque atomic variable
  57. *
  58. * Return: None
  59. */
  60. static inline void qdf_atomic_inc(qdf_atomic_t *v)
  61. {
  62. __qdf_atomic_inc(v);
  63. }
  64. /**
  65. * qdf_atomic_dec() - decrement the value of an atomic variable
  66. * @v: A pointer to an opaque atomic variable
  67. *
  68. * Return: None
  69. */
  70. static inline void qdf_atomic_dec(qdf_atomic_t *v)
  71. {
  72. __qdf_atomic_dec(v);
  73. }
  74. /**
  75. * qdf_atomic_add() - add a value to the value of an atomic variable
  76. * @i: The amount by which to increase the atomic counter
  77. * @v: A pointer to an opaque atomic variable
  78. *
  79. * Return: None
  80. */
  81. static inline void qdf_atomic_add(int i, qdf_atomic_t *v)
  82. {
  83. __qdf_atomic_add(i, v);
  84. }
  85. /**
  86. * qdf_atomic_sub() - Subtract a value from an atomic variable
  87. * @i: the amount by which to decrease the atomic counter
  88. * @v: a pointer to an opaque atomic variable
  89. *
  90. * Return: none
  91. */
  92. static inline void qdf_atomic_sub(int i, qdf_atomic_t *v)
  93. {
  94. __qdf_atomic_sub(i, v);
  95. }
  96. /**
  97. * qdf_atomic_dec_and_test() - decrement an atomic variable and check if the
  98. * new value is zero
  99. * @v: A pointer to an opaque atomic variable
  100. *
  101. * Return:
  102. * true (non-zero) if the new value is zero,
  103. * false (0) if the new value is non-zero
  104. */
  105. static inline int32_t qdf_atomic_dec_and_test(qdf_atomic_t *v)
  106. {
  107. return __qdf_atomic_dec_and_test(v);
  108. }
  109. /**
  110. * qdf_atomic_set() - set a value to the value of an atomic variable
  111. * @v: A pointer to an opaque atomic variable
  112. * @i: required value to set
  113. *
  114. * Atomically sets the value of v to i
  115. * Return: None
  116. */
  117. static inline void qdf_atomic_set(qdf_atomic_t *v, int i)
  118. {
  119. __qdf_atomic_set(v, i);
  120. }
  121. /**
  122. * qdf_atomic_inc_return() - return the incremented value of an atomic variable
  123. * @v: A pointer to an opaque atomic variable
  124. *
  125. * Return: The current value of the variable
  126. */
  127. static inline int32_t qdf_atomic_inc_return(qdf_atomic_t *v)
  128. {
  129. return __qdf_atomic_inc_return(v);
  130. }
  131. /**
  132. * qdf_atomic_dec_return() - return the decremented value of an atomic
  133. * variable
  134. * @v: A pointer to an opaque atomic variable
  135. *
  136. * Return: The current value of the variable
  137. */
  138. static inline int32_t qdf_atomic_dec_return(qdf_atomic_t *v)
  139. {
  140. return __qdf_atomic_dec_return(v);
  141. }
  142. /**
  143. * qdf_atomic_dec_if_positive() - Decrement an atomic variable if its
  144. * value is positive
  145. * @v: A pointer to an opaque atomic variable
  146. *
  147. * Return: The old value of the variable minus 1
  148. */
  149. static inline int32_t qdf_atomic_dec_if_positive(qdf_atomic_t *v)
  150. {
  151. return __qdf_atomic_dec_if_positive(v);
  152. }
  153. /**
  154. * qdf_atomic_inc_not_zero() - increment if not zero
  155. * @v: A pointer to an opaque atomic variable
  156. *
  157. * Return: Returns non-zero on successful increment and zero otherwise
  158. */
  159. static inline int32_t qdf_atomic_inc_not_zero(qdf_atomic_t *v)
  160. {
  161. return __qdf_atomic_inc_not_zero(v);
  162. }
  163. /**
  164. * qdf_atomic_set_bit - Atomically set a bit in memory
  165. * @nr: bit to set
  166. * @addr: the address to start counting from
  167. *
  168. * Return: none
  169. */
  170. static inline void qdf_atomic_set_bit(int nr, volatile unsigned long *addr)
  171. {
  172. __qdf_atomic_set_bit(nr, addr);
  173. }
  174. /**
  175. * qdf_atomic_clear_bit - Atomically clear a bit in memory
  176. * @nr: bit to clear
  177. * @addr: the address to start counting from
  178. *
  179. * Return: none
  180. */
  181. static inline void qdf_atomic_clear_bit(int nr, volatile unsigned long *addr)
  182. {
  183. __qdf_atomic_clear_bit(nr, addr);
  184. }
  185. /**
  186. * qdf_atomic_change_bit - Atomically toggle a bit in memory
  187. * from addr
  188. * @nr: bit to change
  189. * @addr: the address to start counting from
  190. *
  191. * Return: none
  192. */
  193. static inline void qdf_atomic_change_bit(int nr, volatile unsigned long *addr)
  194. {
  195. __qdf_atomic_change_bit(nr, addr);
  196. }
  197. /**
  198. * qdf_atomic_test_and_set_bit - Atomically set a bit and return its old value
  199. * @nr: Bit to set
  200. * @addr: the address to start counting from
  201. *
  202. * Return: return nr bit old value
  203. */
  204. static inline int qdf_atomic_test_and_set_bit(int nr,
  205. volatile unsigned long *addr)
  206. {
  207. return __qdf_atomic_test_and_set_bit(nr, addr);
  208. }
  209. /**
  210. * qdf_atomic_test_and_clear_bit - Atomically clear a bit and return its old
  211. * value
  212. * @nr: bit to clear
  213. * @addr: the address to start counting from
  214. *
  215. * Return: return nr bit old value
  216. */
  217. static inline int qdf_atomic_test_and_clear_bit(int nr,
  218. volatile unsigned long *addr)
  219. {
  220. return __qdf_atomic_test_and_clear_bit(nr, addr);
  221. }
  222. /**
  223. * qdf_atomic_test_and_change_bit - Atomically toggle a bit and return its old
  224. * value
  225. * @nr: bit to change
  226. * @addr: the address to start counting from
  227. *
  228. * Return: return nr bit old value
  229. */
  230. static inline int qdf_atomic_test_and_change_bit(int nr,
  231. volatile unsigned long *addr)
  232. {
  233. return __qdf_atomic_test_and_change_bit(nr, addr);
  234. }
  235. /**
  236. * qdf_atomic_test_bit - Atomically get the nr-th bit value starting from addr
  237. * @nr: bit to get
  238. * @addr: the address to start counting from
  239. *
  240. * Return: return nr bit value
  241. */
  242. static inline int qdf_atomic_test_bit(int nr, volatile unsigned long *addr)
  243. {
  244. return __qdf_atomic_test_bit(nr, addr);
  245. }
  246. #endif