From 280b1c29bfa96373225b21f8abffa9fbdae81e58 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 5 Jul 2025 09:37:12 +0100 Subject: [PATCH 1/2] adding device::gsp_firmware_mode/gsp_firmware_version() --- nvml-wrapper/src/device.rs | 60 ++++++++++++++++++++++++++++++++++ nvml-wrapper/src/test_utils.rs | 1 + 2 files changed, 61 insertions(+) diff --git a/nvml-wrapper/src/device.rs b/nvml-wrapper/src/device.rs index e6c9117..3c21257 100644 --- a/nvml-wrapper/src/device.rs +++ b/nvml-wrapper/src/device.rs @@ -6455,6 +6455,54 @@ impl<'nvml> Device<'nvml> { } } + /** + Get GSP firmware mode. Whether it is enabled and if it is in default mode. + + # Errors + + * `Uninitialized`, if the library has not been successfully initialized + * `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible + * `Unknown`, on any unexpected error + * `NotSupported`, if the platform does not support this feature + */ + #[doc(alias = "nvmlDeviceGetGspFirmwareMode")] + pub fn gsp_firmware_mode(&self) -> Result<(bool, bool), NvmlError> { + let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetGspFirmwareMode.as_ref())?; + + unsafe { + let mut enabled: c_uint = 0; + let mut default: c_uint = 0; + + nvml_try(sym(self.device, &mut enabled, &mut default))?; + + Ok((enabled != 0, default != 0)) + } + } + + /** + Get GSP firmware version. + + # Errors + + * `Uninitialized`, if the library has not been successfully initialized + * `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible + * `Unknown`, on any unexpected error + * `NotSupported`, if the platform does not support this feature + */ + #[doc(alias = "nvmlDeviceGetGspFirmwareVersion")] + pub fn gsp_firmware_version(&self) -> Result { + let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetGspFirmwareVersion.as_ref())?; + + unsafe { + let mut version = vec![0; 80]; + + nvml_try(sym(self.device, version.as_mut_ptr()))?; + let raw = CStr::from_ptr(version.as_ptr()); + + Ok(raw.to_str()?.into()) + } + } + // NvLink /** @@ -7213,6 +7261,18 @@ mod test { }) } + #[test] + fn gsp_firmware_mode() { + let nvml = nvml(); + test_with_device(3, &nvml, |device| device.gsp_firmware_mode()) + } + + #[test] + fn gsp_firmware_version() { + let nvml = nvml(); + test_with_device(3, &nvml, |device| device.gsp_firmware_version()) + } + #[test] fn field_values_for() { let nvml = nvml(); diff --git a/nvml-wrapper/src/test_utils.rs b/nvml-wrapper/src/test_utils.rs index 528651b..be3e41e 100644 --- a/nvml-wrapper/src/test_utils.rs +++ b/nvml-wrapper/src/test_utils.rs @@ -113,6 +113,7 @@ impl ShouldPrint for MigMode {} impl ShouldPrint for Vec {} impl ShouldPrint for (VgpuVersion, VgpuVersion) {} impl ShouldPrint for ProfileInfo {} +impl ShouldPrint for GspFirmwareMode {} #[cfg(target_os = "windows")] impl ShouldPrint for DriverModelState {} From 826a52e15d41c02f5961cfc42496a708364ed280 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 8 Dec 2025 23:07:21 +0000 Subject: [PATCH 2/2] feedback --- nvml-wrapper/src/device.rs | 7 +++++-- nvml-wrapper/src/structs/device.rs | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/nvml-wrapper/src/device.rs b/nvml-wrapper/src/device.rs index 3c21257..2c696c3 100644 --- a/nvml-wrapper/src/device.rs +++ b/nvml-wrapper/src/device.rs @@ -6466,7 +6466,7 @@ impl<'nvml> Device<'nvml> { * `NotSupported`, if the platform does not support this feature */ #[doc(alias = "nvmlDeviceGetGspFirmwareMode")] - pub fn gsp_firmware_mode(&self) -> Result<(bool, bool), NvmlError> { + pub fn gsp_firmware_mode(&self) -> Result { let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetGspFirmwareMode.as_ref())?; unsafe { @@ -6475,7 +6475,10 @@ impl<'nvml> Device<'nvml> { nvml_try(sym(self.device, &mut enabled, &mut default))?; - Ok((enabled != 0, default != 0)) + Ok(GspFirmwareMode { + enabled: enabled != 0, + default: default != 0, + }) } } diff --git a/nvml-wrapper/src/structs/device.rs b/nvml-wrapper/src/structs/device.rs index 4ce3479..871e1ea 100644 --- a/nvml-wrapper/src/structs/device.rs +++ b/nvml-wrapper/src/structs/device.rs @@ -177,3 +177,11 @@ pub struct MigMode { /// Mode set after reboot. pub pending: u32, } + +/// Returned from `Device.gsp_firmware_mode()` +#[derive(Debug, Clone, Eq, PartialEq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct GspFirmwareMode { + pub enabled: bool, + pub default: bool, +}