use iocuddle::{Group, Ioctl, WriteRead};
use std::marker::PhantomData;
use super::rtmr::CsvGuestUserRtmrSubcmd;
pub enum CsvGuestIoctl {
GetReport = 0x1,
RtmrReq = 0x2,
_Undefined,
}
const CSV: Group = Group::new(b'D');
pub const CSV_GET_REPORT: Ioctl<WriteRead, &GuestReportRequest> =
unsafe { CSV.write_read(CsvGuestIoctl::GetReport as u8) };
#[repr(C)]
pub struct GuestReportRequest<'a> {
pub addr: u64,
pub len: u32,
_phantom: PhantomData<&'a ()>,
}
impl<'a> GuestReportRequest<'a> {
pub fn new(data: &'a [u8]) -> Self {
Self {
addr: data.as_ptr() as _,
len: data.len() as _,
_phantom: PhantomData,
}
}
}
pub const CSV_RTMR_REQ: Ioctl<WriteRead, &GuestRtmrRequest> =
unsafe { CSV.write_read(CsvGuestIoctl::RtmrReq as u8) };
#[repr(C, packed)]
pub struct GuestRtmrRequest<'a> {
pub buf: u64,
pub len: u64,
pub subcmd_id: u16,
pub rsvd: u16,
pub fw_error_code: u32,
_phantom: PhantomData<&'a ()>,
}
impl<'a> GuestRtmrRequest<'a> {
pub fn new(subcmd_buf: &'a [u8], subcmd_id: CsvGuestUserRtmrSubcmd) -> Self {
Self {
buf: subcmd_buf.as_ptr() as _,
len: subcmd_buf.len() as _,
subcmd_id: subcmd_id as u16,
rsvd: 0,
fw_error_code: 0,
_phantom: PhantomData,
}
}
pub fn get_fw_error_code(&self) -> u32 {
self.fw_error_code
}
}