/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (C) 2017 Alexandru Elisei <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#ifndef _VMM_HYP_H_28#define _VMM_HYP_H_2930/*31* The translation tables for the hypervisor mode will hold mappings for kernel32* virtual addresses and an identity mapping (VA == PA) necessary when33* enabling/disabling the MMU.34*35* When in EL2 exception level the translation table base register is TTBR0_EL236* and the virtual addresses generated by the CPU must be at the bottom of the37* memory, with the first 16 bits all set to zero:38*39* 0x0000ffffffffffff End hyp address space40* 0x0000000000000000 Start of hyp address space41*42* To run code in hyp mode we need to convert kernel virtual addresses to43* addreses that fit into this address space.44*45* The kernel virtual address range is:46*47* 0xffff007fffffffff End of KVA48* 0xffff000000000000 Kernel base address & start of KVA49*50* (see /sys/arm64/include/vmparam.h).51*52* We could convert the kernel virtual addresses to valid EL2 addresses by53* setting the first 16 bits to zero and thus mapping the kernel addresses in54* the bottom half of the EL2 address space, but then they might clash with the55* identity mapping addresses. Instead we map the kernel addresses in the upper56* half of the EL2 address space.57*58* The hypervisor address space will look like this:59*60* 0x0000807fffffffff End of KVA mapping61* 0x0000800000000000 Start of KVA mapping62*63* 0x00007fffffffffff End of identity mapping64* 0x0000000000000000 Start of identity mapping65*66* With the scheme we have 47 bits at our disposable for the identity map and67* another 47 bits for the kernel virtual addresses. For a maximum physical68* memory size of 128TB we are guaranteed to not have any clashes between69* addresses.70*/71#define HYP_VM_MIN_ADDRESS 0x000000000000000072#define HYP_VM_MAX_ADDRESS 0x00010000000000007374/*75* When the vmm code is installed the following handles can be used by76* the host to call into EL2.77*/78#define HYP_CLEANUP 0x0000000179#define HYP_ENTER_GUEST 0x0000000280#define HYP_READ_REGISTER 0x0000000381#define HYP_REG_ICH_VTR 0x182#define HYP_CLEAN_S2_TLBI 0x0000000483#define HYP_DC_CIVAC 0x0000000584#define HYP_EL2_TLBI 0x0000000685#define HYP_EL2_TLBI_ALL 0x186#define HYP_EL2_TLBI_VA 0x287#define HYP_S2_TLBI_RANGE 0x0000001088#define HYP_S2_TLBI_ALL 0x000000118990/*91* When taking asynchronous exceptions, or interrupts, with the exception of the92* SError interrupt, the exception syndrome register is not updated with the93* exception code. We need to differentiate between the different exception94* types taken to EL2.95*/96#define EXCP_TYPE_EL1_SYNC 097#define EXCP_TYPE_EL1_IRQ 198#define EXCP_TYPE_EL1_FIQ 299#define EXCP_TYPE_EL1_ERROR 3100101#define EXCP_TYPE_EL2_SYNC 4102#define EXCP_TYPE_EL2_IRQ 5103#define EXCP_TYPE_EL2_FIQ 6104#define EXCP_TYPE_EL2_ERROR 7105106#define EXCP_TYPE_MAINT_IRQ 8107/* Used internally in vmm_hyp.c */108#define EXCP_TYPE_REENTER 9109110#define HYP_GET_VECTOR_TABLE -1111112#endif /* !_VMM_HYP_H_ */113114115