#![no_std]
#![deny(missing_docs)]
extern crate alloc;
mod error;
pub use error::{HyperCallError, HyperCallResult, InvalidHyperCallCode};
#[repr(u32)]
#[derive(Eq, PartialEq, Copy, Clone)]
pub enum HyperCallCode {
PSCIVersion = 0x8400_0000,
PSCICpuSuspend = 0x8400_0001,
PSCICpuOff = 0x8400_0002,
PSCICpuOn = 0x8400_0003,
PSCIAffinityInfo = 0x8400_0004,
PSCIMigrate = 0x8400_0005,
PSCIMigrateInfoType = 0x8400_0006,
PSCIMigrateInfoUpCpu = 0x8400_0007,
PSCISystemOff = 0x8400_0008,
PSCISystemReset = 0x8400_0009,
PSCIFeatures = 0x8400_000a,
PSCICpuSuspend64 = 0xc400_0001,
PSCICpuOn64 = 0xc400_0003,
PSCIAffinityInfo64 = 0xc400_0004,
PSCIMigrate64 = 0xc400_0005,
PSCIMigrateInfoUpCpu64 = 0xc400_0007,
HypervisorDisable = 0,
HyperVisorPrepareDisable = 1,
HyperVisorDebug = 2,
HIVCPublishChannel = 3,
HIVCSubscribChannel = 4,
HIVCUnPublishChannel = 5,
HIVCUnSubscribChannel = 6,
}
impl TryFrom<u32> for HyperCallCode {
type Error = InvalidHyperCallCode;
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
0x8400_0000 => Ok(HyperCallCode::PSCIVersion),
0x8400_0001 => Ok(HyperCallCode::PSCICpuSuspend),
0x8400_0002 => Ok(HyperCallCode::PSCICpuOff),
0x8400_0003 => Ok(HyperCallCode::PSCICpuOn),
0x8400_0004 => Ok(HyperCallCode::PSCIAffinityInfo),
0x8400_0005 => Ok(HyperCallCode::PSCIMigrate),
0x8400_0006 => Ok(HyperCallCode::PSCIMigrateInfoType),
0x8400_0007 => Ok(HyperCallCode::PSCIMigrateInfoUpCpu),
0x8400_0008 => Ok(HyperCallCode::PSCISystemOff),
0x8400_0009 => Ok(HyperCallCode::PSCISystemReset),
0x8400_000a => Ok(HyperCallCode::PSCIFeatures),
0xc400_0001 => Ok(HyperCallCode::PSCICpuSuspend64),
0xc400_0003 => Ok(HyperCallCode::PSCICpuOn64),
0xc400_0004 => Ok(HyperCallCode::PSCIAffinityInfo64),
0xc400_0005 => Ok(HyperCallCode::PSCIMigrate64),
0xc400_0007 => Ok(HyperCallCode::PSCIMigrateInfoUpCpu64),
0 => Ok(HyperCallCode::HypervisorDisable),
1 => Ok(HyperCallCode::HyperVisorPrepareDisable),
2 => Ok(HyperCallCode::HyperVisorDebug),
3 => Ok(HyperCallCode::HIVCPublishChannel),
4 => Ok(HyperCallCode::HIVCSubscribChannel),
5 => Ok(HyperCallCode::HIVCUnPublishChannel),
6 => Ok(HyperCallCode::HIVCUnSubscribChannel),
_ => Err(InvalidHyperCallCode(value)),
}
}
}
impl core::fmt::Debug for HyperCallCode {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "(")?;
match self {
Self::PSCIVersion => write!(f, "PSCIVersion"),
Self::PSCICpuSuspend => write!(f, "PSCICpuSuspend"),
Self::PSCICpuOff => write!(f, "PSCICpuOff"),
Self::PSCICpuOn => write!(f, "PSCICpuOn"),
Self::PSCIAffinityInfo => write!(f, "PSCIAffinityInfo"),
Self::PSCIMigrate => write!(f, "PSCIMigrate"),
Self::PSCIMigrateInfoType => write!(f, "PSCIMigrateInfoType"),
Self::PSCIMigrateInfoUpCpu => write!(f, "PSCIMigrateInfoUpCpu"),
Self::PSCISystemOff => write!(f, "PSCISystemOff"),
Self::PSCISystemReset => write!(f, "PSCISystemReset"),
Self::PSCIFeatures => write!(f, "PSCIFeatures"),
Self::PSCICpuSuspend64 => write!(f, "PSCICpuSuspend64"),
Self::PSCICpuOn64 => write!(f, "PSCICpuOn64"),
Self::PSCIAffinityInfo64 => write!(f, "PSCIAffinityInfo64"),
Self::PSCIMigrate64 => write!(f, "PSCIMigrate64"),
Self::PSCIMigrateInfoUpCpu64 => write!(f, "PSCIMigrateInfoUpCpu64"),
HyperCallCode::HypervisorDisable => write!(f, "HypervisorDisable {:#x}", *self as u32),
HyperCallCode::HyperVisorPrepareDisable => {
write!(f, "HyperVisorPrepareDisable {:#x}", *self as u32)
}
HyperCallCode::HyperVisorDebug => write!(f, "HyperVisorDebug {:#x}", *self as u32),
HyperCallCode::HIVCPublishChannel => {
write!(f, "HIVCPublishChannel {:#x}", *self as u32)
}
HyperCallCode::HIVCSubscribChannel => {
write!(f, "HIVCSubscribChannel {:#x}", *self as u32)
}
HyperCallCode::HIVCUnPublishChannel => {
write!(f, "HIVCUnPublishChannel {:#x}", *self as u32)
}
HyperCallCode::HIVCUnSubscribChannel => {
write!(f, "HIVCUnSubscribChannel {:#x}", *self as u32)
}
}?;
write!(f, ")")
}
}