[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v3 10/18] vfio/ap: Use vfio_[attach/detach]_device
From: |
Eric Auger |
Subject: |
[RFC v3 10/18] vfio/ap: Use vfio_[attach/detach]_device |
Date: |
Tue, 31 Jan 2023 21:52:57 +0100 |
Let the vfio-ap device use vfio_attach_device() and
vfio_detach_device(), hence hiding the details of the used
IOMMU backend.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
hw/vfio/ap.c | 62 ++++++++--------------------------------------------
1 file changed, 9 insertions(+), 53 deletions(-)
diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
index e0dd561e85..286ac638e5 100644
--- a/hw/vfio/ap.c
+++ b/hw/vfio/ap.c
@@ -50,58 +50,17 @@ struct VFIODeviceOps vfio_ap_ops = {
.vfio_compute_needs_reset = vfio_ap_compute_needs_reset,
};
-static void vfio_ap_put_device(VFIOAPDevice *vapdev)
-{
- g_free(vapdev->vdev.name);
- vfio_put_base_device(&vapdev->vdev);
-}
-
-static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
-{
- GError *gerror = NULL;
- char *symlink, *group_path;
- int groupid;
-
- symlink = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
- group_path = g_file_read_link(symlink, &gerror);
- g_free(symlink);
-
- if (!group_path) {
- error_setg(errp, "%s: no iommu_group found for %s: %s",
- TYPE_VFIO_AP_DEVICE, vapdev->vdev.sysfsdev,
gerror->message);
- g_error_free(gerror);
- return NULL;
- }
-
- if (sscanf(basename(group_path), "%d", &groupid) != 1) {
- error_setg(errp, "vfio: failed to read %s", group_path);
- g_free(group_path);
- return NULL;
- }
-
- g_free(group_path);
-
- return vfio_get_group(groupid, &address_space_memory, errp);
-}
-
static void vfio_ap_realize(DeviceState *dev, Error **errp)
{
- int ret;
- char *mdevid;
- VFIOGroup *vfio_group;
APDevice *apdev = AP_DEVICE(dev);
VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
+ VFIODevice *vbasedev = &vapdev->vdev;
+ int ret;
- vfio_group = vfio_ap_get_group(vapdev, errp);
- if (!vfio_group) {
- return;
- }
-
- vapdev->vdev.ops = &vfio_ap_ops;
- vapdev->vdev.type = VFIO_DEVICE_TYPE_AP;
- mdevid = basename(vapdev->vdev.sysfsdev);
- vapdev->vdev.name = g_strdup_printf("%s", mdevid);
- vapdev->vdev.dev = dev;
+ vbasedev->name = g_path_get_basename(vbasedev->sysfsdev);
+ vbasedev->ops = &vfio_ap_ops;
+ vbasedev->type = VFIO_DEVICE_TYPE_AP;
+ vbasedev->dev = dev;
/*
* vfio-ap devices operate in a way compatible with discarding of
@@ -111,7 +70,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
*/
vapdev->vdev.ram_block_discard_allowed = true;
- ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, errp);
+ ret = vfio_attach_device(vbasedev, &address_space_memory, errp);
if (ret) {
goto out_get_dev_err;
}
@@ -119,18 +78,15 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
return;
out_get_dev_err:
- vfio_ap_put_device(vapdev);
- vfio_put_group(vfio_group);
+ vfio_detach_device(vbasedev);
}
static void vfio_ap_unrealize(DeviceState *dev)
{
APDevice *apdev = AP_DEVICE(dev);
VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
- VFIOGroup *group = vapdev->vdev.group;
- vfio_ap_put_device(vapdev);
- vfio_put_group(group);
+ vfio_detach_device(&vapdev->vdev);
}
static Property vfio_ap_properties[] = {
--
2.37.3
- [RFC v3 00/18] vfio: Adopt iommufd, Eric Auger, 2023/01/31
- [RFC v3 01/18] scripts/update-linux-headers: Add iommufd.h, Eric Auger, 2023/01/31
- [RFC v3 02/18] linux-headers: Import vfio.h and iommufd.h, Eric Auger, 2023/01/31
- [RFC v3 03/18] vfio/common: Move IOMMU agnostic helpers to a separate file, Eric Auger, 2023/01/31
- [RFC v3 04/18] vfio/common: Introduce vfio_container_add|del_section_window(), Eric Auger, 2023/01/31
- [RFC v3 05/18] vfio/common: Move legacy VFIO backend code into separate container.c, Eric Auger, 2023/01/31
- [RFC v3 06/18] vfio/common: Rename into as.c, Eric Auger, 2023/01/31
- [RFC v3 07/18] vfio: Add base container, Eric Auger, 2023/01/31
- [RFC v3 08/18] vfio/container: Introduce vfio_[attach/detach]_device, Eric Auger, 2023/01/31
- [RFC v3 09/18] vfio/platform: Use vfio_[attach/detach]_device, Eric Auger, 2023/01/31
- [RFC v3 10/18] vfio/ap: Use vfio_[attach/detach]_device,
Eric Auger <=
- [RFC v3 11/18] vfio/ccw: Use vfio_[attach/detach]_device, Eric Auger, 2023/01/31
- [RFC v3 12/18] vfio/container-base: Introduce [attach/detach]_device container callbacks, Eric Auger, 2023/01/31
- [RFC v3 13/18] vfio/container-base: Introduce VFIOContainer reset callback, Eric Auger, 2023/01/31
- [RFC v3 14/18] backends/iommufd: Introduce the iommufd object, Eric Auger, 2023/01/31
- [RFC v3 15/18] util/char_dev: Add open_cdev(), Eric Auger, 2023/01/31
- [RFC v3 16/18] vfio/iommufd: Implement the iommufd backend, Eric Auger, 2023/01/31
- [RFC v3 17/18] vfio/iommufd: Add IOAS_COPY_DMA support, Eric Auger, 2023/01/31
- [RFC v3 18/18] vfio/as: Allow the selection of a given iommu backend, Eric Auger, 2023/01/31