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