2 * vfio based device assignment support - PCI devices
4 * Copyright Red Hat, Inc. 2012-2015
7 * Alex Williamson <alex.williamson@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 #ifndef HW_VFIO_VFIO_PCI_H
13 #define HW_VFIO_VFIO_PCI_H
15 #include "qemu-common.h"
16 #include "exec/memory.h"
17 #include "hw/pci/pci.h"
18 #include "hw/vfio/vfio-common.h"
19 #include "qemu/event_notifier.h"
20 #include "qemu/queue.h"
21 #include "qemu/timer.h"
23 #define PCI_ANY_ID (~0)
27 typedef struct VFIOIOEventFD
{
28 QLIST_ENTRY(VFIOIOEventFD
) next
;
36 bool dynamic
; /* Added runtime, removed on device reset */
40 typedef struct VFIOQuirk
{
41 QLIST_ENTRY(VFIOQuirk
) next
;
43 QLIST_HEAD(, VFIOIOEventFD
) ioeventfds
;
46 void (*reset
)(struct VFIOPCIDevice
*vdev
, struct VFIOQuirk
*quirk
);
49 typedef struct VFIOBAR
{
56 QLIST_HEAD(, VFIOQuirk
) quirks
;
59 typedef struct VFIOVGARegion
{
63 QLIST_HEAD(, VFIOQuirk
) quirks
;
66 typedef struct VFIOVGA
{
69 VFIOVGARegion region
[QEMU_PCI_VGA_NUM_REGIONS
];
72 typedef struct VFIOINTx
{
73 bool pending
; /* interrupt pending */
74 bool kvm_accel
; /* set when QEMU bypass through KVM enabled */
75 uint8_t pin
; /* which pin to pull for qemu_set_irq */
76 EventNotifier interrupt
; /* eventfd triggered on interrupt */
77 EventNotifier unmask
; /* eventfd for unmask on QEMU bypass */
78 PCIINTxRoute route
; /* routing info for QEMU bypass */
79 uint32_t mmap_timeout
; /* delay to re-enable mmaps after interrupt */
80 QEMUTimer
*mmap_timer
; /* enable mmaps after periods w/o interrupts */
83 typedef struct VFIOMSIVector
{
85 * Two interrupt paths are configured per vector. The first, is only used
86 * for interrupts injected via QEMU. This is typically the non-accel path,
87 * but may also be used when we want QEMU to handle masking and pending
88 * bits. The KVM path bypasses QEMU and is therefore higher performance,
89 * but requires masking at the device. virq is used to track the MSI route
90 * through KVM, thus kvm_interrupt is only available when virq is set to a
93 EventNotifier interrupt
;
94 EventNotifier kvm_interrupt
;
95 struct VFIOPCIDevice
*vdev
; /* back pointer to device */
107 /* Cache of MSI-X setup */
108 typedef struct VFIOMSIXInfo
{
112 uint32_t table_offset
;
114 unsigned long *pending
;
117 typedef struct VFIOPCIDevice
{
121 unsigned int config_size
;
122 uint8_t *emulated_config_bits
; /* QEMU emulated bits, little-endian */
123 off_t config_offset
; /* Offset of config space region within device fd */
124 unsigned int rom_size
;
125 off_t rom_offset
; /* Offset of ROM region within device fd */
128 VFIOMSIVector
*msi_vectors
;
130 int nr_vectors
; /* Number of MSI/MSIX vectors currently in use */
131 int interrupt
; /* Current interrupt type */
132 VFIOBAR bars
[PCI_NUM_REGIONS
- 1]; /* No ROM */
133 VFIOVGA
*vga
; /* 0xa0000, 0x3b0, 0x3c0 */
135 PCIHostDeviceAddress host
;
136 EventNotifier err_notifier
;
137 EventNotifier req_notifier
;
138 int (*resetfn
)(struct VFIOPCIDevice
*);
141 uint32_t sub_vendor_id
;
142 uint32_t sub_device_id
;
144 #define VFIO_FEATURE_ENABLE_VGA_BIT 0
145 #define VFIO_FEATURE_ENABLE_VGA (1 << VFIO_FEATURE_ENABLE_VGA_BIT)
146 #define VFIO_FEATURE_ENABLE_REQ_BIT 1
147 #define VFIO_FEATURE_ENABLE_REQ (1 << VFIO_FEATURE_ENABLE_REQ_BIT)
148 #define VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT 2
149 #define VFIO_FEATURE_ENABLE_IGD_OPREGION \
150 (1 << VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT)
152 uint32_t display_xres
;
153 uint32_t display_yres
;
156 OffAutoPCIBAR msix_relo
;
158 uint8_t nv_gpudirect_clique
;
163 bool rom_read_failed
;
167 bool no_geforce_quirks
;
168 bool no_kvm_ioeventfd
;
169 bool no_vfio_ioeventfd
;
174 uint32_t vfio_pci_read_config(PCIDevice
*pdev
, uint32_t addr
, int len
);
175 void vfio_pci_write_config(PCIDevice
*pdev
,
176 uint32_t addr
, uint32_t val
, int len
);
178 uint64_t vfio_vga_read(void *opaque
, hwaddr addr
, unsigned size
);
179 void vfio_vga_write(void *opaque
, hwaddr addr
, uint64_t data
, unsigned size
);
181 bool vfio_blacklist_opt_rom(VFIOPCIDevice
*vdev
);
182 void vfio_vga_quirk_setup(VFIOPCIDevice
*vdev
);
183 void vfio_vga_quirk_exit(VFIOPCIDevice
*vdev
);
184 void vfio_vga_quirk_finalize(VFIOPCIDevice
*vdev
);
185 void vfio_bar_quirk_setup(VFIOPCIDevice
*vdev
, int nr
);
186 void vfio_bar_quirk_exit(VFIOPCIDevice
*vdev
, int nr
);
187 void vfio_bar_quirk_finalize(VFIOPCIDevice
*vdev
, int nr
);
188 void vfio_setup_resetfn_quirk(VFIOPCIDevice
*vdev
);
189 int vfio_add_virt_caps(VFIOPCIDevice
*vdev
, Error
**errp
);
190 void vfio_quirk_reset(VFIOPCIDevice
*vdev
);
192 extern const PropertyInfo qdev_prop_nv_gpudirect_clique
;
194 int vfio_populate_vga(VFIOPCIDevice
*vdev
, Error
**errp
);
196 int vfio_pci_igd_opregion_init(VFIOPCIDevice
*vdev
,
197 struct vfio_region_info
*info
,
200 void vfio_display_reset(VFIOPCIDevice
*vdev
);
201 int vfio_display_probe(VFIOPCIDevice
*vdev
, Error
**errp
);
202 void vfio_display_finalize(VFIOPCIDevice
*vdev
);
204 #endif /* HW_VFIO_VFIO_PCI_H */