1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
5 #ifndef _EAL_PRIVATE_H_
6 #define _EAL_PRIVATE_H_
13 #include <rte_lcore.h>
14 #include <rte_memory.h>
17 * Structure storing internal configuration (per-lcore)
20 pthread_t thread_id; /**< pthread identifier */
21 int pipe_master2slave[2]; /**< communication pipe with master */
22 int pipe_slave2master[2]; /**< communication pipe with master */
24 lcore_function_t * volatile f; /**< function to call */
25 void * volatile arg; /**< argument of function */
26 volatile int ret; /**< return value of function */
28 volatile enum rte_lcore_state_t state; /**< lcore state */
29 unsigned int socket_id; /**< physical socket id for this lcore */
30 unsigned int core_id; /**< core number on socket for this lcore */
31 int core_index; /**< relative index, starting from 0 */
32 uint8_t core_role; /**< role of core eg: OFF, RTE, SERVICE */
34 rte_cpuset_t cpuset; /**< cpu set which the lcore affinity to */
37 extern struct lcore_config lcore_config[RTE_MAX_LCORE];
40 * The global RTE configuration structure.
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. */
50 /** Primary or secondary configuration */
51 enum rte_proc_type_t process_type;
53 /** PA or VA mapping mode */
54 enum rte_iova_mode iova_mode;
57 * Pointer to memory configuration, which may be shared across multiple
60 struct rte_mem_config *mem_config;
64 * Get the global configuration structure.
67 * A pointer to the global configuration structure.
69 struct rte_config *rte_eal_get_configuration(void);
72 * Initialize the memzone subsystem (private to eal).
78 int rte_eal_memzone_init(void);
81 * Common log initialization function (private to eal). Determines
82 * where log data is written when no call to rte_openlog_stream is
86 * The default log stream to be used.
91 void eal_log_set_default(FILE *default_log);
94 * Fill configuration with number of physical and logical processors
96 * This function is private to EAL.
98 * Parse /proc/cpuinfo to get the number of physical and logical
99 * processors on the machine.
102 * 0 on success, negative on error
104 int rte_eal_cpu_init(void);
107 * Create memseg lists
109 * This function is private to EAL.
111 * Preallocate virtual memory.
114 * 0 on success, negative on error
116 int rte_eal_memseg_init(void);
121 * This function is private to EAL.
123 * Fill configuration structure with these infos, and return 0 on success.
126 * 0 on success, negative on error
128 int rte_eal_memory_init(void);
133 * This function is private to EAL.
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.
140 * 0 on success, negative on error
142 int rte_eal_timer_init(void);
145 * Init the default log stream
147 * This function is private to EAL.
150 * 0 on success, negative on error
152 int rte_eal_log_init(const char *id, int facility);
155 * Save the log regexp for later
157 int rte_log_save_regexp(const char *type, int priority);
158 int rte_log_save_pattern(const char *pattern, int priority);
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
164 * This function is private to EAL
167 * 0 on success, negative on error
169 int rte_eal_tailqs_init(void);
172 * Init interrupt handling.
174 * This function is private to EAL.
177 * 0 on success, negative on error
179 int rte_eal_intr_init(void);
182 * Init alarm mechanism. This is to allow a callback be called after
185 * This function is private to EAL.
188 * 0 on success, negative on error
190 int rte_eal_alarm_init(void);
193 * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
197 * The module's name which need to be checked
200 * -1 means some error happens(NULL pointer or open failure)
201 * 0 means the module not loaded
202 * 1 means the module loaded
204 int rte_eal_check_module(const char *module_name);
207 * Memory reservation flags.
209 enum eal_mem_reserve_flags {
211 * Reserve hugepages. May be unsupported by some platforms.
213 EAL_RESERVE_HUGEPAGES = 1 << 0,
215 * Force reserving memory at the requested address.
216 * This can be a destructive action depending on the implementation.
218 * @see RTE_MAP_FORCE_ADDRESS for description of possible consequences
219 * (although implementations are not required to use it).
221 EAL_RESERVE_FORCE_ADDRESS = 1 << 1
225 * Get virtual area of specified size from the OS.
227 * This function is private to the EAL.
229 * @param requested_addr
230 * Address where to request address space.
232 * Size of requested area.
234 * Page size on which to align requested virtual area.
236 * EAL_VIRTUAL_AREA_* flags.
237 * @param reserve_flags
238 * Extra flags passed directly to eal_mem_reserve().
241 * Virtual area address if successful.
242 * NULL if unsuccessful.
245 #define EAL_VIRTUAL_AREA_ADDR_IS_HINT (1 << 0)
246 /**< don't fail if cannot get exact requested address. */
247 #define EAL_VIRTUAL_AREA_ALLOW_SHRINK (1 << 1)
248 /**< try getting smaller sized (decrement by page size) virtual areas if cannot
249 * get area of requested size.
251 #define EAL_VIRTUAL_AREA_UNMAP (1 << 2)
252 /**< immediately unmap reserved virtual area. */
254 eal_get_virtual_area(void *requested_addr, size_t *size,
255 size_t page_sz, int flags, int reserve_flags);
260 * This function is private to the EAL.
262 unsigned eal_cpu_core_id(unsigned lcore_id);
265 * Check if cpu is present.
267 * This function is private to the EAL.
269 int eal_cpu_detected(unsigned lcore_id);
272 * Set TSC frequency from precise value or estimation
274 * This function is private to the EAL.
276 void set_tsc_freq(void);
279 * Get precise TSC frequency from system
281 * This function is private to the EAL.
283 uint64_t get_tsc_freq(void);
286 * Get TSC frequency if the architecture supports.
288 * This function is private to the EAL.
291 * The number of TSC cycles in one second.
292 * Returns zero if the architecture support is not available.
294 uint64_t get_tsc_freq_arch(void);
297 * Prepare physical memory mapping
298 * i.e. hugepages on Linux and
301 * This function is private to the EAL.
303 int rte_eal_hugepage_init(void);
306 * Creates memory mapping in secondary process
307 * i.e. hugepages on Linux and
310 * This function is private to the EAL.
312 int rte_eal_hugepage_attach(void);
315 * Find a bus capable of identifying a device.
318 * A device identifier (PCI address, virtual PMD name, ...).
321 * A valid bus handle if found.
322 * NULL if no bus is able to parse this device.
324 struct rte_bus *rte_bus_find_by_device_name(const char *str);
327 * Create the unix channel for primary/secondary communication.
333 int rte_mp_channel_init(void);
336 * Primary/secondary communication cleanup.
338 void rte_mp_channel_cleanup(void);
342 * Parse a device string and store its information in an
343 * rte_devargs structure.
345 * A device description is split by layers of abstraction of the device:
346 * bus, class and driver. Each layer will offer a set of properties that
347 * can be applied either to configure or recognize a device.
349 * This function will parse those properties and prepare the rte_devargs
350 * to be given to each layers for processing.
352 * Note: if the "data" field of the devargs points to devstr,
353 * then no dynamic allocation is performed and the rte_devargs
354 * can be safely discarded.
356 * Otherwise ``data`` will hold a workable copy of devstr, that will be
357 * used by layers descriptors within rte_devargs. In this case,
358 * any rte_devargs should be cleaned-up before being freed.
361 * rte_devargs structure to fill.
368 * Negative errno values on error (rte_errno is set).
371 rte_devargs_layers_parse(struct rte_devargs *devargs,
375 * probe a device at local process.
378 * Device arguments including bus, class and driver properties.
380 * new device be probed as output.
382 * 0 on success, negative on error.
384 int local_dev_probe(const char *devargs, struct rte_device **new_dev);
387 * Hotplug remove a given device from a specific bus at local process.
390 * Data structure of the device to remove.
392 * 0 on success, negative on error.
394 int local_dev_remove(struct rte_device *dev);
397 * Iterate over all buses to find the corresponding bus to handle the sigbus
399 * @param failure_addr
400 * Pointer of the fault address of the sigbus error.
403 * 0 success to handle the sigbus.
404 * -1 failed to handle the sigbus
405 * 1 no bus can handler the sigbus
407 int rte_bus_sigbus_handler(const void *failure_addr);
411 * Register the sigbus handler.
414 * - On success, zero.
415 * - On failure, a negative value.
418 dev_sigbus_handler_register(void);
422 * Unregister the sigbus handler.
425 * - On success, zero.
426 * - On failure, a negative value.
429 dev_sigbus_handler_unregister(void);
432 * Get OS-specific EAL mapping base address.
435 eal_get_baseaddr(void);
438 eal_malloc_no_trace(const char *type, size_t size, unsigned int align);
440 void eal_free_no_trace(void *addr);
442 /** Options for eal_file_open(). */
443 enum eal_open_flags {
444 /** Open file for reading. */
445 EAL_OPEN_READONLY = 0x00,
446 /** Open file for reading and writing. */
447 EAL_OPEN_READWRITE = 0x02,
449 * Create the file if it doesn't exist.
450 * New files are only accessible to the owner (0600 equivalent).
452 EAL_OPEN_CREATE = 0x04
456 * Open or create a file.
461 * A combination of eal_open_flags controlling operation and FD behavior.
463 * Open file descriptor on success, (-1) on failure and rte_errno is set.
466 eal_file_open(const char *path, int flags);
468 /** File locking operation. */
470 EAL_FLOCK_SHARED, /**< Acquire a shared lock. */
471 EAL_FLOCK_EXCLUSIVE, /**< Acquire an exclusive lock. */
472 EAL_FLOCK_UNLOCK /**< Release a previously taken lock. */
475 /** Behavior on file locking conflict. */
476 enum eal_flock_mode {
477 EAL_FLOCK_WAIT, /**< Wait until the file gets unlocked to lock it. */
478 EAL_FLOCK_RETURN /**< Return immediately if the file is locked. */
482 * Lock or unlock the file.
484 * On failure @code rte_errno @endcode is set to the error code
485 * specified by POSIX flock(3) description.
488 * Opened file descriptor.
490 * Operation to perform.
492 * Behavior on conflict.
494 * 0 on success, (-1) on failure.
497 eal_file_lock(int fd, enum eal_flock_op op, enum eal_flock_mode mode);
500 * Truncate or extend the file to the specified size.
502 * On failure @code rte_errno @endcode is set to the error code
503 * specified by POSIX ftruncate(3) description.
506 * Opened file descriptor.
510 * 0 on success, (-1) on failure.
513 eal_file_truncate(int fd, ssize_t size);
516 * Reserve a region of virtual memory.
518 * Use eal_mem_free() to free reserved memory.
520 * @param requested_addr
521 * A desired reservation address which must be page-aligned.
522 * The system might not respect it.
523 * NULL means the address will be chosen by the system.
525 * Reservation size. Must be a multiple of system page size.
527 * Reservation options, a combination of eal_mem_reserve_flags.
529 * Starting address of the reserved area on success, NULL on failure.
530 * Callers must not access this memory until remapping it.
533 eal_mem_reserve(void *requested_addr, size_t size, int flags);
536 * Free memory obtained by eal_mem_reserve() or eal_mem_alloc().
538 * If *virt* and *size* describe a part of the reserved region,
539 * only this part of the region is freed (accurately up to the system
540 * page size). If *virt* points to allocated memory, *size* must match
541 * the one specified on allocation. The behavior is undefined
542 * if the memory pointed by *virt* is obtained from another source
546 * A virtual address in a region previously reserved.
548 * Number of bytes to unreserve.
551 eal_mem_free(void *virt, size_t size);
554 * Configure memory region inclusion into dumps.
557 * Starting address of the region.
559 * Size of the region.
561 * True to include memory into dumps, false to exclude.
563 * 0 on success, (-1) on failure and rte_errno is set.
566 eal_mem_set_dump(void *virt, size_t size, bool dump);
568 #endif /* _EAL_PRIVATE_H_ */