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