diff --git a/alioth/src/arch/aarch64/layout.rs b/alioth/src/arch/aarch64/layout.rs index e3bb0ac..8c3104e 100644 --- a/alioth/src/arch/aarch64/layout.rs +++ b/alioth/src/arch/aarch64/layout.rs @@ -13,6 +13,10 @@ // limitations under the License. pub const MMIO_32_START: u64 = 0x1000_0000; // 256 MiB + +pub const GIC_V2_DIST_START: u64 = 0x1000_0000; // size 4 KiB +pub const GIC_V2_CPU_INTERFACE_START: u64 = 0x1000_1000; // size 8 KiB + pub const MMIO_32_END: u64 = 0x3000_0000; // 768 MiB, size = 512 MiB pub const PCIE_CONFIG_START: u64 = 0x3000_0000; // 768 MiB pub const MEM_64_START: u64 = 0x1_0000_0000; // 4GiB diff --git a/alioth/src/board/aarch64.rs b/alioth/src/board/aarch64.rs index 492ce11..b932e0a 100644 --- a/alioth/src/board/aarch64.rs +++ b/alioth/src/board/aarch64.rs @@ -12,16 +12,26 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::arch::layout::{GIC_V2_CPU_INTERFACE_START, GIC_V2_DIST_START}; use crate::board::{Board, BoardConfig, Result, VcpuGuard}; -use crate::hv::{Hypervisor, Vm}; +use crate::hv::{GicV2, Hypervisor, Vm}; use crate::loader::InitState; use crate::mem::mapped::ArcMemPages; -pub struct ArchBoard {} +pub struct ArchBoard +where + V: Vm, +{ + gic_v2: V::GicV2, +} -impl ArchBoard { - pub fn new(_hv: &H, _config: &BoardConfig) -> Result { - unimplemented!() +impl ArchBoard { + pub fn new(_hv: &H, vm: &V, _config: &BoardConfig) -> Result + where + H: Hypervisor, + { + let gic_v2 = vm.create_gic_v2(GIC_V2_DIST_START, GIC_V2_CPU_INTERFACE_START)?; + Ok(ArchBoard { gic_v2 }) } } @@ -60,4 +70,9 @@ where pub fn create_firmware_data(&self, _init_state: &InitState) -> Result<()> { unimplemented!() } + + pub fn arch_init(&self) -> Result<()> { + self.arch.gic_v2.init()?; + Ok(()) + } } diff --git a/alioth/src/board/board.rs b/alioth/src/board/board.rs index ecd9490..bda4e09 100644 --- a/alioth/src/board/board.rs +++ b/alioth/src/board/board.rs @@ -91,7 +91,7 @@ where pub vm: V, pub memory: Memory, pub vcpus: Arc>, Sender<()>)>>>, - pub arch: ArchBoard, + pub arch: ArchBoard, pub config: BoardConfig, pub state: AtomicU8, pub payload: RwLock>, @@ -239,6 +239,7 @@ where self.memory.add_io_dev(Some(*port), dev.clone())?; } self.add_pci_devs()?; + self.arch_init()?; let init_state = self.load_payload()?; self.init_boot_vcpu(&mut vcpu, &init_state)?; self.create_firmware_data(&init_state)?; diff --git a/alioth/src/board/x86_64.rs b/alioth/src/board/x86_64.rs index f46198f..08e263f 100644 --- a/alioth/src/board/x86_64.rs +++ b/alioth/src/board/x86_64.rs @@ -14,6 +14,7 @@ use std::arch::x86_64::__cpuid; use std::iter::zip; +use std::marker::PhantomData; use std::mem::size_of; use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::Arc; @@ -33,13 +34,17 @@ use crate::loader::InitState; use crate::mem::mapped::ArcMemPages; use crate::mem::{AddrOpt, MemRange, MemRegion, MemRegionEntry, MemRegionType}; -pub struct ArchBoard { +pub struct ArchBoard { cpuids: Vec, sev_ap_eip: AtomicU32, + _phantom: PhantomData, } -impl ArchBoard { - pub fn new(hv: &H, config: &BoardConfig) -> Result { +impl ArchBoard { + pub fn new(hv: &H, _vm: &V, config: &BoardConfig) -> Result + where + H: Hypervisor, + { let mut cpuids = hv.get_supported_cpuids()?; for cpuid in &mut cpuids { if cpuid.func == 0x1 { @@ -66,6 +71,7 @@ impl ArchBoard { Ok(Self { cpuids, sev_ap_eip: AtomicU32::new(0), + _phantom: PhantomData, }) } } @@ -332,6 +338,10 @@ where } Ok(()) } + + pub fn arch_init(&self) -> Result<()> { + Ok(()) + } } const GUID_TABLE_FOOTER_R_OFFSET: usize = 48; diff --git a/alioth/src/vm.rs b/alioth/src/vm.rs index e188970..ddde8b6 100644 --- a/alioth/src/vm.rs +++ b/alioth/src/vm.rs @@ -87,7 +87,7 @@ where let mut vm = hv.create_vm(&vm_config)?; let vm_memory = vm.create_vm_memory()?; let memory = Memory::new(vm_memory); - let arch = ArchBoard::new(&hv, &config)?; + let arch = ArchBoard::new(&hv, &vm, &config)?; let board = Board { vm,