aarch64: Simplify GIC related structs definition

Combined the `GicDevice` struct in `arch` crate and the `Gic` struct in
`devices` crate.

After moving the KVM specific code for GIC in `arch`, a very thin wapper
layer `GicDevice` was left in `arch` crate. It is easy to combine it
with the `Gic` in `devices` crate.

Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
Michael Zhao
2022-06-01 13:24:12 +08:00
committed by Xin Wang
parent 04949755c0
commit 957d3a7443
12 changed files with 150 additions and 161 deletions

View File

@@ -12,7 +12,6 @@ use icc_regs::{get_icc_regs, set_icc_regs};
use redist_regs::{construct_gicr_typers, get_redist_regs, set_redist_regs};
use serde::{Deserialize, Serialize};
use std::any::Any;
use std::boxed::Box;
use std::convert::TryInto;
use std::sync::Arc;
@@ -254,13 +253,13 @@ impl KvmGicV3Its {
redist_size: u64,
msi_size: u64,
nr_irqs: u32,
) -> Result<Box<dyn Vgic>> {
) -> Result<KvmGicV3Its> {
let vgic = Self::create_device(vm)?;
let redists_size: u64 = redist_size * vcpu_count;
let redists_addr: u64 = dist_addr - redists_size;
let msi_addr: u64 = redists_addr - msi_size;
let mut gic_device = Box::new(KvmGicV3Its {
let mut gic_device = KvmGicV3Its {
device: vgic,
its_device: None,
gicr_typers: vec![0; vcpu_count.try_into().unwrap()],
@@ -271,7 +270,7 @@ impl KvmGicV3Its {
msi_addr,
msi_size,
vcpu_count,
});
};
gic_device.init_device_attributes(vm, nr_irqs)?;

View File

@@ -35,6 +35,8 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::result;
#[cfg(target_arch = "x86_64")]
use std::sync::atomic::{AtomicBool, Ordering};
#[cfg(target_arch = "aarch64")]
use std::sync::Mutex;
use std::sync::{Arc, RwLock};
use vmm_sys_util::eventfd::EventFd;
// x86_64 dependencies
@@ -266,8 +268,8 @@ impl vm::Vm for KvmVm {
redist_size: u64,
msi_size: u64,
nr_irqs: u32,
) -> vm::Result<Box<dyn Vgic>> {
KvmGicV3Its::new(
) -> vm::Result<Arc<Mutex<dyn Vgic>>> {
let gic_device = KvmGicV3Its::new(
self,
vcpu_count,
dist_addr,
@@ -276,7 +278,8 @@ impl vm::Vm for KvmVm {
msi_size,
nr_irqs,
)
.map_err(|e| vm::HypervisorVmError::CreateVgic(anyhow!("Vgic error {:?}", e)))
.map_err(|e| vm::HypervisorVmError::CreateVgic(anyhow!("Vgic error {:?}", e)))?;
Ok(Arc::new(Mutex::new(gic_device)))
}
///
/// Registers an event to be signaled whenever a certain address is written to.

View File

@@ -29,6 +29,8 @@ use kvm_ioctls::Cap;
#[cfg(target_arch = "x86_64")]
use std::fs::File;
use std::sync::Arc;
#[cfg(target_arch = "aarch64")]
use std::sync::Mutex;
use thiserror::Error;
use vmm_sys_util::eventfd::EventFd;
@@ -285,7 +287,7 @@ pub trait Vm: Send + Sync {
redist_size: u64,
msi_size: u64,
nr_irqs: u32,
) -> Result<Box<dyn Vgic>>;
) -> Result<Arc<Mutex<dyn Vgic>>>;
/// Registers an event to be signaled whenever a certain address is written to.
fn register_ioevent(