From a7f7adec8db2477171b03d38d1a395cb65e830b7 Mon Sep 17 00:00:00 2001 From: Jan Viktorin Date: Mon, 4 Jul 2016 17:16:50 +0200 Subject: [PATCH] vfio: initialize out of the PCI subsystem The VFIO does not depend on the PCI anymore so it can be initialized out of the PCI subsystem. Signed-off-by: Jan Viktorin --- lib/librte_eal/linuxapp/eal/eal.c | 31 ++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 17 +----------- lib/librte_eal/linuxapp/eal/eal_pci_init.h | 3 --- lib/librte_eal/linuxapp/eal/eal_vfio.h | 3 +++ 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 543ef86969..606b7775ac 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -82,6 +82,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) @@ -701,6 +702,31 @@ rte_eal_iopl_init(void) return 0; } +#ifdef VFIO_PRESENT +static int rte_eal_vfio_setup(void) +{ + if (internal_config.no_pci) + return 0; + + pci_vfio_enable(); + + if (pci_vfio_is_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) @@ -764,6 +790,11 @@ rte_eal_init(int argc, char **argv) if (rte_eal_pci_init() < 0) rte_panic("Cannot init PCI\n"); +#ifdef VFIO_PRESENT + if (rte_eal_vfio_setup() < 0) + rte_panic("Cannot init VFIO\n"); +#endif + #ifdef RTE_LIBRTE_IVSHMEM if (rte_eal_ivshmem_init() < 0) rte_panic("Cannot init IVSHMEM\n"); diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index d0a64814ca..cd9de7cc94 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -754,21 +754,6 @@ rte_eal_pci_init(void) RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__); return -1; } -#ifdef VFIO_PRESENT - pci_vfio_enable(); - - if (pci_vfio_is_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; - } -#endif + return 0; } diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h index 62c337fbea..6a960d1bac 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h @@ -74,9 +74,6 @@ int pci_uio_ioport_unmap(struct rte_pci_ioport *p); #ifdef VFIO_PRESENT -int pci_vfio_enable(void); -int pci_vfio_is_enabled(void); - /* access config space */ int pci_vfio_read_config(const struct rte_intr_handle *intr_handle, void *buf, size_t len, off_t offs); diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h index 3f549b097d..29f7f3eca5 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.h +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h @@ -143,6 +143,9 @@ int vfio_setup_device(const char *sysfs_base, const char *dev_addr, int vfio_enable(const char *modname); int vfio_is_enabled(const char *modname); +int pci_vfio_enable(void); +int pci_vfio_is_enabled(void); + int vfio_mp_sync_setup(void); #define SOCKET_REQ_CONTAINER 0x100 -- 2.20.1