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 MPIDR_EL1 3, 0, 0, 0, 5
21 #define TTBR0_EL1 3, 0, 2, 0, 0
22 #define SCTLR_EL1 3, 0, 1, 0, 0
23 #define VBAR_EL1 3, 0, 12, 0, 0
25 #define ID_AA64DFR0_EL1 3, 0, 0, 5, 0
30 * DEVICE_nGnRnE 0 0000:0000
31 * DEVICE_nGnRE 1 0000:0100
32 * DEVICE_GRE 2 0000:1100
33 * NORMAL_NC 3 0100:0100
35 * NORMAL_WT 5 1011:1011
37 #define DEFAULT_MAIR_EL1 ((0x00ul << (0 * 8)) | \
38 (0x04ul << (1 * 8)) | \
39 (0x0cul << (2 * 8)) | \
40 (0x44ul << (3 * 8)) | \
41 (0xfful << (4 * 8)) | \
44 #define MPIDR_HWID_BITMASK (0xff00fffffful)
46 static inline void get_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint64_t *addr)
48 struct kvm_one_reg reg;
50 reg.addr = (uint64_t)addr;
51 vcpu_ioctl(vm, vcpuid, KVM_GET_ONE_REG, ®);
54 static inline void set_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint64_t val)
56 struct kvm_one_reg reg;
58 reg.addr = (uint64_t)&val;
59 vcpu_ioctl(vm, vcpuid, KVM_SET_ONE_REG, ®);
62 void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *init);
63 void aarch64_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid,
64 struct kvm_vcpu_init *init, void *guest_code);
76 VECTOR_SYNC_CURRENT_SP0,
77 VECTOR_IRQ_CURRENT_SP0,
78 VECTOR_FIQ_CURRENT_SP0,
79 VECTOR_ERROR_CURRENT_SP0,
89 VECTOR_ERROR_LOWER_64,
94 VECTOR_ERROR_LOWER_32,
97 #define VECTOR_IS_SYNC(v) ((v) == VECTOR_SYNC_CURRENT_SP0 || \
98 (v) == VECTOR_SYNC_CURRENT || \
99 (v) == VECTOR_SYNC_LOWER_64 || \
100 (v) == VECTOR_SYNC_LOWER_32)
102 #define ESR_EC_NUM 64
103 #define ESR_EC_SHIFT 26
104 #define ESR_EC_MASK (ESR_EC_NUM - 1)
106 #define ESR_EC_SVC64 0x15
107 #define ESR_EC_HW_BP_CURRENT 0x31
108 #define ESR_EC_SSTEP_CURRENT 0x33
109 #define ESR_EC_WP_CURRENT 0x35
110 #define ESR_EC_BRK_INS 0x3c
112 void vm_init_descriptor_tables(struct kvm_vm *vm);
113 void vcpu_init_descriptor_tables(struct kvm_vm *vm, uint32_t vcpuid);
115 typedef void(*handler_fn)(struct ex_regs *);
116 void vm_install_exception_handler(struct kvm_vm *vm,
117 int vector, handler_fn handler);
118 void vm_install_sync_handler(struct kvm_vm *vm,
119 int vector, int ec, handler_fn handler);
121 #define write_sysreg(reg, val) \
123 u64 __val = (u64)(val); \
124 asm volatile("msr " __stringify(reg) ", %x0" : : "rZ" (__val)); \
127 #define read_sysreg(reg) \
129 asm volatile("mrs %0, "__stringify(reg) : "=r"(val) : : "memory");\
133 #define isb() asm volatile("isb" : : : "memory")
135 #endif /* SELFTEST_KVM_PROCESSOR_H */