diff --git a/devices/src/irqchip/mod.rs b/devices/src/irqchip/mod.rs index 38b607186a..3ac9a39f1e 100644 --- a/devices/src/irqchip/mod.rs +++ b/devices/src/irqchip/mod.rs @@ -15,54 +15,35 @@ use resources::SystemAllocator; cfg_if::cfg_if! { if #[cfg(unix)] { mod kvm; - - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - mod x86_64; - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - pub use x86_64::*; - - #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] - mod aarch64; - #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] - pub use aarch64::*; - - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - mod pic; - - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - pub use pic::*; - - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - mod ioapic; - - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - pub use ioapic::*; - - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - mod apic; - - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - pub use apic::*; - - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - mod userspace; - - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - pub use userspace::*; - pub use self::kvm::KvmKernelIrqChip; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub use self::kvm::KvmSplitIrqChip; #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] pub use self::kvm::{AARCH64_GIC_NR_IRQS, AARCH64_GIC_NR_SPIS}; - } else if #[cfg(windows)] { - #[cfg(feature = "whpx")] + } else if #[cfg(all(windows, feature = "whpx"))] { mod whpx; - #[cfg(feature = "whpx")] pub use self::whpx::WhpxSplitIrqChip; } } +cfg_if::cfg_if! { + if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { + mod x86_64; + pub use x86_64::*; + mod pic; + pub use pic::*; + mod ioapic; + pub use ioapic::*; + mod apic; + pub use apic::*; + mod userspace; + pub use userspace::*; + } else if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] { + mod aarch64; + pub use aarch64::*; + } +} + pub type IrqEventIndex = usize; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] diff --git a/devices/src/lib.rs b/devices/src/lib.rs index 4b1821798d..952bedd65a 100644 --- a/devices/src/lib.rs +++ b/devices/src/lib.rs @@ -10,14 +10,20 @@ mod bus; mod irq_event; pub mod irqchip; mod pci; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -mod pit; pub mod serial_device; mod sys; pub mod virtio; #[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] mod vtpm_proxy; +cfg_if::cfg_if! { + if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { + mod pit; + pub use self::pit::{Pit, PitError}; + pub mod tsc; + } +} + pub use self::bus::{ Bus, BusAccessInfo, BusDevice, BusDeviceObj, BusDeviceSync, BusRange, BusResumeDevice, BusType, HostHotPlugKey, HotPlugBus, @@ -30,8 +36,6 @@ pub use self::pci::{ PciDeviceError, PciInterruptPin, PciRoot, PciVirtualConfigMmio, StubPciDevice, StubPciParameters, }; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -pub use self::pit::{Pit, PitError}; #[cfg(all(feature = "tpm", feature = "chromeos", target_arch = "x86_64"))] pub use self::vtpm_proxy::VtpmProxy; @@ -56,8 +60,6 @@ cfg_if::cfg_if! { mod serial; #[cfg(feature = "tpm")] mod software_tpm; - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - pub mod tsc; #[cfg(feature = "usb")] pub mod usb; #[cfg(feature = "usb")] diff --git a/devices/src/pit.rs b/devices/src/pit.rs index daeee5608f..85d23c0989 100644 --- a/devices/src/pit.rs +++ b/devices/src/pit.rs @@ -16,15 +16,15 @@ use remain::sorted; use sync::Mutex; use thiserror::Error; -#[cfg(not(test))] -use base::Clock; -#[cfg(test)] -use base::FakeClock as Clock; - -#[cfg(test)] -use base::FakeTimer as Timer; -#[cfg(not(test))] -use base::Timer; +cfg_if::cfg_if! { + if #[cfg(test)] { + use base::FakeClock as Clock; + use base::FakeTimer as Timer; + } else { + use base::Clock; + use base::Timer; + } +} use crate::bus::BusAccessInfo; use crate::pci::CrosvmDeviceId;