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 CAE55428E2; Fri, 7 Apr 2023 08:02:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CABFC42B71; Fri, 7 Apr 2023 08:02:40 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2053.outbound.protection.outlook.com [40.107.237.53]) by mails.dpdk.org (Postfix) with ESMTP id 91ED542B71 for ; Fri, 7 Apr 2023 08:02:38 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R9c3su2cl7TKwYBTFmi5Q8qMGWCoIVOmTLJ5/J0EKpFIZKHGvip/InUN7uZKmbta2TvsPnLeW2dC9XIkZj96YVfGO8C8tdRl0mBH27AC5oKm2ZOzA9LhoWV4+SGM1GtORv1nfuTuCtv7C5HBoFmwUUuYJEFkonTALigxDniFsMAyMGU4Sb6KkV4HGDr/Zb9KgVTHRSnqCbIuJALfgBWW/ilSy5AUciYgcAdx+h0Tx/q4/jooDJ7cIsUPWpS2jU23Gl2la0fSxu/hjV4oMJg48R80+0YZIsmFpz3Dl16BW9vnaQ7gePZpAiFO6hYawLxbiyh9nSSSaw12pBPWj07kqw== 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=d73Te9YpS06aXAiO/8VgB7uGPC2pkvAdXHDo8atDAy4=; b=cPXVePTe2hls9yxA+VDwbDnpVSsuPdFkLu/ITUTSK/wlXpfBpVjW7mFYU/H5N2EGn3gpgUOOq5DgcuqTa+eSA9qFDVrRbR/x58e0t+qfnVTN+b0+9sOhPnWdrr8nN2bCZnJHLPyQ8ly/3WjcWPw0DOp/4HmsFLvlCpXD8iFNWTtmuFRYb7sv0KhfXYLV9QU/PltkxxRhmCO2R9CKFmGAFvN9q1WxXaA0jiRW+4VIamqPQEErS7b6qrNcpjSLBFZxySuAda0e57EvG8g1ZlaqWbS7+wmza8rRc5AXbsGFnzJJ8irQn2LlnoR6sMUoga1Vpi8PTkIhNvVx/ouhTUir6w== 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=d73Te9YpS06aXAiO/8VgB7uGPC2pkvAdXHDo8atDAy4=; b=Dto8YveNEpVCDNeHcOzt1zyVWR7w6BaHLrzR9+IDt09PRJ+9MXa5DrpDGYCovzpuqX1yd7bl+i3ZlXid0YGC8fxckRxwyYjSC7QWZdlxDU5wXEGx8naI26v+hJgRxrDuGhLG1GRXknkV/7nLaQQgBqaUphvL7D+1Jgzc3LX7nGA= Received: from BN9PR03CA0225.namprd03.prod.outlook.com (2603:10b6:408:f8::20) by DM4PR12MB5770.namprd12.prod.outlook.com (2603:10b6:8:61::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.33; Fri, 7 Apr 2023 06:02:33 +0000 Received: from BN8NAM11FT094.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f8:cafe::4b) by BN9PR03CA0225.outlook.office365.com (2603:10b6:408:f8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.31 via Frontend Transport; Fri, 7 Apr 2023 06:02:33 +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 BN8NAM11FT094.mail.protection.outlook.com (10.13.176.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.19 via Frontend Transport; Fri, 7 Apr 2023 06:02:33 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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; Fri, 7 Apr 2023 01:02:30 -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, 7 Apr 2023 01:02:28 -0500 From: Nipun Gupta To: , , CC: , , , Nipun Gupta Subject: [PATCH 2/6] bus/cdx: add dma map and unmap support Date: Fri, 7 Apr 2023 11:31:48 +0530 Message-ID: <20230407060152.16335-3-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230407060152.16335-1-nipun.gupta@amd.com> References: <20230124140746.594066-1-nipun.gupta@amd.com> <20230407060152.16335-1-nipun.gupta@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT094:EE_|DM4PR12MB5770:EE_ X-MS-Office365-Filtering-Correlation-Id: e0006134-6c41-485e-3fed-08db372dae18 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d8tgX4iPs3A61mDb81DlKYkpkdeD9qcgvzssGWp4qeADVwvG6pBGQGsDOaWLr1tg5n+pgFjrruQD6T8Bb40zc/HBPH2F039MXY/U3Jg7OcBP2w9pbztqD7PHI/zUE6jYvEAjEBVDAaBOrAPSNQXgoMcYJQz1AS21WA9zHF32vRlJ3EPN8v01EvoeNR+CjoYgOV2s+C2XvR1pDo0W2su6rQqY00KZLClDJSr6Vd3fDE22mkeGzfYSAY4/Qh1EKMhlQ7/U1n/6GY8PLtd2yk0Bb39vt3oMHon1UWsICxNzw+4Y1JU99SfgdEaawMFvnozkyh3zzptoCNFwC3XXkb0ZTXw4zdCSDlV7n1Pb9WVNLQxCkr6hzcmclDuHs3LXRjjE/HGXap1D8cFSte3fZ/FO+PtXOwfc9UcQKUwOSnRorhaBs37g0iFg4yb4zcBOc51+C1w78SFkqNnaw+KUkMJd03QfUcgnk9XGkaaE1l9cwS9U9wsQvciuEjUUVEJDuTNB7NNkoMkH0rAqZXZV8ZXkEngehglrt9PVVdZrsMlO88VSltdm1PRPBnhkQHrveXTUAGrPgtu2UzApSRGLbq6hxytWLuxSVW2j0tV9d4oRxekc2lM1WxA/2sZjIuPkAEPSzMqj01PddOB4HYnfGuFkhcTglhp29fJFIYdbgI8bGtcyKhOqZ75kexPCDbo/FH80ZxjUnAp0EzgfrRosnZYhwxevhT/kwVaVq2oTLEg/Rw8= 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)(346002)(136003)(396003)(39860400002)(451199021)(40470700004)(46966006)(36840700001)(2616005)(86362001)(36756003)(2906002)(82310400005)(40480700001)(426003)(186003)(6666004)(26005)(1076003)(70586007)(8676002)(82740400003)(336012)(40460700003)(70206006)(4326008)(54906003)(110136005)(478600001)(41300700001)(44832011)(81166007)(47076005)(5660300002)(356005)(316002)(8936002)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2023 06:02:33.6469 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e0006134-6c41-485e-3fed-08db372dae18 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: BN8NAM11FT094.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5770 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 c5f8e37a2f..fa6bfe3bc2 100644 --- a/drivers/bus/cdx/cdx.c +++ b/drivers/bus/cdx/cdx.c @@ -555,12 +555,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.17.1