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 9DE7142A94; Mon, 8 May 2023 13:18:52 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 638F542D1A; Mon, 8 May 2023 13:18:47 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2046.outbound.protection.outlook.com [40.107.244.46]) by mails.dpdk.org (Postfix) with ESMTP id D8A6842D1A for ; Mon, 8 May 2023 13:18:45 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RJDYL5rU2Tufw9ROf5ISljVuIiWUX1fqP3LJcr7//lj9hn525QBpuprjk5BvsJKjIJO1CwYh/wtbu846wZOECflDHy4sduLq+4kNcsCEAWku4j4UWn6Smi/e6w+M/jD19lu8J+ZD1n0auFGIcgYomtYAM68LIyQtq17sVC5cWPRdRQKsqkz1sosYjjeBrO2HLVmZS+mL5dz2zuZiHvefLOxMp8T5ssaNJccdVjaFxkhXcwyNWhrcRubyqUlew7Pyved6oqXu4/dQb7Bm+XIaUk3FiwB4PrVxveRoN9hzG3/PRw7CCdnWH9Pdpd3xq+eJfWEQSbhP8s5n0HKAyxZTSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HSSroEHH/p4mEPGHjbBg/tJA7WlY3xcGMa3jL2YuG8M=; b=MrvYsRAoFe+0FpsHX3tCNifcoFIpbQsbghO/RtBhVVGp00al1iQ15VDFMz+DnEKrwQthc3dTnzelcqCoBXrCDVmr0S9TcvfZXvee5gSe4AMJvimhpn1Nxdz6AGbFDl9sFEJkQiVMkAF+o2xtv4Nm/JXkfeLmfk4jsuIVEQ6voqBXH4kBdszdOCWplyC541YLqXzwJZ6JxhzY/k3uqHIR/4Ov4CbFgzNJY/tK9qCmzTKVtLxV273rs24wE8qIOGEt57nO59hjPaF7VXah5gnJrFmO5Pldd3dFPCmkDv8Z3N1UpbcOAsb1i34I8y3hT73WLFqFCrPyz8vqlCLbtSg7mw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=dpdk.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HSSroEHH/p4mEPGHjbBg/tJA7WlY3xcGMa3jL2YuG8M=; b=tN4QxynlI2M8oidwGIuMpscAlgJOqQOiwwlqIx7sQr1IdLrkTESGAMF+VzzgNHP8OAY0uO6Pb54JzitHxl9SDRs7ISZ+bXg5jhEFGqRmpsIsDQaiM1hwq3+LbLtcefSnwMcCietI6H28rZjwhfih09OdjILiyvSPQqNTsdjE5/A= Received: from BN9PR03CA0947.namprd03.prod.outlook.com (2603:10b6:408:108::22) by BL3PR12MB6476.namprd12.prod.outlook.com (2603:10b6:208:3bc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.29; Mon, 8 May 2023 11:18:43 +0000 Received: from BN8NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:408:108:cafe::e2) by BN9PR03CA0947.outlook.office365.com (2603:10b6:408:108::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32 via Frontend Transport; Mon, 8 May 2023 11:18:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT014.mail.protection.outlook.com (10.13.177.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.32 via Frontend Transport; Mon, 8 May 2023 11:18:43 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 8 May 2023 06:18:43 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 8 May 2023 04:18:42 -0700 Received: from xhdipdslab41.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Mon, 8 May 2023 06:18:40 -0500 From: Nipun Gupta To: , , CC: , , , Nipun Gupta Subject: [PATCH v4 2/4] bus/cdx: add DMA map and unmap support Date: Mon, 8 May 2023 16:48:10 +0530 Message-ID: <20230508111812.2655-3-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230508111812.2655-1-nipun.gupta@amd.com> References: <20230124140746.594066-1-nipun.gupta@amd.com> <20230508111812.2655-1-nipun.gupta@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT014:EE_|BL3PR12MB6476:EE_ X-MS-Office365-Filtering-Correlation-Id: 717332e0-9859-4e78-7494-08db4fb5fbcc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ayeQq8v9S4sY1rvlHWSaNBv4Ujqdp29jDtVrNyZfpc3qe5/0VAxR5u9Mq4XZCe2ngesXblxZVl5bk4g1tGMWPxbceP3xhhlYQgVoburGbdlikJvSZ9sWBJV8PMp9AekBQPcsWBhm0MWkt4kKUGOF2/ftIzglpHy6tfDhVUGYxCuHHhfZ7rq6jXAloG4Mvu5i3x/AULa8+bJw6DjWlxdf/3RLWbPvedSs7795/ZiEWc2U/690w3rXTjo85IEpp/KZTpaiAIgS0APlTDDHfrL3J5H2d30Rk/5hneWlhpdM3GExQrmPXAKyzdAD6Et0JYsdtbSJO3hOh3n1GJyVPRBrgOWE9ny4l0uovgDKbdaHfF0FQiQaUfmZxhJCPIq/ElgLTCF09YwtWHidoQ8+XnUMf4ZH7N7ThxQW80GVZAwkFxEa49V6TDDZavyCae7Lpf5TE9APFYrB4uJ5/AipvIA6e68ZMSiOkoiostGLDUKsJRxwG5sqfgJHywmhTKDJMbKKWtSQBo4iHJKR2XgXXCskjJk5DXK5ysJ6EblDLQuBCEuGqr4bq6qWg8TUps88nQgU6EMziUaniD6ZeCEUYHI1FDT1bbPb9jfuQ/QXh1MJjeYEe7b2BFAU3wwO2Tq5FPhkw6hy0q9UHtJrWzLDZOA8OXjXrFWw9nhkjsbBqguZB1E8CcY42CvPRo0K5aMLXTS46gD6bzQIH3SYzbOxopeiMTI1IMOiBWBf8wzpnUeXMWk= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(346002)(39860400002)(376002)(136003)(396003)(451199021)(40470700004)(46966006)(36840700001)(86362001)(40480700001)(8676002)(8936002)(70586007)(70206006)(4326008)(82740400003)(356005)(5660300002)(40460700003)(36756003)(82310400005)(81166007)(478600001)(47076005)(36860700001)(336012)(426003)(41300700001)(2906002)(54906003)(110136005)(2616005)(1076003)(316002)(26005)(6666004)(44832011)(186003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2023 11:18:43.4899 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 717332e0-9859-4e78-7494-08db4fb5fbcc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6476 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 CDX bus can use VFIO interface for mapping and unmapping of DMA addresses in the IOMMU. This change adds the callback support for map and unmap APIs as well as fetching the IOMMU class. Signed-off-by: Nipun Gupta --- drivers/bus/cdx/cdx.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c index d479daa315..8cc273336e 100644 --- a/drivers/bus/cdx/cdx.c +++ b/drivers/bus/cdx/cdx.c @@ -505,12 +505,52 @@ cdx_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, return NULL; } +static int +cdx_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len) +{ + struct rte_cdx_device *cdx_dev = RTE_DEV_TO_CDX_DEV(dev); + + if (!cdx_dev) { + rte_errno = EINVAL; + return -1; + } + + return rte_vfio_container_dma_map(RTE_VFIO_DEFAULT_CONTAINER_FD, + (uintptr_t)addr, iova, len); +} + +static int +cdx_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len) +{ + struct rte_cdx_device *cdx_dev = RTE_DEV_TO_CDX_DEV(dev); + + if (!cdx_dev) { + rte_errno = EINVAL; + return -1; + } + + return rte_vfio_container_dma_unmap(RTE_VFIO_DEFAULT_CONTAINER_FD, + (uintptr_t)addr, iova, len); +} + +static enum rte_iova_mode +cdx_get_iommu_class(void) +{ + if (TAILQ_EMPTY(&rte_cdx_bus.device_list)) + return RTE_IOVA_DC; + + return RTE_IOVA_VA; +} + struct rte_cdx_bus rte_cdx_bus = { .bus = { .scan = cdx_scan, .probe = cdx_probe, .find_device = cdx_find_device, .parse = cdx_parse, + .dma_map = cdx_dma_map, + .dma_unmap = cdx_dma_unmap, + .get_iommu_class = cdx_get_iommu_class, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_cdx_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_cdx_bus.driver_list), -- 2.17.1