From 7932cd22caea566129bab9972d77ccdf7fc0b0b3 Mon Sep 17 00:00:00 2001 From: Michael Zhao Date: Tue, 1 Jun 2021 20:03:05 +0800 Subject: [PATCH] vmm: Remove GIC entity set/get from DeviceManager Moved the set/get functions from vmm::DeviceManager to devices::Gic. Signed-off-by: Michael Zhao --- devices/src/gic.rs | 13 ++++++++++++- vmm/src/device_manager.rs | 5 +++++ vmm/src/vm.rs | 24 ++++++++++++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/devices/src/gic.rs b/devices/src/gic.rs index 4ed64f336..8621497a4 100644 --- a/devices/src/gic.rs +++ b/devices/src/gic.rs @@ -4,8 +4,9 @@ use super::interrupt_controller::{Error, InterruptController}; extern crate arch; +use arch::aarch64::gic::GicDevice; use std::result; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use vm_device::interrupt::{ InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup, LegacyIrqSourceConfig, MsiIrqGroupConfig, @@ -26,6 +27,7 @@ pub const IRQ_LEGACY_COUNT: usize = 32; // 2. Move this file and ioapic.rs to arch/, as they are architecture specific. pub struct Gic { interrupt_source_group: Arc>, + gic_device: Option>>>, } impl Gic { @@ -42,8 +44,17 @@ impl Gic { Ok(Gic { interrupt_source_group, + gic_device: None, }) } + + pub fn set_gic_device(&mut self, gic_device: Arc>>) { + self.gic_device = Some(gic_device); + } + + pub fn get_gic_device(&self) -> Option<&Arc>>> { + self.gic_device.as_ref() + } } impl InterruptController for Gic { diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index d9936c4ca..c1658f79b 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -1261,6 +1261,11 @@ impl DeviceManager { Ok(interrupt_controller) } + #[cfg(target_arch = "aarch64")] + pub fn get_interrupt_controller(&mut self) -> Option<&Arc>> { + self.interrupt_controller.as_ref() + } + #[cfg(target_arch = "aarch64")] pub fn set_gic_device_entity(&mut self, device_entity: Arc>>) { self.gic_device_entity = Some(device_entity); diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 069f688b0..ff8efd582 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -1044,7 +1044,11 @@ impl Vm { self.device_manager .lock() .unwrap() - .set_gic_device_entity(Arc::new(Mutex::new(gic_device))); + .get_interrupt_controller() + .unwrap() + .lock() + .unwrap() + .set_gic_device(Arc::new(Mutex::new(gic_device))); self.device_manager .lock() @@ -1865,7 +1869,11 @@ impl Vm { self.device_manager .lock() .unwrap() - .get_gic_device_entity() + .get_interrupt_controller() + .unwrap() + .lock() + .unwrap() + .get_gic_device() .unwrap() .lock() .unwrap() @@ -1898,7 +1906,11 @@ impl Vm { self.device_manager .lock() .unwrap() - .set_gic_device_entity(Arc::new(Mutex::new(gic_device))); + .get_interrupt_controller() + .unwrap() + .lock() + .unwrap() + .set_gic_device(Arc::new(Mutex::new(gic_device))); // Here we prepare the GICR_TYPER registers from the restored vCPU states. self.device_manager @@ -1911,7 +1923,11 @@ impl Vm { self.device_manager .lock() .unwrap() - .get_gic_device_entity() + .get_interrupt_controller() + .unwrap() + .lock() + .unwrap() + .get_gic_device() .unwrap() .lock() .unwrap()