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 BD60CA0542; Mon, 24 Oct 2022 17:33:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 691CD42BBB; Mon, 24 Oct 2022 17:33:03 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2076.outbound.protection.outlook.com [40.107.93.76]) by mails.dpdk.org (Postfix) with ESMTP id 0E4D540041 for ; Thu, 13 Oct 2022 20:16:09 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cxy9Do8HG3J1CJZOFPAGISM8xk4Mp96DYBV2X43VYt0qU/F6rScmutNphrORRt54H1fMd92RVxjC2NCkzJ4KiREbAfKhTpxhjGSV1spwK01EpRw1nIALwvAU+W8B0TE4rn3uKpRKwjEn0ysyqD+fLzMVGfwM9/nassoqcmw7N9QtpjGLT4UYqN1Dg3ksPDW/k4ueq7wLId0Mr7jZm8Py2dHEC9z5ZJZ1hXSA1guVmQRCX0k9LFbcToRtNQITEiPP/uA8OXWFkoIm0I54F0ok9+pFh9GjJMOzYLBIl/khK0I8ADAnoIpRIJExNuvBAMNybdP8k3yxEJ5chwQ2nai8gQ== 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=P/QgIsfJNQJZWj7D2U65f+unczDVrzhgcShhpM2IABk=; b=Ck8lUjTcL/E6MxJgo6KkdGUPb8+HAIVwAM3Ik20CIZ0CQp5vQ9+mwgPxC4ljpzZIcApwQvXWo/fivwsoASshNMW3eltqjFzM4XFsFLlGVSrOKjHMYFMwM3rAn+HRuwGduhMa+m3gbdQjh2wxwXUABLzOG4Y6WqOLwnSuNi4ZZGSGdjCRZmvY+7ETHTlEyb+ZRh4Zs2oNQ2OLQWsfXvaGRKXOefR2on9iak9D4vadkPOwwM5df7OzdWX+MeUU7jdR9FxQVFmyS+TpAEMBlptmWVNnhGBF96KmNc46HHUfrwX8Z5DwXbDyu/Mk6sfGY3vtswhhkHCkuHH7Y8sed/1yYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=amd.com smtp.mailfrom=ddn.com; dmarc=pass (p=reject sp=none pct=100) action=none header.from=ddn.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P/QgIsfJNQJZWj7D2U65f+unczDVrzhgcShhpM2IABk=; b=nl+rAquoXK2FkEEJk+P4eLYLEKIWril0SP5QtSGbx/RK7cqNe5F7I+8fd9vdmCxyjQHvVitHmLnVYyi+c9MD47KoCgxdTmphYAVaLocqFYGGMXZrWQyK3pnFfyEyfEobDnEkTq5OIJmYIAC2xfCGxFBh4YHy0/6SUrgFoFbgdxo= Received: from DS7PR05CA0037.namprd05.prod.outlook.com (2603:10b6:8:2f::24) by DM4PR19MB6438.namprd19.prod.outlook.com (2603:10b6:8:a3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.19; Thu, 13 Oct 2022 18:16:05 +0000 Received: from DM6NAM04FT050.eop-NAM04.prod.protection.outlook.com (2603:10b6:8:2f:cafe::c2) by DS7PR05CA0037.outlook.office365.com (2603:10b6:8:2f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.6 via Frontend Transport; Thu, 13 Oct 2022 18:16:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mx01.datadirectnet.com; pr=C Received: from uww-mx01.datadirectnet.com (50.222.100.11) by DM6NAM04FT050.mail.protection.outlook.com (10.13.159.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.20 via Frontend Transport; Thu, 13 Oct 2022 18:16:05 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id B863220C685C; Thu, 13 Oct 2022 12:17:15 -0600 (MDT) From: Michael Piszczek To: dev@dpdk.org Cc: Vipin.Varghese@amd.com, Michael Piszczek Subject: [PATCH v5] pci: read amd iommu virtual address width Date: Thu, 13 Oct 2022 20:16:01 +0200 Message-Id: <20221013181602.873166-1-mpiszczek@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220912160157.3642968-2-mpiszczek@ddn.com> References: <20220912160157.3642968-2-mpiszczek@ddn.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM04FT050:EE_|DM4PR19MB6438:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 8fa856aa-7b9f-4686-a2e6-08daad46fe8f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SmF6/m9H9FeRtLLfNsHV/ctqzgkXnB+eoszzviSIYCb8+9A+LnIf+UCya8unEFOgGZY5zUQbbX8m4uel+HxtKWgPYOCxN1e9C6JWD7G4H1r0Pf6NohhpIZXGw295TK0Ys1Kh/0YVaz9t3jA0tVojAp7D28RsyRdngtgKov7LgbAoDTljj0p/sg/IW6/lPU9FFd7sQoqykGok/1+TBznau4dGbAS+l6AWF5GJvoVg0kSv9mnleru2SM8z6RCfBTLrpX/Zm5igFvwMg22RCjvdLj65+RbU+CMPEotEHklB0fRVpinQ2h0IwoKaoLfsD10XZcjlPOFa0mSntjF5BFo+XqUHD9SprNo/aFPCUqSQfYp2z41AYOEhZxUZ917WmUPRjKIlMnrSwHP1q7l9fJINS6IK7nnaqFzwO6J7FOIC6vJTkNRQ08xz1bC/C8SbZgdPj+Lb6ZLtgG1xnUBTFblmo8PKISxaW9DbSiBD7EsfO088AmWiL7LXcP7FdOzNl8c3jICcJzwOmQvbzDYwWX5c+rIhkhvpgUTHjaUclakixt/ojnPEbOzGDro+G2hK/KkglvHF7IHc7vnjrE21+jFsaDT/yXM8csNaNLMS5mrD9OM3kmeh+iC3FYTbeHzG5OVbRIwmGMrFRqihKpzs2olSPTrfiG+sZtgFJFXAs6QoDggK+9VY3UN7whzSA0ri29GcJFAkk7nfGEGcrYS8IVCfeejFcfEAqNypHGmL397KUuAvjPyo/OJCGIqBz7UX/GNU8LLDghBQEcp5h0Fp/fr0Yw== X-Forefront-Antispam-Report: CIP:50.222.100.11; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:uww-mx01.datadirectnet.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230022)(4636009)(39850400004)(136003)(346002)(376002)(396003)(451199015)(36840700001)(46966006)(36860700001)(36756003)(82740400003)(356005)(6666004)(81166007)(86362001)(316002)(40480700001)(478600001)(8676002)(6266002)(26005)(83380400001)(70206006)(70586007)(2906002)(5660300002)(82310400005)(41300700001)(6916009)(1076003)(336012)(47076005)(8936002)(186003)(4326008)(2616005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 18:16:05.5707 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8fa856aa-7b9f-4686-a2e6-08daad46fe8f X-MS-Exchange-CrossTenant-Id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=753b6e26-6fd3-43e6-8248-3f1735d59bb4; Ip=[50.222.100.11]; Helo=[uww-mx01.datadirectnet.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM04FT050.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR19MB6438 X-Mailman-Approved-At: Mon, 24 Oct 2022 17:33:01 +0200 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 Add code to read the virtual address width for AMD processors. Updated pci_device_iommu_support_va() to use glob to find iommu capability files. Signed-off-by: Michael Piszczek --- drivers/bus/pci/linux/pci.c | 58 ++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index ebd1395502..291090ba7b 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -480,42 +481,53 @@ rte_pci_scan(void) } #if defined(RTE_ARCH_X86) + bool pci_device_iommu_support_va(const struct rte_pci_device *dev) { -#define VTD_CAP_MGAW_SHIFT 16 -#define VTD_CAP_MGAW_MASK (0x3fULL << VTD_CAP_MGAW_SHIFT) +#define VTD_CAP_MGAW_SHIFT 16 +#define VTD_CAP_MGAW_MASK (0x3fULL << VTD_CAP_MGAW_SHIFT) +#define RD_AMD_CAP_VASIZE_SHIFT 15 +#define RD_AMD_CAP_VASIZE_MASK (0x7F << RD_AMD_CAP_VASIZE_SHIFT) + int rc; const struct rte_pci_addr *addr = &dev->addr; - char filename[PATH_MAX]; - FILE *fp; - uint64_t mgaw, vtd_cap_reg = 0; + char pattern[PATH_MAX]; + glob_t glob_results; + uint64_t mgaw = 0; - snprintf(filename, sizeof(filename), - "%s/" PCI_PRI_FMT "/iommu/intel-iommu/cap", + snprintf(pattern, sizeof(pattern), + "%s/" PCI_PRI_FMT "/iommu/*-iommu/cap", rte_pci_get_sysfs_path(), addr->domain, addr->bus, addr->devid, addr->function); - fp = fopen(filename, "r"); - if (fp == NULL) { - /* We don't have an Intel IOMMU, assume VA supported */ - if (errno == ENOENT) - return true; + rc = glob(pattern, 0, NULL, &glob_results); + if (rc != 0 && glob_results.gl_pathc == 1) { + const char *filename = glob_results.gl_pathv[0]; + FILE *fp = fopen(filename, "r"); - RTE_LOG(ERR, EAL, "%s(): can't open %s: %s\n", - __func__, filename, strerror(errno)); - return false; - } + if (fp != NULL) { + uint64_t cap_reg = 0; - /* We have an Intel IOMMU */ - if (fscanf(fp, "%" PRIx64, &vtd_cap_reg) != 1) { - RTE_LOG(ERR, EAL, "%s(): can't read %s\n", __func__, filename); - fclose(fp); - return false; + if (fscanf(fp, "%" PRIx64, &cap_reg) != 1) { + RTE_LOG(ERR, EAL, "%s(): can't read %s\n", __func__, filename); + } + else if (strstr(filename, "intel-iommu") != NULL) { + /* We have an Intel IOMMU */ + mgaw = ((cap_reg & VTD_CAP_MGAW_MASK) >> VTD_CAP_MGAW_SHIFT) + 1; + } + else if (strstr(filename, "amd-iommu") != NULL) { + /* We have an Amd IOMMU */ + mgaw = ((cap_reg & RD_AMD_CAP_VASIZE_MASK) >> RD_AMD_CAP_VASIZE_SHIFT) + 1; + } + + fclose(fp); + } } - fclose(fp); + globfree(&glob_results); - mgaw = ((vtd_cap_reg & VTD_CAP_MGAW_MASK) >> VTD_CAP_MGAW_SHIFT) + 1; + if (mgaw == 0) + return false; /* * Assuming there is no limitation by now. We can not know at this point -- 2.34.1