pci-info 0.1.0

A crate to enumerate PCI devices on desktop operating systems and/or parse PCI configuration headers
Documentation

// This file is AUTOGENERATED.
// Modify `tools/gen_classes.ers` if changes are needed to
// PCI device classes or the file format

#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "pci_class_debug_strings", derive(Debug))]
/// Represent a PCI device class as an enumeration, for easier
/// matching with known valid values.
///
/// See PCI documentation or <https://wiki.osdev.org/PCI#Class_Codes>
/// for possible values.
pub enum PciDeviceClass {
    /// Enumeration matching device class 00h.
    Unclassified,
    /// Enumeration matching device class 01h.
    MassStorageController,
    /// Enumeration matching device class 02h.
    NetworkController,
    /// Enumeration matching device class 03h.
    DisplayController,
    /// Enumeration matching device class 04h.
    MultimediaDevice,
    /// Enumeration matching device class 05h.
    MemoryController,
    /// Enumeration matching device class 06h.
    Bridge,
    /// Enumeration matching device class 07h.
    CommunicationController,
    /// Enumeration matching device class 08h.
    BaseSystemPeripheral,
    /// Enumeration matching device class 09h.
    InputDevice,
    /// Enumeration matching device class 0Ah.
    DockingStation,
    /// Enumeration matching device class 0Bh.
    Processor,
    /// Enumeration matching device class 0Ch.
    SerialBusController,
    /// Enumeration matching device class 0Dh.
    WirelessController,
    /// Enumeration matching device class 0Eh.
    IntelligentIoController,
    /// Enumeration matching device class 0Fh.
    SatelliteCommController,
    /// Enumeration matching device class 10h.
    EncryptionController,
    /// Enumeration matching device class 11h.
    SignalProcessingController,
    /// Enumeration matching device class 12h.
    ProcessingAccelerator,
    /// Enumeration matching device class 13h.
    NonEssentialInstrumentation,
    /// Enumeration matching unknown device classes.
    Unknown(u8),
}

impl PciDeviceClass {
    /// Create a `PciDeviceClass` from the `u8` value that it
    /// represents
    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),
        }
    }

    /// Gets the `u8` value that this `PciDeviceClass` represents
    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())
    }
}