2023-11-02 10:12:29 +03:00
|
|
|
/*
|
|
|
|
* VFIO BASE CONTAINER
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023 Intel Corporation.
|
|
|
|
* Copyright Red Hat, Inc. 2023
|
|
|
|
*
|
|
|
|
* Authors: Yi Liu <yi.l.liu@intel.com>
|
|
|
|
* Eric Auger <eric.auger@redhat.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "hw/vfio/vfio-container-base.h"
|
|
|
|
|
|
|
|
int vfio_container_dma_map(VFIOContainerBase *bcontainer,
|
|
|
|
hwaddr iova, ram_addr_t size,
|
|
|
|
void *vaddr, bool readonly)
|
|
|
|
{
|
|
|
|
g_assert(bcontainer->ops->dma_map);
|
|
|
|
return bcontainer->ops->dma_map(bcontainer, iova, size, vaddr, readonly);
|
|
|
|
}
|
|
|
|
|
|
|
|
int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
|
|
|
|
hwaddr iova, ram_addr_t size,
|
|
|
|
IOMMUTLBEntry *iotlb)
|
|
|
|
{
|
|
|
|
g_assert(bcontainer->ops->dma_unmap);
|
|
|
|
return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb);
|
|
|
|
}
|
2023-11-02 10:12:30 +03:00
|
|
|
|
2023-11-02 10:12:43 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-11-02 10:12:33 +03:00
|
|
|
int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer,
|
|
|
|
bool start)
|
|
|
|
{
|
2023-11-21 11:44:04 +03:00
|
|
|
if (!bcontainer->dirty_pages_supported) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-11-02 10:12:33 +03:00
|
|
|
g_assert(bcontainer->ops->set_dirty_page_tracking);
|
|
|
|
return bcontainer->ops->set_dirty_page_tracking(bcontainer, start);
|
|
|
|
}
|
|
|
|
|
2023-11-21 11:44:17 +03:00
|
|
|
int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
|
2023-11-02 10:12:33 +03:00
|
|
|
VFIOBitmap *vbmap,
|
|
|
|
hwaddr iova, hwaddr size)
|
|
|
|
{
|
|
|
|
g_assert(bcontainer->ops->query_dirty_bitmap);
|
|
|
|
return bcontainer->ops->query_dirty_bitmap(bcontainer, vbmap, iova, size);
|
|
|
|
}
|
|
|
|
|
2023-11-02 10:12:32 +03:00
|
|
|
void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,
|
2023-12-19 09:58:19 +03:00
|
|
|
const VFIOIOMMUClass *ops)
|
2023-11-02 10:12:30 +03:00
|
|
|
{
|
|
|
|
bcontainer->ops = ops;
|
2023-11-02 10:12:32 +03:00
|
|
|
bcontainer->space = space;
|
2023-11-02 10:12:38 +03:00
|
|
|
bcontainer->error = NULL;
|
2023-11-02 10:12:33 +03:00
|
|
|
bcontainer->dirty_pages_supported = false;
|
2023-11-02 10:12:36 +03:00
|
|
|
bcontainer->dma_max_mappings = 0;
|
2023-11-02 10:12:40 +03:00
|
|
|
bcontainer->iova_ranges = NULL;
|
2023-11-02 10:12:31 +03:00
|
|
|
QLIST_INIT(&bcontainer->giommu_list);
|
2023-11-02 10:12:37 +03:00
|
|
|
QLIST_INIT(&bcontainer->vrdl_list);
|
2023-11-02 10:12:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void vfio_container_destroy(VFIOContainerBase *bcontainer)
|
|
|
|
{
|
2023-11-02 10:12:31 +03:00
|
|
|
VFIOGuestIOMMU *giommu, *tmp;
|
|
|
|
|
2023-11-02 10:12:32 +03:00
|
|
|
QLIST_REMOVE(bcontainer, next);
|
|
|
|
|
2023-11-02 10:12:31 +03:00
|
|
|
QLIST_FOREACH_SAFE(giommu, &bcontainer->giommu_list, giommu_next, tmp) {
|
|
|
|
memory_region_unregister_iommu_notifier(
|
|
|
|
MEMORY_REGION(giommu->iommu_mr), &giommu->n);
|
|
|
|
QLIST_REMOVE(giommu, giommu_next);
|
|
|
|
g_free(giommu);
|
|
|
|
}
|
2023-11-02 10:12:40 +03:00
|
|
|
|
|
|
|
g_list_free_full(bcontainer->iova_ranges, g_free);
|
2023-11-02 10:12:30 +03:00
|
|
|
}
|
2023-12-19 09:58:19 +03:00
|
|
|
|
|
|
|
static const TypeInfo types[] = {
|
|
|
|
{
|
|
|
|
.name = TYPE_VFIO_IOMMU,
|
|
|
|
.parent = TYPE_INTERFACE,
|
|
|
|
.class_size = sizeof(VFIOIOMMUClass),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TYPES(types)
|