From: John Hubbard <[email protected]> The two load-and-execute events of the r000 boot protocol arrive as GMC events, and the command ID of a GMC event names its kind. Nova-core has a handler for each of the two events, and no code that selects the handler from the command ID.
Add a dispatcher that selects the handler from the command ID of a GMC event, decodes the payload of the event into the parameters of that handler, and rejects an event with any other command ID. Co-developed-by: Alexandre Courbot <[email protected]> Signed-off-by: Alexandre Courbot <[email protected]> Signed-off-by: John Hubbard <[email protected]> [ecourtney: check MAILBOX0 and call `resume_gsp_rm()` here, for both events] [ecourtney: move some methods to be impls of `GspBootContext`] Signed-off-by: Eliot Courtney <[email protected]> --- drivers/gpu/nova-core/gsp/load_exec.rs | 84 ++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs index 4dbb27dc03a1..b42be7393946 100644 --- a/drivers/gpu/nova-core/gsp/load_exec.rs +++ b/drivers/gpu/nova-core/gsp/load_exec.rs @@ -40,7 +40,11 @@ GenericBootloader, // }, gsp::{ - cmdq::gmc::MessageFromGsp, + cmdq::gmc::{ + GmcMessage, + MessageFromGsp, // + }, + fw::GmcCommandId, GspBootContext, // }, sbuffer::SBufferIter, // @@ -113,6 +117,82 @@ pub(super) fn resume_gsp_rm( } impl GspBootContext<'_, '_> { + /// Runs the handler of the load-and-execute event `event`. + /// + /// The command ID of `event` selects the handler, and the payload of `event` + /// holds the parameters of that handler. `bootloader` is the generic falcon + /// bootloader, which the handler of a `GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER` + /// event requires. Each handler is followed by [`resume_gsp_rm`], which + /// receives `libos_dma_address` and `bootloader_app_version`. + /// + /// # Errors + /// + /// - `EINVAL` if the command ID of `event` is not that of a load-and-execute + /// event, or if the payload of `event` is shorter than the parameters of + /// the handler. + /// + /// Errors from the handlers and from the resume of GSP-RM are propagated + /// as-is. + #[expect(dead_code)] + pub(super) fn handle_load_exec_event( + &self, + bootloader: Option<&GenericBootloader>, + libos_dma_address: DmaAddress, + bootloader_app_version: u32, + event: &GmcMessage<'_>, + ) -> Result { + let dev = self.dev(); + let command = event.header().command(); + let (slice_1, slice_2) = event.payload(); + let mut payload = SBufferIter::new_reader([slice_1, slice_2]); + + let (id, result) = match command.id() { + Ok(id @ GmcCommandId::ExecGenericBootloader) => ( + id, + GenericBootloaderParams::read(&mut payload) + .and_then(|params| self.handle_generic_bootloader(bootloader, ¶ms)), + ), + Ok(id @ GmcCommandId::ExecHsBinary) => ( + id, + HsBinaryParams::read(&mut payload) + .and_then(|params| self.handle_hs_binary(¶ms)), + ), + _ => { + dev_err!(dev, "Not a load-and-execute event: {:?}\n", command); + return Err(EINVAL); + } + }; + + result + .and_then(|mbox0| { + if mbox0 == FLCN_ERR_BINARY_NOT_STARTED { + dev_err!( + dev, + "Binary of load-and-execute event {:?} did not start\n", + id + ); + } else { + dev_dbg!( + dev, + "Binary of load-and-execute event {:?} halted with mbox0={:#x}\n", + id, + mbox0 + ); + } + + resume_gsp_rm( + dev, + self.gsp_falcon, + self.sec2_falcon, + libos_dma_address, + bootloader_app_version, + ) + }) + .inspect_err(|e| { + dev_err!(dev, "Load-and-execute event {:?} failed: {:?}\n", id, e); + }) + } + /// Waits until GSP-RM has suspended the RISC-V core, and then resets the GSP /// falcon. fn reset_gsp_falcon_after_suspend(&self) -> Result { @@ -157,7 +237,6 @@ fn reset_gsp_falcon_after_suspend(&self) -> Result { /// /// Errors from the reset of the GSP falcon and the DMA transfers are /// propagated as-is. - #[expect(dead_code)] fn handle_hs_binary(&self, params: &HsBinaryParams) -> Result<u32> { let dev = self.dev(); let gsp_falcon = self.gsp_falcon; @@ -209,7 +288,6 @@ fn handle_hs_binary(&self, params: &HsBinaryParams) -> Result<u32> { /// /// Errors from the reset of the GSP falcon and the run of the bootloader are /// propagated as-is. - #[expect(dead_code)] fn handle_generic_bootloader( &self, bootloader: Option<&GenericBootloader>, -- 2.56.1
