@@ -2,8 +2,8 @@ use super::{
2
2
context:: { TestCtxTrait , VpExecutor } ,
3
3
hypercall:: HvCall ,
4
4
} ;
5
- use crate :: { debuglog, slog:: AssertResult } ;
6
5
use crate :: uefi:: alloc:: ALLOCATOR ;
6
+ use crate :: { debuglog, slog:: AssertResult } ;
7
7
use crate :: {
8
8
infolog,
9
9
slog:: AssertOption ,
@@ -46,10 +46,7 @@ fn register_command_queue(vp_index: u32) {
46
46
CMD . lock ( ) . insert ( vp_index, LinkedList :: new ( ) ) ;
47
47
debuglog ! ( "registered command queue for vp: {}" , vp_index) ;
48
48
} else {
49
- debuglog ! (
50
- "command queue already registered for vp: {}" ,
51
- vp_index
52
- ) ;
49
+ debuglog ! ( "command queue already registered for vp: {}" , vp_index) ;
53
50
}
54
51
}
55
52
}
@@ -67,6 +64,71 @@ impl Drop for HvTestCtx {
67
64
}
68
65
}
69
66
67
+ /// Implementation of the `TestCtxTrait` for the `HvTestCtx` structure, providing
68
+ /// various methods to manage and interact with virtual processors (VPs) and
69
+ /// Virtual Trust Levels (VTLs) in a hypervisor context.
70
+ ///
71
+ /// # Methods
72
+ ///
73
+ /// - `start_on_vp(&mut self, cmd: VpExecutor)`:
74
+ /// Starts a virtual processor (VP) on a specified VTL. Handles enabling VTLs,
75
+ /// switching between high and low VTLs, and managing VP execution contexts.
76
+ ///
77
+ /// - `queue_command_vp(&mut self, cmd: VpExecutor)`:
78
+ /// Queues a command for a specific VP and VTL.
79
+ ///
80
+ /// - `switch_to_high_vtl(&mut self)`:
81
+ /// Switches the current execution context to a high VTL.
82
+ ///
83
+ /// - `switch_to_low_vtl(&mut self)`:
84
+ /// Switches the current execution context to a low VTL.
85
+ ///
86
+ /// - `setup_partition_vtl(&mut self, vtl: Vtl)`:
87
+ /// Configures the partition to enable a specified VTL.
88
+ ///
89
+ /// - `setup_interrupt_handler(&mut self)`:
90
+ /// Sets up the interrupt handler for the architecture.
91
+ ///
92
+ /// - `setup_vtl_protection(&mut self)`:
93
+ /// Enables VTL protection for the current partition.
94
+ ///
95
+ /// - `setup_secure_intercept(&mut self, interrupt_idx: u8)`:
96
+ /// Configures secure intercept for a specified interrupt index, including
97
+ /// setting up the SIMP and SINT0 registers.
98
+ ///
99
+ /// - `apply_vtl_protection_for_memory(&mut self, range: Range<u64>, vtl: Vtl)`:
100
+ /// Applies VTL protections to a specified memory range.
101
+ ///
102
+ /// - `write_msr(&mut self, msr: u32, value: u64)`:
103
+ /// Writes a value to a specified Model-Specific Register (MSR).
104
+ ///
105
+ /// - `read_msr(&mut self, msr: u32) -> u64`:
106
+ /// Reads the value of a specified Model-Specific Register (MSR).
107
+ ///
108
+ /// - `start_running_vp_with_default_context(&mut self, cmd: VpExecutor)`:
109
+ /// Starts a VP with the default execution context.
110
+ ///
111
+ /// - `set_default_ctx_to_vp(&mut self, vp_index: u32, vtl: Vtl)`:
112
+ /// Sets the default execution context for a specified VP and VTL.
113
+ ///
114
+ /// - `enable_vp_vtl_with_default_context(&mut self, vp_index: u32, vtl: Vtl)`:
115
+ /// Enables a VTL for a specified VP using the default execution context.
116
+ ///
117
+ /// - `set_interupt_idx(&mut self, interrupt_idx: u8, handler: fn())`:
118
+ /// Sets an interrupt handler for a specified interrupt index. (x86_64 only)
119
+ ///
120
+ /// - `get_vp_count(&self) -> u32`:
121
+ /// Retrieves the number of virtual processors available on the system.
122
+ ///
123
+ /// - `get_register(&mut self, reg: u32) -> u128`:
124
+ /// Retrieves the value of a specified register. Supports both x86_64 and
125
+ /// aarch64 architectures.
126
+ ///
127
+ /// - `get_current_vp(&self) -> u32`:
128
+ /// Returns the index of the current virtual processor.
129
+ ///
130
+ /// - `get_current_vtl(&self) -> Vtl`:
131
+ /// Returns the current Virtual Trust Level (VTL).
70
132
impl TestCtxTrait for HvTestCtx {
71
133
fn start_on_vp ( & mut self , cmd : VpExecutor ) {
72
134
let ( vp_index, vtl, cmd) = cmd. get ( ) ;
@@ -145,11 +207,11 @@ impl TestCtxTrait for HvTestCtx {
145
207
}
146
208
147
209
fn switch_to_high_vtl ( & mut self ) {
148
- HvCall :: high_vtl ( ) ;
210
+ HvCall :: vtl_call ( ) ;
149
211
}
150
212
151
213
fn switch_to_low_vtl ( & mut self ) {
152
- HvCall :: low_vtl ( ) ;
214
+ HvCall :: vtl_return ( ) ;
153
215
}
154
216
155
217
fn setup_partition_vtl ( & mut self , vtl : Vtl ) {
0 commit comments