mem: move virtual area function in common directory
[dpdk.git] / lib / librte_eal / common / eal_private.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #ifndef _EAL_PRIVATE_H_
6 #define _EAL_PRIVATE_H_
7
8 #include <stdbool.h>
9 #include <stdint.h>
10 #include <stdio.h>
11
12 /**
13  * Initialize the memzone subsystem (private to eal).
14  *
15  * @return
16  *   - 0 on success
17  *   - Negative on error
18  */
19 int rte_eal_memzone_init(void);
20
21 /**
22  * Common log initialization function (private to eal).  Determines
23  * where log data is written when no call to rte_openlog_stream is
24  * in effect.
25  *
26  * @param default_log
27  *   The default log stream to be used.
28  * @return
29  *   - 0 on success
30  *   - Negative on error
31  */
32 void eal_log_set_default(FILE *default_log);
33
34 /**
35  * Fill configuration with number of physical and logical processors
36  *
37  * This function is private to EAL.
38  *
39  * Parse /proc/cpuinfo to get the number of physical and logical
40  * processors on the machine.
41  *
42  * @return
43  *   0 on success, negative on error
44  */
45 int rte_eal_cpu_init(void);
46
47 /**
48  * Map memory
49  *
50  * This function is private to EAL.
51  *
52  * Fill configuration structure with these infos, and return 0 on success.
53  *
54  * @return
55  *   0 on success, negative on error
56  */
57 int rte_eal_memory_init(void);
58
59 /**
60  * Configure timers
61  *
62  * This function is private to EAL.
63  *
64  * Mmap memory areas used by HPET (high precision event timer) that will
65  * provide our time reference, and configure the TSC frequency also for it
66  * to be used as a reference.
67  *
68  * @return
69  *   0 on success, negative on error
70  */
71 int rte_eal_timer_init(void);
72
73 /**
74  * Init the default log stream
75  *
76  * This function is private to EAL.
77  *
78  * @return
79  *   0 on success, negative on error
80  */
81 int rte_eal_log_init(const char *id, int facility);
82
83 /**
84  * Init tail queues for non-EAL library structures. This is to allow
85  * the rings, mempools, etc. lists to be shared among multiple processes
86  *
87  * This function is private to EAL
88  *
89  * @return
90  *    0 on success, negative on error
91  */
92 int rte_eal_tailqs_init(void);
93
94 /**
95  * Init interrupt handling.
96  *
97  * This function is private to EAL.
98  *
99  * @return
100  *  0 on success, negative on error
101  */
102 int rte_eal_intr_init(void);
103
104 /**
105  * Init alarm mechanism. This is to allow a callback be called after
106  * specific time.
107  *
108  * This function is private to EAL.
109  *
110  * @return
111  *  0 on success, negative on error
112  */
113 int rte_eal_alarm_init(void);
114
115 /**
116  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
117  * etc.) loaded.
118  *
119  * @param module_name
120  *      The module's name which need to be checked
121  *
122  * @return
123  *      -1 means some error happens(NULL pointer or open failure)
124  *      0  means the module not loaded
125  *      1  means the module loaded
126  */
127 int rte_eal_check_module(const char *module_name);
128
129 /**
130  * Get virtual area of specified size from the OS.
131  *
132  * This function is private to the EAL.
133  *
134  * @param requested_addr
135  *   Address where to request address space.
136  * @param size
137  *   Size of requested area.
138  * @param page_sz
139  *   Page size on which to align requested virtual area.
140  * @param flags
141  *   EAL_VIRTUAL_AREA_* flags.
142  * @param mmap_flags
143  *   Extra flags passed directly to mmap().
144  *
145  * @return
146  *   Virtual area address if successful.
147  *   NULL if unsuccessful.
148  */
149
150 #define EAL_VIRTUAL_AREA_ADDR_IS_HINT (1 << 0)
151 /**< don't fail if cannot get exact requested address. */
152 #define EAL_VIRTUAL_AREA_ALLOW_SHRINK (1 << 1)
153 /**< try getting smaller sized (decrement by page size) virtual areas if cannot
154  * get area of requested size.
155  */
156 #define EAL_VIRTUAL_AREA_UNMAP (1 << 2)
157 /**< immediately unmap reserved virtual area. */
158 void *
159 eal_get_virtual_area(void *requested_addr, size_t *size,
160                 size_t page_sz, int flags, int mmap_flags);
161
162 /**
163  * Get cpu core_id.
164  *
165  * This function is private to the EAL.
166  */
167 unsigned eal_cpu_core_id(unsigned lcore_id);
168
169 /**
170  * Check if cpu is present.
171  *
172  * This function is private to the EAL.
173  */
174 int eal_cpu_detected(unsigned lcore_id);
175
176 /**
177  * Set TSC frequency from precise value or estimation
178  *
179  * This function is private to the EAL.
180  */
181 void set_tsc_freq(void);
182
183 /**
184  * Get precise TSC frequency from system
185  *
186  * This function is private to the EAL.
187  */
188 uint64_t get_tsc_freq(void);
189
190 /**
191  * Get TSC frequency if the architecture supports.
192  *
193  * This function is private to the EAL.
194  *
195  * @return
196  *   The number of TSC cycles in one second.
197  *   Returns zero if the architecture support is not available.
198  */
199 uint64_t get_tsc_freq_arch(void);
200
201 /**
202  * Prepare physical memory mapping
203  * i.e. hugepages on Linux and
204  *      contigmem on BSD.
205  *
206  * This function is private to the EAL.
207  */
208 int rte_eal_hugepage_init(void);
209
210 /**
211  * Creates memory mapping in secondary process
212  * i.e. hugepages on Linux and
213  *      contigmem on BSD.
214  *
215  * This function is private to the EAL.
216  */
217 int rte_eal_hugepage_attach(void);
218
219 /**
220  * Find a bus capable of identifying a device.
221  *
222  * @param str
223  *   A device identifier (PCI address, virtual PMD name, ...).
224  *
225  * @return
226  *   A valid bus handle if found.
227  *   NULL if no bus is able to parse this device.
228  */
229 struct rte_bus *rte_bus_find_by_device_name(const char *str);
230
231 /**
232  * Create the unix channel for primary/secondary communication.
233  *
234  * @return
235  *   0 on success;
236  *   (<0) on failure.
237  */
238
239 int rte_mp_channel_init(void);
240
241 #endif /* _EAL_PRIVATE_H_ */