aboutsummaryrefslogtreecommitdiff
path: root/hw/s390x/s390-pci-kvm.c
blob: 9eef4fc3ec72ee68e5d2998f979ee595902b1723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * s390 zPCI KVM interfaces
 *
 * Copyright 2022 IBM Corp.
 * Author(s): Matthew Rosato <mjrosato@linux.ibm.com>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or (at
 * your option) any later version. See the COPYING file in the top-level
 * directory.
 */

#include "qemu/osdep.h"

#include <linux/kvm.h>

#include "kvm/kvm_s390x.h"
#include "target/s390x/kvm/pv.h"
#include "hw/s390x/s390-pci-bus.h"
#include "hw/s390x/s390-pci-kvm.h"
#include "hw/s390x/s390-pci-inst.h"
#include "hw/s390x/s390-pci-vfio.h"
#include "cpu_models.h"

bool s390_pci_kvm_interp_allowed(void)
{
    return kvm_s390_get_zpci_op() && !s390_is_pv();
}

int s390_pci_kvm_aif_enable(S390PCIBusDevice *pbdev, ZpciFib *fib, bool assist)
{
    int rc;
    struct kvm_s390_zpci_op args = {
        .fh = pbdev->fh,
        .op = KVM_S390_ZPCIOP_REG_AEN,
        .u.reg_aen.ibv = fib->aibv,
        .u.reg_aen.sb = fib->aisb,
        .u.reg_aen.noi = FIB_DATA_NOI(fib->data),
        .u.reg_aen.isc = FIB_DATA_ISC(fib->data),
        .u.reg_aen.sbo = FIB_DATA_AISBO(fib->data),
        .u.reg_aen.flags = (assist) ? 0 : KVM_S390_ZPCIOP_REGAEN_HOST
    };

    if (pbdev->aif) {
        return -EINVAL;
    }

    rc = kvm_vm_ioctl(kvm_state, KVM_S390_ZPCI_OP, &args);
    if (rc == 0) {
        pbdev->aif = true;
    }

    return rc;
}

int s390_pci_kvm_aif_disable(S390PCIBusDevice *pbdev)
{
    int rc;

    struct kvm_s390_zpci_op args = {
        .fh = pbdev->fh,
        .op = KVM_S390_ZPCIOP_DEREG_AEN
    };

    if (!pbdev->aif) {
        return -EINVAL;
    }

    /*
     * The device may have already been reset but we still want to relinquish
     * the guest ISC, so always be sure to use an up-to-date host fh.
     */
    if (!s390_pci_get_host_fh(pbdev, &args.fh)) {
        return -EPERM;
    }

    rc = kvm_vm_ioctl(kvm_state, KVM_S390_ZPCI_OP, &args);
    if (rc == 0) {
        pbdev->aif = false;
    }

    return rc;
}