xref: /kvm-unit-tests/lib/s390x/uv.h (revision 95a9408860fc8dacb73e9b302fb96536f91d5ccf)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _S390X_UV_H_
3 #define _S390X_UV_H_
4 
5 #include <sie.h>
6 #include <asm/pgtable.h>
7 #include <vmalloc.h>
8 
9 bool uv_os_is_guest(void);
10 bool uv_os_is_host(void);
11 bool uv_host_requirement_checks(void);
12 bool uv_query_test_call(unsigned int nr);
13 const struct uv_cb_qui *uv_get_query_data(void);
14 void uv_init(void);
15 int uv_setup(void);
16 void uv_create_guest(struct vm *vm);
17 void uv_destroy_guest(struct vm *vm);
18 int uv_unpack(struct vm *vm, uint64_t addr, uint64_t len, uint64_t tweak);
19 void uv_verify_load(struct vm *vm);
20 
21 /*
22  * To run PV guests we need to setup a few things:
23  * - A valid primary ASCE that contains the guest memory and has the P bit set.
24  * - A valid home space ASCE for the UV calls that use home space addresses.
25  */
uv_setup_asces(void)26 static inline void uv_setup_asces(void)
27 {
28 	uint64_t asce;
29 
30 	/* We need to have a valid primary ASCE to run guests. */
31 	setup_vm();
32 
33 	/* Grab the ASCE which setup_vm() just set up */
34 	asce = stctg(1);
35 
36 	/* Copy ASCE into home space CR */
37 	lctlg(13, asce);
38 }
39 
uv_validity_check(struct vm * vm)40 static inline bool uv_validity_check(struct vm *vm)
41 {
42 	uint16_t vir = sie_get_validity(vm);
43 
44 	return vm->sblk->icptcode == ICPT_VALIDITY && (vir & 0xff00) == 0x2000;
45 }
46 
47 #endif /* UV_H */
48