arch: vmm: Move ACPI tables creation to vmm crate

Remove ACPI table creation from arch crate to the vmm crate simplifying
arch::configure_system()

GuestAddress(0) is used to mean no RSDP table rather than adding
complexity with a conditional argument or an Option type as it will
evaluate to a zero value which would be the default anyway.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2019-11-06 17:20:55 +00:00
parent c3eaa41b77
commit 0319a4a09a
7 changed files with 43 additions and 77 deletions

View File

@ -5,7 +5,6 @@ authors = ["The Chromium OS Authors"]
[features]
default = []
acpi = ["acpi_tables"]
[dependencies]
byteorder = "1.3.2"

View File

@ -16,8 +16,7 @@ pub fn configure_system(
_cmdline_addr: GuestAddress,
_cmdline_size: usize,
_num_cpus: u8,
_serial_enabled: bool,
_virt_iommu: Option<(u32, &[u32])>,
_rsdp_addr: Option<GuestAddress>,
) -> super::Result<()> {
Ok(())
}

View File

@ -5,9 +5,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file.
#[cfg(feature = "acpi")]
mod acpi;
mod gdt;
pub mod interrupts;
pub mod layout;
@ -111,9 +108,7 @@ pub fn configure_system(
cmdline_size: usize,
num_cpus: u8,
setup_hdr: Option<setup_header>,
_serial_enabled: bool,
_end_of_range: GuestAddress,
_virt_iommu: Option<(u32, &[u32])>,
rsdp_addr: Option<GuestAddress>,
) -> super::Result<()> {
const KERNEL_BOOT_FLAG_MAGIC: u16 = 0xaa55;
const KERNEL_HDR_MAGIC: u32 = 0x53726448;
@ -172,21 +167,7 @@ pub fn configure_system(
E820_RESERVED,
)?;
#[cfg(feature = "acpi")]
{
let start_of_device_area = if mem_end < layout::MEM_32BIT_RESERVED_START {
layout::RAM_64BIT_START
} else {
guest_mem.end_addr().unchecked_add(1)
};
let rsdp_addr = acpi::create_acpi_tables(
guest_mem,
num_cpus,
_serial_enabled,
start_of_device_area,
_end_of_range,
_virt_iommu,
);
if let Some(rsdp_addr) = rsdp_addr {
params.0.acpi_rsdp_addr = rsdp_addr.0;
}
@ -246,16 +227,7 @@ mod tests {
fn test_system_configuration() {
let no_vcpus = 4;
let gm = GuestMemoryMmap::new(&vec![(GuestAddress(0), 0x10000)]).unwrap();
let config_err = configure_system(
&gm,
GuestAddress(0),
0,
1,
None,
false,
GuestAddress((1 << 36) - 1),
None,
);
let config_err = configure_system(&gm, GuestAddress(0), 0, 1, None, None);
assert!(config_err.is_err());
assert_eq!(
config_err.unwrap_err(),
@ -273,17 +245,7 @@ mod tests {
.map(|r| (r.0, r.1))
.collect();
let gm = GuestMemoryMmap::new(&ram_regions).unwrap();
configure_system(
&gm,
GuestAddress(0),
0,
no_vcpus,
None,
false,
GuestAddress((1 << 36) - 1),
None,
)
.unwrap();
configure_system(&gm, GuestAddress(0), 0, no_vcpus, None, None).unwrap();
// Now assigning some memory that is equal to the start of the 32bit memory hole.
let mem_size = 3328 << 20;
@ -294,17 +256,7 @@ mod tests {
.map(|r| (r.0, r.1))
.collect();
let gm = GuestMemoryMmap::new(&ram_regions).unwrap();
configure_system(
&gm,
GuestAddress(0),
0,
no_vcpus,
None,
false,
GuestAddress((1 << 36) - 1),
None,
)
.unwrap();
configure_system(&gm, GuestAddress(0), 0, no_vcpus, None, None).unwrap();
// Now assigning some memory that falls after the 32bit memory hole.
let mem_size = 3330 << 20;
@ -315,17 +267,7 @@ mod tests {
.map(|r| (r.0, r.1))
.collect();
let gm = GuestMemoryMmap::new(&ram_regions).unwrap();
configure_system(
&gm,
GuestAddress(0),
0,
no_vcpus,
None,
false,
GuestAddress((1 << 36) - 1),
None,
)
.unwrap();
configure_system(&gm, GuestAddress(0), 0, no_vcpus, None, None).unwrap();
}
#[test]

View File

@ -6,7 +6,7 @@ edition = "2018"
[features]
default = []
acpi = ["acpi_tables","devices/acpi", "arch/acpi"]
acpi = ["acpi_tables","devices/acpi"]
pci_support = ["pci", "vfio", "vm-virtio/pci_support"]
mmio_support = ["vm-virtio/mmio_support"]
cmos = ["devices/cmos"]

View File

@ -14,7 +14,7 @@ use vm_memory::{Address, ByteValued, Bytes};
use std::convert::TryInto;
use super::layout;
use arch::layout;
#[repr(packed)]
struct LocalAPIC {

View File

@ -30,6 +30,9 @@ pub mod config;
pub mod device_manager;
pub mod vm;
#[cfg(feature = "acpi")]
mod acpi;
/// Errors associated with VMM management
#[derive(Debug)]
#[allow(clippy::large_enum_variant)]

View File

@ -23,7 +23,7 @@ extern crate vm_allocator;
extern crate vm_memory;
extern crate vm_virtio;
use crate::config::{ConsoleOutputMode, VmConfig};
use crate::config::VmConfig;
use crate::device_manager::{get_win_size, Console, DeviceManager, DeviceManagerError};
use arch::RegionType;
use devices::ioapic;
@ -768,7 +768,34 @@ impl Vm {
)
.map_err(|_| Error::CmdLine)?;
let vcpu_count = self.config.cpus.cpu_count;
let end_of_range = GuestAddress((1 << get_host_cpu_phys_bits()) - 1);
#[allow(unused_mut, unused_assignments)]
let mut rsdp_addr: Option<GuestAddress> = None;
#[cfg(feature = "acpi")]
{
rsdp_addr = Some({
let end_of_range = GuestAddress((1 << get_host_cpu_phys_bits()) - 1);
let mem_end = mem.end_addr();
let start_of_device_area = if mem_end < arch::layout::MEM_32BIT_RESERVED_START {
arch::layout::RAM_64BIT_START
} else {
mem_end.unchecked_add(1)
};
use crate::config::ConsoleOutputMode;
crate::acpi::create_acpi_tables(
&mem,
vcpu_count,
self.config.serial.mode != ConsoleOutputMode::Off,
start_of_device_area,
end_of_range,
self.devices.virt_iommu(),
)
});
}
match entry_addr.setup_header {
Some(hdr) => {
arch::configure_system(
@ -777,9 +804,7 @@ impl Vm {
cmdline_cstring.to_bytes().len() + 1,
vcpu_count,
Some(hdr),
self.config.serial.mode != ConsoleOutputMode::Off,
end_of_range,
self.devices.virt_iommu(),
rsdp_addr,
)
.map_err(|_| Error::CmdLine)?;
@ -798,9 +823,7 @@ impl Vm {
cmdline_cstring.to_bytes().len() + 1,
vcpu_count,
None,
self.config.serial.mode != ConsoleOutputMode::Off,
end_of_range,
self.devices.virt_iommu(),
rsdp_addr,
)
.map_err(|_| Error::CmdLine)?;