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 AB36CA0547; Wed, 12 Oct 2022 10:42:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DFD5A42FD9; Wed, 12 Oct 2022 10:42:21 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2084.outbound.protection.outlook.com [40.107.244.84]) by mails.dpdk.org (Postfix) with ESMTP id C5C0742B7D for ; Tue, 11 Oct 2022 16:53:18 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C3VF57yMs2icusx4BroEglkqRhlXnmwahjEjnduQmIivaZ8zhJpvYLaqYEtcOKT32NGyH0Te3FfWUrA6tCIJ0ZlCS9vHu52zjMYZcLYYibUS07wHVMLg9fIsqKWlHB/oI3fNu4QOXD2Aa+Ny3YGDqKVyHlgIgsuRdO8mKVKdq3ruXLWZUUfZEvB69hE9UQM4EsUc3GYNUFXcrlhh7yGgQtubl+78R818qyIUrySRDkU5db8b3YTfhQXPv33OKBAWLoUadW/pHNuK34A4Dq5zpT1O2nhPywvnnfjUl1fsP8LOUszEEy1kOJZZyKrwEDVPJ275ZhyDz841hFAHYQgHsQ== 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=GTZgVeQs1qN+I4Sfu0CfZX9eRcqd+A0qIyY9OamxJnU=; b=KzZetgkjl6u1en0QkcX98mNLbJKkJVuX3jGTtNxv+oKIvdPtCa1i126fFLRWm5/29kuEi1IsUVIFEOjEegrsijcOV67NEtVIvbg2EUSiGWXiy8h/k+Ye7F3fnbs+TtgREhlzSKNK+fy8gorin8FDd1QUcYMw/ZqXAMQCggmoV6BkMZxkbbw2oivCYqzS/27Pj1fP7+9fk10qsYjnM5FqnvV5KtOzM2ct9ejdklIzPOFUyn5MPbruHpFdyZ8vJ5wmOC6AxrPdFhxgcZIKySf+3Y18B9ToKG/usRvq9jGy8e7ZOv7yavNny1vDvqhTfitBjNqjmTrwzEMkJFyPFY+Ugg== 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=GTZgVeQs1qN+I4Sfu0CfZX9eRcqd+A0qIyY9OamxJnU=; b=pSBQd7zbmaQOOmSwSWyC7NhudqOysK/PXJyF3bvOS4F1ysoaWJL+ti4Md+n921KRPpJcJLkIXyJ+E3/Xxgax7VHhl/BixYu+4juukQGBX2btbdEIK2ib13yu53aYzMJAaVAleoFBhT6aZpagubzcsA8n3ClR39+lgDq2VduOK+I= Received: from BN9PR03CA0679.namprd03.prod.outlook.com (2603:10b6:408:10e::24) by SN7PR19MB6612.namprd19.prod.outlook.com (2603:10b6:806:270::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Tue, 11 Oct 2022 14:53:16 +0000 Received: from BN8NAM04FT004.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:10e:cafe::f5) by BN9PR03CA0679.outlook.office365.com (2603:10b6:408:10e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.20 via Frontend Transport; Tue, 11 Oct 2022 14:53:15 +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 BN8NAM04FT004.mail.protection.outlook.com (10.13.161.176) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.10 via Frontend Transport; Tue, 11 Oct 2022 14:53:15 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 293E120C684C; Tue, 11 Oct 2022 08:54:25 -0600 (MDT) From: Michael Piszczek To: dev@dpdk.org Cc: Vipin.Varghese@amd.com, Michael Piszczek Subject: [PATCH v4] pci: read amd iommu virtual address width Date: Tue, 11 Oct 2022 16:08:54 +0200 Message-Id: <20221011140854.777428-2-mpiszczek@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011140854.777428-1-mpiszczek@ddn.com> References: <20220912160157.3642968-2-mpiszczek@ddn.com> <20221011140854.777428-1-mpiszczek@ddn.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM04FT004:EE_|SN7PR19MB6612:EE_ Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 0c921bee-754a-4687-6be7-08daab9853c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x+jWY5k9+DfKyBnzvdpioOkpq7HRTf2h5CqkaN807TUBBiha99CL5x6GiwezCr1wQR76feF9rnRwvTluu6OwhTSaBuxhy0XjhmNLqysZSNHpSxCSfjCuqsY3M75qq4axn5SVYO1WWidFG/Ff6X0Fn8Uv5JiqDPE57xfHN6oIjg0ygkyCjA6zofduiIMKYADdhBPEnsDH4Mko9rHC7YyrjmQ5t89sJ956w0Y7j8WcKs5gOJJ79ZCa5KcBP6diKMOL3JE1jq+DgirntTAkTn6z9PU1LTIX8soI1ts0RqauAz6llbzPa/a8lAH17YBJNV6/t8ggfGiFWLVA3GOf28MXMNC94BmpLbGWCeLkV+Yahw+Zry+GBRvVkJdfZwPhbTFFl+G6qTHSHzy4/PbyGipw+KS9G/YjhR857PJoWMYOQ2n/71uf15TD7UdcZoioGjXIyuIegSIrbp7aZu50vQVkb/1KishAjVxfoXu1oSB9mocnoq3DvrcCynJVtm5p8aHwJeokrAnmu4LbetE7gZGxtNa/a7XzKsiL5WqPC1LlD3NQIAqr4e9GYsoaRKjUW4K7ZTM+ME7kEpSqEZBp8oS819uB7oXMBAWp+iP08/vTBPoY+8oOz9kAoW2GFqQbs6hgy5rBHooK0bz5EYZnLMrxO9SnAiJY8G6QyWuSuiejOJmwiFJbiE5v21xmFURo3LElXT0IGTGNqU1laUnCIqRvywpU3HvuU+VYMScRJM7soKi72OBOMj9GOemzOLbUB71GZ5OJW6mH50MWl/MTCXTgyw== 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)(396003)(346002)(376002)(39850400004)(451199015)(36840700001)(46966006)(83380400001)(2616005)(86362001)(82740400003)(41300700001)(81166007)(6266002)(36756003)(6666004)(356005)(70206006)(8936002)(8676002)(2906002)(4326008)(6916009)(316002)(1076003)(36860700001)(70586007)(40480700001)(47076005)(5660300002)(478600001)(26005)(186003)(336012)(82310400005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2022 14:53:15.3806 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0c921bee-754a-4687-6be7-08daab9853c8 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: BN8NAM04FT004.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR19MB6612 X-Mailman-Approved-At: Wed, 12 Oct 2022 10:42:19 +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 | 48 ++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index ebd1395502..cdac634e6c 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -480,15 +480,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 = 0, cap_reg = 0; snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT "/iommu/intel-iommu/cap", @@ -496,26 +499,39 @@ 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); + fclose(fp); + mgaw = ((cap_reg & RD_AMD_CAP_VASIZE_MASK) >> RD_AMD_CAP_VASIZE_SHIFT) + 1; + } + } - 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