1
0
mirror of https://github.com/cloud-hypervisor/cloud-hypervisor.git synced 2025-03-07 17:26:14 +00:00

vmm: Split create_gic() from configure_system()

Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
Michael Zhao 2021-05-31 22:30:24 +08:00 committed by Rob Bradford
parent 9341cce8b3
commit 195eba188a
2 changed files with 13 additions and 17 deletions
arch/src/aarch64
vmm/src

@ -131,30 +131,21 @@ pub fn arch_memory_regions(size: GuestUsize) -> Vec<(GuestAddress, usize, Region
} }
/// Configures the system and should be called once per vm before starting vcpu threads. /// Configures the system and should be called once per vm before starting vcpu threads.
///
/// # Arguments
///
/// * `guest_mem` - The memory to be used by the guest.
/// * `num_cpus` - Number of virtual CPUs the guest will have.
#[allow(clippy::too_many_arguments)]
pub fn configure_system<T: DeviceInfoForFdt + Clone + Debug, S: ::std::hash::BuildHasher>( pub fn configure_system<T: DeviceInfoForFdt + Clone + Debug, S: ::std::hash::BuildHasher>(
vm: &Arc<dyn hypervisor::Vm>,
guest_mem: &GuestMemoryMmap, guest_mem: &GuestMemoryMmap,
cmdline_cstring: &CStr, cmdline_cstring: &CStr,
vcpu_count: u64,
vcpu_mpidr: Vec<u64>, vcpu_mpidr: Vec<u64>,
device_info: &HashMap<(DeviceType, String), T, S>, device_info: &HashMap<(DeviceType, String), T, S>,
initrd: &Option<super::InitramfsConfig>, initrd: &Option<super::InitramfsConfig>,
pci_space_address: &(u64, u64), pci_space_address: &(u64, u64),
) -> super::Result<Box<dyn GicDevice>> { gic_device: &dyn GicDevice,
let gic_device = gic::kvm::create_gic(vm, vcpu_count).map_err(Error::SetupGic)?; ) -> super::Result<()> {
let fdt_final = fdt::create_fdt( let fdt_final = fdt::create_fdt(
guest_mem, guest_mem,
cmdline_cstring, cmdline_cstring,
vcpu_mpidr, vcpu_mpidr,
device_info, device_info,
&*gic_device, gic_device,
initrd, initrd,
pci_space_address, pci_space_address,
) )
@ -162,7 +153,7 @@ pub fn configure_system<T: DeviceInfoForFdt + Clone + Debug, S: ::std::hash::Bui
fdt::write_fdt_to_memory(fdt_final, guest_mem).map_err(Error::WriteFdtToMemory)?; fdt::write_fdt_to_memory(fdt_final, guest_mem).map_err(Error::WriteFdtToMemory)?;
Ok(gic_device) Ok(())
} }
/// Returns the memory address where the initramfs could be loaded. /// Returns the memory address where the initramfs could be loaded.

@ -1021,17 +1021,22 @@ impl Vm {
); );
} }
// Call `configure_system` and pass the GIC devices out, so that let gic_device = create_gic(
// we can register the GIC device to the device manager.
let gic_device = arch::configure_system(
&self.memory_manager.lock().as_ref().unwrap().vm, &self.memory_manager.lock().as_ref().unwrap().vm,
self.cpu_manager.lock().unwrap().boot_vcpus() as u64,
)
.map_err(|e| {
Error::ConfigureSystem(arch::Error::AArch64Setup(arch::aarch64::Error::SetupGic(e)))
})?;
arch::configure_system(
&mem, &mem,
&cmdline_cstring, &cmdline_cstring,
self.cpu_manager.lock().unwrap().boot_vcpus() as u64,
vcpu_mpidrs, vcpu_mpidrs,
device_info, device_info,
&initramfs_config, &initramfs_config,
&pci_space, &pci_space,
&*gic_device,
) )
.map_err(Error::ConfigureSystem)?; .map_err(Error::ConfigureSystem)?;