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