2018-03-07 20:57:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
|
|
|
*
|
2018-05-26 01:49:13 +08:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-03-07 20:57:14 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GUEST_H
|
|
|
|
#define GUEST_H
|
|
|
|
|
|
|
|
/* Defines for VM Launch and Resume */
|
|
|
|
#define VM_RESUME 0
|
|
|
|
#define VM_LAUNCH 1
|
|
|
|
|
2018-07-12 11:47:49 +08:00
|
|
|
#define ACRN_DBG_PTIRQ 6U
|
|
|
|
#define ACRN_DBG_IRQ 6U
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
#ifndef ASSEMBLER
|
|
|
|
|
2018-07-13 17:11:27 +08:00
|
|
|
#include <mmu.h>
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
#define foreach_vcpu(idx, vm, vcpu) \
|
2018-07-10 19:07:46 +08:00
|
|
|
for (idx = 0U, vcpu = vm->hw.vcpu_array[idx]; \
|
2018-06-23 07:58:11 +08:00
|
|
|
(idx < vm->hw.num_vcpus) && (vcpu != NULL); \
|
2018-03-07 20:57:14 +08:00
|
|
|
idx++, vcpu = vm->hw.vcpu_array[idx])
|
|
|
|
|
2018-05-04 10:22:51 +08:00
|
|
|
|
|
|
|
/* the index is matched with emulated msrs array*/
|
2018-07-10 19:07:46 +08:00
|
|
|
#define IDX_TSC_DEADLINE 0U
|
|
|
|
#define IDX_BIOS_UPDT_TRIG (IDX_TSC_DEADLINE + 1U)
|
|
|
|
#define IDX_BIOS_SIGN_ID (IDX_BIOS_UPDT_TRIG + 1U)
|
|
|
|
#define IDX_TSC (IDX_BIOS_SIGN_ID + 1U)
|
|
|
|
#define IDX_PAT (IDX_TSC + 1U)
|
|
|
|
#define IDX_MAX_MSR (IDX_PAT + 1U)
|
2018-05-04 10:22:51 +08:00
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
struct vhm_request;
|
|
|
|
|
2018-06-28 16:27:12 +08:00
|
|
|
int32_t acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req);
|
2018-05-17 16:47:54 +08:00
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
/*
|
|
|
|
* VCPU related APIs
|
|
|
|
*/
|
2018-07-12 11:47:49 +08:00
|
|
|
#define ACRN_REQUEST_EXCP 0U
|
|
|
|
#define ACRN_REQUEST_EVENT 1U
|
|
|
|
#define ACRN_REQUEST_EXTINT 2U
|
|
|
|
#define ACRN_REQUEST_NMI 3U
|
|
|
|
#define ACRN_REQUEST_TMR_UPDATE 4U
|
|
|
|
#define ACRN_REQUEST_EPT_FLUSH 5U
|
|
|
|
#define ACRN_REQUEST_TRP_FAULT 6U
|
|
|
|
#define ACRN_REQUEST_VPID_FLUSH 7U /* flush vpid tlb */
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-07-03 18:34:25 +08:00
|
|
|
#define E820_MAX_ENTRIES 32U
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
struct e820_mem_params {
|
|
|
|
uint64_t mem_bottom;
|
|
|
|
uint64_t mem_top;
|
2018-04-13 09:54:06 +08:00
|
|
|
uint64_t total_mem_size;
|
2018-03-07 20:57:14 +08:00
|
|
|
uint64_t max_ram_blk_base; /* used for the start address of UOS */
|
|
|
|
uint64_t max_ram_blk_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
int prepare_vm0_memmap_and_e820(struct vm *vm);
|
2018-05-03 14:21:07 +08:00
|
|
|
uint64_t e820_alloc_low_memory(uint32_t size);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
/* Definition for a mem map lookup */
|
|
|
|
struct vm_lu_mem_map {
|
|
|
|
struct list_head list; /* EPT mem map lookup list*/
|
|
|
|
void *hpa; /* Host physical start address of the map*/
|
|
|
|
void *gpa; /* Guest physical start address of the map */
|
|
|
|
uint64_t size; /* Size of map */
|
|
|
|
};
|
|
|
|
|
2018-05-15 12:04:49 +08:00
|
|
|
/* Use # of paging level to identify paging mode */
|
2018-05-15 11:28:16 +08:00
|
|
|
enum vm_paging_mode {
|
2018-05-15 12:04:49 +08:00
|
|
|
PAGING_MODE_0_LEVEL = 0, /* Flat */
|
|
|
|
PAGING_MODE_2_LEVEL = 2, /* 32bit paging, 2-level */
|
|
|
|
PAGING_MODE_3_LEVEL = 3, /* PAE paging, 3-level */
|
|
|
|
PAGING_MODE_4_LEVEL = 4, /* 64bit paging, 4-level */
|
|
|
|
PAGING_MODE_NUM,
|
2018-05-15 11:28:16 +08:00
|
|
|
};
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
/*
|
|
|
|
* VM related APIs
|
|
|
|
*/
|
|
|
|
bool is_vm0(struct vm *vm);
|
|
|
|
bool vm_lapic_disabled(struct vm *vm);
|
|
|
|
uint64_t vcpumask2pcpumask(struct vm *vm, uint64_t vdmask);
|
|
|
|
|
2018-05-15 14:47:43 +08:00
|
|
|
int gva2gpa(struct vcpu *vcpu, uint64_t gva, uint64_t *gpa, uint32_t *err_code);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
struct vcpu *get_primary_vcpu(struct vm *vm);
|
2018-07-03 16:41:54 +08:00
|
|
|
struct vcpu *vcpu_from_vid(struct vm *vm, uint16_t vcpu_id);
|
2018-06-20 15:42:52 +08:00
|
|
|
struct vcpu *vcpu_from_pid(struct vm *vm, uint16_t pcpu_id);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-05-15 12:04:49 +08:00
|
|
|
enum vm_paging_mode get_vcpu_paging_mode(struct vcpu *vcpu);
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
void init_e820(void);
|
|
|
|
void obtain_e820_mem_info(void);
|
|
|
|
extern uint32_t e820_entries;
|
|
|
|
extern struct e820_entry e820[E820_MAX_ENTRIES];
|
|
|
|
extern uint32_t boot_regs[];
|
|
|
|
extern struct e820_mem_params e820_mem;
|
|
|
|
|
2018-04-16 19:57:05 +08:00
|
|
|
int rdmsr_vmexit_handler(struct vcpu *vcpu);
|
|
|
|
int wrmsr_vmexit_handler(struct vcpu *vcpu);
|
2018-03-07 20:57:14 +08:00
|
|
|
void init_msr_emulation(struct vcpu *vcpu);
|
|
|
|
|
|
|
|
extern const char vm_exit[];
|
2018-07-13 17:11:27 +08:00
|
|
|
struct run_context;
|
2018-03-07 20:57:14 +08:00
|
|
|
int vmx_vmrun(struct run_context *context, int ops, int ibrs);
|
|
|
|
|
|
|
|
int load_guest(struct vm *vm, struct vcpu *vcpu);
|
|
|
|
int general_sw_loader(struct vm *vm, struct vcpu *vcpu);
|
|
|
|
|
|
|
|
typedef int (*vm_sw_loader_t)(struct vm *, struct vcpu *);
|
|
|
|
extern vm_sw_loader_t vm_sw_loader;
|
|
|
|
|
2018-06-05 20:05:22 +08:00
|
|
|
int copy_from_gpa(struct vm *vm, void *h_ptr, uint64_t gpa, uint32_t size);
|
|
|
|
int copy_to_gpa(struct vm *vm, void *h_ptr, uint64_t gpa, uint32_t size);
|
2018-05-24 08:25:48 +08:00
|
|
|
int copy_from_gva(struct vcpu *vcpu, void *h_ptr, uint64_t gva,
|
|
|
|
uint32_t size, uint32_t *err_code);
|
|
|
|
int copy_to_gva(struct vcpu *vcpu, void *h_ptr, uint64_t gva,
|
|
|
|
uint32_t size, uint32_t *err_code);
|
2018-05-15 15:34:07 +08:00
|
|
|
|
2018-07-10 19:07:46 +08:00
|
|
|
uint64_t create_guest_init_gdt(struct vm *vm, uint32_t *limit);
|
2018-07-02 19:01:08 +08:00
|
|
|
|
|
|
|
#ifdef HV_DEBUG
|
|
|
|
void get_req_info(char *str, int str_max);
|
|
|
|
#endif /* HV_DEBUG */
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
#endif /* !ASSEMBLER */
|
|
|
|
|
|
|
|
#endif /* GUEST_H*/
|