2020-05-02 00:30:24 +00:00
|
|
|
// Copyright 2020 The Chromium OS Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-08-03 03:09:41 +00:00
|
|
|
use base::Result;
|
2020-09-29 23:00:24 +00:00
|
|
|
use downcast_rs::impl_downcast;
|
2021-01-08 13:29:03 +00:00
|
|
|
use vm_memory::GuestAddress;
|
2020-09-29 23:00:24 +00:00
|
|
|
|
|
|
|
use crate::{Hypervisor, IrqRoute, IrqSource, IrqSourceChip, Vcpu, Vm};
|
2020-05-02 00:30:24 +00:00
|
|
|
|
2020-11-10 13:18:27 +00:00
|
|
|
/// Represents a version of Power State Coordination Interface (PSCI).
|
|
|
|
pub struct PsciVersion {
|
|
|
|
pub major: u32,
|
|
|
|
pub minor: u32,
|
|
|
|
}
|
|
|
|
|
2020-05-02 00:30:24 +00:00
|
|
|
/// A wrapper for using a VM on aarch64 and getting/setting its state.
|
|
|
|
pub trait VmAArch64: Vm {
|
2020-06-21 04:45:32 +00:00
|
|
|
/// Gets the `Hypervisor` that created this VM.
|
2020-09-29 23:00:24 +00:00
|
|
|
fn get_hypervisor(&self) -> &dyn Hypervisor;
|
2020-06-21 04:45:32 +00:00
|
|
|
|
2021-12-10 17:13:08 +00:00
|
|
|
/// Load pVM firmware for the VM, creating a memslot for it as needed.
|
|
|
|
///
|
|
|
|
/// Only works on protected VMs (i.e. those that support `VmCap::Protected`).
|
|
|
|
fn load_protected_vm_firmware(&mut self, fw_addr: GuestAddress, fw_max_size: u64)
|
|
|
|
-> Result<()>;
|
2021-01-08 13:29:03 +00:00
|
|
|
|
2020-05-02 00:30:24 +00:00
|
|
|
/// Create a Vcpu with the specified Vcpu ID.
|
2020-09-29 23:00:24 +00:00
|
|
|
fn create_vcpu(&self, id: usize) -> Result<Box<dyn VcpuAArch64>>;
|
2020-05-02 00:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A wrapper around creating and using a VCPU on aarch64.
|
|
|
|
pub trait VcpuAArch64: Vcpu {
|
2020-06-16 00:16:18 +00:00
|
|
|
/// Does ARM-specific initialization of this VCPU. Inits the VCPU with the preferred target
|
|
|
|
/// VCPU type and the specified `features`, and resets the value of all registers to defaults.
|
|
|
|
/// All VCPUs should be created before calling this function.
|
|
|
|
fn init(&self, features: &[VcpuFeature]) -> Result<()>;
|
|
|
|
|
|
|
|
/// Initializes the ARM Performance Monitor Unit v3 on this VCPU, with overflow interrupt number
|
|
|
|
/// `irq`.
|
|
|
|
fn init_pmu(&self, irq: u64) -> Result<()>;
|
|
|
|
|
2021-05-02 00:59:06 +00:00
|
|
|
/// Checks if ARM ParaVirtualized Time is supported on this VCPU
|
|
|
|
fn has_pvtime_support(&self) -> bool;
|
|
|
|
|
|
|
|
/// Initializes the ARM ParaVirtualized Time on this VCPU, with base address of the stolen time
|
|
|
|
/// structure as `pvtime_ipa`.
|
|
|
|
fn init_pvtime(&self, pvtime_ipa: u64) -> Result<()>;
|
|
|
|
|
2020-06-16 00:16:18 +00:00
|
|
|
/// Sets the value of a register on this VCPU. `reg_id` is the register ID, as specified in the
|
|
|
|
/// KVM API documentation for KVM_SET_ONE_REG.
|
2020-05-02 00:30:24 +00:00
|
|
|
fn set_one_reg(&self, reg_id: u64, data: u64) -> Result<()>;
|
2020-11-10 13:18:27 +00:00
|
|
|
|
|
|
|
/// Gets the value of a register on this VCPU. `reg_id` is the register ID, as specified in the
|
|
|
|
/// KVM API documentation for KVM_GET_ONE_REG.
|
|
|
|
fn get_one_reg(&self, reg_id: u64) -> Result<u64>;
|
|
|
|
|
|
|
|
/// Gets the current PSCI version.
|
|
|
|
fn get_psci_version(&self) -> Result<PsciVersion>;
|
2020-05-02 00:30:24 +00:00
|
|
|
}
|
2020-06-04 17:33:40 +00:00
|
|
|
|
2020-09-29 23:00:24 +00:00
|
|
|
impl_downcast!(VcpuAArch64);
|
|
|
|
|
2020-06-04 17:33:40 +00:00
|
|
|
// Convenience constructors for IrqRoutes
|
|
|
|
impl IrqRoute {
|
|
|
|
pub fn gic_irq_route(irq_num: u32) -> IrqRoute {
|
|
|
|
IrqRoute {
|
|
|
|
gsi: irq_num,
|
|
|
|
source: IrqSource::Irqchip {
|
|
|
|
chip: IrqSourceChip::Gic,
|
|
|
|
pin: irq_num,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-16 00:16:18 +00:00
|
|
|
|
|
|
|
/// A feature that can be enabled on a VCPU with `VcpuAArch64::init`.
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
pub enum VcpuFeature {
|
|
|
|
/// Emulate PSCI v0.2 (or a future revision backward compatible with v0.2) for the VCPU.
|
|
|
|
PsciV0_2,
|
|
|
|
/// Emulate Performance Monitor Unit v3 for the VCPU.
|
|
|
|
PmuV3,
|
|
|
|
/// Starts the VCPU in a power-off state.
|
|
|
|
PowerOff,
|
|
|
|
}
|