The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] rust: add functions and traits for lossless integer conversions
@ 2026-07-27 10:15 Alexandre Courbot
  2026-07-27 10:15 ` [PATCH 1/2] " Alexandre Courbot
  2026-07-27 10:15 ` [PATCH 2/2] gpu: nova-core: use kernel lossless integer conversion module Alexandre Courbot
  0 siblings, 2 replies; 8+ messages in thread
From: Alexandre Courbot @ 2026-07-27 10:15 UTC (permalink / raw)
  To: Yury Norov, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Onur Özkan, David Airlie, Simona Vetter
  Cc: Alexandre Courbot, John Hubbard, Alistair Popple, Timur Tabi,
	Eliot Courtney, Zhi Wang, linux-kernel, rust-for-linux, nova-gpu,
	dri-devel

This series introduces a copy of the lossless integer conversion
functions/traits of `nova-core` into the `kernel` crate, and makes
`nova-core` use them.

It is way overdue since its RFC [1]; recent dicussions [2] that have
suggested that it might become useful have triggered this posting.

This series is based on `rust-next`.

[1] https://lore.kernel.org/r/20251104-as_casts-v1-1-0a0e95bd2a9f@nvidia.com
[2] https://lore.kernel.org/all/DK82VNBOLWA7.1RFTZQWWNHIEH@nvidia.com/

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Changes in v1:
- Update to latest version in `nova-core`.
- Make `nova-core` use the kernel crate implementation and remove its
  own.
- Link to RFC: https://lore.kernel.org/r/20251104-as_casts-v1-1-0a0e95bd2a9f@nvidia.com

To: Alexandre Courbot <acourbot@nvidia.com>
To: Yury Norov <yury.norov@gmail.com>
To: Miguel Ojeda <ojeda@kernel.org>
To: Boqun Feng <boqun@kernel.org>
To: Gary Guo <gary@garyguo.net>
To: Björn Roy Baron <bjorn3_gh@protonmail.com>
To: Benno Lossin <lossin@kernel.org>
To: Andreas Hindborg <a.hindborg@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
To: Trevor Gross <tmgross@umich.edu>
To: Danilo Krummrich <dakr@kernel.org>
To: Daniel Almeida <daniel.almeida@collabora.com>
To: Tamir Duberstein <tamird@kernel.org>
To: Onur Özkan <work@onurozkan.dev>
To: David Airlie <airlied@gmail.com>
To: Simona Vetter <simona@ffwll.ch>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Timur Tabi <ttabi@nvidia.com>
Cc: Eliot Courtney <ecourtney@nvidia.com>
Cc: Zhi Wang <zhiw@nvidia.com>
Cc: linux-kernel@vger.kernel.org
Cc: rust-for-linux@vger.kernel.org
Cc: nova-gpu@lists.linux.dev
Cc: dri-devel@lists.freedesktop.org

---
Alexandre Courbot (2):
      rust: add functions and traits for lossless integer conversions
      gpu: nova-core: use kernel lossless integer conversion module

 drivers/gpu/nova-core/falcon.rs                    |  10 +-
 drivers/gpu/nova-core/falcon/fsp.rs                |   2 +-
 drivers/gpu/nova-core/fb.rs                        |   2 +-
 drivers/gpu/nova-core/fb/hal/gb100.rs              |   6 +-
 drivers/gpu/nova-core/firmware.rs                  |   8 +-
 drivers/gpu/nova-core/firmware/booter.rs           |  10 +-
 drivers/gpu/nova-core/firmware/fwsec.rs            |   2 +-
 drivers/gpu/nova-core/firmware/fwsec/bootloader.rs |   2 +-
 drivers/gpu/nova-core/firmware/gsp.rs              |   2 +-
 drivers/gpu/nova-core/firmware/riscv.rs            |   6 +-
 drivers/gpu/nova-core/fsp.rs                       |   2 +-
 drivers/gpu/nova-core/gsp.rs                       |   2 +-
 drivers/gpu/nova-core/gsp/cmdq.rs                  |   4 +-
 drivers/gpu/nova-core/gsp/fw.rs                    |   8 +-
 drivers/gpu/nova-core/gsp/sequencer.rs             |   2 +-
 drivers/gpu/nova-core/num.rs                       | 211 ------------------
 drivers/gpu/nova-core/vbios.rs                     |   2 +-
 rust/kernel/num.rs                                 |   3 +
 rust/kernel/num/casts.rs                           | 248 +++++++++++++++++++++
 19 files changed, 286 insertions(+), 246 deletions(-)
---
base-commit: 3dab139d4795f688e4f243e40c7474df00d329d9
change-id: 20251104-as_casts-6a8882ac0192

Best regards,
--  
Alexandre Courbot <acourbot@nvidia.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH 0/2] rust: num: casts: replace const type narrowing methods with a macro
@ 2026-08-25  2:44 Alexandre Courbot
  2026-08-25  2:44 ` [PATCH 2/2] gpu: nova-core: use kernel lossless integer conversion module Alexandre Courbot
  0 siblings, 1 reply; 8+ messages in thread
From: Alexandre Courbot @ 2026-08-25  2:44 UTC (permalink / raw)
  To: Yury Norov, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Onur Özkan
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, rust-for-linux, linux-kernel, nova-gpu,
	Alexandre Courbot

The `casts` module includes lossless const converter functions, as it is
sometimes necessary to cast a bindgen-generated constant into a narrower
type. Such conversions are known to be lossless at compile-time, but
using `as` for them still requires a `CAST` comment and carries the risk
of the conversion becoming lossy should the value of the constant
change.

Since these functions need to be evaluated at compile-time, they take
the expression to narrow as a generic const argument, requiring the use
of the turbofish syntax by callers. Also, a dedicated function is needed
per type conversion, resulting in 9 functions generated by a single
macro. All these factors make them hard to discover and a bit cumbersome
to use.

This series replaces these functions with a single `const_as` macro that
ensures an `as` conversion is lossless at build-time. Since it is unique
and not generated, it is easy to discover, and its syntax also looks
more accessible than the turbofish one.

Patch 2 then performs the conversion of nova-core to use these
conversion helpers in the process of removing its own superseded `num`
module.

This series is based on today's `master`.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Alexandre Courbot (2):
      rust: num: casts: replace const type narrowing methods with a macro
      gpu: nova-core: use kernel lossless integer conversion module

 drivers/gpu/nova-core/falcon.rs                    |  12 +-
 drivers/gpu/nova-core/falcon/fsp.rs                |   4 +-
 drivers/gpu/nova-core/fb.rs                        |   2 +-
 drivers/gpu/nova-core/fb/hal/gb100.rs              |   9 +-
 drivers/gpu/nova-core/firmware.rs                  |   4 +-
 drivers/gpu/nova-core/firmware/booter.rs           |   4 +-
 drivers/gpu/nova-core/firmware/fwsec.rs            |   2 +-
 drivers/gpu/nova-core/firmware/fwsec/bootloader.rs |   4 +-
 drivers/gpu/nova-core/firmware/gsp.rs              |   9 +-
 drivers/gpu/nova-core/firmware/tlv.rs              |  11 +-
 drivers/gpu/nova-core/fsp.rs                       |   8 +-
 drivers/gpu/nova-core/gsp.rs                       |   4 +-
 drivers/gpu/nova-core/gsp/cmdq.rs                  |  22 +--
 drivers/gpu/nova-core/gsp/fw.rs                    |  50 ++---
 drivers/gpu/nova-core/gsp/fw/commands.rs           |   4 +-
 drivers/gpu/nova-core/gsp/sequencer.rs             |   2 +-
 drivers/gpu/nova-core/mctp.rs                      |   8 +-
 drivers/gpu/nova-core/num.rs                       | 211 ---------------------
 drivers/gpu/nova-core/vbios.rs                     |   2 +-
 rust/kernel/num/casts.rs                           | 129 ++++++++-----
 20 files changed, 163 insertions(+), 338 deletions(-)
---
base-commit: 66498c75b4f8017f62d720d9b59675bdf3abce91
change-id: 20260825-const_as-a792dad39943

Best regards,
--  
Alexandre Courbot <acourbot@nvidia.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-08-25  5:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-27 10:15 [PATCH 0/2] rust: add functions and traits for lossless integer conversions Alexandre Courbot
2026-07-27 10:15 ` [PATCH 1/2] " Alexandre Courbot
2026-07-27 10:28   ` Gary Guo
2026-07-27 11:10     ` Miguel Ojeda
2026-07-27 11:19     ` Danilo Krummrich
2026-07-27 10:15 ` [PATCH 2/2] gpu: nova-core: use kernel lossless integer conversion module Alexandre Courbot
  -- strict thread matches above, loose matches on Subject: below --
2026-08-25  2:44 [PATCH 0/2] rust: num: casts: replace const type narrowing methods with a macro Alexandre Courbot
2026-08-25  2:44 ` [PATCH 2/2] gpu: nova-core: use kernel lossless integer conversion module Alexandre Courbot
2026-08-25  5:27   ` Eliot Courtney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox