]>
git.proxmox.com Git - mirror_qemu.git/blob - hw/vfio/container-base.c
4 * Copyright (C) 2023 Intel Corporation.
5 * Copyright Red Hat, Inc. 2023
7 * Authors: Yi Liu <yi.l.liu@intel.com>
8 * Eric Auger <eric.auger@redhat.com>
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "qemu/error-report.h"
16 #include "hw/vfio/vfio-container-base.h"
18 int vfio_container_dma_map(VFIOContainerBase
*bcontainer
,
19 hwaddr iova
, ram_addr_t size
,
20 void *vaddr
, bool readonly
)
22 g_assert(bcontainer
->ops
->dma_map
);
23 return bcontainer
->ops
->dma_map(bcontainer
, iova
, size
, vaddr
, readonly
);
26 int vfio_container_dma_unmap(VFIOContainerBase
*bcontainer
,
27 hwaddr iova
, ram_addr_t size
,
30 g_assert(bcontainer
->ops
->dma_unmap
);
31 return bcontainer
->ops
->dma_unmap(bcontainer
, iova
, size
, iotlb
);
34 int vfio_container_add_section_window(VFIOContainerBase
*bcontainer
,
35 MemoryRegionSection
*section
,
38 if (!bcontainer
->ops
->add_window
) {
42 return bcontainer
->ops
->add_window(bcontainer
, section
, errp
);
45 void vfio_container_del_section_window(VFIOContainerBase
*bcontainer
,
46 MemoryRegionSection
*section
)
48 if (!bcontainer
->ops
->del_window
) {
52 return bcontainer
->ops
->del_window(bcontainer
, section
);
55 int vfio_container_set_dirty_page_tracking(VFIOContainerBase
*bcontainer
,
58 if (!bcontainer
->dirty_pages_supported
) {
62 g_assert(bcontainer
->ops
->set_dirty_page_tracking
);
63 return bcontainer
->ops
->set_dirty_page_tracking(bcontainer
, start
);
66 int vfio_container_query_dirty_bitmap(const VFIOContainerBase
*bcontainer
,
68 hwaddr iova
, hwaddr size
)
70 g_assert(bcontainer
->ops
->query_dirty_bitmap
);
71 return bcontainer
->ops
->query_dirty_bitmap(bcontainer
, vbmap
, iova
, size
);
74 void vfio_container_init(VFIOContainerBase
*bcontainer
, VFIOAddressSpace
*space
,
75 const VFIOIOMMUClass
*ops
)
77 bcontainer
->ops
= ops
;
78 bcontainer
->space
= space
;
79 bcontainer
->error
= NULL
;
80 bcontainer
->dirty_pages_supported
= false;
81 bcontainer
->dma_max_mappings
= 0;
82 bcontainer
->iova_ranges
= NULL
;
83 QLIST_INIT(&bcontainer
->giommu_list
);
84 QLIST_INIT(&bcontainer
->vrdl_list
);
87 void vfio_container_destroy(VFIOContainerBase
*bcontainer
)
89 VFIOGuestIOMMU
*giommu
, *tmp
;
91 QLIST_REMOVE(bcontainer
, next
);
93 QLIST_FOREACH_SAFE(giommu
, &bcontainer
->giommu_list
, giommu_next
, tmp
) {
94 memory_region_unregister_iommu_notifier(
95 MEMORY_REGION(giommu
->iommu_mr
), &giommu
->n
);
96 QLIST_REMOVE(giommu
, giommu_next
);
100 g_list_free_full(bcontainer
->iova_ranges
, g_free
);
103 static const TypeInfo types
[] = {
105 .name
= TYPE_VFIO_IOMMU
,
106 .parent
= TYPE_INTERFACE
,
107 .class_size
= sizeof(VFIOIOMMUClass
),