asterinas/kernel/aster-nix/src/device/tdxguest/mod.rs

81 lines
2.3 KiB
Rust
Raw Normal View History

2024-01-03 03:22:36 +00:00
// SPDX-License-Identifier: MPL-2.0
2024-06-13 06:21:12 +00:00
use tdx_guest::tdcall::TdCallError;
2023-11-29 02:30:05 +00:00
use super::*;
use crate::{
error::Error,
events::IoEvents,
fs::{inode_handle::FileIo, utils::IoctlCmd},
process::signal::Poller,
};
2023-11-29 02:30:05 +00:00
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 {
2023-11-30 06:30:32 +00:00
DeviceId::new(0xa, 0x7b)
2023-11-29 02:30:05 +00:00
}
}
2023-11-30 06:30:32 +00:00
2023-12-06 09:04:07 +00:00
impl From<TdCallError> for Error {
fn from(err: TdCallError) -> Self {
match err {
TdCallError::TdxNoValidVeInfo => {
Error::with_message(Errno::EINVAL, "TdCallError::TdxNoValidVeInfo")
}
TdCallError::TdxOperandInvalid => {
Error::with_message(Errno::EINVAL, "TdCallError::TdxOperandInvalid")
}
TdCallError::TdxPageAlreadyAccepted => {
Error::with_message(Errno::EINVAL, "TdCallError::TdxPageAlreadyAccepted")
}
TdCallError::TdxPageSizeMismatch => {
Error::with_message(Errno::EINVAL, "TdCallError::TdxPageSizeMismatch")
}
TdCallError::TdxOperandBusy => {
Error::with_message(Errno::EBUSY, "TdCallError::TdxOperandBusy")
}
TdCallError::Other => Error::with_message(Errno::EAGAIN, "TdCallError::Other"),
}
}
}
2023-11-29 02:30:05 +00:00
impl FileIo for TdxGuest {
2024-06-13 06:21:12 +00:00
fn read(&self, _buf: &mut [u8]) -> Result<usize> {
2023-11-29 02:30:05 +00:00
return_errno_with_message!(Errno::EPERM, "Read operation not supported")
}
2024-06-13 06:21:12 +00:00
fn write(&self, _buf: &[u8]) -> Result<usize> {
2023-11-29 02:30:05 +00:00
return_errno_with_message!(Errno::EPERM, "Write operation not supported")
}
2024-06-13 06:21:12 +00:00
fn ioctl(&self, cmd: IoctlCmd, _arg: usize) -> Result<i32> {
2023-11-29 02:30:05 +00:00
match cmd {
IoctlCmd::TDXGETREPORT => {
2024-06-13 06:21:12 +00:00
todo!()
2023-11-29 02:30:05 +00:00
}
_ => return_errno_with_message!(Errno::EPERM, "Unsupported ioctl"),
}
}
2024-06-13 06:21:12 +00:00
fn poll(&self, mask: IoEvents, _poller: Option<&Poller>) -> IoEvents {
2023-11-29 02:30:05 +00:00
let events = IoEvents::IN | IoEvents::OUT;
events & mask
}
}