1 /* 2 * Copyright (C) 2018-2022 Intel Corporation. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 /** 7 * @file guest_memory.h 8 * 9 * @brief ACRN Memory Management 10 */ 11 #ifndef GUEST_H 12 #define GUEST_H 13 14 #ifndef ASSEMBLER 15 16 #include <types.h> 17 18 struct acrn_vcpu; 19 struct acrn_vm; 20 /* Use # of paging level to identify paging mode */ 21 enum vm_paging_mode { 22 PAGING_MODE_0_LEVEL = 0U, /* Flat */ 23 PAGING_MODE_2_LEVEL = 2U, /* 32bit paging, 2-level */ 24 PAGING_MODE_3_LEVEL = 3U, /* PAE paging, 3-level */ 25 PAGING_MODE_4_LEVEL = 4U, /* 64bit paging, 4-level */ 26 PAGING_MODE_NUM, 27 }; 28 29 /* 30 * VM related APIs 31 */ 32 int32_t gva2gpa(struct acrn_vcpu *vcpu, uint64_t gva, uint64_t *gpa, uint32_t *err_code); 33 34 enum vm_paging_mode get_vcpu_paging_mode(struct acrn_vcpu *vcpu); 35 36 /* gpa --> hpa -->hva */ 37 void *gpa2hva(struct acrn_vm *vm, uint64_t x); 38 39 /** 40 * @brief Data transfering between hypervisor and VM 41 * 42 * @defgroup acrn_mem ACRN Memory Management 43 * @{ 44 */ 45 /** 46 * @brief Copy data from VM GPA space to HV address space 47 * 48 * @param[in] vm The pointer that points to VM data structure 49 * @param[in] h_ptr The pointer that points the start HV address 50 * of HV memory region which data is stored in 51 * @param[out] gpa The start GPA address of GPA memory region which data 52 * will be copied into 53 * @param[in] size The size (bytes) of GPA memory region which data is 54 * stored in 55 * 56 * @pre Caller(Guest) should make sure gpa is continuous. 57 * - gpa from hypercall input which from kernel stack is gpa continuous, not 58 * support kernel stack from vmap 59 * - some other gpa from hypercall parameters, HSM should make sure it's 60 * continuous 61 * @pre Pointer vm is non-NULL 62 */ 63 int32_t copy_from_gpa(struct acrn_vm *vm, void *h_ptr, uint64_t gpa, uint32_t size); 64 /** 65 * @brief Copy data from HV address space to VM GPA space 66 * 67 * @param[in] vm The pointer that points to VM data structure 68 * @param[in] h_ptr The pointer that points the start HV address 69 * of HV memory region which data is stored in 70 * @param[out] gpa The start GPA address of GPA memory region which data 71 * will be copied into 72 * @param[in] size The size (bytes) of GPA memory region which data will be 73 * copied into 74 * 75 * @pre Caller(Guest) should make sure gpa is continuous. 76 * - gpa from hypercall input which from kernel stack is gpa continuous, not 77 * support kernel stack from vmap 78 * - some other gpa from hypercall parameters, HSM should make sure it's 79 * continuous 80 * @pre Pointer vm is non-NULL 81 */ 82 int32_t copy_to_gpa(struct acrn_vm *vm, void *h_ptr, uint64_t gpa, uint32_t size); 83 /** 84 * @brief Copy data from VM GVA space to HV address space 85 * 86 * @param[in] vcpu The pointer that points to vcpu data structure 87 * @param[out] h_ptr The pointer that returns the start HV address 88 * of HV memory region which data will be copied to 89 * @param[in] gva The start GVA address of GVA memory region which data 90 * is stored in 91 * @param[in] size The size (bytes) of GVA memory region which data is 92 * stored in 93 * @param[out] err_code The page fault flags 94 * @param[out] fault_addr The GVA address that causes a page fault 95 */ 96 int32_t copy_from_gva(struct acrn_vcpu *vcpu, void *h_ptr, uint64_t gva, 97 uint32_t size, uint32_t *err_code, uint64_t *fault_addr); 98 /** 99 * @brief Copy data to VM GVA space from HV address space 100 * 101 * @param[in] vcpu The pointer that points to vcpu data structure 102 * @param[in] h_ptr The pointer that returns the start HV address 103 * of HV memory region which data will be copied to 104 * @param[out] gva The start GVA address of GVA memory region which data 105 * is stored in 106 * @param[in] size The size (bytes) of GVA memory region which data is 107 * stored in 108 * @param[out] err_code The page fault flags 109 * @param[out] fault_addr The GVA address that causes a page fault 110 */ 111 int32_t copy_to_gva(struct acrn_vcpu *vcpu, void *h_ptr, uint64_t gva, 112 uint32_t size, uint32_t *err_code, uint64_t *fault_addr); 113 /** 114 * @} 115 */ 116 #endif /* !ASSEMBLER */ 117 118 #endif /* GUEST_H*/ 119