feat(board)!: create and init GIC V2 for aarch64

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
This commit is contained in:
Changyuan Lyu 2024-06-16 23:37:48 -07:00 committed by Lencerf
parent e79171d626
commit 5d037becae
5 changed files with 40 additions and 10 deletions

View file

@ -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

View file

@ -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<V>
where
V: Vm,
{
gic_v2: V::GicV2,
}
impl ArchBoard {
pub fn new<H: Hypervisor>(_hv: &H, _config: &BoardConfig) -> Result<Self> {
unimplemented!()
impl<V: Vm> ArchBoard<V> {
pub fn new<H>(_hv: &H, vm: &V, _config: &BoardConfig) -> Result<Self>
where
H: Hypervisor<Vm = V>,
{
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(())
}
}

View file

@ -91,7 +91,7 @@ where
pub vm: V,
pub memory: Memory,
pub vcpus: Arc<RwLock<Vec<(JoinHandle<Result<()>>, Sender<()>)>>>,
pub arch: ArchBoard,
pub arch: ArchBoard<V>,
pub config: BoardConfig,
pub state: AtomicU8,
pub payload: RwLock<Option<Payload>>,
@ -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)?;

View file

@ -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<V> {
cpuids: Vec<Cpuid>,
sev_ap_eip: AtomicU32,
_phantom: PhantomData<V>,
}
impl ArchBoard {
pub fn new<H: Hypervisor>(hv: &H, config: &BoardConfig) -> Result<Self> {
impl<V: Vm> ArchBoard<V> {
pub fn new<H>(hv: &H, _vm: &V, config: &BoardConfig) -> Result<Self>
where
H: Hypervisor<Vm = V>,
{
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;

View file

@ -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,