From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EFAC1A0093; Fri, 23 Dec 2022 00:25:35 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 748FE42D40; Fri, 23 Dec 2022 00:25:01 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id DA6B842D31 for ; Fri, 23 Dec 2022 00:24:59 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BMGxxP5026098; Thu, 22 Dec 2022 15:24:59 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=5H676N6tmb7oysnbDjCLzw+5ja+MvWgnYw6R0dtZeOI=; b=SPLIUx2/sJVyaXfCX/yJADqc7lkDIttZgZDiUUTTVNXJAEppqTxAIQZ+Xv+4S8dfSjg1 YrTWPJZcQw8niy+AjZ0AqEGyHEAQRhOhDF3Mx3oXKwpzv0AtnBehY5TweyadPUi4MsIa WdW9kvLy/RWW5JlcjbCVDQ2a7OEjTc7pqxELlS5Qy8ciJZeteX5OwEmhBdcyjxuGV5n6 p88e3DYPRlAxszKQcNm2D9+8jEmulU2oLcQyFI1OkjxhEZU/LxPBNiFLbpE5QbjNg+vn Gp24S2dvOT1zFLZpRemxErJsOG14tJFVjf+0lUMEQ9yNvoUDx4whXEmH+J0+WR/Ydb7k QQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3mhe5runyc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 22 Dec 2022 15:24:59 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 22 Dec 2022 15:24:57 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 22 Dec 2022 15:24:57 -0800 Received: from localhost.localdomain (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id B3E513F7055; Thu, 22 Dec 2022 15:24:55 -0800 (PST) From: Tomasz Duszynski To: CC: , , Tomasz Duszynski Subject: [RFC PATCH 7/7] raw/vfio_platform: support DMA map/unmap Date: Fri, 23 Dec 2022 00:24:35 +0100 Message-ID: <20221222232436.643514-8-tduszynski@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221222232436.643514-1-tduszynski@marvell.com> References: <20221222232436.643514-1-tduszynski@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: 2hLtrGxX_R3duVStz4kChO6YeAGveXjG X-Proofpoint-ORIG-GUID: 2hLtrGxX_R3duVStz4kChO6YeAGveXjG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-22_10,2022-12-22_03,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add support for DMA map/unmap operations. Signed-off-by: Tomasz Duszynski --- .../raw/vfio_platform/rte_pmd_vfio_platform.h | 40 +++++++++++ drivers/raw/vfio_platform/version.map | 2 + drivers/raw/vfio_platform/vfio_platform.c | 67 +++++++++++++++++++ 3 files changed, 109 insertions(+) diff --git a/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h index 377cebde08..e1c194c46d 100644 --- a/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h +++ b/drivers/raw/vfio_platform/rte_pmd_vfio_platform.h @@ -82,6 +82,46 @@ __rte_experimental int rte_pmd_vfio_platform_container_destroy(int container); +/** + * Map DMA memory. + * + * @param dev_id + * Device identifier. + * @param addr + * Virtual address to map. + * @param iova + * IOVA address to map. + * @param len + * Length of the memory segment being mapped. + * + * @return + * 0 on success + * <0 on failure and rte_errno is set + */ +__rte_experimental +int +rte_pmd_vfio_platform_dma_map(uint16_t dev_id, void *addr, uint64_t iova, size_t len); + +/** + * Remove DMA memory mapping. + * + * @param dev_id + * Device identifier. + * @param addr + * Virtual address to map. + * @param iova + * IOVA address to map. + * @param len + * Length of the memory segment being mapped. + * + * @return + * 0 on success + * <0 on failure and rte_errno is set + */ +__rte_experimental +int +rte_pmd_vfio_platform_dma_unmap(uint16_t dev_id, void *addr, uint64_t iova, size_t len); + #ifdef __cplusplus } #endif diff --git a/drivers/raw/vfio_platform/version.map b/drivers/raw/vfio_platform/version.map index 2aea50f4c1..1b54459183 100644 --- a/drivers/raw/vfio_platform/version.map +++ b/drivers/raw/vfio_platform/version.map @@ -7,4 +7,6 @@ EXPERIMENTAL { rte_pmd_vfio_platform_container_create; rte_pmd_vfio_platform_container_destroy; + rte_pmd_vfio_platform_dma_map; + rte_pmd_vfio_platform_dma_unmap; }; diff --git a/drivers/raw/vfio_platform/vfio_platform.c b/drivers/raw/vfio_platform/vfio_platform.c index 8148dce06b..966f9f177e 100644 --- a/drivers/raw/vfio_platform/vfio_platform.c +++ b/drivers/raw/vfio_platform/vfio_platform.c @@ -94,6 +94,45 @@ rte_pmd_vfio_platform_container_destroy(int container) return 0; } +static struct rte_rawdev * +rawdev_from_dev_id(uint16_t dev_id) +{ + if (!rte_rawdev_pmd_is_valid_dev(dev_id)) + return NULL; + + return &rte_rawdevs[dev_id]; +} + +int +rte_pmd_vfio_platform_dma_map(uint16_t dev_id, void *addr, uint64_t iova, size_t len) +{ + struct rte_rawdev *rawdev; + + rawdev = rawdev_from_dev_id(dev_id); + if (!rawdev) { + rte_errno = ENODEV; + + return -1; + } + + return rte_dev_dma_map(rawdev->device, addr, iova, len); +} + +int +rte_pmd_vfio_platform_dma_unmap(uint16_t dev_id, void *addr, uint64_t iova, size_t len) +{ + struct rte_rawdev *rawdev; + + rawdev = rawdev_from_dev_id(dev_id); + if (!rawdev) { + rte_errno = ENODEV; + + return -1; + } + + return rte_dev_dma_unmap(rawdev->device, addr, iova, len); +} + static int vfio_rawdev_dev_info_get(struct rte_rawdev *dev, rte_rawdev_obj_t dev_info, size_t dev_private_size) @@ -371,9 +410,37 @@ vfio_platform_remove(struct rte_platform_device *pdev) return ret; } +static int +vfio_platform_dma_map(struct rte_platform_device *pdev, void *addr, uint64_t iova, size_t len) +{ + struct vfio_platform *plat = pdev->driver_data; + int ret; + + ret = rte_vfio_container_dma_map(container_fd(plat->container), (uint64_t)addr, iova, len); + if (ret) + return -EFAULT; + + return 0; +} + +static int +vfio_platform_dma_unmap(struct rte_platform_device *pdev, void *addr, uint64_t iova, size_t len) +{ + struct vfio_platform *plat = pdev->driver_data; + int ret; + + ret = rte_vfio_container_dma_unmap(container_fd(plat->container), (uint64_t)addr, iova, len); + if (ret) + return -EFAULT; + + return 0; +} + static struct rte_platform_driver vfio_platform = { .probe = vfio_platform_probe, .remove = vfio_platform_remove, + .dma_map = vfio_platform_dma_map, + .dma_unmap = vfio_platform_dma_unmap, }; RTE_PMD_REGISTER_PLATFORM(vfio_platform, vfio_platform); -- 2.25.1