xref: /openbmc/qemu/include/hw/vfio/vfio-region.h (revision d9ce74873a6a5a7c504379857461e4ae64fcf0cd)
1499e53ccSCédric Le Goater /*
2499e53ccSCédric Le Goater  * VFIO region
3499e53ccSCédric Le Goater  *
4499e53ccSCédric Le Goater  * Copyright Red Hat, Inc. 2025
5499e53ccSCédric Le Goater  *
6499e53ccSCédric Le Goater  * SPDX-License-Identifier: GPL-2.0-or-later
7499e53ccSCédric Le Goater  */
8499e53ccSCédric Le Goater 
9499e53ccSCédric Le Goater #ifndef HW_VFIO_REGION_H
10499e53ccSCédric Le Goater #define HW_VFIO_REGION_H
11499e53ccSCédric Le Goater 
12499e53ccSCédric Le Goater #include "system/memory.h"
13499e53ccSCédric Le Goater 
14499e53ccSCédric Le Goater typedef struct VFIOMmap {
15499e53ccSCédric Le Goater     MemoryRegion mem;
16499e53ccSCédric Le Goater     void *mmap;
17499e53ccSCédric Le Goater     off_t offset;
18499e53ccSCédric Le Goater     size_t size;
19499e53ccSCédric Le Goater } VFIOMmap;
20499e53ccSCédric Le Goater 
21499e53ccSCédric Le Goater typedef struct VFIODevice VFIODevice;
22499e53ccSCédric Le Goater 
23499e53ccSCédric Le Goater typedef struct VFIORegion {
24499e53ccSCédric Le Goater     struct VFIODevice *vbasedev;
25499e53ccSCédric Le Goater     off_t fd_offset; /* offset of region within device fd */
26499e53ccSCédric Le Goater     MemoryRegion *mem; /* slow, read/write access */
27499e53ccSCédric Le Goater     size_t size;
28499e53ccSCédric Le Goater     uint32_t flags; /* VFIO region flags (rd/wr/mmap) */
29499e53ccSCédric Le Goater     uint32_t nr_mmaps;
30499e53ccSCédric Le Goater     VFIOMmap *mmaps;
31499e53ccSCédric Le Goater     uint8_t nr; /* cache the region number for debug */
32*a574b061SJohn Levon     bool post_wr; /* writes can be posted */
33499e53ccSCédric Le Goater } VFIORegion;
34499e53ccSCédric Le Goater 
35499e53ccSCédric Le Goater 
36499e53ccSCédric Le Goater void vfio_region_write(void *opaque, hwaddr addr,
37499e53ccSCédric Le Goater                            uint64_t data, unsigned size);
38499e53ccSCédric Le Goater uint64_t vfio_region_read(void *opaque,
39499e53ccSCédric Le Goater                           hwaddr addr, unsigned size);
40499e53ccSCédric Le Goater int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region,
41499e53ccSCédric Le Goater                       int index, const char *name);
42499e53ccSCédric Le Goater int vfio_region_mmap(VFIORegion *region);
43499e53ccSCédric Le Goater void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled);
44499e53ccSCédric Le Goater void vfio_region_unmap(VFIORegion *region);
45499e53ccSCédric Le Goater void vfio_region_exit(VFIORegion *region);
46499e53ccSCédric Le Goater void vfio_region_finalize(VFIORegion *region);
47499e53ccSCédric Le Goater 
48499e53ccSCédric Le Goater #endif /* HW_VFIO_REGION_H */
49