vfio: enable independently of PCI bus
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_vfio.c
index b32cd09..e0d37dc 100644 (file)
@@ -489,7 +489,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 */
@@ -762,10 +762,19 @@ vfio_spapr_dma_map(int vfio_container_fd)
                return -1;
        }
 
-       /* calculate window size based on number of hugepages configured */
-       create.window_size = rte_eal_get_physmem_size();
+       /* create DMA window from 0 to max(phys_addr + len) */
+       for (i = 0; i < RTE_MAX_MEMSEG; i++) {
+               if (ms[i].addr == NULL)
+                       break;
+
+               create.window_size = RTE_MAX(create.window_size,
+                               ms[i].phys_addr + ms[i].len);
+       }
+
+       /* sPAPR requires window size to be a power of 2 */
+       create.window_size = rte_align64pow2(create.window_size);
        create.page_shift = __builtin_ctzll(ms->hugepage_sz);
-       create.levels = 2;
+       create.levels = 1;
 
        ret = ioctl(vfio_container_fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
        if (ret) {
@@ -774,6 +783,11 @@ vfio_spapr_dma_map(int vfio_container_fd)
                return -1;
        }
 
+       if (create.start_addr != 0) {
+               RTE_LOG(ERR, EAL, "  DMA window start address != 0\n");
+               return -1;
+       }
+
        /* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */
        for (i = 0; i < RTE_MAX_MEMSEG; i++) {
                struct vfio_iommu_type1_dma_map dma_map;