xref: /cloud-hypervisor/vm-device/src/lib.rs (revision b440cb7d2330770cd415b63544a371d4caa2db3a)
1 // Copyright © 2020 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #![allow(clippy::significant_drop_in_scrutinee)]
7 
8 use serde::{Deserialize, Serialize};
9 
10 mod bus;
11 pub mod dma_mapping;
12 pub mod interrupt;
13 
14 pub use self::bus::{Bus, BusDevice, Error as BusError};
15 
16 /// Type of Message Signalled Interrupt
17 #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
18 pub enum MsiIrqType {
19     /// PCI MSI IRQ numbers.
20     PciMsi,
21     /// PCI MSIx IRQ numbers.
22     PciMsix,
23     /// Generic MSI IRQ numbers.
24     GenericMsi,
25 }
26 
27 #[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
28 pub enum PciBarType {
29     Io,
30     Mmio32,
31     Mmio64,
32 }
33 
34 /// Enumeration for device resources.
35 #[allow(missing_docs)]
36 #[derive(Clone, Debug, Serialize, Deserialize)]
37 pub enum Resource {
38     /// IO Port address range.
39     PioAddressRange { base: u16, size: u16 },
40     /// Memory Mapped IO address range.
41     MmioAddressRange { base: u64, size: u64 },
42     /// PCI BAR
43     PciBar {
44         index: usize,
45         base: u64,
46         size: u64,
47         type_: PciBarType,
48         prefetchable: bool,
49     },
50     /// Legacy IRQ number.
51     LegacyIrq(u32),
52     /// Message Signaled Interrupt
53     MsiIrq {
54         ty: MsiIrqType,
55         base: u32,
56         size: u32,
57     },
58     /// Network Interface Card MAC address.
59     MacAddress(String),
60     /// KVM memslot index.
61     KvmMemSlot(u32),
62 }
63