1 /* 2 * Copyright (c) 2014-2018 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_set_bit - Atomically set a bit in memory 159 * @nr: bit to set 160 * @addr: the address to start counting from 161 * 162 * Return: none 163 */ 164 static inline void qdf_atomic_set_bit(int nr, volatile unsigned long *addr) 165 { 166 __qdf_atomic_set_bit(nr, addr); 167 } 168 169 /** 170 * qdf_atomic_clear_bit - Atomically clear a bit in memory 171 * @nr: bit to clear 172 * @addr: the address to start counting from 173 * 174 * Return: none 175 */ 176 static inline void qdf_atomic_clear_bit(int nr, volatile unsigned long *addr) 177 { 178 __qdf_atomic_clear_bit(nr, addr); 179 } 180 181 /** 182 * qdf_atomic_change_bit - Atomically toggle a bit in memory 183 * from addr 184 * @nr: bit to change 185 * @addr: the address to start counting from 186 * 187 * Return: none 188 */ 189 static inline void qdf_atomic_change_bit(int nr, volatile unsigned long *addr) 190 { 191 __qdf_atomic_change_bit(nr, addr); 192 } 193 194 /** 195 * qdf_atomic_test_and_set_bit - Atomically set a bit and return its old value 196 * @nr: Bit to set 197 * @addr: the address to start counting from 198 * 199 * Return: return nr bit old value 200 */ 201 static inline int qdf_atomic_test_and_set_bit(int nr, 202 volatile unsigned long *addr) 203 { 204 return __qdf_atomic_test_and_set_bit(nr, addr); 205 } 206 207 /** 208 * qdf_atomic_test_and_clear_bit - Atomically clear a bit and return its old 209 * value 210 * @nr: bit to clear 211 * @addr: the address to start counting from 212 * 213 * Return: return nr bit old value 214 */ 215 static inline int qdf_atomic_test_and_clear_bit(int nr, 216 volatile unsigned long *addr) 217 { 218 return __qdf_atomic_test_and_clear_bit(nr, addr); 219 } 220 221 /** 222 * qdf_atomic_test_and_change_bit - Atomically toggle a bit and return its old 223 * value 224 * @nr: bit to change 225 * @addr: the address to start counting from 226 * 227 * Return: return nr bit old value 228 */ 229 static inline int qdf_atomic_test_and_change_bit(int nr, 230 volatile unsigned long *addr) 231 { 232 return __qdf_atomic_test_and_change_bit(nr, addr); 233 } 234 235 /** 236 * qdf_atomic_test_bit - Atomically get the nr-th bit value starting from addr 237 * @nr: bit to get 238 * @addr: the address to start counting from 239 * 240 * Return: return nr bit value 241 */ 242 static inline int qdf_atomic_test_bit(int nr, volatile unsigned long *addr) 243 { 244 return __qdf_atomic_test_bit(nr, addr); 245 } 246 247 #endif 248