Skip to content

Commit a8148b4

Browse files
authored
adding device::gsp_firmware_mode/gsp_firmware_version() (#113)
1 parent 7a7fd69 commit a8148b4

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

nvml-wrapper/src/device.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6455,6 +6455,57 @@ impl<'nvml> Device<'nvml> {
64556455
}
64566456
}
64576457

6458+
/**
6459+
Get GSP firmware mode. Whether it is enabled and if it is in default mode.
6460+
6461+
# Errors
6462+
6463+
* `Uninitialized`, if the library has not been successfully initialized
6464+
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
6465+
* `Unknown`, on any unexpected error
6466+
* `NotSupported`, if the platform does not support this feature
6467+
*/
6468+
#[doc(alias = "nvmlDeviceGetGspFirmwareMode")]
6469+
pub fn gsp_firmware_mode(&self) -> Result<GspFirmwareMode, NvmlError> {
6470+
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetGspFirmwareMode.as_ref())?;
6471+
6472+
unsafe {
6473+
let mut enabled: c_uint = 0;
6474+
let mut default: c_uint = 0;
6475+
6476+
nvml_try(sym(self.device, &mut enabled, &mut default))?;
6477+
6478+
Ok(GspFirmwareMode {
6479+
enabled: enabled != 0,
6480+
default: default != 0,
6481+
})
6482+
}
6483+
}
6484+
6485+
/**
6486+
Get GSP firmware version.
6487+
6488+
# Errors
6489+
6490+
* `Uninitialized`, if the library has not been successfully initialized
6491+
* `GpuLost`, if this `Device` has fallen off the bus or is otherwise inaccessible
6492+
* `Unknown`, on any unexpected error
6493+
* `NotSupported`, if the platform does not support this feature
6494+
*/
6495+
#[doc(alias = "nvmlDeviceGetGspFirmwareVersion")]
6496+
pub fn gsp_firmware_version(&self) -> Result<String, NvmlError> {
6497+
let sym = nvml_sym(self.nvml.lib.nvmlDeviceGetGspFirmwareVersion.as_ref())?;
6498+
6499+
unsafe {
6500+
let mut version = vec![0; 80];
6501+
6502+
nvml_try(sym(self.device, version.as_mut_ptr()))?;
6503+
let raw = CStr::from_ptr(version.as_ptr());
6504+
6505+
Ok(raw.to_str()?.into())
6506+
}
6507+
}
6508+
64586509
// NvLink
64596510

64606511
/**
@@ -7213,6 +7264,18 @@ mod test {
72137264
})
72147265
}
72157266

7267+
#[test]
7268+
fn gsp_firmware_mode() {
7269+
let nvml = nvml();
7270+
test_with_device(3, &nvml, |device| device.gsp_firmware_mode())
7271+
}
7272+
7273+
#[test]
7274+
fn gsp_firmware_version() {
7275+
let nvml = nvml();
7276+
test_with_device(3, &nvml, |device| device.gsp_firmware_version())
7277+
}
7278+
72167279
#[test]
72177280
fn field_values_for() {
72187281
let nvml = nvml();

nvml-wrapper/src/structs/device.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,11 @@ pub struct MigMode {
177177
/// Mode set after reboot.
178178
pub pending: u32,
179179
}
180+
181+
/// Returned from `Device.gsp_firmware_mode()`
182+
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
183+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
184+
pub struct GspFirmwareMode {
185+
pub enabled: bool,
186+
pub default: bool,
187+
}

nvml-wrapper/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl ShouldPrint for MigMode {}
113113
impl ShouldPrint for Vec<GpuInstancePlacement> {}
114114
impl ShouldPrint for (VgpuVersion, VgpuVersion) {}
115115
impl ShouldPrint for ProfileInfo {}
116+
impl ShouldPrint for GspFirmwareMode {}
116117

117118
#[cfg(target_os = "windows")]
118119
impl ShouldPrint for DriverModelState {}

0 commit comments

Comments
 (0)