mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-24 18:41:58 -06:00
vfio/container: Remove VFIOContainerBase::ops
Instead, use VFIO_IOMMU_GET_CLASS() to get the class pointer. Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Tested-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
2137d2fd17
commit
41d698b8d6
6 changed files with 38 additions and 25 deletions
|
@ -1573,5 +1573,5 @@ void vfio_detach_device(VFIODevice *vbasedev)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
object_unref(vbasedev->hiod);
|
object_unref(vbasedev->hiod);
|
||||||
vbasedev->bcontainer->ops->detach_device(vbasedev);
|
VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer)->detach_device(vbasedev);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,62 +19,73 @@ int vfio_container_dma_map(VFIOContainerBase *bcontainer,
|
||||||
hwaddr iova, ram_addr_t size,
|
hwaddr iova, ram_addr_t size,
|
||||||
void *vaddr, bool readonly)
|
void *vaddr, bool readonly)
|
||||||
{
|
{
|
||||||
g_assert(bcontainer->ops->dma_map);
|
VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
|
||||||
return bcontainer->ops->dma_map(bcontainer, iova, size, vaddr, readonly);
|
|
||||||
|
g_assert(vioc->dma_map);
|
||||||
|
return vioc->dma_map(bcontainer, iova, size, vaddr, readonly);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
|
int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
|
||||||
hwaddr iova, ram_addr_t size,
|
hwaddr iova, ram_addr_t size,
|
||||||
IOMMUTLBEntry *iotlb)
|
IOMMUTLBEntry *iotlb)
|
||||||
{
|
{
|
||||||
g_assert(bcontainer->ops->dma_unmap);
|
VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
|
||||||
return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb);
|
|
||||||
|
g_assert(vioc->dma_unmap);
|
||||||
|
return vioc->dma_unmap(bcontainer, iova, size, iotlb);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vfio_container_add_section_window(VFIOContainerBase *bcontainer,
|
bool vfio_container_add_section_window(VFIOContainerBase *bcontainer,
|
||||||
MemoryRegionSection *section,
|
MemoryRegionSection *section,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
if (!bcontainer->ops->add_window) {
|
VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
|
||||||
|
|
||||||
|
if (!vioc->add_window) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bcontainer->ops->add_window(bcontainer, section, errp);
|
return vioc->add_window(bcontainer, section, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vfio_container_del_section_window(VFIOContainerBase *bcontainer,
|
void vfio_container_del_section_window(VFIOContainerBase *bcontainer,
|
||||||
MemoryRegionSection *section)
|
MemoryRegionSection *section)
|
||||||
{
|
{
|
||||||
if (!bcontainer->ops->del_window) {
|
VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
|
||||||
|
|
||||||
|
if (!vioc->del_window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bcontainer->ops->del_window(bcontainer, section);
|
return vioc->del_window(bcontainer, section);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer,
|
int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer,
|
||||||
bool start, Error **errp)
|
bool start, Error **errp)
|
||||||
{
|
{
|
||||||
|
VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
|
||||||
|
|
||||||
if (!bcontainer->dirty_pages_supported) {
|
if (!bcontainer->dirty_pages_supported) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert(bcontainer->ops->set_dirty_page_tracking);
|
g_assert(vioc->set_dirty_page_tracking);
|
||||||
return bcontainer->ops->set_dirty_page_tracking(bcontainer, start, errp);
|
return vioc->set_dirty_page_tracking(bcontainer, start, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
|
int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
|
||||||
VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
|
VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
|
||||||
{
|
{
|
||||||
g_assert(bcontainer->ops->query_dirty_bitmap);
|
VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
|
||||||
return bcontainer->ops->query_dirty_bitmap(bcontainer, vbmap, iova, size,
|
|
||||||
|
g_assert(vioc->query_dirty_bitmap);
|
||||||
|
return vioc->query_dirty_bitmap(bcontainer, vbmap, iova, size,
|
||||||
errp);
|
errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vfio_container_init(VFIOContainerBase *bcontainer,
|
void vfio_container_init(VFIOContainerBase *bcontainer,
|
||||||
const VFIOIOMMUClass *ops)
|
const VFIOIOMMUClass *ops)
|
||||||
{
|
{
|
||||||
bcontainer->ops = ops;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void vfio_container_destroy(VFIOContainerBase *bcontainer)
|
void vfio_container_destroy(VFIOContainerBase *bcontainer)
|
||||||
|
|
|
@ -548,6 +548,7 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
||||||
VFIOContainerBase *bcontainer;
|
VFIOContainerBase *bcontainer;
|
||||||
int ret, fd;
|
int ret, fd;
|
||||||
VFIOAddressSpace *space;
|
VFIOAddressSpace *space;
|
||||||
|
VFIOIOMMUClass *vioc;
|
||||||
|
|
||||||
space = vfio_get_address_space(as);
|
space = vfio_get_address_space(as);
|
||||||
|
|
||||||
|
@ -632,9 +633,10 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
||||||
goto unregister_container_exit;
|
goto unregister_container_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(bcontainer->ops->setup);
|
vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
|
||||||
|
assert(vioc->setup);
|
||||||
|
|
||||||
if (!bcontainer->ops->setup(bcontainer, errp)) {
|
if (!vioc->setup(bcontainer, errp)) {
|
||||||
goto enable_discards_exit;
|
goto enable_discards_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,8 +665,8 @@ listener_release_exit:
|
||||||
QLIST_REMOVE(bcontainer, next);
|
QLIST_REMOVE(bcontainer, next);
|
||||||
vfio_kvm_device_del_group(group);
|
vfio_kvm_device_del_group(group);
|
||||||
memory_listener_unregister(&bcontainer->listener);
|
memory_listener_unregister(&bcontainer->listener);
|
||||||
if (bcontainer->ops->release) {
|
if (vioc->release) {
|
||||||
bcontainer->ops->release(bcontainer);
|
vioc->release(bcontainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
enable_discards_exit:
|
enable_discards_exit:
|
||||||
|
@ -689,6 +691,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
|
||||||
{
|
{
|
||||||
VFIOContainer *container = group->container;
|
VFIOContainer *container = group->container;
|
||||||
VFIOContainerBase *bcontainer = &container->bcontainer;
|
VFIOContainerBase *bcontainer = &container->bcontainer;
|
||||||
|
VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
|
||||||
|
|
||||||
QLIST_REMOVE(group, container_next);
|
QLIST_REMOVE(group, container_next);
|
||||||
group->container = NULL;
|
group->container = NULL;
|
||||||
|
@ -700,8 +703,8 @@ static void vfio_disconnect_container(VFIOGroup *group)
|
||||||
*/
|
*/
|
||||||
if (QLIST_EMPTY(&container->group_list)) {
|
if (QLIST_EMPTY(&container->group_list)) {
|
||||||
memory_listener_unregister(&bcontainer->listener);
|
memory_listener_unregister(&bcontainer->listener);
|
||||||
if (bcontainer->ops->release) {
|
if (vioc->release) {
|
||||||
bcontainer->ops->release(bcontainer);
|
vioc->release(bcontainer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -324,7 +324,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
|
||||||
/* try to attach to an existing container in this space */
|
/* try to attach to an existing container in this space */
|
||||||
QLIST_FOREACH(bcontainer, &space->containers, next) {
|
QLIST_FOREACH(bcontainer, &space->containers, next) {
|
||||||
container = container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
|
container = container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
|
||||||
if (bcontainer->ops != iommufd_vioc ||
|
if (VFIO_IOMMU_GET_CLASS(bcontainer) != iommufd_vioc ||
|
||||||
vbasedev->iommufd != container->be) {
|
vbasedev->iommufd != container->be) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,7 @@ static VFIODevice *iommufd_cdev_pci_find_by_devid(__u32 devid)
|
||||||
VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD));
|
VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD));
|
||||||
|
|
||||||
QLIST_FOREACH(vbasedev_iter, &vfio_device_list, global_next) {
|
QLIST_FOREACH(vbasedev_iter, &vfio_device_list, global_next) {
|
||||||
if (vbasedev_iter->bcontainer->ops != iommufd_vioc) {
|
if (VFIO_IOMMU_GET_CLASS(vbasedev_iter->bcontainer) != iommufd_vioc) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (devid == vbasedev_iter->devid) {
|
if (devid == vbasedev_iter->devid) {
|
||||||
|
|
|
@ -2511,9 +2511,9 @@ int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev,
|
||||||
static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
|
static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
|
||||||
{
|
{
|
||||||
VFIODevice *vbasedev = &vdev->vbasedev;
|
VFIODevice *vbasedev = &vdev->vbasedev;
|
||||||
const VFIOIOMMUClass *ops = vbasedev->bcontainer->ops;
|
const VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer);
|
||||||
|
|
||||||
return ops->pci_hot_reset(vbasedev, single);
|
return vioc->pci_hot_reset(vbasedev, single);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -35,7 +35,6 @@ typedef struct VFIOAddressSpace {
|
||||||
*/
|
*/
|
||||||
typedef struct VFIOContainerBase {
|
typedef struct VFIOContainerBase {
|
||||||
Object parent;
|
Object parent;
|
||||||
const VFIOIOMMUClass *ops;
|
|
||||||
VFIOAddressSpace *space;
|
VFIOAddressSpace *space;
|
||||||
MemoryListener listener;
|
MemoryListener listener;
|
||||||
Error *error;
|
Error *error;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue