1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* Copyright (c) 2018, EPAM Systems. All rights reserved. */ 3 4 #ifndef KERNEL_VIRTUALIZATION_H 5 #define KERNEL_VIRTUALIZATION_H 6 7 #include <mm/core_mmu.h> 8 #include <stdbool.h> 9 #include <stdint.h> 10 #include <tee_api_types.h> 11 12 #define HYP_CLNT_ID 0 13 14 #if defined(CFG_VIRTUALIZATION) 15 /** 16 * virt_guest_created() - create new VM partition 17 * @guest_id: VM id provided by hypervisor 18 * 19 * This function is called by hypervisor (via fast SMC) 20 * when hypervisor creates new guest VM, so OP-TEE 21 * can prepare partition for that VM 22 */ 23 TEE_Result virt_guest_created(uint16_t guest_id); 24 25 /** 26 * virt_guest_destroyed() - destroy existing VM partition 27 * @guest_id: VM id provided by hypervisor 28 * 29 * This function is called by hypervisor (via fast SMC) 30 * when hypervisor is ready to destroy guest VM. Hypervisor 31 * must ensure that there are no ongoing calls from this 32 * VM right now. 33 */ 34 TEE_Result virt_guest_destroyed(uint16_t guest_id); 35 36 /** 37 * virt_set_guest() - set guest VM context for current core 38 * @guest_id: VM id provided by hypervisor 39 * 40 * This function switches memory partitions, so TEE part of 41 * OP-TEE will see memory associated with current guest. 42 * It should be called on entry to OP-TEE 43 */ 44 TEE_Result virt_set_guest(uint16_t guest_id); 45 46 /** 47 * virt_unset_guest() - set default memory partition 48 * 49 * This function should be called upon leaving OP-TEE, 50 * to switch to default memory partition, so all TEE-specific 51 * memory will be unmapped. This is safety measure to ensure 52 * that TEE memory is untouched when there is no active VM. 53 */ 54 void virt_unset_guest(void); 55 56 /** 57 * virt_on_stdcall() - std call hook 58 * 59 * This hook is called on every std call, but really is needed 60 * only once: to initialize TEE runtime for current guest VM 61 */ 62 void virt_on_stdcall(void); 63 64 /* 65 * Next function are needed because virtualization subsystem manages 66 * memory in own way. There is no one static memory map, instead 67 * every guest gets own memory map. 68 */ 69 70 /** 71 * virt_init_memory() - initialize memory for virtualization subsystem 72 * @memory_map: current OP-TEE memory map 73 */ 74 void virt_init_memory(struct tee_mmap_region *memory_map); 75 76 /** 77 * virt_get_memory_map() - get current memory map 78 */ 79 struct tee_mmap_region *virt_get_memory_map(void); 80 81 /** 82 * virt_get_ta_ram() - get TA RAM mapping for current VM 83 * @start: beginning of TA RAM returned here 84 * @end: end of TA RAM returned here 85 */ 86 void virt_get_ta_ram(vaddr_t *start, vaddr_t *end); 87 88 #else 89 static inline TEE_Result virt_guest_created(uint16_t guest_id __unused) 90 { return TEE_ERROR_NOT_SUPPORTED; } 91 92 static inline TEE_Result virt_guest_destroyed(uint16_t guest_id __unused) 93 { return TEE_ERROR_NOT_SUPPORTED; } 94 95 static inline TEE_Result virt_set_guest(uint16_t guest_id __unused) 96 { return TEE_ERROR_NOT_SUPPORTED; } 97 98 static inline void virt_unset_guest(void) { } 99 static inline void virt_on_stdcall(void) { } 100 static inline struct tee_mmap_region *virt_get_memory_map(void) { return NULL; } 101 static inline void 102 virt_get_ta_ram(vaddr_t *start __unused, vaddr_t *end __unused) { } 103 static inline void 104 virt_init_memory(struct tee_mmap_region *memory_map __unused) { } 105 #endif /*CFG_VIRTUALIZATION*/ 106 107 #endif /* KERNEL_VIRTUALIZATION_H */ 108