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.
35 #include <sys/ioctl.h>
38 #include <rte_memory.h>
43 vfio_type1_dma_map(int vfio_container_fd)
45 const struct rte_memseg *ms = rte_eal_get_physmem_layout();
48 /* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */
49 for (i = 0; i < RTE_MAX_MEMSEG; i++) {
50 struct vfio_iommu_type1_dma_map dma_map;
52 if (ms[i].addr == NULL)
55 memset(&dma_map, 0, sizeof(dma_map));
56 dma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map);
57 dma_map.vaddr = ms[i].addr_64;
58 dma_map.size = ms[i].len;
59 dma_map.iova = ms[i].phys_addr;
60 dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
62 ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);
65 RTE_LOG(ERR, EAL, " cannot set up DMA remapping, "
66 "error %i (%s)\n", errno, strerror(errno));
75 vfio_noiommu_dma_map(int __rte_unused vfio_container_fd)
77 /* No-IOMMU mode does not need DMA mapping */