mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2026-06-07 17:46:15 +00:00
hv:move some files to guest folder
move the following files to guest folder:
renamed: arch/x86/assign.c -> arch/x86/guest/assign.c
renamed: arch/x86/ept.c -> arch/x86/guest/ept.c
renamed: arch/x86/io_emul.c -> arch/x86/guest/io_emul.c
renamed: arch/x86/trusty.c -> arch/x86/guest/trusty.c
renamed: arch/x86/virq.c -> arch/x86/guest/virq.c
renamed: arch/x86/virtual_cr.c -> arch/x86/guest/virtual_cr.c
renamed: arch/x86/vmcs.c -> arch/x86/guest/vmcs.c
renamed: arch/x86/vmexit.c -> arch/x86/guest/vmexit.c
renamed: arch/x86/vmx_asm.S -> arch/x86/guest/vmx_asm.S
renamed: include/arch/x86/assign.h ->
include/arch/x86/guest/assign.h
renamed: include/arch/x86/io_emul.h ->
include/arch/x86/guest/io_emul.h
renamed: include/arch/x86/trusty.h ->
include/arch/x86/guest/trusty.h
renamed: include/arch/x86/virtual_cr.h ->
include/arch/x86/guest/virtual_cr.h
renamed: include/arch/x86/vmcs.h -> include/arch/x86/guest/vmcs.h
renamed: include/arch/x86/vmexit.h ->
include/arch/x86/guest/vmexit.h
After these files movement, all the files in arch/x86 are native
hardware related, and all the files in arch/x86/guest are
virtualiztion related.
Tracked-On: #1842
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
committed by
Eddie Dong
parent
e9bb4267a7
commit
2b2dbe43d7
165
hypervisor/include/arch/x86/guest/assign.h
Normal file
165
hypervisor/include/arch/x86/guest/assign.h
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef ASSIGN_H
|
||||
#define ASSIGN_H
|
||||
|
||||
#include <ptdev.h>
|
||||
|
||||
/**
|
||||
* @file assign.h
|
||||
*
|
||||
* @brief public APIs for Passthrough Interrupt Remapping
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief VT-d
|
||||
*
|
||||
* @defgroup acrn_passthrough ACRN Passthrough
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Acknowledge a virtual interrupt for passthrough device.
|
||||
*
|
||||
* Acknowledge a virtual legacy interrupt for a passthrough device.
|
||||
*
|
||||
* @param[in] vm pointer to acrn_vm
|
||||
* @param[in] virt_pin virtual pin number associated with the passthrough device
|
||||
* @param[in] vpin_src ioapic or pic
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @pre vm != NULL
|
||||
*
|
||||
*/
|
||||
void ptirq_intx_ack(struct acrn_vm *vm, uint32_t virt_pin, uint32_t vpin_src);
|
||||
|
||||
/**
|
||||
* @brief MSI/MSI-x remapping for passthrough device.
|
||||
*
|
||||
* Main entry for PCI device assignment with MSI and MSI-X.
|
||||
* MSI can up to 8 vectors and MSI-X can up to 1024 Vectors.
|
||||
*
|
||||
* @param[in] vm pointer to acrn_vm
|
||||
* @param[in] virt_bdf virtual bdf associated with the passthrough device
|
||||
* @param[in] entry_nr indicate coming vectors, entry_nr = 0 means first vector
|
||||
* @param[in] info structure used for MSI/MSI-x remapping
|
||||
*
|
||||
* @return
|
||||
* - 0: on success
|
||||
* - \p -ENODEV:
|
||||
* - for SOS, the entry already be held by others
|
||||
* - for UOS, no pre-hold mapping found.
|
||||
*
|
||||
* @pre vm != NULL
|
||||
* @pre info != NULL
|
||||
*
|
||||
*/
|
||||
int32_t ptirq_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t entry_nr, struct ptirq_msi_info *info);
|
||||
|
||||
|
||||
/**
|
||||
* @brief INTx remapping for passthrough device.
|
||||
*
|
||||
* Set up the remapping of the given virtual pin for the given vm.
|
||||
* This is the main entry for PCI/Legacy device assignment with INTx, calling from vIOAPIC or vPIC.
|
||||
*
|
||||
* @param[in] vm pointer to acrn_vm
|
||||
* @param[in] virt_pin virtual pin number associated with the passthrough device
|
||||
* @param[in] vpin_src ioapic or pic
|
||||
*
|
||||
* @return
|
||||
* - 0: on success
|
||||
* - \p -ENODEV:
|
||||
* - for SOS, the entry already be held by others
|
||||
* - for UOS, no pre-hold mapping found.
|
||||
*
|
||||
* @pre vm != NULL
|
||||
*
|
||||
*/
|
||||
int32_t ptirq_intx_pin_remap(struct acrn_vm *vm, uint32_t virt_pin, uint32_t vpin_src);
|
||||
|
||||
/**
|
||||
* @brief Add an interrupt remapping entry for INTx as pre-hold mapping.
|
||||
*
|
||||
* Except sos_vm, Device Model should call this function to pre-hold ptdev intx
|
||||
* The entry is identified by phys_pin, one entry vs. one phys_pin.
|
||||
* Currently, one phys_pin can only be held by one pin source (vPIC or vIOAPIC).
|
||||
*
|
||||
* @param[in] vm pointer to acrn_vm
|
||||
* @param[in] virt_pin virtual pin number associated with the passthrough device
|
||||
* @param[in] phys_pin physical pin number associated with the passthrough device
|
||||
* @param[in] pic_pin true for pic, false for ioapic
|
||||
*
|
||||
* @return
|
||||
* - 0: on success
|
||||
* - \p -EINVAL: invalid virt_pin value
|
||||
* - \p -ENODEV: failed to add the remapping entry
|
||||
*
|
||||
* @pre vm != NULL
|
||||
*
|
||||
*/
|
||||
int32_t ptirq_add_intx_remapping(struct acrn_vm *vm, uint32_t virt_pin, uint32_t phys_pin, bool pic_pin);
|
||||
|
||||
/**
|
||||
* @brief Remove an interrupt remapping entry for INTx.
|
||||
*
|
||||
* Deactivate & remove mapping entry of the given virt_pin for given vm.
|
||||
*
|
||||
* @param[in] vm pointer to acrn_vm
|
||||
* @param[in] virt_pin virtual pin number associated with the passthrough device
|
||||
* @param[in] pic_pin true for pic, false for ioapic
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @pre vm != NULL
|
||||
*
|
||||
*/
|
||||
void ptirq_remove_intx_remapping(struct acrn_vm *vm, uint32_t virt_pin, bool pic_pin);
|
||||
|
||||
/**
|
||||
* @brief Add interrupt remapping entry/entries for MSI/MSI-x as pre-hold mapping.
|
||||
*
|
||||
* Add pre-hold mapping of the given number of vectors between the given physical and virtual BDF for the given vm.
|
||||
* Except sos_vm, Device Model should call this function to pre-hold ptdev MSI/MSI-x.
|
||||
* The entry is identified by phys_bdf:msi_idx, one entry vs. one phys_bdf:msi_idx.
|
||||
*
|
||||
* @param[in] vm pointer to acrn_vm
|
||||
* @param[in] virt_bdf virtual bdf associated with the passthrough device
|
||||
* @param[in] phys_bdf physical bdf associated with the passthrough device
|
||||
* @param[in] vector_count number of vectors
|
||||
*
|
||||
* @return
|
||||
* - 0: on success
|
||||
* - \p -ENODEV: failed to add the remapping entry
|
||||
*
|
||||
* @pre vm != NULL
|
||||
*
|
||||
*/
|
||||
int32_t ptirq_add_msix_remapping(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t phys_bdf, uint32_t vector_count);
|
||||
|
||||
/**
|
||||
* @brief Remove interrupt remapping entry/entries for MSI/MSI-x.
|
||||
*
|
||||
* Remove the mapping of given number of vectors of the given virtual BDF for the given vm.
|
||||
*
|
||||
* @param[in] vm pointer to acrn_vm
|
||||
* @param[in] virt_bdf virtual bdf associated with the passthrough device
|
||||
* @param[in] vector_count number of vectors
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
* @pre vm != NULL
|
||||
*
|
||||
*/
|
||||
void ptirq_remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf, uint32_t vector_count);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ASSIGN_H */
|
||||
85
hypervisor/include/arch/x86/guest/io_emul.h
Normal file
85
hypervisor/include/arch/x86/guest/io_emul.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef IO_EMUL_H
|
||||
#define IO_EMUL_H
|
||||
|
||||
|
||||
/* Define emulated port IO index */
|
||||
#define PIC_MASTER_PIO_IDX 0U
|
||||
#define PIC_SLAVE_PIO_IDX (PIC_MASTER_PIO_IDX + 1U)
|
||||
#define PIC_ELC_PIO_IDX (PIC_SLAVE_PIO_IDX + 1U)
|
||||
#define PCI_CFGADDR_PIO_IDX (PIC_ELC_PIO_IDX + 1U)
|
||||
#define PCI_CFGDATA_PIO_IDX (PCI_CFGADDR_PIO_IDX + 1U)
|
||||
#define UART_PIO_IDX (PCI_CFGDATA_PIO_IDX + 1U)
|
||||
#define PM1A_EVT_PIO_IDX (UART_PIO_IDX + 1U)
|
||||
#define PM1A_CNT_PIO_IDX (PM1A_EVT_PIO_IDX + 1U)
|
||||
#define PM1B_EVT_PIO_IDX (PM1A_CNT_PIO_IDX + 1U)
|
||||
#define PM1B_CNT_PIO_IDX (PM1B_EVT_PIO_IDX + 1U)
|
||||
#define RTC_PIO_IDX (PM1B_CNT_PIO_IDX + 1U)
|
||||
#define EMUL_PIO_IDX_MAX (RTC_PIO_IDX + 1U)
|
||||
|
||||
/**
|
||||
* @brief The handler of VM exits on I/O instructions
|
||||
*
|
||||
* @param vcpu The virtual CPU which triggers the VM exit on I/O instruction
|
||||
*/
|
||||
int32_t pio_instr_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
|
||||
/**
|
||||
* @brief EPT violation handling
|
||||
*
|
||||
* @param[in] vcpu the pointer that points to vcpu data structure
|
||||
*
|
||||
* @retval -EINVAL fail to handle the EPT violation
|
||||
* @retval 0 Success to handle the EPT violation
|
||||
*/
|
||||
int32_t ept_violation_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
|
||||
/**
|
||||
* @brief Allow a VM to access a port I/O range
|
||||
*
|
||||
* This API enables direct access from the given \p vm to the port I/O space
|
||||
* starting from \p port_address to \p port_address + \p nbytes - 1.
|
||||
*
|
||||
* @param vm The VM whose port I/O access permissions is to be changed
|
||||
* @param port_address The start address of the port I/O range
|
||||
* @param nbytes The size of the range, in bytes
|
||||
*/
|
||||
void allow_guest_pio_access(struct acrn_vm *vm, uint16_t port_address, uint32_t nbytes);
|
||||
|
||||
/**
|
||||
* @brief Register a port I/O handler
|
||||
*
|
||||
* @param vm The VM to which the port I/O handlers are registered
|
||||
* @param pio_idx The emulated port io index
|
||||
* @param range The emulated port io range
|
||||
* @param io_read_fn_ptr The handler for emulating reads from the given range
|
||||
* @param io_write_fn_ptr The handler for emulating writes to the given range
|
||||
* @pre pio_idx < EMUL_PIO_IDX_MAX
|
||||
*/
|
||||
void register_pio_emulation_handler(struct acrn_vm *vm, uint32_t pio_idx,
|
||||
const struct vm_io_range *range, io_read_fn_t io_read_fn_ptr, io_write_fn_t io_write_fn_ptr);
|
||||
|
||||
/**
|
||||
* @brief Register a MMIO handler
|
||||
*
|
||||
* This API registers a MMIO handler to \p vm before it is launched.
|
||||
*
|
||||
* @param vm The VM to which the MMIO handler is registered
|
||||
* @param read_write The handler for emulating accesses to the given range
|
||||
* @param start The base address of the range \p read_write can emulate
|
||||
* @param end The end of the range (exclusive) \p read_write can emulate
|
||||
* @param handler_private_data Handler-specific data which will be passed to \p read_write when called
|
||||
*
|
||||
* @retval 0 Registration succeeds
|
||||
* @retval -EINVAL \p read_write is NULL, \p end is not larger than \p start or \p vm has been launched
|
||||
*/
|
||||
int32_t register_mmio_emulation_handler(struct acrn_vm *vm,
|
||||
hv_mem_io_handler_t read_write, uint64_t start,
|
||||
uint64_t end, void *handler_private_data);
|
||||
|
||||
#endif /* IO_EMUL_H */
|
||||
136
hypervisor/include/arch/x86/guest/trusty.h
Normal file
136
hypervisor/include/arch/x86/guest/trusty.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef TRUSTY_H_
|
||||
#define TRUSTY_H_
|
||||
|
||||
#define BOOTLOADER_SEED_MAX_ENTRIES 10U
|
||||
#define RPMB_MAX_PARTITION_NUMBER 6U
|
||||
#define MMC_PROD_NAME_WITH_PSN_LEN 15U
|
||||
#define BUP_MKHI_BOOTLOADER_SEED_LEN 64U
|
||||
|
||||
#define TRUSTY_RAM_SIZE (16UL * 1024UL * 1024UL) /* 16 MB for now */
|
||||
|
||||
/* Trusty EPT rebase gpa: 511G */
|
||||
#define TRUSTY_EPT_REBASE_GPA (511UL * 1024UL * 1024UL * 1024UL)
|
||||
|
||||
#define NON_TRUSTY_PDPT_ENTRIES 511U
|
||||
|
||||
/* Structure of seed info */
|
||||
struct seed_info {
|
||||
uint8_t cse_svn;
|
||||
uint8_t bios_svn;
|
||||
uint8_t padding[2];
|
||||
uint8_t seed[BUP_MKHI_BOOTLOADER_SEED_LEN];
|
||||
};
|
||||
|
||||
/* Structure of key info */
|
||||
struct trusty_key_info {
|
||||
uint32_t size_of_this_struct;
|
||||
|
||||
/* version info:
|
||||
0: baseline structure
|
||||
1: add ** new field
|
||||
*/
|
||||
uint32_t version;
|
||||
|
||||
/* platform:
|
||||
0: Dummy (fake secret)
|
||||
1: APL (APL + ABL)
|
||||
2: ICL (ICL + SBL)
|
||||
3: ACRN (APL|ICL + SBL + ACRN)
|
||||
4: Brillo (Android Things)
|
||||
*/
|
||||
uint32_t platform;
|
||||
|
||||
/* flags info:
|
||||
Bit 0: manufacturing state (0:manufacturing done;
|
||||
1:in manufacturing mode)
|
||||
Bit 1: secure boot state (0:disabled; 1: enabled)
|
||||
Bit 2: test seeds (ICL only - 0:production seeds; 1: test seeds)
|
||||
other bits all reserved as 0
|
||||
*/
|
||||
uint32_t flags;
|
||||
|
||||
/* Keep 64-bit align */
|
||||
uint32_t pad1;
|
||||
|
||||
/* Seed list, include useeds(user seeds) and dseed(device seeds) */
|
||||
uint32_t num_seeds;
|
||||
struct seed_info useed_list[BOOTLOADER_SEED_MAX_ENTRIES];
|
||||
struct seed_info dseed_list[BOOTLOADER_SEED_MAX_ENTRIES];
|
||||
|
||||
/* For ICL+ */
|
||||
/* rpmb keys, Currently HMAC-SHA256 is used in RPMB spec
|
||||
* and 256-bit (32byte) is enough. Hence only lower 32 bytes will be
|
||||
* used for now for each entry. But keep higher 32 bytes for future
|
||||
* extension. Note that, RPMB keys are already tied to storage device
|
||||
* serial number.If there are multiple RPMB partitions, then we will
|
||||
* get multiple available RPMB keys. And if rpmb_key[n][64] == 0,
|
||||
* then the n-th RPMB key is unavailable (Either because of no such
|
||||
* RPMB partition, or because OSloader doesn't want to share
|
||||
* the n-th RPMB key with Trusty)
|
||||
*/
|
||||
uint8_t rpmb_key[RPMB_MAX_PARTITION_NUMBER][64];
|
||||
|
||||
/* 256-bit AES encryption key to encrypt/decrypt attestation keybox,
|
||||
this key should be derived from a fixed key which is RPMB seed.
|
||||
RPMB key (HMAC key) and this encryption key (AES key) are both
|
||||
derived from the same RPMB seed.
|
||||
*/
|
||||
uint8_t attkb_enc_key[32];
|
||||
|
||||
/* For APL only */
|
||||
/* RPMB key is derived with dseed together with this serial number,
|
||||
* for ICL +, CSE directly provides the rpmb_key which is already
|
||||
* tied to serial number. Concatenation of emmc product name
|
||||
* with a string representation of PSN
|
||||
*/
|
||||
char serial[MMC_PROD_NAME_WITH_PSN_LEN];
|
||||
char pad2;
|
||||
};
|
||||
|
||||
struct secure_world_memory {
|
||||
/* The original secure world base address allocated by bootloader */
|
||||
uint64_t base_gpa_in_uos;
|
||||
/* The secure world base address of HPA */
|
||||
uint64_t base_hpa;
|
||||
/* Secure world runtime memory size */
|
||||
uint64_t length;
|
||||
};
|
||||
|
||||
struct secure_world_control {
|
||||
/* Flag indicates Secure World's state */
|
||||
struct {
|
||||
/* sworld supporting: 0(unsupported), 1(supported) */
|
||||
uint64_t supported : 1;
|
||||
/* sworld running status: 0(inactive), 1(active) */
|
||||
uint64_t active : 1;
|
||||
/* sworld context saving status: 0(unsaved), 1(saved) */
|
||||
uint64_t ctx_saved : 1;
|
||||
uint64_t reserved : 61;
|
||||
} flag;
|
||||
/* Secure world memory structure */
|
||||
struct secure_world_memory sworld_memory;
|
||||
};
|
||||
|
||||
struct trusty_startup_param {
|
||||
uint32_t size_of_this_struct;
|
||||
uint32_t mem_size;
|
||||
uint64_t tsc_per_ms;
|
||||
uint64_t trusty_mem_base;
|
||||
uint32_t reserved;
|
||||
uint8_t padding[4];
|
||||
};
|
||||
|
||||
void switch_world(struct acrn_vcpu *vcpu, int32_t next_world);
|
||||
bool initialize_trusty(struct acrn_vcpu *vcpu, const struct trusty_boot_param *boot_param);
|
||||
void destroy_secure_world(struct acrn_vm *vm, bool need_clr_mem);
|
||||
void save_sworld_context(struct acrn_vcpu *vcpu);
|
||||
void restore_sworld_context(struct acrn_vcpu *vcpu);
|
||||
void trusty_set_dseed(const void *dseed, uint8_t dseed_num);
|
||||
|
||||
#endif /* TRUSTY_H_ */
|
||||
95
hypervisor/include/arch/x86/guest/virtual_cr.h
Normal file
95
hypervisor/include/arch/x86/guest/virtual_cr.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef VCR_H
|
||||
#define VCR_H
|
||||
|
||||
/**
|
||||
* @file virtual_cr.h
|
||||
*
|
||||
* @brief public APIs for vCR operations
|
||||
*/
|
||||
|
||||
void init_cr0_cr4_host_mask(void);
|
||||
|
||||
/**
|
||||
* @brief vCR from vcpu
|
||||
*
|
||||
* @defgroup vCR ACRN
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief get vcpu CR0 value
|
||||
*
|
||||
* Get & cache target vCPU's CR0 in run_context.
|
||||
*
|
||||
* @param[in] vcpu pointer to vcpu data structure
|
||||
*
|
||||
* @return the value of CR0.
|
||||
*/
|
||||
uint64_t vcpu_get_cr0(struct acrn_vcpu *vcpu);
|
||||
|
||||
/**
|
||||
* @brief set vcpu CR0 value
|
||||
*
|
||||
* Update target vCPU's CR0 in run_context.
|
||||
*
|
||||
* @param[inout] vcpu pointer to vcpu data structure
|
||||
* @param[in] val the value set CR0
|
||||
*/
|
||||
void vcpu_set_cr0(struct acrn_vcpu *vcpu, uint64_t val);
|
||||
|
||||
/**
|
||||
* @brief get vcpu CR2 value
|
||||
*
|
||||
* Get & cache target vCPU's CR2 in run_context.
|
||||
*
|
||||
* @param[in] vcpu pointer to vcpu data structure
|
||||
*
|
||||
* @return the value of CR2.
|
||||
*/
|
||||
uint64_t vcpu_get_cr2(const struct acrn_vcpu *vcpu);
|
||||
|
||||
/**
|
||||
* @brief set vcpu CR2 value
|
||||
*
|
||||
* Update target vCPU's CR2 in run_context.
|
||||
*
|
||||
* @param[inout] vcpu pointer to vcpu data structure
|
||||
* @param[in] val the value set CR2
|
||||
*/
|
||||
void vcpu_set_cr2(struct acrn_vcpu *vcpu, uint64_t val);
|
||||
|
||||
/**
|
||||
* @brief get vcpu CR4 value
|
||||
*
|
||||
* Get & cache target vCPU's CR4 in run_context.
|
||||
*
|
||||
* @param[in] vcpu pointer to vcpu data structure
|
||||
*
|
||||
* @return the value of CR4.
|
||||
*/
|
||||
uint64_t vcpu_get_cr4(struct acrn_vcpu *vcpu);
|
||||
|
||||
/**
|
||||
* @brief set vcpu CR4 value
|
||||
*
|
||||
* Update target vCPU's CR4 in run_context.
|
||||
*
|
||||
* @param[inout] vcpu pointer to vcpu data structure
|
||||
* @param[in] val the value set CR4
|
||||
*/
|
||||
void vcpu_set_cr4(struct acrn_vcpu *vcpu, uint64_t val);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* End of vCR */
|
||||
|
||||
int32_t cr_access_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
|
||||
#endif /* VCR_H */
|
||||
62
hypervisor/include/arch/x86/guest/vmcs.h
Normal file
62
hypervisor/include/arch/x86/guest/vmcs.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef VMCS_H_
|
||||
#define VMCS_H_
|
||||
|
||||
#define VM_SUCCESS 0
|
||||
#define VM_FAIL -1
|
||||
|
||||
#ifndef ASSEMBLER
|
||||
|
||||
#define VMX_VMENTRY_FAIL 0x80000000U
|
||||
|
||||
static inline uint32_t vmx_eoi_exit(uint32_t vector)
|
||||
{
|
||||
return (VMX_EOI_EXIT0_FULL + ((vector >> 6U) * 2U));
|
||||
}
|
||||
|
||||
/* VM exit qulifications for APIC-access
|
||||
* Access type:
|
||||
* 0 = linear access for a data read during instruction execution
|
||||
* 1 = linear access for a data write during instruction execution
|
||||
* 2 = linear access for an instruction fetch
|
||||
* 3 = linear access (read or write) during event delivery
|
||||
* 10 = guest-physical access during event delivery
|
||||
* 15 = guest-physical access for an instructon fetch or during
|
||||
* instruction execution
|
||||
*/
|
||||
static inline uint64_t apic_access_type(uint64_t qual)
|
||||
{
|
||||
return ((qual >> 12U) & 0xFUL);
|
||||
}
|
||||
|
||||
static inline uint64_t apic_access_offset(uint64_t qual)
|
||||
{
|
||||
return (qual & 0xFFFUL);
|
||||
}
|
||||
|
||||
#define RFLAGS_C (1U<<0U)
|
||||
#define RFLAGS_Z (1U<<6U)
|
||||
#define RFLAGS_AC (1U<<18U)
|
||||
|
||||
#define VMX_SUPPORT_UNRESTRICTED_GUEST (1U<<5U)
|
||||
|
||||
void init_vmcs(struct acrn_vcpu *vcpu);
|
||||
|
||||
uint64_t vmx_rdmsr_pat(const struct acrn_vcpu *vcpu);
|
||||
int32_t vmx_wrmsr_pat(struct acrn_vcpu *vcpu, uint64_t value);
|
||||
|
||||
void switch_apicv_mode_x2apic(struct acrn_vcpu *vcpu);
|
||||
|
||||
static inline enum vm_cpu_mode get_vcpu_mode(const struct acrn_vcpu *vcpu)
|
||||
{
|
||||
return vcpu->arch.cpu_mode;
|
||||
}
|
||||
|
||||
#endif /* ASSEMBLER */
|
||||
|
||||
#endif /* VMCS_H_ */
|
||||
86
hypervisor/include/arch/x86/guest/vmexit.h
Normal file
86
hypervisor/include/arch/x86/guest/vmexit.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef VMEXIT_H_
|
||||
#define VMEXIT_H_
|
||||
|
||||
struct vm_exit_dispatch {
|
||||
int32_t (*handler)(struct acrn_vcpu *);
|
||||
uint32_t need_exit_qualification;
|
||||
};
|
||||
|
||||
int32_t vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
int32_t vmcall_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
int32_t cpuid_vmexit_handler(struct acrn_vcpu *vcpu);
|
||||
extern void vm_exit(void);
|
||||
static inline uint64_t
|
||||
vm_exit_qualification_bit_mask(uint64_t exit_qual, uint32_t msb, uint32_t lsb)
|
||||
{
|
||||
return (exit_qual &
|
||||
(((1UL << (msb + 1U)) - 1UL) - ((1UL << lsb) - 1UL)));
|
||||
}
|
||||
|
||||
/* access Control-Register Info using exit qualification field */
|
||||
static inline uint64_t vm_exit_cr_access_cr_num(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 3U, 0U) >> 0U);
|
||||
}
|
||||
|
||||
static inline uint64_t vm_exit_cr_access_type(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 5U, 4U) >> 4U);
|
||||
}
|
||||
|
||||
static inline uint64_t vm_exit_cr_access_lmsw_op(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 6U, 6U) >> 6U);
|
||||
}
|
||||
|
||||
static inline uint64_t vm_exit_cr_access_reg_idx(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 11U, 8U) >> 8U);
|
||||
}
|
||||
|
||||
static inline uint64_t vm_exit_cr_access_lmsw_src_date(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 31U, 16U) >> 16U);
|
||||
}
|
||||
|
||||
/* access IO Access Info using exit qualification field */
|
||||
static inline uint64_t vm_exit_io_instruction_size(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 2U, 0U) >> 0U);
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
vm_exit_io_instruction_access_direction(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 3U, 3U) >> 3U);
|
||||
}
|
||||
|
||||
static inline uint64_t vm_exit_io_instruction_is_string(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 4U, 4U) >> 4U);
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
vm_exit_io_instruction_is_rep_prefixed(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 5U, 5U) >> 5U);
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
vm_exit_io_instruction_is_operand_encoding(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 6U, 6U) >> 6U);
|
||||
}
|
||||
|
||||
static inline uint64_t vm_exit_io_instruction_port_number(uint64_t exit_qual)
|
||||
{
|
||||
return (vm_exit_qualification_bit_mask(exit_qual, 31U, 16U) >> 16U);
|
||||
}
|
||||
|
||||
#endif /* VMEXIT_H_ */
|
||||
Reference in New Issue
Block a user