1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 Cavium, Inc
10 * I/O device memory operations
12 * This file defines the generic API for I/O device memory read/write operations
16 #include <rte_common.h>
17 #include <rte_atomic.h>
22 * Read a 8-bit value from I/O device memory address *addr*.
24 * The relaxed version does not have additional I/O memory barrier, useful in
25 * accessing the device registers of integrated controllers which implicitly
26 * strongly ordered with respect to memory access.
29 * I/O memory address to read the value from
34 rte_read8_relaxed(const volatile void *addr);
37 * Read a 16-bit value from I/O device memory address *addr*.
39 * The relaxed version does not have additional I/O memory barrier, useful in
40 * accessing the device registers of integrated controllers which implicitly
41 * strongly ordered with respect to memory access.
44 * I/O memory address to read the value from
48 static inline uint16_t
49 rte_read16_relaxed(const volatile void *addr);
52 * Read a 32-bit value from I/O device memory address *addr*.
54 * The relaxed version does not have additional I/O memory barrier, useful in
55 * accessing the device registers of integrated controllers which implicitly
56 * strongly ordered with respect to memory access.
59 * I/O memory address to read the value from
63 static inline uint32_t
64 rte_read32_relaxed(const volatile void *addr);
67 * Read a 64-bit value from I/O device memory address *addr*.
69 * The relaxed version does not have additional I/O memory barrier, useful in
70 * accessing the device registers of integrated controllers which implicitly
71 * strongly ordered with respect to memory access.
74 * I/O memory address to read the value from
78 static inline uint64_t
79 rte_read64_relaxed(const volatile void *addr);
82 * Write a 8-bit value to I/O device memory address *addr*.
84 * The relaxed version does not have additional I/O memory barrier, useful in
85 * accessing the device registers of integrated controllers which implicitly
86 * strongly ordered with respect to memory access.
91 * I/O memory address to write the value to
95 rte_write8_relaxed(uint8_t value, volatile void *addr);
98 * Write a 16-bit value to I/O device memory address *addr*.
100 * The relaxed version does not have additional I/O memory barrier, useful in
101 * accessing the device registers of integrated controllers which implicitly
102 * strongly ordered with respect to memory access.
107 * I/O memory address to write the value to
110 rte_write16_relaxed(uint16_t value, volatile void *addr);
113 * Write a 32-bit value to I/O device memory address *addr*.
115 * The relaxed version does not have additional I/O memory barrier, useful in
116 * accessing the device registers of integrated controllers which implicitly
117 * strongly ordered with respect to memory access.
122 * I/O memory address to write the value to
125 rte_write32_relaxed(uint32_t value, volatile void *addr);
128 * Write a 64-bit value to I/O device memory address *addr*.
130 * The relaxed version does not have additional I/O memory barrier, useful in
131 * accessing the device registers of integrated controllers which implicitly
132 * strongly ordered with respect to memory access.
137 * I/O memory address to write the value to
140 rte_write64_relaxed(uint64_t value, volatile void *addr);
143 * Read a 8-bit value from I/O device memory address *addr*.
146 * I/O memory address to read the value from
150 static inline uint8_t
151 rte_read8(const volatile void *addr);
154 * Read a 16-bit value from I/O device memory address *addr*.
158 * I/O memory address to read the value from
162 static inline uint16_t
163 rte_read16(const volatile void *addr);
166 * Read a 32-bit value from I/O device memory address *addr*.
169 * I/O memory address to read the value from
173 static inline uint32_t
174 rte_read32(const volatile void *addr);
177 * Read a 64-bit value from I/O device memory address *addr*.
180 * I/O memory address to read the value from
184 static inline uint64_t
185 rte_read64(const volatile void *addr);
188 * Write a 8-bit value to I/O device memory address *addr*.
193 * I/O memory address to write the value to
197 rte_write8(uint8_t value, volatile void *addr);
200 * Write a 16-bit value to I/O device memory address *addr*.
205 * I/O memory address to write the value to
208 rte_write16(uint16_t value, volatile void *addr);
211 * Write a 32-bit value to I/O device memory address *addr*.
216 * I/O memory address to write the value to
219 rte_write32(uint32_t value, volatile void *addr);
222 * Write a 64-bit value to I/O device memory address *addr*.
227 * I/O memory address to write the value to
230 rte_write64(uint64_t value, volatile void *addr);
232 #endif /* __DOXYGEN__ */
234 #ifndef RTE_OVERRIDE_IO_H
236 static __rte_always_inline uint8_t
237 rte_read8_relaxed(const volatile void *addr)
239 return *(const volatile uint8_t *)addr;
242 static __rte_always_inline uint16_t
243 rte_read16_relaxed(const volatile void *addr)
245 return *(const volatile uint16_t *)addr;
248 static __rte_always_inline uint32_t
249 rte_read32_relaxed(const volatile void *addr)
251 return *(const volatile uint32_t *)addr;
254 static __rte_always_inline uint64_t
255 rte_read64_relaxed(const volatile void *addr)
257 return *(const volatile uint64_t *)addr;
260 static __rte_always_inline void
261 rte_write8_relaxed(uint8_t value, volatile void *addr)
263 *(volatile uint8_t *)addr = value;
266 static __rte_always_inline void
267 rte_write16_relaxed(uint16_t value, volatile void *addr)
269 *(volatile uint16_t *)addr = value;
272 static __rte_always_inline void
273 rte_write32_relaxed(uint32_t value, volatile void *addr)
275 *(volatile uint32_t *)addr = value;
278 static __rte_always_inline void
279 rte_write64_relaxed(uint64_t value, volatile void *addr)
281 *(volatile uint64_t *)addr = value;
284 static __rte_always_inline uint8_t
285 rte_read8(const volatile void *addr)
288 val = rte_read8_relaxed(addr);
293 static __rte_always_inline uint16_t
294 rte_read16(const volatile void *addr)
297 val = rte_read16_relaxed(addr);
302 static __rte_always_inline uint32_t
303 rte_read32(const volatile void *addr)
306 val = rte_read32_relaxed(addr);
311 static __rte_always_inline uint64_t
312 rte_read64(const volatile void *addr)
315 val = rte_read64_relaxed(addr);
320 static __rte_always_inline void
321 rte_write8(uint8_t value, volatile void *addr)
324 rte_write8_relaxed(value, addr);
327 static __rte_always_inline void
328 rte_write16(uint16_t value, volatile void *addr)
331 rte_write16_relaxed(value, addr);
334 static __rte_always_inline void
335 rte_write32(uint32_t value, volatile void *addr)
338 rte_write32_relaxed(value, addr);
341 static __rte_always_inline void
342 rte_write64(uint64_t value, volatile void *addr)
345 rte_write64_relaxed(value, addr);
348 #endif /* RTE_OVERRIDE_IO_H */
350 #endif /* _RTE_IO_H_ */