s390x: protvirt: Support unpack facility
[qemu/ar7.git] / hw / s390x / pv.c
bloba40a8448060c52cda4d177aec87efbbaef8e455c
1 /*
2 * Protected Virtualization functions
4 * Copyright IBM Corp. 2020
5 * Author(s):
6 * Janosch Frank <frankja@linux.ibm.com>
8 * This work is licensed under the terms of the GNU GPL, version 2 or (at
9 * your option) any later version. See the COPYING file in the top-level
10 * directory.
12 #include "qemu/osdep.h"
14 #include <linux/kvm.h>
16 #include "qemu/error-report.h"
17 #include "sysemu/kvm.h"
18 #include "hw/s390x/pv.h"
20 static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
22 struct kvm_pv_cmd pv_cmd = {
23 .cmd = cmd,
24 .data = (uint64_t)data,
26 int rc = kvm_vm_ioctl(kvm_state, KVM_S390_PV_COMMAND, &pv_cmd);
28 if (rc) {
29 error_report("KVM PV command %d (%s) failed: header rc %x rrc %x "
30 "IOCTL rc: %d", cmd, cmdname, pv_cmd.rc, pv_cmd.rrc,
31 rc);
33 return rc;
37 * This macro lets us pass the command as a string to the function so
38 * we can print it on an error.
40 #define s390_pv_cmd(cmd, data) __s390_pv_cmd(cmd, #cmd, data);
41 #define s390_pv_cmd_exit(cmd, data) \
42 { \
43 int rc; \
45 rc = __s390_pv_cmd(cmd, #cmd, data);\
46 if (rc) { \
47 exit(1); \
48 } \
51 int s390_pv_vm_enable(void)
53 return s390_pv_cmd(KVM_PV_ENABLE, NULL);
56 void s390_pv_vm_disable(void)
58 s390_pv_cmd_exit(KVM_PV_DISABLE, NULL);
61 int s390_pv_set_sec_parms(uint64_t origin, uint64_t length)
63 struct kvm_s390_pv_sec_parm args = {
64 .origin = origin,
65 .length = length,
68 return s390_pv_cmd(KVM_PV_SET_SEC_PARMS, &args);
72 * Called for each component in the SE type IPL parameter block 0.
74 int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak)
76 struct kvm_s390_pv_unp args = {
77 .addr = addr,
78 .size = size,
79 .tweak = tweak,
82 return s390_pv_cmd(KVM_PV_UNPACK, &args);
85 void s390_pv_perf_clear_reset(void)
87 s390_pv_cmd_exit(KVM_PV_PREP_RESET, NULL);
90 int s390_pv_verify(void)
92 return s390_pv_cmd(KVM_PV_VERIFY, NULL);
95 void s390_pv_unshare(void)
97 s390_pv_cmd_exit(KVM_PV_UNSHARE_ALL, NULL);