nova-core: Complete GSP boot and begin RPC communication
Subsystems (4)
v4 cover nova-core: Complete GSP boot and begin RPC communication
Changes from v3 to v4:
- Several changes to adapt to Alexandre Courbot's GSP boot v9 series which had changes to the RPC command queue.
- Several changes based on feedback from Alexandre Courbot, Lyude Paul.
These patches a refresh of the series adding support for final stages of the GSP boot process where a sequencer which inteprets firmware instructions needs to run to boot the GSP processor, followed by waiting for an INIT_DONE message from the GSP and finally retrieving GPU information from the GSP.
The patches are based on Alex's github branch which have several prerequisites:
Repo: https://github.com/Gnurou/linux.git Branch: b4/gsp_boot
The entire tree (these patches + patches from Alex, Alistair, John) can be found at the git repository:
git: git://git.kernel.org/pub/scm/linux/kernel/git/jfern/linux.git
tag: nova-sequencer-init-done-v4
Tested on my Ampere GA102 and I see in dmesg:
NovaCore 0000:00:07.0: GPU name: NVIDIA GeForce RTX 3090 Ti
Changes from v2 to v3:
- Added several tags.
- Fixed commit messages, style errors.
- Added GspStaticInfo patch.
- Fixed bug found by Timur in the sequencer code (related to ignoring messages).
- Removed excessive dev_dbg prints in sequencer code (John Hubbard).
Previous series:
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Alistair Popple (2):
gpu: nova-core: gsp: Wait for gsp initialization to complete
gpu: nova-core: gsp: Retrieve GSP static info to gather GPU
information
Joel Fernandes (11):
gpu: nova-core: falcon: Move waiting until halted to a helper
gpu: nova-core: falcon: Move start functionality into separate helper
gpu: nova-core: falcon: Move mbox functionalities into helper
gpu: nova-core: falcon: Move dma_reset functionality into helper
gpu: nova-core: gsp: Add support for checking if GSP reloaded
gpu: nova-core: Add bindings required by GSP sequencer
gpu: nova-core: Implement the GSP sequencer
gpu: nova-core: sequencer: Add register opcodes
gpu: nova-core: sequencer: Add delay opcode support
gpu: nova-core: sequencer: Implement basic core operations
gpu: nova-core: sequencer: Implement core resume operation
drivers/gpu/nova-core/falcon.rs | 101 +++-- drivers/gpu/nova-core/falcon/gsp.rs | 17 + drivers/gpu/nova-core/gsp.rs | 1 + drivers/gpu/nova-core/gsp/boot.rs | 24 + drivers/gpu/nova-core/gsp/cmdq.rs | 1 - drivers/gpu/nova-core/gsp/commands.rs | 115 ++++- drivers/gpu/nova-core/gsp/fw.rs | 326 +++++++++++++- .../gpu/nova-core/gsp/fw/r570_144/bindings.rs | 248 ++++++++++ drivers/gpu/nova-core/gsp/sequencer.rs | 425 ++++++++++++++++++ drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/regs.rs | 6 + drivers/gpu/nova-core/sbuffer.rs | 1 - drivers/gpu/nova-core/util.rs | 16 + 13 files changed, 1245 insertions(+), 37 deletions(-) create mode 100644 drivers/gpu/nova-core/gsp/sequencer.rs create mode 100644 drivers/gpu/nova-core/util.rs
Signature · 1 line
2.34.1
PATCH v4 1/13 gpu: nova-core: falcon: Move waiting until halted to a helper
Move the "waiting until halted" functionality into a helper so that we can use it in the sequencer, which is a separate sequencer operation.
--- drivers/gpu/nova-core/falcon.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/gpu/nova-core/falcon.rs +14 -7
@@ -551,6 +551,19 @@ pub(crate) fn dma_load<F: FalconFirmware<Target = E>>(&self, bar: &Bar0, fw: &F)Ok (()) } +/// Wait until the falcon CPU is halted. +pub (crate )fn wait_till_halted (&self, bar: &Bar0 ) ->Result <()> { +// TIMEOUT: arbitrarily large value, firmwares should complete in less than 2 seconds. +read_poll_timeout ( + ||Ok (regs::NV_PFALCON_FALCON_CPUCTL ::read (bar, &E ::ID )), + |r| r.halted (), +Delta ::ZERO , +Delta ::from_secs (2 ), + )?; + +Ok (()) + } +/// Runs the loaded firmware and waits for its completion. /// /// `mbox0` and `mbox1` are optional parameters to write into the `MBOX0` and `MBOX1` registers
@@ -585,13 +598,7 @@ pub(crate) fn boot( .write(bar, &E::ID), } -// TIMEOUT: arbitrarily large value, firmwares should complete in less than 2 seconds. -read_poll_timeout ( - ||Ok (regs::NV_PFALCON_FALCON_CPUCTL ::read (bar, &E ::ID )), - |r| r.halted (), -Delta ::ZERO , -Delta ::from_secs (2 ), - )?; + self.wait_till_halted (bar)?;let (mbox0, mbox1) = ( regs::NV_PFALCON_FALCON_MAILBOX0::read(bar, &E::ID).value(),
Signature · 1 line
2.34.1
PATCH v4 2/13 gpu: nova-core: falcon: Move start functionality into separate helper
In reply to Joel FernandesMove start functionality into a separate helper so we can use it from the sequencer.
--- drivers/gpu/nova-core/falcon.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/gpu/nova-core/falcon.rs +16 -10
@@ -564,7 +564,21 @@ pub(crate) fn wait_till_halted(&self, bar: &Bar0) -> Result<()> {Ok (()) } -/// Runs the loaded firmware and waits for its completion. +/// Start the falcon CPU. +pub (crate )fn start (&self, bar: &Bar0 ) ->Result <()> { +match regs::NV_PFALCON_FALCON_CPUCTL ::read (bar, &E ::ID ).alias_en () { +true => regs::NV_PFALCON_FALCON_CPUCTL_ALIAS ::default () + .set_startcpu (true ) + .write (bar, &E ::ID ), +false => regs::NV_PFALCON_FALCON_CPUCTL ::default () + .set_startcpu (true ) + .write (bar, &E ::ID ), + } + +Ok (()) + } + +/// Start running the loaded firmware. /// /// `mbox0` and `mbox1` are optional parameters to write into the `MBOX0` and `MBOX1` registers /// prior to running.
@@ -589,15 +603,7 @@ pub(crate) fn boot( .write(bar, &E::ID); } -match regs::NV_PFALCON_FALCON_CPUCTL ::read (bar, &E ::ID ).alias_en () { -true => regs::NV_PFALCON_FALCON_CPUCTL_ALIAS ::default () - .set_startcpu (true ) - .write (bar, &E ::ID ), -false => regs::NV_PFALCON_FALCON_CPUCTL ::default () - .set_startcpu (true ) - .write (bar, &E ::ID ), - } - + self.start (bar)?; self.wait_till_halted (bar)?; let (mbox0, mbox1) = (
Signature · 1 line
2.34.1
PATCH v4 3/13 gpu: nova-core: falcon: Move mbox functionalities into helper
In reply to Joel FernandesMove falcon reading/writing to mbox functionality into helper so we can use it from the sequencer resume flow.
--- drivers/gpu/nova-core/falcon.rs | 51 +++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 15 deletions(-)
drivers/gpu/nova-core/falcon.rs +36 -15
@@ -578,19 +578,13 @@ pub(crate) fn start(&self, bar: &Bar0) -> Result<()> {Ok (()) } -/// Start running the loaded firmware. -/// -/// `mbox0` and `mbox1` are optional parameters to write into the `MBOX0` and `MBOX1` registers -/// prior to running. -/// -/// Wait up to two seconds for the firmware to complete, and return its exit status read from -/// the `MBOX0` and `MBOX1` registers. -pub (crate )fn boot ( +/// Writes values to the mailbox registers if provided. +pub (crate )fn write_mailboxes ( &self, bar: &Bar0 , mbox0:Option <u32 >, mbox1:Option <u32 >, - ) ->Result <(u32 ,u32 )> { + ) ->Result <()> {if let Some (mbox0) = mbox0 { regs::NV_PFALCON_FALCON_MAILBOX0 ::default () .set_value (mbox0)
@@ -602,18 +596,45 @@ pub(crate) fn boot( .set_value(mbox1) .write (bar, &E ::ID ); } +Ok (()) + } - self.start (bar)?; - self.wait_till_halted (bar)?; +/// Reads the value from `mbox0` register. +pub (crate )fn read_mailbox0 (&self, bar: &Bar0 ) ->Result <u32 > { +Ok (regs::NV_PFALCON_FALCON_MAILBOX0 ::read (bar, &E ::ID ).value ()) + } -let (mbox0, mbox1) = ( - regs::NV_PFALCON_FALCON_MAILBOX0 ::read (bar, &E ::ID ).value (), - regs::NV_PFALCON_FALCON_MAILBOX1 ::read (bar, &E ::ID ).value (), - ); +/// Reads the value from `mbox1` register. +pub (crate )fn read_mailbox1 (&self, bar: &Bar0 ) ->Result <u32 > { +Ok (regs::NV_PFALCON_FALCON_MAILBOX1 ::read (bar, &E ::ID ).value ()) + } +/// Reads values from both mailbox registers. +pub (crate )fn read_mailboxes (&self, bar: &Bar0 ) ->Result <(u32 ,u32 )> { +let mbox0 = self.read_mailbox0 (bar)?; +let mbox1 = self.read_mailbox1 (bar)?;Ok ((mbox0, mbox1)) } +/// Start running the loaded firmware. +/// +/// `mbox0` and `mbox1` are optional parameters to write into the `MBOX0` and `MBOX1` registers +/// prior to running. +/// +/// Wait up to two seconds for the firmware to complete, and return its exit status read from +/// the `MBOX0` and `MBOX1` registers. +pub (crate )fn boot ( + &self, + bar: &Bar0 , + mbox0:Option <u32 >, + mbox1:Option <u32 >, + ) ->Result <(u32 ,u32 )> { + self.write_mailboxes (bar, mbox0, mbox1)?; + self.start (bar)?; + self.wait_till_halted (bar)?; + self.read_mailboxes (bar) + } +/// Returns the fused version of the signature to use in order to run a HS firmware on this /// falcon instance. `engine_id_mask` and `ucode_id` are obtained from the firmware header. pub(crate) fn signature_reg_fuse_version(
Signature · 1 line
2.34.1
PATCH v4 4/13 gpu: nova-core: falcon: Move dma_reset functionality into helper
In reply to Joel FernandesMove dma_reset so we can use it for the upcoming sequencer functionality.
--- drivers/gpu/nova-core/falcon.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/falcon.rs +7 -2
@@ -382,6 +382,12 @@ pub(crate) fn new(dev: &device::Device, chipset: Chipset) -> Result<Self> { }) } +/// Resets DMA-related registers. +pub (crate )fn dma_reset (&self, bar: &Bar0 ) { + regs::NV_PFALCON_FBIF_CTL ::update (bar, &E ::ID , |v| v.set_allow_phys_no_ctx (true )); + regs::NV_PFALCON_FALCON_DMACTL ::default ().write (bar, &E ::ID ); + } +/// Wait for memory scrubbing to complete. fn reset_wait_mem_scrubbing (&self, bar: &Bar0 ) ->Result {// TIMEOUT: memory scrubbing should complete in less than 20ms.
@@ -531,8 +537,7 @@ fn dma_wr<F: FalconFirmware<Target = E>>(/// Perform a DMA load into `IMEM` and `DMEM` of `fw`, and prepare the falcon to run it. pub (crate )fn dma_load <F :FalconFirmware <Target =E >>(&self, bar: &Bar0 , fw: &F ) ->Result { - regs::NV_PFALCON_FBIF_CTL ::update (bar, &E ::ID , |v| v.set_allow_phys_no_ctx (true )); - regs::NV_PFALCON_FALCON_DMACTL ::default ().write (bar, &E ::ID ); + self.dma_reset (bar); regs::NV_PFALCON_FBIF_TRANSCFG ::update (bar, &E ::ID ,0 , |v| { v.set_target (FalconFbifTarget ::CoherentSysmem ) .set_mem_type (FalconFbifMemType ::Physical )
Signature · 1 line
2.34.1
PATCH v4 5/13 gpu: nova-core: gsp: Add support for checking if GSP reloaded
In reply to Joel FernandesDuring the sequencer process, we need to check if GSP was successfully reloaded. Add functionality to check for the same.
--- drivers/gpu/nova-core/falcon/gsp.rs | 18 ++++++++++++++++++ drivers/gpu/nova-core/regs.rs | 6 ++++++ 2 files changed, 24 insertions(+)
drivers/gpu/nova-core/falcon/gsp.rs +18 -0
@@ -1,5 +1,11 @@// SPDX-License-Identifier: GPL-2.0 +use kernel::{ + io::poll::read_poll_timeout, + prelude::*, + time::Delta ,// +}; +use crate ::{ driver::Bar0 , falcon::{
@@ -37,4 +43,16 @@ pub(crate) fn clear_swgen0_intr(&self, bar: &Bar0) { .set_swgen0(true) .write (bar, &Gsp ::ID ); } + +/// Checks if GSP reload/resume has completed during the boot process. +#[expect(dead_code)] +pub (crate )fn check_reload_completed (&self, bar: &Bar0 , timeout:Delta ) ->Result <bool > { +read_poll_timeout ( + ||Ok (regs::NV_PGC6_BSI_SECURE_SCRATCH_14 ::read (bar)), + |val| val.boot_stage_3_handoff (), +Delta ::ZERO , + timeout, + ) + .map (|_|true ) + } }
drivers/gpu/nova-core/regs.rs +6 -0
@@ -138,6 +138,12 @@ pub(crate) fn higher_bound(self) -> u64 {// These scratch registers remain powered on even in a low-power state and have a designated group // number. +// Boot Sequence Interface (BSI) register used to determine +// if GSP reload/resume has completed during the boot process. +register! (NV_PGC6_BSI_SECURE_SCRATCH_14 @0x001180f8 { +26 :26 boot_stage_3_handoffas bool ; +}); +// Privilege level mask register. It dictates whether the host CPU has privilege to access the // `PGC6_AON_SECURE_SCRATCH_GROUP_05` register (which it needs to read GFW_BOOT). register! (NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK @0x00118128 ,
Signature · 1 line
2.34.1
PATCH v4 6/13 gpu: nova-core: Add bindings required by GSP sequencer
In reply to Joel FernandesAdd several firmware bindings required by GSP sequencer code.
--- drivers/gpu/nova-core/gsp/fw.rs | 328 +++++++++++++++++- .../gpu/nova-core/gsp/fw/r570_144/bindings.rs | 85 +++++ 2 files changed, 412 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gsp/fw.rs +327 -1
@@ -312,6 +312,332 @@ fn from(value: MsgFunction) -> Self { } } +/// Sequencer buffer opcode for GSP sequencer commands. +#[derive( Copy , Clone , Debug , PartialEq )] +#[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 , + +// Delay opcode +DelayUs = r570_144::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 , +} + +impl fmt::Display for SeqBufOpcode { +fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { +match self { +SeqBufOpcode ::CoreReset =>write! (f,"CORE_RESET" ), +SeqBufOpcode ::CoreResume =>write! (f,"CORE_RESUME" ), +SeqBufOpcode ::CoreStart =>write! (f,"CORE_START" ), +SeqBufOpcode ::CoreWaitForHalt =>write! (f,"CORE_WAIT_FOR_HALT" ), +SeqBufOpcode ::DelayUs =>write! (f,"DELAY_US" ), +SeqBufOpcode ::RegModify =>write! (f,"REG_MODIFY" ), +SeqBufOpcode ::RegPoll =>write! (f,"REG_POLL" ), +SeqBufOpcode ::RegStore =>write! (f,"REG_STORE" ), +SeqBufOpcode ::RegWrite =>write! (f,"REG_WRITE" ), + } + } +} + +impl TryFrom <u32 >for SeqBufOpcode { +type Error = kernel::error::Error ; + +fn try_from (value:u32 ) ->Result <SeqBufOpcode > { +match value { + r570_144::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 => { +Ok (SeqBufOpcode ::CoreResume ) + } + r570_144::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 => { +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 => { +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 ), + _ =>Err (EINVAL ), + } + } +} + +impl From <SeqBufOpcode >for u32 { +fn from (value:SeqBufOpcode ) ->Self { +// CAST: `SeqBufOpcode` is `repr(u32)` and can thus be cast losslessly. + valueas u32 + } +} + +/// Wrapper for GSP sequencer register write payload. +#[repr(transparent)] +#[derive( Copy , Clone )] +pub (crate )struct RegWritePayload (r570_144::GSP_SEQ_BUF_PAYLOAD_REG_WRITE ); + +#[expect(unused)] +impl RegWritePayload { +/// Returns the register address. +pub (crate )fn addr (&self) ->u32 { + self.0 .addr + } + +/// Returns the value to write. +pub (crate )fn val (&self) ->u32 { + self.0 .val + } +} + +// SAFETY: This struct only contains integer types for which all bit patterns are valid. +unsafe impl FromBytes for RegWritePayload {} + +// SAFETY: Padding is explicit and will not contain uninitialized data. +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 ); + +#[expect(unused)] +impl RegModifyPayload { +/// Returns the register address. +pub (crate )fn addr (&self) ->u32 { + self.0 .addr + } + +/// Returns the mask to apply. +pub (crate )fn mask (&self) ->u32 { + self.0 .mask + } + +/// Returns the value to write. +pub (crate )fn val (&self) ->u32 { + self.0 .val + } +} + +// SAFETY: This struct only contains integer types for which all bit patterns are valid. +unsafe impl FromBytes for RegModifyPayload {} + +// SAFETY: Padding is explicit and will not contain uninitialized data. +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 ); + +#[expect(unused)] +impl RegPollPayload { +/// Returns the register address. +pub (crate )fn addr (&self) ->u32 { + self.0 .addr + } + +/// Returns the mask to apply. +pub (crate )fn mask (&self) ->u32 { + self.0 .mask + } + +/// Returns the expected value. +pub (crate )fn val (&self) ->u32 { + self.0 .val + } + +/// Returns the timeout in microseconds. +pub (crate )fn timeout (&self) ->u32 { + self.0 .timeout + } +} + +// SAFETY: This struct only contains integer types for which all bit patterns are valid. +unsafe impl FromBytes for RegPollPayload {} + +// SAFETY: Padding is explicit and will not contain uninitialized data. +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 ); + +#[expect(unused)] +impl DelayUsPayload { +/// Returns the delay value in microseconds. +pub (crate )fn val (&self) ->u32 { + self.0 .val + } +} + +// SAFETY: This struct only contains integer types for which all bit patterns are valid. +unsafe impl FromBytes for DelayUsPayload {} + +// SAFETY: Padding is explicit and will not contain uninitialized data. +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 ); + +#[expect(unused)] +impl RegStorePayload { +/// Returns the register address. +pub (crate )fn addr (&self) ->u32 { + self.0 .addr + } + +/// Returns the storage index. +pub (crate )fn index (&self) ->u32 { + self.0 .index + } +} + +// SAFETY: This struct only contains integer types for which all bit patterns are valid. +unsafe impl FromBytes for RegStorePayload {} + +// SAFETY: Padding is explicit and will not contain uninitialized data. +unsafe impl AsBytes for RegStorePayload {} + +/// Wrapper for GSP sequencer buffer command. +#[repr(transparent)] +pub (crate )struct SequencerBufferCmd (r570_144::GSP_SEQUENCER_BUFFER_CMD ); + +#[expect(unused)] +impl SequencerBufferCmd { +/// Returns the opcode as a `SeqBufOpcode` enum, or error if invalid. +pub (crate )fn opcode (&self) ->Result <SeqBufOpcode > { + self.0 .opCode.try_into () + } + +/// Returns the register write payload by value. +/// +/// Returns an error if the opcode is not `SeqBufOpcode::RegWrite`. +pub (crate )fn reg_write_payload (&self) ->Result <RegWritePayload > { +if self.opcode ()? !=SeqBufOpcode ::RegWrite { +return Err (EINVAL ); + } +// SAFETY: Opcode is verified to be `RegWrite`, so the union contains valid +// `RegWritePayload`. +let payload_bytes =unsafe { + core::slice::from_raw_parts ( + core::ptr::addr_of!(self.0 .payload.regWrite).cast ::<u8 >(), + core::mem::size_of ::<RegWritePayload >(), + ) + }; +Ok (*RegWritePayload ::from_bytes (payload_bytes).ok_or (EINVAL )?) + } + +/// Returns the register modify payload by value. +/// +/// Returns an error if the opcode is not `SeqBufOpcode::RegModify`. +pub (crate )fn reg_modify_payload (&self) ->Result <RegModifyPayload > { +if self.opcode ()? !=SeqBufOpcode ::RegModify { +return Err (EINVAL ); + } +// SAFETY: Opcode is verified to be `RegModify`, so the union contains valid +// `RegModifyPayload`. +let payload_bytes =unsafe { + core::slice::from_raw_parts ( + core::ptr::addr_of!(self.0 .payload.regModify).cast ::<u8 >(), + core::mem::size_of ::<RegModifyPayload >(), + ) + }; +Ok (*RegModifyPayload ::from_bytes (payload_bytes).ok_or (EINVAL )?) + } + +/// Returns the register poll payload by value. +/// +/// Returns an error if the opcode is not `SeqBufOpcode::RegPoll`. +pub (crate )fn reg_poll_payload (&self) ->Result <RegPollPayload > { +if self.opcode ()? !=SeqBufOpcode ::RegPoll { +return Err (EINVAL ); + } +// SAFETY: Opcode is verified to be `RegPoll`, so the union contains valid `RegPollPayload`. +let payload_bytes =unsafe { + core::slice::from_raw_parts ( + core::ptr::addr_of!(self.0 .payload.regPoll).cast ::<u8 >(), + core::mem::size_of ::<RegPollPayload >(), + ) + }; +Ok (*RegPollPayload ::from_bytes (payload_bytes).ok_or (EINVAL )?) + } + +/// Returns the delay payload by value. +/// +/// Returns an error if the opcode is not `SeqBufOpcode::DelayUs`. +pub (crate )fn delay_us_payload (&self) ->Result <DelayUsPayload > { +if self.opcode ()? !=SeqBufOpcode ::DelayUs { +return Err (EINVAL ); + } +// SAFETY: Opcode is verified to be `DelayUs`, so the union contains valid `DelayUsPayload`. +let payload_bytes =unsafe { + core::slice::from_raw_parts ( + core::ptr::addr_of!(self.0 .payload.delayUs).cast ::<u8 >(), + core::mem::size_of ::<DelayUsPayload >(), + ) + }; +Ok (*DelayUsPayload ::from_bytes (payload_bytes).ok_or (EINVAL )?) + } + +/// Returns the register store payload by value. +/// +/// Returns an error if the opcode is not `SeqBufOpcode::RegStore`. +pub (crate )fn reg_store_payload (&self) ->Result <RegStorePayload > { +if self.opcode ()? !=SeqBufOpcode ::RegStore { +return Err (EINVAL ); + } +// SAFETY: Opcode is verified to be `RegStore`, so the union contains valid +// `RegStorePayload`. +let payload_bytes =unsafe { + core::slice::from_raw_parts ( + core::ptr::addr_of!(self.0 .payload.regStore).cast ::<u8 >(), + core::mem::size_of ::<RegStorePayload >(), + ) + }; +Ok (*RegStorePayload ::from_bytes (payload_bytes).ok_or (EINVAL )?) + } +} + +// SAFETY: This struct only contains integer types for which all bit patterns are valid. +unsafe impl FromBytes for SequencerBufferCmd {} + +// SAFETY: Padding is explicit and will not contain uninitialized data. +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 ); + +#[expect(unused)] +impl RunCpuSequencer { +/// Returns the command index. +pub (crate )fn cmd_index (&self) ->u32 { + self.0 .cmdIndex + } +} + +// SAFETY: This struct only contains integer types for which all bit patterns are valid. +unsafe impl FromBytes for RunCpuSequencer {} + +// SAFETY: Padding is explicit and will not contain uninitialized data. +unsafe impl AsBytes for RunCpuSequencer {} +/// Struct containing the arguments required to pass a memory buffer to the GSP /// for use during initialisation. ///
@@ -566,7 +892,7 @@ pub(crate) fn element_count(&self) -> u32 { } } -// SAFETY: Padding is explicit and does not contain uninitialized data. +// SAFETY: Padding is explicit and will not contain uninitialized data. unsafe impl AsBytes for GspMsgElement {}// SAFETY: This struct only contains integer types for which all bit patterns
drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +85 -0
94 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 7/13 gpu: nova-core: Implement the GSP sequencer
In reply to Joel FernandesImplement the GSP sequencer which culminates in INIT_DONE message being received from the GSP indicating that the GSP has successfully booted.
This is just initial sequencer support, the actual commands will be added in the next patches.
--- drivers/gpu/nova-core/gsp.rs | 1 + drivers/gpu/nova-core/gsp/boot.rs | 15 ++ drivers/gpu/nova-core/gsp/cmdq.rs | 1 - drivers/gpu/nova-core/gsp/fw.rs | 1 - drivers/gpu/nova-core/gsp/sequencer.rs | 251 +++++++++++++++++++++++++ drivers/gpu/nova-core/sbuffer.rs | 1 - 6 files changed, 267 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/nova-core/gsp/sequencer.rs
drivers/gpu/nova-core/gsp.rs +1 -0
@@ -17,6 +17,7 @@pub (crate )mod cmdq;pub (crate )mod commands;mod fw; +mod sequencer;pub (crate )use fw::{GspFwWprMeta ,
drivers/gpu/nova-core/gsp/boot.rs +15 -0
@@ -33,6 +33,10 @@ gpu::Chipset, gsp::{ commands, + sequencer::{ + GspSequencer, + GspSequencerParams, // + }, GspFwWprMeta, // }, regs,
@@ -221,6 +225,17 @@ pub(crate) fn boot( gsp_falcon.is_riscv_active(bar), ); +// Create and run the GSP sequencer. +let seq_params =GspSequencerParams { + bootloader_app_version: gsp_fw.bootloader.app_version, + libos_dma_handle: libos_handle, + gsp_falcon, + sec2_falcon, + dev: pdev.as_ref ().into (), + bar, + }; +GspSequencer ::run (&mut self.cmdq, seq_params,Delta ::from_secs (10 ))?; +Ok (()) } }
drivers/gpu/nova-core/gsp/cmdq.rs +0 -1
@@ -645,7 +645,6 @@ fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {/// - `EIO` if there was some inconsistency (e.g. message shorter than advertised) on the /// message queue. /// - `EINVAL` if the function of the message was unrecognized. -#[expect(unused)] pub (crate )fn receive_msg <M :MessageFromGsp >(&mut self, timeout:Delta ) ->Result <M >where // This allows all error types, including `Infallible`, to be used for `M::InitError`.
drivers/gpu/nova-core/gsp/fw.rs +0 -1
@@ -624,7 +624,6 @@ unsafe impl AsBytes for SequencerBufferCmd {}#[repr(transparent)] pub (crate )struct RunCpuSequencer (r570_144::rpc_run_cpu_sequencer_v17_00 ); -#[expect(unused)] impl RunCpuSequencer {/// Returns the command index. pub (crate )fn cmd_index (&self) ->u32 {
drivers/gpu/nova-core/gsp/sequencer.rs new file +251 -0
251 lines not on this page · raw message
drivers/gpu/nova-core/sbuffer.rs +0 -1
@@ -168,7 +168,6 @@ pub(crate) fn read_exact(&mut self, mut dst: &mut [u8]) -> Result {/// Read all the remaining data into a [`KVec`]. /// /// `self` will be empty after this operation. -#[expect(unused)] pub (crate )fn flush_into_kvec (&mut self, flags: kernel::alloc::Flags ) ->Result <KVec <u8 >> {let mut buf =KVec ::<u8 >::new ();
Signature · 1 line
2.34.1
PATCH v4 8/13 gpu: nova-core: sequencer: Add register opcodes
In reply to Joel FernandesThese opcodes are used for register write, modify, poll and store (save) sequencer operations.
--- drivers/gpu/nova-core/gsp/fw.rs | 4 - drivers/gpu/nova-core/gsp/sequencer.rs | 120 ++++++++++++++++++++++--- 2 files changed, 109 insertions(+), 15 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +0 -4
@@ -389,7 +389,6 @@ fn from(value: SeqBufOpcode) -> Self {#[derive( Copy , Clone )] pub (crate )struct RegWritePayload (r570_144::GSP_SEQ_BUF_PAYLOAD_REG_WRITE ); -#[expect(unused)] impl RegWritePayload {/// Returns the register address. pub (crate )fn addr (&self) ->u32 {
@@ -413,7 +412,6 @@ unsafe impl AsBytes for RegWritePayload {}#[derive( Copy , Clone )] pub (crate )struct RegModifyPayload (r570_144::GSP_SEQ_BUF_PAYLOAD_REG_MODIFY ); -#[expect(unused)] impl RegModifyPayload {/// Returns the register address. pub (crate )fn addr (&self) ->u32 {
@@ -442,7 +440,6 @@ unsafe impl AsBytes for RegModifyPayload {}#[derive( Copy , Clone )] pub (crate )struct RegPollPayload (r570_144::GSP_SEQ_BUF_PAYLOAD_REG_POLL ); -#[expect(unused)] impl RegPollPayload {/// Returns the register address. pub (crate )fn addr (&self) ->u32 {
@@ -495,7 +492,6 @@ unsafe impl AsBytes for DelayUsPayload {}#[derive( Copy , Clone )] pub (crate )struct RegStorePayload (r570_144::GSP_SEQ_BUF_PAYLOAD_REG_STORE ); -#[expect(unused)] impl RegStorePayload {/// Returns the register address. pub (crate )fn addr (&self) ->u32 {
drivers/gpu/nova-core/gsp/sequencer.rs +109 -11
150 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 9/13 gpu: nova-core: sequencer: Add delay opcode support
In reply to Joel FernandesImplement a sequencer opcode for delay operations.
--- drivers/gpu/nova-core/gsp/fw.rs | 2 -- drivers/gpu/nova-core/gsp/sequencer.rs | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +0 -2
@@ -473,7 +473,6 @@ unsafe impl AsBytes for RegPollPayload {}#[derive( Copy , Clone )] pub (crate )struct DelayUsPayload (r570_144::GSP_SEQ_BUF_PAYLOAD_DELAY_US ); -#[expect(unused)] impl DelayUsPayload {/// Returns the delay value in microseconds. pub (crate )fn val (&self) ->u32 {
@@ -514,7 +513,6 @@ unsafe impl AsBytes for RegStorePayload {}#[repr(transparent)] pub (crate )struct SequencerBufferCmd (r570_144::GSP_SEQUENCER_BUFFER_CMD ); -#[expect(unused)] impl SequencerBufferCmd {/// Returns the opcode as a `SeqBufOpcode` enum, or error if invalid. pub (crate )fn opcode (&self) ->Result <SeqBufOpcode > {
drivers/gpu/nova-core/gsp/sequencer.rs +19 -2
@@ -29,9 +29,12 @@ device, io::poll::read_poll_timeout, prelude::*, - time::Delta, + time::{ + delay::fsleep, + Delta, // + }, transmute::FromBytes, - types::ARef, // + types::ARef, };use crate ::{
@@ -85,6 +88,7 @@ pub(crate) enum GspSeqCmd { RegWrite(fw::RegWritePayload), RegModify(fw::RegModifyPayload), RegPoll(fw::RegPollPayload), + DelayUs(fw::DelayUsPayload), RegStore(fw::RegStorePayload), }
@@ -110,6 +114,11 @@ pub(crate) fn new(data: &[u8], dev: &device::Device) -> Result<(Self, usize)> {let size = opcode_size +size_of_val (&payload); (GspSeqCmd ::RegPoll (payload), size) } + fw::SeqBufOpcode::DelayUs => { + let payload = fw_cmd.delay_us_payload()?; + let size = opcode_size + size_of_val(&payload); + (GspSeqCmd::DelayUs(payload), size) + } fw::SeqBufOpcode::RegStore => {let payload = fw_cmd.reg_store_payload ()?;let size = opcode_size +size_of_val (&payload);
@@ -197,6 +206,13 @@ fn run(&self, sequencer: &GspSequencer<'_>) -> Result { } } +impl GspSeqCmdRunner for fw::DelayUsPayload { +fn run (&self, _sequencer: &GspSequencer <'_>) ->Result { +fsleep (Delta ::from_micros (i64::from (self.val ()))); +Ok (()) + } +} +impl GspSeqCmdRunner for fw::RegStorePayload {fn run (&self, sequencer: &GspSequencer <'_>) ->Result {let addr = self.addr ()as usize ;
@@ -214,6 +230,7 @@ fn run(&self, seq: &GspSequencer<'_>) -> Result { GspSeqCmd::RegWrite(cmd) => cmd.run(seq), GspSeqCmd::RegModify(cmd) => cmd.run(seq), GspSeqCmd::RegPoll(cmd) => cmd.run(seq), + GspSeqCmd::DelayUs(cmd) => cmd.run(seq), GspSeqCmd::RegStore(cmd) => cmd.run(seq), } }
Signature · 1 line
2.34.1
PATCH v4 10/13 gpu: nova-core: sequencer: Implement basic core operations
In reply to Joel FernandesThese opcodes implement various falcon-related boot operations: reset, start, wait-for-halt.
--- drivers/gpu/nova-core/gsp/sequencer.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/gpu/nova-core/gsp/sequencer.rs +19 -0
@@ -90,6 +90,9 @@ pub(crate) enum GspSeqCmd { RegPoll(fw::RegPollPayload), DelayUs(fw::DelayUsPayload), RegStore(fw::RegStorePayload), + CoreReset, + CoreStart, + CoreWaitForHalt, }impl GspSeqCmd {
@@ -124,6 +127,9 @@ pub(crate) fn new(data: &[u8], dev: &device::Device) -> Result<(Self, usize)> {let size = opcode_size +size_of_val (&payload); (GspSeqCmd ::RegStore (payload), size) } + fw::SeqBufOpcode::CoreReset => (GspSeqCmd::CoreReset, opcode_size), + fw::SeqBufOpcode::CoreStart => (GspSeqCmd::CoreStart, opcode_size), + fw::SeqBufOpcode::CoreWaitForHalt => (GspSeqCmd::CoreWaitForHalt, opcode_size), _ => return Err(EINVAL), };
@@ -232,6 +238,19 @@ fn run(&self, seq: &GspSequencer<'_>) -> Result { GspSeqCmd::RegPoll(cmd) => cmd.run(seq), GspSeqCmd::DelayUs(cmd) => cmd.run(seq), GspSeqCmd::RegStore(cmd) => cmd.run(seq), + GspSeqCmd::CoreReset => { + seq.gsp_falcon.reset(seq.bar)?; + seq.gsp_falcon.dma_reset(seq.bar); + Ok(()) + } + GspSeqCmd::CoreStart => { + seq.gsp_falcon.start(seq.bar)?; + Ok(()) + } + GspSeqCmd::CoreWaitForHalt => { + seq.gsp_falcon.wait_till_halted (seq.bar)?; +Ok (()) + } } } }
Signature · 1 line
2.34.1
PATCH v4 11/13 gpu: nova-core: sequencer: Implement core resume operation
In reply to Joel FernandesImplement core resume operation. This is the last step of the sequencer resulting in resume of the GSP and proceeding to INIT_DONE stage of GSP boot.
--- drivers/gpu/nova-core/falcon/gsp.rs | 1 - drivers/gpu/nova-core/gsp/sequencer.rs | 44 ++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/falcon/gsp.rs +0 -1
@@ -45,7 +45,6 @@ pub(crate) fn clear_swgen0_intr(&self, bar: &Bar0) { }/// Checks if GSP reload/resume has completed during the boot process. -#[expect(dead_code)] pub (crate )fn check_reload_completed (&self, bar: &Bar0 , timeout:Delta ) ->Result <bool > {read_poll_timeout ( || Ok(regs::NV_PGC6_BSI_SECURE_SCRATCH_14::read(bar)),
drivers/gpu/nova-core/gsp/sequencer.rs +42 -2
68 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 12/13 gpu: nova-core: gsp: Wait for gsp initialization to complete
In reply to Joel FernandesFrom: Alistair Popple <[email protected]>
This adds the GSP init done command to wait for GSP initialization to complete. Once this command has been received the GSP is fully operational and will respond properly to normal RPC commands.
--- drivers/gpu/nova-core/gsp/boot.rs | 2 ++ drivers/gpu/nova-core/gsp/commands.rs | 48 +++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/gsp/boot.rs +2 -0
@@ -236,6 +236,8 @@ pub(crate) fn boot( };GspSequencer ::run (&mut self.cmdq, seq_params,Delta ::from_secs (10 ))?; + commands::gsp_init_done (&mut self.cmdq,Delta ::from_secs (10 ))?; +Ok (()) } }
drivers/gpu/nova-core/gsp/commands.rs +45 -3
68 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 13/13 gpu: nova-core: gsp: Retrieve GSP static info to gather GPU information
In reply to Joel FernandesFrom: Alistair Popple <[email protected]>
After GSP initialization is complete, retrieve the static configuration information from GSP-RM. This information includes GPU name, capabilities, memory configuration, and other properties. On some GPU variants, it is also required to do this for initialization to complete.
--- drivers/gpu/nova-core/gsp/boot.rs | 7 + drivers/gpu/nova-core/gsp/commands.rs | 67 +++++++ drivers/gpu/nova-core/gsp/fw.rs | 5 + .../gpu/nova-core/gsp/fw/r570_144/bindings.rs | 163 ++++++++++++++++++ drivers/gpu/nova-core/nova_core.rs | 1 + drivers/gpu/nova-core/util.rs | 16 ++ 6 files changed, 259 insertions(+) create mode 100644 drivers/gpu/nova-core/util.rs
drivers/gpu/nova-core/gsp/boot.rs +7 -0
@@ -40,6 +40,7 @@ GspFwWprMeta, // }, regs, + util, // vbios::Vbios, };
@@ -237,6 +238,12 @@ pub(crate) fn boot(GspSequencer ::run (&mut self.cmdq, seq_params,Delta ::from_secs (10 ))?; commands::gsp_init_done (&mut self.cmdq,Delta ::from_secs (10 ))?; +let info = commands::get_gsp_info (&mut self.cmdq, bar)?; +dev_info! ( + pdev.as_ref (), +"GPU name: {}\n" , + util::str_from_null_terminated (&info.gpu_name) + );Ok (()) }
drivers/gpu/nova-core/gsp/commands.rs +67 -0
91 lines not on this page · raw message
drivers/gpu/nova-core/gsp/fw.rs +5 -0
@@ -885,6 +885,11 @@ pub(crate) fn element_count(&self) -> u32 { } } +pub (crate )use r570_144::{ +// GSP static configuration information. +GspStaticConfigInfo_t ,// +}; +// SAFETY: Padding is explicit and will not contain uninitialized data. unsafe impl AsBytes for GspMsgElement {}
drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs +163 -0
181 lines not on this page · raw message
drivers/gpu/nova-core/nova_core.rs +1 -0
@@ -16,6 +16,7 @@mod num;mod regs;mod sbuffer; +mod util;mod vbios;pub (crate )const MODULE_NAME : &kernel::str::CStr = <LocalModule as kernel::ModuleMetadata >::NAME ;
drivers/gpu/nova-core/util.rs new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 + +/// Converts a null-terminated byte array to a string slice. +/// +/// Returns "invalid" if the bytes are not valid UTF-8 or not null-terminated. +pub (crate )fn str_from_null_terminated (bytes: &[u8 ]) -> &str { +use kernel::str::CStr ; + +// Find the first null byte, then create a slice that includes it. + bytes + .iter () + .position (|&b| b ==0 ) + .and_then (|null_pos|CStr ::from_bytes_with_nul (&bytes[..=null_pos]).ok ()) + .and_then (|cstr| cstr.to_str ().ok ()) + .unwrap_or ("invalid" ) +}
Signature · 1 line
2.34.1