2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (C) 2017 Alexandru Elisei <alexandru.elisei@gmail.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * The translation tables for the hypervisor mode will hold mappings for kernel
33 * virtual addresses and an identity mapping (VA == PA) necessary when
34 * enabling/disabling the MMU.
36 * When in EL2 exception level the translation table base register is TTBR0_EL2
37 * and the virtual addresses generated by the CPU must be at the bottom of the
38 * memory, with the first 16 bits all set to zero:
40 * 0x0000ffffffffffff End hyp address space
41 * 0x0000000000000000 Start of hyp address space
43 * To run code in hyp mode we need to convert kernel virtual addresses to
44 * addreses that fit into this address space.
46 * The kernel virtual address range is:
48 * 0xffff007fffffffff End of KVA
49 * 0xffff000000000000 Kernel base address & start of KVA
51 * (see /sys/arm64/include/vmparam.h).
53 * We could convert the kernel virtual addresses to valid EL2 addresses by
54 * setting the first 16 bits to zero and thus mapping the kernel addresses in
55 * the bottom half of the EL2 address space, but then they might clash with the
56 * identity mapping addresses. Instead we map the kernel addresses in the upper
57 * half of the EL2 address space.
59 * The hypervisor address space will look like this:
61 * 0x0000807fffffffff End of KVA mapping
62 * 0x0000800000000000 Start of KVA mapping
64 * 0x00007fffffffffff End of identity mapping
65 * 0x0000000000000000 Start of identity mapping
67 * With the scheme we have 47 bits at our disposable for the identity map and
68 * another 47 bits for the kernel virtual addresses. For a maximum physical
69 * memory size of 128TB we are guaranteed to not have any clashes between
72 #define HYP_VM_MIN_ADDRESS 0x0000000000000000
73 #define HYP_VM_MAX_ADDRESS 0x0001000000000000
76 * When the vmm code is installed the following handles can be used by
77 * the host to call into EL2.
79 #define HYP_CLEANUP 0x00000001
80 #define HYP_ENTER_GUEST 0x00000002
81 #define HYP_READ_REGISTER 0x00000003
82 #define HYP_REG_ICH_VTR 0x1
83 #define HYP_REG_CNTHCTL 0x2
84 #define HYP_CLEAN_S2_TLBI 0x00000004
85 #define HYP_DC_CIVAC 0x00000005
86 #define HYP_EL2_TLBI 0x00000006
87 #define HYP_EL2_TLBI_ALL 0x1
88 #define HYP_EL2_TLBI_VA 0x2
89 #define HYP_S2_TLBI_RANGE 0x00000010
90 #define HYP_S2_TLBI_ALL 0x00000011
93 * When taking asynchronous exceptions, or interrupts, with the exception of the
94 * SError interrupt, the exception syndrome register is not updated with the
95 * exception code. We need to differentiate between the different exception
98 #define EXCP_TYPE_EL1_SYNC 0
99 #define EXCP_TYPE_EL1_IRQ 1
100 #define EXCP_TYPE_EL1_FIQ 2
101 #define EXCP_TYPE_EL1_ERROR 3
103 #define EXCP_TYPE_EL2_SYNC 4
104 #define EXCP_TYPE_EL2_IRQ 5
105 #define EXCP_TYPE_EL2_FIQ 6
106 #define EXCP_TYPE_EL2_ERROR 7
108 #define EXCP_TYPE_MAINT_IRQ 8
109 /* Used internally in vmm_hyp.c */
110 #define EXCP_TYPE_REENTER 9
112 #define HYP_GET_VECTOR_TABLE -1
114 #endif /* !_VMM_HYP_H_ */