18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2012,2013 - ARM Ltd 48c2ecf20Sopenharmony_ci * Author: Marc Zyngier <marc.zyngier@arm.com> 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef __ARM64_KVM_ARM_H__ 88c2ecf20Sopenharmony_ci#define __ARM64_KVM_ARM_H__ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <asm/esr.h> 118c2ecf20Sopenharmony_ci#include <asm/memory.h> 128c2ecf20Sopenharmony_ci#include <asm/types.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* Hyp Configuration Register (HCR) bits */ 158c2ecf20Sopenharmony_ci#define HCR_ATA (UL(1) << 56) 168c2ecf20Sopenharmony_ci#define HCR_FWB (UL(1) << 46) 178c2ecf20Sopenharmony_ci#define HCR_API (UL(1) << 41) 188c2ecf20Sopenharmony_ci#define HCR_APK (UL(1) << 40) 198c2ecf20Sopenharmony_ci#define HCR_TEA (UL(1) << 37) 208c2ecf20Sopenharmony_ci#define HCR_TERR (UL(1) << 36) 218c2ecf20Sopenharmony_ci#define HCR_TLOR (UL(1) << 35) 228c2ecf20Sopenharmony_ci#define HCR_E2H (UL(1) << 34) 238c2ecf20Sopenharmony_ci#define HCR_ID (UL(1) << 33) 248c2ecf20Sopenharmony_ci#define HCR_CD (UL(1) << 32) 258c2ecf20Sopenharmony_ci#define HCR_RW_SHIFT 31 268c2ecf20Sopenharmony_ci#define HCR_RW (UL(1) << HCR_RW_SHIFT) 278c2ecf20Sopenharmony_ci#define HCR_TRVM (UL(1) << 30) 288c2ecf20Sopenharmony_ci#define HCR_HCD (UL(1) << 29) 298c2ecf20Sopenharmony_ci#define HCR_TDZ (UL(1) << 28) 308c2ecf20Sopenharmony_ci#define HCR_TGE (UL(1) << 27) 318c2ecf20Sopenharmony_ci#define HCR_TVM (UL(1) << 26) 328c2ecf20Sopenharmony_ci#define HCR_TTLB (UL(1) << 25) 338c2ecf20Sopenharmony_ci#define HCR_TPU (UL(1) << 24) 348c2ecf20Sopenharmony_ci#define HCR_TPC (UL(1) << 23) 358c2ecf20Sopenharmony_ci#define HCR_TSW (UL(1) << 22) 368c2ecf20Sopenharmony_ci#define HCR_TAC (UL(1) << 21) 378c2ecf20Sopenharmony_ci#define HCR_TIDCP (UL(1) << 20) 388c2ecf20Sopenharmony_ci#define HCR_TSC (UL(1) << 19) 398c2ecf20Sopenharmony_ci#define HCR_TID3 (UL(1) << 18) 408c2ecf20Sopenharmony_ci#define HCR_TID2 (UL(1) << 17) 418c2ecf20Sopenharmony_ci#define HCR_TID1 (UL(1) << 16) 428c2ecf20Sopenharmony_ci#define HCR_TID0 (UL(1) << 15) 438c2ecf20Sopenharmony_ci#define HCR_TWE (UL(1) << 14) 448c2ecf20Sopenharmony_ci#define HCR_TWI (UL(1) << 13) 458c2ecf20Sopenharmony_ci#define HCR_DC (UL(1) << 12) 468c2ecf20Sopenharmony_ci#define HCR_BSU (3 << 10) 478c2ecf20Sopenharmony_ci#define HCR_BSU_IS (UL(1) << 10) 488c2ecf20Sopenharmony_ci#define HCR_FB (UL(1) << 9) 498c2ecf20Sopenharmony_ci#define HCR_VSE (UL(1) << 8) 508c2ecf20Sopenharmony_ci#define HCR_VI (UL(1) << 7) 518c2ecf20Sopenharmony_ci#define HCR_VF (UL(1) << 6) 528c2ecf20Sopenharmony_ci#define HCR_AMO (UL(1) << 5) 538c2ecf20Sopenharmony_ci#define HCR_IMO (UL(1) << 4) 548c2ecf20Sopenharmony_ci#define HCR_FMO (UL(1) << 3) 558c2ecf20Sopenharmony_ci#define HCR_PTW (UL(1) << 2) 568c2ecf20Sopenharmony_ci#define HCR_SWIO (UL(1) << 1) 578c2ecf20Sopenharmony_ci#define HCR_VM (UL(1) << 0) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* 608c2ecf20Sopenharmony_ci * The bits we set in HCR: 618c2ecf20Sopenharmony_ci * TLOR: Trap LORegion register accesses 628c2ecf20Sopenharmony_ci * RW: 64bit by default, can be overridden for 32bit VMs 638c2ecf20Sopenharmony_ci * TAC: Trap ACTLR 648c2ecf20Sopenharmony_ci * TSC: Trap SMC 658c2ecf20Sopenharmony_ci * TSW: Trap cache operations by set/way 668c2ecf20Sopenharmony_ci * TWE: Trap WFE 678c2ecf20Sopenharmony_ci * TWI: Trap WFI 688c2ecf20Sopenharmony_ci * TIDCP: Trap L2CTLR/L2ECTLR 698c2ecf20Sopenharmony_ci * BSU_IS: Upgrade barriers to the inner shareable domain 708c2ecf20Sopenharmony_ci * FB: Force broadcast of all maintenance operations 718c2ecf20Sopenharmony_ci * AMO: Override CPSR.A and enable signaling with VA 728c2ecf20Sopenharmony_ci * IMO: Override CPSR.I and enable signaling with VI 738c2ecf20Sopenharmony_ci * FMO: Override CPSR.F and enable signaling with VF 748c2ecf20Sopenharmony_ci * SWIO: Turn set/way invalidates into set/way clean+invalidate 758c2ecf20Sopenharmony_ci * PTW: Take a stage2 fault if a stage1 walk steps in device memory 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_ci#define HCR_GUEST_FLAGS (HCR_TSC | HCR_TSW | HCR_TWE | HCR_TWI | HCR_VM | \ 788c2ecf20Sopenharmony_ci HCR_BSU_IS | HCR_FB | HCR_TAC | \ 798c2ecf20Sopenharmony_ci HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \ 808c2ecf20Sopenharmony_ci HCR_FMO | HCR_IMO | HCR_PTW ) 818c2ecf20Sopenharmony_ci#define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF) 828c2ecf20Sopenharmony_ci#define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK | HCR_ATA) 838c2ecf20Sopenharmony_ci#define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* TCR_EL2 Registers bits */ 868c2ecf20Sopenharmony_ci#define TCR_EL2_RES1 ((1U << 31) | (1 << 23)) 878c2ecf20Sopenharmony_ci#define TCR_EL2_TBI (1 << 20) 888c2ecf20Sopenharmony_ci#define TCR_EL2_PS_SHIFT 16 898c2ecf20Sopenharmony_ci#define TCR_EL2_PS_MASK (7 << TCR_EL2_PS_SHIFT) 908c2ecf20Sopenharmony_ci#define TCR_EL2_PS_40B (2 << TCR_EL2_PS_SHIFT) 918c2ecf20Sopenharmony_ci#define TCR_EL2_TG0_MASK TCR_TG0_MASK 928c2ecf20Sopenharmony_ci#define TCR_EL2_SH0_MASK TCR_SH0_MASK 938c2ecf20Sopenharmony_ci#define TCR_EL2_ORGN0_MASK TCR_ORGN0_MASK 948c2ecf20Sopenharmony_ci#define TCR_EL2_IRGN0_MASK TCR_IRGN0_MASK 958c2ecf20Sopenharmony_ci#define TCR_EL2_T0SZ_MASK 0x3f 968c2ecf20Sopenharmony_ci#define TCR_EL2_MASK (TCR_EL2_TG0_MASK | TCR_EL2_SH0_MASK | \ 978c2ecf20Sopenharmony_ci TCR_EL2_ORGN0_MASK | TCR_EL2_IRGN0_MASK | TCR_EL2_T0SZ_MASK) 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* VTCR_EL2 Registers bits */ 1008c2ecf20Sopenharmony_ci#define VTCR_EL2_RES1 (1U << 31) 1018c2ecf20Sopenharmony_ci#define VTCR_EL2_HD (1 << 22) 1028c2ecf20Sopenharmony_ci#define VTCR_EL2_HA (1 << 21) 1038c2ecf20Sopenharmony_ci#define VTCR_EL2_PS_SHIFT TCR_EL2_PS_SHIFT 1048c2ecf20Sopenharmony_ci#define VTCR_EL2_PS_MASK TCR_EL2_PS_MASK 1058c2ecf20Sopenharmony_ci#define VTCR_EL2_TG0_MASK TCR_TG0_MASK 1068c2ecf20Sopenharmony_ci#define VTCR_EL2_TG0_4K TCR_TG0_4K 1078c2ecf20Sopenharmony_ci#define VTCR_EL2_TG0_16K TCR_TG0_16K 1088c2ecf20Sopenharmony_ci#define VTCR_EL2_TG0_64K TCR_TG0_64K 1098c2ecf20Sopenharmony_ci#define VTCR_EL2_SH0_MASK TCR_SH0_MASK 1108c2ecf20Sopenharmony_ci#define VTCR_EL2_SH0_INNER TCR_SH0_INNER 1118c2ecf20Sopenharmony_ci#define VTCR_EL2_ORGN0_MASK TCR_ORGN0_MASK 1128c2ecf20Sopenharmony_ci#define VTCR_EL2_ORGN0_WBWA TCR_ORGN0_WBWA 1138c2ecf20Sopenharmony_ci#define VTCR_EL2_IRGN0_MASK TCR_IRGN0_MASK 1148c2ecf20Sopenharmony_ci#define VTCR_EL2_IRGN0_WBWA TCR_IRGN0_WBWA 1158c2ecf20Sopenharmony_ci#define VTCR_EL2_SL0_SHIFT 6 1168c2ecf20Sopenharmony_ci#define VTCR_EL2_SL0_MASK (3 << VTCR_EL2_SL0_SHIFT) 1178c2ecf20Sopenharmony_ci#define VTCR_EL2_T0SZ_MASK 0x3f 1188c2ecf20Sopenharmony_ci#define VTCR_EL2_VS_SHIFT 19 1198c2ecf20Sopenharmony_ci#define VTCR_EL2_VS_8BIT (0 << VTCR_EL2_VS_SHIFT) 1208c2ecf20Sopenharmony_ci#define VTCR_EL2_VS_16BIT (1 << VTCR_EL2_VS_SHIFT) 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci#define VTCR_EL2_T0SZ(x) TCR_T0SZ(x) 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/* 1258c2ecf20Sopenharmony_ci * We configure the Stage-2 page tables to always restrict the IPA space to be 1268c2ecf20Sopenharmony_ci * 40 bits wide (T0SZ = 24). Systems with a PARange smaller than 40 bits are 1278c2ecf20Sopenharmony_ci * not known to exist and will break with this configuration. 1288c2ecf20Sopenharmony_ci * 1298c2ecf20Sopenharmony_ci * The VTCR_EL2 is configured per VM and is initialised in kvm_arm_setup_stage2(). 1308c2ecf20Sopenharmony_ci * 1318c2ecf20Sopenharmony_ci * Note that when using 4K pages, we concatenate two first level page tables 1328c2ecf20Sopenharmony_ci * together. With 16K pages, we concatenate 16 first level page tables. 1338c2ecf20Sopenharmony_ci * 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define VTCR_EL2_COMMON_BITS (VTCR_EL2_SH0_INNER | VTCR_EL2_ORGN0_WBWA | \ 1378c2ecf20Sopenharmony_ci VTCR_EL2_IRGN0_WBWA | VTCR_EL2_RES1) 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci/* 1408c2ecf20Sopenharmony_ci * VTCR_EL2:SL0 indicates the entry level for Stage2 translation. 1418c2ecf20Sopenharmony_ci * Interestingly, it depends on the page size. 1428c2ecf20Sopenharmony_ci * See D.10.2.121, VTCR_EL2, in ARM DDI 0487C.a 1438c2ecf20Sopenharmony_ci * 1448c2ecf20Sopenharmony_ci * ----------------------------------------- 1458c2ecf20Sopenharmony_ci * | Entry level | 4K | 16K/64K | 1468c2ecf20Sopenharmony_ci * ------------------------------------------ 1478c2ecf20Sopenharmony_ci * | Level: 0 | 2 | - | 1488c2ecf20Sopenharmony_ci * ------------------------------------------ 1498c2ecf20Sopenharmony_ci * | Level: 1 | 1 | 2 | 1508c2ecf20Sopenharmony_ci * ------------------------------------------ 1518c2ecf20Sopenharmony_ci * | Level: 2 | 0 | 1 | 1528c2ecf20Sopenharmony_ci * ------------------------------------------ 1538c2ecf20Sopenharmony_ci * | Level: 3 | - | 0 | 1548c2ecf20Sopenharmony_ci * ------------------------------------------ 1558c2ecf20Sopenharmony_ci * 1568c2ecf20Sopenharmony_ci * The table roughly translates to : 1578c2ecf20Sopenharmony_ci * 1588c2ecf20Sopenharmony_ci * SL0(PAGE_SIZE, Entry_level) = TGRAN_SL0_BASE - Entry_Level 1598c2ecf20Sopenharmony_ci * 1608c2ecf20Sopenharmony_ci * Where TGRAN_SL0_BASE is a magic number depending on the page size: 1618c2ecf20Sopenharmony_ci * TGRAN_SL0_BASE(4K) = 2 1628c2ecf20Sopenharmony_ci * TGRAN_SL0_BASE(16K) = 3 1638c2ecf20Sopenharmony_ci * TGRAN_SL0_BASE(64K) = 3 1648c2ecf20Sopenharmony_ci * provided we take care of ruling out the unsupported cases and 1658c2ecf20Sopenharmony_ci * Entry_Level = 4 - Number_of_levels. 1668c2ecf20Sopenharmony_ci * 1678c2ecf20Sopenharmony_ci */ 1688c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM64_64K_PAGES 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci#define VTCR_EL2_TGRAN VTCR_EL2_TG0_64K 1718c2ecf20Sopenharmony_ci#define VTCR_EL2_TGRAN_SL0_BASE 3UL 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci#elif defined(CONFIG_ARM64_16K_PAGES) 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci#define VTCR_EL2_TGRAN VTCR_EL2_TG0_16K 1768c2ecf20Sopenharmony_ci#define VTCR_EL2_TGRAN_SL0_BASE 3UL 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci#else /* 4K */ 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci#define VTCR_EL2_TGRAN VTCR_EL2_TG0_4K 1818c2ecf20Sopenharmony_ci#define VTCR_EL2_TGRAN_SL0_BASE 2UL 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci#endif 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#define VTCR_EL2_LVLS_TO_SL0(levels) \ 1868c2ecf20Sopenharmony_ci ((VTCR_EL2_TGRAN_SL0_BASE - (4 - (levels))) << VTCR_EL2_SL0_SHIFT) 1878c2ecf20Sopenharmony_ci#define VTCR_EL2_SL0_TO_LVLS(sl0) \ 1888c2ecf20Sopenharmony_ci ((sl0) + 4 - VTCR_EL2_TGRAN_SL0_BASE) 1898c2ecf20Sopenharmony_ci#define VTCR_EL2_LVLS(vtcr) \ 1908c2ecf20Sopenharmony_ci VTCR_EL2_SL0_TO_LVLS(((vtcr) & VTCR_EL2_SL0_MASK) >> VTCR_EL2_SL0_SHIFT) 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci#define VTCR_EL2_FLAGS (VTCR_EL2_COMMON_BITS | VTCR_EL2_TGRAN) 1938c2ecf20Sopenharmony_ci#define VTCR_EL2_IPA(vtcr) (64 - ((vtcr) & VTCR_EL2_T0SZ_MASK)) 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci/* 1968c2ecf20Sopenharmony_ci * ARM VMSAv8-64 defines an algorithm for finding the translation table 1978c2ecf20Sopenharmony_ci * descriptors in section D4.2.8 in ARM DDI 0487C.a. 1988c2ecf20Sopenharmony_ci * 1998c2ecf20Sopenharmony_ci * The algorithm defines the expectations on the translation table 2008c2ecf20Sopenharmony_ci * addresses for each level, based on PAGE_SIZE, entry level 2018c2ecf20Sopenharmony_ci * and the translation table size (T0SZ). The variable "x" in the 2028c2ecf20Sopenharmony_ci * algorithm determines the alignment of a table base address at a given 2038c2ecf20Sopenharmony_ci * level and thus determines the alignment of VTTBR:BADDR for stage2 2048c2ecf20Sopenharmony_ci * page table entry level. 2058c2ecf20Sopenharmony_ci * Since the number of bits resolved at the entry level could vary 2068c2ecf20Sopenharmony_ci * depending on the T0SZ, the value of "x" is defined based on a 2078c2ecf20Sopenharmony_ci * Magic constant for a given PAGE_SIZE and Entry Level. The 2088c2ecf20Sopenharmony_ci * intermediate levels must be always aligned to the PAGE_SIZE (i.e, 2098c2ecf20Sopenharmony_ci * x = PAGE_SHIFT). 2108c2ecf20Sopenharmony_ci * 2118c2ecf20Sopenharmony_ci * The value of "x" for entry level is calculated as : 2128c2ecf20Sopenharmony_ci * x = Magic_N - T0SZ 2138c2ecf20Sopenharmony_ci * 2148c2ecf20Sopenharmony_ci * where Magic_N is an integer depending on the page size and the entry 2158c2ecf20Sopenharmony_ci * level of the page table as below: 2168c2ecf20Sopenharmony_ci * 2178c2ecf20Sopenharmony_ci * -------------------------------------------- 2188c2ecf20Sopenharmony_ci * | Entry level | 4K 16K 64K | 2198c2ecf20Sopenharmony_ci * -------------------------------------------- 2208c2ecf20Sopenharmony_ci * | Level: 0 (4 levels) | 28 | - | - | 2218c2ecf20Sopenharmony_ci * -------------------------------------------- 2228c2ecf20Sopenharmony_ci * | Level: 1 (3 levels) | 37 | 31 | 25 | 2238c2ecf20Sopenharmony_ci * -------------------------------------------- 2248c2ecf20Sopenharmony_ci * | Level: 2 (2 levels) | 46 | 42 | 38 | 2258c2ecf20Sopenharmony_ci * -------------------------------------------- 2268c2ecf20Sopenharmony_ci * | Level: 3 (1 level) | - | 53 | 51 | 2278c2ecf20Sopenharmony_ci * -------------------------------------------- 2288c2ecf20Sopenharmony_ci * 2298c2ecf20Sopenharmony_ci * We have a magic formula for the Magic_N below: 2308c2ecf20Sopenharmony_ci * 2318c2ecf20Sopenharmony_ci * Magic_N(PAGE_SIZE, Level) = 64 - ((PAGE_SHIFT - 3) * Number_of_levels) 2328c2ecf20Sopenharmony_ci * 2338c2ecf20Sopenharmony_ci * where Number_of_levels = (4 - Level). We are only interested in the 2348c2ecf20Sopenharmony_ci * value for Entry_Level for the stage2 page table. 2358c2ecf20Sopenharmony_ci * 2368c2ecf20Sopenharmony_ci * So, given that T0SZ = (64 - IPA_SHIFT), we can compute 'x' as follows: 2378c2ecf20Sopenharmony_ci * 2388c2ecf20Sopenharmony_ci * x = (64 - ((PAGE_SHIFT - 3) * Number_of_levels)) - (64 - IPA_SHIFT) 2398c2ecf20Sopenharmony_ci * = IPA_SHIFT - ((PAGE_SHIFT - 3) * Number of levels) 2408c2ecf20Sopenharmony_ci * 2418c2ecf20Sopenharmony_ci * Here is one way to explain the Magic Formula: 2428c2ecf20Sopenharmony_ci * 2438c2ecf20Sopenharmony_ci * x = log2(Size_of_Entry_Level_Table) 2448c2ecf20Sopenharmony_ci * 2458c2ecf20Sopenharmony_ci * Since, we can resolve (PAGE_SHIFT - 3) bits at each level, and another 2468c2ecf20Sopenharmony_ci * PAGE_SHIFT bits in the PTE, we have : 2478c2ecf20Sopenharmony_ci * 2488c2ecf20Sopenharmony_ci * Bits_Entry_level = IPA_SHIFT - ((PAGE_SHIFT - 3) * (n - 1) + PAGE_SHIFT) 2498c2ecf20Sopenharmony_ci * = IPA_SHIFT - (PAGE_SHIFT - 3) * n - 3 2508c2ecf20Sopenharmony_ci * where n = number of levels, and since each pointer is 8bytes, we have: 2518c2ecf20Sopenharmony_ci * 2528c2ecf20Sopenharmony_ci * x = Bits_Entry_Level + 3 2538c2ecf20Sopenharmony_ci * = IPA_SHIFT - (PAGE_SHIFT - 3) * n 2548c2ecf20Sopenharmony_ci * 2558c2ecf20Sopenharmony_ci * The only constraint here is that, we have to find the number of page table 2568c2ecf20Sopenharmony_ci * levels for a given IPA size (which we do, see stage2_pt_levels()) 2578c2ecf20Sopenharmony_ci */ 2588c2ecf20Sopenharmony_ci#define ARM64_VTTBR_X(ipa, levels) ((ipa) - ((levels) * (PAGE_SHIFT - 3))) 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci#define VTTBR_CNP_BIT (UL(1)) 2618c2ecf20Sopenharmony_ci#define VTTBR_VMID_SHIFT (UL(48)) 2628c2ecf20Sopenharmony_ci#define VTTBR_VMID_MASK(size) (_AT(u64, (1 << size) - 1) << VTTBR_VMID_SHIFT) 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci/* Hyp System Trap Register */ 2658c2ecf20Sopenharmony_ci#define HSTR_EL2_T(x) (1 << x) 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci/* Hyp Coprocessor Trap Register Shifts */ 2688c2ecf20Sopenharmony_ci#define CPTR_EL2_TFP_SHIFT 10 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci/* Hyp Coprocessor Trap Register */ 2718c2ecf20Sopenharmony_ci#define CPTR_EL2_TCPAC (1U << 31) 2728c2ecf20Sopenharmony_ci#define CPTR_EL2_TAM (1 << 30) 2738c2ecf20Sopenharmony_ci#define CPTR_EL2_TTA (1 << 20) 2748c2ecf20Sopenharmony_ci#define CPTR_EL2_TFP (1 << CPTR_EL2_TFP_SHIFT) 2758c2ecf20Sopenharmony_ci#define CPTR_EL2_TZ (1 << 8) 2768c2ecf20Sopenharmony_ci#define CPTR_EL2_RES1 0x000032ff /* known RES1 bits in CPTR_EL2 */ 2778c2ecf20Sopenharmony_ci#define CPTR_EL2_DEFAULT CPTR_EL2_RES1 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci/* Hyp Debug Configuration Register bits */ 2808c2ecf20Sopenharmony_ci#define MDCR_EL2_TTRF (1 << 19) 2818c2ecf20Sopenharmony_ci#define MDCR_EL2_TPMS (1 << 14) 2828c2ecf20Sopenharmony_ci#define MDCR_EL2_E2PB_MASK (UL(0x3)) 2838c2ecf20Sopenharmony_ci#define MDCR_EL2_E2PB_SHIFT (UL(12)) 2848c2ecf20Sopenharmony_ci#define MDCR_EL2_TDRA (1 << 11) 2858c2ecf20Sopenharmony_ci#define MDCR_EL2_TDOSA (1 << 10) 2868c2ecf20Sopenharmony_ci#define MDCR_EL2_TDA (1 << 9) 2878c2ecf20Sopenharmony_ci#define MDCR_EL2_TDE (1 << 8) 2888c2ecf20Sopenharmony_ci#define MDCR_EL2_HPME (1 << 7) 2898c2ecf20Sopenharmony_ci#define MDCR_EL2_TPM (1 << 6) 2908c2ecf20Sopenharmony_ci#define MDCR_EL2_TPMCR (1 << 5) 2918c2ecf20Sopenharmony_ci#define MDCR_EL2_HPMN_MASK (0x1F) 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci/* For compatibility with fault code shared with 32-bit */ 2948c2ecf20Sopenharmony_ci#define FSC_FAULT ESR_ELx_FSC_FAULT 2958c2ecf20Sopenharmony_ci#define FSC_ACCESS ESR_ELx_FSC_ACCESS 2968c2ecf20Sopenharmony_ci#define FSC_PERM ESR_ELx_FSC_PERM 2978c2ecf20Sopenharmony_ci#define FSC_SEA ESR_ELx_FSC_EXTABT 2988c2ecf20Sopenharmony_ci#define FSC_SEA_TTW0 (0x14) 2998c2ecf20Sopenharmony_ci#define FSC_SEA_TTW1 (0x15) 3008c2ecf20Sopenharmony_ci#define FSC_SEA_TTW2 (0x16) 3018c2ecf20Sopenharmony_ci#define FSC_SEA_TTW3 (0x17) 3028c2ecf20Sopenharmony_ci#define FSC_SECC (0x18) 3038c2ecf20Sopenharmony_ci#define FSC_SECC_TTW0 (0x1c) 3048c2ecf20Sopenharmony_ci#define FSC_SECC_TTW1 (0x1d) 3058c2ecf20Sopenharmony_ci#define FSC_SECC_TTW2 (0x1e) 3068c2ecf20Sopenharmony_ci#define FSC_SECC_TTW3 (0x1f) 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci/* Hyp Prefetch Fault Address Register (HPFAR/HDFAR) */ 3098c2ecf20Sopenharmony_ci#define HPFAR_MASK (~UL(0xf)) 3108c2ecf20Sopenharmony_ci/* 3118c2ecf20Sopenharmony_ci * We have 3128c2ecf20Sopenharmony_ci * PAR [PA_Shift - 1 : 12] = PA [PA_Shift - 1 : 12] 3138c2ecf20Sopenharmony_ci * HPFAR [PA_Shift - 9 : 4] = FIPA [PA_Shift - 1 : 12] 3148c2ecf20Sopenharmony_ci */ 3158c2ecf20Sopenharmony_ci#define PAR_TO_HPFAR(par) \ 3168c2ecf20Sopenharmony_ci (((par) & GENMASK_ULL(PHYS_MASK_SHIFT - 1, 12)) >> 8) 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci#define ECN(x) { ESR_ELx_EC_##x, #x } 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci#define kvm_arm_exception_class \ 3218c2ecf20Sopenharmony_ci ECN(UNKNOWN), ECN(WFx), ECN(CP15_32), ECN(CP15_64), ECN(CP14_MR), \ 3228c2ecf20Sopenharmony_ci ECN(CP14_LS), ECN(FP_ASIMD), ECN(CP10_ID), ECN(PAC), ECN(CP14_64), \ 3238c2ecf20Sopenharmony_ci ECN(SVC64), ECN(HVC64), ECN(SMC64), ECN(SYS64), ECN(SVE), \ 3248c2ecf20Sopenharmony_ci ECN(IMP_DEF), ECN(IABT_LOW), ECN(IABT_CUR), \ 3258c2ecf20Sopenharmony_ci ECN(PC_ALIGN), ECN(DABT_LOW), ECN(DABT_CUR), \ 3268c2ecf20Sopenharmony_ci ECN(SP_ALIGN), ECN(FP_EXC32), ECN(FP_EXC64), ECN(SERROR), \ 3278c2ecf20Sopenharmony_ci ECN(BREAKPT_LOW), ECN(BREAKPT_CUR), ECN(SOFTSTP_LOW), \ 3288c2ecf20Sopenharmony_ci ECN(SOFTSTP_CUR), ECN(WATCHPT_LOW), ECN(WATCHPT_CUR), \ 3298c2ecf20Sopenharmony_ci ECN(BKPT32), ECN(VECTOR32), ECN(BRK64) 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci#define CPACR_EL1_FPEN (3 << 20) 3328c2ecf20Sopenharmony_ci#define CPACR_EL1_TTA (1 << 28) 3338c2ecf20Sopenharmony_ci#define CPACR_EL1_DEFAULT (CPACR_EL1_FPEN | CPACR_EL1_ZEN_EL1EN) 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci#endif /* __ARM64_KVM_ARM_H__ */ 336