vfio/spapr: switch to spapr IOMMU BE add/del_section_window

No functional change intended.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
Zhenzhong Duan 2023-11-02 15:12:43 +08:00 committed by Cédric Le Goater
parent 9b7d38bf5a
commit 233309e8e4
5 changed files with 42 additions and 16 deletions

View File

@ -571,8 +571,6 @@ static void vfio_listener_region_add(MemoryListener *listener,
{ {
VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase, VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
listener); listener);
VFIOContainer *container = container_of(bcontainer, VFIOContainer,
bcontainer);
hwaddr iova, end; hwaddr iova, end;
Int128 llend, llsize; Int128 llend, llsize;
void *vaddr; void *vaddr;
@ -595,7 +593,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
return; return;
} }
if (vfio_container_add_section_window(container, section, &err)) { if (vfio_container_add_section_window(bcontainer, section, &err)) {
goto fail; goto fail;
} }
@ -738,8 +736,6 @@ static void vfio_listener_region_del(MemoryListener *listener,
{ {
VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase, VFIOContainerBase *bcontainer = container_of(listener, VFIOContainerBase,
listener); listener);
VFIOContainer *container = container_of(bcontainer, VFIOContainer,
bcontainer);
hwaddr iova, end; hwaddr iova, end;
Int128 llend, llsize; Int128 llend, llsize;
int ret; int ret;
@ -818,7 +814,7 @@ static void vfio_listener_region_del(MemoryListener *listener,
memory_region_unref(section->mr); memory_region_unref(section->mr);
vfio_container_del_section_window(container, section); vfio_container_del_section_window(bcontainer, section);
} }
typedef struct VFIODirtyRanges { typedef struct VFIODirtyRanges {

View File

@ -31,6 +31,27 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb); return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb);
} }
int vfio_container_add_section_window(VFIOContainerBase *bcontainer,
MemoryRegionSection *section,
Error **errp)
{
if (!bcontainer->ops->add_window) {
return 0;
}
return bcontainer->ops->add_window(bcontainer, section, errp);
}
void vfio_container_del_section_window(VFIOContainerBase *bcontainer,
MemoryRegionSection *section)
{
if (!bcontainer->ops->del_window) {
return;
}
return bcontainer->ops->del_window(bcontainer, section);
}
int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer,
bool start) bool start)
{ {

View File

@ -319,10 +319,13 @@ static int vfio_spapr_create_window(VFIOContainer *container,
return 0; return 0;
} }
int vfio_container_add_section_window(VFIOContainer *container, static int
MemoryRegionSection *section, vfio_spapr_container_add_section_window(VFIOContainerBase *bcontainer,
Error **errp) MemoryRegionSection *section,
Error **errp)
{ {
VFIOContainer *container = container_of(bcontainer, VFIOContainer,
bcontainer);
VFIOHostDMAWindow *hostwin; VFIOHostDMAWindow *hostwin;
hwaddr pgsize = 0; hwaddr pgsize = 0;
int ret; int ret;
@ -407,9 +410,13 @@ int vfio_container_add_section_window(VFIOContainer *container,
return 0; return 0;
} }
void vfio_container_del_section_window(VFIOContainer *container, static void
MemoryRegionSection *section) vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer,
MemoryRegionSection *section)
{ {
VFIOContainer *container = container_of(bcontainer, VFIOContainer,
bcontainer);
if (container->iommu_type != VFIO_SPAPR_TCE_v2_IOMMU) { if (container->iommu_type != VFIO_SPAPR_TCE_v2_IOMMU) {
return; return;
} }
@ -430,6 +437,8 @@ static VFIOIOMMUOps vfio_iommu_spapr_ops;
static void setup_spapr_ops(VFIOContainerBase *bcontainer) static void setup_spapr_ops(VFIOContainerBase *bcontainer)
{ {
vfio_iommu_spapr_ops = *bcontainer->ops; 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; bcontainer->ops = &vfio_iommu_spapr_ops;
} }

View File

@ -169,11 +169,6 @@ VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
void vfio_put_address_space(VFIOAddressSpace *space); void vfio_put_address_space(VFIOAddressSpace *space);
/* SPAPR specific */ /* SPAPR specific */
int vfio_container_add_section_window(VFIOContainer *container,
MemoryRegionSection *section,
Error **errp);
void vfio_container_del_section_window(VFIOContainer *container,
MemoryRegionSection *section);
int vfio_spapr_container_init(VFIOContainer *container, Error **errp); int vfio_spapr_container_init(VFIOContainer *container, Error **errp);
void vfio_spapr_container_deinit(VFIOContainer *container); void vfio_spapr_container_deinit(VFIOContainer *container);

View File

@ -75,6 +75,11 @@ int vfio_container_dma_map(VFIOContainerBase *bcontainer,
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);
int vfio_container_add_section_window(VFIOContainerBase *bcontainer,
MemoryRegionSection *section,
Error **errp);
void vfio_container_del_section_window(VFIOContainerBase *bcontainer,
MemoryRegionSection *section);
int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer,
bool start); bool start);
int vfio_container_query_dirty_bitmap(VFIOContainerBase *bcontainer, int vfio_container_query_dirty_bitmap(VFIOContainerBase *bcontainer,