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