aarch64: Porting fdt related files from Firecracker

When booting VM on AArch64 machines, we need to construct the
flattened device tree before loading kernel. Hence here we add
the implementation of the flattened device tree for AArch64.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
This commit is contained in:
Henry Wang
2020-06-03 13:01:56 +08:00
committed by Rob Bradford
parent 5a18dd36e2
commit 2d13751d7d
3 changed files with 802 additions and 29 deletions

View File

@@ -4,6 +4,8 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//! Implements platform specific functionality.
//! Supported platforms: x86_64, aarch64.
#![allow(
clippy::unreadable_literal,
clippy::redundant_static_lifetimes,
@@ -14,18 +16,21 @@
extern crate byteorder;
extern crate kvm_bindings;
extern crate kvm_ioctls;
extern crate libc;
extern crate vm_memory;
#[cfg(feature = "acpi")]
extern crate acpi_tables;
extern crate arch_gen;
extern crate kvm_ioctls;
extern crate linux_loader;
extern crate vm_memory;
use kvm_ioctls::*;
use std::fmt;
use std::result;
/// Type for returning error code.
#[derive(Debug)]
pub enum Error {
#[cfg(target_arch = "x86_64")]
@@ -55,9 +60,12 @@ pub enum Error {
/// Capability missing
CapabilityMissing(Cap),
}
/// Type for returning public functions outcome.
pub type Result<T> = result::Result<T, Error>;
#[derive(PartialEq)]
/// Type for memory region types.
#[derive(PartialEq, Debug)]
pub enum RegionType {
/// RAM type
Ram,
@@ -75,14 +83,15 @@ pub enum RegionType {
Reserved,
}
/// Module for aarch64 related functionality.
#[cfg(target_arch = "aarch64")]
pub mod aarch64;
#[cfg(target_arch = "aarch64")]
pub use aarch64::{
arch_memory_regions, check_required_kvm_extensions, configure_system, configure_vcpu,
get_host_cpu_phys_bits, get_reserved_mem_addr, layout, layout::CMDLINE_MAX_SIZE,
layout::IRQ_BASE, layout::IRQ_MAX, EntryPoint,
fdt::DeviceInfoForFDT, get_host_cpu_phys_bits, get_kernel_start, layout,
layout::CMDLINE_MAX_SIZE, layout::IRQ_BASE, layout::IRQ_MAX, EntryPoint,
};
#[cfg(target_arch = "x86_64")]
@@ -110,3 +119,54 @@ pub struct InitramfsConfig {
/// Size of initramfs in guest memory
pub size: usize,
}
/// Types of devices that can get attached to this platform.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Copy)]
pub enum DeviceType {
/// Device Type: Virtio.
Virtio(u32),
/// Device Type: Serial.
#[cfg(target_arch = "aarch64")]
Serial,
/// Device Type: RTC.
#[cfg(target_arch = "aarch64")]
RTC,
}
/// Type for passing information about the initrd in the guest memory.
pub struct InitrdConfig {
/// Load address of initrd in guest memory
pub address: vm_memory::GuestAddress,
/// Size of initrd in guest memory
pub size: usize,
}
/// Default (smallest) memory page size for the supported architectures.
pub const PAGE_SIZE: usize = 4096;
impl fmt::Display for DeviceType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
/// Structure to describe MMIO device information
#[derive(Clone, Debug)]
#[cfg(target_arch = "aarch64")]
pub struct MMIODeviceInfo {
pub addr: u64,
pub irq: u32,
}
#[cfg(target_arch = "aarch64")]
impl DeviceInfoForFDT for MMIODeviceInfo {
fn addr(&self) -> u64 {
self.addr
}
fn irq(&self) -> u32 {
self.irq
}
fn length(&self) -> u64 {
4096 as u64
}
}