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 2D62942933; Thu, 13 Apr 2023 15:27:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF10142B71; Thu, 13 Apr 2023 15:27:52 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2051.outbound.protection.outlook.com [40.107.93.51]) by mails.dpdk.org (Postfix) with ESMTP id ECEB9410F2 for ; Thu, 13 Apr 2023 15:27:51 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LbVSSR7kAKBqi4WW+cJ2tb04EbsrtEBPBnlgRt/0Nc0PjJ/UIdVEtjgi+88lCOPv8vDyEjglZ5R8jpd+hNlwILJbh81e/zv6wC2hm0F924rzySEZmrBIBq1Z1f+TDO3LtccG+Qj7oqGJJWU3zzi1fOUIDrCygyohvp1HkqItIZeBcyFz6AfKpbLAoghqNUYoZtis1y0ZsbpVLeq01z0n2sFUt//2Tp0mGiH8pacNMo5feXBsZZHvt6cWbkYuzjFQ1uBnarKZoG1IWI6yloHz6t93w1wX0T0mXMBeYNM+OPODUHGDHcWx7LxNWXvnLgU3K1yhPJdnWGm6ZKXKYSvPJg== 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=6uc8hYhxmsRh3RlIaX0z7pSR1DfICwTOu7OvlztOPzw=; b=eyzI9FV/ZjyQbXqhqlJxhkAA6frIhqoSYp2jp8YR6bu4uEADuu3VCcg+G23SWmKmwmr8kzhV3jVL8/c4Ouvl3YvX/GFNZnLkdnvj7+twuzVYvXydBJ4SeZVQmCDXr/nrhLZg4M91fek+ubwgB82WjIm+JiU8+94HU6isirtBCQ8DvADSuZ43p+ReEBB5x6L6O7gDw74fXcOJVhfLPH+HuT6mNhVWXpa0AVixaM4monI5IcYLjfDGO/w1qrqU5Nt+HdYYnDurgTzlI+yxN+p2LaiSC8l2MuXvQiq97SRjvMtobfwalatRtS/WQFoefcZH46HsJN2XzSFB1vp06ZOpMg== 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=6uc8hYhxmsRh3RlIaX0z7pSR1DfICwTOu7OvlztOPzw=; b=R724nI4URdziGzns0cB0CXZ+htgerd47t6MRfiCt8/vLfXLqEcwodeugY3HsZAuRtZLyrpu1P97lw5t0ptyWVB5104/RAbllqnsug8G0IpTPTZuRPHhcDAQP7s/sfzMOgeaEKVhX3TO1lEgSSKxNAng9e2sMm8Q1EUECixIbWh4= Received: from DM6PR18CA0015.namprd18.prod.outlook.com (2603:10b6:5:15b::28) by CH0PR12MB5345.namprd12.prod.outlook.com (2603:10b6:610:d4::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.30; Thu, 13 Apr 2023 13:27:49 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:5:15b:cafe::2c) by DM6PR18CA0015.outlook.office365.com (2603:10b6:5:15b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.32 via Frontend Transport; Thu, 13 Apr 2023 13:27:49 +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 DM6NAM11FT045.mail.protection.outlook.com (10.13.173.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.31 via Frontend Transport; Thu, 13 Apr 2023 13:27:49 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) 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; Thu, 13 Apr 2023 08:27:46 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 13 Apr 2023 06:27:41 -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; Thu, 13 Apr 2023 08:27:39 -0500 From: Nipun Gupta To: , , CC: , , , Nipun Gupta Subject: [PATCH v2 2/6] bus/cdx: add dma map and unmap support Date: Thu, 13 Apr 2023 18:57:00 +0530 Message-ID: <20230413132704.17586-3-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230413132704.17586-1-nipun.gupta@amd.com> References: <20230124140746.594066-1-nipun.gupta@amd.com> <20230413132704.17586-1-nipun.gupta@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT045:EE_|CH0PR12MB5345:EE_ X-MS-Office365-Filtering-Correlation-Id: c9f2cb15-a3fe-451e-87ef-08db3c22e07a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vHr5Ki9bhTvsUs8eUGnCV6tss0GFAc+0YXpf1hj/w6jpUJmNrqKBRj2+Io6Wa95q6RBACBuWFOyy6Ax/8v6rTqzGVPVn5i/W7LtCafcqyi1z8HxcO9Bh0oHULUDQXQPT3wky3zl+s8rrJEDwDLEEnp3MbpccAzfA1moYxChxmTfscqFdoYnUduy1Ak6eXmAvOwbMVDoKeNFjB1JzbijlQ5ERy48NS2FP8Bo7NadWnx8x4wMN7RY67BRb4BvDdRYPD8aZ5TuCcNdpsLHDTsTglHsgkBovoIw/qGOBeNPNppqT9RzUnQP17IoxkNrz+GURUnK8nsguGW87H+1CZjXu4svjl7WjtymoN/NvpU2vxfeD9/E0lXzC2TmiDRmtKfiTd7KNBzZE3QBywN3gC8Zva2eZtXm92AUISYAyYn540f2ws7qE574bUnrWAPznnkB19HhKqqLOJTnVBQnBoBELnFnQoo4CDObjXMkl2mJSIlbHjM1PoeZaGWWSOuoxCWrT5yIyPXxrWS79ASeoJjkpa8j1EoH7lT9WnImelxVsVvW7+M1qE3fNsxmGOdeiyz8/pN8BtOxdkAQeOU4slB9D8MOlzTt/gjt1MBog1Ix/IXEQ8MtMNzAgSeM/N0Pdz5pGnABIMrzzs9TInMUnQlRdbVzRv+Ep/m/+os/xH4rSUlXTUriGQk7sIhFXeox2kcbjlEy0b9goLWrqrKYQQDCtyB2cQ9q3cnSvMg3IXxbK4vs= 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)(376002)(39860400002)(346002)(136003)(396003)(451199021)(36840700001)(40470700004)(46966006)(8676002)(36860700001)(47076005)(336012)(426003)(2616005)(478600001)(6666004)(40460700003)(26005)(54906003)(110136005)(1076003)(186003)(2906002)(44832011)(5660300002)(36756003)(81166007)(316002)(4326008)(356005)(82310400005)(70586007)(70206006)(41300700001)(82740400003)(8936002)(40480700001)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2023 13:27:49.4957 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c9f2cb15-a3fe-451e-87ef-08db3c22e07a 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: DM6NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5345 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 bb23b32312..b1d8f8382f 100644 --- a/drivers/bus/cdx/cdx.c +++ b/drivers/bus/cdx/cdx.c @@ -506,12 +506,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