xref: /openbmc/qemu/hw/vfio/container-base.c (revision c7b313d3)
1 /*
2  * VFIO BASE CONTAINER
3  *
4  * Copyright (C) 2023 Intel Corporation.
5  * Copyright Red Hat, Inc. 2023
6  *
7  * Authors: Yi Liu <yi.l.liu@intel.com>
8  *          Eric Auger <eric.auger@redhat.com>
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  */
12 
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "qemu/error-report.h"
16 #include "hw/vfio/vfio-container-base.h"
17 
18 int vfio_container_dma_map(VFIOContainerBase *bcontainer,
19                            hwaddr iova, ram_addr_t size,
20                            void *vaddr, bool readonly)
21 {
22     g_assert(bcontainer->ops->dma_map);
23     return bcontainer->ops->dma_map(bcontainer, iova, size, vaddr, readonly);
24 }
25 
26 int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
27                              hwaddr iova, ram_addr_t size,
28                              IOMMUTLBEntry *iotlb)
29 {
30     g_assert(bcontainer->ops->dma_unmap);
31     return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb);
32 }
33 
34 int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer,
35                                            bool start)
36 {
37     g_assert(bcontainer->ops->set_dirty_page_tracking);
38     return bcontainer->ops->set_dirty_page_tracking(bcontainer, start);
39 }
40 
41 int vfio_container_query_dirty_bitmap(VFIOContainerBase *bcontainer,
42                                       VFIOBitmap *vbmap,
43                                       hwaddr iova, hwaddr size)
44 {
45     g_assert(bcontainer->ops->query_dirty_bitmap);
46     return bcontainer->ops->query_dirty_bitmap(bcontainer, vbmap, iova, size);
47 }
48 
49 void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space,
50                          const VFIOIOMMUOps *ops)
51 {
52     bcontainer->ops = ops;
53     bcontainer->space = space;
54     bcontainer->error = NULL;
55     bcontainer->dirty_pages_supported = false;
56     bcontainer->dma_max_mappings = 0;
57     QLIST_INIT(&bcontainer->giommu_list);
58     QLIST_INIT(&bcontainer->vrdl_list);
59 }
60 
61 void vfio_container_destroy(VFIOContainerBase *bcontainer)
62 {
63     VFIOGuestIOMMU *giommu, *tmp;
64 
65     QLIST_REMOVE(bcontainer, next);
66 
67     QLIST_FOREACH_SAFE(giommu, &bcontainer->giommu_list, giommu_next, tmp) {
68         memory_region_unregister_iommu_notifier(
69                 MEMORY_REGION(giommu->iommu_mr), &giommu->n);
70         QLIST_REMOVE(giommu, giommu_next);
71         g_free(giommu);
72     }
73 }
74