diff options
| author | Alexandre Courbot <acourbot@nvidia.com> | 2025-10-16 11:55:48 +0900 |
|---|---|---|
| committer | Alexandre Courbot <acourbot@nvidia.com> | 2025-11-08 08:22:36 +0900 |
| commit | 5525ac03ca7adec61d39f3fd3a143b5e294bdff7 (patch) | |
| tree | 518677f9f6556cd116414409feb2ef14b4e66fdd /drivers/gpu/nova-core/nova_core.rs | |
| parent | 453a73000c56d2ee21f327c0a2a3249aa359bcc9 (diff) | |
gpu: nova-core: add functions and traits for lossless integer conversions
The core library's `From` implementations do not cover conversions
that are not portable or future-proof. For instance, even though it is
safe today, `From<usize>` is not implemented for `u64` because of the
possibility to support larger-than-64bit architectures in the future.
However, the kernel supports a narrower set of architectures, and in the
case of Nova we only support 64-bit. This makes it helpful and desirable
to provide more infallible conversions, lest we need to rely on the `as`
keyword and carry the risk of silently losing data.
Thus, introduce a new module `num` that provides safe const functions
performing more conversions allowed by the build target, as well as
`FromSafeCast` and `IntoSafeCast` traits that are just extensions of
`From` and `Into` to conversions that are known to be lossless.
Suggested-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/rust-for-linux/DDK4KADWJHMG.1FUPL3SDR26XF@kernel.org/
Acked-by: Danilo Krummrich <dakr@kernel.org>
[acourbot@nvidia.com: fix merge conflicts after rebase.]
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Message-ID: <20251029-nova-as-v3-4-6a30c7333ad9@nvidia.com>
Diffstat (limited to 'drivers/gpu/nova-core/nova_core.rs')
| -rw-r--r-- | drivers/gpu/nova-core/nova_core.rs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs index e130166c1086..9180ec9c27ef 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -13,6 +13,7 @@ mod firmware; mod gfw; mod gpu; mod gsp; +mod num; mod regs; mod vbios; |