gpu: nova-core: gsp: preparatory patches for the r000 firmware
Subsystems (4)
Alexandre Courbot
maintainerv3 cover gpu: nova-core: gsp: preparatory patches for the r000 firmware
These patches come from John's series switching nova-core to the r000 GSP firmware [1]. They do not depend on the switch itself, and both the rest of the r000 work and the vGPU series build on them, so I would like to get them in soon.
Patch 1 adds the r000 queue element header. It has no user yet and was previously posted on its own [2].
Patches 2 and 3 make the static GPU configuration something the boot sequence returns, since that is where r000 provides it. Patch 4 adds the GPU short name and GID to the schema of the GSP_INIT reply, which is not used yet either.
Patches 5 to 7 prepare the log buffers code for the extra buffers of r000, without functional change.
Patches 8 to 10 tidy the command queue constants and make the msgq TX header take its values from the queue layout, without functional change.
Patch 11 moves the loading of the file referenced by a TLV into the TLV parser, so the r000 ucodes loader can use it.
Based on drm-rust-next.
[1] https://lore.kernel.org/[email protected]
[2] https://lore.kernel.org/[email protected]
---
Changes in v3:
- Move MCTP_MAGIC to an associated const. (Eliot)
- Drop unneeded #[allow(dead_code)]. (Eliot)
- Use assert instead of static_assert in const block. (Eliot)
- Use from_safe_cast instead of u32_as_usize.
- Avoid unneeded saturating add. (Eliot)
- Remove unneeded u32::from. (Eliot)
- Convert core::result::Result to just Result when moving code. (Eliot)
- Use writer to write the init arguments. (Eliot)
- Deconstruct self in is_empty. (Eliot)
- Remove unneeded map_err in the TLV code. (Eliot)
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Use an anonymous const for the queue element header checks. (Gary)
- Import offset_of for the queue element header checks. (Gary)
- Derive the zerocopy traits on the queue element header. (Gary)
- Add patches 5 to 11 (log buffers, msgq TX header, TLV loading).
- Use the defined constants in more places on patch 4.
- Link to v1: https://patch.msgid.link/[email protected]
---
Alexandre Courbot (2):
gpu: nova-core: gsp: cmdq: reduce visibility of gsp-level constants
gpu: nova-core: gsp: take all the msgq layout values from Cmdq in MsgqTxHeader::new()
John Hubbard (9):
gpu: nova-core: gsp: add the r000 queue element header
gpu: nova-core: gsp: rename and move the static configuration type
gpu: nova-core: gsp: return the static GPU configuration from boot
gpu: nova-core: gsp: add the short name and GID to the GSP_INIT reply
gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments()
gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size
gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty()
gpu: nova-core: gsp: compute the msgq entry offset in MsgqTxHeader::new()
gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV
drivers/gpu/nova-core/api.rs | 8 +- drivers/gpu/nova-core/firmware/gsp.rs | 15 +- drivers/gpu/nova-core/firmware/tlv.rs | 40 ++++- drivers/gpu/nova-core/gpu.rs | 36 ++-- drivers/gpu/nova-core/gsp.rs | 70 +++++--- drivers/gpu/nova-core/gsp/boot.rs | 15 +- drivers/gpu/nova-core/gsp/cmdq.rs | 27 +-- drivers/gpu/nova-core/gsp/commands.rs | 70 ++++++++ drivers/gpu/nova-core/gsp/commands/rpc.rs | 68 +------- drivers/gpu/nova-core/gsp/fw.rs | 204 +++++++++++++++++++++-- drivers/gpu/nova-core/gsp/fw/commands.rs | 23 +-- drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs | 97 +++++++++++ drivers/gpu/nova-core/gsp/logbuffer.rs | 69 ++++++-- drivers/gpu/nova-core/mctp.rs | 27 ++- 14 files changed, 585 insertions(+), 184 deletions(-)
---
base-commit: abfb640b2374e26de8ff81d488c39d8254db538e
change-id: 20261127-nova-r000-staging-905c7f559e47
Best regards,
Signature · 1 line
Alexandre Courbot <[email protected]>
Alexandre Courbot
maintainerPATCH v3 1/11 gpu: nova-core: gsp: add the r000 queue element header
From: John Hubbard <[email protected]>
The upcoming r000 firmware uses a new queue element header that includes MCTP and NVDM headers describing the type of message (RPC or GMC) that follows.
Add that header as the QueueElementHeader type, along with the two NVDM types that the GSP queues use and the MCTP version and NVDM vendor checks that validating it requires.
The type is written out field by field rather than wrapped around the generated binding, as GSP_MSG_QUEUE_ELEMENT keeps a 16-byte encryption tag, only used with confidential computing, in a union with its last two fields, making the binding 16 bytes larger than what the GSP expects on the queues. Static assertions check every field offset and the size of the type against the binding.
The header has no user yet: it replaces GspMsgElement at the transport level in a later patch that switches to the r000 firmware, and is built as dead code until then.
--- drivers/gpu/nova-core/gsp/fw.rs | 177 ++++++++++++++++++++++- drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs | 97 +++++++++++++ drivers/gpu/nova-core/mctp.rs | 27 +++- 3 files changed, 298 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +176 -1
@@ -33,6 +33,11 @@ }, }; +use zerocopy_derive::{ +Immutable , +KnownLayout ,// +}; +use crate ::{ bounded_enum, fb::{
@@ -48,6 +53,11 @@ cmdq::Cmdq, // GSP_PAGE_SIZE, }, + mctp::{ + MctpHeader, + NvdmHeader, + NvdmType, // + }, num::{ self,FromSafeCast ,//
@@ -835,7 +845,7 @@ pub(crate) fn msg_length(&self) -> usize {size_of ::<Self >() + self.rpc_header ().rpc_length () } -/// Returns the number of elements (i.e. memory pages) used by this message. +/// Returns the number of slots (i.e. memory pages) used by this message. pub (crate )fn element_count (&self) ->u32 { self.inner.elemCount }
@@ -901,6 +911,171 @@ pub(crate) fn function(&self) -> Result<MsgFunction, u32> { } } +/// Header opening every element of the r000 GSP queues. +/// +/// A queue element is laid out as follows: +/// +/// ```text +/// +------------------------------------+ +/// | Queue element header | QueueElementHeader: MCTP magic, element length, +/// | | MCTP header, NVDM header, message length. +/// +------------------------------------+ +/// | Message header | RPC header or GMC API header. The NVDM type +/// | | selects between the two. +/// +------------------------------------+ +/// | Payload | Message-specific data. +/// +------------------------------------+ +/// ``` +/// +/// This is the `noEncryption` layout of the `GSP_MSG_QUEUE_ELEMENT` binding. That binding keeps +/// a 16-byte encryption tag, used only with confidential computing, in a union with the two +/// trailing fields of the queue element header, so wrapping the binding would make every element +/// 16 bytes larger than what the GSP expects. The fields are therefore declared again here, with +/// their offsets checked against the binding. +#[repr( C )] +#[derive( FromBytes , IntoBytes , Immutable , KnownLayout )] +pub (crate )struct QueueElementHeader { +/// Always [`Self::MCTP_MAGIC`]. + mctp_magic:u32 , +/// Length in bytes of the whole element, this header included. +/// +/// Under confidential computing the GSP pads elements out to whole queue slots, so this can +/// be larger than `nvdm_payload_size` plus the size of this header, but never smaller. + mctp_payload_size:u32 , +/// MCTP transport header of the element. + mctp_header:MctpHeader , +/// NVDM header of the message. + nvdm_header:NvdmHeader , +/// Length in bytes of the message following this header: the message header and its +/// payload. + nvdm_payload_size:u32 , + reserved:u32 , +} + +// Static validation of `QueueElementHeader` against its bindings type. +const _: () = { +use core::mem::offset_of; + +// Offsets of `QueueElementHeader`'s fields + +assert! ( +offset_of! (QueueElementHeader , mctp_magic) + ==offset_of! (r000_00::GSP_MSG_QUEUE_ELEMENT , mctpMagic) + ); +assert! ( +offset_of! (QueueElementHeader , mctp_payload_size) + ==offset_of! (r000_00::GSP_MSG_QUEUE_ELEMENT , mctpPayloadSize) + ); +assert! ( +offset_of! (QueueElementHeader , mctp_header) + ==offset_of! (r000_00::GSP_MSG_QUEUE_ELEMENT , mctpHeader) + ); +assert! ( +offset_of! (QueueElementHeader , nvdm_header) + ==offset_of! (r000_00::GSP_MSG_QUEUE_ELEMENT , nvdmHeader) + ); + +/// The `noEncryption` member of the union of `GSP_MSG_QUEUE_ELEMENT`, which holds the two +/// trailing fields of [`QueueElementHeader`]. +type QueueElementNoEncryption = r000_00::GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2 ; + +// Offsets of fields under [`QueueElementNoEncryption`] within `GSP_MSG_QUEUE_ELEMENT`. + +const QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET :usize = +offset_of! (r000_00::GSP_MSG_QUEUE_ELEMENT , __bindgen_anon_1) + +offset_of! (r000_00::GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1 , noEncryption); + +assert! ( +offset_of! (QueueElementHeader , nvdm_payload_size) + ==QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + +offset_of! (QueueElementNoEncryption , nvdmPayloadSize) + ); +assert! ( +offset_of! (QueueElementHeader , reserved) + ==QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET +offset_of! (QueueElementNoEncryption , reserved) + ); + +// Ensure the size of `QueueElementHeader` matches the `noEncryption` layout. + +assert! ( +size_of ::<QueueElementHeader >() + ==QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET +size_of ::<QueueElementNoEncryption >() + ); +}; + +#[expect(dead_code)] +impl QueueElementHeader { +/// First word of every r000 queue element: `"MCTP"` in ASCII. +const MCTP_MAGIC :u32 =0x4D43_5450 ; + +/// Creates the queue element header of an element carrying a message of NVDM type `nvdm_type` +/// and `message_len` bytes, message header included. +/// +/// # Errors +/// +/// - `EOVERFLOW` if a length does not fit its 32-bit field. +pub (crate )fn init (nvdm_type:NvdmType , message_len:usize ) ->impl Init <Self ,Error > { +try_init! (QueueElementHeader { + mctp_magic:Self ::MCTP_MAGIC , + mctp_payload_size:size_of ::<Self >() + .checked_add (message_len) + .ok_or (EOVERFLOW )? + .try_into () + .map_err (|_|EOVERFLOW )?, + mctp_header:MctpHeader ::single_packet (), + nvdm_header:NvdmHeader ::new (nvdm_type), + nvdm_payload_size: message_len.try_into ().map_err (|_|EOVERFLOW )?, + reserved:0 , + }) + } + +/// Returns the length of the whole element, this header included. +pub (crate )fn element_len (&self) ->usize { + usize::from_safe_cast (self.mctp_payload_size) + } + +/// Returns the length of the message following this header, message header included. +pub (crate )fn message_len (&self) ->usize { + usize::from_safe_cast (self.nvdm_payload_size) + } + +/// Returns the number of slots (i.e. memory pages) used by this element. +pub (crate )fn element_count (&self) ->u32 { + self.mctp_payload_size.div_ceil (cv! (GSP_PAGE_SIZE )) + } + +/// Returns the NVDM type of the message following this header, or `EINVAL` if it is not a +/// known one. +pub (crate )fn nvdm_type (&self) ->Result <NvdmType > { + self.nvdm_header.nvdm_type () + } + +/// Validates the framing of the element. +/// +/// # Errors +/// +/// - `EIO` if the magic, the MCTP version or the NVDM vendor is wrong, or if the element +/// length is smaller than this header and the message together, or larger than the +/// maximum element size. +pub (crate )fn validate (&self) ->Result { +if self.mctp_magic !=Self ::MCTP_MAGIC + || !self.mctp_header.has_expected_version () + || !self.nvdm_header.has_nvidia_vendor () + { +return Err (EIO ); + } + +let element_len = self.element_len (); +if element_len <size_of ::<Self >() + self.message_len () + || element_len >GSP_MSG_QUEUE_ELEMENT_SIZE_MAX + { +return Err (EIO ); + } + +Ok (()) + } +} +bounded_enum! {/// Commands of the GMC API. #[derive( Debug , Clone , Copy , PartialEq , Eq )]
drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs +97 -0
109 lines not on this page · raw message
drivers/gpu/nova-core/mctp.rs +25 -2
@@ -13,6 +13,11 @@ prelude::*, // }; +use zerocopy_derive::{ +Immutable , +KnownLayout ,// +}; +use crate ::{ bounded_enum, num,//
@@ -28,11 +33,16 @@ pub(crate) enum NvdmType with TryFrom<Bounded<u32, 8>> { Cot = 0x14,/// FSP command response. FspResponse = 0x15, +/// RPC message to or from GSP-RM. + RmRpc = 0x25, +/// GMC (GPU Management Controller) API message to or from GSP-RM. + GmcApi = 0x26, } }bitfield! {/// MCTP transport header for NVIDIA firmware messages. +#[derive( FromBytes , IntoBytes , Immutable , KnownLayout )] pub (crate )struct MctpHeader (u32 ) {/// Start-of-message bit. 31 :31 som;
@@ -67,6 +77,11 @@ pub(crate) fn single_packet() -> Self {pub (crate )fn is_single_packet (self) ->bool { self.som ().into_bool () && self.eom ().into_bool () } + +/// Returns `true` if this MCTP header carries the version that this driver uses. +pub (crate )fn has_expected_version (self) ->bool { + self.version () ==Self ::VERSION + } }/// MCTP message type for PCI vendor-defined messages.
@@ -74,6 +89,7 @@ pub(crate) fn is_single_packet(self) -> bool {bitfield! {/// NVIDIA Vendor-Defined Message header over MCTP. +#[derive( FromBytes , IntoBytes , Immutable , KnownLayout )] pub (crate )struct NvdmHeader (u32 ) {/// NVDM message type. 31 :24 nvdm_type ?=>NvdmType ;
@@ -93,10 +109,17 @@ pub(crate) fn new(nvdm_type: NvdmType) -> Self { .with_nvdm_type(nvdm_type) } -/// Validates this header against the expected NVIDIA NVDM format and type. -pub (crate )fn validate (self, expected_type:NvdmType ) ->bool { +/// Returns `true` if this NVDM header belongs to a PCI vendor-defined message from NVIDIA. +/// +/// The GPU firmware only ever sends such messages, so a mismatch is a sign of corruption. +pub (crate )fn has_nvidia_vendor (self) ->bool { u8::from (self.msg_type ()) ==MSG_TYPE_VENDOR_PCI && u16::from (self.vendor_id ()) ==Vendor ::NVIDIA .as_raw () + } + +/// Validates this header against the expected NVIDIA NVDM format and type. +pub (crate )fn validate (self, expected_type:NvdmType ) ->bool { + self.has_nvidia_vendor () &&matches! (self.nvdm_type (),Ok (nvdm_type)if nvdm_type == expected_type) } }
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v3 2/11 gpu: nova-core: gsp: rename and move the static configuration type
In reply to Alexandre CourbotFrom: John Hubbard <[email protected]>
With the r000 firmware, GSP-RM reports the static GPU configuration in its reply to GSP_INIT, a GMC command, and no RPC command fetches it.
The type that holds the configuration is named after the r570 RPC command that fetches it, and it is defined among the RPC commands.
In order to make the type available to a GMC reply, name it after its contents, and move it out of the RPC commands, up into the commands module.
No functional changes.
--- drivers/gpu/nova-core/api.rs | 6 +-- drivers/gpu/nova-core/gpu.rs | 4 +- drivers/gpu/nova-core/gsp.rs | 2 +- drivers/gpu/nova-core/gsp/commands.rs | 65 +++++++++++++++++++++++++++++ drivers/gpu/nova-core/gsp/commands/rpc.rs | 68 +++---------------------------- 5 files changed, 76 insertions(+), 69 deletions(-)
drivers/gpu/nova-core/api.rs +3 -3
@@ -18,7 +18,7 @@use crate ::{ driver, gpu::Gpu , - gsp::commands::rpc::GetGspStaticInfoReply ,// + gsp::commands::GspStaticInfo ,// };/// API handle for the auxiliary bus child drivers to interact with nova-core.
@@ -39,8 +39,8 @@ pub fn of(adev: &auxiliary::Device<Bound>) -> Result<NovaCoreApiHandle<'_>> {NovaCoreApiHandle ::of (adev) } -/// Returns the GPU [`GetGspStaticInfoReply`]. -pub fn gsp_static_info (&self) -> &GetGspStaticInfoReply { +/// Returns the GPU [`GspStaticInfo`]. +pub fn gsp_static_info (&self) -> &GspStaticInfo { &self.gpu.gsp_static_info }
drivers/gpu/nova-core/gpu.rs +2 -2
@@ -32,7 +32,7 @@ gsp::{ self, cmdq::Cmdq, - commands::rpc::GetGspStaticInfoReply, + commands::GspStaticInfo,Gsp ,GspBootContext ,// },
@@ -394,7 +394,7 @@ pub(crate) struct Gpu<'gpu> {#[uses('tree)] _gsp_subtree: GspSubtree<'gsp_resources>,/// Static GPU information as provided by the GSP. - pub(crate) gsp_static_info: GetGspStaticInfoReply, + pub(crate) gsp_static_info: GspStaticInfo,/// GPU memory manager owning memory management resources. /// /// Must be kept declared *before* `gsp_resources`, so that its components are dropped while
drivers/gpu/nova-core/gsp.rs +1 -1
@@ -159,7 +159,7 @@ pub(crate) fn new( }/// Query the GSP for the static GPU information. -pub (crate )fn get_static_info (&self) ->Result <commands::rpc::GetGspStaticInfoReply > { +pub (crate )fn get_static_info (&self) ->Result <commands::GspStaticInfo > { self.cmdq.send_rpc_command (commands::rpc::GetGspStaticInfo ) } }
drivers/gpu/nova-core/gsp/commands.rs +65 -0
68 lines not on this page · raw message
drivers/gpu/nova-core/gsp/commands/rpc.rs +5 -63
104 lines not on this page · raw message
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v3 3/11 gpu: nova-core: gsp: return the static GPU configuration from boot
In reply to Alexandre CourbotFrom: John Hubbard <[email protected]>
With the r000 firmware, GSP-RM reports the static GPU configuration in its reply to the GSP_INIT command that ends the boot, so the boot sequence holds the configuration when it returns.
Nova-core fetches the configuration with an RPC command after the boot, once the interrupt handler is registered. On r000, the boot sequence would have to keep the GSP_INIT reply for that later step to read.
Return the configuration from the boot sequence, together with the unload bundle, and send the RPC command at the end of the boot sequence instead.
--- drivers/gpu/nova-core/api.rs | 2 +- drivers/gpu/nova-core/gpu.rs | 36 +++++++++++++++++++----------------- drivers/gpu/nova-core/gsp.rs | 13 ++++++++----- drivers/gpu/nova-core/gsp/boot.rs | 15 +++++++++++---- 4 files changed, 39 insertions(+), 27 deletions(-)
drivers/gpu/nova-core/api.rs +1 -1
@@ -41,7 +41,7 @@ pub fn of(adev: &auxiliary::Device<Bound>) -> Result<NovaCoreApiHandle<'_>> {/// Returns the GPU [`GspStaticInfo`]. pub fn gsp_static_info (&self) -> &GspStaticInfo { - &self.gpu.gsp_static_info + self.gpu.gsp_static_info () }/// Returns the GPU [`Spec`].
drivers/gpu/nova-core/gpu.rs +19 -17
@@ -32,7 +32,6 @@ gsp::{ self, cmdq::Cmdq, - commands::GspStaticInfo,Gsp ,GspBootContext ,// },
@@ -341,8 +340,8 @@ struct GspResources<'gpu> {/// GSP runtime data. #[pin] gsp: Gsp<'gpu>, -/// GSP unload firmware bundle, if any. - unload_bundle: Option<gsp::UnloadBundle<'gpu>>, +/// The static GPU configuration and the unload bundle that the boot sequence returned. + boot_result: gsp::BootResult<'gpu>, }/// The GSP event handler's registration and the enable of its subtree at `TOP`.
@@ -393,8 +392,6 @@ pub(crate) struct Gpu<'gpu> {#[pin] #[uses('tree)] _gsp_subtree: GspSubtree<'gsp_resources>, -/// Static GPU information as provided by the GSP. - pub(crate) gsp_static_info: GspStaticInfo,/// GPU memory manager owning memory management resources. /// /// Must be kept declared *before* `gsp_resources`, so that its components are dropped while
@@ -425,7 +422,7 @@ fn drop(self: Pin<&mut Self>) {let this = self.project ();let device = *this.device;let bar = *this.bar; -let bundle = this.unload_bundle.take (); +let bundle = this.boot_result.unload_bundle.take ();let _ = this .gsp
@@ -505,7 +502,7 @@ pub(crate) fn new<'a>(// This member must be initialized last, so the `UnloadBundle` can never be dropped // from outside of the constructed `GspResources`, ensuring that the unload sequence // is properly run in case of failure. - unload_bundle: gsp.boot(GspBootContext { + boot_result: gsp.boot(GspBootContext { pdev, bar, chipset: spec.chipset,
@@ -537,9 +534,9 @@ pub(crate) fn new<'a>( gsp_resources.gsp.cmdq.drain ()?; }, - gsp_static_info: { + _: {// Obtain and display basic GPU information. - let info = gsp_resources.gsp.get_static_info()?; +let info = &gsp_resources.boot_result.static_info;match info.gpu_name () {Ok (name) =>dev_info! (dev,"GPU name: {}\n" , name),Err (e) =>dev_warn! (dev,"GPU name unavailable: {:?}\n" , e),
@@ -557,13 +554,12 @@ pub(crate) fn new<'a>( info.vram_size () / u64::SZ_1M ); } - - info },// Create GPU memory manager owning memory management resources. mm: { - let usable_vram = gsp_static_info.usable_fb_regions.first().ok_or(ENODEV)?; + let info = &gsp_resources.boot_result.static_info; +let usable_vram = info.usable_fb_regions.first ().ok_or (ENODEV )?; let buddy_params = GpuBuddyParams { base_offset: usable_vram.start, size: usable_vram.end - usable_vram.start,
@@ -574,13 +570,14 @@ pub(crate) fn new<'a>( bar, gsp_resources.spec.chipset, buddy_params, - VramAddress::from_raw(gsp_static_info.total_fb_end), + VramAddress::from_raw(info.total_fb_end), )? },// Create BAR1 user interface for CPU access to GPU virtual memory. bar_user <- { -let pdb_addr =VramAddress ::from_raw (gsp_static_info.bar1_pde_base); +let info = &gsp_resources.boot_result.static_info; +let pdb_addr =VramAddress ::from_raw (info.bar1_pde_base);let bar1_idx =crate ::driver::bar1_resource_index (pdev)?;let bar1_size = pdev.resource_len (bar1_idx)?;
@@ -594,6 +591,11 @@ pub(crate) fn new<'a>( }) } +/// Returns the static GPU configuration that GSP-RM reported at boot. +pub (crate )fn gsp_static_info (&self) -> &gsp::commands::GspStaticInfo { + &self.gsp_resources.boot_result.static_info + } +/// Waits for GFW, the GPU's boot firmware, to report completion. /// /// The driver must not program the GPU before then.
@@ -616,14 +618,14 @@ pub(crate) fn wait_gfw_boot_completion(pub (crate )fn run_selftests (self:Pin <&mut Self >, pdev: &pci::Device <device::Bound >) {let this = self.project ();let dev = pdev.as_ref (); -let regions = &this.gsp_static_info.usable_fb_regions; +let info = &this.gsp_resources.boot_result.static_info;if let Err (err) =crate ::mm::selftest::run ( dev, this.mm, - regions, + &info.usable_fb_regions, &this.bar_user, - this.gsp_static_info.bar1_pde_base, + info.bar1_pde_base, this.spec.chipset, ) {dev_err! (dev,"self-tests failed: {:?}\n" , err);
drivers/gpu/nova-core/gsp.rs +8 -5
@@ -157,12 +157,15 @@ pub(crate) fn new( })) }) } - -/// Query the GSP for the static GPU information. -pub (crate )fn get_static_info (&self) ->Result <commands::GspStaticInfo > { - self.cmdq.send_rpc_command (commands::rpc::GetGspStaticInfo ) - } }/// Opaque bundle required to unload the GSP. Created by [`Gsp::boot`], consumed by [`Gsp::unload`]. pub (crate )struct UnloadBundle <'a>(KBox <dyn hal::UnloadBundle + 'a>); + +/// The output of [`Gsp::boot`]: the static GPU configuration and the unload bundle. +pub (crate )struct BootResult <'a> { +/// The unload bundle for [`Gsp::unload`], if one could be built. +pub (crate ) unload_bundle:Option <UnloadBundle <'a>>, +/// The static GPU configuration as reported by GSP-RM. +pub (crate ) static_info: commands::GspStaticInfo , +}
drivers/gpu/nova-core/gsp/boot.rs +11 -4
@@ -27,12 +27,12 @@ impl<'gsp> super::Gsp<'gsp> {/// user-space, patching them with signatures, and building firmware-specific intricate data /// structures that the GSP will use at runtime. /// -/// Upon return, the GSP is up and running, and its unload bundle (to be given as argument to -/// [`Self::unload`]) returned. +/// Returns, with the GSP running, the static configuration that GSP-RM reported and the +/// unload bundle for [`Self::unload`]. pub (crate )fn boot ( self:Pin <&mut Self >,mut ctx:super ::GspBootContext <'_, 'gsp>, - ) ->Result <Option <super ::UnloadBundle <'gsp>>> { + ) ->Result <super ::BootResult <'gsp>> {let pdev = ctx.pdev;let chipset = ctx.chipset;let gsp_falcon = ctx.gsp_falcon;
@@ -84,7 +84,14 @@ pub(crate) fn boot(// Wait until GSP is fully initialized. commands::rpc::wait_gsp_init_done (&self.cmdq)?; -Ok (unload_guard.dismiss ().1 ) +let static_info = self + .cmdq + .send_rpc_command (commands::rpc::GetGspStaticInfo )?; + +Ok (super ::BootResult { + unload_bundle: unload_guard.dismiss ().1 , + static_info, + }) }/// Shut down the GSP and wait until it is offline.
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v3 4/11 gpu: nova-core: gsp: add the short name and GID to the GSP_INIT reply
In reply to Alexandre CourbotFrom: John Hubbard <[email protected]>
The static GPU configuration holds the short name of the GPU and the GPU identifier (GID). Nova-drm reports both to user space, and the r570 static-info reply provides both.
The r000 GSP-RM sends both in its reply to GSP_INIT, and nova-core's schema of that reply has no key for either.
Add the two keys to the schema. Move the lengths of the names and of the identifier onto the static configuration type, so that the schema and the type share them.
--- drivers/gpu/nova-core/gsp/commands.rs | 11 ++++++++--- drivers/gpu/nova-core/gsp/fw/commands.rs | 23 ++++++++++++----------- 2 files changed, 20 insertions(+), 14 deletions(-)
drivers/gpu/nova-core/gsp/commands.rs +8 -3
@@ -14,10 +14,10 @@/// The static GPU configuration, which GSP-RM reports in reply to /// [`GetGspStaticInfo`](rpc::GetGspStaticInfo). pub struct GspStaticInfo { - gpu_name: [u8 ;64 ], - gpu_short_name: [u8 ;64 ], + gpu_name: [u8 ;Self ::MAX_GPU_NAME_LEN ], + gpu_short_name: [u8 ;Self ::MAX_GPU_NAME_LEN ],/// The 16-byte SHA-1 based GPU identifier (GID) reported by GSP-RM. -pub gpu_gid: [u8 ;16 ], +pub gpu_gid: [u8 ;Self ::GID_LEN ],/// BAR1 Page Directory Entry base address. pub (crate ) bar1_pde_base:u64 ,/// Usable FB (VRAM) regions for driver memory allocation.
@@ -37,6 +37,11 @@ pub enum GpuNameError { }impl GspStaticInfo { +/// Length of the buffers holding the GPU names, NUL terminator included. +pub (crate )const MAX_GPU_NAME_LEN :usize =64 ; +/// Length of the GPU identifier. +pub (crate )const GID_LEN :usize =16 ; +/// Returns the name of the GPU as a string. /// /// Returns an error if the string given by the GSP does not contain a null terminator or
drivers/gpu/nova-core/gsp/fw/commands.rs +12 -11
@@ -18,6 +18,7 @@use crate ::{ gpu::Chipset , gsp::{ + commands::GspStaticInfo , nvkv::{ nvkv_decode, nvkv_encode,
@@ -176,12 +177,12 @@ unsafe impl FromBytes for PackedRegistryTable {}impl GspStaticConfigInfo {/// Returns a bytes array containing the (hopefully) zero-terminated name of this GPU. -pub (crate )fn gpu_name_str (&self) -> [u8 ;64 ] { +pub (crate )fn gpu_name_str (&self) -> [u8 ;GspStaticInfo ::MAX_GPU_NAME_LEN ] { self.0 .gpuNameString }/// Returns a bytes array containing the (hopefully) zero-terminated short name of this GPU. -pub (crate )fn gpu_short_name_str (&self) -> [u8 ;64 ] { +pub (crate )fn gpu_short_name_str (&self) -> [u8 ;GspStaticInfo ::MAX_GPU_NAME_LEN ] { self.0 .gpuShortNameString }
@@ -189,9 +190,9 @@ impl GspStaticConfigInfo {/// /// GSP-RM reports the GID in binary SHA-1 form, which occupies the first 16 bytes of the /// GID info payload. -pub (crate )fn gpu_gid (&self) -> [u8 ;16 ] { -let mut gid = [0u8 ;16 ]; - gid.copy_from_slice (&self.0 .gidInfo.data[..16 ]); +pub (crate )fn gpu_gid (&self) -> [u8 ;GspStaticInfo ::GID_LEN ] { +let mut gid = [0u8 ;GspStaticInfo ::GID_LEN ]; + gid.copy_from_slice (&self.0 .gidInfo.data[..GspStaticInfo ::GID_LEN ]); gid }
@@ -386,7 +387,9 @@ struct GspInitRequest {// https://github.com/rust-lang/rust/pull/154377 #[allow(dead_code)] struct GspInitResponseSchema => GspInitResponse { - gpu_name:TruncatingArray <u8 , {GspInitResponse ::MAX_GPU_NAME_LEN },0x2000 >, + gpu_name:TruncatingArray <u8 , {GspStaticInfo ::MAX_GPU_NAME_LEN },0x2000 >, + gpu_short_name:TruncatingArray <u8 , {GspStaticInfo ::MAX_GPU_NAME_LEN },0x2001 >, + gpu_gid:TruncatingArray <u8 , {GspStaticInfo ::GID_LEN },0x2002 >, fb_regions:Accumulated <FbRegionSchema >, bar1_pde_base:Required <Key <u64 ,0x1020 >>, vmmu_segment_size:Key <u64 ,0x1050 >,
@@ -398,16 +401,14 @@ struct GspInitResponseSchema => GspInitResponse {// https://github.com/rust-lang/rust/pull/154377 #[allow(dead_code)] struct GspInitResponse { - gpu_name:ArrayVec <u8 , {Self ::MAX_GPU_NAME_LEN }>, + gpu_name:ArrayVec <u8 , {GspStaticInfo ::MAX_GPU_NAME_LEN }>, + gpu_short_name:ArrayVec <u8 , {GspStaticInfo ::MAX_GPU_NAME_LEN }>, + gpu_gid:ArrayVec <u8 , {GspStaticInfo ::GID_LEN }>, fb_regions:KVVec <FbRegion >, bar1_pde_base:u64 , vmmu_segment_size:u64 , } -impl GspInitResponse { -const MAX_GPU_NAME_LEN :usize =64 ; -} -nvkv_decode! {/// Schema for one FB region of the `GSP_INIT` response. struct FbRegionSchema =>FbRegion {
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v3 5/11 gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments()
In reply to Alexandre CourbotFrom: John Hubbard <[email protected]>
Gsp::new() names each log buffer in the init argument array itself, which requires the buffers to be visible outside of their module.
Move that code into LogBuffers::init_arguments(), using a new LibosInitArgs writer type to fill the arguments while transparently keeping track of the current position.
No functional change.
--- drivers/gpu/nova-core/gsp.rs | 57 +++++++++++++++++++++------------- drivers/gpu/nova-core/gsp/logbuffer.rs | 21 +++++++++++-- 2 files changed, 54 insertions(+), 24 deletions(-)
drivers/gpu/nova-core/gsp.rs +36 -21
@@ -98,6 +98,38 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> { } } +/// Writer for the `LibosMemoryRegionInitArgument` array passed to the GSP bootloader. +struct LibosInitArgs <'a> { + buf:CoherentBox <'a, [LibosMemoryRegionInitArgument ]>, + len:usize , +} + +impl <'a>LibosInitArgs <'a> { +/// Allocates a zeroed `LibosMemoryRegionInitArgument` array for `dev`. +fn new (dev: &'a device::Device <device::Bound >) ->Result <Self > { +Ok (Self { + buf:CoherentBox ::zeroed_slice ( + dev, +GSP_PAGE_SIZE /size_of ::<LibosMemoryRegionInitArgument >(), +GFP_KERNEL , + )?, + len:0 , + }) + } + +/// Appends an entry to the array. +fn push (&mut self, arg:impl Init <LibosMemoryRegionInitArgument >) ->Result { + self.buf.init_at (self.len, arg)?; + self.len +=1 ; +Ok (()) + } + +/// Consumes the writer and returns the underlying coherent DMA allocation. +fn finish (self) ->Coherent <'a, [LibosMemoryRegionInitArgument ]> { + self.buf.into () + } +} +/// GSP runtime data. #[pin_data] pub (crate )struct Gsp <'gsp> {
@@ -131,27 +163,10 @@ pub(crate) fn new( cmdq <- Cmdq::new(dev, bar), rmargs: Coherent::init(dev, GFP_KERNEL, GspArgumentsPadded::new(&cmdq))?, libos: { - let mut libos = CoherentBox::zeroed_slice( - dev, -GSP_PAGE_SIZE /size_of ::<LibosMemoryRegionInitArgument >(), -GFP_KERNEL , - )?; - - libos.init_at ( -0 , -LibosMemoryRegionInitArgument ::new ("LOGINIT" , &log_buffers.loginit.0 ), - )?; - libos.init_at ( -1 , -LibosMemoryRegionInitArgument ::new ("LOGINTR" , &log_buffers.logintr.0 ), - )?; - libos.init_at ( -2 , -LibosMemoryRegionInitArgument ::new ("LOGRM" , &log_buffers.logrm.0 ), - )?; - libos.init_at (3 ,LibosMemoryRegionInitArgument ::new ("RMARGS" , rmargs))?; - - libos.into () + let mut libos = LibosInitArgs::new(dev)?; + log_buffers.init_arguments (&mut libos)?; + libos.push (LibosMemoryRegionInitArgument ::new ("RMARGS" , rmargs))?; + libos.finish () }, logs <- log_buffers.into_debugfs_scope(), }))
drivers/gpu/nova-core/gsp/logbuffer.rs +18 -3
@@ -20,6 +20,8 @@use crate ::{ gsp::{ +LibosInitArgs , +LibosMemoryRegionInitArgument ,PteArray ,GSP_PAGE_SIZE ,// },
@@ -90,11 +92,11 @@ pub(super) struct LogBuffers<'a> {/// Device the buffers belong to. dev: &'a device::Device<device::Bound>,/// Init log buffer. - pub(super) loginit: LogBuffer<'a>, + loginit: LogBuffer<'a>,/// Interrupts log buffer. - pub(super) logintr: LogBuffer<'a>, + logintr: LogBuffer<'a>,/// RM log buffer. - pub(super) logrm: LogBuffer<'a>, + logrm: LogBuffer<'a>, }impl <'a>LogBuffers <'a> {
@@ -108,6 +110,19 @@ pub(super) fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> { }) } +/// Appends the log buffers to `libos`, under the names that GSP-RM looks them up by. +pub (super )fn init_arguments (&self, libos: &mut LibosInitArgs <'_>) ->Result { + libos.push (LibosMemoryRegionInitArgument ::new ( +"LOGINIT" , + &self.loginit.0 , + ))?; + libos.push (LibosMemoryRegionInitArgument ::new ( +"LOGINTR" , + &self.logintr.0 , + ))?; + libos.push (LibosMemoryRegionInitArgument ::new ("LOGRM" , &self.logrm.0 )) + } +/// Exposes the buffers in debugfs, in a directory named after their device. pub (super )fn into_debugfs_scope (self) ->impl PinInit <debugfs::Scope <Self >> + 'a {let dev = self.dev;
Signature · 1 line
2.56.1
Re: [PATCH v3 05/11] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments()
Quoted 9 lines · Alexandre Courbot
From: John Hubbard <[email protected]>
Gsp::new()names each log buffer in the init argument array itself, which requires the buffers to be visible outside of their module.Move that code into
LogBuffers::init_arguments(), using a newLibosInitArgswriter type to fill the arguments while transparently keeping track of the current position.
Quoted 6 lines
No functional change.
Signed-off-by John Hubbard <[email protected]>Co-developed-by Alexandre Courbot <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>---
Alexandre Courbot
maintainerPATCH v3 6/11 gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size
In reply to Alexandre CourbotFrom: John Hubbard <[email protected]>
The r000 firmware has more log buffers than r570, of two sizes.
Make LogBuffer generic over its number of pages. An array length cannot be computed from a const parameter, so the buffer becomes an array of pages instead of an array of bytes, and a snapshot is copied page by page.
No functional change.
--- drivers/gpu/nova-core/gsp/logbuffer.rs | 38 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-)
drivers/gpu/nova-core/gsp/logbuffer.rs +24 -14
@@ -30,7 +30,6 @@/// Number of GSP pages to use in a RM log buffer. const RM_LOG_BUFFER_NUM_PAGES :usize =0x10 ; -const LOG_BUFFER_SIZE :usize =RM_LOG_BUFFER_NUM_PAGES *GSP_PAGE_SIZE ;/// The logging buffers are byte queues that contain encoded printf-like /// messages from GSP-RM. They need to be decoded by a special application
@@ -46,9 +45,17 @@/// then pp points to index into the buffer where the next logging entry will /// be written. Therefore, the logging data is valid if: /// 1 <= pp < sizeof(buffer)/sizeof(u64) -pub (super )struct LogBuffer <'a>(pub (super )Coherent <'a, [u8 ;LOG_BUFFER_SIZE ]>); +pub (super )struct LogBuffer <'a,const NUM_PAGES :usize >( +pub (super )Coherent <'a, [[u8 ;GSP_PAGE_SIZE ];NUM_PAGES ]>, +); -impl <'a>LogBuffer <'a> { +/// A log buffer at the default size, [`RM_LOG_BUFFER_NUM_PAGES`] pages. +/// +/// Matches the registry defaults for the init, interrupt and RM tasks +/// (`NV_REG_STR_RM_GSP_LOG_BUFFER_SIZE_TASK_*_DEFAULT`). +type TaskLogBuffer <'a> =LogBuffer <'a,RM_LOG_BUFFER_NUM_PAGES >; + +impl <'a,const NUM_PAGES :usize >LogBuffer <'a,NUM_PAGES > {/// Creates a new `LogBuffer` mapped on `dev`. fn new (dev: &'a device::Device <device::Bound >) ->Result <Self > {let obj =Self (Coherent ::zeroed (dev,GFP_KERNEL )?);
@@ -57,9 +64,9 @@ fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {let pte_view =io_project! ( obj.0 , - [build:size_of ::<u64 >()..][build: ..RM_LOG_BUFFER_NUM_PAGES *size_of ::<u64 >()] + [build:0 ][build:size_of ::<u64 >()..][build: ..NUM_PAGES *size_of ::<u64 >()] ) - .try_cast ::<PteArray <RM_LOG_BUFFER_NUM_PAGES >>()?; + .try_cast ::<PteArray <NUM_PAGES >>()?;PteArray ::init (pte_view, start_addr)?;Ok (obj)
@@ -67,7 +74,7 @@ fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {/// Copies the buffer, or returns an empty vector if the GSP never wrote to it. fn snapshot (&self) ->Result <VVec <u8 >> { -let put =io_project! (self.0 , [build: ..size_of ::<u64 >()]) +let put =io_project! (self.0 , [build:0 ][build: ..size_of ::<u64 >()]) .try_cast ::<u64 >()? .read_val ();if put ==0 {
@@ -78,8 +85,11 @@ fn snapshot(&self) -> Result<VVec<u8>> {// GSP that failed to boot may still be writing. dma_mb (Read ); -let mut snapshot =VVec ::zeroed (LOG_BUFFER_SIZE ,GFP_KERNEL )?; -io_project! (self.0 , [build: ..]).copy_to_slice (&mut snapshot); +let mut snapshot =VVec ::zeroed (NUM_PAGES *GSP_PAGE_SIZE ,GFP_KERNEL )?; +for (i, page)in snapshot.chunks_exact_mut (GSP_PAGE_SIZE ).enumerate () { +// PANIC: `snapshot` holds `NUM_PAGES` pages, so `i` is below `NUM_PAGES`. +io_project! (self.0 , [panic: i][build: ..]).copy_to_slice (page); + }// The copy reads "put" again, unordered against the data, so keep the value read above. snapshot[..size_of ::<u64 >()].copy_from_slice (&put.to_ne_bytes ());
@@ -92,11 +102,11 @@ pub(super) struct LogBuffers<'a> {/// Device the buffers belong to. dev: &'a device::Device<device::Bound>,/// Init log buffer. - loginit: LogBuffer<'a>, + loginit: TaskLogBuffer<'a>,/// Interrupts log buffer. - logintr: LogBuffer<'a>, + logintr: TaskLogBuffer<'a>,/// RM log buffer. - logrm: LogBuffer<'a>, + logrm: TaskLogBuffer<'a>, }impl <'a>LogBuffers <'a> {
@@ -104,9 +114,9 @@ impl<'a> LogBuffers<'a> {pub (super )fn new (dev: &'a device::Device <device::Bound >) ->Result <Self > {Ok (Self { dev, - loginit:LogBuffer ::new (dev)?, - logintr:LogBuffer ::new (dev)?, - logrm:LogBuffer ::new (dev)?, + loginit:TaskLogBuffer ::new (dev)?, + logintr:TaskLogBuffer ::new (dev)?, + logrm:TaskLogBuffer ::new (dev)?, }) }
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v3 7/11 gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty()
In reply to Alexandre CourbotFrom: John Hubbard <[email protected]>
Move the check for retained logs that the GSP never wrote to into a helper, so that it stays in one place when buffers are added.
No functional change.
--- drivers/gpu/nova-core/gsp/logbuffer.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gsp/logbuffer.rs +15 -1
@@ -161,7 +161,7 @@ fn retain(&self) -> Result { logrm: self.logrm.snapshot()?, }; -if logs.loginit.is_empty () && logs.logintr.is_empty () && logs.logrm.is_empty () { +if logs.is_empty () {return Ok (()); }
@@ -207,6 +207,20 @@ struct RetainedLogBuffers { logrm: VVec<u8>, } +impl RetainedLogBuffers { +/// Returns `true` if the GSP never wrote to any of the buffers. +fn is_empty (&self) ->bool { +let Self { + name: _, + loginit, + logintr, + logrm, + } = self; + + loginit.is_empty () && logintr.is_empty () && logrm.is_empty () + } +} +/// Copies of the log buffers of all GPUs that are no longer bound. pub (crate )struct RetainedLogs (KVec <Pin <KBox <debugfs::Scope <RetainedLogBuffers >>>>);
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v3 8/11 gpu: nova-core: gsp: cmdq: reduce visibility of gsp-level constants
In reply to Alexandre CourbotThese constants are defined for sibling modules, not the whole crate.
No functional change.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/gsp/cmdq.rs +4 -4
@@ -84,7 +84,7 @@ trait CommandElement { }/// Number of GSP pages making the [`Msgq`]. -pub (crate )const MSGQ_NUM_PAGES :u32 =64 ; +pub (super )const MSGQ_NUM_PAGES :u32 =64 ;// The queue pointers are wrapping `u32` counters, and the slot is // `counter % MSGQ_NUM_PAGES`. For slots to remain contiguous when a counter
@@ -474,17 +474,17 @@ impl<'cmdq> Cmdq<'cmdq> {const POST_PTE_OFFSET :usize = core::mem::offset_of!(GspMem , cpuq);/// Offset of command queue ring buffer. -pub (crate )const CMDQ_OFFSET :usize = core::mem::offset_of!(GspMem , cpuq) +pub (super )const CMDQ_OFFSET :usize = core::mem::offset_of!(GspMem , cpuq) + core::mem::offset_of!(Msgq , msgq) -Self ::POST_PTE_OFFSET ;/// Offset of message queue ring buffer. -pub (crate )const STATQ_OFFSET :usize = core::mem::offset_of!(GspMem , gspq) +pub (super )const STATQ_OFFSET :usize = core::mem::offset_of!(GspMem , gspq) + core::mem::offset_of!(Msgq , msgq) -Self ::POST_PTE_OFFSET ;/// Number of page table entries for the GSP shared region. -pub (crate )const NUM_PTES :usize =size_of ::<GspMem >() >>GSP_PAGE_SHIFT ; +pub (super )const NUM_PTES :usize =size_of ::<GspMem >() >>GSP_PAGE_SHIFT ;/// Default timeout for receiving a message from the GSP. pub (super )const RECEIVE_TIMEOUT :Delta =Delta ::from_secs (5 );
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v3 9/11 gpu: nova-core: gsp: compute the msgq entry offset in MsgqTxHeader::new()
In reply to Alexandre CourbotFrom: John Hubbard <[email protected]>
The entry offset is a property of the queue layout. Take it from the layout of Msgq.
No functional change as both values are GSP_PAGE_SIZE.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 6 ++++++ drivers/gpu/nova-core/gsp/fw.rs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/gsp/cmdq.rs +6 -0
@@ -473,6 +473,12 @@ impl<'cmdq> Cmdq<'cmdq> {/// Offset of the data after the PTEs. const POST_PTE_OFFSET :usize = core::mem::offset_of!(GspMem , cpuq); +/// Size of a queue slot. An element spans one or more slots. +pub (super )const MSG_SIZE :usize =GSP_PAGE_SIZE ; + +/// Offset of the ring buffer of a queue from its TX header. +pub (super )const MSGQ_ENTRY_OFFSET :usize = core::mem::offset_of!(Msgq , msgq); +/// Offset of command queue ring buffer. pub (super )const CMDQ_OFFSET :usize = core::mem::offset_of!(GspMem , cpuq) + core::mem::offset_of!(Msgq , msgq)
drivers/gpu/nova-core/gsp/fw.rs +2 -2
@@ -715,12 +715,12 @@ pub(crate) fn new(msgq_size: u32, rx_hdr_offset: u32, msg_count: u32) -> Self {Self (bindings::msgqTxHeader { version:0 , size: msgq_size, - msgSize:cv! (GSP_PAGE_SIZE ), + msgSize:cv! (Cmdq ::MSG_SIZE ), msgCount: msg_count, writePtr:0 , flags:1 , rxHdrOff: rx_hdr_offset, - entryOff:cv! (GSP_PAGE_SIZE ), + entryOff:cv! (Cmdq ::MSGQ_ENTRY_OFFSET ), }) }
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v3 10/11 gpu: nova-core: gsp: take all the msgq layout values from Cmdq in MsgqTxHeader::new()
In reply to Alexandre CourbotThe queue size, RX header offset and slot count are layout constants just like the entry offset, so stop passing them as parameters.
No functional change.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 13 +++++++------ drivers/gpu/nova-core/gsp/fw.rs | 23 +++++++++-------------- 2 files changed, 16 insertions(+), 20 deletions(-)
drivers/gpu/nova-core/gsp/cmdq.rs +7 -6
@@ -7,8 +7,6 @@pub (super )mod gmc;pub (super )mod rpc; -use core::mem; -use kernel::{ device, dma::{
@@ -176,11 +174,8 @@ struct DmaGspMem<'a> {impl <'a>DmaGspMem <'a> {/// Allocate a new instance and map it for `dev`. fn new (dev: &'a device::Device <device::Bound >, bar:Bar0 <'a>) ->Result <Self > { -const MSGQ_SIZE :u32 =cv! (size_of ::<Msgq >()); -const RX_HDR_OFF :u32 =cv! (mem::offset_of!(Msgq , rx)); -let mut gsp_mem =CoherentBox ::<'_,GspMem >::zeroed (dev,GFP_KERNEL )?; - gsp_mem.cpuq.tx =MsgqTxHeader ::new (MSGQ_SIZE ,RX_HDR_OFF ,MSGQ_NUM_PAGES ); + gsp_mem.cpuq.tx =MsgqTxHeader ::new (); gsp_mem.cpuq.rx =MsgqRxHeader ::new ();let gsp_mem:Coherent <'_,_ > = gsp_mem.into ();
@@ -476,6 +471,12 @@ impl<'cmdq> Cmdq<'cmdq> {/// Size of a queue slot. An element spans one or more slots. pub (super )const MSG_SIZE :usize =GSP_PAGE_SIZE ; +/// Total size of a queue, headers included. +pub (super )const MSGQ_SIZE :usize =size_of ::<Msgq >(); + +/// Offset of the RX header of a queue from its TX header. +pub (super )const MSGQ_RX_HDR_OFFSET :usize = core::mem::offset_of!(Msgq , rx); +/// Offset of the ring buffer of a queue from its TX header. pub (super )const MSGQ_ENTRY_OFFSET :usize = core::mem::offset_of!(Msgq , msgq);
drivers/gpu/nova-core/gsp/fw.rs +9 -14
@@ -50,7 +50,10 @@ Chipset, // }, gsp::{ - cmdq::Cmdq, // + cmdq::{ + Cmdq, + MSGQ_NUM_PAGES, // + }, GSP_PAGE_SIZE, }, mctp::{
@@ -702,24 +705,16 @@ fn id8(name: &str) -> u64 {pub (crate )struct MsgqTxHeader (bindings::msgqTxHeader );impl MsgqTxHeader { -/// Create a new TX queue header. -/// -/// # Arguments -/// -/// * `msgq_size` - Total size of the message queue structure, in bytes. -/// * `rx_hdr_offset` - Offset, in bytes, of the start of the RX header in the message queue -/// structure. -/// * `msg_count` - Number of messages that can be sent, i.e. the number of memory pages -/// allocated for the message queue in the message queue structure. -pub (crate )fn new (msgq_size:u32 , rx_hdr_offset:u32 , msg_count:u32 ) ->Self { +/// Create a new TX queue header, describing the queue layout defined by [`Cmdq`]. +pub (crate )fn new () ->Self {Self (bindings::msgqTxHeader { version:0 , - size: msgq_size, + size:cv! (Cmdq ::MSGQ_SIZE ), msgSize:cv! (Cmdq ::MSG_SIZE ), - msgCount: msg_count, + msgCount:MSGQ_NUM_PAGES , writePtr:0 , flags:1 , - rxHdrOff: rx_hdr_offset, + rxHdrOff:cv! (Cmdq ::MSGQ_RX_HDR_OFFSET ), entryOff:cv! (Cmdq ::MSGQ_ENTRY_OFFSET ), }) }
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerPATCH v3 11/11 gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV
In reply to Alexandre CourbotFrom: John Hubbard <[email protected]>
The GSP firmware TLV names a separate file in its FILE tag and gives that file's length in its SIZE tag. The GSP firmware wrapper reads the two tags and loads the file itself, so no other loader can share that code.
Move it into the TLV parser as Tlv::load_file(), which also fails with ENODATA when SIZE is zero.
The r000 ucodes loader will be the second user of this.
--- drivers/gpu/nova-core/firmware/gsp.rs | 15 +++---------- drivers/gpu/nova-core/firmware/tlv.rs | 40 ++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 15 deletions(-)
drivers/gpu/nova-core/firmware/gsp.rs +3 -12
@@ -6,9 +6,7 @@ Coherent, DmaAddress, // }, - firmware, - prelude::*, - str::CString, + prelude::*, // };use crate ::{
@@ -20,8 +18,7 @@ Tlv, }, }, - gpu::Chipset, - num::FromSafeCast, + gpu::Chipset, // };/// The GSP firmware image, its signatures, and the GSP bootloader.
@@ -48,13 +45,7 @@ pub(crate) fn new(let tlv =Tlv ::new (firmware.data ())?;dev_dbg! (dev,"loaded gsp firmware v{}\n" , tlv.get_string (b"VERS" )?); -let size = usize::from_safe_cast (tlv.get_u32 (b"SIZE" )?); -let mut fw_vvec =VVec ::zeroed (size,GFP_KERNEL ).map_err (|_|ENOMEM )?; - -let chip_name = chipset.name (); -let file = tlv.get_string (b"FILE" )?; -let filename =CString ::try_from_fmt (fmt! ("nvidia/{chip_name}/gsp/{file}" ))?; - firmware::request_into_buf (&filename, dev, fw_vvec.as_mut_slice ())?; +let fw_vvec = tlv.load_file (dev, chipset)?;let signatures =Coherent ::from_slice (dev, tlv.get_bytes (b"SIGN" )?,GFP_KERNEL )?;
drivers/gpu/nova-core/firmware/tlv.rs +37 -3
@@ -4,6 +4,7 @@use kernel::{ device, firmware, + fmt, prelude::*, str::CString ,// };
@@ -13,15 +14,18 @@ num::*, // }; +/// Returns the path of `file` in `chipset`'s GSP firmware directory. +fn gsp_firmware_path (chipset: gpu::Chipset , file: fmt::Arguments <'_>) ->Result <CString > { +CString ::try_from_fmt (fmt! ("nvidia/{}/gsp/{}" , chipset.name (), file)) +} +/// Requests the GPU firmware TLV `name` suitable for `chipset`. pub (crate )fn request_tlv ( dev: &device::Device , chipset: gpu::Chipset , name: &str , ) ->Result <firmware::Firmware > { -let chip_name = chipset.name (); - -let filename =CString ::try_from_fmt (fmt! ("nvidia/{chip_name}/gsp/{name}.tlv" ))?; +let filename =gsp_firmware_path (chipset,fmt! ("{name}.tlv" ))?;dev_dbg! (dev,"loading firmware image {:?}\n" , &filename);
@@ -198,6 +202,36 @@ fn iter(&self) -> TlvIter<'_, 'a> { self.iter ().find (|b| b.tag == *tag).ok_or (EINVAL ) } +/// Loads the file that the `FILE` tag names from `chipset`'s GSP firmware directory. +/// +/// The `SIZE` tag gives the file's length, and the returned buffer is that long. +/// +/// # Errors +/// +/// - `EINVAL` if `FILE` or `SIZE` is absent, or `FILE` does not hold a valid string. +/// - `ENODATA` if `SIZE` is zero. +/// - `ENOMEM` if the buffer cannot be allocated. +/// +/// Errors from the firmware request are propagated as-is. +pub (crate )fn load_file ( + &self, + dev: &device::Device , + chipset: gpu::Chipset , + ) ->Result <VVec <u8 >> { +let file = self.get_string (b"FILE" )?; +let path =gsp_firmware_path (chipset,fmt! ("{file}" ))?; + +let size = usize::from_safe_cast (self.get_u32 (b"SIZE" )?); +if size ==0 { +return Err (ENODATA ); + } + +let mut data =VVec ::zeroed (size,GFP_KERNEL )?; + firmware::request_into_buf (&path, dev, data.as_mut_slice ())?; + +Ok (data) + } +/// Return a slice of bytes. /// /// Returns `EINVAL` if the value is empty.
Signature · 1 line
2.56.1
Alexandre Courbot
maintainerQuoted 9 lines · Alexandre Courbot
Alexandre Courbot (2):
gpu: nova-core: gsp: cmdq: reduce visibility of gsp-level constants
gpu: nova-core: gsp: take all the msgq layout values from Cmdq inMsgqTxHeader::new()John Hubbard (9):
gpu: nova-core: gsp: rename and move the static configuration type
gpu: nova-core: gsp: return the static GPU configuration from boot
gpu: nova-core: gsp: add the short name and GID to theGSP_INITreply
gpu: nova-core: gsp: compute the msgq entry offset inMsgqTxHeader::new()
These 6 patches, pushed to drm-rust-next! Thanks, I'll respin the rest with one additional patch that I forgot.