gpu: nova-core: fixups for GSP message queue and bindings
Subsystems (4)
Alexandre Courbot
maintainerv3 cover gpu: nova-core: fixups for GSP message queue and bindings
This series contains a few fixups for the recently merged GSP command-queue code, by order of importance:
- Some explicit padding required to safely implement AsBytes was missing in the bindings,
- A bug in the received message length calculation results in the message handler being given more data than it should,
- MaybeZeroable is now derived by the kernel's bindgen, but the Nova bindings have not been updated for that,
- Some items in the bindings were referred to using the version module directly, instead of the alias we defined to limit the diff when we upgrade firmware versions.
All of them address "bugs" (with the first two fixing actual correctness issues), but since Nova does not do much anyway, they are also not absolutely critical. Other series planned for this cycle will depend on them, so one way or the other it would be great to see them in drm-rust-next.
---
Changes in v3:
- Rebase on top of drm-rust-next.
- Add method to return the payload size of a message. (thanks Alistair!)
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Add missing "Fixes:" tags.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Alexandre Courbot (4):
gpu: nova-core: bindings: add missing explicit padding
gpu: nova-core: gsp: fix length of received messages
gpu: nova-core: bindings: derive MaybeZeroable
gpu: nova-core: gsp: replace firmware version with "bindings" alias
drivers/gpu/nova-core/gsp/cmdq.rs | 10 ++- drivers/gpu/nova-core/gsp/fw.rs | 78 ++++++++-------- drivers/gpu/nova-core/gsp/fw/r570_144.rs | 11 ++- drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 105 ++++++++++++---------- 4 files changed, 110 insertions(+), 94 deletions(-)
---
base-commit: 60c7398bded2e11f0db40a409a241b8be5910ee2
change-id: 20251121-nova-fixes-dc9b4f17b90e
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>
Alexandre Courbot
maintainerPATCH v3 1/4 gpu: nova-core: bindings: add missing explicit padding
Explicit padding is needed in order to avoid uninitialized bytes and safely implement AsBytes. The --explicit-padding of bindgen was omitted by mistake when these bindings were generated.
--- drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +12 -0
@@ -325,6 +325,7 @@ pub struct NV0080_CTRL_GPU_GET_SRIOV_CAPS_PARAMS { pub totalVFs: u32_, pub firstVfOffset: u32_, pub vfFeatureMask: u32_, + pub __bindgen_padding_0: [u8; 4usize], pub FirstVFBar0Address: u64_, pub FirstVFBar1Address: u64_, pub FirstVFBar2Address: u64_,
@@ -340,6 +341,7 @@ pub struct NV0080_CTRL_GPU_GET_SRIOV_CAPS_PARAMS { pub bClientRmAllocatedCtxBuffer: u8_, pub bNonPowerOf2ChannelCountSupported: u8_, pub bVfResizableBAR1Supported: u8_, + pub __bindgen_padding_1: [u8; 7usize], }#[repr( C )] #[derive( Debug , Default , Copy , Clone )]
@@ -347,11 +349,13 @@ pub struct NV2080_CTRL_BIOS_GET_SKU_INFO_PARAMS { pub BoardID: u32_, pub chipSKU: [ffi::c_char; 9usize], pub chipSKUMod: [ffi::c_char; 5usize], + pub __bindgen_padding_0: [u8; 2usize], pub skuConfigVersion: u32_, pub project: [ffi::c_char; 5usize], pub projectSKU: [ffi::c_char; 5usize], pub CDP: [ffi::c_char; 6usize], pub projectSKUMod: [ffi::c_char; 2usize], + pub __bindgen_padding_1: [u8; 2usize], pub businessCycle: u32_, }pub type NV2080_CTRL_CMD_FB_GET_FB_REGION_SURFACE_MEM_TYPE_FLAG = [u8_ ;17usize ];
@@ -371,6 +375,7 @@ pub struct NV2080_CTRL_CMD_FB_GET_FB_REGION_FB_REGION_INFO {#[derive( Debug , Default , Copy , Clone )] pub struct NV2080_CTRL_CMD_FB_GET_FB_REGION_INFO_PARAMS {pub numFBRegions:u32_ , +pub __bindgen_padding_0: [u8 ;4usize ],pub fbRegion: [NV2080_CTRL_CMD_FB_GET_FB_REGION_FB_REGION_INFO ;16usize ], }#[repr( C )]
@@ -495,13 +500,16 @@ pub struct FW_WPR_LAYOUT_OFFSET {#[derive( Debug , Copy , Clone )] pub struct GspStaticConfigInfo_t {pub grCapsBits: [u8_ ;23usize ], +pub __bindgen_padding_0:u8 ,pub gidInfo:NV2080_CTRL_GPU_GET_GID_INFO_PARAMS ,pub SKUInfo:NV2080_CTRL_BIOS_GET_SKU_INFO_PARAMS , +pub __bindgen_padding_1: [u8 ;4usize ],pub fbRegionInfoParams:NV2080_CTRL_CMD_FB_GET_FB_REGION_INFO_PARAMS ,pub sriovCaps:NV0080_CTRL_GPU_GET_SRIOV_CAPS_PARAMS ,pub sriovMaxGfid:u32_ ,pub engineCaps: [u32_ ;3usize ],pub poisonFuseEnabled:u8_ , +pub __bindgen_padding_2: [u8 ;7usize ],pub fb_length:u64_ ,pub fbio_mask:u64_ ,pub fb_bus_width:u32_ ,
@@ -527,16 +535,20 @@ pub struct GspStaticConfigInfo_t { pub bIsMigSupported: u8_, pub RTD3GC6TotalBoardPower: u16_, pub RTD3GC6PerstDelay: u16_, + pub __bindgen_padding_3: [u8; 2usize], pub bar1PdeBase: u64_, pub bar2PdeBase: u64_, pub bVbiosValid: u8_, + pub __bindgen_padding_4: [u8; 3usize], pub vbiosSubVendor: u32_, pub vbiosSubDevice: u32_, pub bPageRetirementSupported: u8_, pub bSplitVasBetweenServerClientRm: u8_, pub bClRootportNeedsNosnoopWAR: u8_, + pub __bindgen_padding_5: u8, pub displaylessMaxHeads: VIRTUAL_DISPLAY_GET_NUM_HEADS_PARAMS, pub displaylessMaxResolution: VIRTUAL_DISPLAY_GET_MAX_RESOLUTION_PARAMS, + pub __bindgen_padding_6: [u8; 4usize], pub displaylessMaxPixels: u64_, pub hInternalClient: u32_, pub hInternalDevice: u32_,
Signature · 1 line
2.52.0
Alexandre Courbot
maintainerPATCH v3 2/4 gpu: nova-core: gsp: fix length of received messages
In reply to Alexandre CourbotThe size of messages' payload is miscalculated, leading to extra data passed to the message handler. While this is not a problem with our current set of commands, others with a variable-length payload may misbehave. Fix this by introducing a method returning the payload size and using it.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 10 ++++++---- drivers/gpu/nova-core/gsp/fw.rs | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-)
drivers/gpu/nova-core/gsp/cmdq.rs +6 -4
@@ -588,21 +588,23 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> { header.length(), ); +let payload_length = header.payload_length (); +// Check that the driver read area is large enough for the message. -if slice_1.len () + slice_2.len () < header.length () { +if slice_1.len () + slice_2.len () < payload_length {return Err (EIO ); }// Cut the message slices down to the actual length of the message. -let (slice_1, slice_2) =if slice_1.len () > header.length () { +let (slice_1, slice_2) =if slice_1.len () > payload_length {// PANIC: we checked above that `slice_1` is at least as long as `msg_header.length()`. - (slice_1.split_at (header.length ()).0 , &slice_2[0 ..0 ]) + (slice_1.split_at (payload_length).0 , &slice_2[0 ..0 ]) }else { ( slice_1,// PANIC: we checked above that `slice_1.len() + slice_2.len()` is at least as // large as `msg_header.length()`. - slice_2.split_at (header.length () - slice_1.len ()).0 , + slice_2.split_at (payload_length - slice_1.len ()).0 , ) };
drivers/gpu/nova-core/gsp/fw.rs +9 -4
@@ -853,11 +853,16 @@ pub(crate) fn set_checksum(&mut self, checksum: u32) { self.inner.checkSum = checksum; } -/// Returns the total length of the message. +/// Returns the length of the message's payload. +pub (crate )fn payload_length (&self) ->usize { +// `rpc.length` includes the length of the RPC message header. + num::u32_as_usize (self.inner.rpc.length) + .saturating_sub (size_of ::<bindings::rpc_message_header_v >()) + } + +/// Returns the total length of the message, message and RPC headers included. pub (crate )fn length (&self) ->usize { -// `rpc.length` includes the length of the GspRpcHeader but not the message header. -size_of ::<Self >() -size_of ::<bindings::rpc_message_header_v >() - + num::u32_as_usize (self.inner.rpc.length) +size_of ::<Self >() + self.payload_length () }// Returns the sequence number of the message.
Signature · 1 line
2.52.0
Re: [PATCH v3 2/4] gpu: nova-core: gsp: fix length of received messages
On 2025-12-16 at 13:57 +1100, Alexandre Courbot <[email protected]> wrote...
Quoted 5 lines
The size of messages' payload is miscalculated, leading to extra data passed to the message handler. While this is not a problem with our current set of commands, others with a variable-length payload may misbehave. Fix this by introducing a method returning the payload size and using it.
The whole inconsistency of the message element struct not including it's header fields in the size whilst the rpc struct does has caused endless confusion, this looks much better, thanks for fixing!
Quoted 69 lines
Fixes 75f6b1de8133 ("gpu: nova-core: gsp: Add GSP command queue bindings and handling")Reviewed-by Lyude Paul <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>--- drivers/gpu/nova-core/gsp/cmdq.rs | 10 ++++++---- drivers/gpu/nova-core/gsp/fw.rs | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-)drivers/gpu/nova-core/gsp/cmdq.rs +6
-4@@ -588,21 +588,23 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> { header.length(), ); +let payload_length = header.payload_length (); +// Check that the driver read area is large enough for the message. -if slice_1.len () + slice_2.len () < header.length () { +if slice_1.len () + slice_2.len () < payload_length {return Err (EIO ); }// Cut the message slices down to the actual length of the message. -let (slice_1, slice_2) =if slice_1.len () > header.length () { +let (slice_1, slice_2) =if slice_1.len () > payload_length {// PANIC: we checked above that `slice_1` is at least as long as `msg_header.length()`. - (slice_1.split_at (header.length ()).0 , &slice_2[0 ..0 ]) + (slice_1.split_at (payload_length).0 , &slice_2[0 ..0 ]) }else { ( slice_1,// PANIC: we checked above that `slice_1.len() + slice_2.len()` is at least as // large as `msg_header.length()`. - slice_2.split_at (header.length () - slice_1.len ()).0 , + slice_2.split_at (payload_length - slice_1.len ()).0 , ) };drivers/gpu/nova-core/gsp/fw.rs +9
-4@@ -853,11 +853,16 @@ pub(crate) fn set_checksum(&mut self, checksum: u32) { self.inner.checkSum = checksum; } -/// Returns the total length of the message. +/// Returns the length of the message's payload. +pub (crate )fn payload_length (&self) ->usize { +// `rpc.length` includes the length of the RPC message header. + num::u32_as_usize (self.inner.rpc.length) + .saturating_sub (size_of ::<bindings::rpc_message_header_v >()) + } + +/// Returns the total length of the message, message and RPC headers included. pub (crate )fn length (&self) ->usize { -// `rpc.length` includes the length of the GspRpcHeader but not the message header. -size_of ::<Self >() -size_of ::<bindings::rpc_message_header_v >() - + num::u32_as_usize (self.inner.rpc.length) +size_of ::<Self >() + self.payload_length () }// Returns the sequence number of the message. Signature · 2 lines
-- 2.52.0
Alexandre Courbot
maintainerRe: [PATCH v3 2/4] gpu: nova-core: gsp: fix length of received messages
Quoted 10 lines · Alistair Popple
On 2025-12-16 at 13:57 +1100, Alexandre Courbot <[email protected]> wrote...
Quoted 5 lines
The size of messages' payload is miscalculated, leading to extra data passed to the message handler. While this is not a problem with our current set of commands, others with a variable-length payload may misbehave. Fix this by introducing a method returning the payload size and using it.
The whole inconsistency of the message element struct not including it's header fields in the size whilst the rpc struct does has caused endless confusion, this looks much better, thanks for fixing!
Indeed. It would be so much simpler if the RPC header just included the size of its *payload* - because if we have the header to begin with, of course it is part of the message!
Instead we have to deal with the possibility of a nonsensical length value if it is shorter than that of the header. Thankfully a saturating sub always yields a correct behavior, else we would have to return a Result. :/
Quoted 2 lines
Reviewed-by Alistair Popple <[email protected]>
Thanks!
Re: [PATCH v3 2/4] gpu: nova-core: gsp: fix length of received messages
In reply to Alexandre CourbotHi Alex,
Quoted 35 lines · Alexandre Courbot
The size of messages' payload is miscalculated, leading to extra data passed to the message handler. While this is not a problem with our current set of commands, others with a variable-length payload may misbehave. Fix this by introducing a method returning the payload size and using it.
Fixes 75f6b1de8133 ("gpu: nova-core: gsp: Add GSP command queue bindings and handling")Reviewed-by Lyude Paul <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>---
drivers/gpu/nova-core/gsp/cmdq.rs| 10 ++++++----drivers/gpu/nova-core/gsp/fw.rs| 13 +++++++++----2 files changed, 15 insertions(+), 8 deletions(-)drivers/gpu/nova-core/gsp/cmdq.rs +4
-2@@ -588,21 +588,23 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> { header.length(), ); +let payload_length = header.payload_length (); +// Check that the driver read area is large enough for the message. -if slice_1.len () + slice_2.len () < header.length () { +if slice_1.len () + slice_2.len () < payload_length {return Err (EIO ); }// Cut the message slices down to the actual length of the message. -let (slice_1, slice_2) =if slice_1.len () > header.length () { +let (slice_1, slice_2) =if slice_1.len () > payload_length {
drivers/gpu/nova-core/gsp/cmdq.rs fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> { · line 607
Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +2
-2// PANIC: we checked above that `slice_1` is at least as long as `msg_header.length()`. - (slice_1.split_at (header.length ()).0 , &slice_2[0 ..0 ]) + (slice_1.split_at (payload_length).0 , &slice_2[0 ..0 ]) }else { ( slice_1,// PANIC: we checked above that `slice_1.len() + slice_2.len()` is at least as // large as `msg_header.length()`. - slice_2.split_at(header.length() - slice_1.len()).0, + slice_2.split_at(payload_length - slice_1.len()).0,
The panic comments also need updating?
Other than the nit,
thanks,
- Joel
Quoted 32 lines
drivers/gpu/nova-core/gsp/cmdq.rs +0
-0) };drivers/gpu/nova-core/gsp/fw.rs +9
-5@@ -853,11 +853,16 @@ pub(crate) fn set_checksum(&mut self, checksum: u32) { self.inner.checkSum = checksum; } -/// Returns the total length of the message. +/// Returns the length of the message's payload. +pub (crate )fn payload_length (&self) ->usize { +// `rpc.length` includes the length of the RPC message header. + num::u32_as_usize (self.inner.rpc.length) + .saturating_sub (size_of ::<bindings::rpc_message_header_v >()) + } + +/// Returns the total length of the message, message and RPC headers included. pub (crate )fn length (&self) ->usize { -// `rpc.length` includes the length of the GspRpcHeader but not the message header. -size_of ::<Self >() -size_of ::<bindings::rpc_message_header_v >() - + num::u32_as_usize (self.inner.rpc.length) +size_of ::<Self >() + self.payload_length () }// Returns the sequence number of the message. --2.52.0
Alexandre Courbot
maintainerRe: [PATCH v3 2/4] gpu: nova-core: gsp: fix length of received messages
Quoted 34 lines · Joel Fernandes
Hi Alex,
Quoted 32 lines · Alexandre Courbot
The size of messages' payload is miscalculated, leading to extra data passed to the message handler. While this is not a problem with our current set of commands, others with a variable-length payload may misbehave. Fix this by introducing a method returning the payload size and using it.
Fixes 75f6b1de8133 ("gpu: nova-core: gsp: Add GSP command queue bindings and handling")Reviewed-by Lyude Paul <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>---
drivers/gpu/nova-core/gsp/cmdq.rs| 10 ++++++----drivers/gpu/nova-core/gsp/fw.rs| 13 +++++++++----2 files changed, 15 insertions(+), 8 deletions(-)drivers/gpu/nova-core/gsp/cmdq.rs +3
-1@@ -588,21 +588,23 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> { header.length(), ); +let payload_length = header.payload_length (); +// Check that the driver read area is large enough for the message. -if slice_1.len () + slice_2.len () < header.length () { +if slice_1.len () + slice_2.len () < payload_length {return Err (EIO ); }
Quoted 15 lines
drivers/gpu/nova-core/gsp/cmdq.rs fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> { · line 607
Quoted 13 lines
drivers/gpu/nova-core/gsp/cmdq.rs +3
-3// Cut the message slices down to the actual length of the message. -let (slice_1, slice_2) =if slice_1.len () > header.length () { +let (slice_1, slice_2) =if slice_1.len () > payload_length {// PANIC: we checked above that `slice_1` is at least as long as `msg_header.length()`. - (slice_1.split_at (header.length ()).0 , &slice_2[0 ..0 ]) + (slice_1.split_at (payload_length).0 , &slice_2[0 ..0 ]) }else { ( slice_1,// PANIC: we checked above that `slice_1.len() + slice_2.len()` is at least as // large as `msg_header.length()`. - slice_2.split_at(header.length() - slice_1.len()).0, + slice_2.split_at(payload_length - slice_1.len()).0,The panic comments also need updating?
Oh, they do - nice catch, thanks!
Alexandre Courbot
maintainerPATCH v3 3/4 gpu: nova-core: bindings: derive `MaybeZeroable`
In reply to Alexandre CourbotCommit 4846300ba8f9 ("rust: derive Zeroable for all structs & unions generated by bindgen where possible") automatically derives MaybeZeroable for all bindings. This is better than selectively deriving Zeroable as it ensures all types that can implement Zeroable do.
Regenerate the nova-core bindings so they benefit from this, and remove a now unneeded implementation of Zeroable.
--- drivers/gpu/nova-core/gsp/fw.rs | 7 -- drivers/gpu/nova-core/gsp/fw/r570_144.rs | 11 ++- drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 93 ++++++++++++----------- 3 files changed, 54 insertions(+), 57 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +0 -7
@@ -797,13 +797,6 @@ fn init(cmd_size: usize, function: MsgFunction) -> impl Init<Self, Error> { } } -// SAFETY: We can't derive the Zeroable trait for this binding because the -// procedural macro doesn't support the syntax used by bindgen to create the -// __IncompleteArrayField types. So instead we implement it here, which is safe -// because these are explicitly padded structures only containing types for -// which any bit pattern, including all zeros, is valid. -unsafe impl Zeroable for bindings::rpc_message_header_v {} -/// GSP Message Element. /// /// This is essentially a message header expected to be followed by the message data.
drivers/gpu/nova-core/gsp/fw/r570_144.rs +7 -4
@@ -24,8 +24,11 @@ unreachable_pub, unsafe_op_in_unsafe_fn )] -use kernel::{ - ffi, - prelude::Zeroable ,// -}; +use kernel::ffi; +use pin_init::MaybeZeroable ; +include! ("r570_144/bindings.rs" ); + +// SAFETY: This type has a size of zero, so its inclusion into another type should not affect their +// ability to implement `Zeroable`. +unsafe impl <T > kernel::prelude::Zeroable for __IncompleteArrayField <T > {}
drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +47 -46
360 lines not on this page · raw message
Signature · 1 line
2.52.0
Alexandre Courbot
maintainerPATCH v3 4/4 gpu: nova-core: gsp: replace firmware version with "bindings" alias
In reply to Alexandre CourbotWe have an "bindings" alias to avoid having to mention the firmware version again and again, and limit the diff when upgrading the firmware. Use it where we neglected to.
--- drivers/gpu/nova-core/gsp/fw.rs | 58 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +29 -29
@@ -141,8 +141,8 @@ unsafe impl AsBytes for GspFwWprMeta {}// are valid. unsafe impl FromBytes for GspFwWprMeta {} -type GspFwWprMetaBootResumeInfo = r570_144::GspFwWprMeta__bindgen_ty_1 ; -type GspFwWprMetaBootInfo = r570_144::GspFwWprMeta__bindgen_ty_1__bindgen_ty_1 ; +type GspFwWprMetaBootResumeInfo = bindings::GspFwWprMeta__bindgen_ty_1 ; +type GspFwWprMetaBootInfo = bindings::GspFwWprMeta__bindgen_ty_1__bindgen_ty_1 ;impl GspFwWprMeta {/// Fill in and return a `GspFwWprMeta` suitable for booting `gsp_firmware` using the
@@ -150,8 +150,8 @@ impl GspFwWprMeta {pub (crate )fn new (gsp_firmware: &GspFirmware , fb_layout: &FbLayout ) ->Self {Self (bindings::GspFwWprMeta {// CAST: we want to store the bits of `GSP_FW_WPR_META_MAGIC` unmodified. - magic: r570_144::GSP_FW_WPR_META_MAGIC as u64 , - revision: u64::from (r570_144::GSP_FW_WPR_META_REVISION ), + magic: bindings::GSP_FW_WPR_META_MAGIC as u64 , + revision: u64::from (bindings::GSP_FW_WPR_META_REVISION ), sysmemAddrOfRadix3Elf: gsp_firmware.radix3_dma_handle (), sizeOfRadix3Elf: u64::from_safe_cast (gsp_firmware.size), sysmemAddrOfBootloader: gsp_firmware.bootloader.ucode.dma_handle (),
@@ -315,19 +315,19 @@ fn from(value: MsgFunction) -> Self {#[repr( u32 )] pub (crate )enum SeqBufOpcode {// Core operation opcodes -CoreReset = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESET , -CoreResume = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESUME , -CoreStart = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_START , -CoreWaitForHalt = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_WAIT_FOR_HALT , +CoreReset = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESET , +CoreResume = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESUME , +CoreStart = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_START , +CoreWaitForHalt = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_WAIT_FOR_HALT ,// Delay opcode -DelayUs = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_DELAY_US , +DelayUs = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_DELAY_US ,// Register operation opcodes -RegModify = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_MODIFY , -RegPoll = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_POLL , -RegStore = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_STORE , -RegWrite = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_WRITE , +RegModify = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_MODIFY , +RegPoll = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_POLL , +RegStore = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_STORE , +RegWrite = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_WRITE , }impl fmt::Display for SeqBufOpcode {
@@ -351,25 +351,25 @@ impl TryFrom<u32> for SeqBufOpcode {fn try_from (value:u32 ) ->Result <SeqBufOpcode > {match value { - r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESET => { + bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESET => {Ok (SeqBufOpcode ::CoreReset ) } - r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESUME => { + bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESUME => {Ok (SeqBufOpcode ::CoreResume ) } - r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_START => { + bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_START => {Ok (SeqBufOpcode ::CoreStart ) } - r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_WAIT_FOR_HALT => { + bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_WAIT_FOR_HALT => {Ok (SeqBufOpcode ::CoreWaitForHalt ) } - r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_DELAY_US =>Ok (SeqBufOpcode ::DelayUs ), - r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_MODIFY => { + bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_DELAY_US =>Ok (SeqBufOpcode ::DelayUs ), + bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_MODIFY => {Ok (SeqBufOpcode ::RegModify ) } - r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_POLL =>Ok (SeqBufOpcode ::RegPoll ), - r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_STORE =>Ok (SeqBufOpcode ::RegStore ), - r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_WRITE =>Ok (SeqBufOpcode ::RegWrite ), + bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_POLL =>Ok (SeqBufOpcode ::RegPoll ), + bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_STORE =>Ok (SeqBufOpcode ::RegStore ), + bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_WRITE =>Ok (SeqBufOpcode ::RegWrite ), _ =>Err (EINVAL ), } }
@@ -385,7 +385,7 @@ fn from(value: SeqBufOpcode) -> Self {/// Wrapper for GSP sequencer register write payload. #[repr(transparent)] #[derive( Copy , Clone )] -pub (crate )struct RegWritePayload (r570_144::GSP_SEQ_BUF_PAYLOAD_REG_WRITE ); +pub (crate )struct RegWritePayload (bindings::GSP_SEQ_BUF_PAYLOAD_REG_WRITE );impl RegWritePayload {/// Returns the register address.
@@ -408,7 +408,7 @@ unsafe impl AsBytes for RegWritePayload {}/// Wrapper for GSP sequencer register modify payload. #[repr(transparent)] #[derive( Copy , Clone )] -pub (crate )struct RegModifyPayload (r570_144::GSP_SEQ_BUF_PAYLOAD_REG_MODIFY ); +pub (crate )struct RegModifyPayload (bindings::GSP_SEQ_BUF_PAYLOAD_REG_MODIFY );impl RegModifyPayload {/// Returns the register address.
@@ -436,7 +436,7 @@ unsafe impl AsBytes for RegModifyPayload {}/// Wrapper for GSP sequencer register poll payload. #[repr(transparent)] #[derive( Copy , Clone )] -pub (crate )struct RegPollPayload (r570_144::GSP_SEQ_BUF_PAYLOAD_REG_POLL ); +pub (crate )struct RegPollPayload (bindings::GSP_SEQ_BUF_PAYLOAD_REG_POLL );impl RegPollPayload {/// Returns the register address.
@@ -469,7 +469,7 @@ unsafe impl AsBytes for RegPollPayload {}/// Wrapper for GSP sequencer delay payload. #[repr(transparent)] #[derive( Copy , Clone )] -pub (crate )struct DelayUsPayload (r570_144::GSP_SEQ_BUF_PAYLOAD_DELAY_US ); +pub (crate )struct DelayUsPayload (bindings::GSP_SEQ_BUF_PAYLOAD_DELAY_US );impl DelayUsPayload {/// Returns the delay value in microseconds.
@@ -487,7 +487,7 @@ unsafe impl AsBytes for DelayUsPayload {}/// Wrapper for GSP sequencer register store payload. #[repr(transparent)] #[derive( Copy , Clone )] -pub (crate )struct RegStorePayload (r570_144::GSP_SEQ_BUF_PAYLOAD_REG_STORE ); +pub (crate )struct RegStorePayload (bindings::GSP_SEQ_BUF_PAYLOAD_REG_STORE );impl RegStorePayload {/// Returns the register address.
@@ -510,7 +510,7 @@ unsafe impl AsBytes for RegStorePayload {}/// Wrapper for GSP sequencer buffer command. #[repr(transparent)] -pub (crate )struct SequencerBufferCmd (r570_144::GSP_SEQUENCER_BUFFER_CMD ); +pub (crate )struct SequencerBufferCmd (bindings::GSP_SEQUENCER_BUFFER_CMD );impl SequencerBufferCmd {/// Returns the opcode as a `SeqBufOpcode` enum, or error if invalid.
@@ -612,7 +612,7 @@ unsafe impl AsBytes for SequencerBufferCmd {}/// Wrapper for GSP run CPU sequencer RPC. #[repr(transparent)] -pub (crate )struct RunCpuSequencer (r570_144::rpc_run_cpu_sequencer_v17_00 ); +pub (crate )struct RunCpuSequencer (bindings::rpc_run_cpu_sequencer_v17_00 );impl RunCpuSequencer {/// Returns the command index.
Signature · 1 line
2.52.0
Quoted 34 lines · Alexandre Courbot
This series contains a few fixups for the recently merged GSP command-queue code, by order of importance:
- Some explicit padding required to safely implement
AsByteswas missing in the bindings,
- A bug in the received message length calculation results in the message handler being given more data than it should,
-MaybeZeroableis now derived by the kernel's bindgen, but the Nova bindings have not been updated for that,
- Some items in the bindings were referred to using the version module directly, instead of the alias we defined to limit the diff when we upgrade firmware versions.All of them address "bugs" (with the first two fixing actual correctness issues), but since Nova does not do much anyway, they are also not absolutely critical. Other series planned for this cycle will depend on them, so one way or the other it would be great to see them in drm-rust-next.
Signed-off-by Alexandre Courbot <[email protected]>---
Changes in v3:
- Rebase on top of drm-rust-next.
- Add method to return the payload size of a message. (thanks Alistair!)
- Link to v2: https://patch.msgid.link/[email protected]Changes in v2:
- Add missing "Fixes:" tags.
- Link to v1: https://lore.kernel.org/r/[email protected]
Quoted 6 lines
---
Alexandre Courbot (4):
gpu: nova-core: bindings: add missing explicit padding
gpu: nova-core: gsp: fix length of received messages
gpu: nova-core: bindings: deriveMaybeZeroable
gpu: nova-core: gsp: replace firmware version with "bindings" alias
thanks,
- Joel
Quoted 14 lines
drivers/gpu/nova-core/gsp/cmdq.rs | 10 ++- drivers/gpu/nova-core/gsp/fw.rs | 78 ++++++++-------- drivers/gpu/nova-core/gsp/fw/r570_144.rs | 11 ++- drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 105 ++++++++++++---------- 4 files changed, 110 insertions(+), 94 deletions(-)---
base-commit:60c7398bded2e11f0db40a409a241b8be5910ee2
change-id: 20251121-nova-fixes-dc9b4f17b90eBest regards,
--
Alexandre Courbot <[email protected]>
Alexandre Courbot
maintainerQuoted 13 lines · Alexandre Courbot
This series contains a few fixups for the recently merged GSP command-queue code, by order of importance:
- Some explicit padding required to safely implement
AsByteswas missing in the bindings,
- A bug in the received message length calculation results in the message handler being given more data than it should,
-MaybeZeroableis now derived by the kernel's bindgen, but the Nova bindings have not been updated for that,
- Some items in the bindings were referred to using the version module directly, instead of the alias we defined to limit the diff when we upgrade firmware versions.
Quoted 7 lines
All of them address "bugs" (with the first two fixing actual correctness issues), but since Nova does not do much anyway, they are also not absolutely critical. Other series planned for this cycle will depend on them, so one way or the other it would be great to see them in drm-rust-next.
Signed-off-by Alexandre Courbot <[email protected]>
Pushed (with Danilo's Acked-by received on Zulip) to drm-rust-fixes, thanks!
["gpu: nova-core: gsp: fix length of received messages":
update PANIC: comments as pointed out by Joel.]