eal: add write combining store
[dpdk.git] / lib / librte_eal / x86 / include / rte_io.h
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
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 static __rte_always_inline void
32 rte_write32_wc_relaxed(uint32_t value, volatile void *addr)
33 {
34         static int _x86_movdiri_flag = -1;
35
36         if (_x86_movdiri_flag == 1) {
37                 __rte_x86_movdiri(value, addr);
38         } else if (_x86_movdiri_flag == 0) {
39                 rte_write32_relaxed(value, addr);
40         } else {
41                 _x86_movdiri_flag =
42                         (rte_cpu_get_flag_enabled(RTE_CPUFLAG_MOVDIRI) > 0);
43                 if (_x86_movdiri_flag == 1)
44                         __rte_x86_movdiri(value, addr);
45                 else
46                         rte_write32_relaxed(value, addr);
47         }
48 }
49
50 static __rte_always_inline void
51 rte_write32_wc(uint32_t value, volatile void *addr)
52 {
53         rte_wmb();
54         rte_write32_wc_relaxed(value, addr);
55 }
56
57 #ifdef __cplusplus
58 }
59 #endif
60
61 #endif /* _RTE_IO_X86_H_ */