diff options
Diffstat (limited to 'hw/vfio/spapr.c')
| -rw-r--r-- | hw/vfio/spapr.c | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 5c6426e697..0d949bb728 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -440,19 +440,29 @@ vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer, } } -static VFIOIOMMUOps vfio_iommu_spapr_ops; - -static void setup_spapr_ops(VFIOContainerBase *bcontainer) +static void vfio_spapr_container_release(VFIOContainerBase *bcontainer) { - vfio_iommu_spapr_ops = *bcontainer->ops; - vfio_iommu_spapr_ops.add_window = vfio_spapr_container_add_section_window; - vfio_iommu_spapr_ops.del_window = vfio_spapr_container_del_section_window; - bcontainer->ops = &vfio_iommu_spapr_ops; + VFIOContainer *container = container_of(bcontainer, VFIOContainer, + bcontainer); + VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer, + container); + VFIOHostDMAWindow *hostwin, *next; + + if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU) { + memory_listener_unregister(&scontainer->prereg_listener); + } + QLIST_FOREACH_SAFE(hostwin, &scontainer->hostwin_list, hostwin_next, + next) { + QLIST_REMOVE(hostwin, hostwin_next); + g_free(hostwin); + } } -int vfio_spapr_container_init(VFIOContainer *container, Error **errp) +static int vfio_spapr_container_setup(VFIOContainerBase *bcontainer, + Error **errp) { - VFIOContainerBase *bcontainer = &container->bcontainer; + VFIOContainer *container = container_of(bcontainer, VFIOContainer, + bcontainer); VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer, container); struct vfio_iommu_spapr_tce_info info; @@ -517,8 +527,6 @@ int vfio_spapr_container_init(VFIOContainer *container, Error **errp) 0x1000); } - setup_spapr_ops(bcontainer); - return 0; listener_unregister_exit: @@ -528,18 +536,22 @@ listener_unregister_exit: return ret; } -void vfio_spapr_container_deinit(VFIOContainer *container) +static void vfio_iommu_spapr_class_init(ObjectClass *klass, void *data) { - VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer, - container); - VFIOHostDMAWindow *hostwin, *next; + VFIOIOMMUClass *vioc = VFIO_IOMMU_CLASS(klass); - if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU) { - memory_listener_unregister(&scontainer->prereg_listener); - } - QLIST_FOREACH_SAFE(hostwin, &scontainer->hostwin_list, hostwin_next, - next) { - QLIST_REMOVE(hostwin, hostwin_next); - g_free(hostwin); - } -} + vioc->add_window = vfio_spapr_container_add_section_window; + vioc->del_window = vfio_spapr_container_del_section_window; + vioc->release = vfio_spapr_container_release; + vioc->setup = vfio_spapr_container_setup; +}; + +static const TypeInfo types[] = { + { + .name = TYPE_VFIO_IOMMU_SPAPR, + .parent = TYPE_VFIO_IOMMU_LEGACY, + .class_init = vfio_iommu_spapr_class_init, + }, +}; + +DEFINE_TYPES(types) |