pci_types/
device_type.rs

1use crate::{BaseClass, Interface, SubClass};
2use core::convert::TryFrom;
3
4/// Combines the Base Class and the Sub-class of a device to classify it into a `DeviceType`. Combined with the
5/// device's Interface, this can be enough to know how to drive the device.
6#[derive(Clone, Copy, PartialEq, Eq, Debug)]
7pub enum DeviceType {
8    Unknown,
9
10    /*
11     * Base Class 0x00 - Devices that predate Class Codes
12     */
13    LegacyVgaCompatible,
14    LegacyNotVgaCompatible,
15
16    /*
17     * Base Class 0x01 - Mass Storage Controllers
18     */
19    ScsiBusController,
20    IdeController,
21    FloppyController,
22    IpiBusController,
23    RaidController,
24    AtaController,
25    SataController,
26    SasController,
27    NvmeController,
28    UfsController,
29    OtherMassStorageController,
30
31    /*
32     * Base Class 0x02 - Network Controllers
33     */
34    EthernetController,
35    TokenRingController,
36    FddiController,
37    AtmController,
38    IsdnController,
39    WorldFipController,
40    PicmgController,
41    OtherNetworkController,
42
43    /*
44     * Base Class 0x03 - Display Controllers
45     */
46    VgaCompatibleController,
47    XgaController,
48    ThreeDController,
49    OtherDisplayController,
50
51    /*
52     * Base Class 0x04 - Multimedia Devices
53     */
54    VideoDevice,
55    AudioDevice,
56    TelephonyDevice,
57    OtherMultimediaDevice,
58
59    /*
60     * Base Class 0x05 - Memory Controllers
61     */
62    RamController,
63    FlashController,
64    OtherMemoryController,
65
66    /*
67     * Base Class 0x06 - Bridge Devices
68     */
69    HostBridge,
70    IsaBridge,
71    EisaBridge,
72    McaBridge,
73    PciPciBridge,
74    PcmciaBridge,
75    NuBusBridge,
76    CardBusBridge,
77    RacewayBridge,
78    SemiTransparentPciPciBridge,
79    InfinibandPciHostBridge,
80    OtherBridgeDevice,
81
82    /*
83     * Base Class 0x07 - Simple Communications Controllers
84     */
85    SerialController,
86    ParallelPort,
87    MultiportSerialController,
88    Modem,
89    GpibController,
90    SmartCard,
91    OtherCommunicationsDevice,
92
93    /*
94     * Base Class 0x08 - Generic System Peripherals
95     */
96    InterruptController,
97    DmaController,
98    SystemTimer,
99    RtcController,
100    GenericPciHotPlugController,
101    SdHostController,
102    OtherSystemPeripheral,
103
104    /*
105     * Base Class 0x09 - Input Devices
106     */
107    KeyboardController,
108    Digitizer,
109    MouseController,
110    ScannerController,
111    GameportController,
112    OtherInputController,
113
114    /*
115     * Base Class 0x0a - Docking Stations
116     */
117    GenericDockingStation,
118    OtherDockingStation,
119
120    /*
121     * Base Class 0x0b - Processors
122     */
123    Processor386,
124    Processor486,
125    ProcessorPentium,
126    ProcessorAlpha,
127    ProcessorPowerPc,
128    ProcessorMips,
129    CoProcessor,
130
131    /*
132     * Base Class 0x0c - Serial Bus Controllers
133     */
134    FirewireController,
135    AccessBusController,
136    SsaBusController,
137    UsbController,
138    FibreChannelController,
139    SmBusController,
140    InfiniBandController,
141    IpmiController,
142    SercosController,
143    CanBusController,
144
145    /*
146     * Base Class 0x0d - Wireless Controllers
147     */
148    IrdaController,
149    ConsumerIrController,
150    RfController,
151    BluetoothController,
152    BroadbandController,
153    Ethernet5GHzController,
154    Ethernet24GHzController,
155    OtherWirelessController,
156
157    /*
158     * Base Class 0x0e - Intelligent IO Controllers
159     */
160    IntelligentIoController,
161
162    /*
163     * Base Class 0x0f - Satellite Communications Controllers
164     */
165    TvSatelliteCommunicationsController,
166    AudioSatelliteCommunicationsController,
167    VoiceSatelliteCommunicationsController,
168    DataSatelliteCommunicationsController,
169
170    /*
171     * Base Class 0x10 - Encryption and Decryption Controllers
172     */
173    NetworkCryptionController,
174    EntertainmentCryptionController,
175    OtherCryptionController,
176
177    /*
178     * Base Class 0x11 - Data Acquisition and Signal Processing Controllers
179     */
180    DpioModule,
181    PerformanceCounter,
182    CommunicationsSynchronizationController,
183    ManagementCard,
184    OtherSignalProcessingController,
185}
186
187impl From<(BaseClass, SubClass)> for DeviceType {
188    fn from(class: (BaseClass, SubClass)) -> Self {
189        match class {
190            (0x00, 0x00) => DeviceType::LegacyNotVgaCompatible,
191            (0x00, 0x01) => DeviceType::LegacyVgaCompatible,
192
193            (0x01, 0x00) => DeviceType::ScsiBusController,
194            (0x01, 0x01) => DeviceType::IdeController,
195            (0x01, 0x02) => DeviceType::FloppyController,
196            (0x01, 0x03) => DeviceType::IpiBusController,
197            (0x01, 0x04) => DeviceType::RaidController,
198            (0x01, 0x05) => DeviceType::AtaController,
199            (0x01, 0x06) => DeviceType::SataController,
200            (0x01, 0x07) => DeviceType::SasController,
201            (0x01, 0x08) => DeviceType::NvmeController,
202            (0x01, 0x09) => DeviceType::UfsController,
203            (0x01, 0x80) => DeviceType::OtherMassStorageController,
204
205            (0x02, 0x00) => DeviceType::EthernetController,
206            (0x02, 0x01) => DeviceType::TokenRingController,
207            (0x02, 0x02) => DeviceType::FddiController,
208            (0x02, 0x03) => DeviceType::AtmController,
209            (0x02, 0x04) => DeviceType::IsdnController,
210            (0x02, 0x06) => DeviceType::PicmgController,
211            (0x02, 0x80) => DeviceType::OtherNetworkController,
212
213            (0x03, 0x00) => DeviceType::VgaCompatibleController,
214            (0x03, 0x01) => DeviceType::XgaController,
215            (0x03, 0x02) => DeviceType::ThreeDController,
216            (0x03, 0x80) => DeviceType::OtherDisplayController,
217
218            (0x04, 0x00) => DeviceType::VideoDevice,
219            (0x04, 0x01) => DeviceType::AudioDevice,
220            (0x04, 0x02) => DeviceType::TelephonyDevice,
221            (0x04, 0x03) => DeviceType::OtherMultimediaDevice,
222
223            (0x05, 0x00) => DeviceType::RamController,
224            (0x05, 0x01) => DeviceType::FlashController,
225            (0x05, 0x02) => DeviceType::OtherMemoryController,
226
227            (0x06, 0x00) => DeviceType::HostBridge,
228            (0x06, 0x01) => DeviceType::IsaBridge,
229            (0x06, 0x02) => DeviceType::EisaBridge,
230            (0x06, 0x03) => DeviceType::McaBridge,
231            (0x06, 0x04) => DeviceType::PciPciBridge,
232            (0x06, 0x05) => DeviceType::PcmciaBridge,
233            (0x06, 0x06) => DeviceType::NuBusBridge,
234            (0x06, 0x07) => DeviceType::CardBusBridge,
235            (0x06, 0x08) => DeviceType::RacewayBridge,
236            (0x06, 0x09) => DeviceType::SemiTransparentPciPciBridge,
237            (0x06, 0x0a) => DeviceType::InfinibandPciHostBridge,
238            (0x06, 0x80) => DeviceType::OtherBridgeDevice,
239
240            (0x07, 0x00) => DeviceType::SerialController,
241            (0x07, 0x01) => DeviceType::ParallelPort,
242            (0x07, 0x02) => DeviceType::MultiportSerialController,
243            (0x07, 0x03) => DeviceType::Modem,
244            (0x07, 0x04) => DeviceType::GpibController,
245            (0x07, 0x05) => DeviceType::SmartCard,
246            (0x07, 0x80) => DeviceType::OtherCommunicationsDevice,
247
248            (0x08, 0x00) => DeviceType::InterruptController,
249            (0x08, 0x01) => DeviceType::DmaController,
250            (0x08, 0x02) => DeviceType::SystemTimer,
251            (0x08, 0x03) => DeviceType::RtcController,
252            (0x08, 0x04) => DeviceType::GenericPciHotPlugController,
253            (0x08, 0x05) => DeviceType::SdHostController,
254            (0x08, 0x80) => DeviceType::OtherSystemPeripheral,
255
256            (0x09, 0x00) => DeviceType::KeyboardController,
257            (0x09, 0x01) => DeviceType::Digitizer,
258            (0x09, 0x02) => DeviceType::MouseController,
259            (0x09, 0x03) => DeviceType::ScannerController,
260            (0x09, 0x04) => DeviceType::GameportController,
261            (0x09, 0x80) => DeviceType::OtherInputController,
262
263            (0x0a, 0x00) => DeviceType::GenericDockingStation,
264            (0x0a, 0x80) => DeviceType::OtherDockingStation,
265
266            (0x0b, 0x00) => DeviceType::Processor386,
267            (0x0b, 0x01) => DeviceType::Processor486,
268            (0x0b, 0x02) => DeviceType::ProcessorPentium,
269            (0x0b, 0x10) => DeviceType::ProcessorAlpha,
270            (0x0b, 0x20) => DeviceType::ProcessorPowerPc,
271            (0x0b, 0x30) => DeviceType::ProcessorMips,
272            (0x0b, 0x40) => DeviceType::CoProcessor,
273
274            (0x0c, 0x00) => DeviceType::FirewireController,
275            (0x0c, 0x01) => DeviceType::AccessBusController,
276            (0x0c, 0x02) => DeviceType::SsaBusController,
277            (0x0c, 0x03) => DeviceType::UsbController,
278            (0x0c, 0x04) => DeviceType::FibreChannelController,
279            (0x0c, 0x05) => DeviceType::SmBusController,
280            (0x0c, 0x06) => DeviceType::InfiniBandController,
281            (0x0c, 0x07) => DeviceType::IpmiController,
282            (0x0c, 0x08) => DeviceType::SercosController,
283            (0x0c, 0x09) => DeviceType::CanBusController,
284
285            (0x0d, 0x00) => DeviceType::IrdaController,
286            (0x0d, 0x01) => DeviceType::ConsumerIrController,
287            (0x0d, 0x10) => DeviceType::RfController,
288            (0x0d, 0x11) => DeviceType::BluetoothController,
289            (0x0d, 0x12) => DeviceType::BroadbandController,
290            (0x0d, 0x20) => DeviceType::Ethernet5GHzController,
291            (0x0d, 0x21) => DeviceType::Ethernet24GHzController,
292            (0x0d, 0x80) => DeviceType::OtherWirelessController,
293
294            (0x0e, 0x00) => DeviceType::IntelligentIoController,
295
296            (0x0f, 0x00) => DeviceType::TvSatelliteCommunicationsController,
297            (0x0f, 0x01) => DeviceType::AudioSatelliteCommunicationsController,
298            (0x0f, 0x02) => DeviceType::VoiceSatelliteCommunicationsController,
299            (0x0f, 0x03) => DeviceType::DataSatelliteCommunicationsController,
300
301            (0x10, 0x00) => DeviceType::NetworkCryptionController,
302            (0x10, 0x10) => DeviceType::EntertainmentCryptionController,
303            (0x10, 0x80) => DeviceType::OtherCryptionController,
304
305            (0x11, 0x00) => DeviceType::DpioModule,
306            (0x11, 0x01) => DeviceType::PerformanceCounter,
307            (0x11, 0x10) => DeviceType::CommunicationsSynchronizationController,
308            (0x11, 0x20) => DeviceType::ManagementCard,
309            (0x11, 0x80) => DeviceType::OtherSignalProcessingController,
310
311            _ => DeviceType::Unknown,
312        }
313    }
314}
315
316/// The different register-level programming interfaces defined for USB controllers (devices of type
317/// `DeviceType::UsbController`).
318#[derive(Clone, Copy, PartialEq, Eq, Debug)]
319pub enum UsbType {
320    Uhci,
321    Ohci,
322    Ehci,
323    Xhci,
324    OtherInterface,
325    Device,
326}
327
328impl TryFrom<Interface> for UsbType {
329    type Error = ();
330
331    fn try_from(interface: Interface) -> Result<Self, Self::Error> {
332        match interface {
333            0x00 => Ok(UsbType::Uhci),
334            0x10 => Ok(UsbType::Ohci),
335            0x20 => Ok(UsbType::Ehci),
336            0x30 => Ok(UsbType::Xhci),
337            0x80 => Ok(UsbType::OtherInterface),
338            0xfe => Ok(UsbType::Device),
339            _ => Err(()),
340        }
341    }
342}