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 <stdbool.h> 8 #include <stdint.h> 9 #include <mm/core_mmu.h> 10 11 #define HYP_CLNT_ID 0 12 13 /** 14 * virt_guest_created() - create new VM partition 15 * @guest_id: VM id provided by hypervisor 16 * 17 * This function is called by hypervisor (via fast SMC) 18 * when hypervisor creates new guest VM, so OP-TEE 19 * can prepare partition for that VM 20 * 21 * Return: OPTEE_SMC_RETURN_* code 22 */ 23 uint32_t 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 * Return: OPTEE_SMC_RETURN_OK 35 */ 36 uint32_t virt_guest_destroyed(uint16_t guest_id); 37 38 /** 39 * virt_set_guest() - set guest VM context for current core 40 * @guest_id: VM id provided by hypervisor 41 * 42 * This function switches memory partitions, so TEE part of 43 * OP-TEE will see memory associated with current guest. 44 * It should be called on entry to OP-TEE 45 * 46 * Return: True if VM partition was found and set 47 */ 48 bool virt_set_guest(uint16_t guest_id); 49 50 /** 51 * virt_unset_guest() - set default memory partition 52 * 53 * This function should be called upon leaving OP-TEE, 54 * to switch to default memory partition, so all TEE-specific 55 * memory will be unmapped. This is safety measure to ensure 56 * that TEE memory is untouched when there is no active VM. 57 */ 58 void virt_unset_guest(void); 59 60 /** 61 * virt_on_stdcall() - std call hook 62 * 63 * This hook is called on every std call, but really is needed 64 * only once: to initialize TEE runtime for current guest VM 65 */ 66 void virt_on_stdcall(void); 67 68 /* 69 * Next function are needed because virtualization subsystem manages 70 * memory in own way. There is no one static memory map, instead 71 * every guest gets own memory map. 72 */ 73 74 /** 75 * virt_init_memory() - initialize memory for virtualization subsystem 76 * @memory_map: current OP-TEE memory map 77 */ 78 void virt_init_memory(struct tee_mmap_region *memory_map); 79 80 /** 81 * virt_get_memory_map() - get current memory map 82 */ 83 struct tee_mmap_region *virt_get_memory_map(void); 84 85 /** 86 * virt_get_ta_ram() - get TA RAM mapping for current VM 87 * @start: beginning of TA RAM returned here 88 * @end: end of TA RAM returned here 89 */ 90 void virt_get_ta_ram(vaddr_t *start, vaddr_t *end); 91 92 #endif /* KERNEL_VIRTUALIZATION_H */ 93