From patchwork Mon Jul 15 08:44:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 168983 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4104518ilk; Mon, 15 Jul 2019 01:46:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwabJlRis/E62K0fYdDRC9n9f+mogjVWvDBTCnK5p6tx0wkcQa5gEU4l8fmeK2G6B1Z72ql X-Received: by 2002:aa7:c999:: with SMTP id c25mr21874265edt.134.1563180401996; Mon, 15 Jul 2019 01:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563180401; cv=none; d=google.com; s=arc-20160816; b=faHbYvJPYGZH8MNwX9L/vIvjmGOSLR06Fk7d8DLx0zRKrRhBGKPDm8AFd+VCyh39QL xUoxuc/E9Yoft6a8FMslHxkL7MPJQJ/Ul2auB+TZN9GtzQn6Mi0h94gNQQIgCELO5R1e aBdeWKOmEXpnPBcDSzsjXELtfANA2J3ZhJiKakFfb7ZbCHhomzvvG9b5ogShst4XdBoc gKUqHng+0p+Qvh7E42jmjkcPGmlyPGKJ5aeaziui18bi7TVOuX0r5XdmU++nBpwoa/Uo jmk+TLJ295t8ajhI68gTkHkX2bs2z+jkA1NR13Q2Oq4FeESAnSzhxlWECxZkEharg+uW IhXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=VS12UG0mJgm6RtWkbybirupZhXYI4UR5Ss2oqDLCwNU=; b=ixtprm3eHTZXHACjc76HDYFGYvMLuiw9+mohfW92aTZoN5CzZWhsa3oUK78VxX1N0d MlGCSQ2ECkBz83Ns+ZI9aKuhUL48Gsl+am9IsNk8w1xCNRKouTiA6WJwITGU4NnhsyHN 51ciuru7ddOQ7r/gvgBag2UokPMP47KXA17jjzOU8GuoOdkT9AHZtRYZIhMnz+Qov3YR u9ANS7LBWtjdnfEfHCY2uBB9YGebOjiZ5JERyUBWIXeYEI0q0TmHI2r+g9i9xAglKkjo Ta/V2Ic6tMOCJl2i4Cd2MYPLPVhb9xMwEAKsj4qVeQdHkr8iYBYDNVOsClPajl/KWBEE EdIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id by8si9036927ejb.129.2019.07.15.01.46.41; Mon, 15 Jul 2019 01:46:41 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F03B31B9DF; Mon, 15 Jul 2019 10:46:13 +0200 (CEST) Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by dpdk.org (Postfix) with ESMTP id BC9331B94F for ; Mon, 15 Jul 2019 10:46:05 +0200 (CEST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 9F1E920000E; Mon, 15 Jul 2019 10:46:05 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 46D8E2001A6; Mon, 15 Jul 2019 10:46:03 +0200 (CEST) Received: from bf-netperf1.ap.freescale.net (bf-netperf1.ap.freescale.net [10.232.133.63]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 2D006402B5; Mon, 15 Jul 2019 16:46:00 +0800 (SGT) From: Hemant Agrawal To: dev@dpdk.org Cc: thomas@monjalon.net, Sachin Saxena Date: Mon, 15 Jul 2019 14:14:42 +0530 Message-Id: <20190715084442.14686-6-hemant.agrawal@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190715084442.14686-1-hemant.agrawal@nxp.com> References: <20190627093343.5171-2-hemant.agrawal@nxp.com> <20190715084442.14686-1-hemant.agrawal@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH v3 5/5] mempool/dpaa2: vfio dmamap for user allocated memory X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Sachin Saxena This patch help in adding a routine to help memory map the user provided memory via VFIO. Signed-off-by: Sachin Saxena --- drivers/bus/fslmc/fslmc_vfio.c | 39 +++++++++++++++++++++ drivers/bus/fslmc/fslmc_vfio.h | 5 ++- drivers/bus/fslmc/rte_bus_fslmc_version.map | 6 ++++ drivers/mempool/dpaa2/dpaa2_hw_mempool.c | 13 +++++++ 4 files changed, 62 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 1383af4f1..247b2a4a1 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -358,6 +358,45 @@ fslmc_dmamap_seg(const struct rte_memseg_list *msl __rte_unused, return ret; } +int +rte_fslmc_vfio_mem_dmamap(uint64_t vaddr, uint64_t iova, uint64_t size) +{ + int ret; + struct fslmc_vfio_group *group; + struct vfio_iommu_type1_dma_map dma_map = { + .argsz = sizeof(struct vfio_iommu_type1_dma_map), + .flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE, + }; + + if (fslmc_iommu_type == RTE_VFIO_NOIOMMU) { + DPAA2_BUS_DEBUG("Running in NOIOMMU mode"); + return 0; + } + + /* SET DMA MAP for IOMMU */ + group = &vfio_group; + if (!group->container) { + DPAA2_BUS_ERR("Container is not connected"); + return -1; + } + + dma_map.size = size; + dma_map.vaddr = vaddr; + dma_map.iova = iova; + + DPAA2_BUS_DEBUG("VFIO dmamap 0x%llx:0x%llx, size 0x%llx\n", + dma_map.vaddr, dma_map.iova, dma_map.size); + ret = ioctl(group->container->fd, VFIO_IOMMU_MAP_DMA, + &dma_map); + if (ret) { + printf("Unable to map DMA address (errno = %d)\n", + errno); + return ret; + } + + return 0; +} + int rte_fslmc_vfio_dmamap(void) { int i = 0, ret; diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h index 9e2c4feef..4132f1fa4 100644 --- a/drivers/bus/fslmc/fslmc_vfio.h +++ b/drivers/bus/fslmc/fslmc_vfio.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 2015-2016 Freescale Semiconductor, Inc. All rights reserved. - * Copyright 2016 NXP + * Copyright 2016,2019 NXP * */ @@ -50,5 +50,8 @@ int fslmc_vfio_process_group(void); char *fslmc_get_container(void); int fslmc_get_container_group(int *gropuid); int rte_fslmc_vfio_dmamap(void); +__rte_experimental +int +rte_fslmc_vfio_mem_dmamap(uint64_t vaddr, uint64_t iova, uint64_t size); #endif /* _FSLMC_VFIO_H_ */ diff --git a/drivers/bus/fslmc/rte_bus_fslmc_version.map b/drivers/bus/fslmc/rte_bus_fslmc_version.map index e86007384..4da787236 100644 --- a/drivers/bus/fslmc/rte_bus_fslmc_version.map +++ b/drivers/bus/fslmc/rte_bus_fslmc_version.map @@ -141,3 +141,9 @@ DPDK_19.05 { qbman_result_eqresp_set_rspid; qbman_swp_enqueue_multiple_fd; } DPDK_18.11; + +EXPERIMENTAL { + global: + + rte_fslmc_vfio_mem_dmamap; +}; diff --git a/drivers/mempool/dpaa2/dpaa2_hw_mempool.c b/drivers/mempool/dpaa2/dpaa2_hw_mempool.c index da66577cc..f26c30b00 100644 --- a/drivers/mempool/dpaa2/dpaa2_hw_mempool.c +++ b/drivers/mempool/dpaa2/dpaa2_hw_mempool.c @@ -23,6 +23,7 @@ #include #include "rte_dpaa2_mempool.h" +#include "fslmc_vfio.h" #include #include #include @@ -405,6 +406,18 @@ dpaa2_populate(struct rte_mempool *mp, unsigned int max_objs, void *vaddr, rte_iova_t paddr, size_t len, rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg) { + struct rte_memseg_list *msl; + /* The memsegment list exists incase the memory is not external. + * So, DMA-Map is required only when memory is provided by user, + * i.e. External. + */ + msl = rte_mem_virt2memseg_list(vaddr); + + if (!msl) { + DPAA2_MEMPOOL_DEBUG("Memsegment is External.\n"); + rte_fslmc_vfio_mem_dmamap((size_t)vaddr, + (size_t)paddr, (size_t)len); + } /* Insert entry into the PA->VA Table */ dpaax_iova_table_update(paddr, vaddr, len);