vfio: expose functions
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_vfio.c
index 9d66247..5bbcdf9 100644 (file)
@@ -39,6 +39,7 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_eal_memconfig.h>
+#include <rte_vfio.h>
 
 #include "eal_filesystem.h"
 #include "eal_vfio.h"
@@ -68,8 +69,8 @@ vfio_get_group_fd(int iommu_group_no)
 {
        int i;
        int vfio_group_fd;
-       int group_idx = -1;
        char filename[PATH_MAX];
+       struct vfio_group *cur_grp;
 
        /* check if we already have the group descriptor open */
        for (i = 0; i < VFIO_MAX_GROUPS; i++)
@@ -85,12 +86,12 @@ vfio_get_group_fd(int iommu_group_no)
        /* Now lets get an index for the new group */
        for (i = 0; i < VFIO_MAX_GROUPS; i++)
                if (vfio_cfg.vfio_groups[i].group_no == -1) {
-                       group_idx = i;
+                       cur_grp = &vfio_cfg.vfio_groups[i];
                        break;
                }
 
        /* This should not happen */
-       if (group_idx == -1) {
+       if (i == VFIO_MAX_GROUPS) {
                RTE_LOG(ERR, EAL, "No VFIO group free slot found\n");
                return -1;
        }
@@ -123,8 +124,8 @@ vfio_get_group_fd(int iommu_group_no)
                        /* noiommu group found */
                }
 
-               vfio_cfg.vfio_groups[group_idx].group_no = iommu_group_no;
-               vfio_cfg.vfio_groups[group_idx].fd = vfio_group_fd;
+               cur_grp->group_no = iommu_group_no;
+               cur_grp->fd = vfio_group_fd;
                vfio_cfg.vfio_active_groups++;
                return vfio_group_fd;
        }
@@ -157,9 +158,12 @@ vfio_get_group_fd(int iommu_group_no)
                        return 0;
                case SOCKET_OK:
                        vfio_group_fd = vfio_mp_sync_receive_fd(socket_fd);
-                       /* if we got the fd, return it */
+                       /* if we got the fd, store it and return it */
                        if (vfio_group_fd > 0) {
                                close(socket_fd);
+                               cur_grp->group_no = iommu_group_no;
+                               cur_grp->fd = vfio_group_fd;
+                               vfio_cfg.vfio_active_groups++;
                                return vfio_group_fd;
                        }
                        /* fall-through on error */
@@ -489,7 +493,7 @@ vfio_enable(const char *modname)
        /* inform the user that we are probing for VFIO */
        RTE_LOG(INFO, EAL, "Probing VFIO support...\n");
 
-       /* check if vfio-pci module is loaded */
+       /* check if vfio module is loaded */
        vfio_available = rte_eal_check_module(modname);
 
        /* return error directly */