From: Zhi Wang <[email protected]>

The vGPU manager reports the enabled bus-mastering state to the GSP plugin
after its initial configuration. The guest can then use the vGPU from now
on.

Add the BME state request and NVKV encoder, and send the enabled state
after configuration succeeds.

Co-developed-by: Eliot Courtney <[email protected]>
Signed-off-by: Eliot Courtney <[email protected]>
Signed-off-by: Zhi Wang <[email protected]>
Signed-off-by: Alok Kumar <[email protected]>
---
 drivers/gpu/nova-core/vgpu/commands.rs    | 11 +++++++++++
 drivers/gpu/nova-core/vgpu/fw/commands.rs | 18 ++++++++++++++++++
 drivers/gpu/nova-core/vgpu/instance.rs    |  4 +++-
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/nova-core/vgpu/commands.rs 
b/drivers/gpu/nova-core/vgpu/commands.rs
index 3517f29e5715..0456a928cf41 100644
--- a/drivers/gpu/nova-core/vgpu/commands.rs
+++ b/drivers/gpu/nova-core/vgpu/commands.rs
@@ -40,6 +40,7 @@
     vgpu::{
         fw::{
             commands::{
+                encode_plugin_set_bme,
                 AssignedVfVgpuType,
                 VgpuProperties,
                 VgpuPropertiesSchema, //
@@ -244,3 +245,13 @@ pub(super) fn send_plugin_config(
 ) -> Result {
     rpc.rpc_call_nvkv(dev, RpcMessage::SetupConfigParamsAndInit, config)
 }
+
+/// Update the bus-mastering state reported to the GSP plugin.
+pub(super) fn set_plugin_bme(
+    dev: &device::Device,
+    rpc: &mut PluginRpc<'_, '_, '_>,
+    enable: bool,
+) -> Result {
+    let bme = encode_plugin_set_bme(enable)?;
+    rpc.rpc_call_nvkv(dev, RpcMessage::UpdateBmeState, &bme)
+}
diff --git a/drivers/gpu/nova-core/vgpu/fw/commands.rs 
b/drivers/gpu/nova-core/vgpu/fw/commands.rs
index 2e70cf8b25b6..7d67a1172d3d 100644
--- a/drivers/gpu/nova-core/vgpu/fw/commands.rs
+++ b/drivers/gpu/nova-core/vgpu/fw/commands.rs
@@ -37,6 +37,7 @@
 pub(crate) enum RpcMessage {
     VersionNegotiation = 
bindings::MESSAGE_NV_VGPU_CPU_RPC_MSG_VERSION_NEGOTIATION,
     SetupConfigParamsAndInit = 
bindings::MESSAGE_NV_VGPU_CPU_RPC_MSG_SETUP_CONFIG_PARAMS_AND_INIT,
+    UpdateBmeState = bindings::MESSAGE_NV_VGPU_CPU_RPC_MSG_UPDATE_BME_STATE,
 }
 
 #[derive(Clone, Copy)]
@@ -329,6 +330,23 @@ pub(crate) fn encode_plugin_config_params(
     Ok(encoder.finish())
 }
 
+nvkv_encode! {
+    struct PluginSetBmeRequest {
+        bme_enable: Key<bool, 0x0100, u32>,
+    }
+}
+
+/// Encodes a plugin BME state update using the typed NVKV schema.
+pub(crate) fn encode_plugin_set_bme(enable: bool) -> Result<KVVec<u64>> {
+    let request = PluginSetBmeRequest {
+        bme_enable: enable.into(),
+    };
+
+    let mut encoder = Encoder::new();
+    request.encode(&mut encoder)?;
+    Ok(encoder.finish())
+}
+
 // TODO: extract from bindings
 #[repr(C)]
 #[derive(FromBytes, IntoBytes)]
diff --git a/drivers/gpu/nova-core/vgpu/instance.rs 
b/drivers/gpu/nova-core/vgpu/instance.rs
index d31f840997a7..91648ddf2d7c 100644
--- a/drivers/gpu/nova-core/vgpu/instance.rs
+++ b/drivers/gpu/nova-core/vgpu/instance.rs
@@ -35,7 +35,8 @@
         send_bootload,
         send_cleanup,
         send_plugin_config,
-        send_shutdown, //
+        send_shutdown,
+        set_plugin_bme, //
     },
     fw::commands::{
         encode_plugin_config_params,
@@ -167,6 +168,7 @@ fn activate(&mut self, vgpu: &VgpuManagerInner<'gpu>) -> 
Result {
         self.plugin_rpc.init_rpc()?;
         negotiate_plugin_version(dev, &mut self.plugin_rpc)?;
         self.configure_plugin(dev)?;
+        set_plugin_bme(dev, &mut self.plugin_rpc, true)?;
 
         Ok(())
     }

Reply via email to