xref: /openbmc/qemu/hw/vfio/container-base.c (revision dddf83ab)
1b08501a9SEric Auger /*
2b08501a9SEric Auger  * VFIO BASE CONTAINER
3b08501a9SEric Auger  *
4b08501a9SEric Auger  * Copyright (C) 2023 Intel Corporation.
5b08501a9SEric Auger  * Copyright Red Hat, Inc. 2023
6b08501a9SEric Auger  *
7b08501a9SEric Auger  * Authors: Yi Liu <yi.l.liu@intel.com>
8b08501a9SEric Auger  *          Eric Auger <eric.auger@redhat.com>
9b08501a9SEric Auger  *
10b08501a9SEric Auger  * SPDX-License-Identifier: GPL-2.0-or-later
11b08501a9SEric Auger  */
12b08501a9SEric Auger 
13b08501a9SEric Auger #include "qemu/osdep.h"
14b08501a9SEric Auger #include "qapi/error.h"
15b08501a9SEric Auger #include "qemu/error-report.h"
16b08501a9SEric Auger #include "hw/vfio/vfio-container-base.h"
17b08501a9SEric Auger 
18b08501a9SEric Auger int vfio_container_dma_map(VFIOContainerBase *bcontainer,
19b08501a9SEric Auger                            hwaddr iova, ram_addr_t size,
20b08501a9SEric Auger                            void *vaddr, bool readonly)
21b08501a9SEric Auger {
22b08501a9SEric Auger     g_assert(bcontainer->ops->dma_map);
23b08501a9SEric Auger     return bcontainer->ops->dma_map(bcontainer, iova, size, vaddr, readonly);
24b08501a9SEric Auger }
25b08501a9SEric Auger 
26b08501a9SEric Auger int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
27b08501a9SEric Auger                              hwaddr iova, ram_addr_t size,
28b08501a9SEric Auger                              IOMMUTLBEntry *iotlb)
29b08501a9SEric Auger {
30b08501a9SEric Auger     g_assert(bcontainer->ops->dma_unmap);
31b08501a9SEric Auger     return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb);
32b08501a9SEric Auger }
33ed2f7f80SZhenzhong Duan 
34ed2f7f80SZhenzhong Duan void vfio_container_init(VFIOContainerBase *bcontainer, const VFIOIOMMUOps *ops)
35ed2f7f80SZhenzhong Duan {
36ed2f7f80SZhenzhong Duan     bcontainer->ops = ops;
37*dddf83abSEric Auger     QLIST_INIT(&bcontainer->giommu_list);
38ed2f7f80SZhenzhong Duan }
39ed2f7f80SZhenzhong Duan 
40ed2f7f80SZhenzhong Duan void vfio_container_destroy(VFIOContainerBase *bcontainer)
41ed2f7f80SZhenzhong Duan {
42*dddf83abSEric Auger     VFIOGuestIOMMU *giommu, *tmp;
43*dddf83abSEric Auger 
44*dddf83abSEric Auger     QLIST_FOREACH_SAFE(giommu, &bcontainer->giommu_list, giommu_next, tmp) {
45*dddf83abSEric Auger         memory_region_unregister_iommu_notifier(
46*dddf83abSEric Auger                 MEMORY_REGION(giommu->iommu_mr), &giommu->n);
47*dddf83abSEric Auger         QLIST_REMOVE(giommu, giommu_next);
48*dddf83abSEric Auger         g_free(giommu);
49*dddf83abSEric Auger     }
50ed2f7f80SZhenzhong Duan }
51