]>
Commit | Line | Data |
---|---|---|
dd1d5fd9 MR |
1 | /* |
2 | * s390 zPCI KVM interfaces | |
3 | * | |
4 | * Copyright 2022 IBM Corp. | |
5 | * Author(s): Matthew Rosato <mjrosato@linux.ibm.com> | |
6 | * | |
7 | * This work is licensed under the terms of the GNU GPL, version 2 or (at | |
8 | * your option) any later version. See the COPYING file in the top-level | |
9 | * directory. | |
10 | */ | |
11 | ||
12 | #include "qemu/osdep.h" | |
13 | ||
d0bc7091 MR |
14 | #include <linux/kvm.h> |
15 | ||
dd1d5fd9 | 16 | #include "kvm/kvm_s390x.h" |
f5f9c6ea | 17 | #include "target/s390x/kvm/pv.h" |
d0bc7091 | 18 | #include "hw/s390x/s390-pci-bus.h" |
dd1d5fd9 | 19 | #include "hw/s390x/s390-pci-kvm.h" |
d0bc7091 | 20 | #include "hw/s390x/s390-pci-inst.h" |
30e35258 | 21 | #include "hw/s390x/s390-pci-vfio.h" |
dd1d5fd9 MR |
22 | #include "cpu_models.h" |
23 | ||
24 | bool s390_pci_kvm_interp_allowed(void) | |
25 | { | |
57702891 | 26 | return kvm_s390_get_zpci_op() && !s390_is_pv(); |
dd1d5fd9 | 27 | } |
d0bc7091 MR |
28 | |
29 | int s390_pci_kvm_aif_enable(S390PCIBusDevice *pbdev, ZpciFib *fib, bool assist) | |
30 | { | |
07b2c8e0 | 31 | int rc; |
d0bc7091 MR |
32 | struct kvm_s390_zpci_op args = { |
33 | .fh = pbdev->fh, | |
34 | .op = KVM_S390_ZPCIOP_REG_AEN, | |
35 | .u.reg_aen.ibv = fib->aibv, | |
36 | .u.reg_aen.sb = fib->aisb, | |
37 | .u.reg_aen.noi = FIB_DATA_NOI(fib->data), | |
38 | .u.reg_aen.isc = FIB_DATA_ISC(fib->data), | |
39 | .u.reg_aen.sbo = FIB_DATA_AISBO(fib->data), | |
40 | .u.reg_aen.flags = (assist) ? 0 : KVM_S390_ZPCIOP_REGAEN_HOST | |
41 | }; | |
42 | ||
07b2c8e0 MR |
43 | if (pbdev->aif) { |
44 | return -EINVAL; | |
45 | } | |
46 | ||
47 | rc = kvm_vm_ioctl(kvm_state, KVM_S390_ZPCI_OP, &args); | |
48 | if (rc == 0) { | |
49 | pbdev->aif = true; | |
50 | } | |
51 | ||
52 | return rc; | |
d0bc7091 MR |
53 | } |
54 | ||
55 | int s390_pci_kvm_aif_disable(S390PCIBusDevice *pbdev) | |
56 | { | |
07b2c8e0 MR |
57 | int rc; |
58 | ||
d0bc7091 MR |
59 | struct kvm_s390_zpci_op args = { |
60 | .fh = pbdev->fh, | |
61 | .op = KVM_S390_ZPCIOP_DEREG_AEN | |
62 | }; | |
63 | ||
07b2c8e0 MR |
64 | if (!pbdev->aif) { |
65 | return -EINVAL; | |
66 | } | |
67 | ||
30e35258 MR |
68 | /* |
69 | * The device may have already been reset but we still want to relinquish | |
70 | * the guest ISC, so always be sure to use an up-to-date host fh. | |
71 | */ | |
72 | if (!s390_pci_get_host_fh(pbdev, &args.fh)) { | |
73 | return -EPERM; | |
74 | } | |
75 | ||
07b2c8e0 MR |
76 | rc = kvm_vm_ioctl(kvm_state, KVM_S390_ZPCI_OP, &args); |
77 | if (rc == 0) { | |
78 | pbdev->aif = false; | |
79 | } | |
80 | ||
81 | return rc; | |
d0bc7091 | 82 | } |