mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-10 13:56:48 +00:00
Add tdx-guest device
This commit is contained in:
parent
a91a35ebce
commit
55ea3dc86f
@ -1,6 +1,8 @@
|
||||
mod null;
|
||||
mod pty;
|
||||
mod random;
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
mod tdxguest;
|
||||
pub mod tty;
|
||||
mod urandom;
|
||||
mod zero;
|
||||
@ -10,6 +12,8 @@ use crate::prelude::*;
|
||||
pub use pty::new_pty_pair;
|
||||
pub use pty::{PtyMaster, PtySlave};
|
||||
pub use random::Random;
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
pub use tdxguest::TdxGuest;
|
||||
pub use urandom::Urandom;
|
||||
|
||||
use self::tty::get_n_tty;
|
||||
@ -25,6 +29,10 @@ pub fn init() -> Result<()> {
|
||||
add_node(console, "console")?;
|
||||
let tty = Arc::new(tty::TtyDevice);
|
||||
add_node(tty, "tty")?;
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
let tdx_guest = Arc::new(tdxguest::TdxGuest);
|
||||
#[cfg(feature = "intel_tdx")]
|
||||
add_node(tdx_guest, "tdx-guest")?;
|
||||
let random = Arc::new(random::Random);
|
||||
add_node(random, "random")?;
|
||||
let urandom = Arc::new(urandom::Urandom);
|
||||
|
55
services/libs/jinux-std/src/device/tdxguest/mod.rs
Normal file
55
services/libs/jinux-std/src/device/tdxguest/mod.rs
Normal file
@ -0,0 +1,55 @@
|
||||
use super::*;
|
||||
use crate::events::IoEvents;
|
||||
use crate::fs::inode_handle::FileIo;
|
||||
use crate::fs::utils::IoctlCmd;
|
||||
use crate::process::signal::Poller;
|
||||
use crate::util::{read_val_from_user, write_val_to_user};
|
||||
use tdx_guest::tdcall::get_report;
|
||||
|
||||
const TDX_REPORTDATA_LEN: usize = 64;
|
||||
const TDX_REPORT_LEN: usize = 1024;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Pod)]
|
||||
#[repr(C)]
|
||||
pub struct TdxReportRequest {
|
||||
reportdata: [u8; TDX_REPORTDATA_LEN],
|
||||
tdreport: [u8; TDX_REPORT_LEN],
|
||||
}
|
||||
|
||||
pub struct TdxGuest;
|
||||
|
||||
impl Device for TdxGuest {
|
||||
fn type_(&self) -> DeviceType {
|
||||
DeviceType::MiscDevice
|
||||
}
|
||||
|
||||
fn id(&self) -> DeviceId {
|
||||
DeviceId::new(10, 0)
|
||||
}
|
||||
}
|
||||
impl FileIo for TdxGuest {
|
||||
fn read(&self, buf: &mut [u8]) -> Result<usize> {
|
||||
return_errno_with_message!(Errno::EPERM, "Read operation not supported")
|
||||
}
|
||||
|
||||
fn write(&self, buf: &[u8]) -> Result<usize> {
|
||||
return_errno_with_message!(Errno::EPERM, "Write operation not supported")
|
||||
}
|
||||
|
||||
fn ioctl(&self, cmd: IoctlCmd, arg: usize) -> Result<i32> {
|
||||
match cmd {
|
||||
IoctlCmd::TDXGETREPORT => {
|
||||
let tdx_report: TdxReportRequest = read_val_from_user(arg)?;
|
||||
get_report(&tdx_report.tdreport, &tdx_report.reportdata).unwrap();
|
||||
write_val_to_user(arg, &tdx_report)?;
|
||||
Ok(0)
|
||||
}
|
||||
_ => return_errno_with_message!(Errno::EPERM, "Unsupported ioctl"),
|
||||
}
|
||||
}
|
||||
|
||||
fn poll(&self, mask: IoEvents, poller: Option<&Poller>) -> IoEvents {
|
||||
let events = IoEvents::IN | IoEvents::OUT;
|
||||
events & mask
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ impl Debug for dyn Device {
|
||||
pub enum DeviceType {
|
||||
CharDevice,
|
||||
BlockDevice,
|
||||
MiscDevice,
|
||||
}
|
||||
|
||||
/// Device Id
|
||||
|
@ -51,6 +51,7 @@ impl From<DeviceType> for InodeType {
|
||||
match type_ {
|
||||
DeviceType::CharDevice => InodeType::CharDevice,
|
||||
DeviceType::BlockDevice => InodeType::BlockDevice,
|
||||
DeviceType::MiscDevice => InodeType::CharDevice,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,4 +29,6 @@ pub enum IoctlCmd {
|
||||
TIOCSPTLCK = 0x40045431,
|
||||
/// Safely open the slave
|
||||
TIOCGPTPEER = 0x40045441,
|
||||
/// Get tdx report using TDCALL
|
||||
TDXGETREPORT = 0xc4405401,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user