xref: /linux/tools/testing/selftests/kvm/include/aarch64/processor.h (revision 95298d63c67673c654c08952672d016212b26054)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * AArch64 processor specific defines
4  *
5  * Copyright (C) 2018, Red Hat, Inc.
6  */
7 #ifndef SELFTEST_KVM_PROCESSOR_H
8 #define SELFTEST_KVM_PROCESSOR_H
9 
10 #include "kvm_util.h"
11 
12 
13 #define ARM64_CORE_REG(x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
14 			   KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(x))
15 
16 #define CPACR_EL1	3, 0,  1, 0, 2
17 #define TCR_EL1		3, 0,  2, 0, 2
18 #define MAIR_EL1	3, 0, 10, 2, 0
19 #define TTBR0_EL1	3, 0,  2, 0, 0
20 #define SCTLR_EL1	3, 0,  1, 0, 0
21 
22 /*
23  * Default MAIR
24  *                  index   attribute
25  * DEVICE_nGnRnE      0     0000:0000
26  * DEVICE_nGnRE       1     0000:0100
27  * DEVICE_GRE         2     0000:1100
28  * NORMAL_NC          3     0100:0100
29  * NORMAL             4     1111:1111
30  * NORMAL_WT          5     1011:1011
31  */
32 #define DEFAULT_MAIR_EL1 ((0x00ul << (0 * 8)) | \
33 			  (0x04ul << (1 * 8)) | \
34 			  (0x0cul << (2 * 8)) | \
35 			  (0x44ul << (3 * 8)) | \
36 			  (0xfful << (4 * 8)) | \
37 			  (0xbbul << (5 * 8)))
38 
39 static inline void get_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint64_t *addr)
40 {
41 	struct kvm_one_reg reg;
42 	reg.id = id;
43 	reg.addr = (uint64_t)addr;
44 	vcpu_ioctl(vm, vcpuid, KVM_GET_ONE_REG, &reg);
45 }
46 
47 static inline void set_reg(struct kvm_vm *vm, uint32_t vcpuid, uint64_t id, uint64_t val)
48 {
49 	struct kvm_one_reg reg;
50 	reg.id = id;
51 	reg.addr = (uint64_t)&val;
52 	vcpu_ioctl(vm, vcpuid, KVM_SET_ONE_REG, &reg);
53 }
54 
55 void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *init);
56 void aarch64_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid,
57 			      struct kvm_vcpu_init *init, void *guest_code);
58 
59 #endif /* SELFTEST_KVM_PROCESSOR_H */
60