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 260E4429AE; Fri, 21 Apr 2023 16:54:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5351342D29; Fri, 21 Apr 2023 16:54:34 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2048.outbound.protection.outlook.com [40.107.243.48]) by mails.dpdk.org (Postfix) with ESMTP id 8B8D142D12 for ; Fri, 21 Apr 2023 16:54:32 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nksa04HeF/+Ox/jeF6/T2T9YJ5jzgImo/8s5NStBExlTelf8cu6U3Muyu5D96aUH4trHyBQbGHjK0BdwtcunZdtGCrPPhfguVWoBHvhIhe9vfXWkc0TD49CstuPDOTbyn5qnNJOgA+jbkXZJ8qV0x9AezscKCf3qupmoXnOSLECuYAv3GVJ2TazCEYLwU9QCIDwxhI3y/22K2OzrgATb2msAZ6aq1b/BJnH7t12ansnIWyaeGm6uP0Zn0Zkvm9X2YQPVCnlKgGZma2ln1c6eEyHaKcRV8rewEXpYuNhdCpCvw8eQ29o9WctkSiMr19IgHBQ/rWep/msCHg1IZii7Zg== 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=O5gi9eJb+FEz15eV7iUceOALhC5pkMElL9QAM9+kRfS29XHPbVNU9DhYLnMUqRGLYkTjX51j8jIDpNIs4TlYuM3mXCGvx+g/DKohmWSdLrmh8zq9SXjrkqwc3RH6T2CrBd8uJoqNrIfa158kxSJ5Uog01VrSrtbu00Qrl1bSPXOnSV9d6R9OS7Eb8Kb5ZjRZLcWxG5lutyJ15lOazOMJ3hYwh7H0W74z/8z6rOJ8nL9od3fOf8R4TsgUZtW9m90WkuvuR5qZ4eeTijqw4jaI7OdFiiUJwqLt75TXyNDxd+9f8g6Y1jiiIWGHWrfh9fNqYzOgYk04zKdcTE0LALLhmg== 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=NbB5h9gmL7bbT/mpxWd2QkyP6I0EqYJddsNUgamGXAkR0FXV9lpmna04dXrALLasdtMP1/tC9zk0Dph6+R7qC8fI9Q7GKrFL/n6cwGnGxttvH7/Cj5oJpMvik29gV9dMYevtJLonef/ZPtqnaHDuOW5R7PMpJRoDP+M+Ka37OBo= Received: from MW4PR03CA0320.namprd03.prod.outlook.com (2603:10b6:303:dd::25) by DS0PR12MB6438.namprd12.prod.outlook.com (2603:10b6:8:ca::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Fri, 21 Apr 2023 14:54:30 +0000 Received: from CO1NAM11FT089.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dd:cafe::b0) by MW4PR03CA0320.outlook.office365.com (2603:10b6:303:dd::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.25 via Frontend Transport; Fri, 21 Apr 2023 14:54:29 +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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT089.mail.protection.outlook.com (10.13.175.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.25 via Frontend Transport; Fri, 21 Apr 2023 14:54:29 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 21 Apr 2023 09:54:28 -0500 Received: from xhdipdslab41.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 21 Apr 2023 09:54:26 -0500 From: Nipun Gupta To: , , , CC: , , Nipun Gupta Subject: [PATCH v3 2/5] bus/cdx: add DMA map and unmap support Date: Fri, 21 Apr 2023 20:24:03 +0530 Message-ID: <20230421145406.12831-3-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230421145406.12831-1-nipun.gupta@amd.com> References: <20230124140746.594066-1-nipun.gupta@amd.com> <20230421145406.12831-1-nipun.gupta@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT089:EE_|DS0PR12MB6438:EE_ X-MS-Office365-Filtering-Correlation-Id: ec98c711-8e30-47e7-4526-08db42784f66 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BOC0iPhu9nM7EBUMV4amRYFOukeBtOZTwpxJ8lkqDV4p+xD7FyLfDLD13EGqACU9nmH6pw0UMKiZBQBoQeGbkzOPcYcwZ4yyaOiooDHlpKwMgDrqlWLxuVT1ixFWj6UeRSHRF2rILOX68cmd5LnbH87TT08u7OJfucf4xojb+LLMzka3orxAcfIpfLH2THQCNG+RJUSksl8u0MA0lKvPvFCxajuDVRg5UO91Uv7sSLd38xO50r1sAB05psWmUGtAFLRLmAywYdSFEyk8eNpNBZFPAgl4CQF+L6yddpI8WSt8tEKxvhbAJlxEddmn6qTTuOCqWIFwhfoDwOvGXdWHgq9MhJDMONje93r3UX0ooAUxHEhcCswyZH0USJTE7pu3tLL4ExfXdcYOtHHOJvaqus5sQNq1aXOz5ihxKvqNVYRi5N7jH1uEycNWjzqbLKISepVB6+v9TqHECXw9tKlOw93tj+iWmsLfO6GeSMI2+cgFN1UhLnZ2iqlrgJZYL5f4D6ykLbLqC2W7dBr/S1WJEzuZRcgwbyHEIDFAD8Y5m8Z2qKg9SGkuK/y8gCXe5EPljqfgzIwGOQl6jwnAGA8wb8sYuAn9+sxBWbz+CWVgeVljoG2RnABp03WY2aiblhpMgb7mTjwglkcIu5RHeCUJfchAAdD3rsC7Aa9wa/IQzSJC6EburxS+DkchGz5+HdsrYdBHkk+BPXSNy7C/a0MEwTkHd2Lj2JpZigTuuAT26a4= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB03.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(376002)(346002)(136003)(396003)(39860400002)(451199021)(40470700004)(36840700001)(46966006)(2616005)(44832011)(82310400005)(82740400003)(26005)(81166007)(40460700003)(1076003)(356005)(70206006)(478600001)(70586007)(6636002)(4326008)(36756003)(316002)(86362001)(41300700001)(6666004)(54906003)(110136005)(47076005)(426003)(36860700001)(40480700001)(336012)(8676002)(2906002)(8936002)(5660300002)(186003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2023 14:54:29.7262 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec98c711-8e30-47e7-4526-08db42784f66 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT089.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6438 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