#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "pci_class_debug_strings", derive(Debug))]
pub enum PciDeviceClass {
Unclassified,
MassStorageController,
NetworkController,
DisplayController,
MultimediaDevice,
MemoryController,
Bridge,
CommunicationController,
BaseSystemPeripheral,
InputDevice,
DockingStation,
Processor,
SerialBusController,
WirelessController,
IntelligentIoController,
SatelliteCommController,
EncryptionController,
SignalProcessingController,
ProcessingAccelerator,
NonEssentialInstrumentation,
Unknown(u8),
}
impl PciDeviceClass {
pub fn from_code(class_code: u8) -> Self {
match class_code {
0x00 => Self::Unclassified,
0x01 => Self::MassStorageController,
0x02 => Self::NetworkController,
0x03 => Self::DisplayController,
0x04 => Self::MultimediaDevice,
0x05 => Self::MemoryController,
0x06 => Self::Bridge,
0x07 => Self::CommunicationController,
0x08 => Self::BaseSystemPeripheral,
0x09 => Self::InputDevice,
0x0a => Self::DockingStation,
0x0b => Self::Processor,
0x0c => Self::SerialBusController,
0x0d => Self::WirelessController,
0x0e => Self::IntelligentIoController,
0x0f => Self::SatelliteCommController,
0x10 => Self::EncryptionController,
0x11 => Self::SignalProcessingController,
0x12 => Self::ProcessingAccelerator,
0x13 => Self::NonEssentialInstrumentation,
unk => Self::Unknown(unk),
}
}
pub fn as_code(&self) -> u8 {
match self {
Self::Unclassified => 0x00,
Self::MassStorageController => 0x01,
Self::NetworkController => 0x02,
Self::DisplayController => 0x03,
Self::MultimediaDevice => 0x04,
Self::MemoryController => 0x05,
Self::Bridge => 0x06,
Self::CommunicationController => 0x07,
Self::BaseSystemPeripheral => 0x08,
Self::InputDevice => 0x09,
Self::DockingStation => 0x0a,
Self::Processor => 0x0b,
Self::SerialBusController => 0x0c,
Self::WirelessController => 0x0d,
Self::IntelligentIoController => 0x0e,
Self::SatelliteCommController => 0x0f,
Self::EncryptionController => 0x10,
Self::SignalProcessingController => 0x11,
Self::ProcessingAccelerator => 0x12,
Self::NonEssentialInstrumentation => 0x13,
Self::Unknown(unk) => *unk,
}
}
}
impl From<u8> for PciDeviceClass {
fn from(value: u8) -> Self {
Self::from_code(value)
}
}
impl From<PciDeviceClass> for u8 {
fn from(value: PciDeviceClass) -> Self {
value.as_code()
}
}
#[cfg(not(feature = "pci_class_debug_strings"))]
impl std::fmt::Debug for PciDeviceClass {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "(class:{})", self.as_code())
}
}