0b88c3414515af19c0dfb672abd2360e03b34309
[deb_dpdk.git] / lib / librte_eal / common / include / generic / rte_io.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016 Cavium, Inc. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Cavium, Inc 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  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_IO_H_
35 #define _RTE_IO_H_
36
37 /**
38  * @file
39  * I/O device memory operations
40  *
41  * This file defines the generic API for I/O device memory read/write operations
42  */
43
44 #include <stdint.h>
45 #include <rte_common.h>
46 #include <rte_atomic.h>
47
48 #ifdef __DOXYGEN__
49
50 /**
51  * Read a 8-bit value from I/O device memory address *addr*.
52  *
53  * The relaxed version does not have additional I/O memory barrier, useful in
54  * accessing the device registers of integrated controllers which implicitly
55  * strongly ordered with respect to memory access.
56  *
57  * @param addr
58  *  I/O memory address to read the value from
59  * @return
60  *  read value
61  */
62 static inline uint8_t
63 rte_read8_relaxed(const volatile void *addr);
64
65 /**
66  * Read a 16-bit value from I/O device memory address *addr*.
67  *
68  * The relaxed version does not have additional I/O memory barrier, useful in
69  * accessing the device registers of integrated controllers which implicitly
70  * strongly ordered with respect to memory access.
71  *
72  * @param addr
73  *  I/O memory address to read the value from
74  * @return
75  *  read value
76  */
77 static inline uint16_t
78 rte_read16_relaxed(const volatile void *addr);
79
80 /**
81  * Read a 32-bit value from I/O device memory address *addr*.
82  *
83  * The relaxed version does not have additional I/O memory barrier, useful in
84  * accessing the device registers of integrated controllers which implicitly
85  * strongly ordered with respect to memory access.
86  *
87  * @param addr
88  *  I/O memory address to read the value from
89  * @return
90  *  read value
91  */
92 static inline uint32_t
93 rte_read32_relaxed(const volatile void *addr);
94
95 /**
96  * Read a 64-bit value from I/O device memory address *addr*.
97  *
98  * The relaxed version does not have additional I/O memory barrier, useful in
99  * accessing the device registers of integrated controllers which implicitly
100  * strongly ordered with respect to memory access.
101  *
102  * @param addr
103  *  I/O memory address to read the value from
104  * @return
105  *  read value
106  */
107 static inline uint64_t
108 rte_read64_relaxed(const volatile void *addr);
109
110 /**
111  * Write a 8-bit value to I/O device memory address *addr*.
112  *
113  * The relaxed version does not have additional I/O memory barrier, useful in
114  * accessing the device registers of integrated controllers which implicitly
115  * strongly ordered with respect to memory access.
116  *
117  * @param value
118  *  Value to write
119  * @param addr
120  *  I/O memory address to write the value to
121  */
122
123 static inline void
124 rte_write8_relaxed(uint8_t value, volatile void *addr);
125
126 /**
127  * Write a 16-bit value to I/O device memory address *addr*.
128  *
129  * The relaxed version does not have additional I/O memory barrier, useful in
130  * accessing the device registers of integrated controllers which implicitly
131  * strongly ordered with respect to memory access.
132  *
133  * @param value
134  *  Value to write
135  * @param addr
136  *  I/O memory address to write the value to
137  */
138 static inline void
139 rte_write16_relaxed(uint16_t value, volatile void *addr);
140
141 /**
142  * Write a 32-bit value to I/O device memory address *addr*.
143  *
144  * The relaxed version does not have additional I/O memory barrier, useful in
145  * accessing the device registers of integrated controllers which implicitly
146  * strongly ordered with respect to memory access.
147  *
148  * @param value
149  *  Value to write
150  * @param addr
151  *  I/O memory address to write the value to
152  */
153 static inline void
154 rte_write32_relaxed(uint32_t value, volatile void *addr);
155
156 /**
157  * Write a 64-bit value to I/O device memory address *addr*.
158  *
159  * The relaxed version does not have additional I/O memory barrier, useful in
160  * accessing the device registers of integrated controllers which implicitly
161  * strongly ordered with respect to memory access.
162  *
163  * @param value
164  *  Value to write
165  * @param addr
166  *  I/O memory address to write the value to
167  */
168 static inline void
169 rte_write64_relaxed(uint64_t value, volatile void *addr);
170
171 /**
172  * Read a 8-bit value from I/O device memory address *addr*.
173  *
174  * @param addr
175  *  I/O memory address to read the value from
176  * @return
177  *  read value
178  */
179 static inline uint8_t
180 rte_read8(const volatile void *addr);
181
182 /**
183  * Read a 16-bit value from I/O device memory address *addr*.
184  *
185  *
186  * @param addr
187  *  I/O memory address to read the value from
188  * @return
189  *  read value
190  */
191 static inline uint16_t
192 rte_read16(const volatile void *addr);
193
194 /**
195  * Read a 32-bit value from I/O device memory address *addr*.
196  *
197  * @param addr
198  *  I/O memory address to read the value from
199  * @return
200  *  read value
201  */
202 static inline uint32_t
203 rte_read32(const volatile void *addr);
204
205 /**
206  * Read a 64-bit value from I/O device memory address *addr*.
207  *
208  * @param addr
209  *  I/O memory address to read the value from
210  * @return
211  *  read value
212  */
213 static inline uint64_t
214 rte_read64(const volatile void *addr);
215
216 /**
217  * Write a 8-bit value to I/O device memory address *addr*.
218  *
219  * @param value
220  *  Value to write
221  * @param addr
222  *  I/O memory address to write the value to
223  */
224
225 static inline void
226 rte_write8(uint8_t value, volatile void *addr);
227
228 /**
229  * Write a 16-bit value to I/O device memory address *addr*.
230  *
231  * @param value
232  *  Value to write
233  * @param addr
234  *  I/O memory address to write the value to
235  */
236 static inline void
237 rte_write16(uint16_t value, volatile void *addr);
238
239 /**
240  * Write a 32-bit value to I/O device memory address *addr*.
241  *
242  * @param value
243  *  Value to write
244  * @param addr
245  *  I/O memory address to write the value to
246  */
247 static inline void
248 rte_write32(uint32_t value, volatile void *addr);
249
250 /**
251  * Write a 64-bit value to I/O device memory address *addr*.
252  *
253  * @param value
254  *  Value to write
255  * @param addr
256  *  I/O memory address to write the value to
257  */
258 static inline void
259 rte_write64(uint64_t value, volatile void *addr);
260
261 #endif /* __DOXYGEN__ */
262
263 #ifndef RTE_OVERRIDE_IO_H
264
265 static __rte_always_inline uint8_t
266 rte_read8_relaxed(const volatile void *addr)
267 {
268         return *(const volatile uint8_t *)addr;
269 }
270
271 static __rte_always_inline uint16_t
272 rte_read16_relaxed(const volatile void *addr)
273 {
274         return *(const volatile uint16_t *)addr;
275 }
276
277 static __rte_always_inline uint32_t
278 rte_read32_relaxed(const volatile void *addr)
279 {
280         return *(const volatile uint32_t *)addr;
281 }
282
283 static __rte_always_inline uint64_t
284 rte_read64_relaxed(const volatile void *addr)
285 {
286         return *(const volatile uint64_t *)addr;
287 }
288
289 static __rte_always_inline void
290 rte_write8_relaxed(uint8_t value, volatile void *addr)
291 {
292         *(volatile uint8_t *)addr = value;
293 }
294
295 static __rte_always_inline void
296 rte_write16_relaxed(uint16_t value, volatile void *addr)
297 {
298         *(volatile uint16_t *)addr = value;
299 }
300
301 static __rte_always_inline void
302 rte_write32_relaxed(uint32_t value, volatile void *addr)
303 {
304         *(volatile uint32_t *)addr = value;
305 }
306
307 static __rte_always_inline void
308 rte_write64_relaxed(uint64_t value, volatile void *addr)
309 {
310         *(volatile uint64_t *)addr = value;
311 }
312
313 static __rte_always_inline uint8_t
314 rte_read8(const volatile void *addr)
315 {
316         uint8_t val;
317         val = rte_read8_relaxed(addr);
318         rte_io_rmb();
319         return val;
320 }
321
322 static __rte_always_inline uint16_t
323 rte_read16(const volatile void *addr)
324 {
325         uint16_t val;
326         val = rte_read16_relaxed(addr);
327         rte_io_rmb();
328         return val;
329 }
330
331 static __rte_always_inline uint32_t
332 rte_read32(const volatile void *addr)
333 {
334         uint32_t val;
335         val = rte_read32_relaxed(addr);
336         rte_io_rmb();
337         return val;
338 }
339
340 static __rte_always_inline uint64_t
341 rte_read64(const volatile void *addr)
342 {
343         uint64_t val;
344         val = rte_read64_relaxed(addr);
345         rte_io_rmb();
346         return val;
347 }
348
349 static __rte_always_inline void
350 rte_write8(uint8_t value, volatile void *addr)
351 {
352         rte_io_wmb();
353         rte_write8_relaxed(value, addr);
354 }
355
356 static __rte_always_inline void
357 rte_write16(uint16_t value, volatile void *addr)
358 {
359         rte_io_wmb();
360         rte_write16_relaxed(value, addr);
361 }
362
363 static __rte_always_inline void
364 rte_write32(uint32_t value, volatile void *addr)
365 {
366         rte_io_wmb();
367         rte_write32_relaxed(value, addr);
368 }
369
370 static __rte_always_inline void
371 rte_write64(uint64_t value, volatile void *addr)
372 {
373         rte_io_wmb();
374         rte_write64_relaxed(value, addr);
375 }
376
377 #endif /* RTE_OVERRIDE_IO_H */
378
379 #endif /* _RTE_IO_H_ */