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 2C2E74247C; Tue, 24 Jan 2023 15:08:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 353E442D3E; Tue, 24 Jan 2023 15:08:00 +0100 (CET) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2070.outbound.protection.outlook.com [40.107.237.70]) by mails.dpdk.org (Postfix) with ESMTP id EEB5C427EE for ; Tue, 24 Jan 2023 15:07:57 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j9gjz9C/pZNR+kyEMtGE94gK2g7z2tT3CZts2J+DC3Xxp3zWI6vNrDDHzeNT33R6PR8YtVcQTV523GmAt7FDS1YaNt21PvOVF8diR9tnyrVG5OPSpVDTtkd+yeje7cGBRsbfHFg9xr8NT5YpX2MJwnfSI7O8zBVlq0aFb7Wzlft+M6nKO4qD3xaEFHEa+k/7mmJzmE41/OEi4IA7x0pHT3xLiBKUIqvry5Qg28aqWAKuibpxI03hTtyJ2J9kZChS7gLKUy1l5G2NtC6WQk3l9b2oJqjqAJm99+A8r8ozM/6f+S0ybApHtol8CrB31obgAGjWcwG5lQiDK5yPykrSLQ== 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=bmq14dUO9n5MxgfnEPpcbmGDrOmELcVU7I6hnhqfGy8=; b=ZiBf6sRZqJMyVFchkgTHY1UnBORoAmxoWjnqbGrm8iagGYViwtReCl6BVWBmeoeIxHa/j9lqWsHOfcIhlYMsZwbCJBZk6J1m08UzX5WBnX6oDrzUMEnMJy2+e5VBhEV9LTo/wX+XJdg0VVQ4J98HFTtPty04aCWZ+sNE1EcDqCE6Lwc521EA1Cq0DflbHdHGzYPoaaMSl5y8whjVyRnBrLpOwzTt2saiK2X+T32Wka9Je0vkw5KCbFqK15f3rOYs36cJ59r/yeviNL/Lswel5ep8jdjL4LLirLl5tbXxqmigK02wIsK6XfW0tXymIWb/VK6n+bs8rG3CdEnNFB9xyw== 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=bmq14dUO9n5MxgfnEPpcbmGDrOmELcVU7I6hnhqfGy8=; b=391BuqoytBXsH20v7gXRM41wfcJcvgSgMv6UVLmKdLzsgolOmDevMLXqvZVw+BVvl6/GlwP4a54w0jc4sHqDfYrRqWT2hM10+1gfi5Y8kgHhBbbXHlENiLcpE4HpmFefDdlPetrOdMpn87Dq4p+E4I3GaEhKd/U+zZqgvq5KKmI= Received: from BN9PR03CA0238.namprd03.prod.outlook.com (2603:10b6:408:f8::33) by MN0PR12MB5810.namprd12.prod.outlook.com (2603:10b6:208:376::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 14:07:55 +0000 Received: from BN8NAM11FT021.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f8:cafe::66) by BN9PR03CA0238.outlook.office365.com (2603:10b6:408:f8::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Tue, 24 Jan 2023 14:07:55 +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 BN8NAM11FT021.mail.protection.outlook.com (10.13.177.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.17 via Frontend Transport; Tue, 24 Jan 2023 14:07:54 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Tue, 24 Jan 2023 08:07:53 -0600 Received: from xhdipdslab49.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; Tue, 24 Jan 2023 08:07:52 -0600 From: Nipun Gupta To: , , CC: , , Subject: [RFC PATCH 2/6] bus/cdx: add dma map and unmap support Date: Tue, 24 Jan 2023 19:37:42 +0530 Message-ID: <20230124140746.594066-3-nipun.gupta@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230124140746.594066-1-nipun.gupta@amd.com> References: <20230124140746.594066-1-nipun.gupta@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT021:EE_|MN0PR12MB5810:EE_ X-MS-Office365-Filtering-Correlation-Id: 0445afc4-5672-4547-30b5-08dafe146382 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3Kgi207AxwSasgAQFGUl+anZSVJ/NGZlx9tyx3/aPUfGZJIk9tpoJNuZcepOJ/MzU/0Paf0EHDDXI/hsoWmE118RIDMeQFRfgioSk7W5gapoTW4ymh1QiaUWzfRjHNsH2ppep6sJdgSnRcHtk2UchVPEjD9YpKtC8cFb9OYee/Pkut0mHfVBGnKTnAYLXvue4HiD0ORe8VVccKM9Al0nAvYXEXMbwkfAfJZwNh+0oLSQRpbPXLtIMLlampO24vVTub0lsjdALgMFw3qKjm+Fy7pYm0rOZ8sqfvgaaSyGaMse+RBSWuCX5UbZYdJwbNZhUF0fLAaCbOMc7yA3eeyyKsx9DqxCzBgsEqxobrVVNIpvRj+QeYdxip0QF75ydspdRqxzfAfSpfQLdiJEwu84np0sgk9Y1uPmiFhd4ah0dwkmk6NGKLnphdwnemuK5+c24jEBtqS2zzL70keARbQhRqMCQc5o+SBr9nGBAj580IugYpmq2Dy37WkfTgbCaTdcPf8LxbUGGBQaN/FztleNtV30+ATSHMow3/dj+cb0JcYY3KU0iW1jlmZDQVK8JQGM6R2MSk+lUkHyufK6/ZttUobeMuXYCfEDWqdpc9TC8DWhSOhmcW5vwuXRbpsxI417VHsSUvSLtmJaDSgFYvv7VAl8r4J4op0VhKEQ7RLVYtGo37aZzvIvAqOLbe6duZLS2w8j9aJGrSOHTwfLXonKGKCgmhImM9BT71EpXb5HTjk= 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:(13230022)(4636009)(39860400002)(346002)(376002)(136003)(396003)(451199015)(46966006)(40470700004)(36840700001)(36756003)(356005)(86362001)(2906002)(82740400003)(81166007)(4326008)(82310400005)(8936002)(5660300002)(44832011)(41300700001)(36860700001)(478600001)(110136005)(8676002)(26005)(40460700003)(186003)(40480700001)(70206006)(70586007)(54906003)(1076003)(2616005)(316002)(6666004)(426003)(47076005)(336012)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 14:07:54.8155 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0445afc4-5672-4547-30b5-08dafe146382 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: BN8NAM11FT021.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5810 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 4c85c5dc01..cb04639b0d 100644 --- a/drivers/bus/cdx/cdx.c +++ b/drivers/bus/cdx/cdx.c @@ -549,12 +549,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 +rte_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 = rte_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 = rte_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.25.1