1 /* 2 * vfio generic region quirks (mostly backdoors to PCI config space) 3 * 4 * Copyright Red Hat, Inc. 2012-2015 5 * 6 * Authors: 7 * Alex Williamson <alex.williamson@redhat.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2. See 10 * the COPYING file in the top-level directory. 11 */ 12 #ifndef HW_VFIO_VFIO_PCI_QUIRKS_H 13 #define HW_VFIO_VFIO_PCI_QUIRKS_H 14 15 #include "qemu/osdep.h" 16 #include "exec/memop.h" 17 18 /* 19 * The generic window quirks operate on an address and data register, 20 * vfio_generic_window_address_quirk handles the address register and 21 * vfio_generic_window_data_quirk handles the data register. These ops 22 * pass reads and writes through to hardware until a value matching the 23 * stored address match/mask is written. When this occurs, the data 24 * register access emulated PCI config space for the device rather than 25 * passing through accesses. This enables devices where PCI config space 26 * is accessible behind a window register to maintain the virtualization 27 * provided through vfio. 28 */ 29 typedef struct VFIOConfigWindowMatch { 30 uint32_t match; 31 uint32_t mask; 32 } VFIOConfigWindowMatch; 33 34 typedef struct VFIOConfigWindowQuirk { 35 struct VFIOPCIDevice *vdev; 36 37 uint32_t address_val; 38 39 uint32_t address_offset; 40 uint32_t data_offset; 41 42 bool window_enabled; 43 uint8_t bar; 44 45 MemoryRegion *addr_mem; 46 MemoryRegion *data_mem; 47 48 uint32_t nr_matches; 49 VFIOConfigWindowMatch matches[]; 50 } VFIOConfigWindowQuirk; 51 52 extern const MemoryRegionOps vfio_generic_window_address_quirk; 53 extern const MemoryRegionOps vfio_generic_window_data_quirk; 54 55 /* 56 * The generic mirror quirk handles devices which expose PCI config space 57 * through a region within a BAR. When enabled, reads and writes are 58 * redirected through to emulated PCI config space. XXX if PCI config space 59 * used memory regions, this could just be an alias. 60 */ 61 typedef struct VFIOConfigMirrorQuirk { 62 struct VFIOPCIDevice *vdev; 63 uint32_t offset; /* Offset in BAR */ 64 uint32_t config_offset; /* Offset in PCI config space */ 65 uint8_t bar; 66 MemoryRegion *mem; 67 uint8_t data[]; 68 } VFIOConfigMirrorQuirk; 69 70 extern const MemoryRegionOps vfio_generic_mirror_quirk; 71 72 #endif /* HW_VFIO_VFIO_PCI_QUIRKS_H */ 73