xref: /dpdk/lib/eal/windows/eal_windows.h (revision ae67895b507bb6af22263c79ba0d5c374b396485)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2020 Dmitry Kozlyuk
3  */
4 
5 #ifndef _EAL_WINDOWS_H_
6 #define _EAL_WINDOWS_H_
7 
8 /**
9  * @file Facilities private to Windows EAL
10  */
11 
12 #include <rte_errno.h>
13 #include <rte_windows.h>
14 
15 #include "eal_private.h"
16 
17 /**
18  * Log current function as not implemented and set rte_errno.
19  */
20 #define EAL_LOG_NOT_IMPLEMENTED() \
21 	do { \
22 		EAL_LOG(DEBUG, "%s() is not implemented", __func__); \
23 		rte_errno = ENOTSUP; \
24 	} while (0)
25 
26 /**
27  * Log current function as a stub.
28  */
29 #define EAL_LOG_STUB() \
30 	EAL_LOG(DEBUG, "Windows: %s() is a stub", __func__)
31 
32 /**
33  * Create a map of processors and cores on the system.
34  *
35  * @return
36  *  0 on success, (-1) on failure and rte_errno is set.
37  */
38 int eal_create_cpu_map(void);
39 
40 /**
41  * Get system NUMA node number for a socket ID.
42  *
43  * @param socket_id
44  *  Valid EAL socket ID.
45  * @return
46  *  NUMA node number to use with Win32 API.
47  */
48 unsigned int eal_socket_numa_node(unsigned int socket_id);
49 
50 /**
51  * Get pointer to the group affinity for the cpu.
52  *
53  * @param cpu_index
54  *  Index of the cpu, as it comes from rte_cpuset_t.
55  * @return
56  *  Pointer to the group affinity for the cpu.
57  */
58 PGROUP_AFFINITY eal_get_cpu_affinity(size_t cpu_index);
59 
60 /**
61  * Schedule code for execution in the interrupt thread.
62  *
63  * @param func
64  *  Function to call.
65  * @param arg
66  *  Argument to the called function.
67  * @return
68  *  0 on success, negative error code on failure.
69  */
70 int eal_intr_thread_schedule(void (*func)(void *arg), void *arg);
71 
72 /**
73  * Request interrupt thread to stop and wait its termination.
74  */
75 void eal_intr_thread_cancel(void);
76 
77 /**
78  * Open virt2phys driver interface device.
79  *
80  * @return 0 on success, (-1) on failure.
81  */
82 int eal_mem_virt2iova_init(void);
83 
84 /**
85  * Cleanup resources used for virtual to physical address translation.
86  */
87 void eal_mem_virt2iova_cleanup(void);
88 
89 /**
90  * Locate Win32 memory management routines in system libraries.
91  *
92  * @return 0 on success, (-1) on failure.
93  */
94 int eal_mem_win32api_init(void);
95 
96 /**
97  * Allocate new memory in hugepages on the specified NUMA node.
98  *
99  * @param size
100  *  Number of bytes to allocate. Must be a multiple of huge page size.
101  * @param socket_id
102  *  Socket ID.
103  * @return
104  *  Address of the memory allocated on success or NULL on failure.
105  */
106 void *eal_mem_alloc_socket(size_t size, int socket_id);
107 
108 /**
109  * Commit memory previously reserved with eal_mem_reserve()
110  * or decommitted from hugepages by eal_mem_decommit().
111  *
112  * @param requested_addr
113  *  Address within a reserved region. Must not be NULL.
114  * @param size
115  *  Number of bytes to commit. Must be a multiple of page size.
116  * @param socket_id
117  *  Socket ID to allocate on. Can be SOCKET_ID_ANY.
118  * @return
119  *  On success, address of the committed memory, that is, requested_addr.
120  *  On failure, NULL and rte_errno is set.
121  */
122 void *eal_mem_commit(void *requested_addr, size_t size, int socket_id);
123 
124 /**
125  * Put allocated or committed memory back into reserved state.
126  *
127  * @param addr
128  *  Address of the region to decommit.
129  * @param size
130  *  Number of bytes to decommit, must be the size of a page
131  *  (hugepage or regular one).
132  *
133  * The *addr* and *size* must match location and size
134  * of a previously allocated or committed region.
135  *
136  * @return
137  *  0 on success, (-1) on failure.
138  */
139 int eal_mem_decommit(void *addr, size_t size);
140 
141 #endif /* _EAL_WINDOWS_H_ */
142