Alioth Code Coverage

dt.rs80.00%

1// Copyright 2024 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15pub mod dtb;
16
17use std::collections::HashMap;
18use std::mem::size_of_val;
19
20#[derive(Debug, Clone)]
21pub enum PropVal {
22 Empty,
23 U32(u32),
24 U64(u64),
25 String(String),
26 Str(&'static str),
27 PHandle(u32),
28 StringList(Vec<String>),
29 U32List(Vec<u32>),
30 U64List(Vec<u64>),
31 Bytes(Vec<u8>),
32}
33
34impl PropVal {
35 pub fn size(&self) -> usize {30x
36 match self {30x
37 PropVal::Empty => 0,3x
38 PropVal::U32(_) | PropVal::PHandle(_) => 4,6x
39 PropVal::U64(_) => 8,3x
40 PropVal::String(s) => s.len() + 1,3x
41 PropVal::Str(s) => s.len() + 1,3x
42 PropVal::Bytes(d) => d.len(),3x
43 PropVal::U32List(r) => size_of_val(r.as_slice()),3x
44 PropVal::U64List(r) => size_of_val(r.as_slice()),3x
45 PropVal::StringList(l) => l.iter().map(|s| s.len() + 1).sum(),6x
46 }
47 }30x
48}
49
50#[derive(Debug, Clone, Default)]
51pub struct Node {
52 pub props: HashMap<&'static str, PropVal>,
53 pub nodes: Vec<(String, Node)>,
54}
55
56#[derive(Debug, Clone, Default)]
57pub struct DeviceTree {
58 pub root: Node,
59 pub reserved_mem: Vec<(usize, usize)>,
60 pub boot_cpuid_phys: u32,
61}
62
63impl DeviceTree {
64 pub fn new() -> Self {
65 DeviceTree::default()
66 }
67}
68
69#[cfg(test)]
70#[path = "dt_test.rs"]
71mod tests;
72