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 06E2442B9A; Thu, 25 May 2023 12:09:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6839342D47; Thu, 25 May 2023 12:09:04 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2052.outbound.protection.outlook.com [40.107.220.52]) by mails.dpdk.org (Postfix) with ESMTP id 99375410DC for ; Thu, 25 May 2023 12:09:02 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RKWRM6OcZJnw/QZO1G/cuK+zPAdKb4t8GZo/0x+yF9yxPinxqWPxUsfABR/ZGcGW3xXf8OWadVNEvaCAlBVzTduuqVQajRO1RuSNHgSu78xv9MtwgZ5+PViqFwqWAI7DPJlkU9V4X48okP6qAQfF3H/yBrQAC8KQnDKDPdGGP/9HlyFI1WyWkjzGF3ifpzhi1yIaQIZoiHgrPE51Z2Hv+8BM0v9oY2JLOjtSpVuUkLvQuxMyBvVM+RhRhNEiZV8rovJsubFEOHfw+SpF09Swvx5nbOfgOuEO88naUcrYbUmqzf98EkvfJ8p8KqyZxwzdEcMyAsQitsgIgANZz9QfsQ== 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=lRzf1jClW9tkIr8sYfsYwYgybKirbNFdJ1kg8liVrGE=; b=dABrURDB1uMhMwyMgPdPMBzjO9n5OkntYLyXwJ90Y+59oisKKpGQXJKgWnW9lW1yiSPFP3ba3KJuNFKTSxTeT5MAyywvLpCwpXwyJrQRspK4L+s+3NznNFj80Y4osTvBy/LueChvRgN0F6hcs+9Q7G93oyoaUmWjt8flotOze+MpMzP4uqxKZ4+jcjex+gCZoL2KT/KFvqr00MIVyiabig1XjzYklqqZiTNb3jM5MK5Gy360E9hlxony3XN7COsGdeWWzPlMoEXNVhMo3FkChtjlFAyW461yhDF6WPvrinWZ1eoKkpGxGjtogbxcj/B+/b34Pp3xCmV7CUzRoXK8Iw== 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=lRzf1jClW9tkIr8sYfsYwYgybKirbNFdJ1kg8liVrGE=; b=jWYtcmiWRMtvNGRfhF+QAzs+EK9yErnT8J2nCbtWS4i5gyyeLZVRBQJv+5yDnHu1QoQbR+LCuxe8tVEgLd4b6UzyRNOis7g5wMFE/L5Gbv8qHcxIw3v6+3gk4+uml2kBPF2B2QaIEGdq08wnaRr43UcKupWIh7Xs3TrhwzeXsAc= Received: from MW4P223CA0018.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::23) by CH3PR12MB8971.namprd12.prod.outlook.com (2603:10b6:610:177::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.15; Thu, 25 May 2023 10:09:00 +0000 Received: from CO1NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:303:80:cafe::f7) by MW4P223CA0018.outlook.office365.com (2603:10b6:303:80::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.17 via Frontend Transport; Thu, 25 May 2023 10:09:00 +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 CO1NAM11FT010.mail.protection.outlook.com (10.13.175.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6433.17 via Frontend Transport; Thu, 25 May 2023 10:08:43 +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; Thu, 25 May 2023 05:08:41 -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; Thu, 25 May 2023 05:08:38 -0500 From: Nipun Gupta To: , , , , , CC: , , , Nipun Gupta Subject: [PATCH v5 2/5] bus/cdx: add DMA map and unmap support Date: Thu, 25 May 2023 15:38:18 +0530 Message-ID: <20230525100821.12148-3-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230525100821.12148-1-nipun.gupta@amd.com> References: <20230124140746.594066-1-nipun.gupta@amd.com> <20230525100821.12148-1-nipun.gupta@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT010:EE_|CH3PR12MB8971:EE_ X-MS-Office365-Filtering-Correlation-Id: 314d5218-875c-4ba7-6ebd-08db5d080548 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xNpioiSoDmjNnGhtftwkXN0tzK8NiqfogH2Gjdyq+tnRZIjgOPyu/cKJLS5gBpEzVoZB3rKKgly2JIOiYl4MXQQ5/Sbevwk3ULduqpL3J6f1S9KA3pxWlDtqJucnchQ3iWtRCa0fz0BzSWZtZx1vLwIpJzNxX3oyAaEXtlVc5SZdVrFZYJ2vklsYi4DkIL4nN+JAptkBrYLWWaYWbQ6+NGDIfjeYFRfakdPsAoZKneMzS/VC6ZPz0znBsTtZUZifMnY2oe3I0eFCf9gINChvNAdTqtpUT6d/15JshJx9cj11X8JpkufDFnFYFr6S96ju3fEnc4h0g1N8R+OqGkbTzPgKep7/5lrBnKx2xcLBwDsHKr9PKQ0/I+R7GVrrv9VrlKbREAGJ53hlypQu+rwQ87D8t8yOWY5wLjQqkKKEwFoIjUVQQm6T8Ry+VlxDXr/iT7VDznJq958Dx2FXqFJk0JRoJeHQQcK0glPQ4Ko45NnvKiog1MljXguWPG6TOtsylIdqmwWhF8hd0e/e1wNZl+RTXHH8GNd6bOleUf3Dznwb2Ueg9T2iMJOeuUw7yTJAz2IyztZSobEvUwd4tYZi1mqveYXOmdFX4VHsUT+5l6sE4+QcYLi1rQYIMWpiakdHyPOEiBjwuAaRhG2GDodTCV1PPUE7GFBCagwGLRpdYC3n8g0qkw4TNjCuGMrWj9QtO/EczDdhSeO5g210M/xGcj35REdIkCLTAS/4V5z0ME8zY+6nIYIii6kJmL7FdsiRpBIv/LX34exvU+GQIqnXoA== 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)(136003)(39860400002)(396003)(346002)(451199021)(46966006)(40470700004)(36840700001)(70206006)(4326008)(70586007)(110136005)(54906003)(1076003)(316002)(82310400005)(40480700001)(26005)(6666004)(41300700001)(478600001)(81166007)(8676002)(8936002)(5660300002)(40460700003)(47076005)(2616005)(86362001)(426003)(36756003)(336012)(356005)(82740400003)(44832011)(186003)(2906002)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2023 10:08:43.1405 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 314d5218-875c-4ba7-6ebd-08db5d080548 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: CO1NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8971 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 AMD 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 Acked-by: Ferruh Yigit --- 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 1ddb5a92f7..64ea879f3b 100644 --- a/drivers/bus/cdx/cdx.c +++ b/drivers/bus/cdx/cdx.c @@ -502,12 +502,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