1 /* 2 * Copyright (c) 2014-2020 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 /** 20 * DOC: qdf_atomic.h 21 * This file provides OS abstraction for atomic APIs. 22 */ 23 24 #ifndef _QDF_ATOMIC_H 25 #define _QDF_ATOMIC_H 26 27 #include <i_qdf_atomic.h> 28 29 /** 30 * qdf_atomic_t - atomic type of variable 31 * 32 * Use this when you want a simple resource counter etc. which is atomic 33 * across multiple CPU's. These maybe slower than usual counters on some 34 * platforms/OS'es, so use them with caution. 35 */ 36 37 typedef __qdf_atomic_t qdf_atomic_t; 38 39 /** 40 * qdf_atomic_init() - initialize an atomic type variable 41 * @v: A pointer to an opaque atomic variable 42 * 43 * Return: None 44 */ 45 static inline QDF_STATUS qdf_atomic_init(qdf_atomic_t *v) 46 { 47 return __qdf_atomic_init(v); 48 } 49 50 /** 51 * qdf_atomic_read() - read the value of an atomic variable 52 * @v: A pointer to an opaque atomic variable 53 * 54 * Return: The current value of the variable 55 */ 56 static inline int32_t qdf_atomic_read(qdf_atomic_t *v) 57 { 58 return __qdf_atomic_read(v); 59 } 60 61 /** 62 * qdf_atomic_inc() - increment the value of an atomic variable 63 * @v: A pointer to an opaque atomic variable 64 * 65 * Return: None 66 */ 67 static inline void qdf_atomic_inc(qdf_atomic_t *v) 68 { 69 __qdf_atomic_inc(v); 70 } 71 72 /** 73 * qdf_atomic_dec() - decrement the value of an atomic variable 74 * @v: A pointer to an opaque atomic variable 75 * 76 * Return: None 77 */ 78 static inline void qdf_atomic_dec(qdf_atomic_t *v) 79 { 80 __qdf_atomic_dec(v); 81 } 82 83 /** 84 * qdf_atomic_add() - add a value to the value of an atomic variable 85 * @i: The amount by which to increase the atomic counter 86 * @v: A pointer to an opaque atomic variable 87 * 88 * Return: None 89 */ 90 static inline void qdf_atomic_add(int i, qdf_atomic_t *v) 91 { 92 __qdf_atomic_add(i, v); 93 } 94 95 /** 96 * qdf_atomic_sub() - Subtract a value from an atomic variable 97 * @i: the amount by which to decrease the atomic counter 98 * @v: a pointer to an opaque atomic variable 99 * 100 * Return: none 101 */ 102 static inline void qdf_atomic_sub(int i, qdf_atomic_t *v) 103 { 104 __qdf_atomic_sub(i, v); 105 } 106 107 /** 108 * qdf_atomic_dec_and_test() - decrement an atomic variable and check if the 109 * new value is zero 110 * @v: A pointer to an opaque atomic variable 111 * 112 * Return: 113 * true (non-zero) if the new value is zero, 114 * false (0) if the new value is non-zero 115 */ 116 static inline int32_t qdf_atomic_dec_and_test(qdf_atomic_t *v) 117 { 118 return __qdf_atomic_dec_and_test(v); 119 } 120 121 /** 122 * qdf_atomic_set() - set a value to the value of an atomic variable 123 * @v: A pointer to an opaque atomic variable 124 * @i: required value to set 125 * 126 * Atomically sets the value of v to i 127 * Return: None 128 */ 129 static inline void qdf_atomic_set(qdf_atomic_t *v, int i) 130 { 131 __qdf_atomic_set(v, i); 132 } 133 134 /** 135 * qdf_atomic_inc_return() - return the incremented value of an atomic variable 136 * @v: A pointer to an opaque atomic variable 137 * 138 * Return: The current value of the variable 139 */ 140 static inline int32_t qdf_atomic_inc_return(qdf_atomic_t *v) 141 { 142 return __qdf_atomic_inc_return(v); 143 } 144 145 /** 146 * qdf_atomic_dec_return() - return the decremented value of an atomic 147 * variable 148 * @v: A pointer to an opaque atomic variable 149 * 150 * Return: The current value of the variable 151 */ 152 static inline int32_t qdf_atomic_dec_return(qdf_atomic_t *v) 153 { 154 return __qdf_atomic_dec_return(v); 155 } 156 157 /** 158 * qdf_atomic_inc_not_zero() - increment if not zero 159 * @v: A pointer to an opaque atomic variable 160 * 161 * Return: Returns non-zero on successful increment and zero otherwise 162 */ 163 static inline int32_t qdf_atomic_inc_not_zero(qdf_atomic_t *v) 164 { 165 return __qdf_atomic_inc_not_zero(v); 166 } 167 168 /** 169 * qdf_atomic_set_bit - Atomically set a bit in memory 170 * @nr: bit to set 171 * @addr: the address to start counting from 172 * 173 * Return: none 174 */ 175 static inline void qdf_atomic_set_bit(int nr, volatile unsigned long *addr) 176 { 177 __qdf_atomic_set_bit(nr, addr); 178 } 179 180 /** 181 * qdf_atomic_clear_bit - Atomically clear a bit in memory 182 * @nr: bit to clear 183 * @addr: the address to start counting from 184 * 185 * Return: none 186 */ 187 static inline void qdf_atomic_clear_bit(int nr, volatile unsigned long *addr) 188 { 189 __qdf_atomic_clear_bit(nr, addr); 190 } 191 192 /** 193 * qdf_atomic_change_bit - Atomically toggle a bit in memory 194 * from addr 195 * @nr: bit to change 196 * @addr: the address to start counting from 197 * 198 * Return: none 199 */ 200 static inline void qdf_atomic_change_bit(int nr, volatile unsigned long *addr) 201 { 202 __qdf_atomic_change_bit(nr, addr); 203 } 204 205 /** 206 * qdf_atomic_test_and_set_bit - Atomically set a bit and return its old value 207 * @nr: Bit to set 208 * @addr: the address to start counting from 209 * 210 * Return: return nr bit old value 211 */ 212 static inline int qdf_atomic_test_and_set_bit(int nr, 213 volatile unsigned long *addr) 214 { 215 return __qdf_atomic_test_and_set_bit(nr, addr); 216 } 217 218 /** 219 * qdf_atomic_test_and_clear_bit - Atomically clear a bit and return its old 220 * value 221 * @nr: bit to clear 222 * @addr: the address to start counting from 223 * 224 * Return: return nr bit old value 225 */ 226 static inline int qdf_atomic_test_and_clear_bit(int nr, 227 volatile unsigned long *addr) 228 { 229 return __qdf_atomic_test_and_clear_bit(nr, addr); 230 } 231 232 /** 233 * qdf_atomic_test_and_change_bit - Atomically toggle a bit and return its old 234 * value 235 * @nr: bit to change 236 * @addr: the address to start counting from 237 * 238 * Return: return nr bit old value 239 */ 240 static inline int qdf_atomic_test_and_change_bit(int nr, 241 volatile unsigned long *addr) 242 { 243 return __qdf_atomic_test_and_change_bit(nr, addr); 244 } 245 246 /** 247 * qdf_atomic_test_bit - Atomically get the nr-th bit value starting from addr 248 * @nr: bit to get 249 * @addr: the address to start counting from 250 * 251 * Return: return nr bit value 252 */ 253 static inline int qdf_atomic_test_bit(int nr, volatile unsigned long *addr) 254 { 255 return __qdf_atomic_test_bit(nr, addr); 256 } 257 258 #endif 259