From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2082.outbound.protection.outlook.com [40.107.100.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5DC22FE054; Tue, 26 Aug 2025 23:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.82 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756249953; cv=fail; b=YKVAWgR0ELiiVjIXRPdLLnW3H65NYWy5cgMNNsviN0QZe4sm1ICkac2jRiPEuYgbDCg93Df9ggKwZdvwzCj9wNJcc3L0S/bznKT+BIUt8LAmFG277Yfb6B04mKmQ6xu45FajJWq9FptcaIhfkhoZAXOoTfdg/LfhCUQUb0oRpCg= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756249953; c=relaxed/simple; bh=KTALXiXimP6faBjuTBhyqHfGPZiEyPMfTLgthdjhVi0=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=HnhKzCHp8ro4mReeA6XhbtkQSxuN2VTQPEeFKSoZcVVL1wqUSS+V5pxYkG0LJ4N9Nr9xPpHkIgxrA+S8yrqkmPoPS2Xm5Br1qFZBaqELN+e8MIo5r4bjIGhZXt2nLyraswLsU+1nSvV0UmLXjp9QNnuC6ohYkwLGBzZZF8yMp44= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=YB0/ZY2p; arc=fail smtp.client-ip=40.107.100.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="YB0/ZY2p" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uQqzHJzlUUzconGmZK8v0gr3rJ1O2lSEV8xZPyzgk3LqZiz4jwXG480ridOJGh4FSLc2Nl03zFD1LtHSJ9IVkf24/OCItYvX0kc12YcgFyBDb+CTnS7qZo+XURe82VrFX4w/uamZxYgrgEcYJOS21cRTU0lx78i+JL9eDB4gpqE8U8LZlE/DZQtEdJO4QrbSUgVpSD7OT60iwjbTXdcLVsQlBVs54rJ1MAHoWF6orIX/k1dP42Dq1vk3hpltlLpo6wiFGK7CRafCXRQhN+YXeuOi8Y9+e0sN4jN0NfxNcYD7viEOqauOlxPZq1Sv2LBxfa/StebJY3uWHCqONUAvcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=VQvDb/ufqIuS8nBQjQBmase2KJtZYMuF4UmRjzGvL4s=; b=pYQsdNnrZ7UJynOWt93KFeyq6oKsKqI25iCmSJWmpJ6soewE6Tyhddt+tjdjwJZWOo7nLxFPwpwLOY0tthcBTbCoA2I2rI1omAd1BR3S1kHoX45cXBr6WgHKoJ7HO/NCvvY8XSLosShnHATLtbO8wLNWwfEgXQ48nbmMKzCfnTeYFMr3gxpEt9imVCSatmtv7qWrrpILBoBfVJQf/tuZgN7qYhFgZrI0sAOnM7QsAojafPlMJ9nQU8SV1rH96Y0+4/gwtVMZMdU95E6vYdAGpOdMwteOr8x6Bl5onJcHhe2/cTjAihJYzRN7GTCFWN3o5Bo5zDXc/h1IlE0kFVrZSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VQvDb/ufqIuS8nBQjQBmase2KJtZYMuF4UmRjzGvL4s=; b=YB0/ZY2pIOluNDcosjcpbJSd/MXvmq5+V7Zbf7bIU6f041a/SQBJirMuXgbiietyH7GOvUUKsbwUu+4lLmx0sF0B3yO3TMDTQOiBj66F25kI5giwgMYynJgXY6qAmIDtTq/033RDh88ft1xgbJAsHnsqca3EiPUm0RKVnocf5uBnMJ/WEEeuDxBTbXm6WihJN/xWU/OAxw6Z4Hilhz88pe5E6vAzH7zaiapQ13NSgVKRFqrQ1n0VWPb1LMTksbxM+8hv80VyHVrt2URq+8WFuk7yURTbda5w7GZ0KUazpdbY3Rpe3TXVBF43RjBjnRHam8oiRFrpnL/IktRNKkUZig== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5968.namprd12.prod.outlook.com (2603:10b6:408:14f::7) by PH7PR12MB7913.namprd12.prod.outlook.com (2603:10b6:510:27b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9073.13; Tue, 26 Aug 2025 23:12:27 +0000 Received: from LV2PR12MB5968.namprd12.prod.outlook.com ([fe80::e6dd:1206:6677:f9c4]) by LV2PR12MB5968.namprd12.prod.outlook.com ([fe80::e6dd:1206:6677:f9c4%6]) with mapi id 15.20.9073.010; Tue, 26 Aug 2025 23:12:27 +0000 From: John Hubbard To: Danilo Krummrich Cc: Alexandre Courbot , Joel Fernandes , Timur Tabi , Alistair Popple , David Airlie , Simona Vetter , Bjorn Helgaas , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , nouveau@lists.freedesktop.org, linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, LKML , John Hubbard , Elle Rhumsaa Subject: [PATCH v7 0/6] rust, nova-core: PCI Class, Vendor support Date: Tue, 26 Aug 2025 16:12:18 -0700 Message-ID: <20250826231224.1241349-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.51.0 X-NVConfidentiality: public Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0PR03CA0096.namprd03.prod.outlook.com (2603:10b6:a03:333::11) To LV2PR12MB5968.namprd12.prod.outlook.com (2603:10b6:408:14f::7) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5968:EE_|PH7PR12MB7913:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c97337b-c01c-4f1e-64b8-08dde4f60635 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?VHuz6yz89KOCzDR9xmsC2uyzM5vhDp9nLnV0Gh/q8ANglDSKzJw7KsKlgb3R?= =?us-ascii?Q?WOGyz7a4Q8cpeZIGeTPuw5Qaw5yvKXUYro7Kk31gS9/tL9CY+jKCwbdIiiyM?= =?us-ascii?Q?HqFU+8KCLbuu1X05RET8ALLosVt2+ZhErOpuk0l4YIHaAeWAN2txp3mkMMaz?= =?us-ascii?Q?kQb8oPIaCngZM6yaTZxOflTv1R756U0UOr5jfyAa7aA4Mx7JgjnVqa1REn7V?= =?us-ascii?Q?hgdIauWiM2LpgHqbT5tQ41I/83MgsNctSIY0b3vl4kvi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m88i8ukA/ryFE/GETNuq6saIj14foMfxsf37kMTCL/9tN+525CYm9os2?= =?us-ascii?Q?kQx8kTJw9Vs1V4E+8ka7WWkpLDDm/s+++NUD1k5WUF9c8B6KXl9L6M+rl/8r?= =?us-ascii?Q?TBbQ1hpl2tvBdkU0blz0fC6sFVbOk/zZ9cXcAAA3iq4jBwxyr0TMHxSoKn4B?= =?us-ascii?Q?t5KVF4pO8Tqs75m45RqwZxsTwE+eh4fljHtegCFby3Grvd3htSv4CHI/pN3e?= =?us-ascii?Q?3RdOJLhFgkaC75jb4OiTlOyeNNSwzpRxXcf6E4SR1iBuLpDfetN+IGa9WVuu?= =?us-ascii?Q?rhD/5smBjts=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5968.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Z3IsEH9on3pGR4nHp7BmvZ1NcrdsuGiqYFwRNwF1JxizqgJ7aqExU3/hz/Cs?= =?us-ascii?Q?Nrb2A8cYfZ/efMklUZTYY8+AAZ+lMD2LWTvA65bXEQVD1l70cxMWRr+SIMT9?= =?us-ascii?Q?OFYSl02735j169hNPg6ZjzOOJ4qSMJfSIjCIimP3ybsYZUXGoDTVWvDoE9+a?= =?us-ascii?Q?OwWMHH6OKqujM3Wh9Oq2uQ4/wM/NcMXjZAv9psiu7tBCbldpTqjWMafnaRVp?= =?us-ascii?Q?D9p8AgDDEdCqulToxQvPOA7/Ri7ay9LrMIqk00HxnAjsbUewKVpHXYqWLZ+7?= =?us-ascii?Q?uZB7jZPwv1+4+TjtDeHDOFH4K920mXr3bvZ+vl4rHWw1E0aqpFJClU+bkn7Q?= =?us-ascii?Q?PlOchjdWp/x0+vWf4do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4ctx?= =?us-ascii?Q?RoX1GXitrqZwJiK0zRbYTK3/h3sY3VYeAtDII0hKOzQZPnC2bN/Ugq8HMbNK?= =?us-ascii?Q?M8LsMMyovKFdBh5dTHqY03y30SnFLJlbRha21Fz2Voxuh7/JC76XWkw7V/pi?= =?us-ascii?Q?SnFKBfOcFMmw9ZJCA/2FoFZDStVpl5NFq32z93+Sn/F+mOxp/IW9agOBI6/7?= =?us-ascii?Q?TC5HjTpUhnvLqFCJ2ALELBDp6a1ftiwWkibv1C2zU+qII6NeWIaaRdh8TCiI?= =?us-ascii?Q?VYWUcRDdqyRa+T+s8i/+FnT5psbblMx6gnS3i7RFfK9cTMsf1QT7ITLOYDIT?= =?us-ascii?Q?rEgnGwxixqxyXpDW1x6yleZ126vMZLsZCGJwlOtS?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c97337b-c01c-4f1e-64b8-08dde4f60635 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5968.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2025 23:12:27.5122 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Cya+U3FPPKQXnbDLk5zT6hAEq6InbkcqwwRabEnwad9GvAw3cQRSdpt2od+TcwQwPXdt0GGS7eSuvLx8PwGjmQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7913 Changes since v6: * Applied changes from Danilo's and Alex's and Elle's reviews (thanks!): * Rebased onto driver-core-next, which is here: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git * Changed pci::Vendor to be a u16, instead of a u32. * Inlined all of the tiniest functions. * Changed from Class/Vendor new(), to from_raw(). * Made from_raw() only accessible to super, which in this case is the pci module. * Restored infallible operations. That causes Alex's request for the following reasonable behavior to work once again: from_raw(0x10de).as_raw() == 0x10de * Added a new patch, to inline the remaining PCI operations. This provides consistent inline choices throughout pci.rs. Changes since v5: * Applied changes from Danilo's review (thanks!): * Split the nova-core patch into two patches, for nova and pci. * Added rust/kernel/pci/ to MAINTAINERS. Changes since v4: * Applied changes from Danilo's and Alex's review (thanks!): * Reorganized the patches so that the Nova changes consume the results of Class and Vendor upgrades, all in one shot. * Made Class and Vendor types get constructed infallibly. * This was all somewhat disruptive, and also required one more patch in order to properly separate the various steps. But I think it is all correct now. And CLIPPY=1 builds cleanly too. * Elle Rhumsaa provided a Reviewed-by for v4 (thanks!), but due to the churn in v5 here, I thought it best to not add that tag to v5 yet. Instead, I have directly Cc'd Elle on the patches for now. Changes since v3: * Applied changes from Danilo's review (thanks!): * Moved Class and Vendor to a new pci/id.rs file. * Added ClassMask, to constrain callers to use only the two valid masks. * Removed pci_class_code_raw() * Changed Class and Vendor .as_u32() to .as_raw(), because after Danilo's comment I looked around rust/kernel and learned that .as_raw() is the overwhelmingly used convention. * Changed vendor_id() to return a Vendor instance directly. * Also, validated Vendor during construction, just as is done with Class. Both of these items are expected to match known values, even for new devices, so that's a reasonable move. Changes since v2: * Applied changes from Danilo's and Alex's review (thanks!): * Moved everything possible out of the new define_all_pci_classes!() and define_all_pci_vendors!() macros. * Used "impl TryFrom for Class/Vendor", instead of .from_u32(). * Made the new DeviceId methods infallible. * Upgraded DeviceId::from_id() to accept a Vendor struct. * Changed the names to be a little clearer: * class_code_raw() --> pci_class_code_raw() * class_enum() --> pci_class() * Added doctests for the items that are not yet used in real drivers. v2 is here: https://lore.kernel.org/20250818013305.1089446-1-jhubbard@nvidia.com Changes since v1: 1) Use the pci_device_table for filtering, instead of open-coding filters in the .probe() callback. 2) Add PCI Class (class, subclass, implementation) and PCI Vendor to Rust for Linux. 3) Rebased onto the latest nova-next branch, which is here: https://gitlab.freedesktop.org/drm/nova.git v1 is here: https://lore.kernel.org/20250813232859.224316-1-jhubbard@nvidia.com Cc: Danilo Krummrich Cc: Alexandre Courbot Cc: Elle Rhumsaa John Hubbard (6): rust: pci: provide access to PCI Class and Class-related items rust: pci: provide access to PCI Vendor values rust: pci: add DeviceId::from_class_and_vendor() method gpu: nova-core: avoid probing non-display/compute PCI functions rust: pci: use pci::Vendor instead of bindings::PCI_VENDOR_ID_* rust: pci: inline several tiny functions MAINTAINERS | 1 + drivers/gpu/nova-core/driver.rs | 33 +- rust/kernel/pci.rs | 55 ++- rust/kernel/pci/id.rs | 577 ++++++++++++++++++++++++++ samples/rust/rust_dma.rs | 6 +- samples/rust/rust_driver_auxiliary.rs | 12 +- samples/rust/rust_driver_pci.rs | 9 +- 7 files changed, 665 insertions(+), 28 deletions(-) create mode 100644 rust/kernel/pci/id.rs base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585 -- 2.51.0