@@ -2,8 +2,8 @@ use super::{
22 context:: { TestCtxTrait , VpExecutor } ,
33 hypercall:: HvCall ,
44} ;
5- use crate :: { debuglog, slog:: AssertResult } ;
65use crate :: uefi:: alloc:: ALLOCATOR ;
6+ use crate :: { debuglog, slog:: AssertResult } ;
77use crate :: {
88 infolog,
99 slog:: AssertOption ,
@@ -46,10 +46,7 @@ fn register_command_queue(vp_index: u32) {
4646 CMD . lock ( ) . insert ( vp_index, LinkedList :: new ( ) ) ;
4747 debuglog ! ( "registered command queue for vp: {}" , vp_index) ;
4848 } else {
49- debuglog ! (
50- "command queue already registered for vp: {}" ,
51- vp_index
52- ) ;
49+ debuglog ! ( "command queue already registered for vp: {}" , vp_index) ;
5350 }
5451 }
5552}
@@ -67,6 +64,71 @@ impl Drop for HvTestCtx {
6764 }
6865}
6966
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).
70132impl TestCtxTrait for HvTestCtx {
71133 fn start_on_vp ( & mut self , cmd : VpExecutor ) {
72134 let ( vp_index, vtl, cmd) = cmd. get ( ) ;
@@ -145,11 +207,11 @@ impl TestCtxTrait for HvTestCtx {
145207 }
146208
147209 fn switch_to_high_vtl ( & mut self ) {
148- HvCall :: high_vtl ( ) ;
210+ HvCall :: vtl_call ( ) ;
149211 }
150212
151213 fn switch_to_low_vtl ( & mut self ) {
152- HvCall :: low_vtl ( ) ;
214+ HvCall :: vtl_return ( ) ;
153215 }
154216
155217 fn setup_partition_vtl ( & mut self , vtl : Vtl ) {
0 commit comments