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