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 6AAE0A0542; Mon, 24 Oct 2022 17:33:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A83E542BC9; Mon, 24 Oct 2022 17:33:04 +0200 (CEST) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2084.outbound.protection.outlook.com [40.107.96.84]) by mails.dpdk.org (Postfix) with ESMTP id B1DE240041 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=dvS3ce97GG6UvCHRD9JDet+BSwoy6j22BW2UPNp25FrptpslDOVKHfvZaYzhAVh25lrCIydV615KbIRkQHRbrHeQGxM+TGqVdaRcTItGrFEBQNSGUpOdmwsbVcY9mOUCizfUg3/xevK+3uogxO1nfVWf/XBPtZaPTrEZX+CZc/8wvOwnQgqYYL/+AwQFGdQGcAfN4gBu5M+iE+uEJzSNu8DCESIwRrQnXbxf1HY3y9uHPQYMOq16z6jWkE+0Z2Hf4L436neUVRG8RMeZNFKjXhF8pmQ6wwKInzJXJsRaddZ8N7kdDKt5HDUa+CDkMfvNZttCfZLp9g2m8lzM4SngLw== 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=QnFWYU15XOpkrgtkPuULpu5GczUKNosbAqOC0TbSep2G4ItmMKIDk+40jpZnAMKa22u0kiLanf3PAaLmq1YrpdsQr55WFXiNkLKwrkdMOcvBE2koRb0Fdss8f8y4SHtNnv8P+Q0HkBz4Qx3QFXlZT3RPoH2h94uPAo7pzMTOu29410cQwe1R3bk6xIN9AvTmEQ1qEgemlHKwFqsVamM3R3a4ASRNtojXpfADQNxX1NcAWgTsI7Y73o/9J6tjLq3xJe6TBlyKgdveXFvz+h7hhsU/kbWfdse2xmn2wwHFFfM+kT6HJZoLsb2bAaq+53gpRdpwEA+EDpdLa4ZM7HIkdA== 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=cte94XJ/7LixxMoVF2a+B3L9lQTpMm9utltXXd76JwWC0hGNAqyN8iIKorMoQ052k1Nhl2TKjLvvRsR1635nlvsiAVvPISysq5nfqTHHoMc+IUVQf7YeP8jx5IyXBxdmg66mPtnrA9BHn1oKpsW50H2v9y+/zPzyD4ZmwEupdog= Received: from DS7PR05CA0067.namprd05.prod.outlook.com (2603:10b6:8:57::12) by SN7PR19MB6637.namprd19.prod.outlook.com (2603:10b6:806:26b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Thu, 13 Oct 2022 18:16:07 +0000 Received: from DM6NAM04FT059.eop-NAM04.prod.protection.outlook.com (2603:10b6:8:57:cafe::ef) by DS7PR05CA0067.outlook.office365.com (2603:10b6:8:57::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.10 via Frontend Transport; Thu, 13 Oct 2022 18:16:07 +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 DM6NAM04FT059.mail.protection.outlook.com (10.13.158.176) 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:07 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id C37A920C685C; Thu, 13 Oct 2022 12:17:17 -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:02 +0200 Message-Id: <20221013181602.873166-2-mpiszczek@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013181602.873166-1-mpiszczek@ddn.com> References: <20220912160157.3642968-2-mpiszczek@ddn.com> <20221013181602.873166-1-mpiszczek@ddn.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM04FT059:EE_|SN7PR19MB6637:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 8d6a927c-d162-4760-49d5-08daad46ffc3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iF36g11ximX0kVf/LlvhxSyiEMkf7y6xHAwAXB4WVin28dkefBhCODJdEl+68grA3tSjWQZsE8tClTqJr5aq/FJxUOFtxiM4vr0J1MruMf3DNYeB+6kymOIyI35zTMUISpR6jo8J0JP3nAHEHj7okNmy++RqcQZ10w348kbdysZS0AYy1aeaRqW1hq8BRG62PqKhcEiu2uRNrqiIq5jz2pxUQdyIf5FHKS+fsrVKdBjQ3UzBu0ojEyy2nugF5n9M12RotG3gT1JSdZ5n8eyjkHY2ZZJsYc5eVKQUg9FqJt8PWZO54a664aXw4lFzUqnzSD23ZABLsm+ek3b6XcImvXQH8qQmdc1Am35IG0svvrMgo/OsGrN2miDRUC+x2kdKXhG04xLMC+j612QUQIWzKBQq0KDED/BeVtfpqaGjpeSuIj1o7jgmkWNbGlRUqIA2m39pGZMwNQnr74Pw992FepZGWVTSOEnd0D7VefxTOvxMFo0gs309nSUjFtQVSOISnLV89gwjBZtk1OiFpN+mI/AvFcgXEbj9s1gI+neROmAeHbxjOYoeO0gdd4ygP8i6jyDzNEFHaKHx8QuZVYPeER4XJHlfijlC+DgNfnwlZv2VfxSbQIX0I65MDKaaOFXve0QRbTgTyvI1t/WbjNrUkOdRzyJBmGUFh8eLxWWUyUlhes5Wh/cdPSR4qoqV8Oful3bgSktla5AENIQq0TXEx9cFMEQTHvrQFiyhp/FtHd/Wt8VFZDgyyY7jVxVL3r5I8I7lg5NgmtLt6PQHI+YM9g== 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)(136003)(376002)(396003)(39850400004)(346002)(451199015)(46966006)(36840700001)(70586007)(356005)(6916009)(186003)(83380400001)(26005)(47076005)(82740400003)(1076003)(336012)(6266002)(2906002)(36860700001)(82310400005)(8936002)(81166007)(70206006)(478600001)(8676002)(2616005)(5660300002)(6666004)(41300700001)(4326008)(40480700001)(86362001)(316002)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 18:16:07.5869 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8d6a927c-d162-4760-49d5-08daad46ffc3 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: DM6NAM04FT059.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR19MB6637 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