xref: /qemu/include/hw/vfio/vfio-region.h (revision 090c9641882da217e40936c98742749e4cc94130)
1 /*
2  * VFIO region
3  *
4  * Copyright Red Hat, Inc. 2025
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #ifndef HW_VFIO_REGION_H
10 #define HW_VFIO_REGION_H
11 
12 #include "system/memory.h"
13 
14 typedef struct VFIOMmap {
15     MemoryRegion mem;
16     void *mmap;
17     off_t offset;
18     size_t size;
19 } VFIOMmap;
20 
21 typedef struct VFIODevice VFIODevice;
22 
23 typedef struct VFIORegion {
24     struct VFIODevice *vbasedev;
25     off_t fd_offset; /* offset of region within device fd */
26     MemoryRegion *mem; /* slow, read/write access */
27     size_t size;
28     uint32_t flags; /* VFIO region flags (rd/wr/mmap) */
29     uint32_t nr_mmaps;
30     VFIOMmap *mmaps;
31     uint8_t nr; /* cache the region number for debug */
32 } VFIORegion;
33 
34 
35 void vfio_region_write(void *opaque, hwaddr addr,
36                            uint64_t data, unsigned size);
37 uint64_t vfio_region_read(void *opaque,
38                           hwaddr addr, unsigned size);
39 int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region,
40                       int index, const char *name);
41 int vfio_region_mmap(VFIORegion *region);
42 void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled);
43 void vfio_region_unmap(VFIORegion *region);
44 void vfio_region_exit(VFIORegion *region);
45 void vfio_region_finalize(VFIORegion *region);
46 
47 #endif /* HW_VFIO_REGION_H */
48