#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct PartitionId(u32);
impl PartitionId {
pub const HYPERVISOR: Self = Self(0);
pub const MAX_LOGICAL: u32 = 4096;
#[must_use]
pub const fn new(id: u32) -> Self {
Self(id)
}
#[must_use]
pub const fn try_new(id: u32) -> Option<Self> {
if id == 0 || id > Self::MAX_LOGICAL {
None
} else {
Some(Self(id))
}
}
#[must_use]
pub const fn hypervisor() -> Self {
Self::HYPERVISOR
}
#[must_use]
pub const fn as_u32(self) -> u32 {
self.0
}
#[must_use]
pub const fn vmid(self) -> u16 {
(self.0 & 0xFF) as u16
}
#[must_use]
pub const fn is_hypervisor(self) -> bool {
self.0 == 0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct VcpuId {
partition: PartitionId,
index: u16,
}
impl VcpuId {
#[must_use]
pub const fn new(partition: PartitionId, index: u16) -> Self {
Self { partition, index }
}
#[must_use]
pub const fn partition(self) -> PartitionId {
self.partition
}
#[must_use]
pub const fn index(self) -> u16 {
self.index
}
}