xref: /kvm-unit-tests/lib/s390x/sie.h (revision 1f08a91a41402b0e032ecce8ed1b5952cbfca0ea)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _S390X_SIE_H_
3 #define _S390X_SIE_H_
4 
5 #include <stdint.h>
6 #include <asm/arch_def.h>
7 #include <asm/sie-arch.h>
8 
9 struct vm_uv {
10 	uint64_t vm_handle;
11 	uint64_t vcpu_handle;
12 	uint64_t asce;
13 	void *conf_base_stor;
14 	void *conf_var_stor;
15 	void *cpu_stor;
16 };
17 
18 struct vm_save_regs {
19 	uint64_t asce;
20 	uint64_t grs[16];
21 	uint64_t fprs[16];
22 	uint32_t fpc;
23 };
24 
25 /* We might be able to nestle all of this into the stack frame. But
26  * having a dedicated save area that saves more than the s390 ELF ABI
27  * defines leaves us more freedom in the implementation.
28 */
29 struct vm_save_area {
30 	struct vm_save_regs guest;
31 	struct vm_save_regs host;
32 };
33 
34 struct vm {
35 	struct kvm_s390_sie_block *sblk;
36 	struct vm_save_area save_area;
37 	struct esca_block *sca;			/* System Control Area */
38 	uint8_t *crycb;				/* Crypto Control Block */
39 	struct vm_uv uv;			/* PV UV information */
40 	/* Ptr to first guest page */
41 	uint8_t *guest_mem;
42 	bool validity_expected;
43 };
44 
45 extern void sie_entry(void);
46 extern void sie_exit(void);
47 extern void sie_entry_gregs(void);
48 extern void sie_exit_gregs(void);
49 extern void sie64a(struct kvm_s390_sie_block *sblk, struct vm_save_area *save_area);
50 void sie(struct vm *vm);
51 void sie_expect_validity(struct vm *vm);
52 uint16_t sie_get_validity(struct vm *vm);
53 void sie_check_validity(struct vm *vm, uint16_t vir_exp);
54 void sie_handle_validity(struct vm *vm);
55 
sie_is_pv(struct vm * vm)56 static inline bool sie_is_pv(struct vm *vm)
57 {
58 	return vm->sblk->sdf == 2;
59 }
60 
61 void sie_guest_sca_create(struct vm *vm);
62 void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len);
63 void sie_guest_destroy(struct vm *vm);
64 
65 uint8_t *sie_guest_alloc(uint64_t guest_size);
66 
67 #endif /* _S390X_SIE_H_ */
68