From: Alexandre Courbot Some GMC commands are not answered, and report their completion with a separate event instead. Receiving that event after releasing the queue would let another receiver, such as the interrupt thread, consume it. Add a method that sends such a command and offers the GMC events that follow to a closure until it accepts one, all under a single lock of the queue. The wait is bounded by the command's `COMPLETION_TIMEOUT`. Signed-off-by: Alexandre Courbot Signed-off-by: Alok Kumar --- drivers/gpu/nova-core/gsp/cmdq/gmc.rs | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs index bf54f73afbc8..d4017c2e04ce 100644 --- a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs +++ b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs @@ -349,6 +349,50 @@ pub(crate) fn send_gmc_command( }) } + /// Sends `command`, which the GSP does not answer, and waits for the event that completes it. + /// + /// GMC events are passed to `on_event` until it returns `Ok(Some(_))`, which ends the wait. + /// Other messages are logged and consumed. + /// + /// The queue is locked for the entire send+receive cycle, including the calls to `on_event`, + /// so that no other receiver can consume the event. `on_event` must thus not use the queue. + /// + /// # Errors + /// + /// - `EMSGSIZE` if the command does not fit in a single command queue element. + /// - `ETIMEDOUT` if space does not become available to send the command, or if `on_event` + /// accepts no event within [`CommandToGsp::COMPLETION_TIMEOUT`] of the send. + /// - `EIO` if the variable payload requested by the command has not been entirely + /// written to by its [`CommandToGsp::init_variable_payload`] method, or if a message fails + /// framing validation. + /// + /// Error codes returned by the command initializer and by `on_event` are propagated as-is. + #[expect(dead_code)] + pub(crate) fn send_gmc_command_await_event( + &self, + command: C, + on_event: impl Fn(&GmcMessage<'_>) -> Result>, + ) -> Result + where + C: CommandToGsp, + Error: From, + { + self.with_inner_locked(|inner| { + inner.send_gmc_command(command)?; + let dev = inner.dev; + + inner.await_msg_with(C::COMPLETION_TIMEOUT, |message| match message { + GspParsedMessage::Gmc(event) if !event.header.command().is_response() => { + on_event(&event) + } + _ => { + message.log(dev); + Ok(None) + } + }) + }) + } + /// Sends `command` to the GSP without waiting for a reply. /// /// # Errors -- 2.53.0