Files
QEMU-S5L8950X/hw/vfio/kvm-spapr.c
T
Yaya48 cf256aa081 Import QEMU upstream snapshot d2e570c
Upstream: https://gitlab.com/qemu-project/qemu.git

Upstream-Commit: d2e570cc0f97b936902a5b1b86b73c0f5998b475
2026-08-31 02:15:30 +02:00

48 lines
1.5 KiB
C

/*
* VFIO sPAPR KVM specific functions
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "qemu/osdep.h"
#include <sys/ioctl.h>
#include <linux/vfio.h>
#include <linux/kvm.h>
#include "hw/vfio/vfio-container-legacy.h"
#include "hw/vfio/kvm-spapr.h"
#include "qapi/error.h"
#include "trace.h"
#include "vfio-helpers.h"
bool vfio_spapr_kvm_attach_tce(VFIOContainer *bcontainer,
MemoryRegionSection *section,
Error **errp)
{
VFIOLegacyContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
VFIOGroup *group;
IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
struct kvm_vfio_spapr_tce param;
struct kvm_device_attr attr = {
.group = KVM_DEV_VFIO_GROUP,
.attr = KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE,
.addr = (uint64_t)(unsigned long)&param,
};
if (!memory_region_iommu_get_attr(iommu_mr, IOMMU_ATTR_SPAPR_TCE_FD,
&param.tablefd)) {
QLIST_FOREACH(group, &container->group_list, container_next) {
param.groupfd = group->fd;
if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
error_setg_errno(errp, errno,
"vfio: failed GROUP_SET_SPAPR_TCE for "
"KVM VFIO device %d and group fd %d",
param.tablefd, param.groupfd);
return false;
}
trace_vfio_spapr_group_attach(param.groupfd, param.tablefd);
}
}
return true;
}