4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <linux/pci_regs.h>
37 #include <sys/eventfd.h>
38 #include <sys/socket.h>
39 #include <sys/ioctl.h>
44 #include <rte_tailq.h>
45 #include <rte_eal_memconfig.h>
46 #include <rte_malloc.h>
47 #include <eal_private.h>
49 #include "eal_filesystem.h"
50 #include "eal_pci_init.h"
55 * PCI probing under linux (VFIO version)
57 * This code tries to determine if the PCI device is bound to VFIO driver,
58 * and initialize it (map BARs, set up interrupts) if that's the case.
60 * This file is only compiled if CONFIG_RTE_EAL_VFIO is set to "y".
65 #define VFIO_DIR "/dev/vfio"
66 #define VFIO_CONTAINER_PATH "/dev/vfio/vfio"
67 #define VFIO_GROUP_FMT "/dev/vfio/%u"
68 #define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL)
70 /* per-process VFIO config */
71 static struct vfio_config vfio_cfg;
73 /* get PCI BAR number where MSI-X interrupts are */
75 pci_vfio_get_msix_bar(int fd, int *msix_bar)
79 uint8_t cap_id, cap_offset;
81 /* read PCI capability pointer from config space */
82 ret = pread64(fd, ®, sizeof(reg),
83 VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) +
85 if (ret != sizeof(reg)) {
86 RTE_LOG(ERR, EAL, "Cannot read capability pointer from PCI "
91 /* we need first byte */
92 cap_offset = reg & 0xFF;
96 /* read PCI capability ID */
97 ret = pread64(fd, ®, sizeof(reg),
98 VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) +
100 if (ret != sizeof(reg)) {
101 RTE_LOG(ERR, EAL, "Cannot read capability ID from PCI "
106 /* we need first byte */
109 /* if we haven't reached MSI-X, check next capability */
110 if (cap_id != PCI_CAP_ID_MSIX) {
111 ret = pread64(fd, ®, sizeof(reg),
112 VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) +
114 if (ret != sizeof(reg)) {
115 RTE_LOG(ERR, EAL, "Cannot read capability pointer from PCI "
120 /* we need second byte */
121 cap_offset = (reg & 0xFF00) >> 8;
125 /* else, read table offset */
127 /* table offset resides in the next 4 bytes */
128 ret = pread64(fd, ®, sizeof(reg),
129 VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) +
131 if (ret != sizeof(reg)) {
132 RTE_LOG(ERR, EAL, "Cannot read table offset from PCI config "
137 *msix_bar = reg & RTE_PCI_MSIX_TABLE_BIR;
145 /* set PCI bus mastering */
147 pci_vfio_set_bus_master(int dev_fd)
152 ret = pread64(dev_fd, ®, sizeof(reg),
153 VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) +
155 if (ret != sizeof(reg)) {
156 RTE_LOG(ERR, EAL, "Cannot read command from PCI config space!\n");
160 /* set the master bit */
161 reg |= PCI_COMMAND_MASTER;
163 ret = pwrite64(dev_fd, ®, sizeof(reg),
164 VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) +
167 if (ret != sizeof(reg)) {
168 RTE_LOG(ERR, EAL, "Cannot write command to PCI config space!\n");
175 /* set up DMA mappings */
177 pci_vfio_setup_dma_maps(int vfio_container_fd)
179 const struct rte_memseg *ms = rte_eal_get_physmem_layout();
182 ret = ioctl(vfio_container_fd, VFIO_SET_IOMMU,
185 RTE_LOG(ERR, EAL, " cannot set IOMMU type, "
186 "error %i (%s)\n", errno, strerror(errno));
190 /* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */
191 for (i = 0; i < RTE_MAX_MEMSEG; i++) {
192 struct vfio_iommu_type1_dma_map dma_map;
194 if (ms[i].addr == NULL)
197 memset(&dma_map, 0, sizeof(dma_map));
198 dma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map);
199 dma_map.vaddr = ms[i].addr_64;
200 dma_map.size = ms[i].len;
201 dma_map.iova = ms[i].phys_addr;
202 dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
204 ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);
207 RTE_LOG(ERR, EAL, " cannot set up DMA remapping, "
208 "error %i (%s)\n", errno, strerror(errno));
216 /* set up interrupt support (but not enable interrupts) */
218 pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd)
220 int i, ret, intr_idx;
222 /* default to invalid index */
223 intr_idx = VFIO_PCI_NUM_IRQS;
225 /* get interrupt type from internal config (MSI-X by default, can be
226 * overriden from the command line
228 switch (internal_config.vfio_intr_mode) {
229 case RTE_INTR_MODE_MSIX:
230 intr_idx = VFIO_PCI_MSIX_IRQ_INDEX;
232 case RTE_INTR_MODE_MSI:
233 intr_idx = VFIO_PCI_MSI_IRQ_INDEX;
235 case RTE_INTR_MODE_LEGACY:
236 intr_idx = VFIO_PCI_INTX_IRQ_INDEX;
238 /* don't do anything if we want to automatically determine interrupt type */
239 case RTE_INTR_MODE_NONE:
242 RTE_LOG(ERR, EAL, " unknown default interrupt type!\n");
246 /* start from MSI-X interrupt type */
247 for (i = VFIO_PCI_MSIX_IRQ_INDEX; i >= 0; i--) {
248 struct vfio_irq_info irq = { .argsz = sizeof(irq) };
251 /* skip interrupt modes we don't want */
252 if (internal_config.vfio_intr_mode != RTE_INTR_MODE_NONE &&
258 ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_IRQ_INFO, &irq);
260 RTE_LOG(ERR, EAL, " cannot get IRQ info, "
261 "error %i (%s)\n", errno, strerror(errno));
265 /* if this vector cannot be used with eventfd, fail if we explicitly
266 * specified interrupt type, otherwise continue */
267 if ((irq.flags & VFIO_IRQ_INFO_EVENTFD) == 0) {
268 if (internal_config.vfio_intr_mode != RTE_INTR_MODE_NONE) {
270 " interrupt vector does not support eventfd!\n");
276 /* set up an eventfd for interrupts */
279 RTE_LOG(ERR, EAL, " cannot set up eventfd, "
280 "error %i (%s)\n", errno, strerror(errno));
284 dev->intr_handle.fd = fd;
285 dev->intr_handle.vfio_dev_fd = vfio_dev_fd;
288 case VFIO_PCI_MSIX_IRQ_INDEX:
289 internal_config.vfio_intr_mode = RTE_INTR_MODE_MSIX;
290 dev->intr_handle.type = RTE_INTR_HANDLE_VFIO_MSIX;
292 case VFIO_PCI_MSI_IRQ_INDEX:
293 internal_config.vfio_intr_mode = RTE_INTR_MODE_MSI;
294 dev->intr_handle.type = RTE_INTR_HANDLE_VFIO_MSI;
296 case VFIO_PCI_INTX_IRQ_INDEX:
297 internal_config.vfio_intr_mode = RTE_INTR_MODE_LEGACY;
298 dev->intr_handle.type = RTE_INTR_HANDLE_VFIO_LEGACY;
301 RTE_LOG(ERR, EAL, " unknown interrupt type!\n");
308 /* if we're here, we haven't found a suitable interrupt vector */
312 /* open container fd or get an existing one */
314 pci_vfio_get_container_fd(void)
316 int ret, vfio_container_fd;
318 /* if we're in a primary process, try to open the container */
319 if (internal_config.process_type == RTE_PROC_PRIMARY) {
320 vfio_container_fd = open(VFIO_CONTAINER_PATH, O_RDWR);
321 if (vfio_container_fd < 0) {
322 RTE_LOG(ERR, EAL, " cannot open VFIO container, "
323 "error %i (%s)\n", errno, strerror(errno));
327 /* check VFIO API version */
328 ret = ioctl(vfio_container_fd, VFIO_GET_API_VERSION);
329 if (ret != VFIO_API_VERSION) {
331 RTE_LOG(ERR, EAL, " could not get VFIO API version, "
332 "error %i (%s)\n", errno, strerror(errno));
334 RTE_LOG(ERR, EAL, " unsupported VFIO API version!\n");
335 close(vfio_container_fd);
339 /* check if we support IOMMU type 1 */
340 ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU);
343 RTE_LOG(ERR, EAL, " could not get IOMMU type, "
344 "error %i (%s)\n", errno,
347 RTE_LOG(ERR, EAL, " unsupported IOMMU type "
348 "detected in VFIO\n");
349 close(vfio_container_fd);
353 return vfio_container_fd;
356 * if we're in a secondary process, request container fd from the
357 * primary process via our socket
361 socket_fd = vfio_mp_sync_connect_to_primary();
363 RTE_LOG(ERR, EAL, " cannot connect to primary process!\n");
366 if (vfio_mp_sync_send_request(socket_fd, SOCKET_REQ_CONTAINER) < 0) {
367 RTE_LOG(ERR, EAL, " cannot request container fd!\n");
371 vfio_container_fd = vfio_mp_sync_receive_fd(socket_fd);
372 if (vfio_container_fd < 0) {
373 RTE_LOG(ERR, EAL, " cannot get container fd!\n");
378 return vfio_container_fd;
384 /* open group fd or get an existing one */
386 pci_vfio_get_group_fd(int iommu_group_no)
390 char filename[PATH_MAX];
392 /* check if we already have the group descriptor open */
393 for (i = 0; i < vfio_cfg.vfio_group_idx; i++)
394 if (vfio_cfg.vfio_groups[i].group_no == iommu_group_no)
395 return vfio_cfg.vfio_groups[i].fd;
397 /* if primary, try to open the group */
398 if (internal_config.process_type == RTE_PROC_PRIMARY) {
399 snprintf(filename, sizeof(filename),
400 VFIO_GROUP_FMT, iommu_group_no);
401 vfio_group_fd = open(filename, O_RDWR);
402 if (vfio_group_fd < 0) {
403 /* if file not found, it's not an error */
404 if (errno != ENOENT) {
405 RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", filename,
412 /* if the fd is valid, create a new group for it */
413 if (vfio_cfg.vfio_group_idx == VFIO_MAX_GROUPS) {
414 RTE_LOG(ERR, EAL, "Maximum number of VFIO groups reached!\n");
417 vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = iommu_group_no;
418 vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = vfio_group_fd;
419 return vfio_group_fd;
421 /* if we're in a secondary process, request group fd from the primary
422 * process via our socket
427 socket_fd = vfio_mp_sync_connect_to_primary();
430 RTE_LOG(ERR, EAL, " cannot connect to primary process!\n");
433 if (vfio_mp_sync_send_request(socket_fd, SOCKET_REQ_GROUP) < 0) {
434 RTE_LOG(ERR, EAL, " cannot request container fd!\n");
438 if (vfio_mp_sync_send_request(socket_fd, iommu_group_no) < 0) {
439 RTE_LOG(ERR, EAL, " cannot send group number!\n");
443 ret = vfio_mp_sync_receive_request(socket_fd);
449 vfio_group_fd = vfio_mp_sync_receive_fd(socket_fd);
450 /* if we got the fd, return it */
451 if (vfio_group_fd > 0) {
453 return vfio_group_fd;
455 /* fall-through on error */
457 RTE_LOG(ERR, EAL, " cannot get container fd!\n");
465 /* parse IOMMU group number for a PCI device
466 * returns -1 for errors, 0 for non-existent group */
468 pci_vfio_get_group_no(const char *pci_addr)
470 char linkname[PATH_MAX];
471 char filename[PATH_MAX];
472 char *tok[16], *group_tok, *end;
473 int ret, iommu_group_no;
475 memset(linkname, 0, sizeof(linkname));
476 memset(filename, 0, sizeof(filename));
478 /* try to find out IOMMU group for this device */
479 snprintf(linkname, sizeof(linkname),
480 SYSFS_PCI_DEVICES "/%s/iommu_group", pci_addr);
482 ret = readlink(linkname, filename, sizeof(filename));
484 /* if the link doesn't exist, no VFIO for us */
488 ret = rte_strsplit(filename, sizeof(filename),
489 tok, RTE_DIM(tok), '/');
492 RTE_LOG(ERR, EAL, " %s cannot get IOMMU group\n", pci_addr);
496 /* IOMMU group is always the last token */
498 group_tok = tok[ret - 1];
500 iommu_group_no = strtol(group_tok, &end, 10);
501 if ((end != group_tok && *end != '\0') || errno != 0) {
502 RTE_LOG(ERR, EAL, " %s error parsing IOMMU number!\n", pci_addr);
506 return iommu_group_no;
510 clear_current_group(void)
512 vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = 0;
513 vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = -1;
518 * map the PCI resources of a PCI device in virtual memory (VFIO version).
519 * primary and secondary processes follow almost exactly the same path
522 pci_vfio_map_resource(struct rte_pci_device *dev)
524 struct vfio_group_status group_status = {
525 .argsz = sizeof(group_status)
527 struct vfio_device_info device_info = { .argsz = sizeof(device_info) };
528 int vfio_group_fd, vfio_dev_fd;
530 char pci_addr[PATH_MAX] = {0};
531 struct rte_pci_addr *loc = &dev->addr;
532 int i, ret, msix_bar;
533 struct mapped_pci_resource *vfio_res = NULL;
534 struct pci_map *maps;
536 dev->intr_handle.fd = -1;
537 dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
539 /* store PCI address string */
540 snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
541 loc->domain, loc->bus, loc->devid, loc->function);
543 /* get group number */
544 iommu_group_no = pci_vfio_get_group_no(pci_addr);
546 /* if 0, group doesn't exist */
547 if (iommu_group_no == 0) {
548 RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
552 /* if negative, something failed */
553 else if (iommu_group_no < 0)
556 /* get the actual group fd */
557 vfio_group_fd = pci_vfio_get_group_fd(iommu_group_no);
558 if (vfio_group_fd < 0)
562 vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = iommu_group_no;
563 vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = vfio_group_fd;
565 /* if group_fd == 0, that means the device isn't managed by VFIO */
566 if (vfio_group_fd == 0) {
567 RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
569 /* we store 0 as group fd to distinguish between existing but
570 * unbound VFIO groups, and groups that don't exist at all.
572 vfio_cfg.vfio_group_idx++;
577 * at this point, we know at least one port on this device is bound to VFIO,
578 * so we can proceed to try and set this particular port up
581 /* check if the group is viable */
582 ret = ioctl(vfio_group_fd, VFIO_GROUP_GET_STATUS, &group_status);
584 RTE_LOG(ERR, EAL, " %s cannot get group status, "
585 "error %i (%s)\n", pci_addr, errno, strerror(errno));
586 close(vfio_group_fd);
587 clear_current_group();
589 } else if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE)) {
590 RTE_LOG(ERR, EAL, " %s VFIO group is not viable!\n", pci_addr);
591 close(vfio_group_fd);
592 clear_current_group();
597 * at this point, we know that this group is viable (meaning, all devices
598 * are either bound to VFIO or not bound to anything)
601 /* check if group does not have a container yet */
602 if (!(group_status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET)) {
604 /* add group to a container */
605 ret = ioctl(vfio_group_fd, VFIO_GROUP_SET_CONTAINER,
606 &vfio_cfg.vfio_container_fd);
608 RTE_LOG(ERR, EAL, " %s cannot add VFIO group to container, "
609 "error %i (%s)\n", pci_addr, errno, strerror(errno));
610 close(vfio_group_fd);
611 clear_current_group();
615 * at this point we know that this group has been successfully
616 * initialized, so we increment vfio_group_idx to indicate that we can
619 vfio_cfg.vfio_group_idx++;
623 * set up DMA mappings for container
625 * needs to be done only once, only when at least one group is assigned to
626 * a container and only in primary process
628 if (internal_config.process_type == RTE_PROC_PRIMARY &&
629 vfio_cfg.vfio_container_has_dma == 0) {
630 ret = pci_vfio_setup_dma_maps(vfio_cfg.vfio_container_fd);
632 RTE_LOG(ERR, EAL, " %s DMA remapping failed, "
633 "error %i (%s)\n", pci_addr, errno, strerror(errno));
636 vfio_cfg.vfio_container_has_dma = 1;
639 /* get a file descriptor for the device */
640 vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD, pci_addr);
641 if (vfio_dev_fd < 0) {
642 /* if we cannot get a device fd, this simply means that this
643 * particular port is not bound to VFIO
645 RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
650 /* test and setup the device */
651 ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_INFO, &device_info);
653 RTE_LOG(ERR, EAL, " %s cannot get device info, "
654 "error %i (%s)\n", pci_addr, errno, strerror(errno));
659 /* get MSI-X BAR, if any (we have to know where it is because we can't
660 * mmap it when using VFIO) */
662 ret = pci_vfio_get_msix_bar(vfio_dev_fd, &msix_bar);
664 RTE_LOG(ERR, EAL, " %s cannot get MSI-X BAR number!\n", pci_addr);
669 /* if we're in a primary process, allocate vfio_res and get region info */
670 if (internal_config.process_type == RTE_PROC_PRIMARY) {
671 vfio_res = rte_zmalloc("VFIO_RES", sizeof(*vfio_res), 0);
672 if (vfio_res == NULL) {
674 "%s(): cannot store uio mmap details\n", __func__);
678 memcpy(&vfio_res->pci_addr, &dev->addr, sizeof(vfio_res->pci_addr));
680 /* get number of registers (up to BAR5) */
681 vfio_res->nb_maps = RTE_MIN((int) device_info.num_regions,
682 VFIO_PCI_BAR5_REGION_INDEX + 1);
684 /* if we're in a secondary process, just find our tailq entry */
685 TAILQ_FOREACH(vfio_res, pci_res_list, next) {
686 if (memcmp(&vfio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
690 /* if we haven't found our tailq entry, something's wrong */
691 if (vfio_res == NULL) {
692 RTE_LOG(ERR, EAL, " %s cannot find TAILQ entry for PCI device!\n",
700 maps = vfio_res->maps;
702 for (i = 0; i < (int) vfio_res->nb_maps; i++) {
703 struct vfio_region_info reg = { .argsz = sizeof(reg) };
708 ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®);
711 RTE_LOG(ERR, EAL, " %s cannot get device region info "
712 "error %i (%s)\n", pci_addr, errno, strerror(errno));
714 if (internal_config.process_type == RTE_PROC_PRIMARY)
719 /* skip non-mmapable BARs */
720 if ((reg.flags & VFIO_REGION_INFO_FLAG_MMAP) == 0)
727 if (internal_config.process_type == RTE_PROC_PRIMARY) {
728 /* try mapping somewhere close to the end of hugepages */
729 if (pci_map_addr == NULL)
730 pci_map_addr = pci_find_max_end_va();
732 bar_addr = pci_map_resource(pci_map_addr, vfio_dev_fd, reg.offset,
734 pci_map_addr = RTE_PTR_ADD(bar_addr, (size_t) reg.size);
736 bar_addr = pci_map_resource(maps[i].addr, vfio_dev_fd, reg.offset,
740 if (bar_addr == MAP_FAILED ||
741 (internal_config.process_type == RTE_PROC_SECONDARY &&
742 bar_addr != maps[i].addr)) {
743 RTE_LOG(ERR, EAL, " %s mapping BAR%i failed: %s\n", pci_addr, i,
746 if (internal_config.process_type == RTE_PROC_PRIMARY)
751 maps[i].addr = bar_addr;
752 maps[i].offset = reg.offset;
753 maps[i].size = reg.size;
754 dev->mem_resource[i].addr = bar_addr;
757 /* if secondary process, do not set up interrupts */
758 if (internal_config.process_type == RTE_PROC_PRIMARY) {
759 if (pci_vfio_setup_interrupts(dev, vfio_dev_fd) != 0) {
760 RTE_LOG(ERR, EAL, " %s error setting up interrupts!\n", pci_addr);
766 /* set bus mastering for the device */
767 if (pci_vfio_set_bus_master(vfio_dev_fd)) {
768 RTE_LOG(ERR, EAL, " %s cannot set up bus mastering!\n", pci_addr);
774 /* Reset the device */
775 ioctl(vfio_dev_fd, VFIO_DEVICE_RESET);
778 if (internal_config.process_type == RTE_PROC_PRIMARY)
779 TAILQ_INSERT_TAIL(pci_res_list, vfio_res, next);
785 pci_vfio_enable(void)
787 /* initialize group list */
789 int module_vfio_type1;
791 for (i = 0; i < VFIO_MAX_GROUPS; i++) {
792 vfio_cfg.vfio_groups[i].fd = -1;
793 vfio_cfg.vfio_groups[i].group_no = -1;
796 module_vfio_type1 = rte_eal_check_module("vfio_iommu_type1");
798 /* return error directly */
799 if (module_vfio_type1 == -1) {
800 RTE_LOG(INFO, EAL, "Could not get loaded module details!\n");
804 /* return 0 if VFIO modules not loaded */
805 if (module_vfio_type1 == 0) {
806 RTE_LOG(INFO, EAL, "VFIO modules not all loaded, "
807 "skip VFIO support...\n");
811 vfio_cfg.vfio_container_fd = pci_vfio_get_container_fd();
813 /* check if we have VFIO driver enabled */
814 if (vfio_cfg.vfio_container_fd != -1)
815 vfio_cfg.vfio_enabled = 1;
817 RTE_LOG(INFO, EAL, "VFIO support could not be initialized\n");
823 pci_vfio_is_enabled(void)
825 return vfio_cfg.vfio_enabled;