xref: /dpdk/lib/eal/common/eal_private.h (revision 5dc68f2be8adea7aad24dc56dad57ec9a3bfe413)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2010-2018 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _EAL_PRIVATE_H_
699a2dd95SBruce Richardson #define _EAL_PRIVATE_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson #include <stdbool.h>
999a2dd95SBruce Richardson #include <stdint.h>
1099a2dd95SBruce Richardson #include <stdio.h>
11f1f6ebc0SWilliam Tu #include <sys/queue.h>
1299a2dd95SBruce Richardson 
13fbd59c8eSDavid Marchand #include <dev_driver.h>
1499a2dd95SBruce Richardson #include <rte_lcore.h>
15ae67895bSDavid Marchand #include <rte_log.h>
1699a2dd95SBruce Richardson #include <rte_memory.h>
1799a2dd95SBruce Richardson 
1899a2dd95SBruce Richardson #include "eal_internal_cfg.h"
1999a2dd95SBruce Richardson 
2099a2dd95SBruce Richardson /**
2199a2dd95SBruce Richardson  * Structure storing internal configuration (per-lcore)
2299a2dd95SBruce Richardson  */
2399a2dd95SBruce Richardson struct lcore_config {
248b0a1b8cSTyler Retzlaff 	rte_thread_t thread_id;    /**< thread identifier */
2599a2dd95SBruce Richardson 	int pipe_main2worker[2];   /**< communication pipe with main */
2699a2dd95SBruce Richardson 	int pipe_worker2main[2];   /**< communication pipe with main */
2799a2dd95SBruce Richardson 
282a7a42a5STyler Retzlaff 	RTE_ATOMIC(lcore_function_t *) volatile f; /**< function to call */
2999a2dd95SBruce Richardson 	void * volatile arg;       /**< argument of function */
3099a2dd95SBruce Richardson 	volatile int ret;          /**< return value of function */
3199a2dd95SBruce Richardson 
322a7a42a5STyler Retzlaff 	volatile RTE_ATOMIC(enum rte_lcore_state_t) state; /**< lcore state */
3399a2dd95SBruce Richardson 	unsigned int socket_id;    /**< physical socket id for this lcore */
3499a2dd95SBruce Richardson 	unsigned int core_id;      /**< core number on socket for this lcore */
3599a2dd95SBruce Richardson 	int core_index;            /**< relative index, starting from 0 */
3699a2dd95SBruce Richardson 	uint8_t core_role;         /**< role of core eg: OFF, RTE, SERVICE */
3799a2dd95SBruce Richardson 
3899a2dd95SBruce Richardson 	rte_cpuset_t cpuset;       /**< cpu set which the lcore affinity to */
3999a2dd95SBruce Richardson };
4099a2dd95SBruce Richardson 
4199a2dd95SBruce Richardson extern struct lcore_config lcore_config[RTE_MAX_LCORE];
4299a2dd95SBruce Richardson 
4399a2dd95SBruce Richardson /**
4499a2dd95SBruce Richardson  * The global RTE configuration structure.
4599a2dd95SBruce Richardson  */
4699a2dd95SBruce Richardson struct rte_config {
4799a2dd95SBruce Richardson 	uint32_t main_lcore;         /**< Id of the main lcore */
4899a2dd95SBruce Richardson 	uint32_t lcore_count;        /**< Number of available logical cores. */
4999a2dd95SBruce Richardson 	uint32_t numa_node_count;    /**< Number of detected NUMA nodes. */
5099a2dd95SBruce Richardson 	uint32_t numa_nodes[RTE_MAX_NUMA_NODES]; /**< List of detected NUMA nodes. */
5199a2dd95SBruce Richardson 	uint32_t service_lcore_count;/**< Number of available service cores. */
5299a2dd95SBruce Richardson 	enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
5399a2dd95SBruce Richardson 
5499a2dd95SBruce Richardson 	/** Primary or secondary configuration */
5599a2dd95SBruce Richardson 	enum rte_proc_type_t process_type;
5699a2dd95SBruce Richardson 
5799a2dd95SBruce Richardson 	/** PA or VA mapping mode */
5899a2dd95SBruce Richardson 	enum rte_iova_mode iova_mode;
5999a2dd95SBruce Richardson 
6099a2dd95SBruce Richardson 	/**
6199a2dd95SBruce Richardson 	 * Pointer to memory configuration, which may be shared across multiple
6299a2dd95SBruce Richardson 	 * DPDK instances
6399a2dd95SBruce Richardson 	 */
6499a2dd95SBruce Richardson 	struct rte_mem_config *mem_config;
65*5dc68f2bSAndre Muezerie };
6699a2dd95SBruce Richardson 
6799a2dd95SBruce Richardson /**
6899a2dd95SBruce Richardson  * Get the global configuration structure.
6999a2dd95SBruce Richardson  *
7099a2dd95SBruce Richardson  * @return
7199a2dd95SBruce Richardson  *   A pointer to the global configuration structure.
7299a2dd95SBruce Richardson  */
7399a2dd95SBruce Richardson struct rte_config *rte_eal_get_configuration(void);
7499a2dd95SBruce Richardson 
7599a2dd95SBruce Richardson /**
7699a2dd95SBruce Richardson  * Initialize the memzone subsystem (private to eal).
7799a2dd95SBruce Richardson  *
7899a2dd95SBruce Richardson  * @return
7999a2dd95SBruce Richardson  *   - 0 on success
8099a2dd95SBruce Richardson  *   - Negative on error
8199a2dd95SBruce Richardson  */
8299a2dd95SBruce Richardson int rte_eal_memzone_init(void);
8399a2dd95SBruce Richardson 
8499a2dd95SBruce Richardson /**
8599a2dd95SBruce Richardson  * Fill configuration with number of physical and logical processors
8699a2dd95SBruce Richardson  *
8799a2dd95SBruce Richardson  * This function is private to EAL.
8899a2dd95SBruce Richardson  *
8999a2dd95SBruce Richardson  * Parse /proc/cpuinfo to get the number of physical and logical
9099a2dd95SBruce Richardson  * processors on the machine.
9199a2dd95SBruce Richardson  *
9299a2dd95SBruce Richardson  * @return
9399a2dd95SBruce Richardson  *   0 on success, negative on error
9499a2dd95SBruce Richardson  */
9599a2dd95SBruce Richardson int rte_eal_cpu_init(void);
9699a2dd95SBruce Richardson 
9799a2dd95SBruce Richardson /**
98e168b189SDavid Christensen  * Check for architecture supported MMU.
99e168b189SDavid Christensen  *
100e168b189SDavid Christensen  * This function is private to EAL.
101e168b189SDavid Christensen  */
102e168b189SDavid Christensen bool eal_mmu_supported(void);
103e168b189SDavid Christensen 
104e168b189SDavid Christensen /**
10599a2dd95SBruce Richardson  * Create memseg lists
10699a2dd95SBruce Richardson  *
10799a2dd95SBruce Richardson  * This function is private to EAL.
10899a2dd95SBruce Richardson  *
10999a2dd95SBruce Richardson  * Preallocate virtual memory.
11099a2dd95SBruce Richardson  *
11199a2dd95SBruce Richardson  * @return
11299a2dd95SBruce Richardson  *   0 on success, negative on error
11399a2dd95SBruce Richardson  */
11499a2dd95SBruce Richardson int rte_eal_memseg_init(void);
11599a2dd95SBruce Richardson 
11699a2dd95SBruce Richardson /**
11799a2dd95SBruce Richardson  * Map memory
11899a2dd95SBruce Richardson  *
11999a2dd95SBruce Richardson  * This function is private to EAL.
12099a2dd95SBruce Richardson  *
12199a2dd95SBruce Richardson  * Fill configuration structure with these infos, and return 0 on success.
12299a2dd95SBruce Richardson  *
12399a2dd95SBruce Richardson  * @return
12499a2dd95SBruce Richardson  *   0 on success, negative on error
12599a2dd95SBruce Richardson  */
1264dd146e5SArtemy Kovalyov int rte_eal_memory_init(void)
1274dd146e5SArtemy Kovalyov 	__rte_shared_locks_required(rte_mcfg_mem_get_lock());
12899a2dd95SBruce Richardson 
12999a2dd95SBruce Richardson /**
13099a2dd95SBruce Richardson  * Configure timers
13199a2dd95SBruce Richardson  *
13299a2dd95SBruce Richardson  * This function is private to EAL.
13399a2dd95SBruce Richardson  *
13499a2dd95SBruce Richardson  * Mmap memory areas used by HPET (high precision event timer) that will
13599a2dd95SBruce Richardson  * provide our time reference, and configure the TSC frequency also for it
13699a2dd95SBruce Richardson  * to be used as a reference.
13799a2dd95SBruce Richardson  *
13899a2dd95SBruce Richardson  * @return
13999a2dd95SBruce Richardson  *   0 on success, negative on error
14099a2dd95SBruce Richardson  */
14199a2dd95SBruce Richardson int rte_eal_timer_init(void);
14299a2dd95SBruce Richardson 
14399a2dd95SBruce Richardson /**
14499a2dd95SBruce Richardson  * Init tail queues for non-EAL library structures. This is to allow
14599a2dd95SBruce Richardson  * the rings, mempools, etc. lists to be shared among multiple processes
14699a2dd95SBruce Richardson  *
14799a2dd95SBruce Richardson  * This function is private to EAL
14899a2dd95SBruce Richardson  *
14999a2dd95SBruce Richardson  * @return
15099a2dd95SBruce Richardson  *    0 on success, negative on error
15199a2dd95SBruce Richardson  */
15299a2dd95SBruce Richardson int rte_eal_tailqs_init(void);
15399a2dd95SBruce Richardson 
15499a2dd95SBruce Richardson /**
15599a2dd95SBruce Richardson  * Init interrupt handling.
15699a2dd95SBruce Richardson  *
15799a2dd95SBruce Richardson  * This function is private to EAL.
15899a2dd95SBruce Richardson  *
15999a2dd95SBruce Richardson  * @return
16099a2dd95SBruce Richardson  *  0 on success, negative on error
16199a2dd95SBruce Richardson  */
16299a2dd95SBruce Richardson int rte_eal_intr_init(void);
16399a2dd95SBruce Richardson 
16499a2dd95SBruce Richardson /**
16599a2dd95SBruce Richardson  * Init alarm mechanism. This is to allow a callback be called after
16699a2dd95SBruce Richardson  * specific time.
16799a2dd95SBruce Richardson  *
16899a2dd95SBruce Richardson  * This function is private to EAL.
16999a2dd95SBruce Richardson  *
17099a2dd95SBruce Richardson  * @return
17199a2dd95SBruce Richardson  *  0 on success, negative on error
17299a2dd95SBruce Richardson  */
17399a2dd95SBruce Richardson int rte_eal_alarm_init(void);
17499a2dd95SBruce Richardson 
17599a2dd95SBruce Richardson /**
17690b13ab8SHarman Kalra  * Alarm mechanism cleanup.
17790b13ab8SHarman Kalra  *
17890b13ab8SHarman Kalra  * This function is private to EAL.
17990b13ab8SHarman Kalra  *
18090b13ab8SHarman Kalra  * @return
18190b13ab8SHarman Kalra  *  0 on success, negative on error
18290b13ab8SHarman Kalra  */
18390b13ab8SHarman Kalra void rte_eal_alarm_cleanup(void);
18490b13ab8SHarman Kalra 
18590b13ab8SHarman Kalra /**
18699a2dd95SBruce Richardson  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
18799a2dd95SBruce Richardson  * etc.) loaded.
18899a2dd95SBruce Richardson  *
18999a2dd95SBruce Richardson  * @param module_name
19099a2dd95SBruce Richardson  *	The module's name which need to be checked
19199a2dd95SBruce Richardson  *
19299a2dd95SBruce Richardson  * @return
19399a2dd95SBruce Richardson  *	-1 means some error happens(NULL pointer or open failure)
19499a2dd95SBruce Richardson  *	0  means the module not loaded
19599a2dd95SBruce Richardson  *	1  means the module loaded
19699a2dd95SBruce Richardson  */
19799a2dd95SBruce Richardson int rte_eal_check_module(const char *module_name);
19899a2dd95SBruce Richardson 
19999a2dd95SBruce Richardson /**
20099a2dd95SBruce Richardson  * Memory reservation flags.
20199a2dd95SBruce Richardson  */
20299a2dd95SBruce Richardson enum eal_mem_reserve_flags {
20399a2dd95SBruce Richardson 	/**
20499a2dd95SBruce Richardson 	 * Reserve hugepages. May be unsupported by some platforms.
20599a2dd95SBruce Richardson 	 */
20699a2dd95SBruce Richardson 	EAL_RESERVE_HUGEPAGES = 1 << 0,
20799a2dd95SBruce Richardson 	/**
20899a2dd95SBruce Richardson 	 * Force reserving memory at the requested address.
20999a2dd95SBruce Richardson 	 * This can be a destructive action depending on the implementation.
21099a2dd95SBruce Richardson 	 *
21199a2dd95SBruce Richardson 	 * @see RTE_MAP_FORCE_ADDRESS for description of possible consequences
21299a2dd95SBruce Richardson 	 *      (although implementations are not required to use it).
21399a2dd95SBruce Richardson 	 */
21499a2dd95SBruce Richardson 	EAL_RESERVE_FORCE_ADDRESS = 1 << 1
21599a2dd95SBruce Richardson };
21699a2dd95SBruce Richardson 
21799a2dd95SBruce Richardson /**
21899a2dd95SBruce Richardson  * Get virtual area of specified size from the OS.
21999a2dd95SBruce Richardson  *
22099a2dd95SBruce Richardson  * This function is private to the EAL.
22199a2dd95SBruce Richardson  *
22299a2dd95SBruce Richardson  * @param requested_addr
22399a2dd95SBruce Richardson  *   Address where to request address space.
22499a2dd95SBruce Richardson  * @param size
22599a2dd95SBruce Richardson  *   Size of requested area.
22699a2dd95SBruce Richardson  * @param page_sz
22799a2dd95SBruce Richardson  *   Page size on which to align requested virtual area.
22899a2dd95SBruce Richardson  * @param flags
22999a2dd95SBruce Richardson  *   EAL_VIRTUAL_AREA_* flags.
23099a2dd95SBruce Richardson  * @param reserve_flags
23199a2dd95SBruce Richardson  *   Extra flags passed directly to eal_mem_reserve().
23299a2dd95SBruce Richardson  *
23399a2dd95SBruce Richardson  * @return
23499a2dd95SBruce Richardson  *   Virtual area address if successful.
23599a2dd95SBruce Richardson  *   NULL if unsuccessful.
23699a2dd95SBruce Richardson  */
23799a2dd95SBruce Richardson 
23899a2dd95SBruce Richardson #define EAL_VIRTUAL_AREA_ADDR_IS_HINT (1 << 0)
23999a2dd95SBruce Richardson /**< don't fail if cannot get exact requested address. */
24099a2dd95SBruce Richardson #define EAL_VIRTUAL_AREA_ALLOW_SHRINK (1 << 1)
24199a2dd95SBruce Richardson /**< try getting smaller sized (decrement by page size) virtual areas if cannot
24299a2dd95SBruce Richardson  * get area of requested size.
24399a2dd95SBruce Richardson  */
24499a2dd95SBruce Richardson #define EAL_VIRTUAL_AREA_UNMAP (1 << 2)
24599a2dd95SBruce Richardson /**< immediately unmap reserved virtual area. */
24699a2dd95SBruce Richardson void *
24799a2dd95SBruce Richardson eal_get_virtual_area(void *requested_addr, size_t *size,
24899a2dd95SBruce Richardson 		size_t page_sz, int flags, int reserve_flags);
24999a2dd95SBruce Richardson 
25099a2dd95SBruce Richardson /**
25199a2dd95SBruce Richardson  * Initialize a memory segment list and create its backing storage.
25299a2dd95SBruce Richardson  *
25399a2dd95SBruce Richardson  * @param msl
25499a2dd95SBruce Richardson  *  Memory segment list to be filled.
25599a2dd95SBruce Richardson  * @param name
25699a2dd95SBruce Richardson  *  Name for the backing storage.
25799a2dd95SBruce Richardson  * @param page_sz
25899a2dd95SBruce Richardson  *  Size of segment pages in the MSL.
25999a2dd95SBruce Richardson  * @param n_segs
26099a2dd95SBruce Richardson  *  Number of segments.
26199a2dd95SBruce Richardson  * @param socket_id
26299a2dd95SBruce Richardson  *  Socket ID. Must not be SOCKET_ID_ANY.
26399a2dd95SBruce Richardson  * @param heap
26499a2dd95SBruce Richardson  *  Mark MSL as pointing to a heap.
26599a2dd95SBruce Richardson  * @return
26699a2dd95SBruce Richardson  *  0 on success, (-1) on failure and rte_errno is set.
26799a2dd95SBruce Richardson  */
26899a2dd95SBruce Richardson int
26999a2dd95SBruce Richardson eal_memseg_list_init_named(struct rte_memseg_list *msl, const char *name,
27099a2dd95SBruce Richardson 	uint64_t page_sz, int n_segs, int socket_id, bool heap);
27199a2dd95SBruce Richardson 
27299a2dd95SBruce Richardson /**
27399a2dd95SBruce Richardson  * Initialize memory segment list and create its backing storage
27499a2dd95SBruce Richardson  * with a name corresponding to MSL parameters.
27599a2dd95SBruce Richardson  *
27699a2dd95SBruce Richardson  * @param type_msl_idx
27799a2dd95SBruce Richardson  *  Index of the MSL among other MSLs of the same socket and page size.
27899a2dd95SBruce Richardson  *
27999a2dd95SBruce Richardson  * @see eal_memseg_list_init_named for remaining parameters description.
28099a2dd95SBruce Richardson  */
28199a2dd95SBruce Richardson int
28299a2dd95SBruce Richardson eal_memseg_list_init(struct rte_memseg_list *msl, uint64_t page_sz,
28399a2dd95SBruce Richardson 	int n_segs, int socket_id, int type_msl_idx, bool heap);
28499a2dd95SBruce Richardson 
28599a2dd95SBruce Richardson /**
28699a2dd95SBruce Richardson  * Reserve VA space for a memory segment list
28799a2dd95SBruce Richardson  * previously initialized with eal_memseg_list_init().
28899a2dd95SBruce Richardson  *
28999a2dd95SBruce Richardson  * @param msl
29099a2dd95SBruce Richardson  *  Initialized memory segment list with page size defined.
29199a2dd95SBruce Richardson  * @param reserve_flags
29299a2dd95SBruce Richardson  *  Extra memory reservation flags. Can be 0 if unnecessary.
29399a2dd95SBruce Richardson  * @return
29499a2dd95SBruce Richardson  *  0 on success, (-1) on failure and rte_errno is set.
29599a2dd95SBruce Richardson  */
29699a2dd95SBruce Richardson int
29799a2dd95SBruce Richardson eal_memseg_list_alloc(struct rte_memseg_list *msl, int reserve_flags);
29899a2dd95SBruce Richardson 
29999a2dd95SBruce Richardson /**
30099a2dd95SBruce Richardson  * Populate MSL, each segment is one page long.
30199a2dd95SBruce Richardson  *
30299a2dd95SBruce Richardson  * @param msl
30399a2dd95SBruce Richardson  *  Initialized memory segment list with page size defined.
30499a2dd95SBruce Richardson  * @param addr
30599a2dd95SBruce Richardson  *  Starting address of list segments.
30699a2dd95SBruce Richardson  * @param n_segs
30799a2dd95SBruce Richardson  *  Number of segments to populate.
30899a2dd95SBruce Richardson  */
30999a2dd95SBruce Richardson void
31099a2dd95SBruce Richardson eal_memseg_list_populate(struct rte_memseg_list *msl, void *addr, int n_segs);
31199a2dd95SBruce Richardson 
31299a2dd95SBruce Richardson /**
31399a2dd95SBruce Richardson  * Distribute available memory between MSLs.
31499a2dd95SBruce Richardson  *
31599a2dd95SBruce Richardson  * @return
31699a2dd95SBruce Richardson  *  0 on success, (-1) on failure.
31799a2dd95SBruce Richardson  */
31899a2dd95SBruce Richardson int
31999a2dd95SBruce Richardson eal_dynmem_memseg_lists_init(void);
32099a2dd95SBruce Richardson 
32199a2dd95SBruce Richardson /**
32299a2dd95SBruce Richardson  * Preallocate hugepages for dynamic allocation.
32399a2dd95SBruce Richardson  *
32499a2dd95SBruce Richardson  * @return
32599a2dd95SBruce Richardson  *  0 on success, (-1) on failure.
32699a2dd95SBruce Richardson  */
32799a2dd95SBruce Richardson int
32899a2dd95SBruce Richardson eal_dynmem_hugepage_init(void);
32999a2dd95SBruce Richardson 
33099a2dd95SBruce Richardson /**
33199a2dd95SBruce Richardson  * Given the list of hugepage sizes and the number of pages thereof,
33299a2dd95SBruce Richardson  * calculate the best number of pages of each size to fulfill the request
33399a2dd95SBruce Richardson  * for RAM on each NUMA node.
33499a2dd95SBruce Richardson  *
33599a2dd95SBruce Richardson  * @param memory
33699a2dd95SBruce Richardson  *  Amounts of memory requested for each NUMA node of RTE_MAX_NUMA_NODES.
33799a2dd95SBruce Richardson  * @param hp_info
33899a2dd95SBruce Richardson  *  Information about hugepages of different size.
33999a2dd95SBruce Richardson  * @param hp_used
34099a2dd95SBruce Richardson  *  Receives information about used hugepages of each size.
34199a2dd95SBruce Richardson  * @param num_hp_info
34299a2dd95SBruce Richardson  *  Number of elements in hp_info and hp_used.
34399a2dd95SBruce Richardson  * @return
34499a2dd95SBruce Richardson  *  0 on success, (-1) on failure.
34599a2dd95SBruce Richardson  */
34699a2dd95SBruce Richardson int
34799a2dd95SBruce Richardson eal_dynmem_calc_num_pages_per_socket(
34899a2dd95SBruce Richardson 		uint64_t *memory, struct hugepage_info *hp_info,
34999a2dd95SBruce Richardson 		struct hugepage_info *hp_used, unsigned int num_hp_info);
35099a2dd95SBruce Richardson 
35199a2dd95SBruce Richardson /**
35299a2dd95SBruce Richardson  * Get cpu core_id.
35399a2dd95SBruce Richardson  *
35499a2dd95SBruce Richardson  * This function is private to the EAL.
35599a2dd95SBruce Richardson  */
35699a2dd95SBruce Richardson unsigned eal_cpu_core_id(unsigned lcore_id);
35799a2dd95SBruce Richardson 
35899a2dd95SBruce Richardson /**
35999a2dd95SBruce Richardson  * Check if cpu is present.
36099a2dd95SBruce Richardson  *
36199a2dd95SBruce Richardson  * This function is private to the EAL.
36299a2dd95SBruce Richardson  */
36399a2dd95SBruce Richardson int eal_cpu_detected(unsigned lcore_id);
36499a2dd95SBruce Richardson 
36599a2dd95SBruce Richardson /**
36699a2dd95SBruce Richardson  * Set TSC frequency from precise value or estimation
36799a2dd95SBruce Richardson  *
36899a2dd95SBruce Richardson  * This function is private to the EAL.
36999a2dd95SBruce Richardson  */
37099a2dd95SBruce Richardson void set_tsc_freq(void);
37199a2dd95SBruce Richardson 
37299a2dd95SBruce Richardson /**
37399a2dd95SBruce Richardson  * Get precise TSC frequency from system
37499a2dd95SBruce Richardson  *
37599a2dd95SBruce Richardson  * This function is private to the EAL.
37699a2dd95SBruce Richardson  */
377dbdf3d55SIsaac Boukris uint64_t get_tsc_freq(uint64_t arch_hz);
37899a2dd95SBruce Richardson 
37999a2dd95SBruce Richardson /**
38099a2dd95SBruce Richardson  * Get TSC frequency if the architecture supports.
38199a2dd95SBruce Richardson  *
38299a2dd95SBruce Richardson  * This function is private to the EAL.
38399a2dd95SBruce Richardson  *
38499a2dd95SBruce Richardson  * @return
38599a2dd95SBruce Richardson  *   The number of TSC cycles in one second.
38699a2dd95SBruce Richardson  *   Returns zero if the architecture support is not available.
38799a2dd95SBruce Richardson  */
38899a2dd95SBruce Richardson uint64_t get_tsc_freq_arch(void);
38999a2dd95SBruce Richardson 
39099a2dd95SBruce Richardson /**
39199a2dd95SBruce Richardson  * Allocate a free lcore to associate to a non-EAL thread.
39299a2dd95SBruce Richardson  *
39399a2dd95SBruce Richardson  * @return
39499a2dd95SBruce Richardson  *   - the id of a lcore with role ROLE_NON_EAL on success.
39599a2dd95SBruce Richardson  *   - RTE_MAX_LCORE if none was available or initializing was refused (see
39699a2dd95SBruce Richardson  *     rte_lcore_callback_register).
39799a2dd95SBruce Richardson  */
39899a2dd95SBruce Richardson unsigned int eal_lcore_non_eal_allocate(void);
39999a2dd95SBruce Richardson 
40099a2dd95SBruce Richardson /**
40199a2dd95SBruce Richardson  * Release the lcore used by a non-EAL thread.
40299a2dd95SBruce Richardson  * Counterpart of eal_lcore_non_eal_allocate().
40399a2dd95SBruce Richardson  *
40499a2dd95SBruce Richardson  * @param lcore_id
40599a2dd95SBruce Richardson  *   The lcore with role ROLE_NON_EAL to release.
40699a2dd95SBruce Richardson  */
40799a2dd95SBruce Richardson void eal_lcore_non_eal_release(unsigned int lcore_id);
40899a2dd95SBruce Richardson 
40999a2dd95SBruce Richardson /**
41099a2dd95SBruce Richardson  * Prepare physical memory mapping
41199a2dd95SBruce Richardson  * i.e. hugepages on Linux and
41299a2dd95SBruce Richardson  *      contigmem on BSD.
41399a2dd95SBruce Richardson  *
41499a2dd95SBruce Richardson  * This function is private to the EAL.
41599a2dd95SBruce Richardson  */
41699a2dd95SBruce Richardson int rte_eal_hugepage_init(void);
41799a2dd95SBruce Richardson 
41899a2dd95SBruce Richardson /**
41999a2dd95SBruce Richardson  * Creates memory mapping in secondary process
42099a2dd95SBruce Richardson  * i.e. hugepages on Linux and
42199a2dd95SBruce Richardson  *      contigmem on BSD.
42299a2dd95SBruce Richardson  *
42399a2dd95SBruce Richardson  * This function is private to the EAL.
42499a2dd95SBruce Richardson  */
42599a2dd95SBruce Richardson int rte_eal_hugepage_attach(void);
42699a2dd95SBruce Richardson 
42799a2dd95SBruce Richardson /**
42899a2dd95SBruce Richardson  * Detaches all memory mappings from a process.
42999a2dd95SBruce Richardson  *
43099a2dd95SBruce Richardson  * This function is private to the EAL.
43199a2dd95SBruce Richardson  */
43299a2dd95SBruce Richardson int rte_eal_memory_detach(void);
43399a2dd95SBruce Richardson 
43499a2dd95SBruce Richardson /**
43599a2dd95SBruce Richardson  * Find a bus capable of identifying a device.
43699a2dd95SBruce Richardson  *
43799a2dd95SBruce Richardson  * @param str
43899a2dd95SBruce Richardson  *   A device identifier (PCI address, virtual PMD name, ...).
43999a2dd95SBruce Richardson  *
44099a2dd95SBruce Richardson  * @return
44199a2dd95SBruce Richardson  *   A valid bus handle if found.
44299a2dd95SBruce Richardson  *   NULL if no bus is able to parse this device.
44399a2dd95SBruce Richardson  */
44499a2dd95SBruce Richardson struct rte_bus *rte_bus_find_by_device_name(const char *str);
44599a2dd95SBruce Richardson 
44699a2dd95SBruce Richardson /**
4471cab1a40SKevin Laatz  * For each device on the buses, call the driver-specific function for
4481cab1a40SKevin Laatz  * device cleanup.
4491cab1a40SKevin Laatz  *
4501cab1a40SKevin Laatz  * @return
4511cab1a40SKevin Laatz  * 0 for successful cleanup
4521cab1a40SKevin Laatz  * !0 otherwise
4531cab1a40SKevin Laatz  */
4541cab1a40SKevin Laatz int eal_bus_cleanup(void);
4551cab1a40SKevin Laatz 
4561cab1a40SKevin Laatz /**
45799a2dd95SBruce Richardson  * Create the unix channel for primary/secondary communication.
45899a2dd95SBruce Richardson  *
45999a2dd95SBruce Richardson  * @return
46099a2dd95SBruce Richardson  *   0 on success;
46199a2dd95SBruce Richardson  *   (<0) on failure.
46299a2dd95SBruce Richardson  */
46399a2dd95SBruce Richardson int rte_mp_channel_init(void);
46499a2dd95SBruce Richardson 
46599a2dd95SBruce Richardson /**
46699a2dd95SBruce Richardson  * Primary/secondary communication cleanup.
46799a2dd95SBruce Richardson  */
46899a2dd95SBruce Richardson void rte_mp_channel_cleanup(void);
46999a2dd95SBruce Richardson 
47099a2dd95SBruce Richardson /**
47199a2dd95SBruce Richardson  * @internal
47299a2dd95SBruce Richardson  * Parse a device string and store its information in an
47399a2dd95SBruce Richardson  * rte_devargs structure.
47499a2dd95SBruce Richardson  *
47599a2dd95SBruce Richardson  * A device description is split by layers of abstraction of the device:
47699a2dd95SBruce Richardson  * bus, class and driver. Each layer will offer a set of properties that
47799a2dd95SBruce Richardson  * can be applied either to configure or recognize a device.
47899a2dd95SBruce Richardson  *
47999a2dd95SBruce Richardson  * This function will parse those properties and prepare the rte_devargs
48099a2dd95SBruce Richardson  * to be given to each layers for processing.
48199a2dd95SBruce Richardson  *
48299a2dd95SBruce Richardson  * Note: if the "data" field of the devargs points to devstr,
48399a2dd95SBruce Richardson  * then no dynamic allocation is performed and the rte_devargs
48499a2dd95SBruce Richardson  * can be safely discarded.
48599a2dd95SBruce Richardson  *
48699a2dd95SBruce Richardson  * Otherwise ``data`` will hold a workable copy of devstr, that will be
48799a2dd95SBruce Richardson  * used by layers descriptors within rte_devargs. In this case,
48899a2dd95SBruce Richardson  * any rte_devargs should be cleaned-up before being freed.
48999a2dd95SBruce Richardson  *
49099a2dd95SBruce Richardson  * @param da
49199a2dd95SBruce Richardson  *   rte_devargs structure to fill.
49299a2dd95SBruce Richardson  *
49399a2dd95SBruce Richardson  * @param devstr
49499a2dd95SBruce Richardson  *   Device string.
49599a2dd95SBruce Richardson  *
49699a2dd95SBruce Richardson  * @return
49799a2dd95SBruce Richardson  *   0 on success.
49899a2dd95SBruce Richardson  *   Negative errno values on error (rte_errno is set).
49999a2dd95SBruce Richardson  */
50099a2dd95SBruce Richardson int
50199a2dd95SBruce Richardson rte_devargs_layers_parse(struct rte_devargs *devargs,
50299a2dd95SBruce Richardson 			 const char *devstr);
50399a2dd95SBruce Richardson 
50499a2dd95SBruce Richardson /*
50599a2dd95SBruce Richardson  * probe a device at local process.
50699a2dd95SBruce Richardson  *
50799a2dd95SBruce Richardson  * @param devargs
50899a2dd95SBruce Richardson  *   Device arguments including bus, class and driver properties.
50999a2dd95SBruce Richardson  * @param new_dev
51099a2dd95SBruce Richardson  *   new device be probed as output.
51199a2dd95SBruce Richardson  * @return
51299a2dd95SBruce Richardson  *   0 on success, negative on error.
51399a2dd95SBruce Richardson  */
51499a2dd95SBruce Richardson int local_dev_probe(const char *devargs, struct rte_device **new_dev);
51599a2dd95SBruce Richardson 
51699a2dd95SBruce Richardson /**
51799a2dd95SBruce Richardson  * Hotplug remove a given device from a specific bus at local process.
51899a2dd95SBruce Richardson  *
51999a2dd95SBruce Richardson  * @param dev
52099a2dd95SBruce Richardson  *   Data structure of the device to remove.
52199a2dd95SBruce Richardson  * @return
52299a2dd95SBruce Richardson  *   0 on success, negative on error.
52399a2dd95SBruce Richardson  */
52499a2dd95SBruce Richardson int local_dev_remove(struct rte_device *dev);
52599a2dd95SBruce Richardson 
52699a2dd95SBruce Richardson /**
52799a2dd95SBruce Richardson  * Iterate over all buses to find the corresponding bus to handle the sigbus
52899a2dd95SBruce Richardson  * error.
52999a2dd95SBruce Richardson  * @param failure_addr
53099a2dd95SBruce Richardson  *	Pointer of the fault address of the sigbus error.
53199a2dd95SBruce Richardson  *
53299a2dd95SBruce Richardson  * @return
53399a2dd95SBruce Richardson  *	 0 success to handle the sigbus.
53499a2dd95SBruce Richardson  *	-1 failed to handle the sigbus
53599a2dd95SBruce Richardson  *	 1 no bus can handler the sigbus
53699a2dd95SBruce Richardson  */
53799a2dd95SBruce Richardson int rte_bus_sigbus_handler(const void *failure_addr);
53899a2dd95SBruce Richardson 
53999a2dd95SBruce Richardson /**
54099a2dd95SBruce Richardson  * Get OS-specific EAL mapping base address.
54199a2dd95SBruce Richardson  */
54299a2dd95SBruce Richardson uint64_t
54399a2dd95SBruce Richardson eal_get_baseaddr(void);
54499a2dd95SBruce Richardson 
54599a2dd95SBruce Richardson void *
54699a2dd95SBruce Richardson eal_malloc_no_trace(const char *type, size_t size, unsigned int align);
54799a2dd95SBruce Richardson 
54899a2dd95SBruce Richardson void eal_free_no_trace(void *addr);
54999a2dd95SBruce Richardson 
55099a2dd95SBruce Richardson /** Options for eal_file_open(). */
55199a2dd95SBruce Richardson enum eal_open_flags {
55299a2dd95SBruce Richardson 	/** Open file for reading. */
55399a2dd95SBruce Richardson 	EAL_OPEN_READONLY = 0x00,
55499a2dd95SBruce Richardson 	/** Open file for reading and writing. */
55599a2dd95SBruce Richardson 	EAL_OPEN_READWRITE = 0x02,
55699a2dd95SBruce Richardson 	/**
55799a2dd95SBruce Richardson 	 * Create the file if it doesn't exist.
55899a2dd95SBruce Richardson 	 * New files are only accessible to the owner (0600 equivalent).
55999a2dd95SBruce Richardson 	 */
56099a2dd95SBruce Richardson 	EAL_OPEN_CREATE = 0x04
56199a2dd95SBruce Richardson };
56299a2dd95SBruce Richardson 
56399a2dd95SBruce Richardson /**
56499a2dd95SBruce Richardson  * Open or create a file.
56599a2dd95SBruce Richardson  *
56699a2dd95SBruce Richardson  * @param path
56799a2dd95SBruce Richardson  *  Path to the file.
56899a2dd95SBruce Richardson  * @param flags
56999a2dd95SBruce Richardson  *  A combination of eal_open_flags controlling operation and FD behavior.
57099a2dd95SBruce Richardson  * @return
57199a2dd95SBruce Richardson  *  Open file descriptor on success, (-1) on failure and rte_errno is set.
57299a2dd95SBruce Richardson  */
57399a2dd95SBruce Richardson int
57499a2dd95SBruce Richardson eal_file_open(const char *path, int flags);
57599a2dd95SBruce Richardson 
57699a2dd95SBruce Richardson /** File locking operation. */
57799a2dd95SBruce Richardson enum eal_flock_op {
57899a2dd95SBruce Richardson 	EAL_FLOCK_SHARED,    /**< Acquire a shared lock. */
57999a2dd95SBruce Richardson 	EAL_FLOCK_EXCLUSIVE, /**< Acquire an exclusive lock. */
58099a2dd95SBruce Richardson 	EAL_FLOCK_UNLOCK     /**< Release a previously taken lock. */
58199a2dd95SBruce Richardson };
58299a2dd95SBruce Richardson 
58399a2dd95SBruce Richardson /** Behavior on file locking conflict. */
58499a2dd95SBruce Richardson enum eal_flock_mode {
58599a2dd95SBruce Richardson 	EAL_FLOCK_WAIT,  /**< Wait until the file gets unlocked to lock it. */
58699a2dd95SBruce Richardson 	EAL_FLOCK_RETURN /**< Return immediately if the file is locked. */
58799a2dd95SBruce Richardson };
58899a2dd95SBruce Richardson 
58999a2dd95SBruce Richardson /**
59099a2dd95SBruce Richardson  * Lock or unlock the file.
59199a2dd95SBruce Richardson  *
59299a2dd95SBruce Richardson  * On failure @code rte_errno @endcode is set to the error code
59399a2dd95SBruce Richardson  * specified by POSIX flock(3) description.
59499a2dd95SBruce Richardson  *
59599a2dd95SBruce Richardson  * @param fd
59699a2dd95SBruce Richardson  *  Opened file descriptor.
59799a2dd95SBruce Richardson  * @param op
59899a2dd95SBruce Richardson  *  Operation to perform.
59999a2dd95SBruce Richardson  * @param mode
60099a2dd95SBruce Richardson  *  Behavior on conflict.
60199a2dd95SBruce Richardson  * @return
60299a2dd95SBruce Richardson  *  0 on success, (-1) on failure.
60399a2dd95SBruce Richardson  */
60499a2dd95SBruce Richardson int
60599a2dd95SBruce Richardson eal_file_lock(int fd, enum eal_flock_op op, enum eal_flock_mode mode);
60699a2dd95SBruce Richardson 
60799a2dd95SBruce Richardson /**
60899a2dd95SBruce Richardson  * Truncate or extend the file to the specified size.
60999a2dd95SBruce Richardson  *
61099a2dd95SBruce Richardson  * On failure @code rte_errno @endcode is set to the error code
61199a2dd95SBruce Richardson  * specified by POSIX ftruncate(3) description.
61299a2dd95SBruce Richardson  *
61399a2dd95SBruce Richardson  * @param fd
61499a2dd95SBruce Richardson  *  Opened file descriptor.
61599a2dd95SBruce Richardson  * @param size
61699a2dd95SBruce Richardson  *  Desired file size.
61799a2dd95SBruce Richardson  * @return
61899a2dd95SBruce Richardson  *  0 on success, (-1) on failure.
61999a2dd95SBruce Richardson  */
62099a2dd95SBruce Richardson int
62199a2dd95SBruce Richardson eal_file_truncate(int fd, ssize_t size);
62299a2dd95SBruce Richardson 
62399a2dd95SBruce Richardson /**
62499a2dd95SBruce Richardson  * Reserve a region of virtual memory.
62599a2dd95SBruce Richardson  *
62699a2dd95SBruce Richardson  * Use eal_mem_free() to free reserved memory.
62799a2dd95SBruce Richardson  *
62899a2dd95SBruce Richardson  * @param requested_addr
62999a2dd95SBruce Richardson  *  A desired reservation address which must be page-aligned.
63099a2dd95SBruce Richardson  *  The system might not respect it.
63199a2dd95SBruce Richardson  *  NULL means the address will be chosen by the system.
63299a2dd95SBruce Richardson  * @param size
63399a2dd95SBruce Richardson  *  Reservation size. Must be a multiple of system page size.
63499a2dd95SBruce Richardson  * @param flags
63599a2dd95SBruce Richardson  *  Reservation options, a combination of eal_mem_reserve_flags.
63699a2dd95SBruce Richardson  * @returns
63799a2dd95SBruce Richardson  *  Starting address of the reserved area on success, NULL on failure.
63899a2dd95SBruce Richardson  *  Callers must not access this memory until remapping it.
63999a2dd95SBruce Richardson  */
64099a2dd95SBruce Richardson void *
64199a2dd95SBruce Richardson eal_mem_reserve(void *requested_addr, size_t size, int flags);
64299a2dd95SBruce Richardson 
64399a2dd95SBruce Richardson /**
64499a2dd95SBruce Richardson  * Free memory obtained by eal_mem_reserve() and possibly allocated.
64599a2dd95SBruce Richardson  *
64699a2dd95SBruce Richardson  * If *virt* and *size* describe a part of the reserved region,
64799a2dd95SBruce Richardson  * only this part of the region is freed (accurately up to the system
64899a2dd95SBruce Richardson  * page size). If *virt* points to allocated memory, *size* must match
64999a2dd95SBruce Richardson  * the one specified on allocation. The behavior is undefined
65099a2dd95SBruce Richardson  * if the memory pointed by *virt* is obtained from another source
65199a2dd95SBruce Richardson  * than listed above.
65299a2dd95SBruce Richardson  *
65399a2dd95SBruce Richardson  * @param virt
65499a2dd95SBruce Richardson  *  A virtual address in a region previously reserved.
65599a2dd95SBruce Richardson  * @param size
65699a2dd95SBruce Richardson  *  Number of bytes to unreserve.
65799a2dd95SBruce Richardson  */
65899a2dd95SBruce Richardson void
65999a2dd95SBruce Richardson eal_mem_free(void *virt, size_t size);
66099a2dd95SBruce Richardson 
66199a2dd95SBruce Richardson /**
66299a2dd95SBruce Richardson  * Configure memory region inclusion into dumps.
66399a2dd95SBruce Richardson  *
66499a2dd95SBruce Richardson  * @param virt
66599a2dd95SBruce Richardson  *  Starting address of the region.
66699a2dd95SBruce Richardson  * @param size
66799a2dd95SBruce Richardson  *  Size of the region.
66899a2dd95SBruce Richardson  * @param dump
66999a2dd95SBruce Richardson  *  True to include memory into dumps, false to exclude.
67099a2dd95SBruce Richardson  * @return
67199a2dd95SBruce Richardson  *  0 on success, (-1) on failure and rte_errno is set.
67299a2dd95SBruce Richardson  */
67399a2dd95SBruce Richardson int
67499a2dd95SBruce Richardson eal_mem_set_dump(void *virt, size_t size, bool dump);
67599a2dd95SBruce Richardson 
67699a2dd95SBruce Richardson /**
67799a2dd95SBruce Richardson  * Sets the runtime directory of DPDK
67899a2dd95SBruce Richardson  *
67999a2dd95SBruce Richardson  * @param run_dir
68099a2dd95SBruce Richardson  *   The new runtime directory path of DPDK
68199a2dd95SBruce Richardson  * @return
68299a2dd95SBruce Richardson  *   0 on success, (-1) on failure.
68399a2dd95SBruce Richardson  */
68499a2dd95SBruce Richardson int
68536514d8dSStephen Hemminger eal_set_runtime_dir(const char *run_dir);
68699a2dd95SBruce Richardson 
68799a2dd95SBruce Richardson /**
68899a2dd95SBruce Richardson  * Get the internal configuration structure.
68999a2dd95SBruce Richardson  *
69099a2dd95SBruce Richardson  * @return
69199a2dd95SBruce Richardson  *   A pointer to the internal configuration structure.
69299a2dd95SBruce Richardson  */
69399a2dd95SBruce Richardson struct internal_config *
69499a2dd95SBruce Richardson eal_get_internal_configuration(void);
69599a2dd95SBruce Richardson 
69699a2dd95SBruce Richardson /**
69799a2dd95SBruce Richardson  * Get the current value of the rte_application_usage pointer
69899a2dd95SBruce Richardson  *
69999a2dd95SBruce Richardson  * @return
70099a2dd95SBruce Richardson  *   Pointer to the current value of rte_application_usage .
70199a2dd95SBruce Richardson  */
70299a2dd95SBruce Richardson rte_usage_hook_t
70399a2dd95SBruce Richardson eal_get_application_usage_hook(void);
70499a2dd95SBruce Richardson 
70599a2dd95SBruce Richardson /**
70699a2dd95SBruce Richardson  * Instruct primary process that a secondary process wants to attach.
70799a2dd95SBruce Richardson  */
70899a2dd95SBruce Richardson bool __rte_mp_enable(void);
70999a2dd95SBruce Richardson 
71099a2dd95SBruce Richardson /**
71199a2dd95SBruce Richardson  * Init per-lcore info in current thread.
71299a2dd95SBruce Richardson  *
71399a2dd95SBruce Richardson  * @param lcore_id
71499a2dd95SBruce Richardson  *   identifier of lcore.
71599a2dd95SBruce Richardson  * @param cpuset
71699a2dd95SBruce Richardson  *   CPU affinity for this thread.
71799a2dd95SBruce Richardson  */
71899a2dd95SBruce Richardson void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
71999a2dd95SBruce Richardson 
72099a2dd95SBruce Richardson /**
72199a2dd95SBruce Richardson  * Uninitialize per-lcore info for current thread.
72299a2dd95SBruce Richardson  */
72399a2dd95SBruce Richardson void __rte_thread_uninit(void);
72499a2dd95SBruce Richardson 
72599a2dd95SBruce Richardson /**
72699a2dd95SBruce Richardson  * asprintf(3) replacement for Windows.
72799a2dd95SBruce Richardson  */
72899a2dd95SBruce Richardson #ifdef RTE_EXEC_ENV_WINDOWS
72999a2dd95SBruce Richardson __rte_format_printf(2, 3)
73099a2dd95SBruce Richardson int eal_asprintf(char **buffer, const char *format, ...);
73199a2dd95SBruce Richardson 
73299a2dd95SBruce Richardson #define asprintf(buffer, format, ...) \
73399a2dd95SBruce Richardson 		eal_asprintf(buffer, format, ##__VA_ARGS__)
73499a2dd95SBruce Richardson #endif
73599a2dd95SBruce Richardson 
73697433132SDavid Marchand #define EAL_LOG(level, ...) \
73797433132SDavid Marchand 	RTE_LOG_LINE(level, EAL, "" __VA_ARGS__)
738ae67895bSDavid Marchand 
73999a2dd95SBruce Richardson #endif /* _EAL_PRIVATE_H_ */
740