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 VFIOQuirk
{
28 QLIST_ENTRY(VFIOQuirk
) next
;
34 typedef struct VFIOBAR
{
38 QLIST_HEAD(, VFIOQuirk
) quirks
;
41 typedef struct VFIOVGARegion
{
45 QLIST_HEAD(, VFIOQuirk
) quirks
;
48 typedef struct VFIOVGA
{
51 VFIOVGARegion region
[QEMU_PCI_VGA_NUM_REGIONS
];
54 typedef struct VFIOINTx
{
55 bool pending
; /* interrupt pending */
56 bool kvm_accel
; /* set when QEMU bypass through KVM enabled */
57 uint8_t pin
; /* which pin to pull for qemu_set_irq */
58 EventNotifier interrupt
; /* eventfd triggered on interrupt */
59 EventNotifier unmask
; /* eventfd for unmask on QEMU bypass */
60 PCIINTxRoute route
; /* routing info for QEMU bypass */
61 uint32_t mmap_timeout
; /* delay to re-enable mmaps after interrupt */
62 QEMUTimer
*mmap_timer
; /* enable mmaps after periods w/o interrupts */
65 typedef struct VFIOMSIVector
{
67 * Two interrupt paths are configured per vector. The first, is only used
68 * for interrupts injected via QEMU. This is typically the non-accel path,
69 * but may also be used when we want QEMU to handle masking and pending
70 * bits. The KVM path bypasses QEMU and is therefore higher performance,
71 * but requires masking at the device. virq is used to track the MSI route
72 * through KVM, thus kvm_interrupt is only available when virq is set to a
75 EventNotifier interrupt
;
76 EventNotifier kvm_interrupt
;
77 struct VFIOPCIDevice
*vdev
; /* back pointer to device */
89 /* Cache of MSI-X setup plus extra mmap and memory region for split BAR map */
90 typedef struct VFIOMSIXInfo
{
94 uint32_t table_offset
;
96 MemoryRegion mmap_mem
;
98 unsigned long *pending
;
101 typedef struct VFIOPCIDevice
{
105 unsigned int config_size
;
106 uint8_t *emulated_config_bits
; /* QEMU emulated bits, little-endian */
107 off_t config_offset
; /* Offset of config space region within device fd */
108 unsigned int rom_size
;
109 off_t rom_offset
; /* Offset of ROM region within device fd */
112 VFIOMSIVector
*msi_vectors
;
114 int nr_vectors
; /* Number of MSI/MSIX vectors currently in use */
115 int interrupt
; /* Current interrupt type */
116 VFIOBAR bars
[PCI_NUM_REGIONS
- 1]; /* No ROM */
117 VFIOVGA
*vga
; /* 0xa0000, 0x3b0, 0x3c0 */
119 PCIHostDeviceAddress host
;
120 EventNotifier err_notifier
;
121 EventNotifier req_notifier
;
122 int (*resetfn
)(struct VFIOPCIDevice
*);
125 uint32_t sub_vendor_id
;
126 uint32_t sub_device_id
;
128 #define VFIO_FEATURE_ENABLE_VGA_BIT 0
129 #define VFIO_FEATURE_ENABLE_VGA (1 << VFIO_FEATURE_ENABLE_VGA_BIT)
130 #define VFIO_FEATURE_ENABLE_REQ_BIT 1
131 #define VFIO_FEATURE_ENABLE_REQ (1 << VFIO_FEATURE_ENABLE_REQ_BIT)
132 #define VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT 2
133 #define VFIO_FEATURE_ENABLE_IGD_OPREGION \
134 (1 << VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT)
143 bool rom_read_failed
;
149 uint32_t vfio_pci_read_config(PCIDevice
*pdev
, uint32_t addr
, int len
);
150 void vfio_pci_write_config(PCIDevice
*pdev
,
151 uint32_t addr
, uint32_t val
, int len
);
153 uint64_t vfio_vga_read(void *opaque
, hwaddr addr
, unsigned size
);
154 void vfio_vga_write(void *opaque
, hwaddr addr
, uint64_t data
, unsigned size
);
156 bool vfio_blacklist_opt_rom(VFIOPCIDevice
*vdev
);
157 void vfio_vga_quirk_setup(VFIOPCIDevice
*vdev
);
158 void vfio_vga_quirk_exit(VFIOPCIDevice
*vdev
);
159 void vfio_vga_quirk_finalize(VFIOPCIDevice
*vdev
);
160 void vfio_bar_quirk_setup(VFIOPCIDevice
*vdev
, int nr
);
161 void vfio_bar_quirk_exit(VFIOPCIDevice
*vdev
, int nr
);
162 void vfio_bar_quirk_finalize(VFIOPCIDevice
*vdev
, int nr
);
163 void vfio_setup_resetfn_quirk(VFIOPCIDevice
*vdev
);
165 int vfio_populate_vga(VFIOPCIDevice
*vdev
);
167 int vfio_pci_igd_opregion_init(VFIOPCIDevice
*vdev
,
168 struct vfio_region_info
*info
);
170 #endif /* HW_VFIO_VFIO_PCI_H */