This series adds support for the NVKV wire format for communicating
with GSP.
Essentially, the format encodes a sequence of calls to some function
f(key, index, value), where value is a [u8], u32, u64, [u32], or a
[u64]. The key is a u16 and the index is a 12 bit integer. The
interpretation of these function calls is per GMCAPI (RPC interface
used in firmwares later than r570). Generally speaking, the function
calls will map to some struct - for example, f(GPU_NAME_STRING_KEY, 0,
b"some gpu") naturally maps to storing a &str with the GPU name.
This series adds a general encoder and decoder that works with the
base formats used ([u8], u32, u64, [u32], or a [u64]) for encode and a
general `Schema` trait for decode. This could be used directly, but
since most messages are struct-like, it's more ergonomic to use some
typed helpers for this declarative use case. So this series adds two
simple macros for encode and decode of structs, plus some general
types and implementations that help with using these.
Future patches will wire this up through the command queue.
This is based on drm-rust-next.
---
Changes in v3:
- Rebase + drop zerocopy prereqs which are in now.
- Define Opcode with bounded_enum! (Alex)
- Use #[inline] instead of #[inline(always)] (Alex)
- Add Co-developed-by for Danilo on the encoder patch (EncodedStream)
- Split Schema into Schema (init/finish) and Visit<'data> (visit) to let
schemas borrow from the encoded stream
- Support schemas that borrow from the stream in nvkv_decode!, e.g.
struct NameSchema<'d> => Name<'d>
- Construct schemas only in place with a required Schema::init() and
drop the Default impls + stack size asserts (Alex)
- Doc improvements (Alex)
- Add a TODO for the O(#fields) visit dispatch in nvkv_decode! (Alex)
- Replace the Key<Option<T>> special case with TryFrom<DecoderValue>
for Option<T>
- Make Key's field and IndexedKey::new private (Alex)
- Move the nvkv_*! re-exports to GSP_INIT patch (Alex)
- Add decoder tests (Alex)
- Add error path tests (Alex)
- Add IndexedKey tests (Alex)
- Add RegKey tests (Alex)
- Link to v2: https://patch.msgid.link/20260827-b4-nvkv-v2-0-0de9d5c8658c@nvidia.com
Changes in v2:
- Tweak Schema trait to avoid materializing copies on the stack
- Move ArrayVec to alloc module (+add potentially useful methods) (Danilo)
- Add Vec::try_push_init (Danilo)
- Add sum error type for try_push_init, PushInitError
- Use Danilo's EncodedStream abstraction
- Add some stack space asserts (Danilo) - needs to skip on clippy tho
- Using zerocopy e.g. ref_from_prefix_with_elems requires updated zerocopy to
avoid linking error, so added those as prereqs.
- Link to v1: https://patch.msgid.link/20260817-b4-nvkv-v1-0-b84db5e84b67@nvidia.com
---
Eliot Courtney (8):
rust: alloc: add Vec::try_push_init
rust: alloc: add Vec::push_init
rust: alloc: add ArrayVec
gpu: nova-core: add NVKV encoder
gpu: nova-core: add NVKV decoder
gpu: nova-core: add NVKV typed encoding
gpu: nova-core: add NVKV typed decoding
gpu: nova-core: add NVKV GSP_INIT schemas
drivers/gpu/nova-core/gsp.rs | 1 +
drivers/gpu/nova-core/gsp/fw/commands.rs | 447 +++++++++++-
drivers/gpu/nova-core/gsp/nvkv.rs | 183 +++++
drivers/gpu/nova-core/gsp/nvkv/decode.rs | 1104 ++++++++++++++++++++++++++++++
drivers/gpu/nova-core/gsp/nvkv/encode.rs | 452 ++++++++++++
rust/kernel/alloc.rs | 3 +
rust/kernel/alloc/arrayvec.rs | 347 ++++++++++
rust/kernel/alloc/kvec.rs | 73 +-
rust/kernel/alloc/kvec/errors.rs | 30 +
9 files changed, 2637 insertions(+), 3 deletions(-)
---
base-commit: 66a2c223b620d844fe26c6bd4844d2a6a8c9dffc
change-id: 20260812-b4-nvkv-131af5c2661c
Best regards,
--
Eliot Courtney <ecourtney@nvidia.com>