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 void vfio_container_init(VFIOContainerBase *bcontainer,
42                          const VFIOIOMMUOps *ops);
43 void vfio_container_destroy(VFIOContainerBase *bcontainer);
44 
45 struct VFIOIOMMUOps {
46     /* basic feature */
47     int (*dma_map)(VFIOContainerBase *bcontainer,
48                    hwaddr iova, ram_addr_t size,
49                    void *vaddr, bool readonly);
50     int (*dma_unmap)(VFIOContainerBase *bcontainer,
51                      hwaddr iova, ram_addr_t size,
52                      IOMMUTLBEntry *iotlb);
53     int (*attach_device)(const char *name, VFIODevice *vbasedev,
54                          AddressSpace *as, Error **errp);
55     void (*detach_device)(VFIODevice *vbasedev);
56     /* migration feature */
57     int (*set_dirty_page_tracking)(VFIOContainerBase *bcontainer, bool start);
58     int (*query_dirty_bitmap)(VFIOContainerBase *bcontainer, VFIOBitmap *vbmap,
59                               hwaddr iova, hwaddr size);
60 };
61 #endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */
62