xref: /dpdk/lib/eal/common/eal_common_config.c (revision a4ce111cc89f580b8c4aad51bdb061acbdfde86b)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Mellanox Technologies, Ltd
3  */
4 
5 #include <rte_string_fns.h>
6 
7 #include "eal_private.h"
8 #include "eal_memcfg.h"
9 
10 /* early configuration structure, when memory config is not mmapped */
11 static struct rte_mem_config early_mem_config = {
12 	.mlock = RTE_RWLOCK_INITIALIZER,
13 	.qlock = RTE_RWLOCK_INITIALIZER,
14 	.mplock = RTE_RWLOCK_INITIALIZER,
15 	.tlock = RTE_SPINLOCK_INITIALIZER,
16 	.ethdev_lock = RTE_SPINLOCK_INITIALIZER,
17 	.memory_hotplug_lock = RTE_RWLOCK_INITIALIZER,
18 };
19 
20 /* Address of global and public configuration */
21 static struct rte_config rte_config = {
22 	.mem_config = &early_mem_config,
23 };
24 
25 /* platform-specific runtime dir */
26 static char runtime_dir[PATH_MAX];
27 
28 /* internal configuration */
29 static struct internal_config internal_config;
30 
31 const char *
rte_eal_get_runtime_dir(void)32 rte_eal_get_runtime_dir(void)
33 {
34 	return runtime_dir;
35 }
36 
37 int
eal_set_runtime_dir(const char * run_dir)38 eal_set_runtime_dir(const char *run_dir)
39 {
40 	if (strlcpy(runtime_dir, run_dir, PATH_MAX) >= PATH_MAX) {
41 		EAL_LOG(ERR, "Runtime directory string too long");
42 		return -1;
43 	}
44 
45 	return 0;
46 }
47 
48 /* Return a pointer to the configuration structure */
49 struct rte_config *
rte_eal_get_configuration(void)50 rte_eal_get_configuration(void)
51 {
52 	return &rte_config;
53 }
54 
55 /* Return a pointer to the internal configuration structure */
56 struct internal_config *
eal_get_internal_configuration(void)57 eal_get_internal_configuration(void)
58 {
59 	return &internal_config;
60 }
61 
62 enum rte_iova_mode
rte_eal_iova_mode(void)63 rte_eal_iova_mode(void)
64 {
65 	return rte_eal_get_configuration()->iova_mode;
66 }
67 
68 /* Get the EAL base address */
69 uint64_t
rte_eal_get_baseaddr(void)70 rte_eal_get_baseaddr(void)
71 {
72 	return (internal_config.base_virtaddr != 0) ?
73 		       (uint64_t) internal_config.base_virtaddr :
74 		       eal_get_baseaddr();
75 }
76 
77 enum rte_proc_type_t
rte_eal_process_type(void)78 rte_eal_process_type(void)
79 {
80 	return rte_config.process_type;
81 }
82 
83 /* Return user provided mbuf pool ops name */
84 const char *
rte_eal_mbuf_user_pool_ops(void)85 rte_eal_mbuf_user_pool_ops(void)
86 {
87 	return internal_config.user_mbuf_pool_ops_name;
88 }
89 
90 /* return non-zero if hugepages are enabled. */
91 int
rte_eal_has_hugepages(void)92 rte_eal_has_hugepages(void)
93 {
94 	return !internal_config.no_hugetlbfs;
95 }
96 
97 int
rte_eal_has_pci(void)98 rte_eal_has_pci(void)
99 {
100 	return !internal_config.no_pci;
101 }
102