]>
git.proxmox.com Git - mirror_qemu.git/blob - hw/s390x/s390-pci-vfio.c
2 * s390 vfio-pci interfaces
4 * Copyright 2020 IBM Corp.
5 * Author(s): Matthew Rosato <mjrosato@linux.ibm.com>
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
12 #include <sys/ioctl.h>
14 #include "qemu/osdep.h"
15 #include "hw/s390x/s390-pci-bus.h"
16 #include "hw/s390x/s390-pci-vfio.h"
17 #include "hw/vfio/pci.h"
18 #include "hw/vfio/vfio-common.h"
21 * Get the current DMA available count from vfio. Returns true if vfio is
22 * limiting DMA requests, false otherwise. The current available count read
23 * from vfio is returned in avail.
25 bool s390_pci_update_dma_avail(int fd
, unsigned int *avail
)
27 g_autofree
struct vfio_iommu_type1_info
*info
;
32 argsz
= sizeof(struct vfio_iommu_type1_info
);
33 info
= g_malloc0(argsz
);
36 * If the specified argsz is not large enough to contain all capabilities
37 * it will be updated upon return from the ioctl. Retry until we have
38 * a big enough buffer to hold the entire capability chain.
43 if (ioctl(fd
, VFIO_IOMMU_GET_INFO
, info
)) {
47 if (info
->argsz
> argsz
) {
49 info
= g_realloc(info
, argsz
);
53 /* If the capability exists, update with the current value */
54 return vfio_get_info_dma_avail(info
, avail
);
57 S390PCIDMACount
*s390_pci_start_dma_count(S390pciState
*s
,
58 S390PCIBusDevice
*pbdev
)
62 VFIOPCIDevice
*vpdev
= container_of(pbdev
->pdev
, VFIOPCIDevice
, pdev
);
67 id
= vpdev
->vbasedev
.group
->container
->fd
;
69 if (!s390_pci_update_dma_avail(id
, &avail
)) {
73 QTAILQ_FOREACH(cnt
, &s
->zpci_dma_limit
, link
) {
80 cnt
= g_new0(S390PCIDMACount
, 1);
84 QTAILQ_INSERT_TAIL(&s
->zpci_dma_limit
, cnt
, link
);
88 void s390_pci_end_dma_count(S390pciState
*s
, S390PCIDMACount
*cnt
)
93 if (cnt
->users
== 0) {
94 QTAILQ_REMOVE(&s
->zpci_dma_limit
, cnt
, link
);