xref: /optee_os/core/include/kernel/virtualization.h (revision bddb2f8987cb257ec67290f815f9f0ecbd5d3424)
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 /**
15  * virt_guest_created() - create new VM partition
16  * @guest_id: VM id provided by hypervisor
17  *
18  * This function is called by hypervisor (via fast SMC)
19  * when hypervisor creates new guest VM, so OP-TEE
20  * can prepare partition for that VM
21  */
22 TEE_Result virt_guest_created(uint16_t guest_id);
23 
24 /**
25  * virt_guest_destroyed() - destroy existing VM partition
26  * @guest_id: VM id provided by hypervisor
27  *
28  * This function is called by hypervisor (via fast SMC)
29  * when hypervisor is ready to destroy guest VM. Hypervisor
30  * must ensure that there are no ongoing calls from this
31  * VM right now.
32  */
33 TEE_Result virt_guest_destroyed(uint16_t guest_id);
34 
35 /**
36  * virt_set_guest() - set guest VM context for current core
37  * @guest_id: VM id provided by hypervisor
38  *
39  * This function switches memory partitions, so TEE part of
40  * OP-TEE will see memory associated with current guest.
41  * It should be called on entry to OP-TEE
42  */
43 TEE_Result virt_set_guest(uint16_t guest_id);
44 
45 /**
46  * virt_unset_guest() - set default memory partition
47  *
48  * This function should be called upon leaving OP-TEE,
49  * to switch to default memory partition, so all TEE-specific
50  * memory will be unmapped. This is safety measure to ensure
51  * that TEE memory is untouched when there is no active VM.
52  */
53 void virt_unset_guest(void);
54 
55 /**
56  * virt_on_stdcall() - std call hook
57  *
58  * This hook is called on every std call, but really is needed
59  * only once: to initialize TEE runtime for current guest VM
60  */
61 void virt_on_stdcall(void);
62 
63 /*
64  * Next function are needed because virtualization subsystem manages
65  * memory in own way. There is no one static memory map, instead
66  * every guest gets own memory map.
67  */
68 
69 /**
70  * virt_init_memory() - initialize memory for virtualization subsystem
71  * @memory_map: current OP-TEE memory map
72  */
73 void virt_init_memory(struct tee_mmap_region *memory_map);
74 
75 /**
76  * virt_get_memory_map() - get current memory map
77  */
78 struct tee_mmap_region *virt_get_memory_map(void);
79 
80 /**
81  * virt_get_ta_ram() - get TA RAM mapping for current VM
82  * @start: beginning of TA RAM returned here
83  * @end: end of TA RAM returned here
84  */
85 void virt_get_ta_ram(vaddr_t *start, vaddr_t *end);
86 
87 #endif	/* KERNEL_VIRTUALIZATION_H */
88