1 /* SPDX-License-Identifier: GPL-2.0 */
3 * AArch64 processor specific defines
5 * Copyright (C) 2018, Red Hat, Inc.
7 #ifndef SELFTEST_KVM_PROCESSOR_H
8 #define SELFTEST_KVM_PROCESSOR_H
11 #include <linux/stringify.h>
14 #define ARM64_CORE_REG(x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
15 KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(x))
17 #define CPACR_EL1 3, 0, 1, 0, 2
18 #define TCR_EL1 3, 0, 2, 0, 2
19 #define MAIR_EL1 3, 0, 10, 2, 0
20 #define TTBR0_EL1 3, 0, 2, 0, 0
21 #define SCTLR_EL1 3, 0, 1, 0, 0
22 #define VBAR_EL1 3, 0, 12, 0, 0
24 #define ID_AA64DFR0_EL1 3, 0, 0, 5, 0
29 * DEVICE_nGnRnE 0 0000:0000
30 * DEVICE_nGnRE 1 0000:0100
31 * DEVICE_GRE 2 0000:1100
32 * NORMAL_NC 3 0100:0100
34 * NORMAL_WT 5 1011:1011
36 #define DEFAULT_MAIR_EL1 ((0x00ul << (0 * 8)) | \
37 (0x04ul << (1 * 8)) | \
38 (0x0cul << (2 * 8)) | \
39 (0x44ul << (3 * 8)) | \
40 (0xfful << (4 * 8)) | \
43 static inline void get_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint64_t *addr)
45 struct kvm_one_reg reg;
47 reg.addr = (uint64_t)addr;
48 vcpu_ioctl(vm, vcpuid, KVM_GET_ONE_REG, ®);
51 static inline void set_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint64_t val)
53 struct kvm_one_reg reg;
55 reg.addr = (uint64_t)&val;
56 vcpu_ioctl(vm, vcpuid, KVM_SET_ONE_REG, ®);
59 void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *init);
60 void aarch64_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid,
61 struct kvm_vcpu_init *init, void *guest_code);
73 VECTOR_SYNC_CURRENT_SP0,
74 VECTOR_IRQ_CURRENT_SP0,
75 VECTOR_FIQ_CURRENT_SP0,
76 VECTOR_ERROR_CURRENT_SP0,
86 VECTOR_ERROR_LOWER_64,
91 VECTOR_ERROR_LOWER_32,
94 #define VECTOR_IS_SYNC(v) ((v) == VECTOR_SYNC_CURRENT_SP0 || \
95 (v) == VECTOR_SYNC_CURRENT || \
96 (v) == VECTOR_SYNC_LOWER_64 || \
97 (v) == VECTOR_SYNC_LOWER_32)
100 #define ESR_EC_SHIFT 26
101 #define ESR_EC_MASK (ESR_EC_NUM - 1)
103 #define ESR_EC_SVC64 0x15
104 #define ESR_EC_HW_BP_CURRENT 0x31
105 #define ESR_EC_SSTEP_CURRENT 0x33
106 #define ESR_EC_WP_CURRENT 0x35
107 #define ESR_EC_BRK_INS 0x3c
109 void vm_init_descriptor_tables(struct kvm_vm *vm);
110 void vcpu_init_descriptor_tables(struct kvm_vm *vm, uint32_t vcpuid);
112 typedef void(*handler_fn)(struct ex_regs *);
113 void vm_install_exception_handler(struct kvm_vm *vm,
114 int vector, handler_fn handler);
115 void vm_install_sync_handler(struct kvm_vm *vm,
116 int vector, int ec, handler_fn handler);
118 #define write_sysreg(reg, val) \
120 u64 __val = (u64)(val); \
121 asm volatile("msr " __stringify(reg) ", %x0" : : "rZ" (__val)); \
124 #define read_sysreg(reg) \
126 asm volatile("mrs %0, "__stringify(reg) : "=r"(val) : : "memory");\
130 #define isb() asm volatile("isb" : : : "memory")
132 #endif /* SELFTEST_KVM_PROCESSOR_H */