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 D9204A054D; Wed, 12 Oct 2022 00:00:47 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9EA2940691; Wed, 12 Oct 2022 00:00:47 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2068.outbound.protection.outlook.com [40.107.220.68]) by mails.dpdk.org (Postfix) with ESMTP id BC0374067C for ; Wed, 12 Oct 2022 00:00:45 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OUI9jUEqa0TN0KMCKFlMKrNU9oKywpHeWKQwkT04RwyokcjbllBNOXz7wB3hv1SMgMEjCtQBTELANCom6n2aIE5OGGpRYq2ONm7vIShE7Y8yR2LOSjUyZAms1mEmNmB6D0ZgxHeHfQy+8IpbcR6dD89lRbHM6oJOwVfpdvYgrrTjvgxpsBPhF9rw5bDwH/ByMejmovXJcLm/lUsCOPtW4na9zfeN77XP/NarygCEM7dELhsphnvRrK2uRA/1etnAMMdUQPxGkmoac/PCxuX5STtjQrmg8A5ysMzHnOalUVoQ6PTE9CNfRNCccmWjjheCahLrdY/VaIL18riChKtwcg== 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=y+bDTPJqBtopHEEyBvKFp6aJw+SwwdEoQCHM7NTetH4=; b=h9ARKr4yH4VF899TVvxnlq29lZk2JlUE81Vo7E4JuB9EWqRgOd9ndFNeaa71g0ExkJ6KltTpud8cr9uwLnD5GHJEPYW++Y86gF9i6HnfAo+l3l4AZfwvaVewMjTq7983J7kAp5QeG3bAWg54mfSQDoqs99nUU8AsdCvOS3Vq1RlYGFblnuG+WCtKpMV731lPMzOFQDbDTdSH9EvOQWkIfmaimi4F/rRN7l6IA/ftgnQqvMy3Vb3oKnCIIMKMB5bajwxLJU/hOTZM3qY14fWqXMCznxXG9W+Fohe9W4iM+nrheejKd4PMYxEvKJBGmbbEXa7nyKulz+R+Z/pGuDyNWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=y+bDTPJqBtopHEEyBvKFp6aJw+SwwdEoQCHM7NTetH4=; b=rya12MPpNxlMegfiTngEPkLxSsbe+nU08ns9YSXX0uh6iBCeTd/3B2NhPmJfz5TtP9cilBJeanET3l58V0Qw2LgOKuN7xyLzsIN77ppUa4OdPHO2JFOAD/Lzgz2ehJ+f+k5xLHjOJilE/WzBT2BpPBfvaNl3BoqoW3i1bXPKLs4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB4297.namprd12.prod.outlook.com (2603:10b6:5:211::20) by CH2PR12MB4908.namprd12.prod.outlook.com (2603:10b6:610:6b::15) 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 22:00:43 +0000 Received: from DM6PR12MB4297.namprd12.prod.outlook.com ([fe80::b9fd:e732:4585:6b25]) by DM6PR12MB4297.namprd12.prod.outlook.com ([fe80::b9fd:e732:4585:6b25%7]) with mapi id 15.20.5676.036; Tue, 11 Oct 2022 22:00:43 +0000 Message-ID: Date: Tue, 11 Oct 2022 23:00:37 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.2 Subject: Re: [PATCH v3] pci: read amd iommu virtual address width Content-Language: en-US To: Michael Piszczek Cc: Vipin.Varghese@amd.com, dev@dpdk.org References: <20220912160157.3642968-2-mpiszczek@ddn.com> <20221010214720.766459-1-mpiszczek@ddn.com> From: Ferruh Yigit In-Reply-To: <20221010214720.766459-1-mpiszczek@ddn.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: PR3P193CA0007.EURP193.PROD.OUTLOOK.COM (2603:10a6:102:50::12) To DM6PR12MB4297.namprd12.prod.outlook.com (2603:10b6:5:211::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB4297:EE_|CH2PR12MB4908:EE_ X-MS-Office365-Filtering-Correlation-Id: c21a819b-9522-41a7-e14a-08daabd40ab7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: INKitq/MXcqt7VF9cjDIJ7gxYk6oJa8AsRYFhvj/TMEBQFDCh3N7AQTetxPH2yJTDGvyPxCp1dqa6VTmVJMKX3zbhQz/PeIIntBUUSjE5uhr+ygkaw4L+eRUTmPaso4e5HsLTtO7rxYWCwMsAJ9lI6k81ToXaZ11fBuRpxNynCU+swT3b3OFgwql6GYYLUUosQcGxKIfw/MgU7zRiVx5pF7OoqyNb41/wZoxbL5E+OUD5aqpOkiUGotTPbl9Mtzgpzj0AVT8d8mK8MUZBAasP8AYn0ETVuI6SweeroCsC5QWMWwMeMV9L+BP1KcY2DviJb31OWyn4sledBVtgIsTkC7yGvo5Nd0ClHVj38w33f7mr1ub0Z1ah4bwSD5z3IIRMvRlQv6usuCwWe46uG8AW8F67Dc7PmrSQN5rQ78u74MvAXyoWVuMhJwt9n1AZc1nz/fuTpfxAFY5vldDuM4xjnTzyPF54eyvPaE/bkjZjs4iK3OnwjV4xZivyy5ou/Acz4FaQNywcbXs3l1cCCKO3PioEMZ9XjRAlsityl429JO6QnLXgcHk+gb6VYcgzF9bKguP+LNJ3so8GgA52Al1c0498ruDdZy8DmfTyxn/AKU0OWbktJbRm50e6tENZ5Qqy4jrHeJZ9WhqWGrIJCKy47YzBOxFXJnVlvxFHmQJnl2Z4UEaOEmzRX8rq9yzHAH0ly29W3T5AnqT5bl0M/UCfWBHWy9a/d8JoFPIt8pbtOv+zqWbQxprjUujg9ZouO1vKylbhUTrZV4oVGI4JzMYgVD/eqM5JZZroURoBK4ilxQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR12MB4297.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39860400002)(366004)(376002)(136003)(396003)(346002)(451199015)(83380400001)(31686004)(86362001)(31696002)(6512007)(36756003)(38100700002)(41300700001)(2906002)(66946007)(66556008)(44832011)(66476007)(8936002)(4326008)(8676002)(5660300002)(316002)(186003)(2616005)(53546011)(6506007)(26005)(6916009)(6666004)(478600001)(6486002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?YmN6Y2tTbG0rUXVFMHh3RWM3anNBOWI3OFlYN0RWZnZTSm12cTFrSGtRRWdu?= =?utf-8?B?eGNrM0p2R0ovZnNtWjhzUzNaZXRUS3FDclVPaEhuaDI0R2ZqZlJDWDBpSU5H?= =?utf-8?B?NEFDUnZLUVBrUTZ3MC84UG9GNFI3ZUNxc0JSYVhRK0ZCcUlwcUJsR2xnTExJ?= =?utf-8?B?dC9PckdZMWZvb1RBVXoxdmo1ckVJa0p3bi9YUzI1dmRSamM5Y2JJcjF4Q1g1?= =?utf-8?B?dWVXbDFlTzJtVWJDN1dPWURJR1VlTkJucjlCbzBYUFQ2WnpiaE0rR1RJM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sbHluR3FITmFFSUltaWJiVEdUZ3BIeDJR?= =?utf-8?Q?5nzrZv6TXEwcIyOb2+QSZYtkc?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c21a819b-9522-41a7-e14a-08daabd40ab7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4297.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2022 22:00:43.4303 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LWXXgCSGwQZar/x1Xhy1gwJPOy343j5QWd/YWlxVoeQ0wYt0ntIR6OukBLvxshF8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4908 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 On 10/10/2022 10:47 PM, Michael Piszczek wrote: > 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; > + } Instead what do you think to use 'glob()' with "%s/" PCI_PRI_FMT "/iommu/*-iommu/cap" to detect the file name? > > - 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