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 14 #include <linux/kvm.h> 15 16 #include "kvm/kvm_s390x.h" 17 #include "target/s390x/kvm/pv.h" 18 #include "hw/s390x/s390-pci-bus.h" 19 #include "hw/s390x/s390-pci-kvm.h" 20 #include "hw/s390x/s390-pci-inst.h" 21 #include "cpu_models.h" 22 23 bool s390_pci_kvm_interp_allowed(void) 24 { 25 return kvm_s390_get_zpci_op() && !s390_is_pv(); 26 } 27 28 int s390_pci_kvm_aif_enable(S390PCIBusDevice *pbdev, ZpciFib *fib, bool assist) 29 { 30 int rc; 31 struct kvm_s390_zpci_op args = { 32 .fh = pbdev->fh, 33 .op = KVM_S390_ZPCIOP_REG_AEN, 34 .u.reg_aen.ibv = fib->aibv, 35 .u.reg_aen.sb = fib->aisb, 36 .u.reg_aen.noi = FIB_DATA_NOI(fib->data), 37 .u.reg_aen.isc = FIB_DATA_ISC(fib->data), 38 .u.reg_aen.sbo = FIB_DATA_AISBO(fib->data), 39 .u.reg_aen.flags = (assist) ? 0 : KVM_S390_ZPCIOP_REGAEN_HOST 40 }; 41 42 if (pbdev->aif) { 43 return -EINVAL; 44 } 45 46 rc = kvm_vm_ioctl(kvm_state, KVM_S390_ZPCI_OP, &args); 47 if (rc == 0) { 48 pbdev->aif = true; 49 } 50 51 return rc; 52 } 53 54 int s390_pci_kvm_aif_disable(S390PCIBusDevice *pbdev) 55 { 56 int rc; 57 58 struct kvm_s390_zpci_op args = { 59 .fh = pbdev->fh, 60 .op = KVM_S390_ZPCIOP_DEREG_AEN 61 }; 62 63 if (!pbdev->aif) { 64 return -EINVAL; 65 } 66 67 rc = kvm_vm_ioctl(kvm_state, KVM_S390_ZPCI_OP, &args); 68 if (rc == 0) { 69 pbdev->aif = false; 70 } 71 72 return rc; 73 } 74