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
|
|
|
|
|
|
|
|
#define ACRN_DBG_PTIRQ 6
|
|
|
|
#define ACRN_DBG_IRQ 6
|
|
|
|
|
|
|
|
#ifndef ASSEMBLER
|
|
|
|
|
|
|
|
#define foreach_vcpu(idx, vm, vcpu) \
|
|
|
|
for (idx = 0, 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*/
|
|
|
|
enum {
|
|
|
|
IDX_TSC_DEADLINE,
|
|
|
|
IDX_BIOS_UPDT_TRIG,
|
|
|
|
IDX_BIOS_SIGN_ID,
|
|
|
|
IDX_TSC,
|
|
|
|
|
|
|
|
IDX_MAX_MSR
|
|
|
|
};
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
struct vhm_request;
|
|
|
|
|
2018-05-17 16:47:54 +08:00
|
|
|
int acrn_insert_request_wait(struct vcpu *vcpu, struct vhm_request *req);
|
2018-06-19 10:15:48 +08:00
|
|
|
void get_req_info(char *str, int str_max);
|
2018-05-17 16:47:54 +08:00
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
/*
|
|
|
|
* VCPU related APIs
|
|
|
|
*/
|
2018-05-28 13:29:55 +08:00
|
|
|
#define ACRN_REQUEST_EXCP 0
|
|
|
|
#define ACRN_REQUEST_EVENT 1
|
|
|
|
#define ACRN_REQUEST_EXTINT 2
|
|
|
|
#define ACRN_REQUEST_NMI 3
|
2018-03-07 20:57:14 +08:00
|
|
|
#define ACRN_REQUEST_TMR_UPDATE 4
|
2018-05-23 15:34:54 +08:00
|
|
|
#define ACRN_REQUEST_EPT_FLUSH 5
|
2018-05-28 13:00:04 +08:00
|
|
|
#define ACRN_REQUEST_TRP_FAULT 6
|
2018-05-31 16:39:49 +08:00
|
|
|
#define ACRN_REQUEST_VPID_FLUSH 7 /* flush vpid tlb */
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
#define E820_MAX_ENTRIES 32
|
|
|
|
|
|
|
|
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 11:28:16 +08:00
|
|
|
enum vm_cpu_mode {
|
|
|
|
CPU_MODE_REAL,
|
|
|
|
CPU_MODE_PROTECTED,
|
|
|
|
CPU_MODE_COMPATIBILITY, /* IA-32E mode (CS.L = 0) */
|
|
|
|
CPU_MODE_64BIT, /* IA-32E mode (CS.L = 1) */
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
struct vcpu *vcpu_from_vid(struct vm *vm, int 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[];
|
|
|
|
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
|
|
|
|
|
|
|
uint32_t create_guest_init_gdt(struct vm *vm, uint32_t *limit);
|
2018-03-07 20:57:14 +08:00
|
|
|
#endif /* !ASSEMBLER */
|
|
|
|
|
|
|
|
#endif /* GUEST_H*/
|