8a9d493f0c54624b473e98174a8bdf1014e70e25
[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 #include <rte_dev.h>
13 #include <rte_lcore.h>
14
15 /**
16  * Structure storing internal configuration (per-lcore)
17  */
18 struct lcore_config {
19         pthread_t thread_id;       /**< pthread identifier */
20         int pipe_master2slave[2];  /**< communication pipe with master */
21         int pipe_slave2master[2];  /**< communication pipe with master */
22
23         lcore_function_t * volatile f; /**< function to call */
24         void * volatile arg;       /**< argument of function */
25         volatile int ret;          /**< return value of function */
26
27         volatile enum rte_lcore_state_t state; /**< lcore state */
28         unsigned int socket_id;    /**< physical socket id for this lcore */
29         unsigned int core_id;      /**< core number on socket for this lcore */
30         int core_index;            /**< relative index, starting from 0 */
31         uint8_t core_role;         /**< role of core eg: OFF, RTE, SERVICE */
32         uint8_t detected;          /**< true if lcore was detected */
33
34         rte_cpuset_t cpuset;       /**< cpu set which the lcore affinity to */
35 };
36
37 extern struct lcore_config lcore_config[RTE_MAX_LCORE];
38
39 /**
40  * The global RTE configuration structure.
41  */
42 struct rte_config {
43         uint32_t master_lcore;       /**< Id of the master lcore */
44         uint32_t lcore_count;        /**< Number of available logical cores. */
45         uint32_t numa_node_count;    /**< Number of detected NUMA nodes. */
46         uint32_t numa_nodes[RTE_MAX_NUMA_NODES]; /**< List of detected NUMA nodes. */
47         uint32_t service_lcore_count;/**< Number of available service cores. */
48         enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
49
50         /** Primary or secondary configuration */
51         enum rte_proc_type_t process_type;
52
53         /** PA or VA mapping mode */
54         enum rte_iova_mode iova_mode;
55
56         /**
57          * Pointer to memory configuration, which may be shared across multiple
58          * DPDK instances
59          */
60         struct rte_mem_config *mem_config;
61 } __attribute__((__packed__));
62
63 /**
64  * Get the global configuration structure.
65  *
66  * @return
67  *   A pointer to the global configuration structure.
68  */
69 struct rte_config *rte_eal_get_configuration(void);
70
71 /**
72  * Initialize the memzone subsystem (private to eal).
73  *
74  * @return
75  *   - 0 on success
76  *   - Negative on error
77  */
78 int rte_eal_memzone_init(void);
79
80 /**
81  * Common log initialization function (private to eal).  Determines
82  * where log data is written when no call to rte_openlog_stream is
83  * in effect.
84  *
85  * @param default_log
86  *   The default log stream to be used.
87  * @return
88  *   - 0 on success
89  *   - Negative on error
90  */
91 void eal_log_set_default(FILE *default_log);
92
93 /**
94  * Fill configuration with number of physical and logical processors
95  *
96  * This function is private to EAL.
97  *
98  * Parse /proc/cpuinfo to get the number of physical and logical
99  * processors on the machine.
100  *
101  * @return
102  *   0 on success, negative on error
103  */
104 int rte_eal_cpu_init(void);
105
106 /**
107  * Create memseg lists
108  *
109  * This function is private to EAL.
110  *
111  * Preallocate virtual memory.
112  *
113  * @return
114  *   0 on success, negative on error
115  */
116 int rte_eal_memseg_init(void);
117
118 /**
119  * Map memory
120  *
121  * This function is private to EAL.
122  *
123  * Fill configuration structure with these infos, and return 0 on success.
124  *
125  * @return
126  *   0 on success, negative on error
127  */
128 int rte_eal_memory_init(void);
129
130 /**
131  * Configure timers
132  *
133  * This function is private to EAL.
134  *
135  * Mmap memory areas used by HPET (high precision event timer) that will
136  * provide our time reference, and configure the TSC frequency also for it
137  * to be used as a reference.
138  *
139  * @return
140  *   0 on success, negative on error
141  */
142 int rte_eal_timer_init(void);
143
144 /**
145  * Init the default log stream
146  *
147  * This function is private to EAL.
148  *
149  * @return
150  *   0 on success, negative on error
151  */
152 int rte_eal_log_init(const char *id, int facility);
153
154 /**
155  * Save the log regexp for later
156  */
157 int rte_log_save_regexp(const char *type, int priority);
158 int rte_log_save_pattern(const char *pattern, int priority);
159
160 /**
161  * Init tail queues for non-EAL library structures. This is to allow
162  * the rings, mempools, etc. lists to be shared among multiple processes
163  *
164  * This function is private to EAL
165  *
166  * @return
167  *    0 on success, negative on error
168  */
169 int rte_eal_tailqs_init(void);
170
171 /**
172  * Init interrupt handling.
173  *
174  * This function is private to EAL.
175  *
176  * @return
177  *  0 on success, negative on error
178  */
179 int rte_eal_intr_init(void);
180
181 /**
182  * Init alarm mechanism. This is to allow a callback be called after
183  * specific time.
184  *
185  * This function is private to EAL.
186  *
187  * @return
188  *  0 on success, negative on error
189  */
190 int rte_eal_alarm_init(void);
191
192 /**
193  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
194  * etc.) loaded.
195  *
196  * @param module_name
197  *      The module's name which need to be checked
198  *
199  * @return
200  *      -1 means some error happens(NULL pointer or open failure)
201  *      0  means the module not loaded
202  *      1  means the module loaded
203  */
204 int rte_eal_check_module(const char *module_name);
205
206 /**
207  * Get virtual area of specified size from the OS.
208  *
209  * This function is private to the EAL.
210  *
211  * @param requested_addr
212  *   Address where to request address space.
213  * @param size
214  *   Size of requested area.
215  * @param page_sz
216  *   Page size on which to align requested virtual area.
217  * @param flags
218  *   EAL_VIRTUAL_AREA_* flags.
219  * @param mmap_flags
220  *   Extra flags passed directly to mmap().
221  *
222  * @return
223  *   Virtual area address if successful.
224  *   NULL if unsuccessful.
225  */
226
227 #define EAL_VIRTUAL_AREA_ADDR_IS_HINT (1 << 0)
228 /**< don't fail if cannot get exact requested address. */
229 #define EAL_VIRTUAL_AREA_ALLOW_SHRINK (1 << 1)
230 /**< try getting smaller sized (decrement by page size) virtual areas if cannot
231  * get area of requested size.
232  */
233 #define EAL_VIRTUAL_AREA_UNMAP (1 << 2)
234 /**< immediately unmap reserved virtual area. */
235 void *
236 eal_get_virtual_area(void *requested_addr, size_t *size,
237                 size_t page_sz, int flags, int mmap_flags);
238
239 /**
240  * Get cpu core_id.
241  *
242  * This function is private to the EAL.
243  */
244 unsigned eal_cpu_core_id(unsigned lcore_id);
245
246 /**
247  * Check if cpu is present.
248  *
249  * This function is private to the EAL.
250  */
251 int eal_cpu_detected(unsigned lcore_id);
252
253 /**
254  * Set TSC frequency from precise value or estimation
255  *
256  * This function is private to the EAL.
257  */
258 void set_tsc_freq(void);
259
260 /**
261  * Get precise TSC frequency from system
262  *
263  * This function is private to the EAL.
264  */
265 uint64_t get_tsc_freq(void);
266
267 /**
268  * Get TSC frequency if the architecture supports.
269  *
270  * This function is private to the EAL.
271  *
272  * @return
273  *   The number of TSC cycles in one second.
274  *   Returns zero if the architecture support is not available.
275  */
276 uint64_t get_tsc_freq_arch(void);
277
278 /**
279  * Prepare physical memory mapping
280  * i.e. hugepages on Linux and
281  *      contigmem on BSD.
282  *
283  * This function is private to the EAL.
284  */
285 int rte_eal_hugepage_init(void);
286
287 /**
288  * Creates memory mapping in secondary process
289  * i.e. hugepages on Linux and
290  *      contigmem on BSD.
291  *
292  * This function is private to the EAL.
293  */
294 int rte_eal_hugepage_attach(void);
295
296 /**
297  * Find a bus capable of identifying a device.
298  *
299  * @param str
300  *   A device identifier (PCI address, virtual PMD name, ...).
301  *
302  * @return
303  *   A valid bus handle if found.
304  *   NULL if no bus is able to parse this device.
305  */
306 struct rte_bus *rte_bus_find_by_device_name(const char *str);
307
308 /**
309  * Create the unix channel for primary/secondary communication.
310  *
311  * @return
312  *   0 on success;
313  *   (<0) on failure.
314  */
315 int rte_mp_channel_init(void);
316
317 /**
318  * Primary/secondary communication cleanup.
319  */
320 void rte_mp_channel_cleanup(void);
321
322 /**
323  * @internal
324  * Parse a device string and store its information in an
325  * rte_devargs structure.
326  *
327  * A device description is split by layers of abstraction of the device:
328  * bus, class and driver. Each layer will offer a set of properties that
329  * can be applied either to configure or recognize a device.
330  *
331  * This function will parse those properties and prepare the rte_devargs
332  * to be given to each layers for processing.
333  *
334  * Note: if the "data" field of the devargs points to devstr,
335  * then no dynamic allocation is performed and the rte_devargs
336  * can be safely discarded.
337  *
338  * Otherwise ``data`` will hold a workable copy of devstr, that will be
339  * used by layers descriptors within rte_devargs. In this case,
340  * any rte_devargs should be cleaned-up before being freed.
341  *
342  * @param da
343  *   rte_devargs structure to fill.
344  *
345  * @param devstr
346  *   Device string.
347  *
348  * @return
349  *   0 on success.
350  *   Negative errno values on error (rte_errno is set).
351  */
352 int
353 rte_devargs_layers_parse(struct rte_devargs *devargs,
354                          const char *devstr);
355
356 /*
357  * probe a device at local process.
358  *
359  * @param devargs
360  *   Device arguments including bus, class and driver properties.
361  * @param new_dev
362  *   new device be probed as output.
363  * @return
364  *   0 on success, negative on error.
365  */
366 int local_dev_probe(const char *devargs, struct rte_device **new_dev);
367
368 /**
369  * Hotplug remove a given device from a specific bus at local process.
370  *
371  * @param dev
372  *   Data structure of the device to remove.
373  * @return
374  *   0 on success, negative on error.
375  */
376 int local_dev_remove(struct rte_device *dev);
377
378 /**
379  * Iterate over all buses to find the corresponding bus to handle the sigbus
380  * error.
381  * @param failure_addr
382  *      Pointer of the fault address of the sigbus error.
383  *
384  * @return
385  *       0 success to handle the sigbus.
386  *      -1 failed to handle the sigbus
387  *       1 no bus can handler the sigbus
388  */
389 int rte_bus_sigbus_handler(const void *failure_addr);
390
391 /**
392  * @internal
393  * Register the sigbus handler.
394  *
395  * @return
396  *   - On success, zero.
397  *   - On failure, a negative value.
398  */
399 int
400 dev_sigbus_handler_register(void);
401
402 /**
403  * @internal
404  * Unregister the sigbus handler.
405  *
406  * @return
407  *   - On success, zero.
408  *   - On failure, a negative value.
409  */
410 int
411 dev_sigbus_handler_unregister(void);
412
413 /**
414  * Check if the option is registered.
415  *
416  * @param option
417  *  The option to be parsed.
418  *
419  * @return
420  *  0 on success
421  * @return
422  *  -1 on fail
423  */
424 int
425 rte_option_parse(const char *opt);
426
427 /**
428  * Iterate through the registered options and execute the associated
429  * callback if enabled.
430  */
431 void
432 rte_option_init(void);
433
434 /**
435  * Iterate through the registered options and show the associated
436  * usage string.
437  */
438 void
439 rte_option_usage(void);
440
441 /**
442  * Get OS-specific EAL mapping base address.
443  */
444 uint64_t
445 eal_get_baseaddr(void);
446
447 #endif /* _EAL_PRIVATE_H_ */