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 struct VFIOIOMMUOps {
35     /* basic feature */
36     int (*dma_map)(VFIOContainerBase *bcontainer,
37                    hwaddr iova, ram_addr_t size,
38                    void *vaddr, bool readonly);
39     int (*dma_unmap)(VFIOContainerBase *bcontainer,
40                      hwaddr iova, ram_addr_t size,
41                      IOMMUTLBEntry *iotlb);
42     int (*attach_device)(const char *name, VFIODevice *vbasedev,
43                          AddressSpace *as, Error **errp);
44     void (*detach_device)(VFIODevice *vbasedev);
45     /* migration feature */
46     int (*set_dirty_page_tracking)(VFIOContainerBase *bcontainer, bool start);
47     int (*query_dirty_bitmap)(VFIOContainerBase *bcontainer, VFIOBitmap *vbmap,
48                               hwaddr iova, hwaddr size);
49 };
50 #endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */
51