qdf_atomic.h 5.7 KB

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