vfio: export some internal functions
[dpdk.git] / lib / librte_eal / bsdapp / eal / eal.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <stdarg.h>
11 #include <unistd.h>
12 #include <pthread.h>
13 #include <syslog.h>
14 #include <getopt.h>
15 #include <sys/file.h>
16 #include <stddef.h>
17 #include <errno.h>
18 #include <limits.h>
19 #include <sys/mman.h>
20 #include <sys/queue.h>
21
22 #include <rte_compat.h>
23 #include <rte_common.h>
24 #include <rte_debug.h>
25 #include <rte_memory.h>
26 #include <rte_launch.h>
27 #include <rte_eal.h>
28 #include <rte_eal_memconfig.h>
29 #include <rte_errno.h>
30 #include <rte_per_lcore.h>
31 #include <rte_lcore.h>
32 #include <rte_service_component.h>
33 #include <rte_log.h>
34 #include <rte_random.h>
35 #include <rte_cycles.h>
36 #include <rte_string_fns.h>
37 #include <rte_cpuflags.h>
38 #include <rte_interrupts.h>
39 #include <rte_bus.h>
40 #include <rte_dev.h>
41 #include <rte_devargs.h>
42 #include <rte_version.h>
43 #include <rte_atomic.h>
44 #include <malloc_heap.h>
45
46 #include "eal_private.h"
47 #include "eal_thread.h"
48 #include "eal_internal_cfg.h"
49 #include "eal_filesystem.h"
50 #include "eal_hugepages.h"
51 #include "eal_options.h"
52
53 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
54
55 /* Allow the application to print its usage message too if set */
56 static rte_usage_hook_t rte_application_usage_hook = NULL;
57 /* early configuration structure, when memory config is not mmapped */
58 static struct rte_mem_config early_mem_config;
59
60 /* define fd variable here, because file needs to be kept open for the
61  * duration of the program, as we hold a write lock on it in the primary proc */
62 static int mem_cfg_fd = -1;
63
64 static struct flock wr_lock = {
65                 .l_type = F_WRLCK,
66                 .l_whence = SEEK_SET,
67                 .l_start = offsetof(struct rte_mem_config, memsegs),
68                 .l_len = sizeof(early_mem_config.memsegs),
69 };
70
71 /* Address of global and public configuration */
72 static struct rte_config rte_config = {
73                 .mem_config = &early_mem_config,
74 };
75
76 /* internal configuration (per-core) */
77 struct lcore_config lcore_config[RTE_MAX_LCORE];
78
79 /* internal configuration */
80 struct internal_config internal_config;
81
82 /* used by rte_rdtsc() */
83 int rte_cycles_vmware_tsc_map;
84
85 /* Return user provided mbuf pool ops name */
86 const char * __rte_experimental
87 rte_eal_mbuf_user_pool_ops(void)
88 {
89         return internal_config.user_mbuf_pool_ops_name;
90 }
91
92 /* Return mbuf pool ops name */
93 const char *
94 rte_eal_mbuf_default_mempool_ops(void)
95 {
96         if (internal_config.user_mbuf_pool_ops_name == NULL)
97                 return RTE_MBUF_DEFAULT_MEMPOOL_OPS;
98
99         return internal_config.user_mbuf_pool_ops_name;
100 }
101
102 /* Return a pointer to the configuration structure */
103 struct rte_config *
104 rte_eal_get_configuration(void)
105 {
106         return &rte_config;
107 }
108
109 enum rte_iova_mode
110 rte_eal_iova_mode(void)
111 {
112         return rte_eal_get_configuration()->iova_mode;
113 }
114
115 /* parse a sysfs (or other) file containing one integer value */
116 int
117 eal_parse_sysfs_value(const char *filename, unsigned long *val)
118 {
119         FILE *f;
120         char buf[BUFSIZ];
121         char *end = NULL;
122
123         if ((f = fopen(filename, "r")) == NULL) {
124                 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
125                         __func__, filename);
126                 return -1;
127         }
128
129         if (fgets(buf, sizeof(buf), f) == NULL) {
130                 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
131                         __func__, filename);
132                 fclose(f);
133                 return -1;
134         }
135         *val = strtoul(buf, &end, 0);
136         if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
137                 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
138                                 __func__, filename);
139                 fclose(f);
140                 return -1;
141         }
142         fclose(f);
143         return 0;
144 }
145
146
147 /* create memory configuration in shared/mmap memory. Take out
148  * a write lock on the memsegs, so we can auto-detect primary/secondary.
149  * This means we never close the file while running (auto-close on exit).
150  * We also don't lock the whole file, so that in future we can use read-locks
151  * on other parts, e.g. memzones, to detect if there are running secondary
152  * processes. */
153 static void
154 rte_eal_config_create(void)
155 {
156         void *rte_mem_cfg_addr;
157         int retval;
158
159         const char *pathname = eal_runtime_config_path();
160
161         if (internal_config.no_shconf)
162                 return;
163
164         if (mem_cfg_fd < 0){
165                 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
166                 if (mem_cfg_fd < 0)
167                         rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
168         }
169
170         retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
171         if (retval < 0){
172                 close(mem_cfg_fd);
173                 rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
174         }
175
176         retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
177         if (retval < 0){
178                 close(mem_cfg_fd);
179                 rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
180                                 "process running?\n", pathname);
181         }
182
183         rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
184                                 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
185
186         if (rte_mem_cfg_addr == MAP_FAILED){
187                 rte_panic("Cannot mmap memory for rte_config\n");
188         }
189         memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
190         rte_config.mem_config = rte_mem_cfg_addr;
191 }
192
193 /* attach to an existing shared memory config */
194 static void
195 rte_eal_config_attach(void)
196 {
197         void *rte_mem_cfg_addr;
198         const char *pathname = eal_runtime_config_path();
199
200         if (internal_config.no_shconf)
201                 return;
202
203         if (mem_cfg_fd < 0){
204                 mem_cfg_fd = open(pathname, O_RDWR);
205                 if (mem_cfg_fd < 0)
206                         rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
207         }
208
209         rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
210                                 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
211         close(mem_cfg_fd);
212         if (rte_mem_cfg_addr == MAP_FAILED)
213                 rte_panic("Cannot mmap memory for rte_config\n");
214
215         rte_config.mem_config = rte_mem_cfg_addr;
216 }
217
218 /* Detect if we are a primary or a secondary process */
219 enum rte_proc_type_t
220 eal_proc_type_detect(void)
221 {
222         enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
223         const char *pathname = eal_runtime_config_path();
224
225         /* if we can open the file but not get a write-lock we are a secondary
226          * process. NOTE: if we get a file handle back, we keep that open
227          * and don't close it to prevent a race condition between multiple opens */
228         if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
229                         (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
230                 ptype = RTE_PROC_SECONDARY;
231
232         RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
233                         ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
234
235         return ptype;
236 }
237
238 /* Sets up rte_config structure with the pointer to shared memory config.*/
239 static void
240 rte_config_init(void)
241 {
242         rte_config.process_type = internal_config.process_type;
243
244         switch (rte_config.process_type){
245         case RTE_PROC_PRIMARY:
246                 rte_eal_config_create();
247                 break;
248         case RTE_PROC_SECONDARY:
249                 rte_eal_config_attach();
250                 rte_eal_mcfg_wait_complete(rte_config.mem_config);
251                 break;
252         case RTE_PROC_AUTO:
253         case RTE_PROC_INVALID:
254                 rte_panic("Invalid process type\n");
255         }
256 }
257
258 /* display usage */
259 static void
260 eal_usage(const char *prgname)
261 {
262         printf("\nUsage: %s ", prgname);
263         eal_common_usage();
264         /* Allow the application to print its usage message too if hook is set */
265         if ( rte_application_usage_hook ) {
266                 printf("===== Application Usage =====\n\n");
267                 rte_application_usage_hook(prgname);
268         }
269 }
270
271 /* Set a per-application usage message */
272 rte_usage_hook_t
273 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
274 {
275         rte_usage_hook_t        old_func;
276
277         /* Will be NULL on the first call to denote the last usage routine. */
278         old_func                                        = rte_application_usage_hook;
279         rte_application_usage_hook      = usage_func;
280
281         return old_func;
282 }
283
284 static inline size_t
285 eal_get_hugepage_mem_size(void)
286 {
287         uint64_t size = 0;
288         unsigned i, j;
289
290         for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
291                 struct hugepage_info *hpi = &internal_config.hugepage_info[i];
292                 if (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0) {
293                         for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
294                                 size += hpi->hugepage_sz * hpi->num_pages[j];
295                         }
296                 }
297         }
298
299         return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
300 }
301
302 /* Parse the arguments for --log-level only */
303 static void
304 eal_log_level_parse(int argc, char **argv)
305 {
306         int opt;
307         char **argvopt;
308         int option_index;
309         const int old_optind = optind;
310         const int old_optopt = optopt;
311         const int old_optreset = optreset;
312         char * const old_optarg = optarg;
313
314         argvopt = argv;
315         optind = 1;
316         optreset = 1;
317
318         while ((opt = getopt_long(argc, argvopt, eal_short_options,
319                                   eal_long_options, &option_index)) != EOF) {
320
321                 int ret;
322
323                 /* getopt is not happy, stop right now */
324                 if (opt == '?')
325                         break;
326
327                 ret = (opt == OPT_LOG_LEVEL_NUM) ?
328                         eal_parse_common_option(opt, optarg, &internal_config) : 0;
329
330                 /* common parser is not happy */
331                 if (ret < 0)
332                         break;
333         }
334
335         /* restore getopt lib */
336         optind = old_optind;
337         optopt = old_optopt;
338         optreset = old_optreset;
339         optarg = old_optarg;
340 }
341
342 /* Parse the argument given in the command line of the application */
343 static int
344 eal_parse_args(int argc, char **argv)
345 {
346         int opt, ret;
347         char **argvopt;
348         int option_index;
349         char *prgname = argv[0];
350         const int old_optind = optind;
351         const int old_optopt = optopt;
352         const int old_optreset = optreset;
353         char * const old_optarg = optarg;
354
355         argvopt = argv;
356         optind = 1;
357         optreset = 1;
358
359         while ((opt = getopt_long(argc, argvopt, eal_short_options,
360                                   eal_long_options, &option_index)) != EOF) {
361
362                 /* getopt is not happy, stop right now */
363                 if (opt == '?') {
364                         eal_usage(prgname);
365                         ret = -1;
366                         goto out;
367                 }
368
369                 ret = eal_parse_common_option(opt, optarg, &internal_config);
370                 /* common parser is not happy */
371                 if (ret < 0) {
372                         eal_usage(prgname);
373                         ret = -1;
374                         goto out;
375                 }
376                 /* common parser handled this option */
377                 if (ret == 0)
378                         continue;
379
380                 switch (opt) {
381                 case OPT_MBUF_POOL_OPS_NAME_NUM:
382                         internal_config.user_mbuf_pool_ops_name = optarg;
383                         break;
384                 case 'h':
385                         eal_usage(prgname);
386                         exit(EXIT_SUCCESS);
387                 default:
388                         if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
389                                 RTE_LOG(ERR, EAL, "Option %c is not supported "
390                                         "on FreeBSD\n", opt);
391                         } else if (opt >= OPT_LONG_MIN_NUM &&
392                                    opt < OPT_LONG_MAX_NUM) {
393                                 RTE_LOG(ERR, EAL, "Option %s is not supported "
394                                         "on FreeBSD\n",
395                                         eal_long_options[option_index].name);
396                         } else {
397                                 RTE_LOG(ERR, EAL, "Option %d is not supported "
398                                         "on FreeBSD\n", opt);
399                         }
400                         eal_usage(prgname);
401                         ret = -1;
402                         goto out;
403                 }
404         }
405
406         if (eal_adjust_config(&internal_config) != 0) {
407                 ret = -1;
408                 goto out;
409         }
410
411         /* sanity checks */
412         if (eal_check_common_options(&internal_config) != 0) {
413                 eal_usage(prgname);
414                 ret = -1;
415                 goto out;
416         }
417
418         if (optind >= 0)
419                 argv[optind-1] = prgname;
420         ret = optind-1;
421
422 out:
423         /* restore getopt lib */
424         optind = old_optind;
425         optopt = old_optopt;
426         optreset = old_optreset;
427         optarg = old_optarg;
428
429         return ret;
430 }
431
432 static int
433 check_socket(const struct rte_memseg_list *msl, void *arg)
434 {
435         int *socket_id = arg;
436
437         if (msl->socket_id == *socket_id && msl->memseg_arr.count != 0)
438                 return 1;
439
440         return 0;
441 }
442
443 static void
444 eal_check_mem_on_local_socket(void)
445 {
446         int socket_id;
447
448         socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
449
450         if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
451                 RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n");
452 }
453
454
455 static int
456 sync_func(__attribute__((unused)) void *arg)
457 {
458         return 0;
459 }
460
461 inline static void
462 rte_eal_mcfg_complete(void)
463 {
464         /* ALL shared mem_config related INIT DONE */
465         if (rte_config.process_type == RTE_PROC_PRIMARY)
466                 rte_config.mem_config->magic = RTE_MAGIC;
467 }
468
469 /* return non-zero if hugepages are enabled. */
470 int rte_eal_has_hugepages(void)
471 {
472         return !internal_config.no_hugetlbfs;
473 }
474
475 /* Abstraction for port I/0 privilege */
476 int
477 rte_eal_iopl_init(void)
478 {
479         static int fd;
480
481         fd = open("/dev/io", O_RDWR);
482         if (fd < 0)
483                 return -1;
484         /* keep fd open for iopl */
485         return 0;
486 }
487
488 static void rte_eal_init_alert(const char *msg)
489 {
490         fprintf(stderr, "EAL: FATAL: %s\n", msg);
491         RTE_LOG(ERR, EAL, "%s\n", msg);
492 }
493
494 /* Launch threads, called at application init(). */
495 int
496 rte_eal_init(int argc, char **argv)
497 {
498         int i, fctret, ret;
499         pthread_t thread_id;
500         static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
501         char cpuset[RTE_CPU_AFFINITY_STR_LEN];
502         char thread_name[RTE_MAX_THREAD_NAME_LEN];
503
504         /* checks if the machine is adequate */
505         if (!rte_cpu_is_supported()) {
506                 rte_eal_init_alert("unsupported cpu type.");
507                 rte_errno = ENOTSUP;
508                 return -1;
509         }
510
511         if (!rte_atomic32_test_and_set(&run_once)) {
512                 rte_eal_init_alert("already called initialization.");
513                 rte_errno = EALREADY;
514                 return -1;
515         }
516
517         thread_id = pthread_self();
518
519         eal_reset_internal_config(&internal_config);
520
521         /* set log level as early as possible */
522         eal_log_level_parse(argc, argv);
523
524         if (rte_eal_cpu_init() < 0) {
525                 rte_eal_init_alert("Cannot detect lcores.");
526                 rte_errno = ENOTSUP;
527                 return -1;
528         }
529
530         fctret = eal_parse_args(argc, argv);
531         if (fctret < 0) {
532                 rte_eal_init_alert("Invalid 'command line' arguments.");
533                 rte_errno = EINVAL;
534                 rte_atomic32_clear(&run_once);
535                 return -1;
536         }
537
538         /* FreeBSD always uses legacy memory model */
539         internal_config.legacy_mem = true;
540
541         if (eal_plugins_init() < 0) {
542                 rte_eal_init_alert("Cannot init plugins\n");
543                 rte_errno = EINVAL;
544                 rte_atomic32_clear(&run_once);
545                 return -1;
546         }
547
548         if (eal_option_device_parse()) {
549                 rte_errno = ENODEV;
550                 rte_atomic32_clear(&run_once);
551                 return -1;
552         }
553
554         if (rte_bus_scan()) {
555                 rte_eal_init_alert("Cannot scan the buses for devices\n");
556                 rte_errno = ENODEV;
557                 rte_atomic32_clear(&run_once);
558                 return -1;
559         }
560
561         /* autodetect the iova mapping mode (default is iova_pa) */
562         rte_eal_get_configuration()->iova_mode = rte_bus_get_iommu_class();
563
564         if (internal_config.no_hugetlbfs == 0) {
565                 /* rte_config isn't initialized yet */
566                 ret = internal_config.process_type == RTE_PROC_PRIMARY ?
567                         eal_hugepage_info_init() :
568                         eal_hugepage_info_read();
569                 if (ret < 0) {
570                         rte_eal_init_alert("Cannot get hugepage information.");
571                         rte_errno = EACCES;
572                         rte_atomic32_clear(&run_once);
573                         return -1;
574                 }
575         }
576
577         if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
578                 if (internal_config.no_hugetlbfs)
579                         internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
580                 else
581                         internal_config.memory = eal_get_hugepage_mem_size();
582         }
583
584         if (internal_config.vmware_tsc_map == 1) {
585 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
586                 rte_cycles_vmware_tsc_map = 1;
587                 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
588                                 "you must have monitor_control.pseudo_perfctr = TRUE\n");
589 #else
590                 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
591                                 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
592 #endif
593         }
594
595         rte_srand(rte_rdtsc());
596
597         rte_config_init();
598
599         if (rte_mp_channel_init() < 0) {
600                 rte_eal_init_alert("failed to init mp channel\n");
601                 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
602                         rte_errno = EFAULT;
603                         return -1;
604                 }
605         }
606
607         /* in secondary processes, memory init may allocate additional fbarrays
608          * not present in primary processes, so to avoid any potential issues,
609          * initialize memzones first.
610          */
611         if (rte_eal_memzone_init() < 0) {
612                 rte_eal_init_alert("Cannot init memzone\n");
613                 rte_errno = ENODEV;
614                 return -1;
615         }
616
617         if (rte_eal_memory_init() < 0) {
618                 rte_eal_init_alert("Cannot init memory\n");
619                 rte_errno = ENOMEM;
620                 return -1;
621         }
622
623         if (rte_eal_malloc_heap_init() < 0) {
624                 rte_eal_init_alert("Cannot init malloc heap\n");
625                 rte_errno = ENODEV;
626                 return -1;
627         }
628
629         if (rte_eal_tailqs_init() < 0) {
630                 rte_eal_init_alert("Cannot init tail queues for objects\n");
631                 rte_errno = EFAULT;
632                 return -1;
633         }
634
635         if (rte_eal_alarm_init() < 0) {
636                 rte_eal_init_alert("Cannot init interrupt-handling thread\n");
637                 /* rte_eal_alarm_init sets rte_errno on failure. */
638                 return -1;
639         }
640
641         if (rte_eal_intr_init() < 0) {
642                 rte_eal_init_alert("Cannot init interrupt-handling thread\n");
643                 return -1;
644         }
645
646         if (rte_eal_timer_init() < 0) {
647                 rte_eal_init_alert("Cannot init HPET or TSC timers\n");
648                 rte_errno = ENOTSUP;
649                 return -1;
650         }
651
652         eal_check_mem_on_local_socket();
653
654         eal_thread_init_master(rte_config.master_lcore);
655
656         ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN);
657
658         RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
659                 rte_config.master_lcore, thread_id, cpuset,
660                 ret == 0 ? "" : "...");
661
662         RTE_LCORE_FOREACH_SLAVE(i) {
663
664                 /*
665                  * create communication pipes between master thread
666                  * and children
667                  */
668                 if (pipe(lcore_config[i].pipe_master2slave) < 0)
669                         rte_panic("Cannot create pipe\n");
670                 if (pipe(lcore_config[i].pipe_slave2master) < 0)
671                         rte_panic("Cannot create pipe\n");
672
673                 lcore_config[i].state = WAIT;
674
675                 /* create a thread for each lcore */
676                 ret = pthread_create(&lcore_config[i].thread_id, NULL,
677                                      eal_thread_loop, NULL);
678                 if (ret != 0)
679                         rte_panic("Cannot create thread\n");
680
681                 /* Set thread_name for aid in debugging. */
682                 snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN,
683                                 "lcore-slave-%d", i);
684                 rte_thread_setname(lcore_config[i].thread_id, thread_name);
685         }
686
687         /*
688          * Launch a dummy function on all slave lcores, so that master lcore
689          * knows they are all ready when this function returns.
690          */
691         rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
692         rte_eal_mp_wait_lcore();
693
694         /* initialize services so vdevs register service during bus_probe. */
695         ret = rte_service_init();
696         if (ret) {
697                 rte_eal_init_alert("rte_service_init() failed\n");
698                 rte_errno = ENOEXEC;
699                 return -1;
700         }
701
702         /* Probe all the buses and devices/drivers on them */
703         if (rte_bus_probe()) {
704                 rte_eal_init_alert("Cannot probe devices\n");
705                 rte_errno = ENOTSUP;
706                 return -1;
707         }
708
709         /* initialize default service/lcore mappings and start running. Ignore
710          * -ENOTSUP, as it indicates no service coremask passed to EAL.
711          */
712         ret = rte_service_start_with_defaults();
713         if (ret < 0 && ret != -ENOTSUP) {
714                 rte_errno = ENOEXEC;
715                 return -1;
716         }
717
718         rte_eal_mcfg_complete();
719
720         return fctret;
721 }
722
723 int __rte_experimental
724 rte_eal_cleanup(void)
725 {
726         rte_service_finalize();
727         return 0;
728 }
729
730 /* get core role */
731 enum rte_lcore_role_t
732 rte_eal_lcore_role(unsigned lcore_id)
733 {
734         return rte_config.lcore_role[lcore_id];
735 }
736
737 enum rte_proc_type_t
738 rte_eal_process_type(void)
739 {
740         return rte_config.process_type;
741 }
742
743 int rte_eal_has_pci(void)
744 {
745         return !internal_config.no_pci;
746 }
747
748 int rte_eal_create_uio_dev(void)
749 {
750         return internal_config.create_uio_dev;
751 }
752
753 enum rte_intr_mode
754 rte_eal_vfio_intr_mode(void)
755 {
756         return RTE_INTR_MODE_NONE;
757 }
758
759 /* dummy forward declaration. */
760 struct vfio_device_info;
761
762 /* dummy prototypes. */
763 int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
764                 int *vfio_dev_fd, struct vfio_device_info *device_info);
765 int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd);
766 int rte_vfio_enable(const char *modname);
767 int rte_vfio_is_enabled(const char *modname);
768 int rte_vfio_noiommu_is_enabled(void);
769 int rte_vfio_clear_group(int vfio_group_fd);
770 int rte_vfio_dma_map(uint64_t vaddr, uint64_t iova, uint64_t len);
771 int rte_vfio_dma_unmap(uint64_t vaddr, uint64_t iova, uint64_t len);
772
773 int rte_vfio_setup_device(__rte_unused const char *sysfs_base,
774                       __rte_unused const char *dev_addr,
775                       __rte_unused int *vfio_dev_fd,
776                       __rte_unused struct vfio_device_info *device_info)
777 {
778         return -1;
779 }
780
781 int rte_vfio_release_device(__rte_unused const char *sysfs_base,
782                         __rte_unused const char *dev_addr,
783                         __rte_unused int fd)
784 {
785         return -1;
786 }
787
788 int rte_vfio_enable(__rte_unused const char *modname)
789 {
790         return -1;
791 }
792
793 int rte_vfio_is_enabled(__rte_unused const char *modname)
794 {
795         return 0;
796 }
797
798 int rte_vfio_noiommu_is_enabled(void)
799 {
800         return 0;
801 }
802
803 int rte_vfio_clear_group(__rte_unused int vfio_group_fd)
804 {
805         return 0;
806 }
807
808 int __rte_experimental
809 rte_vfio_dma_map(uint64_t __rte_unused vaddr, __rte_unused uint64_t iova,
810                   __rte_unused uint64_t len)
811 {
812         return -1;
813 }
814
815 int __rte_experimental
816 rte_vfio_dma_unmap(uint64_t __rte_unused vaddr, uint64_t __rte_unused iova,
817                     __rte_unused uint64_t len)
818 {
819         return -1;
820 }
821
822 int __rte_experimental
823 rte_vfio_get_group_num(__rte_unused const char *sysfs_base,
824                        __rte_unused const char *dev_addr,
825                        __rte_unused int *iommu_group_num)
826 {
827         return -1;
828 }
829
830 int  __rte_experimental
831 rte_vfio_get_container_fd(void)
832 {
833         return -1;
834 }
835
836 int  __rte_experimental
837 rte_vfio_get_group_fd(__rte_unused int iommu_group_num)
838 {
839         return -1;
840 }