1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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 {
    /// Returns an iterator over all of the available memory regions
    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 {
    /// `compatible` property
    pub fn compatible(self) -> &'static str {
        self.node.compatible().unwrap().first()
    }

    /// `method` property
    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()
    }
    /// Optional`cpu_suspend` property
    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())
    }

    /// Optional`cpu_on` property
    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())
    }

    /// Optional`cpu_off` property
    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())
    }

    /// Optional`migrate` property
    pub fn migrate(self) -> Option<u32> {
        self.node
            .properties()
            .find(|p| p.name == "migrate")
            .map(|p| BigEndianU32::from_bytes(p.value).unwrap().get())
    }
}