|
2 | 2 | //
|
3 | 3 | // SPDX-License-Identifier: Apache-2.0
|
4 | 4 |
|
5 |
| -use paste::paste; |
6 |
| - |
7 | 5 | use core::sync::atomic::{AtomicU8, Ordering};
|
8 | 6 | pub use td_exception::*;
|
9 | 7 | use td_payload::arch::apic::{disable, enable_and_hlt};
|
10 | 8 | use td_payload::interrupt_handler_template;
|
| 9 | + |
11 | 10 | pub const NOTIFY_VALUE_CLEAR: u8 = 0;
|
12 | 11 | pub const NOTIFY_VALUE_SET: u8 = 1;
|
13 | 12 |
|
14 |
| -#[macro_export] |
15 |
| -macro_rules! register_interrupt { |
16 |
| - ($name:ident, $notifiy_vector:expr) => { |
17 |
| - |
18 |
| - paste! { |
19 |
| - const [<NOTIFY_VECTOR_ $name:upper>]: u8 = $notifiy_vector; |
20 |
| - static [<NOTIFY_ $name:upper>]: AtomicU8 = AtomicU8::new(NOTIFY_VALUE_CLEAR); |
21 |
| - interrupt_handler_template!([<vmm_notification_ $name:lower>], _stack, { |
22 |
| - [<NOTIFY_ $name:upper>].store(NOTIFY_VALUE_SET, Ordering::SeqCst); |
23 |
| - }); |
24 |
| - |
25 |
| - pub fn [<register_vmm_notification_ $name:lower>]() { |
26 |
| - // log::info!("Calling {:?}", stringify!([<register_vmm_notification_ $name:lower>])); |
27 |
| - // #[cfg(test)] |
28 |
| - // return; |
29 |
| - |
30 |
| - // Setup interrupt handler |
31 |
| - unsafe { |
32 |
| - idt::register_handler([<NOTIFY_VECTOR_ $name:upper>], [<vmm_notification_ $name:lower>]); |
33 |
| - } |
34 |
| - } |
35 |
| - |
36 |
| - pub fn [<wait_for_vmm_notification_ $name:lower>]() { |
37 |
| - // #[cfg(test)] |
38 |
| - // return; |
39 |
| - |
40 |
| - // log::info!("Calling {:?}", stringify!([<wait_for_vmm_notification_ $name:lower>])); |
| 13 | +// 32~255 are available |
| 14 | +pub const INTERRUPT_VECTOR_WAIT_FOR_REQUEST: u8 = 32; |
41 | 15 |
|
42 |
| - while([<NOTIFY_ $name:upper>].load(Ordering::SeqCst) != NOTIFY_VALUE_SET){ |
43 |
| - enable_and_hlt(); |
44 |
| - if ([<NOTIFY_ $name:upper>].load(Ordering::SeqCst) == NOTIFY_VALUE_SET){ |
45 |
| - break; |
46 |
| - } |
47 |
| - } |
48 |
| - disable(); |
| 16 | +// Define a static atomic variable to store the notification state. |
| 17 | +static NOTIFY_WAIT_FOR_REQUEST: AtomicU8 = AtomicU8::new(NOTIFY_VALUE_CLEAR); |
| 18 | +const NOTIFY_VECTOR_WAIT_FOR_REQUEST: u8 = INTERRUPT_VECTOR_WAIT_FOR_REQUEST; |
| 19 | + |
| 20 | +// Define the interrupt handler via the provided interrupt_handler_template macro. |
| 21 | +interrupt_handler_template!(vmm_notification_wait_for_request, _stack, { |
| 22 | + NOTIFY_WAIT_FOR_REQUEST.store(NOTIFY_VALUE_SET, Ordering::SeqCst); |
| 23 | +}); |
| 24 | + |
| 25 | +// Function to register the VMM notification interrupt. |
| 26 | +pub fn register_vmm_notification_wait_for_request() { |
| 27 | + // Setup interrupt handler. |
| 28 | + unsafe { |
| 29 | + idt::register_handler( |
| 30 | + NOTIFY_VECTOR_WAIT_FOR_REQUEST, |
| 31 | + vmm_notification_wait_for_request, |
| 32 | + ); |
| 33 | + } |
| 34 | +} |
49 | 35 |
|
50 |
| - // log::debug!("============== WOKE UP ============\n"); |
51 |
| - // log::debug!("NOTIFY_WAIT_FOR_REQUEST:{:?}\n", NOTIFY_WAIT_FOR_REQUEST); |
52 |
| - // log::debug!("NOTIFY_REPORT_STATUS:{:?}\n", NOTIFY_REPORT_STATUS); |
53 |
| - // log::debug!("NOTIFY_SPDM_PCI_DOE:{:?}\n", NOTIFY_SPDM_PCI_DOE); |
54 |
| - // log::debug!("NOTIFY_SHUTDOWN:{:?}\n", NOTIFY_SHUTDOWN); |
55 |
| - // log::debug!("NOTIFY_SERVICE_QUERY:{:?}\n", NOTIFY_SERVICE_QUERY); |
56 |
| - [<NOTIFY_ $name:upper>].store(NOTIFY_VALUE_CLEAR, Ordering::SeqCst); |
57 |
| - } |
| 36 | +// Function to wait for the VMM notification interrupt. |
| 37 | +pub fn wait_for_vmm_notification_wait_for_request() { |
| 38 | + while NOTIFY_WAIT_FOR_REQUEST.load(Ordering::SeqCst) != NOTIFY_VALUE_SET { |
| 39 | + enable_and_hlt(); |
| 40 | + if NOTIFY_WAIT_FOR_REQUEST.load(Ordering::SeqCst) == NOTIFY_VALUE_SET { |
| 41 | + break; |
58 | 42 | }
|
59 |
| - }; |
| 43 | + } |
| 44 | + disable(); |
| 45 | + // Reset notification state. |
| 46 | + NOTIFY_WAIT_FOR_REQUEST.store(NOTIFY_VALUE_CLEAR, Ordering::SeqCst); |
60 | 47 | }
|
61 |
| - |
62 |
| -// 32~255 are available |
63 |
| -pub const INTERRUPT_VECTOR_WAIT_FOR_REQUEST: u8 = 32; |
64 |
| - |
65 |
| -register_interrupt!(wait_for_request, INTERRUPT_VECTOR_WAIT_FOR_REQUEST); |
0 commit comments