diff --git a/arch/src/lib.rs b/arch/src/lib.rs index 91b4b6775c..31a94c423e 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -92,6 +92,7 @@ pub struct VmComponents { #[cfg(all(target_arch = "x86_64", feature = "gdb"))] pub gdb: Option<(u32, Tube)>, // port and control tube. pub dmi_path: Option, + pub no_legacy: bool, } /// Holds the elements needed to run a Linux VM. Created by `build_vm`. diff --git a/src/crosvm.rs b/src/crosvm.rs index 7a4318ab3e..e40c54fcdc 100644 --- a/src/crosvm.rs +++ b/src/crosvm.rs @@ -264,6 +264,7 @@ pub struct Config { #[cfg(feature = "direct")] pub direct_edge_irq: Vec, pub dmi_path: Option, + pub no_legacy: bool, } impl Default for Config { @@ -340,6 +341,7 @@ impl Default for Config { #[cfg(feature = "direct")] direct_edge_irq: Vec::new(), dmi_path: None, + no_legacy: false, } } } diff --git a/src/linux.rs b/src/linux.rs index 9632dbd31b..d0f8f072a9 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -2325,6 +2325,7 @@ fn setup_vm_components(cfg: &Config) -> Result { #[cfg(all(target_arch = "x86_64", feature = "gdb"))] gdb: None, dmi_path: cfg.dmi_path.clone(), + no_legacy: cfg.no_legacy, }) } diff --git a/src/main.rs b/src/main.rs index e86845a656..2d951a0536 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1751,6 +1751,9 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument:: } cfg.dmi_path = Some(dmi_path); } + "no-legacy" => { + cfg.no_legacy = true; + } "help" => return Err(argument::Error::PrintHelp), _ => unreachable!(), } @@ -1972,6 +1975,7 @@ writeback=BOOL - Indicates whether the VM can use writeback caching (default: fa #[cfg(feature = "direct")] Argument::value("direct-edge-irq", "irq", "Enable interrupt passthrough"), Argument::value("dmi", "DIR", "Directory with smbios_entry_point/DMI files"), + Argument::flag("no-legacy", "Don't use legacy KBD/RTC devices emulation"), Argument::short_flag('h', "help", "Print help message.")]; let mut cfg = Config::default(); diff --git a/x86_64/src/lib.rs b/x86_64/src/lib.rs index 91dde5d218..b8444dbfd8 100644 --- a/x86_64/src/lib.rs +++ b/x86_64/src/lib.rs @@ -409,18 +409,19 @@ impl arch::LinuxArch for X8664arch { ) .map_err(Error::CreatePciRoot)?; let pci_bus = Arc::new(Mutex::new(PciConfigIo::new(pci))); + io_bus.insert(pci_bus, 0xcf8, 0x8).unwrap(); // Event used to notify crosvm that guest OS is trying to suspend. let suspend_evt = Event::new().map_err(Error::CreateEvent)?; - Self::setup_io_bus( - &mut io_bus, - irq_chip.pit_uses_speaker_port(), - exit_evt.try_clone().map_err(Error::CloneEvent)?, - Some(pci_bus), - components.memory_size, - )?; - + if !components.no_legacy { + Self::setup_legacy_devices( + &mut io_bus, + irq_chip.pit_uses_speaker_port(), + exit_evt.try_clone().map_err(Error::CloneEvent)?, + components.memory_size, + )?; + } Self::setup_serial_devices( components.protected_vm, irq_chip.as_irq_chip_mut(), @@ -947,7 +948,7 @@ impl X8664arch { cmdline } - /// Sets up the IO bus for this platform + /// Sets up the legacy x86 IO platform devices /// /// # Arguments /// @@ -955,11 +956,10 @@ impl X8664arch { /// * - `pit_uses_speaker_port` - does the PIT use port 0x61 for the PC speaker /// * - `exit_evt` - the event object which should receive exit events /// * - `mem_size` - the size in bytes of physical ram for the guest - fn setup_io_bus( + fn setup_legacy_devices( io_bus: &mut devices::Bus, pit_uses_speaker_port: bool, exit_evt: Event, - pci: Option>>, mem_size: u64, ) -> Result<()> { struct NoDevice; @@ -1005,13 +1005,6 @@ impl X8664arch { io_bus.insert(nul_device.clone(), 0x0ed, 0x1).unwrap(); // most likely this one does nothing io_bus.insert(nul_device.clone(), 0x0f0, 0x2).unwrap(); // ignore fpu - if let Some(pci_root) = pci { - io_bus.insert(pci_root, 0xcf8, 0x8).unwrap(); - } else { - // ignore pci. - io_bus.insert(nul_device, 0xcf8, 0x8).unwrap(); - } - Ok(()) } diff --git a/x86_64/src/test_integration.rs b/x86_64/src/test_integration.rs index 051a4015ea..551a259eaf 100644 --- a/x86_64/src/test_integration.rs +++ b/x86_64/src/test_integration.rs @@ -137,12 +137,12 @@ where ) .unwrap(); let pci_bus = Arc::new(Mutex::new(PciConfigIo::new(pci))); + io_bus.insert(pci_bus, 0xcf8, 0x8).unwrap(); - X8664arch::setup_io_bus( + X8664arch::setup_legacy_devices( &mut io_bus, irq_chip.pit_uses_speaker_port(), exit_evt.try_clone().unwrap(), - Some(pci_bus), memory_size, ) .unwrap();