-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathboot_params.rs
More file actions
89 lines (81 loc) · 2.74 KB
/
Copy pathboot_params.rs
File metadata and controls
89 lines (81 loc) · 2.74 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright (c) 2026 Microsoft Corporation
//
// Author: Jon Lange <jlange@microsoft.com>
use igvm_defs::PAGE_SIZE_4K;
#[derive(Clone, Copy, Debug)]
pub enum BootParamType {
General,
MemoryMap,
Madt,
DeviceTree,
GuestContext,
}
#[derive(Debug)]
pub struct BootParamLayout {
general_param_offset: u32,
memory_map_offset: u32,
madt_offset: u32,
device_tree_offset: u32,
device_tree_size: u32,
guest_context_offset: u32,
guest_context_size: u32,
total_size: u32,
}
impl BootParamLayout {
pub fn new(include_guest_context: bool, include_device_tree: bool) -> Self {
let page_size = PAGE_SIZE_4K as u32;
// If a guest context is present, it is the first parameter page after
// the parameter block header. Otherwise, no space is consumed.
let (guest_context_offset, guest_context_size) = if include_guest_context {
(page_size, page_size)
} else {
(0, 0)
};
let general_param_offset = page_size + guest_context_size;
let madt_offset = general_param_offset + page_size;
let memory_map_offset = madt_offset + page_size;
let (device_tree_offset, device_tree_size) = if include_device_tree {
(memory_map_offset + page_size, page_size)
} else {
(0, 0)
};
let total_size = memory_map_offset + page_size + device_tree_size;
Self {
general_param_offset,
memory_map_offset,
madt_offset,
device_tree_offset,
device_tree_size,
guest_context_offset,
guest_context_size,
total_size,
}
}
pub fn total_size(&self) -> u32 {
self.total_size
}
pub fn get_param_offset(&self, param_type: BootParamType) -> u32 {
match param_type {
BootParamType::General => self.general_param_offset,
BootParamType::MemoryMap => self.memory_map_offset,
BootParamType::Madt => self.madt_offset,
BootParamType::DeviceTree => self.device_tree_offset,
BootParamType::GuestContext => self.guest_context_offset,
}
}
pub fn get_param_size(&self, param_type: BootParamType) -> u32 {
match param_type {
BootParamType::GuestContext => self.guest_context_size,
BootParamType::DeviceTree => self.device_tree_size,
_ => {
// All other parameter types are currently a single page.
PAGE_SIZE_4K as u32
}
}
}
pub fn get_param_gpa(&self, param_base_gpa: u64, param_type: BootParamType) -> u64 {
param_base_gpa + self.get_param_offset(param_type) as u64
}
}