1 // Copyright 2017 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 //! Emulates virtual and hardware devices. 6 7 mod bus; 8 mod cmos; 9 #[cfg(feature = "direct")] 10 pub mod direct_io; 11 #[cfg(feature = "direct")] 12 pub mod direct_irq; 13 mod i8042; 14 mod irq_event; 15 pub mod irqchip; 16 mod pci; 17 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] 18 mod pit; 19 pub mod pl030; 20 mod platform; 21 mod proxy; 22 #[cfg(feature = "usb")] 23 #[macro_use] 24 mod register_space; 25 pub mod acpi; 26 pub mod bat; 27 mod serial; 28 pub mod serial_device; 29 #[cfg(feature = "tpm")] 30 mod software_tpm; 31 mod sys; 32 #[cfg(feature = "usb")] 33 pub mod usb; 34 #[cfg(feature = "usb")] 35 mod utils; 36 pub mod vfio; 37 pub mod virtio; 38 39 pub use self::acpi::ACPIPMResource; 40 pub use self::bat::{BatteryError, GoldfishBattery}; 41 pub use self::bus::Error as BusError; 42 pub use self::bus::{ 43 Bus, BusAccessInfo, BusDevice, BusDeviceObj, BusDeviceSync, BusRange, BusResumeDevice, BusType, 44 HostHotPlugKey, HotPlugBus, 45 }; 46 pub use self::cmos::Cmos; 47 #[cfg(feature = "direct")] 48 pub use self::direct_io::{DirectIo, DirectMmio}; 49 #[cfg(feature = "direct")] 50 pub use self::direct_irq::{DirectIrq, DirectIrqError}; 51 pub use self::i8042::I8042Device; 52 pub use self::irq_event::{IrqEdgeEvent, IrqLevelEvent}; 53 pub use self::irqchip::*; 54 #[cfg(feature = "audio")] 55 pub use self::pci::{Ac97Backend, Ac97Dev, Ac97Parameters}; 56 pub use self::pci::{ 57 BarRange, CoIommuDev, CoIommuParameters, CoIommuUnpinPolicy, PciAddress, PciBridge, 58 PciClassCode, PciConfigIo, PciConfigMmio, PciDevice, PciDeviceError, PciInterruptPin, PciRoot, 59 PciVirtualConfigMmio, PcieHostRootPort, PcieRootPort, PvPanicCode, PvPanicPciDevice, 60 StubPciDevice, StubPciParameters, VfioPciDevice, 61 }; 62 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] 63 pub use self::pit::{Pit, PitError}; 64 pub use self::pl030::Pl030; 65 pub use self::platform::VfioPlatformDevice; 66 pub use self::proxy::Error as ProxyError; 67 pub use self::proxy::ProxyDevice; 68 pub use self::serial::Serial; 69 pub use self::serial_device::{ 70 Error as SerialError, SerialDevice, SerialHardware, SerialParameters, SerialType, 71 }; 72 #[cfg(feature = "tpm")] 73 pub use self::software_tpm::SoftwareTpm; 74 #[cfg(feature = "usb")] 75 pub use self::usb::host_backend::host_backend_device_provider::HostBackendDeviceProvider; 76 #[cfg(feature = "usb")] 77 pub use self::usb::xhci::xhci_controller::XhciController; 78 pub use self::vfio::{VfioContainer, VfioDevice}; 79 pub use self::virtio::{vfio_wrapper, VirtioPciDevice}; 80 81 /// Request CoIOMMU to unpin a specific range. 82 use serde::{Deserialize, Serialize}; 83 #[derive(Serialize, Deserialize, Debug)] 84 pub struct UnpinRequest { 85 /// The ranges presents (start gfn, count). 86 ranges: Vec<(u64, u64)>, 87 } 88 89 #[derive(Serialize, Deserialize, Debug)] 90 pub enum UnpinResponse { 91 Success, 92 Failed, 93 } 94 95 #[derive(Debug)] 96 pub enum ParseIommuDevTypeResult { 97 NoSuchType, 98 } 99 100 #[derive(Copy, Clone, Eq, PartialEq)] 101 pub enum IommuDevType { 102 NoIommu, 103 VirtioIommu, 104 CoIommu, 105 } 106 107 use std::str::FromStr; 108 impl FromStr for IommuDevType { 109 type Err = ParseIommuDevTypeResult; 110 from_str(s: &str) -> Result<Self, Self::Err>111 fn from_str(s: &str) -> Result<Self, Self::Err> { 112 match s { 113 "off" => Ok(IommuDevType::NoIommu), 114 "viommu" => Ok(IommuDevType::VirtioIommu), 115 "coiommu" => Ok(IommuDevType::CoIommu), 116 _ => Err(ParseIommuDevTypeResult::NoSuchType), 117 } 118 } 119 } 120