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 #ifndef HW_VFIO_VFIO_CONTAINER_BASE_H
14 #define HW_VFIO_VFIO_CONTAINER_BASE_H
15 
16 #include "exec/memory.h"
17 
18 typedef struct VFIODevice VFIODevice;
19 typedef struct VFIOIOMMUOps VFIOIOMMUOps;
20 
21 typedef struct {
22     unsigned long *bitmap;
23     hwaddr size;
24     hwaddr pages;
25 } VFIOBitmap;
26 
27 /*
28  * This is the base object for vfio container backends
29  */
30 typedef struct VFIOContainerBase {
31     const VFIOIOMMUOps *ops;
32 } VFIOContainerBase;
33 
34 int vfio_container_dma_map(VFIOContainerBase *bcontainer,
35                            hwaddr iova, ram_addr_t size,
36                            void *vaddr, bool readonly);
37 int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
38                              hwaddr iova, ram_addr_t size,
39                              IOMMUTLBEntry *iotlb);
40 
41 struct VFIOIOMMUOps {
42     /* basic feature */
43     int (*dma_map)(VFIOContainerBase *bcontainer,
44                    hwaddr iova, ram_addr_t size,
45                    void *vaddr, bool readonly);
46     int (*dma_unmap)(VFIOContainerBase *bcontainer,
47                      hwaddr iova, ram_addr_t size,
48                      IOMMUTLBEntry *iotlb);
49     int (*attach_device)(const char *name, VFIODevice *vbasedev,
50                          AddressSpace *as, Error **errp);
51     void (*detach_device)(VFIODevice *vbasedev);
52     /* migration feature */
53     int (*set_dirty_page_tracking)(VFIOContainerBase *bcontainer, bool start);
54     int (*query_dirty_bitmap)(VFIOContainerBase *bcontainer, VFIOBitmap *vbmap,
55                               hwaddr iova, hwaddr size);
56 };
57 #endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */
58