Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions build/i2c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,27 @@ pub struct I2cDeviceDescription {
pub sensors: Vec<DeviceSensor>,
pub device_id: Option<String>,
pub name: Option<String>,
/// If this is a PMBus device, this field contains additional data about the
/// PMBus device to be used for generating PMBus-y code.
pub pmbus: Option<PmbusDeviceDescription>,
}

#[derive(Debug, Clone)]
pub struct PmbusDeviceDescription {
pub rails: Vec<PmbusRailDescription>,
}

#[derive(Debug, Clone)]
pub struct PmbusRailDescription {
pub name: String,
pub phases: Vec<u8>,
}

impl I2cDeviceDescription {
/// Returns `true` if this device is a PMBus device.
pub fn is_pmbus(&self) -> bool {
self.pmbus.is_some()
}
}

///
Expand All @@ -1801,12 +1822,59 @@ pub fn device_descriptions() -> impl Iterator<Item = I2cDeviceDescription> {
g.devices.into_iter().zip(sensors.device_sensors).map(
|(device, sensors)| {
let device_id = device.refdes.as_ref().map(Refdes::to_component_id);
let pmbus = device.power.as_ref().and_then(|power| {
if !power.pmbus {
return None;
}

let rails = match (power.rails.as_ref(), power.phases.as_ref())
{
(Some(rails), Some(phases)) => {
assert_eq!(
rails.len(),
phases.len(),
"invalid config: PMBus device {device_id:?}'s \
`power.rails` and `power.phases` lists are not \
the same length"
);
rails
.iter()
.cloned()
.zip(phases.iter().cloned())
.map(|(name, phases)| PmbusRailDescription {
name,
phases,
})
.collect()
}
(Some(rails), None) => rails
.iter()
.cloned()
.map(|name| PmbusRailDescription {
name,
phases: Vec::new(),
})
.collect(),
(None, Some(_)) => {
panic!(
"invalid config: PMBus device {device_id:?} \
defines a `power.phases` list, but not a \
`power.rails` list"
);
}
(None, None) => Vec::new(),
};

Some(PmbusDeviceDescription { rails })
});

I2cDeviceDescription {
device: device.device,
description: device.description,
sensors,
device_id,
name: device.name,
pmbus,
}
},
)
Expand Down
3 changes: 3 additions & 0 deletions task/control-plane-agent/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ impl Inventory {
};

let mut capabilities = DeviceCapabilities::empty();
if device.is_pmbus {
capabilities |= DeviceCapabilities::IS_PMBUS;
}
if !device.sensors.is_empty() {
capabilities |= DeviceCapabilities::HAS_MEASUREMENT_CHANNELS;
}
Expand Down
4 changes: 3 additions & 1 deletion task/validate-api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ fn write_pub_device_descriptions() -> anyhow::Result<()> {
let mut id2idx = std::collections::BTreeMap::new();

for (idx, dev) in devices.into_iter().enumerate() {
let is_pmbus = dev.is_pmbus();
writeln!(file, " DeviceDescription {{")?;
writeln!(file, " device: {:?},", dev.device)?;
writeln!(file, " description: {:?},", dev.description)?;
if let Some(id) = dev.device_id {
if let Ok(component) = SpComponent::try_from(id.as_ref()) {
write!(file, " id: {:?},", component.id)?;
writeln!(file, " id: {:?},", component.id)?;
if id2idx.insert(component.id, idx).is_some() {
println!("cargo::error=duplicate device id {id:?}",);
duplicate_ids += 1;
Expand All @@ -83,6 +84,7 @@ fn write_pub_device_descriptions() -> anyhow::Result<()> {
);
missing_ids += 1;
};
writeln!(file, " is_pmbus: {is_pmbus:?},")?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically you want an extra newline before this, or you could change line 68 to a writeln!

DeviceDescription {
    device: "at24csw080",
    description: "U.2 Sharkfin A VPD",
    id: [74, 50, 48, 48, 47, 85, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0],        is_pmbus: false,
    sensors: &[
    ],
},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ew, whoops

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out this was, amusingly, a preexisting bug --- the bit that writes out the device ID was using write! rather than writeln!. before this PR it would have been sensors: &[ that would be jammed at the end of the line.

in any case, i fixed it.

writeln!(file, " sensors: &[")?;
for s in dev.sensors {
writeln!(file, " SensorDescription {{")?;
Expand Down
1 change: 1 addition & 0 deletions task/validate-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct DeviceDescription {
pub description: &'static str,
pub sensors: &'static [SensorDescription],
pub id: [u8; MAX_ID_LENGTH],
pub is_pmbus: bool,
}

include!(concat!(env!("OUT_DIR"), "/device_descriptions.rs"));
Loading