use crate::types::{AccessType, SecurityState};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct PRIEntry {
pub stream_id: u32,
pub pasid: u32,
pub requested_address: u64,
pub access_type: AccessType,
pub is_last_request: bool,
pub timestamp: u64,
pub prg_index: u16,
pub security_state: SecurityState,
pub span: u8,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct PriAutoFailureResponse {
pub entry: PRIEntry,
pub response_code: u8,
}
impl PriAutoFailureResponse {
#[must_use]
pub fn new(entry: PRIEntry) -> Self {
let response_code = if entry.pasid == 0 { 0x0 } else { 0xF };
Self { entry, response_code }
}
}
impl PRIEntry {
#[must_use]
pub const fn new(stream_id: u32, pasid: u32) -> Self {
Self {
stream_id,
pasid,
requested_address: 0,
access_type: AccessType::Read,
is_last_request: false,
timestamp: 0,
prg_index: 0,
security_state: SecurityState::NonSecure,
span: 0,
}
}
#[must_use]
pub const fn with_address(stream_id: u32, pasid: u32, requested_address: u64, access_type: AccessType) -> Self {
Self {
stream_id,
pasid,
requested_address,
access_type,
is_last_request: false,
timestamp: 0,
prg_index: 0,
security_state: SecurityState::NonSecure,
span: 0,
}
}
#[must_use]
pub const fn with_prg_index(mut self, prg_index: u16) -> Self {
self.prg_index = prg_index;
self
}
#[must_use]
pub const fn with_security_state(mut self, security_state: SecurityState) -> Self {
self.security_state = security_state;
self
}
#[must_use]
pub const fn with_span(mut self, span: u8) -> Self {
self.span = span;
self
}
}