use super::{ProfileGroup, ProfileProvider, Setting, SettingRisk, SettingValue, Subsystem};
pub struct MemoryProfileProvider {
_private: (),
}
impl MemoryProfileProvider {
pub fn new() -> Self {
Self { _private: () }
}
}
impl Default for MemoryProfileProvider {
fn default() -> Self {
Self::new()
}
}
impl ProfileProvider for MemoryProfileProvider {
fn subsystem(&self) -> Subsystem {
Subsystem::Memory
}
fn snapshot(&mut self) -> Vec<ProfileGroup> {
let mut groups = super::spd_xmp::scan_xmp_groups();
let monitor = match crate::memory_topology::MemoryTopologyMonitor::new() {
Ok(m) => m,
Err(_) => return groups,
};
for dimm in monitor.populated_dimms() {
let label = format!(
"{} — {} {} ({} {:?})",
dimm.locator,
if dimm.manufacturer.is_empty() {
"Unknown"
} else {
&dimm.manufacturer
},
if dimm.part_number.is_empty() {
""
} else {
&dimm.part_number
},
dimm.capacity_gib()
.map_or_else(|| "size not read".to_string(), |g| format!("{g:.2} GiB")),
dimm.memory_type,
);
let mut g = ProfileGroup::new(
Subsystem::Memory,
label,
"DIMM SPD / configured",
"SMBIOS Type 17",
);
g.push(Setting::info(
"bank",
"Bank Locator",
SettingValue::Text(dimm.bank.clone()),
));
if let Some(rated) = dimm.speed_mts {
g.push(
Setting::info(
"rated_speed_mts",
"Rated Speed",
SettingValue::Uint(rated as u64),
)
.with_unit("MT/s")
.with_description("Maximum speed the DIMM is rated for (SPD)."),
);
}
if let Some(configured) = dimm.configured_speed_mts {
g.push(
Setting::info(
"configured_speed_mts",
"Configured Speed",
SettingValue::Uint(configured as u64),
)
.with_unit("MT/s")
.with_description(concat!(
"Speed the BIOS programmed at boot. If lower than Rated Speed, ",
"XMP/EXPO is likely disabled."
)),
);
}
match (dimm.configured_speed_mts, dimm.speed_mts) {
(Some(configured), Some(rated)) if configured < rated => {
g.note(format!(
concat!(
"DIMM is running at {} MT/s but is rated for {} MT/s — ",
"enable XMP/EXPO in BIOS to use the rated speed."
),
configured, rated
));
}
(None, Some(_)) => {
g.note(concat!(
"This platform did not report the configured memory speed, ",
"so whether XMP/EXPO is enabled cannot be determined here."
));
}
_ => {}
}
g.push(Setting::info(
"memory_type",
"Memory Type",
SettingValue::Text(format!("{:?}", dimm.memory_type)),
));
g.push(Setting::info(
"form_factor",
"Form Factor",
SettingValue::Text(format!("{:?}", dimm.form_factor)),
));
if let Some(voltage) = dimm.voltage {
g.push(
Setting::info("voltage_v", "Voltage", SettingValue::Float(voltage))
.with_unit("V")
.with_risk(SettingRisk::Dangerous)
.with_description(
"DIMM operating voltage. Overriding via XMP/EXPO can affect stability.",
),
);
}
if let Some(ranks) = dimm.ranks {
g.push(Setting::info(
"ranks",
"Ranks",
SettingValue::Uint(ranks as u64),
));
}
if let Some(w) = dimm.data_width_bits {
g.push(Setting::info(
"data_width_bits",
"Data Width",
SettingValue::Uint(w as u64),
));
}
if let Some(w) = dimm.total_width_bits {
g.push(Setting::info(
"total_width_bits",
"Total Width",
SettingValue::Uint(w as u64),
));
}
if let Some(ecc) = dimm.is_ecc() {
g.push(Setting::info("ecc", "ECC", SettingValue::Bool(ecc)));
}
if !dimm.serial_number.is_empty() {
g.push(Setting::info(
"serial_number",
"Serial Number",
SettingValue::Text(dimm.serial_number.clone()),
));
}
g.note(
"Raw XMP/EXPO profile blocks (full sub-timings, secondary/tertiary \
straps, voltages per profile) require direct SPD/SMBus reads and \
are not yet implemented.",
);
groups.push(g);
}
groups
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn smoke() {
let mut p = MemoryProfileProvider::new();
let _ = p.snapshot();
}
}