DPDK  17.05.2
rte_io.h
Go to the documentation of this file.
1 /*
2  * BSD LICENSE
3  *
4  * Copyright(c) 2016 Cavium networks. 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 networks 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 #include <rte_atomic.h>
38 
46 #include <stdint.h>
47 #include <rte_common.h>
48 #include <rte_atomic.h>
49 
50 #ifdef __DOXYGEN__
51 
64 static inline uint8_t
65 rte_read8_relaxed(const volatile void *addr);
66 
79 static inline uint16_t
80 rte_read16_relaxed(const volatile void *addr);
81 
94 static inline uint32_t
95 rte_read32_relaxed(const volatile void *addr);
96 
109 static inline uint64_t
110 rte_read64_relaxed(const volatile void *addr);
111 
125 static inline void
126 rte_write8_relaxed(uint8_t value, volatile void *addr);
127 
140 static inline void
141 rte_write16_relaxed(uint16_t value, volatile void *addr);
142 
155 static inline void
156 rte_write32_relaxed(uint32_t value, volatile void *addr);
157 
170 static inline void
171 rte_write64_relaxed(uint64_t value, volatile void *addr);
172 
181 static inline uint8_t
182 rte_read8(const volatile void *addr);
183 
193 static inline uint16_t
194 rte_read16(const volatile void *addr);
195 
204 static inline uint32_t
205 rte_read32(const volatile void *addr);
206 
215 static inline uint64_t
216 rte_read64(const volatile void *addr);
217 
227 static inline void
228 rte_write8(uint8_t value, volatile void *addr);
229 
238 static inline void
239 rte_write16(uint16_t value, volatile void *addr);
240 
249 static inline void
250 rte_write32(uint32_t value, volatile void *addr);
251 
260 static inline void
261 rte_write64(uint64_t value, volatile void *addr);
262 
263 #endif /* __DOXYGEN__ */
264 
265 #ifndef RTE_OVERRIDE_IO_H
266 
267 static inline uint8_t __attribute__((always_inline))
268 rte_read8_relaxed(const volatile void *addr)
269 {
270  return *(const volatile uint8_t *)addr;
271 }
272 
273 static inline uint16_t __attribute__((always_inline))
274 rte_read16_relaxed(const volatile void *addr)
275 {
276  return *(const volatile uint16_t *)addr;
277 }
278 
279 static inline uint32_t __attribute__((always_inline))
280 rte_read32_relaxed(const volatile void *addr)
281 {
282  return *(const volatile uint32_t *)addr;
283 }
284 
285 static inline uint64_t __attribute__((always_inline))
286 rte_read64_relaxed(const volatile void *addr)
287 {
288  return *(const volatile uint64_t *)addr;
289 }
290 
291 static inline void __attribute__((always_inline))
292 rte_write8_relaxed(uint8_t value, volatile void *addr)
293 {
294  *(volatile uint8_t *)addr = value;
295 }
296 
297 static inline void __attribute__((always_inline))
298 rte_write16_relaxed(uint16_t value, volatile void *addr)
299 {
300  *(volatile uint16_t *)addr = value;
301 }
302 
303 static inline void __attribute__((always_inline))
304 rte_write32_relaxed(uint32_t value, volatile void *addr)
305 {
306  *(volatile uint32_t *)addr = value;
307 }
308 
309 static inline void __attribute__((always_inline))
310 rte_write64_relaxed(uint64_t value, volatile void *addr)
311 {
312  *(volatile uint64_t *)addr = value;
313 }
314 
315 static inline uint8_t __attribute__((always_inline))
316 rte_read8(const volatile void *addr)
317 {
318  uint8_t val;
319  val = rte_read8_relaxed(addr);
320  rte_io_rmb();
321  return val;
322 }
323 
324 static inline uint16_t __attribute__((always_inline))
325 rte_read16(const volatile void *addr)
326 {
327  uint16_t val;
328  val = rte_read16_relaxed(addr);
329  rte_io_rmb();
330  return val;
331 }
332 
333 static inline uint32_t __attribute__((always_inline))
334 rte_read32(const volatile void *addr)
335 {
336  uint32_t val;
337  val = rte_read32_relaxed(addr);
338  rte_io_rmb();
339  return val;
340 }
341 
342 static inline uint64_t __attribute__((always_inline))
343 rte_read64(const volatile void *addr)
344 {
345  uint64_t val;
346  val = rte_read64_relaxed(addr);
347  rte_io_rmb();
348  return val;
349 }
350 
351 static inline void __attribute__((always_inline))
352 rte_write8(uint8_t value, volatile void *addr)
353 {
354  rte_io_wmb();
355  rte_write8_relaxed(value, addr);
356 }
357 
358 static inline void __attribute__((always_inline))
359 rte_write16(uint16_t value, volatile void *addr)
360 {
361  rte_io_wmb();
362  rte_write16_relaxed(value, addr);
363 }
364 
365 static inline void __attribute__((always_inline))
366 rte_write32(uint32_t value, volatile void *addr)
367 {
368  rte_io_wmb();
369  rte_write32_relaxed(value, addr);
370 }
371 
372 static inline void __attribute__((always_inline))
373 rte_write64(uint64_t value, volatile void *addr)
374 {
375  rte_io_wmb();
376  rte_write64_relaxed(value, addr);
377 }
378 
379 #endif /* RTE_OVERRIDE_IO_H */
380 
381 #endif /* _RTE_IO_H_ */