qdf_lock.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. /**
  27. * @file qdf_lock.h
  28. * This file abstracts locking operations.
  29. */
  30. #ifndef _QDF_LOCK_H
  31. #define _QDF_LOCK_H
  32. #include <qdf_types.h>
  33. #include <i_qdf_lock.h>
  34. #define WIFI_POWER_EVENT_DEFAULT_WAKELOCK_TIMEOUT 0
  35. #define WIFI_POWER_EVENT_WAKELOCK_TAKEN 0
  36. #define WIFI_POWER_EVENT_WAKELOCK_RELEASED 1
  37. /**
  38. * qdf_semaphore_acquire_timeout() - Take the semaphore before timeout
  39. * @m: semaphore to take
  40. * @timeout: maximum time to try to take the semaphore
  41. * Return: int
  42. */
  43. static inline int qdf_semaphore_acquire_timeout(struct semaphore *m,
  44. unsigned long timeout)
  45. {
  46. return __qdf_semaphore_acquire_timeout(m, timeout);
  47. }
  48. /**
  49. * @brief Platform spinlock object
  50. */
  51. typedef __qdf_spinlock_t qdf_spinlock_t;
  52. /**
  53. * @brief Platform mutex object
  54. */
  55. typedef __qdf_semaphore_t qdf_semaphore_t;
  56. typedef __qdf_mutex_t qdf_mutex_t;
  57. /* function Declaration */
  58. QDF_STATUS qdf_mutex_create(qdf_mutex_t *m);
  59. QDF_STATUS qdf_mutex_acquire(qdf_mutex_t *m);
  60. QDF_STATUS qdf_mutex_release(qdf_mutex_t *m);
  61. QDF_STATUS qdf_mutex_destroy(qdf_mutex_t *lock);
  62. /**
  63. * qdf_spinlock_create - Initialize a spinlock
  64. * @lock: spinlock object pointer
  65. * Retrun: none
  66. */
  67. static inline void qdf_spinlock_create(qdf_spinlock_t *lock)
  68. {
  69. __qdf_spinlock_create(lock);
  70. }
  71. /**
  72. * qdf_spinlock_destroy - Delete a spinlock
  73. * @lock: spinlock object pointer
  74. * Return: none
  75. */
  76. static inline void qdf_spinlock_destroy(qdf_spinlock_t *lock)
  77. {
  78. __qdf_spinlock_destroy(lock);
  79. }
  80. /**
  81. * qdf_spin_trylock_bh() - spin trylock bottomhalf
  82. * @lock: spinlock object
  83. * Return: int
  84. */
  85. static inline int qdf_spin_trylock_bh(qdf_spinlock_t *lock)
  86. {
  87. return __qdf_spin_trylock_bh(lock);
  88. }
  89. int qdf_spin_trylock_bh_outline(qdf_spinlock_t *lock);
  90. /**
  91. * qdf_spin_lock_bh() - locks the spinlock mutex in soft irq context
  92. * @lock: spinlock object pointer
  93. * Return: none
  94. */
  95. static inline void qdf_spin_lock_bh(qdf_spinlock_t *lock)
  96. {
  97. __qdf_spin_lock_bh(lock);
  98. }
  99. void qdf_spin_lock_bh_outline(qdf_spinlock_t *lock);
  100. /**
  101. * qdf_spin_unlock_bh() - unlocks the spinlock mutex in soft irq context
  102. * @lock: spinlock object pointer
  103. * Return: none
  104. */
  105. static inline void qdf_spin_unlock_bh(qdf_spinlock_t *lock)
  106. {
  107. __qdf_spin_unlock_bh(lock);
  108. }
  109. void qdf_spin_unlock_bh_outline(qdf_spinlock_t *lock);
  110. /**
  111. * qdf_spinlock_irq_exec - Execute the input function with spinlock held
  112. * and interrupt disabled.
  113. * @hdl: OS handle
  114. * @lock: spinlock to be held for the critical region
  115. * @func: critical region function that to be executed
  116. * @context: context of the critical region function
  117. * Return: Boolean status returned by the critical region function
  118. */
  119. static inline bool qdf_spinlock_irq_exec(qdf_handle_t hdl,
  120. qdf_spinlock_t *lock,
  121. qdf_irqlocked_func_t func, void *arg)
  122. {
  123. return __qdf_spinlock_irq_exec(hdl, lock, func, arg);
  124. }
  125. /**
  126. * qdf_spin_lock() - Acquire a Spinlock(SMP) & disable Preemption (Preemptive)
  127. * @lock: Lock object
  128. *
  129. * Return: none
  130. */
  131. static inline void qdf_spin_lock(qdf_spinlock_t *lock)
  132. {
  133. __qdf_spin_lock(lock);
  134. }
  135. /**
  136. * qdf_spin_unlock() - Unlock the spinlock and enables the Preemption
  137. * @lock: Lock object
  138. *
  139. * Return: none
  140. */
  141. static inline void qdf_spin_unlock(qdf_spinlock_t *lock)
  142. {
  143. __qdf_spin_unlock(lock);
  144. }
  145. /**
  146. * qdf_spin_lock_irq() - Acquire a Spinlock(SMP) & save the irq state
  147. * @lock: Lock object
  148. * @flags: flags
  149. *
  150. * Return: none
  151. */
  152. static inline void qdf_spin_lock_irq(qdf_spinlock_t *lock, unsigned long flags)
  153. {
  154. __qdf_spin_lock_irq(&lock->spinlock, flags);
  155. }
  156. /**
  157. * qdf_spin_lock_irqsave() - Acquire a Spinlock (SMP) & disable Preemption
  158. * (Preemptive) and disable IRQs
  159. * @lock: Lock object
  160. *
  161. * Return: none
  162. */
  163. static inline void qdf_spin_lock_irqsave(qdf_spinlock_t *lock)
  164. {
  165. __qdf_spin_lock_irqsave(lock);
  166. }
  167. /**
  168. * qdf_spin_unlock_irqrestore() - Unlock the spinlock and enables the
  169. * Preemption and enable IRQ
  170. * @lock: Lock object
  171. *
  172. * Return: none
  173. */
  174. static inline void qdf_spin_unlock_irqrestore(qdf_spinlock_t *lock)
  175. {
  176. __qdf_spin_unlock_irqrestore(lock);
  177. }
  178. /**
  179. * qdf_spin_unlock_irq() - Unlock a Spinlock(SMP) & save the restore state
  180. * @lock: Lock object
  181. * @flags: flags
  182. *
  183. * Return: none
  184. */
  185. static inline void qdf_spin_unlock_irq(qdf_spinlock_t *lock,
  186. unsigned long flags)
  187. {
  188. __qdf_spin_unlock_irq(&lock->spinlock, flags);
  189. }
  190. /**
  191. * qdf_semaphore_init() - initialize a semaphore
  192. * @m: Semaphore to initialize
  193. * Return: None
  194. */
  195. static inline void qdf_semaphore_init(qdf_semaphore_t *m)
  196. {
  197. __qdf_semaphore_init(m);
  198. }
  199. /**
  200. * qdf_semaphore_acquire() - take the semaphore
  201. * @m: Semaphore to take
  202. * Return: int
  203. */
  204. static inline int qdf_semaphore_acquire(qdf_semaphore_t *m)
  205. {
  206. return __qdf_semaphore_acquire(m);
  207. }
  208. /**
  209. * qdf_semaphore_release() - give the semaphore
  210. * @m: Semaphore to give
  211. * Return: None
  212. */
  213. static inline void qdf_semaphore_release(qdf_semaphore_t *m)
  214. {
  215. __qdf_semaphore_release(m);
  216. }
  217. /**
  218. * qdf_semaphore_acquire_intr - Take the semaphore, interruptible version
  219. * @osdev: OS Device
  220. * @m: mutex to take
  221. * Return: int
  222. */
  223. static inline int qdf_semaphore_acquire_intr(qdf_semaphore_t *m)
  224. {
  225. return __qdf_semaphore_acquire_intr(m);
  226. }
  227. QDF_STATUS qdf_wake_lock_create(qdf_wake_lock_t *lock, const char *name);
  228. QDF_STATUS qdf_wake_lock_acquire(qdf_wake_lock_t *lock, uint32_t reason);
  229. const char *qdf_wake_lock_name(qdf_wake_lock_t *lock);
  230. QDF_STATUS qdf_wake_lock_timeout_acquire(qdf_wake_lock_t *lock,
  231. uint32_t msec);
  232. QDF_STATUS qdf_wake_lock_release(qdf_wake_lock_t *lock, uint32_t reason);
  233. QDF_STATUS qdf_wake_lock_destroy(qdf_wake_lock_t *lock);
  234. struct hif_pm_runtime_lock;
  235. typedef struct hif_pm_runtime_lock *qdf_runtime_lock_t;
  236. QDF_STATUS qdf_runtime_pm_get(void);
  237. QDF_STATUS qdf_runtime_pm_put(void);
  238. QDF_STATUS qdf_runtime_pm_prevent_suspend(qdf_runtime_lock_t lock);
  239. QDF_STATUS qdf_runtime_pm_allow_suspend(qdf_runtime_lock_t lock);
  240. qdf_runtime_lock_t qdf_runtime_lock_init(const char *name);
  241. void qdf_runtime_lock_deinit(qdf_runtime_lock_t lock);
  242. QDF_STATUS qdf_spinlock_acquire(qdf_spinlock_t *lock);
  243. QDF_STATUS qdf_spinlock_release(qdf_spinlock_t *lock);
  244. #endif /* _QDF_LOCK_H */