4 * Copyright (C) 2023 Intel Corporation.
5 * Copyright Red Hat, Inc. 2023
7 * Authors: Yi Liu <yi.l.liu@intel.com>
8 * Eric Auger <eric.auger@redhat.com>
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #ifndef HW_VFIO_VFIO_CONTAINER_BASE_H
14 #define HW_VFIO_VFIO_CONTAINER_BASE_H
16 #include "exec/memory.h"
18 typedef struct VFIODevice VFIODevice
;
19 typedef struct VFIOIOMMUOps VFIOIOMMUOps
;
22 unsigned long *bitmap
;
27 typedef struct VFIOAddressSpace
{
29 QLIST_HEAD(, VFIOContainerBase
) containers
;
30 QLIST_ENTRY(VFIOAddressSpace
) list
;
34 * This is the base object for vfio container backends
36 typedef struct VFIOContainerBase
{
37 const VFIOIOMMUOps
*ops
;
38 VFIOAddressSpace
*space
;
39 bool dirty_pages_supported
;
40 QLIST_HEAD(, VFIOGuestIOMMU
) giommu_list
;
41 QLIST_ENTRY(VFIOContainerBase
) next
;
42 QLIST_HEAD(, VFIODevice
) device_list
;
45 typedef struct VFIOGuestIOMMU
{
46 VFIOContainerBase
*bcontainer
;
47 IOMMUMemoryRegion
*iommu_mr
;
50 QLIST_ENTRY(VFIOGuestIOMMU
) giommu_next
;
53 int vfio_container_dma_map(VFIOContainerBase
*bcontainer
,
54 hwaddr iova
, ram_addr_t size
,
55 void *vaddr
, bool readonly
);
56 int vfio_container_dma_unmap(VFIOContainerBase
*bcontainer
,
57 hwaddr iova
, ram_addr_t size
,
58 IOMMUTLBEntry
*iotlb
);
59 int vfio_container_set_dirty_page_tracking(VFIOContainerBase
*bcontainer
,
61 int vfio_container_query_dirty_bitmap(VFIOContainerBase
*bcontainer
,
63 hwaddr iova
, hwaddr size
);
65 void vfio_container_init(VFIOContainerBase
*bcontainer
,
66 VFIOAddressSpace
*space
,
67 const VFIOIOMMUOps
*ops
);
68 void vfio_container_destroy(VFIOContainerBase
*bcontainer
);
72 int (*dma_map
)(VFIOContainerBase
*bcontainer
,
73 hwaddr iova
, ram_addr_t size
,
74 void *vaddr
, bool readonly
);
75 int (*dma_unmap
)(VFIOContainerBase
*bcontainer
,
76 hwaddr iova
, ram_addr_t size
,
77 IOMMUTLBEntry
*iotlb
);
78 int (*attach_device
)(const char *name
, VFIODevice
*vbasedev
,
79 AddressSpace
*as
, Error
**errp
);
80 void (*detach_device
)(VFIODevice
*vbasedev
);
81 /* migration feature */
82 int (*set_dirty_page_tracking
)(VFIOContainerBase
*bcontainer
, bool start
);
83 int (*query_dirty_bitmap
)(VFIOContainerBase
*bcontainer
, VFIOBitmap
*vbmap
,
84 hwaddr iova
, hwaddr size
);
86 #endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */