linux/drivers/gpu/nova-core
Alexandre Courbot 5525ac03ca 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>
History 2025-11-08 08:22:36 +09:00
..
falcon gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
fb gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
firmware gpu: nova-core: Fix capitalization of some comments 2025-11-07 23:10:44 +09:00
gsp gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
regs gpu: nova-core: regs: rename .alter() --> .update() 2025-10-25 13:12:02 +09:00
bitfield.rs gpu: nova-core: bitfield: remove BitOr implementation 2025-10-25 13:16:31 +09:00
dma.rs gpu: nova-core: Simplify DmaObject::from_data in nova-core/dma.rs 2025-11-07 23:10:44 +09:00
driver.rs gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
falcon.rs gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
fb.rs gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
firmware.rs gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
gfw.rs gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
gpu.rs gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
gsp.rs gpu: nova-core: Add base files for r570.144 firmware bindings 2025-09-13 23:17:48 +09:00
Kconfig gpu: nova-core: depend on CONFIG_64BIT 2025-09-01 11:06:37 +02:00
Makefile gpu: nova-core: add initial driver stub 2025-03-09 19:24:27 +01:00
nova_core.rs gpu: nova-core: add functions and traits for lossless integer conversions 2025-11-08 08:22:36 +09:00
num.rs gpu: nova-core: add functions and traits for lossless integer conversions 2025-11-08 08:22:36 +09:00
regs.rs gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
vbios.rs gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00