eal: auto detect IOVA mode
[dpdk.git] / lib / librte_eal / bsdapp / eal / eal.c
index debecaa..f003f4c 100644 (file)
@@ -45,7 +45,6 @@
 #include <stddef.h>
 #include <errno.h>
 #include <limits.h>
-#include <errno.h>
 #include <sys/mman.h>
 #include <sys/queue.h>
 
@@ -59,6 +58,7 @@
 #include <rte_errno.h>
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
+#include <rte_service_component.h>
 #include <rte_log.h>
 #include <rte_random.h>
 #include <rte_cycles.h>
@@ -69,7 +69,6 @@
 #include <rte_pci.h>
 #include <rte_dev.h>
 #include <rte_devargs.h>
-#include <rte_common.h>
 #include <rte_version.h>
 #include <rte_atomic.h>
 #include <malloc_heap.h>
@@ -120,6 +119,12 @@ rte_eal_get_configuration(void)
        return &rte_config;
 }
 
+enum rte_iova_mode
+rte_eal_iova_mode(void)
+{
+       return rte_eal_get_configuration()->iova_mode;
+}
+
 /* parse a sysfs (or other) file containing one integer value */
 int
 eal_parse_sysfs_value(const char *filename, unsigned long *val)
@@ -195,7 +200,7 @@ rte_eal_config_create(void)
                rte_panic("Cannot mmap memory for rte_config\n");
        }
        memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
-       rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
+       rte_config.mem_config = rte_mem_cfg_addr;
 }
 
 /* attach to an existing shared memory config */
@@ -220,7 +225,7 @@ rte_eal_config_attach(void)
        if (rte_mem_cfg_addr == MAP_FAILED)
                rte_panic("Cannot mmap memory for rte_config\n");
 
-       rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
+       rte_config.mem_config = rte_mem_cfg_addr;
 }
 
 /* Detect if we are a primary or a secondary process */
@@ -323,8 +328,6 @@ eal_log_level_parse(int argc, char **argv)
        optind = 1;
        optreset = 1;
 
-       eal_reset_internal_config(&internal_config);
-
        while ((opt = getopt_long(argc, argvopt, eal_short_options,
                                  eal_long_options, &option_index)) != EOF) {
 
@@ -519,10 +522,10 @@ rte_eal_init(int argc, char **argv)
 
        thread_id = pthread_self();
 
-       eal_log_level_parse(argc, argv);
+       eal_reset_internal_config(&internal_config);
 
        /* set log level as early as possible */
-       rte_set_log_level(internal_config.log_level);
+       eal_log_level_parse(argc, argv);
 
        if (rte_eal_cpu_init() < 0) {
                rte_eal_init_alert("Cannot detect lcores.");
@@ -538,6 +541,22 @@ rte_eal_init(int argc, char **argv)
                return -1;
        }
 
+       if (eal_option_device_parse()) {
+               rte_errno = ENODEV;
+               rte_atomic32_clear(&run_once);
+               return -1;
+       }
+
+       if (rte_bus_scan()) {
+               rte_eal_init_alert("Cannot scan the buses for devices\n");
+               rte_errno = ENODEV;
+               rte_atomic32_clear(&run_once);
+               return -1;
+       }
+
+       /* autodetect the iova mapping mode (default is iova_pa) */
+       rte_eal_get_configuration()->iova_mode = rte_bus_get_iommu_class();
+
        if (internal_config.no_hugetlbfs == 0 &&
                        internal_config.process_type != RTE_PROC_SECONDARY &&
                        eal_hugepage_info_init() < 0) {
@@ -604,13 +623,6 @@ rte_eal_init(int argc, char **argv)
                return -1;
        }
 
-       if (rte_eal_pci_init() < 0) {
-               rte_eal_init_alert("Cannot init PCI\n");
-               rte_errno = EPROTO;
-               rte_atomic32_clear(&run_once);
-               return -1;
-       }
-
        eal_check_mem_on_local_socket();
 
        if (eal_plugins_init() < 0)
@@ -624,9 +636,6 @@ rte_eal_init(int argc, char **argv)
                rte_config.master_lcore, thread_id, cpuset,
                ret == 0 ? "" : "...");
 
-       if (rte_bus_scan())
-               rte_panic("Cannot scan the buses for devices\n");
-
        RTE_LCORE_FOREACH_SLAVE(i) {
 
                /*
@@ -659,19 +668,29 @@ rte_eal_init(int argc, char **argv)
        rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
        rte_eal_mp_wait_lcore();
 
-       /* Probe all the buses and devices/drivers on them */
-       if (rte_bus_probe())
-               rte_panic("Cannot probe devices\n");
+       /* initialize services so vdevs register service during bus_probe. */
+       ret = rte_service_init();
+       if (ret) {
+               rte_eal_init_alert("rte_service_init() failed\n");
+               rte_errno = ENOEXEC;
+               return -1;
+       }
 
-       /* Probe & Initialize PCI devices */
-       if (rte_eal_pci_probe()) {
-               rte_eal_init_alert("Cannot probe PCI\n");
+       /* Probe all the buses and devices/drivers on them */
+       if (rte_bus_probe()) {
+               rte_eal_init_alert("Cannot probe devices\n");
                rte_errno = ENOTSUP;
                return -1;
        }
 
-       if (rte_eal_dev_init() < 0)
-               rte_eal_init_alert("Cannot init pmd devices\n");
+       /* initialize default service/lcore mappings and start running. Ignore
+        * -ENOTSUP, as it indicates no service coremask passed to EAL.
+        */
+       ret = rte_service_start_with_defaults();
+       if (ret < 0 && ret != -ENOTSUP) {
+               rte_errno = ENOEXEC;
+               return -1;
+       }
 
        rte_eal_mcfg_complete();