4 * Copyright(c) 2016 Cavium, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
39 * I/O device memory operations
41 * This file defines the generic API for I/O device memory read/write operations
45 #include <rte_common.h>
46 #include <rte_atomic.h>
51 * Read a 8-bit value from I/O device memory address *addr*.
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.
58 * I/O memory address to read the value from
63 rte_read8_relaxed(const volatile void *addr);
66 * Read a 16-bit value from I/O device memory address *addr*.
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.
73 * I/O memory address to read the value from
77 static inline uint16_t
78 rte_read16_relaxed(const volatile void *addr);
81 * Read a 32-bit value from I/O device memory address *addr*.
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.
88 * I/O memory address to read the value from
92 static inline uint32_t
93 rte_read32_relaxed(const volatile void *addr);
96 * Read a 64-bit value from I/O device memory address *addr*.
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.
103 * I/O memory address to read the value from
107 static inline uint64_t
108 rte_read64_relaxed(const volatile void *addr);
111 * Write a 8-bit value to I/O device memory address *addr*.
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.
120 * I/O memory address to write the value to
124 rte_write8_relaxed(uint8_t value, volatile void *addr);
127 * Write a 16-bit value to I/O device memory address *addr*.
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.
136 * I/O memory address to write the value to
139 rte_write16_relaxed(uint16_t value, volatile void *addr);
142 * Write a 32-bit value to I/O device memory address *addr*.
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.
151 * I/O memory address to write the value to
154 rte_write32_relaxed(uint32_t value, volatile void *addr);
157 * Write a 64-bit value to I/O device memory address *addr*.
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.
166 * I/O memory address to write the value to
169 rte_write64_relaxed(uint64_t value, volatile void *addr);
172 * Read a 8-bit value from I/O device memory address *addr*.
175 * I/O memory address to read the value from
179 static inline uint8_t
180 rte_read8(const volatile void *addr);
183 * Read a 16-bit value from I/O device memory address *addr*.
187 * I/O memory address to read the value from
191 static inline uint16_t
192 rte_read16(const volatile void *addr);
195 * Read a 32-bit value from I/O device memory address *addr*.
198 * I/O memory address to read the value from
202 static inline uint32_t
203 rte_read32(const volatile void *addr);
206 * Read a 64-bit value from I/O device memory address *addr*.
209 * I/O memory address to read the value from
213 static inline uint64_t
214 rte_read64(const volatile void *addr);
217 * Write a 8-bit value to I/O device memory address *addr*.
222 * I/O memory address to write the value to
226 rte_write8(uint8_t value, volatile void *addr);
229 * Write a 16-bit value to I/O device memory address *addr*.
234 * I/O memory address to write the value to
237 rte_write16(uint16_t value, volatile void *addr);
240 * Write a 32-bit value to I/O device memory address *addr*.
245 * I/O memory address to write the value to
248 rte_write32(uint32_t value, volatile void *addr);
251 * Write a 64-bit value to I/O device memory address *addr*.
256 * I/O memory address to write the value to
259 rte_write64(uint64_t value, volatile void *addr);
261 #endif /* __DOXYGEN__ */
263 #ifndef RTE_OVERRIDE_IO_H
265 static __rte_always_inline uint8_t
266 rte_read8_relaxed(const volatile void *addr)
268 return *(const volatile uint8_t *)addr;
271 static __rte_always_inline uint16_t
272 rte_read16_relaxed(const volatile void *addr)
274 return *(const volatile uint16_t *)addr;
277 static __rte_always_inline uint32_t
278 rte_read32_relaxed(const volatile void *addr)
280 return *(const volatile uint32_t *)addr;
283 static __rte_always_inline uint64_t
284 rte_read64_relaxed(const volatile void *addr)
286 return *(const volatile uint64_t *)addr;
289 static __rte_always_inline void
290 rte_write8_relaxed(uint8_t value, volatile void *addr)
292 *(volatile uint8_t *)addr = value;
295 static __rte_always_inline void
296 rte_write16_relaxed(uint16_t value, volatile void *addr)
298 *(volatile uint16_t *)addr = value;
301 static __rte_always_inline void
302 rte_write32_relaxed(uint32_t value, volatile void *addr)
304 *(volatile uint32_t *)addr = value;
307 static __rte_always_inline void
308 rte_write64_relaxed(uint64_t value, volatile void *addr)
310 *(volatile uint64_t *)addr = value;
313 static __rte_always_inline uint8_t
314 rte_read8(const volatile void *addr)
317 val = rte_read8_relaxed(addr);
322 static __rte_always_inline uint16_t
323 rte_read16(const volatile void *addr)
326 val = rte_read16_relaxed(addr);
331 static __rte_always_inline uint32_t
332 rte_read32(const volatile void *addr)
335 val = rte_read32_relaxed(addr);
340 static __rte_always_inline uint64_t
341 rte_read64(const volatile void *addr)
344 val = rte_read64_relaxed(addr);
349 static __rte_always_inline void
350 rte_write8(uint8_t value, volatile void *addr)
353 rte_write8_relaxed(value, addr);
356 static __rte_always_inline void
357 rte_write16(uint16_t value, volatile void *addr)
360 rte_write16_relaxed(value, addr);
363 static __rte_always_inline void
364 rte_write32(uint32_t value, volatile void *addr)
367 rte_write32_relaxed(value, addr);
370 static __rte_always_inline void
371 rte_write64(uint64_t value, volatile void *addr)
374 rte_write64_relaxed(value, addr);
377 #endif /* RTE_OVERRIDE_IO_H */
379 #endif /* _RTE_IO_H_ */