bus: add probing
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal.c
index ceac435..bf6b818 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   Copyright(c) 2012-2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -50,7 +50,7 @@
 #include <sys/mman.h>
 #include <sys/queue.h>
 #include <sys/stat.h>
-#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686)
+#if defined(RTE_ARCH_X86)
 #include <sys/io.h>
 #endif
 
@@ -69,7 +69,9 @@
 #include <rte_string_fns.h>
 #include <rte_cpuflags.h>
 #include <rte_interrupts.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
+#include <rte_dev.h>
 #include <rte_devargs.h>
 #include <rte_common.h>
 #include <rte_version.h>
@@ -82,6 +84,7 @@
 #include "eal_filesystem.h"
 #include "eal_hugepages.h"
 #include "eal_options.h"
+#include "eal_vfio.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
 
@@ -237,7 +240,8 @@ rte_eal_config_attach(void)
        mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),
                        PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
        if (mem_config == MAP_FAILED)
-               rte_panic("Cannot mmap memory for rte_config\n");
+               rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
+                         errno, strerror(errno));
 
        rte_config.mem_config = mem_config;
 }
@@ -262,9 +266,17 @@ rte_eal_config_reattach(void)
        mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
                        sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,
                        mem_cfg_fd, 0);
+       if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
+               if (mem_config != MAP_FAILED)
+                       /* errno is stale, don't use */
+                       rte_panic("Cannot mmap memory for rte_config at [%p], got [%p]"
+                                 " - please use '--base-virtaddr' option\n",
+                                 rte_mem_cfg_addr, mem_config);
+               else
+                       rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
+                                 errno, strerror(errno));
+       }
        close(mem_cfg_fd);
-       if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr)
-               rte_panic("Cannot mmap memory for rte_config\n");
 
        rte_config.mem_config = mem_config;
 }
@@ -465,24 +477,6 @@ eal_parse_vfio_intr(const char *mode)
        return -1;
 }
 
-static inline size_t
-eal_get_hugepage_mem_size(void)
-{
-       uint64_t size = 0;
-       unsigned i, j;
-
-       for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
-               struct hugepage_info *hpi = &internal_config.hugepage_info[i];
-               if (hpi->hugedir != NULL) {
-                       for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
-                               size += hpi->hugepage_sz * hpi->num_pages[j];
-                       }
-               }
-       }
-
-       return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
-}
-
 /* Parse the arguments for --log-level only */
 static void
 eal_log_level_parse(int argc, char **argv)
@@ -712,17 +706,40 @@ rte_eal_mcfg_complete(void)
 int
 rte_eal_iopl_init(void)
 {
-#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686)
+#if defined(RTE_ARCH_X86)
        if (iopl(3) != 0)
                return -1;
-       return 0;
-#elif defined(RTE_ARCH_ARM) || defined(RTE_ARCH_ARM64)
-       return 0; /* iopl syscall not supported for ARM/ARM64 */
-#else
-       return -1;
 #endif
+       return 0;
 }
 
+#ifdef VFIO_PRESENT
+static int rte_eal_vfio_setup(void)
+{
+       int vfio_enabled = 0;
+
+       if (!internal_config.no_pci) {
+               pci_vfio_enable();
+               vfio_enabled |= pci_vfio_is_enabled();
+       }
+
+       if (vfio_enabled) {
+
+               /* if we are primary process, create a thread to communicate with
+                * secondary processes. the thread will use a socket to wait for
+                * requests from secondary process to send open file descriptors,
+                * because VFIO does not allow multiple open descriptors on a group or
+                * VFIO container.
+                */
+               if (internal_config.process_type == RTE_PROC_PRIMARY &&
+                               vfio_mp_sync_setup() < 0)
+                       return -1;
+       }
+
+       return 0;
+}
+#endif
+
 /* Launch threads, called at application init(). */
 int
 rte_eal_init(int argc, char **argv)
@@ -734,6 +751,9 @@ rte_eal_init(int argc, char **argv)
        char cpuset[RTE_CPU_AFFINITY_STR_LEN];
        char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
+       /* checks if the machine is adequate */
+       rte_cpu_check_supported();
+
        if (!rte_atomic32_test_and_set(&run_once))
                return -1;
 
@@ -742,9 +762,6 @@ rte_eal_init(int argc, char **argv)
 
        thread_id = pthread_self();
 
-       if (rte_eal_log_early_init() < 0)
-               rte_panic("Cannot init early logs\n");
-
        eal_log_level_parse(argc, argv);
 
        /* set log level as early as possible */
@@ -766,8 +783,6 @@ rte_eal_init(int argc, char **argv)
        if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
                if (internal_config.no_hugetlbfs)
                        internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
-               else
-                       internal_config.memory = eal_get_hugepage_mem_size();
        }
 
        if (internal_config.vmware_tsc_map == 1) {
@@ -785,12 +800,15 @@ rte_eal_init(int argc, char **argv)
 
        rte_config_init();
 
+       if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0)
+               rte_panic("Cannot init logs\n");
+
        if (rte_eal_pci_init() < 0)
                rte_panic("Cannot init PCI\n");
 
-#ifdef RTE_LIBRTE_IVSHMEM
-       if (rte_eal_ivshmem_init() < 0)
-               rte_panic("Cannot init IVSHMEM\n");
+#ifdef VFIO_PRESENT
+       if (rte_eal_vfio_setup() < 0)
+               rte_panic("Cannot init VFIO\n");
 #endif
 
        if (rte_eal_memory_init() < 0)
@@ -805,14 +823,6 @@ rte_eal_init(int argc, char **argv)
        if (rte_eal_tailqs_init() < 0)
                rte_panic("Cannot init tail queues for objects\n");
 
-#ifdef RTE_LIBRTE_IVSHMEM
-       if (rte_eal_ivshmem_obj_init() < 0)
-               rte_panic("Cannot init IVSHMEM objects\n");
-#endif
-
-       if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0)
-               rte_panic("Cannot init logs\n");
-
        if (rte_eal_alarm_init() < 0)
                rte_panic("Cannot init interrupt-handling thread\n");
 
@@ -821,8 +831,6 @@ rte_eal_init(int argc, char **argv)
 
        eal_check_mem_on_local_socket();
 
-       rte_eal_mcfg_complete();
-
        if (eal_plugins_init() < 0)
                rte_panic("Cannot init plugins\n");
 
@@ -834,12 +842,12 @@ rte_eal_init(int argc, char **argv)
                rte_config.master_lcore, (int)thread_id, cpuset,
                ret == 0 ? "" : "...");
 
-       if (rte_eal_dev_init() < 0)
-               rte_panic("Cannot init pmd devices\n");
-
        if (rte_eal_intr_init() < 0)
                rte_panic("Cannot init interrupt-handling thread\n");
 
+       if (rte_bus_scan())
+               rte_panic("Cannot scan the buses for devices\n");
+
        RTE_LCORE_FOREACH_SLAVE(i) {
 
                /*
@@ -865,7 +873,7 @@ rte_eal_init(int argc, char **argv)
                ret = rte_thread_setname(lcore_config[i].thread_id,
                                                thread_name);
                if (ret != 0)
-                       RTE_LOG(ERR, EAL,
+                       RTE_LOG(DEBUG, EAL,
                                "Cannot set name for lcore thread\n");
        }
 
@@ -876,10 +884,19 @@ 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");
+
        /* Probe & Initialize PCI devices */
        if (rte_eal_pci_probe())
                rte_panic("Cannot probe PCI\n");
 
+       if (rte_eal_dev_init() < 0)
+               rte_panic("Cannot init pmd devices\n");
+
+       rte_eal_mcfg_complete();
+
        return fctret;
 }