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 5D6DCA0544; Tue, 11 Oct 2022 03:51:18 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7059942BC8; Tue, 11 Oct 2022 03:51:11 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2084.outbound.protection.outlook.com [40.107.220.84]) by mails.dpdk.org (Postfix) with ESMTP id CA2FE40146 for ; Mon, 10 Oct 2022 23:47:33 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K3or/wAPIJnrW5ZwCO0ZDYufzzJ+GKBLlVmM2Q7COwY1C7ZGL8EZAmA96D5CzZKgbhcE9Xk3VYECivhahh8y0DO58opFcqa6iroIRIcF0OVcP/7D/E866hOpPOK9ZmlLy5zU2OJTWFasAKaQEQlxJgjr5bL12eyzLHrjR0tAnatCJzk1IVs/byQR/l/Zihab2esZ139EN+1qj7jBghSd6DudFf/g8p1aXupwrAXR6AC8w9r0Dz0ONIO9meKe54LNxRIAl32NiIE0GasDrsw8AhCxvzwHoUy1hFiqcnmHKb6k702gn0VkkGuIUZ3B+DNwDJdlqXaL8Mwv5OFC5Mkf9A== 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=6RFBDaZJY9leCz+YJ5hcLitKpkHpdJzxh8SVVyW4IOk=; b=aPdTOJYALa/+CWxQ2a5K57um57rF/mFpqfLt1tZNB93mnrkmD5JHrNPYVCQ0DLc2HE2+m/RaOXg2jK/P1/AU11jL8a4UP+x5pnamX8L1NP79JEoGbNnl21lDKsZ88pEw47wLGnL0GKaELARWe3oHqoJKsA58dq5aYzq6UStZpOH1glUhKMt0hu9e8PL6cTNYrKpAsfkCcbP6MbXNDUG38Ey4dZIGQ915DYg9Ld+6yUeXVOacw4DITQioZb/LP7f+8FZwaG3k6tzlDukbChK02kLn0l64WkcvjvNBw8NK/2vdEUoJUmTWFo6+XlDORjcfvBTgp8fgon9nIjl+lwpAJw== 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=6RFBDaZJY9leCz+YJ5hcLitKpkHpdJzxh8SVVyW4IOk=; b=fNCpL7fXXLuCXNWrJbm2AaFqugWrOzES/U9HvdcGsiJrZr+pknTEWKKPADleqmf95Vp17TiqmKgWCwikz4MW3WBAUysS3N4gHxo+qzM3QAjt+3nIBqutI9cFLPt/Y7AHxquz3tkIvfa7xsaNhkC+7U7kiES1lAZgUZO17lBQhoo= Received: from DM5PR07CA0089.namprd07.prod.outlook.com (2603:10b6:4:ae::18) by DM4PR19MB6341.namprd19.prod.outlook.com (2603:10b6:8:a8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Mon, 10 Oct 2022 21:47:31 +0000 Received: from DM6NAM04FT050.eop-NAM04.prod.protection.outlook.com (2603:10b6:4:ae:cafe::a8) by DM5PR07CA0089.outlook.office365.com (2603:10b6:4:ae::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17 via Frontend Transport; Mon, 10 Oct 2022 21:47:31 +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.5709.10 via Frontend Transport; Mon, 10 Oct 2022 21:47:30 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 2FD7D20C684B; Mon, 10 Oct 2022 15:48:41 -0600 (MDT) From: Michael Piszczek To: dev@dpdk.org Cc: Vipin.Varghese@amd.com, Michael Piszczek Subject: [PATCH v3] pci: read amd iommu virtual address width Date: Mon, 10 Oct 2022 23:47:19 +0200 Message-Id: <20221010214720.766459-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_|DM4PR19MB6341:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 00c75939-f6f9-41de-47fe-08daab09086c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VzFZVZcUf+MhZR2nmgPH89yoJOVpU4L1YvDGo4SjsZFEZfPwGhyXwbGGQEUiEip9zKABZX2Dtp5kmustWhSStXGSov1K+760PhAmIxce+vn/njyBJVGGRCt1ChhiPgwv/IwIMx0lM33DxuEOe0BEuwL++2OVtHwuhd6bTOTN7CThvzZ5QywfcGwDERiraSuYDbgEQzF7wi3zj6H8d6yGnGustDOUl50jmY4vsKt5HQsbaBM3JLhp+H1tC0tT4R/gOPShFKX0YmiMlfJYexsnnwh4/56orUQw2nVljw6h6rUVIyIiUL0Zd2tSzwYGshz+Xpys/1Kfyb6gwH3D0BsH6X7HeP0kqbITkJ3hoTdodNkljd/YPvvpDAiXksqtumCqCWKoVGPJhYFVmtyLO56ixyX5itEvxtUabdjSncJuTh8Ei12kim0mflxQcjworftr6BUuVrMDulw5UYvpNzLwAR7XGMiAV7VKgzBPk0eX8zWHuGDaQowjClkYCaqjwMr21h9hsa/LrL2LbHEd0YMvWR0EZo5JxeUBG2D6ug7SPGUS7sdJc6iNOrDUqkz+Ty2pDoU0WN6Z6yAefxu/pthjXcPOXfPkpc6kDFIT7AwU5YXyL/UWQaelV747uGN+ciKU3/IAs4ssrfRflvbncEMZDn86AK9yvomV5L9lexoxkkLkNn6+jSxTU8Ko3bW+wbLsn6PwI5w53vNieLBVMPCCtl3xggXc7ErACKfjFC/obUTmdDoDS8ULhwv3FIgbSpzbGGwnoVioxR9x12r0bVyFvw== 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)(396003)(39850400004)(136003)(376002)(346002)(451199015)(36840700001)(46966006)(36756003)(40480700001)(2906002)(86362001)(70586007)(186003)(1076003)(41300700001)(4326008)(8936002)(70206006)(8676002)(81166007)(356005)(5660300002)(316002)(82740400003)(6916009)(36860700001)(478600001)(336012)(6666004)(83380400001)(6266002)(82310400005)(2616005)(26005)(47076005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2022 21:47:30.9934 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00c75939-f6f9-41de-47fe-08daab09086c 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: DM4PR19MB6341 X-Mailman-Approved-At: Tue, 11 Oct 2022 03:51:08 +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. Signed-off-by: Michael Piszczek --- drivers/bus/pci/linux/pci.c | 47 +++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index e521459870..8c6082ee7a 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -492,15 +492,18 @@ 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 RD_AMD_CAP_VASIZE_SHIFT 15 +#define RD_AMD_CAP_VASIZE_MASK (0x7F << RD_AMD_CAP_VASIZE_SHIFT) const struct rte_pci_addr *addr = &dev->addr; char filename[PATH_MAX]; FILE *fp; - uint64_t mgaw, vtd_cap_reg = 0; + uint64_t mgaw, cap_reg = 0; snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT "/iommu/intel-iommu/cap", @@ -508,26 +511,36 @@ pci_device_iommu_support_va(const struct rte_pci_device *dev) addr->function); fp = fopen(filename, "r"); - if (fp == NULL) { - /* We don't have an Intel IOMMU, assume VA supported */ - if (errno == ENOENT) - return true; - - RTE_LOG(ERR, EAL, "%s(): can't open %s: %s\n", - __func__, filename, strerror(errno)); - return false; - } + if (fp != NULL) { + /* We have an Intel IOMMU */ + if (fscanf(fp, "%" PRIx64, &cap_reg) != 1) { + RTE_LOG(ERR, EAL, "%s(): can't read %s\n", __func__, filename); + fclose(fp); + return false; + } - /* 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; + mgaw = ((cap_reg & VTD_CAP_MGAW_MASK) >> VTD_CAP_MGAW_SHIFT) + 1; } + else { + snprintf(filename, sizeof(filename), + "%s/" PCI_PRI_FMT "/iommu/amd-iommu/cap", + rte_pci_get_sysfs_path(), addr->domain, addr->bus, addr->devid, + addr->function); + + fp = fopen(filename, "r"); + if (fp != NULL) { + /* We have an Amd IOMMU */ + if (fscanf(fp, "%" PRIx64, &cap_reg) != 1) { + RTE_LOG(ERR, EAL, "%s(): can't read %s\n", __func__, filename); + fclose(fp); + return false; + } - fclose(fp); - - mgaw = ((vtd_cap_reg & VTD_CAP_MGAW_MASK) >> VTD_CAP_MGAW_SHIFT) + 1; + fclose(fp); + mgaw = ((cap_reg & RD_AMD_CAP_VASIZE_MASK) >> RD_AMD_CAP_VASIZE_SHIFT) + 1; + } + } /* * Assuming there is no limitation by now. We can not know at this point -- 2.34.1