Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Rajeev Kumar Sirasanagandla | 5b21a9c | 2018-01-08 17:05:11 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2015, 2018 The Linux Foundation. All rights reserved. |
Kiet Lam | 1ed83fc | 2014-02-19 01:15:45 -0800 | [diff] [blame] | 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. |
Gopichand Nakkala | 92f07d8 | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 20 | */ |
Kiet Lam | 1ed83fc | 2014-02-19 01:15:45 -0800 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 28 | #if !defined( __VOS_LOCK_H ) |
| 29 | #define __VOS_LOCK_H |
| 30 | |
| 31 | /**========================================================================= |
| 32 | |
| 33 | \file vos_lock.h |
| 34 | |
| 35 | \brief virtual Operating System Servies (vOS) Locks |
| 36 | |
| 37 | Definitions for vOSS Locks |
| 38 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 39 | |
| 40 | ========================================================================*/ |
| 41 | |
| 42 | /* $Header$ */ |
| 43 | |
| 44 | /*-------------------------------------------------------------------------- |
| 45 | Include Files |
| 46 | ------------------------------------------------------------------------*/ |
| 47 | #include "vos_status.h" |
| 48 | #include "i_vos_lock.h" |
| 49 | |
| 50 | /*-------------------------------------------------------------------------- |
| 51 | Preprocessor definitions and constants |
| 52 | ------------------------------------------------------------------------*/ |
| 53 | |
| 54 | /*-------------------------------------------------------------------------- |
| 55 | Type declarations |
| 56 | ------------------------------------------------------------------------*/ |
| 57 | |
| 58 | /*------------------------------------------------------------------------- |
| 59 | Function declarations and documenation |
| 60 | ------------------------------------------------------------------------*/ |
| 61 | |
| 62 | /*-------------------------------------------------------------------------- |
| 63 | |
| 64 | \brief vos_lock_init() - initialize a vOSS lock |
| 65 | |
| 66 | The \a vos_lock_init() function initializes the specified lock. Upon |
| 67 | successful initialization, the state of the lock becomes initialized |
| 68 | and unlocked. |
| 69 | |
| 70 | A lock must be initialized by calling vos_lock_init() before it |
| 71 | may be used in any other lock functions. |
| 72 | |
| 73 | Attempting to initialize an already initialized lock results in |
| 74 | a failure. |
| 75 | |
| 76 | \param lock - pointer to the opaque lock object to initialize |
| 77 | |
| 78 | \return VOS_STATUS_SUCCESS - lock was successfully initialized and |
| 79 | is ready to be used. |
| 80 | |
| 81 | VOS_STATUS_E_RESOURCES - System resources (other than memory) |
| 82 | are unavailable to initilize the lock |
| 83 | |
| 84 | VOS_STATUS_E_NOMEM - insufficient memory exists to initialize |
| 85 | the lock |
| 86 | |
| 87 | VOS_STATUS_E_BUSY - The implementation has detected an attempt |
| 88 | to reinitialize the object referenced by lock, a previously |
| 89 | initialized, but not yet destroyed, lock. |
| 90 | |
| 91 | VOS_STATUS_E_FAULT - lock is an invalid pointer. |
| 92 | \sa |
| 93 | |
| 94 | --------------------------------------------------------------------------*/ |
| 95 | VOS_STATUS vos_lock_init( vos_lock_t *lock ); |
| 96 | |
| 97 | /*-------------------------------------------------------------------------- |
| 98 | |
| 99 | \brief vos_lock_acquire() - acquire a lock |
| 100 | |
| 101 | A lock object is acquired by calling \a vos_lock_acquire(). If the lock |
| 102 | is already locked, the calling thread shall block until the lock becomes |
| 103 | available. This operation shall return with the lock object referenced by |
| 104 | lock in the locked state with the calling thread as its owner. |
| 105 | |
| 106 | \param lock - the lock object to acquire |
| 107 | |
| 108 | \return VOS_STATUS_SUCCESS - the lock was successfully acquired by |
| 109 | the calling thread. |
| 110 | |
| 111 | VOS_STATUS_E_INVAL - The value specified by lock does not refer |
| 112 | to an initialized lock object. |
| 113 | |
| 114 | VOS_STATUS_E_FAULT - lock is an invalid pointer. |
| 115 | |
| 116 | \sa |
| 117 | |
| 118 | ------------------------------------------------------------------------*/ |
| 119 | VOS_STATUS vos_lock_acquire( vos_lock_t * lock ); |
| 120 | |
| 121 | |
| 122 | /*-------------------------------------------------------------------------- |
| 123 | |
| 124 | \brief vos_lock_release() - release a lock |
| 125 | |
| 126 | The \a vos_lock_release() function shall release the lock object |
| 127 | referenced by 'lock'. |
| 128 | |
| 129 | If a thread attempts to release a lock that it unlocked or is not |
| 130 | initialized, an error is returned. |
| 131 | |
| 132 | \param lock - the lock to release |
| 133 | |
| 134 | \return VOS_STATUS_SUCCESS - the lock was successfully released |
| 135 | |
| 136 | VOS_STATUS_E_INVAL - The value specified by lock does not refer |
| 137 | to an initialized lock object. |
| 138 | |
| 139 | VOS_STATUS_E_FAULT - The value specified by lock does not refer |
| 140 | to an initialized lock object. |
| 141 | |
| 142 | VOS_STATUS_E_PERM - Operation is not permitted. The calling |
| 143 | thread does not own the lock. |
| 144 | |
| 145 | \sa |
| 146 | |
| 147 | ------------------------------------------------------------------------*/ |
| 148 | VOS_STATUS vos_lock_release( vos_lock_t *lock ); |
| 149 | |
| 150 | |
| 151 | /*-------------------------------------------------------------------------- |
| 152 | |
| 153 | \brief vos_lock_destroy() - Destroy a vOSS Lock |
| 154 | |
| 155 | The \a vos_lock_destroy() function shall destroy the lock object |
| 156 | referenced by lock. After a successful return from \a vos_lock_destroy() |
| 157 | the lock object becomes, in effect, uninitialized. |
| 158 | |
| 159 | A destroyed lock object can be reinitialized using vos_lock_init(); |
| 160 | the results of otherwise referencing the object after it has been destroyed |
| 161 | are undefined. Calls to vOSS lock functions to manipulate the lock such |
| 162 | as vos_lock_acquire() will fail if the lock is destroyed. Therefore, |
| 163 | don't use the lock after it has been destroyed until it has |
| 164 | been re-initialized. |
| 165 | |
| 166 | \param lock - the lock object to be destroyed. |
| 167 | |
| 168 | \return VOS_STATUS_SUCCESS - lock was successfully destroyed. |
| 169 | |
| 170 | VOS_STATUS_E_BUSY - The implementation has detected an attempt |
| 171 | to destroy the object referenced by lock while it is locked |
| 172 | or still referenced. |
| 173 | |
| 174 | VOS_STATUS_E_INVAL - The value specified by lock is invalid. |
| 175 | |
| 176 | VOS_STATUS_E_FAULT - lock is an invalid pointer. |
| 177 | \sa |
| 178 | |
| 179 | ------------------------------------------------------------------------*/ |
| 180 | VOS_STATUS vos_lock_destroy( vos_lock_t *lock ); |
| 181 | |
| 182 | /*-------------------------------------------------------------------------- |
| 183 | |
| 184 | \brief vos_spin_lock_init() - initializes a vOSS spin lock |
| 185 | |
| 186 | The vos_spin_lock_init() function initializes the specified spin lock. Upon |
| 187 | successful initialization, the state of the lock becomes initialized |
| 188 | and unlocked. |
| 189 | |
| 190 | A lock must be initialized by calling vos_spin_lock_init() before it |
| 191 | may be used in any other lock functions. |
| 192 | |
| 193 | Attempting to initialize an already initialized lock results in |
| 194 | a failure. |
| 195 | |
| 196 | \param pLock - pointer to the opaque lock object to initialize |
| 197 | |
| 198 | \return VOS_STATUS_SUCCESS - spin lock was successfully initialized and |
| 199 | is ready to be used. |
| 200 | --------------------------------------------------------------------------*/ |
| 201 | VOS_STATUS vos_spin_lock_init(vos_spin_lock_t *pLock); |
| 202 | |
| 203 | /*-------------------------------------------------------------------------- |
| 204 | |
| 205 | \brief vos_spin_lock_acquire() - acquires a spin lock |
| 206 | |
| 207 | A lock object is acquired by calling \a vos_spin_lock_acquire(). If the lock |
| 208 | is already locked, the calling thread shall spin until the lock becomes |
| 209 | available. This operation shall return with the lock object referenced by |
| 210 | lock in the locked state with the calling thread as its owner. |
| 211 | |
| 212 | \param pLock - the lock object to acquire |
| 213 | |
| 214 | \return VOS_STATUS_SUCCESS - the lock was successfully acquired by |
| 215 | the calling thread. |
| 216 | |
| 217 | \sa |
| 218 | ------------------------------------------------------------------------*/ |
| 219 | VOS_STATUS vos_spin_lock_acquire(vos_spin_lock_t *pLock); |
| 220 | |
| 221 | /*-------------------------------------------------------------------------- |
| 222 | |
| 223 | \brief vos_spin_lock_release() - releases a lock |
| 224 | |
| 225 | The \a vos_lock_release() function shall release the spin lock object |
| 226 | referenced by 'lock'. |
| 227 | |
| 228 | If a thread attempts to release a lock that it unlocked or is not |
| 229 | initialized, an error is returned. |
| 230 | |
| 231 | \param pLock - the lock to release |
| 232 | |
| 233 | \return VOS_STATUS_SUCCESS - the lock was successfully released |
| 234 | |
| 235 | \sa |
| 236 | ------------------------------------------------------------------------*/ |
| 237 | VOS_STATUS vos_spin_lock_release(vos_spin_lock_t *pLock); |
| 238 | |
| 239 | /*-------------------------------------------------------------------------- |
| 240 | |
| 241 | \brief vos_spin_lock_destroy() - releases resource of a lock |
| 242 | |
| 243 | \param pLock - pointer to a lock to release |
| 244 | |
| 245 | \return VOS_STATUS_SUCCESS - the lock was successfully released |
| 246 | |
| 247 | \sa |
| 248 | ------------------------------------------------------------------------*/ |
| 249 | VOS_STATUS vos_spin_lock_destroy(vos_spin_lock_t *pLock); |
| 250 | |
Sushant Kaushik | 83392fa | 2015-05-05 17:44:40 +0530 | [diff] [blame] | 251 | /*-------------------------------------------------------------------------- |
| 252 | |
| 253 | \brief vos_wake_lock_init() - initializes a vOSS wake lock |
| 254 | |
| 255 | \param pLock - the wake lock to initialize |
| 256 | name - wakelock name |
| 257 | |
| 258 | \return VOS_STATUS_SUCCESS - wake lock was successfully initialized and |
| 259 | is ready to be used. |
| 260 | --------------------------------------------------------------------------*/ |
| 261 | VOS_STATUS vos_wake_lock_init(vos_wake_lock_t *pLock, const char *name); |
| 262 | |
| 263 | /*-------------------------------------------------------------------------- |
| 264 | |
| 265 | \brief vos_wake_lock_acquire() - acquires a wake lock |
| 266 | |
| 267 | \param pLock - the wake lock to acquire |
| 268 | reason - reason for taking wakelock |
| 269 | |
| 270 | \return VOS_STATUS_SUCCESS - the wake lock was successfully acquired |
| 271 | |
| 272 | ------------------------------------------------------------------------*/ |
| 273 | VOS_STATUS vos_wake_lock_acquire(vos_wake_lock_t *pLock, uint32_t reason); |
| 274 | /*-------------------------------------------------------------------------- |
| 275 | |
| 276 | \brief vos_wake_lock_timeout_release() - release a wake lock with a timeout |
| 277 | |
| 278 | \param pLock - the wake lock to release |
| 279 | reason - reason for taking wakelock |
| 280 | |
| 281 | \return VOS_STATUS_SUCCESS - the wake lock was successfully released |
| 282 | |
| 283 | ------------------------------------------------------------------------*/ |
| 284 | VOS_STATUS vos_wake_lock_timeout_release(vos_wake_lock_t *pLock, |
| 285 | v_U32_t msec, uint32_t reason); |
| 286 | |
| 287 | /*-------------------------------------------------------------------------- |
| 288 | |
| 289 | \brief vos_wake_lock_release() - releases a wake lock |
| 290 | |
| 291 | \param pLock - the wake lock to release |
| 292 | reason - reason for taking wakelock |
| 293 | |
| 294 | \return VOS_STATUS_SUCCESS - the lock was successfully released |
| 295 | |
| 296 | ------------------------------------------------------------------------*/ |
| 297 | VOS_STATUS vos_wake_lock_release(vos_wake_lock_t *pLock, uint32_t reason); |
| 298 | |
| 299 | /*-------------------------------------------------------------------------- |
| 300 | |
| 301 | \brief vos_wake_lock_destroy() - destroys a wake lock |
| 302 | |
| 303 | \param pLock - the wake lock to destroy |
| 304 | |
| 305 | \return VOS_STATUS_SUCCESS - the lock was successfully destroyed |
| 306 | |
| 307 | ------------------------------------------------------------------------*/ |
| 308 | VOS_STATUS vos_wake_lock_destroy(vos_wake_lock_t *pLock); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 309 | |
Rajeev Kumar Sirasanagandla | 5b21a9c | 2018-01-08 17:05:11 +0530 | [diff] [blame] | 310 | /** |
| 311 | * vos_wake_lock_active() - Check for wake lock state |
| 312 | * @lock: lock to be checked |
| 313 | * |
| 314 | * Return: If active return true else false |
| 315 | */ |
| 316 | bool vos_wake_lock_active(vos_wake_lock_t *lock); |
| 317 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 318 | #endif // __VOSS_LOCK_H |