qdf_lock.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. #if !defined(__CDF_LOCK_H)
  27. #define __CDF_LOCK_H
  28. /**
  29. *
  30. * @file cdf_lock.h
  31. *
  32. * @brief Connectivity driver framework (CDF) lock APIs
  33. *
  34. * Definitions for CDF locks
  35. *
  36. */
  37. /* Include Files */
  38. #include "cdf_status.h"
  39. #include "i_cdf_lock.h"
  40. /* Preprocessor definitions and constants */
  41. /* Type declarations */
  42. /**
  43. * @brief Platform spinlock object
  44. */
  45. typedef __cdf_spinlock_t cdf_spinlock_t;
  46. /**
  47. * @brief Platform mutex object
  48. */
  49. typedef __cdf_semaphore_t cdf_semaphore_t;
  50. /* Function declarations and documenation */
  51. /**
  52. * cdf_semaphore_init() - initialize a semaphore
  53. * @m: Semaphore to initialize
  54. *
  55. * Return: None
  56. */
  57. static inline void cdf_semaphore_init(cdf_semaphore_t *m)
  58. {
  59. __cdf_semaphore_init(m);
  60. }
  61. /**
  62. * cdf_semaphore_acquire() - take the semaphore
  63. * @m: Semaphore to take
  64. *
  65. * Return: None
  66. */
  67. static inline int cdf_semaphore_acquire(cdf_device_t osdev, cdf_semaphore_t *m)
  68. {
  69. return __cdf_semaphore_acquire(osdev, m);
  70. }
  71. /**
  72. * cdf_semaphore_release () - give the semaphore
  73. * @m: Semaphore to give
  74. *
  75. * Return: None
  76. */
  77. static inline void
  78. cdf_semaphore_release(cdf_device_t osdev, cdf_semaphore_t *m)
  79. {
  80. __cdf_semaphore_release(osdev, m);
  81. }
  82. /**
  83. * cdf_mutex_init() - initialize a CDF lock
  84. * @lock: Pointer to the opaque lock object to initialize
  85. *
  86. * cdf_mutex_init() function initializes the specified lock. Upon
  87. * successful initialization, the state of the lock becomes initialized
  88. * and unlocked.
  89. *
  90. * A lock must be initialized by calling cdf_mutex_init() before it
  91. * may be used in any other lock functions.
  92. *
  93. * Attempting to initialize an already initialized lock results in
  94. * a failure.
  95. *
  96. * Return:
  97. * CDF_STATUS_SUCCESS: lock was successfully initialized
  98. * CDF failure reason codes: lock is not initialized and can't be used
  99. */
  100. CDF_STATUS cdf_mutex_init(cdf_mutex_t *lock);
  101. /**
  102. * cdf_mutex_acquire () - acquire a CDF lock
  103. * @lock: Pointer to the opaque lock object to acquire
  104. *
  105. * A lock object is acquired by calling cdf_mutex_acquire(). If the lock
  106. * is already locked, the calling thread shall block until the lock becomes
  107. * available. This operation shall return with the lock object referenced by
  108. * lock in the locked state with the calling thread as its owner.
  109. *
  110. * Return:
  111. * CDF_STATUS_SUCCESS: lock was successfully initialized
  112. * CDF failure reason codes: lock is not initialized and can't be used
  113. */
  114. CDF_STATUS cdf_mutex_acquire(cdf_mutex_t *lock);
  115. /**
  116. * cdf_mutex_release() - release a CDF lock
  117. * @lock: Pointer to the opaque lock object to be released
  118. *
  119. * cdf_mutex_release() function shall release the lock object
  120. * referenced by 'lock'.
  121. *
  122. * If a thread attempts to release a lock that it unlocked or is not
  123. * initialized, an error is returned.
  124. *
  125. * Return:
  126. * CDF_STATUS_SUCCESS: lock was successfully initialized
  127. * CDF failure reason codes: lock is not initialized and can't be used
  128. */
  129. CDF_STATUS cdf_mutex_release(cdf_mutex_t *lock);
  130. /**
  131. * cdf_mutex_destroy() - destroy a CDF lock
  132. * @lock: Pointer to the opaque lock object to be destroyed
  133. *
  134. * cdf_mutex_destroy() function shall destroy the lock object
  135. * referenced by lock. After a successful return from \a cdf_mutex_destroy()
  136. * the lock object becomes, in effect, uninitialized.
  137. *
  138. * A destroyed lock object can be reinitialized using cdf_mutex_init();
  139. * the results of otherwise referencing the object after it has been destroyed
  140. * are undefined. Calls to CDF lock functions to manipulate the lock such
  141. * as cdf_mutex_acquire() will fail if the lock is destroyed. Therefore,
  142. * don't use the lock after it has been destroyed until it has
  143. * been re-initialized.
  144. *
  145. * Return:
  146. * CDF_STATUS_SUCCESS: lock was successfully initialized
  147. * CDF failure reason codes: lock is not initialized and can't be used
  148. */
  149. CDF_STATUS cdf_mutex_destroy(cdf_mutex_t *lock);
  150. /**
  151. * cdf_spinlock_init() - initialize a spinlock
  152. * @lock: Spinlock object pointer
  153. *
  154. * Return: None
  155. */
  156. static inline void cdf_spinlock_init(cdf_spinlock_t *lock)
  157. {
  158. __cdf_spinlock_init(lock);
  159. }
  160. /**
  161. * cdf_spinlock_destroy() - delete a spinlock
  162. * @lock: Spinlock object pointer
  163. *
  164. * Return: None
  165. */
  166. static inline void cdf_spinlock_destroy(cdf_spinlock_t *lock)
  167. {
  168. __cdf_spinlock_destroy(lock);
  169. }
  170. /**
  171. * cdf_spin_lock_bh() - locks the spinlock semaphore in soft irq context
  172. * @lock: Spinlock object pointer
  173. *
  174. * Return: None
  175. */
  176. static inline void cdf_spin_lock_bh(cdf_spinlock_t *lock)
  177. {
  178. __cdf_spin_lock_bh(lock);
  179. }
  180. /**
  181. * cdf_spin_lock_bh() - unlocks the spinlock semaphore in soft irq context
  182. * @lock: Spinlock object pointer
  183. *
  184. * Return: None
  185. */
  186. static inline void cdf_spin_unlock_bh(cdf_spinlock_t *lock)
  187. {
  188. __cdf_spin_unlock_bh(lock);
  189. }
  190. /**
  191. * cdf_wake_lock_init() - initializes a CDF wake lock
  192. * @lock: The wake lock to initialize
  193. * @name: Name of wake lock
  194. *
  195. * Return:
  196. * CDF status success : if wake lock is initialized
  197. * CDF status fialure : if wake lock was not initialized
  198. */
  199. CDF_STATUS cdf_wake_lock_init(cdf_wake_lock_t *lock, const char *name);
  200. /**
  201. * cdf_wake_lock_acquire() - acquires a wake lock
  202. * @lock: The wake lock to acquire
  203. * @reason: Reason for taking wakelock
  204. *
  205. * Return:
  206. * CDF status success : if wake lock is acquired
  207. * CDF status fialure : if wake lock was not acquired
  208. */
  209. CDF_STATUS cdf_wake_lock_acquire(cdf_wake_lock_t *pLock, uint32_t reason);
  210. /**
  211. * cdf_wake_lock_timeout_acquire() - acquires a wake lock with a timeout
  212. * @lock: The wake lock to acquire
  213. * @reason: Reason for taking wakelock
  214. *
  215. * Return:
  216. * CDF status success : if wake lock is acquired
  217. * CDF status fialure : if wake lock was not acquired
  218. */
  219. CDF_STATUS cdf_wake_lock_timeout_acquire(cdf_wake_lock_t *pLock,
  220. uint32_t msec, uint32_t reason);
  221. /**
  222. * cdf_wake_lock_release() - releases a wake lock
  223. * @lock: the wake lock to release
  224. * @@reason: Reason for taking wakelock
  225. *
  226. * Return:
  227. * CDF status success : if wake lock is acquired
  228. * CDF status fialure : if wake lock was not acquired
  229. */
  230. CDF_STATUS cdf_wake_lock_release(cdf_wake_lock_t *pLock, uint32_t reason);
  231. /**
  232. * cdf_wake_lock_destroy() - destroys a wake lock
  233. * @lock: The wake lock to destroy
  234. *
  235. * Return:
  236. * CDF status success : if wake lock is acquired
  237. * CDF status fialure : if wake lock was not acquired
  238. */
  239. CDF_STATUS cdf_wake_lock_destroy(cdf_wake_lock_t *pLock);
  240. struct hif_pm_runtime_lock;
  241. typedef struct hif_pm_runtime_lock *cdf_runtime_lock_t;
  242. CDF_STATUS cdf_runtime_pm_get(void);
  243. CDF_STATUS cdf_runtime_pm_put(void);
  244. CDF_STATUS cdf_runtime_pm_prevent_suspend(cdf_runtime_lock_t lock);
  245. CDF_STATUS cdf_runtime_pm_allow_suspend(cdf_runtime_lock_t lock);
  246. cdf_runtime_lock_t cdf_runtime_lock_init(const char *name);
  247. void cdf_runtime_lock_deinit(cdf_runtime_lock_t lock);
  248. /**
  249. * cdf_spinlock_acquire() - acquires a spin lock
  250. * @lock: Spin lock to acquire
  251. *
  252. * Return:
  253. * CDF status success : if wake lock is acquired
  254. * CDF status fialure : if wake lock was not acquired
  255. */
  256. CDF_STATUS cdf_spinlock_acquire(cdf_spinlock_t *pLock);
  257. /**
  258. * cdf_spinlock_release() - release a spin lock
  259. * @lock: Spin lock to release
  260. *
  261. * Return:
  262. * CDF status success : if wake lock is acquired
  263. * CDF status fialure : if wake lock was not acquired
  264. */
  265. CDF_STATUS cdf_spinlock_release(cdf_spinlock_t *pLock);
  266. #define cdf_spin_lock(_lock) __cdf_spin_lock(_lock)
  267. #define cdf_spin_unlock(_lock) __cdf_spin_unlock(_lock)
  268. #define cdf_spin_lock_irqsave(_lock) __cdf_spin_lock_irqsave(_lock)
  269. #define cdf_spin_unlock_irqrestore(_lock) \
  270. __cdf_spin_unlock_irqrestore(_lock)
  271. #define cdf_spin_lock_irq(_pLock, _flags) __cdf_spin_lock_irq(_pLock, _flags)
  272. #define cdf_spin_unlock_irq(_pLock, _flags) \
  273. __cdf_spin_unlock_irq(_pLock, _flags)
  274. #define cdf_in_softirq() __cdf_in_softirq()
  275. #endif /* __CDF_LOCK_H */