use crate::parsing::BigEndianU32;
use fdt::standard_nodes::MemoryRegion;
#[derive(Clone, Copy)]
pub struct Memory {
pub(crate) node: fdt::node::FdtNode<'static, 'static>,
}
impl Memory {
pub fn regions(self) -> impl Iterator<Item = MemoryRegion> + 'static {
self.node.reg().unwrap()
}
}
#[derive(Clone, Copy)]
pub struct Pcsi {
pub(crate) node: fdt::node::FdtNode<'static, 'static>,
}
impl Pcsi {
pub fn compatible(self) -> &'static str {
self.node.compatible().unwrap().first()
}
pub fn method(self) -> &'static str {
self.node
.properties()
.find(|p| p.name == "method")
.and_then(|p| {
core::str::from_utf8(p.value)
.map(|s| s.trim_end_matches('\0'))
.ok()
})
.unwrap()
}
pub fn cpu_suspend(self) -> Option<u32> {
self.node
.properties()
.find(|p| p.name == "cpu_suspend")
.map(|p| BigEndianU32::from_bytes(p.value).unwrap().get())
}
pub fn cpu_on(self) -> Option<u32> {
self.node
.properties()
.find(|p| p.name == "cpu_on")
.map(|p| BigEndianU32::from_bytes(p.value).unwrap().get())
}
pub fn cpu_off(self) -> Option<u32> {
self.node
.properties()
.find(|p| p.name == "cpu_off")
.map(|p| BigEndianU32::from_bytes(p.value).unwrap().get())
}
pub fn migrate(self) -> Option<u32> {
self.node
.properties()
.find(|p| p.name == "migrate")
.map(|p| BigEndianU32::from_bytes(p.value).unwrap().get())
}
}