diff --git a/arch/src/lib.rs b/arch/src/lib.rs index 266bb77dd1..086ad114f4 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -40,12 +40,6 @@ use devices::BusError; use devices::BusResumeDevice; use devices::HotPlugBus; use devices::IrqChip; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use devices::IrqChipAArch64 as IrqChipArch; -#[cfg(target_arch = "riscv64")] -use devices::IrqChipRiscv64 as IrqChipArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use devices::IrqChipX86_64 as IrqChipArch; use devices::IrqEventSource; use devices::PciAddress; use devices::PciBus; @@ -62,42 +56,8 @@ use devices::SerialParameters; use devices::VirtioMmioDevice; #[cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), feature = "gdb"))] use gdbstub::arch::Arch; -#[cfg(all(target_arch = "aarch64", feature = "gdb"))] -use gdbstub_arch::aarch64::AArch64 as GdbArch; -#[cfg(all(target_arch = "x86_64", feature = "gdb"))] -use gdbstub_arch::x86::X86_64_SSE as GdbArch; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::CpuConfigAArch64 as CpuConfigArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::CpuConfigRiscv64 as CpuConfigArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::CpuConfigX86_64 as CpuConfigArch; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::Hypervisor as HypervisorArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::Hypervisor as HypervisorArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::HypervisorX86_64 as HypervisorArch; use hypervisor::IoEventAddress; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VcpuAArch64 as VcpuArch; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VcpuInitAArch64 as VcpuInitArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::VcpuInitRiscv64 as VcpuInitArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VcpuInitX86_64 as VcpuInitArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::VcpuRiscv64 as VcpuArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VcpuX86_64 as VcpuArch; use hypervisor::Vm; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VmAArch64 as VmArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::VmRiscv64 as VmArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VmX86_64 as VmArch; #[cfg(windows)] use jail::FakeMinijailStub as Minijail; #[cfg(unix)] @@ -126,6 +86,35 @@ use vm_memory::GuestMemory; use vm_memory::GuestMemoryError; use vm_memory::MemoryRegionOptions; +cfg_if::cfg_if! { + if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] { + pub use devices::IrqChipAArch64 as IrqChipArch; + #[cfg(feature = "gdb")] + pub use gdbstub_arch::aarch64::AArch64 as GdbArch; + pub use hypervisor::CpuConfigAArch64 as CpuConfigArch; + pub use hypervisor::Hypervisor as HypervisorArch; + pub use hypervisor::VcpuAArch64 as VcpuArch; + pub use hypervisor::VcpuInitAArch64 as VcpuInitArch; + pub use hypervisor::VmAArch64 as VmArch; + } else if #[cfg(target_arch = "riscv64")] { + pub use devices::IrqChipRiscv64 as IrqChipArch; + pub use hypervisor::CpuConfigRiscv64 as CpuConfigArch; + pub use hypervisor::Hypervisor as HypervisorArch; + pub use hypervisor::VcpuInitRiscv64 as VcpuInitArch; + pub use hypervisor::VcpuRiscv64 as VcpuArch; + pub use hypervisor::VmRiscv64 as VmArch; + } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { + pub use devices::IrqChipX86_64 as IrqChipArch; + #[cfg(feature = "gdb")] + pub use gdbstub_arch::x86::X86_64_SSE as GdbArch; + pub use hypervisor::CpuConfigX86_64 as CpuConfigArch; + pub use hypervisor::HypervisorX86_64 as HypervisorArch; + pub use hypervisor::VcpuInitX86_64 as VcpuInitArch; + pub use hypervisor::VcpuX86_64 as VcpuArch; + pub use hypervisor::VmX86_64 as VmArch; + } +} + pub enum VmImage { Kernel(File), Bios(File), diff --git a/src/crosvm/gdb.rs b/src/crosvm/gdb.rs index b00979d712..2f66c9e015 100644 --- a/src/crosvm/gdb.rs +++ b/src/crosvm/gdb.rs @@ -9,6 +9,8 @@ use std::time::Duration; #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] use aarch64::AArch64 as CrosvmArch; use anyhow::Context; +use arch::GdbArch; +use arch::VcpuArch; use base::error; use base::info; use base::Tube; @@ -36,14 +38,6 @@ use gdbstub::target::ext::breakpoints::HwBreakpointOps; use gdbstub::target::Target; use gdbstub::target::TargetError::NonFatal; use gdbstub::target::TargetResult; -#[cfg(target_arch = "aarch64")] -use gdbstub_arch::aarch64::AArch64 as GdbArch; -#[cfg(target_arch = "x86_64")] -use gdbstub_arch::x86::X86_64_SSE as GdbArch; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VcpuAArch64 as VcpuArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VcpuX86_64 as VcpuArch; use remain::sorted; use sync::Mutex; use thiserror::Error as ThisError; diff --git a/src/crosvm/sys/unix.rs b/src/crosvm/sys/unix.rs index cc35d36c36..7687819485 100644 --- a/src/crosvm/sys/unix.rs +++ b/src/crosvm/sys/unix.rs @@ -45,10 +45,13 @@ use anyhow::anyhow; use anyhow::bail; use anyhow::Context; use anyhow::Result; +use arch::IrqChipArch; use arch::LinuxArch; use arch::RunnableLinuxVm; use arch::VcpuAffinity; +use arch::VcpuArch; use arch::VirtioDeviceStub; +use arch::VmArch; use arch::VmComponents; use arch::VmImage; use base::ReadNotifier; @@ -93,12 +96,6 @@ use devices::HostHotPlugKey; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] use devices::HotPlugBus; use devices::IommuDevType; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use devices::IrqChipAArch64 as IrqChipArch; -#[cfg(target_arch = "riscv64")] -use devices::IrqChipRiscv64 as IrqChipArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use devices::IrqChipX86_64 as IrqChipArch; use devices::IrqEventIndex; use devices::IrqEventSource; use devices::KvmKernelIrqChip; @@ -149,20 +146,8 @@ use hypervisor::CpuConfigX86_64; use hypervisor::Hypervisor; use hypervisor::HypervisorCap; use hypervisor::ProtectionType; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VcpuAArch64 as VcpuArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::VcpuRiscv64 as VcpuArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VcpuX86_64 as VcpuArch; use hypervisor::Vm; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VmAArch64 as VmArch; use hypervisor::VmCap; -#[cfg(target_arch = "riscv64")] -use hypervisor::VmRiscv64 as VmArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VmX86_64 as VmArch; use jail::*; use libc; use minijail::Minijail; diff --git a/src/crosvm/sys/unix/vcpu.rs b/src/crosvm/sys/unix/vcpu.rs index 13d2d8de85..61c37e868f 100644 --- a/src/crosvm/sys/unix/vcpu.rs +++ b/src/crosvm/sys/unix/vcpu.rs @@ -21,48 +21,23 @@ use aarch64::AArch64 as Arch; use aarch64::MsrHandlers; use anyhow::Context; use anyhow::Result; +use arch::CpuConfigArch; use arch::CpuSet; +use arch::IrqChipArch; use arch::LinuxArch; use arch::MsrConfig; +use arch::VcpuArch; +use arch::VcpuInitArch; +use arch::VmArch; use base::*; use devices::Bus; use devices::IrqChip; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use devices::IrqChipAArch64 as IrqChipArch; -#[cfg(target_arch = "riscv64")] -use devices::IrqChipRiscv64 as IrqChipArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use devices::IrqChipX86_64 as IrqChipArch; use devices::VcpuRunState; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::CpuConfigAArch64 as CpuConfigArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::CpuConfigRiscv64 as CpuConfigArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::CpuConfigX86_64 as CpuConfigArch; use hypervisor::IoOperation; use hypervisor::IoParams; use hypervisor::Vcpu; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VcpuAArch64 as VcpuArch; use hypervisor::VcpuExit; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VcpuInitAArch64 as VcpuInitArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::VcpuInitRiscv64 as VcpuInitArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VcpuInitX86_64 as VcpuInitArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::VcpuRiscv64 as VcpuArch; use hypervisor::VcpuRunHandle; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VcpuX86_64 as VcpuArch; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VmAArch64 as VmArch; -#[cfg(target_arch = "riscv64")] -use hypervisor::VmRiscv64 as VmArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VmX86_64 as VmArch; use libc::c_int; #[cfg(target_arch = "riscv64")] use riscv64::MsrHandlers; diff --git a/src/sys/windows.rs b/src/sys/windows.rs index 5feb6589da..4f0546f5ce 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -38,9 +38,13 @@ use anyhow::anyhow; use anyhow::bail; use anyhow::Context; use anyhow::Result; +use arch::CpuConfigArch; +use arch::IrqChipArch; use arch::LinuxArch; use arch::RunnableLinuxVm; +use arch::VcpuArch; use arch::VirtioDeviceStub; +use arch::VmArch; use arch::VmComponents; use arch::VmImage; use base::enable_high_res_timers; @@ -105,10 +109,6 @@ use devices::BusDeviceObj; use devices::GvmIrqChip; #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] use devices::IrqChip; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use devices::IrqChipAArch64 as IrqChipArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use devices::IrqChipX86_64 as IrqChipArch; use devices::UserspaceIrqChip; use devices::VirtioPciDevice; #[cfg(feature = "whpx")] @@ -141,24 +141,14 @@ use hypervisor::whpx::WhpxFeature; use hypervisor::whpx::WhpxVcpu; #[cfg(feature = "whpx")] use hypervisor::whpx::WhpxVm; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::CpuConfigX86_64; use hypervisor::Hypervisor; #[cfg(feature = "whpx")] use hypervisor::HypervisorCap; #[cfg(feature = "whpx")] use hypervisor::HypervisorX86_64; use hypervisor::ProtectionType; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VcpuAArch64 as VcpuArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VcpuX86_64 as VcpuArch; #[cfg(any(feature = "gvm", feature = "whpx"))] use hypervisor::Vm; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VmAArch64 as VmArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VmX86_64 as VmArch; use irq_wait::IrqWaitWorker; use jail::FakeMinijailStub as Minijail; #[cfg(not(feature = "crash-report"))] diff --git a/src/sys/windows/generic.rs b/src/sys/windows/generic.rs index a25801633c..d98c42305a 100644 --- a/src/sys/windows/generic.rs +++ b/src/sys/windows/generic.rs @@ -7,7 +7,9 @@ use std::thread::JoinHandle; use anyhow::Result; use arch::RunnableLinuxVm; +use arch::VcpuArch; use arch::VirtioDeviceStub; +use arch::VmArch; use base::AsRawDescriptor; use base::Event; use base::EventToken; @@ -34,8 +36,6 @@ use devices::virtio::DisplayBackend; use devices::virtio::EventDevice; use devices::virtio::Gpu; use devices::virtio::GpuParameters; -use hypervisor::VcpuX86_64 as VcpuArch; -use hypervisor::VmX86_64 as VmArch; pub(crate) use metrics::log_descriptor; pub(crate) use metrics::MetricEventType; use sync::Mutex; diff --git a/src/sys/windows/irq_wait.rs b/src/sys/windows/irq_wait.rs index 9029b4d3a3..be7b23a70c 100644 --- a/src/sys/windows/irq_wait.rs +++ b/src/sys/windows/irq_wait.rs @@ -12,6 +12,7 @@ use std::thread::JoinHandle; use std::time::Duration; use std::time::Instant; +use arch::IrqChipArch; use base::error; use base::info; use base::warn; @@ -23,10 +24,6 @@ use base::Tube; use base::TubeError; use base::WaitContext; use base::MAXIMUM_WAIT_OBJECTS; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use devices::IrqChipAArch64 as IrqChipArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use devices::IrqChipX86_64 as IrqChipArch; use devices::IrqEdgeEvent; use devices::IrqEventIndex; use devices::IrqEventSource; diff --git a/src/sys/windows/run_vcpu.rs b/src/sys/windows/run_vcpu.rs index 073025e0b4..9e03398dcb 100644 --- a/src/sys/windows/run_vcpu.rs +++ b/src/sys/windows/run_vcpu.rs @@ -20,10 +20,14 @@ use std::time::Instant; use aarch64::AArch64 as Arch; use anyhow::anyhow; use anyhow::Result; +use arch::CpuConfigArch; use arch::CpuSet; +use arch::IrqChipArch; use arch::LinuxArch; use arch::RunnableLinuxVm; use arch::VcpuAffinity; +use arch::VcpuArch; +use arch::VmArch; use base::error; use base::info; use base::set_audio_thread_priorities; @@ -48,12 +52,6 @@ use crosvm_cli::sys::windows::exit::ExitContext; use crosvm_cli::sys::windows::exit::ExitContextAnyhow; use devices::tsc::TscSyncMitigations; use devices::Bus; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use devices::IrqChip; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use devices::IrqChipAArch64 as IrqChipArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use devices::IrqChipX86_64 as IrqChipArch; use devices::VcpuRunState; use futures::pin_mut; #[cfg(feature = "whpx")] @@ -64,17 +62,9 @@ use hypervisor::HypervisorCap; use hypervisor::IoEventAddress; use hypervisor::IoOperation; use hypervisor::IoParams; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VcpuAArch64 as VcpuArch; use hypervisor::VcpuExit; use hypervisor::VcpuInitX86_64; use hypervisor::VcpuRunHandle; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VcpuX86_64 as VcpuArch; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] -use hypervisor::VmAArch64 as VmArch; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use hypervisor::VmX86_64 as VmArch; use sync::Condvar; use sync::Mutex; use vm_control::VmRunMode;