From: John Hubbard <[email protected]>

The r000 firmware suspends GSP-RM on a GSP_SUSPEND request, a GMC
command whose payload is one word of flags. GSP-RM sends no response on
the message queue, and reports the completed suspend in the GSP falcon's
MAILBOX0 register instead.

Signed-off-by: John Hubbard <[email protected]>
[acourbot: set GMCAPI_GSP_SUSPEND_FLAGS_HIBERNATE for Level7.]
[acourbot: use bitfield and drop the FromBytes/AsBytes impls.]
Co-developed-by: Alexandre Courbot <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
---
 drivers/gpu/nova-core/gsp/commands/gmc.rs | 42 ++++++++++++++++++++++++++++---
 drivers/gpu/nova-core/gsp/fw/commands.rs  | 19 ++++++++++++++
 2 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/commands/gmc.rs 
b/drivers/gpu/nova-core/gsp/commands/gmc.rs
index f0a0a6798d6b..cec66b80c489 100644
--- a/drivers/gpu/nova-core/gsp/commands/gmc.rs
+++ b/drivers/gpu/nova-core/gsp/commands/gmc.rs
@@ -16,12 +16,19 @@
 use crate::{
     gpu::Chipset,
     gsp::{
-        cmdq::gmc::{
-            CommandToGsp,
-            MessageFromGsp, //
+        cmdq::{
+            gmc::{
+                CommandToGsp,
+                MessageFromGsp, //
+            },
+            NoReply, //
+        },
+        commands::{
+            GspStaticInfo,
+            PowerStateLevel, //
         },
-        commands::GspStaticInfo,
         fw::{
+            self,
             commands::{
                 GspInitRequest,
                 GspInitResponseSchema, //
@@ -101,6 +108,33 @@ fn init_variable_payload(
     }
 }
 
+/// The `GSP_SUSPEND` command, which suspends GSP-RM.
+///
+/// GSP-RM sends no reply on the message queue. It reports the completed 
suspend in the GSP
+/// falcon's `MAILBOX0` register instead.
+pub(crate) struct GspSuspend {
+    level: PowerStateLevel,
+}
+
+impl GspSuspend {
+    /// Creates a `GSP_SUSPEND` command for the given [`PowerStateLevel`].
+    pub(crate) fn new(level: PowerStateLevel) -> Self {
+        Self { level }
+    }
+}
+
+impl CommandToGsp for GspSuspend {
+    const COMMAND: GmcCommandId = GmcCommandId::GspSuspend;
+    type Command = u64;
+    type Reply = NoReply;
+    const MAX_REPLY_SIZE: u32 = 0;
+    type InitError = Infallible;
+
+    fn init(&self) -> impl Init<Self::Command, Self::InitError> {
+        u64::from(fw::commands::GspSuspendFlags::from(self.level))
+    }
+}
+
 impl MessageFromGsp for GspStaticInfo {
     type InitError = Error;
 
diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs 
b/drivers/gpu/nova-core/gsp/fw/commands.rs
index 791a336bce16..2dae9f19b6c6 100644
--- a/drivers/gpu/nova-core/gsp/fw/commands.rs
+++ b/drivers/gpu/nova-core/gsp/fw/commands.rs
@@ -276,6 +276,25 @@ pub(crate) fn is_power_transition(self) -> bool {
     }
 }
 
+bitfield! {
+    /// Flags of the `GSP_SUSPEND` GMC command.
+    pub(crate) struct GspSuspendFlags(u64) {
+        /// GSP is being suspended as part of a power management transition 
(S3, hibernate, etc.)
+        /// rather than a full unload.
+        0:0 pm_transition => bool;
+        /// Hibernate (suspend to disk).
+        2:2 hibernate => bool;
+    }
+}
+
+impl From<PowerStateLevel> for GspSuspendFlags {
+    fn from(level: PowerStateLevel) -> Self {
+        Self::zeroed()
+            .with_pm_transition(level.is_power_transition())
+            .with_hibernate(level == PowerStateLevel::Level7)
+    }
+}
+
 /// Payload of the `UnloadingGuestDriver` command and message.
 #[repr(transparent)]
 #[derive(Clone, Copy, Debug, Zeroable)]

-- 
2.56.1

Reply via email to