eal/windows: implement basic memory management
[dpdk.git] / lib / librte_eal / windows / eal_windows.h
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 /**
16  * Log current function as not implemented and set rte_errno.
17  */
18 #define EAL_LOG_NOT_IMPLEMENTED() \
19         do { \
20                 RTE_LOG(DEBUG, EAL, "%s() is not implemented\n", __func__); \
21                 rte_errno = ENOTSUP; \
22         } while (0)
23
24 /**
25  * Log current function as a stub.
26  */
27 #define EAL_LOG_STUB() \
28         RTE_LOG(DEBUG, EAL, "Windows: %s() is a stub\n", __func__)
29
30 /**
31  * Create a map of processors and cores on the system.
32  *
33  * @return
34  *  0 on success, (-1) on failure and rte_errno is set.
35  */
36 int eal_create_cpu_map(void);
37
38 /**
39  * Create a thread.
40  *
41  * @param thread
42  *   The location to store the thread id if successful.
43  * @return
44  *   0 for success, -1 if the thread is not created.
45  */
46 int eal_thread_create(pthread_t *thread);
47
48 /**
49  * Get system NUMA node number for a socket ID.
50  *
51  * @param socket_id
52  *  Valid EAL socket ID.
53  * @return
54  *  NUMA node number to use with Win32 API.
55  */
56 unsigned int eal_socket_numa_node(unsigned int socket_id);
57
58 /**
59  * Open virt2phys driver interface device.
60  *
61  * @return 0 on success, (-1) on failure.
62  */
63 int eal_mem_virt2iova_init(void);
64
65 /**
66  * Locate Win32 memory management routines in system libraries.
67  *
68  * @return 0 on success, (-1) on failure.
69  */
70 int eal_mem_win32api_init(void);
71
72 /**
73  * Allocate new memory in hugepages on the specified NUMA node.
74  *
75  * @param size
76  *  Number of bytes to allocate. Must be a multiple of huge page size.
77  * @param socket_id
78  *  Socket ID.
79  * @return
80  *  Address of the memory allocated on success or NULL on failure.
81  */
82 void *eal_mem_alloc_socket(size_t size, int socket_id);
83
84 /**
85  * Commit memory previously reserved with eal_mem_reserve()
86  * or decommitted from hugepages by eal_mem_decommit().
87  *
88  * @param requested_addr
89  *  Address within a reserved region. Must not be NULL.
90  * @param size
91  *  Number of bytes to commit. Must be a multiple of page size.
92  * @param socket_id
93  *  Socket ID to allocate on. Can be SOCKET_ID_ANY.
94  * @return
95  *  On success, address of the committed memory, that is, requested_addr.
96  *  On failure, NULL and rte_errno is set.
97  */
98 void *eal_mem_commit(void *requested_addr, size_t size, int socket_id);
99
100 /**
101  * Put allocated or committed memory back into reserved state.
102  *
103  * @param addr
104  *  Address of the region to decommit.
105  * @param size
106  *  Number of bytes to decommit, must be the size of a page
107  *  (hugepage or regular one).
108  *
109  * The *addr* and *size* must match location and size
110  * of a previously allocated or committed region.
111  *
112  * @return
113  *  0 on success, (-1) on failure.
114  */
115 int eal_mem_decommit(void *addr, size_t size);
116
117 #endif /* _EAL_WINDOWS_H_ */