Setting up repository
[linux-libre-firmware.git] / ath9k_htc / target_firmware / magpie_fw_dev / target / inc / adf_os_bitops.h
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted (subject to the limitations in the
7  * disclaimer below) provided that the following conditions are met:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *  * Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the
15  *    distribution.
16  *
17  *  * Neither the name of Qualcomm Atheros nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22  * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 /** 
36  * @ingroup adf_os_public
37  * @file adf_os_bitops.h
38  * This file abstracts bit-level operations on a stream of bytes.
39  */
40
41 #ifndef _ADF_OS_BITOPS_H
42 #define _ADF_OS_BITOPS_H
43
44 #include <adf_os_types.h>
45
46 /**
47  * @brief Set a bit atomically
48  * @param[in] nr    Bit to change
49  * @param[in] addr  Address to start counting from
50  *
51  * @note its atomic and cannot be re-ordered.
52  * Note that nr may be almost arbitrarily large; this function is not
53  * restricted to acting on a single-word quantity.
54  */
55 static inline void adf_os_set_bit_a(a_uint32_t nr, volatile a_uint32_t *addr)
56 {
57     __adf_os_set_bit_a(nr, addr);
58 }
59
60 /**
61  * @brief Set a bit
62  * @param[in] nr    Bit to change
63  * @param[in] addr  Address to start counting from
64  *
65  * @note its not atomic and can be re-ordered.
66  * Note that nr may be almost arbitrarily large; this function is not
67  * restricted to acting on a single-word quantity.
68  */
69 static inline void adf_os_set_bit(a_uint32_t nr, volatile a_uint32_t *addr)
70 {
71     __adf_os_set_bit(nr, addr);
72 }
73
74 /**
75  * @brief Clear a bit atomically
76  * @param[in] nr    Bit to change
77  * @param[in] addr  Address to start counting from
78  *
79  * @note its atomic and cannot be re-ordered.
80  * Note that nr may be almost arbitrarily large; this function is not
81  * restricted to acting on a single-word quantity.
82  */
83 static inline void adf_os_clear_bit_a(a_uint32_t nr, volatile a_uint32_t *addr)
84 {
85     __adf_os_clear_bit_a(nr, addr);
86 }
87
88 /**
89  * @brief Clear a bit
90  * @param[in] nr    Bit to change
91  * @param[in] addr  Address to start counting from
92  *
93  * @note its not atomic and can be re-ordered.
94  * Note that nr may be almost arbitrarily large; this function is not
95  * restricted to acting on a single-word quantity.
96  */
97 static inline void adf_os_clear_bit(a_uint32_t nr, volatile a_uint32_t *addr)
98 {
99     __adf_os_clear_bit(nr, addr);
100 }
101
102 /**
103  * @brief Toggle a bit atomically
104  * @param[in] nr    Bit to change
105  * @param[in] addr  Address to start counting from
106  *
107  * @note its atomic and cannot be re-ordered.
108  * Note that nr may be almost arbitrarily large; this function is not
109  * restricted to acting on a single-word quantity.
110  */
111 static inline void adf_os_change_bit_a(a_uint32_t nr, volatile a_uint32_t *addr)
112 {
113     __adf_os_change_bit_a(nr, addr);
114 }
115
116 /**
117  * @brief Toggle a bit
118  * @param[in] nr    Bit to change
119  * @param[in] addr  Address to start counting from
120  *
121  * @note its not atomic and can be re-ordered.
122  * Note that nr may be almost arbitrarily large; this function is not
123  * restricted to acting on a single-word quantity.
124  */
125 static inline void adf_os_change_bit(a_uint32_t nr, volatile a_uint32_t *addr)
126 {
127     __adf_os_change_bit(nr, addr);
128 }
129
130 /**
131  * @brief Test and Set a bit atomically
132  * @param[in] nr    Bit to set
133  * @param[in] addr  Address to start counting from
134  *
135  * @note its atomic and cannot be re-ordered.
136  * Note that nr may be almost arbitrarily large; this function is not
137  * restricted to acting on a single-word quantity.
138  */
139 static inline void adf_os_test_and_set_bit_a(a_uint32_t nr, 
140                                           volatile a_uint32_t *addr)
141 {
142     __adf_os_test_and_set_bit_a(nr, addr);
143 }
144
145 /**
146  * @brief Test and Set a bit
147  * @param[in] nr    Bit to set
148  * @param[in] addr  Address to start counting from
149  *
150  * @note its not atomic and can be re-ordered.
151  * Note that nr may be almost arbitrarily large; this function is not
152  * restricted to acting on a single-word quantity.
153  */
154 static inline void adf_os_test_and_set_bit(a_uint32_t nr, 
155                                           volatile a_uint32_t *addr)
156 {
157     __adf_os_test_and_set_bit(nr, addr);
158 }
159
160 /**
161  * @brief Test and clear a bit atomically
162  * @param[in] nr    Bit to set
163  * @param[in] addr  Address to start counting from
164  *
165  * @note its atomic and cannot be re-ordered.
166  * Note that nr may be almost arbitrarily large; this function is not
167  * restricted to acting on a single-word quantity.
168  */
169 static inline void adf_os_test_and_clear_bit_a(a_uint32_t nr, 
170                                           volatile a_uint32_t *addr)
171 {
172     __adf_os_test_and_clear_bit_a(nr, addr);
173 }
174
175 /**
176  * @brief Test and clear a bit
177  * @param[in] nr    Bit to set
178  * @param[in] addr  Address to start counting from
179  *
180  * @note its not atomic and can be re-ordered.
181  * Note that nr may be almost arbitrarily large; this function is not
182  * restricted to acting on a single-word quantity.
183  */
184 static inline void adf_os_test_and_clear_bit(a_uint32_t nr, 
185                                           volatile a_uint32_t *addr)
186 {
187     __adf_os_test_and_clear_bit(nr, addr);
188 }
189
190 /**
191  * @brief Test and change a bit atomically
192  * @param[in] nr    Bit to set
193  * @param[in] addr  Address to start counting from
194  *
195  * @note its atomic and cannot be re-ordered.
196  * Note that nr may be almost arbitrarily large; this function is not
197  * restricted to acting on a single-word quantity.
198  */
199 static inline void adf_os_test_and_change_bit_a(a_uint32_t nr, 
200                                           volatile a_uint32_t *addr)
201 {
202     __adf_os_test_and_change_bit_a(nr, addr);
203 }
204
205 /**
206  * @brief Test and clear a bit
207  * @param[in] nr    Bit to set
208  * @param[in] addr  Address to start counting from
209  *
210  * @note its not atomic and can be re-ordered.
211  * Note that nr may be almost arbitrarily large; this function is not
212  * restricted to acting on a single-word quantity.
213  */
214 static inline void adf_os_test_and_change_bit(a_uint32_t nr, 
215                                           volatile a_uint32_t *addr)
216 {
217     __adf_os_test_and_change_bit(nr, addr);
218 }
219
220 /**
221  * @brief test_bit - Determine whether a bit is set
222  * @param[in] nr    bit number to test
223  * @param[in] addr  Address to start counting from
224  *
225  * @return 1 if set, 0 if not
226  */
227 static inline int adf_os_test_bit(a_uint32_t nr, volatile a_uint32_t *addr)
228 {
229     __adf_os_test_bit(nr, addr);
230 }
231
232
233 #endif /**_AOD_BITOPS_H*/