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