mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 03:13:23 +00:00
Handle TDX MMIO and DMA direct
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
461c872c43
commit
37c3a7a48c
@ -11,6 +11,8 @@ mod asm;
|
||||
pub mod tdcall;
|
||||
pub mod tdvmcall;
|
||||
|
||||
use core::sync::atomic::{AtomicBool, Ordering::Relaxed};
|
||||
|
||||
use raw_cpuid::{native_cpuid::cpuid_count, CpuIdResult};
|
||||
use tdcall::{InitError, TdgVpInfo};
|
||||
|
||||
@ -19,8 +21,16 @@ pub use self::{
|
||||
tdvmcall::print,
|
||||
};
|
||||
|
||||
static TDX_ENABLED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
#[inline(always)]
|
||||
pub fn tdx_is_enabled() -> bool {
|
||||
TDX_ENABLED.load(Relaxed)
|
||||
}
|
||||
|
||||
pub fn init_tdx() -> Result<TdgVpInfo, InitError> {
|
||||
check_tdx_guest()?;
|
||||
TDX_ENABLED.store(true, Relaxed);
|
||||
Ok(tdcall::get_tdinfo()?)
|
||||
}
|
||||
|
||||
@ -32,7 +42,7 @@ fn check_tdx_guest() -> Result<(), InitError> {
|
||||
}
|
||||
let cpuid_result: CpuIdResult = cpuid_count(TDX_CPUID_LEAF_ID as u32, 0);
|
||||
if &cpuid_result.ebx.to_ne_bytes() != b"Inte"
|
||||
|| &cpuid_result.ebx.to_ne_bytes() != b"lTDX"
|
||||
|| &cpuid_result.edx.to_ne_bytes() != b"lTDX"
|
||||
|| &cpuid_result.ecx.to_ne_bytes() != b" "
|
||||
{
|
||||
return Err(InitError::TdxVendorIdError);
|
||||
|
Reference in New Issue
Block a user