From patchwork Mon Feb 17 14:04:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 13977899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2DC93C021A9 for ; Mon, 17 Feb 2025 14:04:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DE52710E46C; Mon, 17 Feb 2025 14:04:56 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.b="Be81bUf2"; dkim-atps=neutral Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2082.outbound.protection.outlook.com [40.107.220.82]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4C3B410E46C; Mon, 17 Feb 2025 14:04:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jQntMUQD5uf9hDFVBqzaTzamAWJce8ON4UdGtN6QXfAbNhfOBPLqxH93P1o6dnJJMJ1zf0n8phtp8ubU1jAnEJwXdHDSz5cMfQQn+8Zwo3ooDeAgjgWLwdQ8RXpy0uq7+ydHrMMMsL2ifVHZiNo2y81VOecKX4lFx5aAQvjU5+eh9cVbZuDaI5oTl7/UVPSUygR6cG74OSrMLKvViywGvqJ0QmDJbqN/+dT7fXR531lZS+NZINtEcJFTknIG4qgMPcPEPDJn0Mdbh2Ri85rhb0W7L6KQjGtzE6MePTniwM7blv+X3dYowggA+jlLpNeic7dUX971/a3JPsygB2bDOg== 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=a99x7DWKCuH25MLjZC88kbZwr2fA4pIdu1TGhFmqrEo=; b=n4svnGc+YKeONlS8sxpeM2Or32kJJBMDqa/rdU6P6LlvS76uv3kdjY/+xLEDnx/AS2DJSvmZht6FQcNwYsWPn2jIUIjCP0i1ChBAHzdDWr6iuwgwMdy/yQ3r2rQ53PDvr8XnXXOG51Y/MY2Uo/NVC9YBvAXoBNwr5WMquPOfKHA1SlFPdysdRVhM7yJ+C3hVm5QJOnETJyZZkZkwaK9X9zl+NmJI2bbLeYMsrswT4t+/gZaG/gRpz3vj4scM1S4AFDoCuGBJHckiuWbMGddPIv+bOcPWy6msg8uyF6MBJNa2Du1YMMvVUunzF61197yKHH8GTnmt3CyOndJJ34AsBw== 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=a99x7DWKCuH25MLjZC88kbZwr2fA4pIdu1TGhFmqrEo=; b=Be81bUf28KVOLXaf85R2F/4rkOtQvm6G6iaQLb0syJim7g+DATY8s10y6asDMlcKml1aCAMi7WJoNE7nDLKqUHeNL2+fXJfr3TCIKzHasxt8OErr795TUEbaOcBxp94rlJcikKtycT/O80e1SBYwjk10wLVf4DQyQjRbN3i4DCO617BO0Wz0MGbn57enq3mtDNKqC5wJ9x7+UE9RJBjtIVpOQzpVSGp+kPxRGGAFQ4v1DDQpgWlCsn7NI/i9/7RzL4fHDScm8lIZ0nWh9wKuqwnMRfC2WKEOSs4CFr7ilZ30elfxD098wk/4xeCTb5kEIttx0BPEz9wByLTQJgNuQw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB3990.namprd12.prod.outlook.com (2603:10b6:610:28::18) by MN2PR12MB4208.namprd12.prod.outlook.com (2603:10b6:208:1d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.19; Mon, 17 Feb 2025 14:04:51 +0000 Received: from CH2PR12MB3990.namprd12.prod.outlook.com ([fe80::6e37:569f:82ee:3f99]) by CH2PR12MB3990.namprd12.prod.outlook.com ([fe80::6e37:569f:82ee:3f99%6]) with mapi id 15.20.8445.017; Mon, 17 Feb 2025 14:04:51 +0000 From: Alexandre Courbot Subject: [RFC PATCH 0/3] gpu: nova-core: add basic timer subdevice implementation Date: Mon, 17 Feb 2025 23:04:45 +0900 Message-Id: <20250217-nova_timer-v1-0-78c5ace2d987@nvidia.com> X-B4-Tracking: v=1; b=H4sIAP1Bs2cC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI1MDI0Mz3bz8ssT4kszc1CLdZDNLE2MDQwuTNFMTJaCGgqLUtMwKsGHRsbW 1ACjb2D5cAAAA X-Change-ID: 20250216-nova_timer-c69430184f54 To: Danilo Krummrich , David Airlie , John Hubbard , Ben Skeggs Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Alexandre Courbot X-Mailer: b4 0.14.2 X-ClientProxiedBy: TYAPR01CA0115.jpnprd01.prod.outlook.com (2603:1096:404:2a::31) To CH2PR12MB3990.namprd12.prod.outlook.com (2603:10b6:610:28::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR12MB3990:EE_|MN2PR12MB4208:EE_ X-MS-Office365-Filtering-Correlation-Id: 635987a1-ebe1-4c2f-8b52-08dd4f5c0bf9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?jbyUvprDXHPQuKWYw+cNhg7J4nHydFZ?= =?utf-8?q?YChKemAkSIQ/3RH/HecPLmd5mjuxjzZISDTk6kTUYPlQLUARX+DK1LP1cUfLsJ56M?= =?utf-8?q?6cILZuh7QH1VDLhp4o1ISBYQN+5A47FETmADfWy3ePh+nx+CicTkLob1i+cexxAPW?= =?utf-8?q?2+z3jUk+Iq/c3hPC8SS9ILATePT7f4jBVquCUxcaw171zi5bQoSgBRMBJNi61MU0s?= =?utf-8?q?PYKXQecZuAMLVIym049LIrtMdNuTjNhjd2I1ezpufjyzTvrRpewU7DeDildHYTbFw?= =?utf-8?q?dU91V5hX/+n0b7+gClxexHmUWZySMGwa5j+o87btVu3DXTsHJgHCAK5/WEXkQk+25?= =?utf-8?q?/Qw+jxHnmk1PTZDvCn+1p9bVmFycZF8GShXgm7NS72AphPvZClW4zcfVeqZVmh6az?= =?utf-8?q?R/9f2QMFeQIpvyMPTotNnCAHg3IOQNjW0T7dHoz+LoEbw+MUCth+71ZxJ35hBf9NV?= =?utf-8?q?MKUIqdY5yGF1zkicQH8AeqMyPxDzYXbFBdhOdc/q+Qtg0GB6ZxZxJnaZVToKH4xcj?= =?utf-8?q?3e+DS3vw7/lnPifSsUO9ir6+5EU8PDISdmqu1uLqcm25OzJRM/e5Uty6QKCkAw3v/?= =?utf-8?q?UiM842GvEGYBx+nODrovgJc7tsebtONgT/mxVtZBSzJoQLNIg+9Ez1MvqAYqQkFje?= =?utf-8?q?A7Dw78ZEm9dKFiokV3BfD4E/bbhxGLNGHdx4JUqie+JaDfsS0h7RcoA86H0v46wk8?= =?utf-8?q?7pRCyostDkzO5wXoB2h09jdIB0PpJK5DcAu1YgZjL3EGcp/L/RAhf1gVlbmBrrN0o?= =?utf-8?q?eyl5ZlDXPUTa2VwPtRRPyUXwVYXtPy/M+dTDhnF7CaeMpaXKEN31GGpZ8Hkcs6cw1?= =?utf-8?q?bt1MugDTbQzNPYYW/wYXRpe1gx5IBZY6Soj/Ysbk6yVQ6UXAHfFTTCB3AhFNgczwB?= =?utf-8?q?PfCliRQp397FOKChrueyf8nfLcR7qB6x+92309TvyTwYfP5iAyWDrfKmIj0tHA+pS?= =?utf-8?q?wGjrZLYCOCBbeOoYtMQZtE8FwM2Ea51vIIcigFX1FRp8cseYlKiM+6r72AcVWYExk?= =?utf-8?q?Ryv/6AT+zGrpGw0EBPyaGM6PJ7T13vWI/rLs69WX6wocoYOmD/c0a2BYMU80a1/Fh?= =?utf-8?q?+RNgpv8P6J+rgW/yYc0REI6E3Srn0MD1YS4jUAULRwLReIiyGnVEgRA2LtItvpriD?= =?utf-8?q?Fspij2jt7ADAAJ1fHmpNUbGIPHzzVXKyhN2tsC41V/l/ry7rVTfqVblqdk/2nOisi?= =?utf-8?q?3lYvthG5aPZySrO9iYCbLuZJoU6udK6i6a2qdgCFEN+kVWp9GsPQsq1IbQv7CmqRZ?= =?utf-8?q?6n3Snx6gqYy7imGWWtXGuGzyoDGNAL/nrKb4S8rdKP20ncLQYitc1KQPM11jJu8sf?= =?utf-8?q?SyypdZp/7HfJ?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB3990.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(10070799003)(376014)(366016)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?LQkcOgFOYi2l1cGeUKSZMpnUmgoy?= =?utf-8?q?Hhwi7fTcAPzowmUZLHErZ+I32W8KP4/OBtwkg1MRhhy/+31tU41zk7Vp8rbwhZvG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v8SHafYfbM?= =?utf-8?q?lf1vOgAD0bt1k9OOeeeV/9WdphNiyNy1bfW0G9Xur6lxT0dvl0G0Z1LpDNiLXSxKd?= =?utf-8?q?34BgdEqhfhhrZNKHAAVk7u3HA3UCrFCuy4Nuq+gMx30d3w/gqZWQRUFWC7L5ClTN/?= =?utf-8?q?InEZo4kxJ2Op0c0x3vySwMx1NB/iz0tOgOZIEAD/YkwWUCjrsFlfdQOC5VHSyglyO?= =?utf-8?q?2eBbRL36xQK9iGCP4WH1HWJHDPGKwfd2DQjYaKtTTsGm5JOheJKdJZ5DFY2h7vDBn?= =?utf-8?q?e3bbc1rafRv+B9xzbLrqeMfCgWENo3iRL+nKGp76ksC5wH3PJgij8QLW6rLbvNi3G?= =?utf-8?q?YBRB8SwdklaePDDlVFHjrwACfC6Q3/vXue6a6f8QMgS0FIYCzY6lteNPNGgyJ0Bsc?= =?utf-8?q?RqtvNqZKpwTtbTOyQW9O69k5jcFCKh47VahMF3k93YdyOP0TWLRMfNGP0f+5zR/xb?= =?utf-8?q?D/ZtO84aUaAjnKXm4B08FxQqQwroV1yRbgLIU9P6+B9F2QgiRcrOvqn9Z9C+OXgtw?= =?utf-8?q?T5NRNMw3b2+Spf39a49CRnpR8jqlbQDfObTm6lWmAJLb1COQVT+yWl34MlORK4/Cr?= =?utf-8?q?1J3f+INrbKY4JWzGTCBTFYwCf1Q86b91BAzuSnkUJB2S+nQ0RKwnP82KEhA3fdvO8?= =?utf-8?q?zAooLqpOUM5?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 635987a1-ebe1-4c2f-8b52-08dd4f5c0bf9 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB3990.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2025 14:04:51.4095 (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: hE3zP+D978PxCQYvUPRHkzMe5hBR5nd1onEbxUfCrbG/egmBSI7qBNWSeHa37qaaQX0INImvvnFiOnameP3LJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4208 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi everyone, This short RFC is based on top of Danilo's initial driver stub series [1] and has for goal to initiate discussions and hopefully some design decisions using the simplest subdevice of the GPU (the timer) as an example, before implementing more devices allowing the GPU initialization sequence to progress (Falcon being the logical next step so we can get the GSP rolling). It is kept simple and short for that purpose, and to avoid bumping into a wall with much more device code because my assumptions were incorrect. This is my first time trying to write Rust kernel code, and some of my questions below are probably due to me not understanding yet how to use the core kernel interfaces. So before going further I thought it would make sense to raise the most obvious questions that came to my mind while writing this draft: - Where and how to store subdevices. The timer device is currently a direct member of the GPU structure. It might work for GSP devices which are IIUC supposed to have at least a few fixed devices required to bring the GSP up ; but as a general rule this probably won't scale as not all subdevices are present on all GPU variants, or in the same numbers. So we will probably need to find an equivalent to the `subdev` linked list in Nouveau. - BAR sharing between subdevices. Right now each subdevice gets access to the full BAR range. I am wondering whether we could not split it into the relevant slices for each-subdevice, and transfer ownership of each slice to the device that is supposed to use it. That way each register would have a single owner, which is arguably safer - but maybe not as flexible as we will need down the road? - On a related note, since the BAR is behind a Devres its availability must first be secured before any hardware access using try_access(). Doing this on a per-register or per-operation basis looks overkill, so all methods that access the BAR take a reference to it, allowing to call try_access() from the highest-level caller and thus reducing the number of times this needs to be performed. Doing so comes at the cost of an extra argument to most subdevice methods ; but also with the benefit that we don't need to put the BAR behind another Arc and share it across all subdevices. I don't know which design is better here, and input would be very welcome. - We will probably need sometime like a `Subdevice` trait or something down the road, but I'll wait until we have more than one subdevice to think about it. The first 2 patches are small additions to the core Rust modules, that the following patches make use of and which might be useful for other drivers as well. The last patch is the naive implementation of the timer device. I don't expect it to stay this way at all, so please point out all the deficiencies in this very early code! :) [1] https://lore.kernel.org/nouveau/20250209173048.17398-1-dakr@kernel.org/ Signed-off-by: Alexandre Courbot --- Alexandre Courbot (3): rust: add useful ops for u64 rust: make ETIMEDOUT error available gpu: nova-core: add basic timer device drivers/gpu/nova-core/driver.rs | 4 +- drivers/gpu/nova-core/gpu.rs | 35 ++++++++++++++- drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/regs.rs | 43 ++++++++++++++++++ drivers/gpu/nova-core/timer.rs | 91 ++++++++++++++++++++++++++++++++++++++ rust/kernel/error.rs | 1 + rust/kernel/lib.rs | 1 + rust/kernel/num.rs | 32 ++++++++++++++ 8 files changed, 206 insertions(+), 2 deletions(-) --- base-commit: 6484e46f33eac8dd42aa36fa56b51d8daa5ae1c1 change-id: 20250216-nova_timer-c69430184f54 Best regards,