xref: /f-stack/dpdk/lib/librte_eal/x86/include/rte_io.h (revision 2d9fd380)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016 Cavium, Inc
3  */
4 
5 #ifndef _RTE_IO_X86_H_
6 #define _RTE_IO_X86_H_
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include "rte_cpuflags.h"
13 
14 #define RTE_NATIVE_WRITE32_WC
15 #include "generic/rte_io.h"
16 
17 /**
18  * @internal
19  * MOVDIRI wrapper.
20  */
21 static __rte_always_inline void
__rte_x86_movdiri(uint32_t value,volatile void * addr)22 __rte_x86_movdiri(uint32_t value, volatile void *addr)
23 {
24 	asm volatile(
25 		/* MOVDIRI */
26 		".byte 0x40, 0x0f, 0x38, 0xf9, 0x02"
27 		:
28 		: "a" (value), "d" (addr));
29 }
30 
31 __rte_experimental
32 static __rte_always_inline void
rte_write32_wc_relaxed(uint32_t value,volatile void * addr)33 rte_write32_wc_relaxed(uint32_t value, volatile void *addr)
34 {
35 	static int _x86_movdiri_flag = -1;
36 
37 	if (_x86_movdiri_flag == 1) {
38 		__rte_x86_movdiri(value, addr);
39 	} else if (_x86_movdiri_flag == 0) {
40 		rte_write32_relaxed(value, addr);
41 	} else {
42 		_x86_movdiri_flag =
43 			(rte_cpu_get_flag_enabled(RTE_CPUFLAG_MOVDIRI) > 0);
44 		if (_x86_movdiri_flag == 1)
45 			__rte_x86_movdiri(value, addr);
46 		else
47 			rte_write32_relaxed(value, addr);
48 	}
49 }
50 
51 __rte_experimental
52 static __rte_always_inline void
rte_write32_wc(uint32_t value,volatile void * addr)53 rte_write32_wc(uint32_t value, volatile void *addr)
54 {
55 	/* gcc complains about calling this experimental function even
56 	 * when not using it. Hide it with ALLOW_EXPERIMENTAL_API.
57 	 */
58 #ifdef ALLOW_EXPERIMENTAL_API
59 	rte_wmb();
60 	rte_write32_wc_relaxed(value, addr);
61 #else
62 	rte_write32(value, addr);
63 #endif
64 }
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 #endif /* _RTE_IO_X86_H_ */
71