]> Git Repo - qemu.git/blame - hw/vfio/pci.h
Merge remote-tracking branch 'remotes/edgar/tags/edgar/xilinx-next-2018-06-15.for...
[qemu.git] / hw / vfio / pci.h
CommitLineData
78f33d2b
AW
1/*
2 * vfio based device assignment support - PCI devices
3 *
4 * Copyright Red Hat, Inc. 2012-2015
5 *
6 * Authors:
7 * Alex Williamson <[email protected]>
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_H
13#define HW_VFIO_VFIO_PCI_H
14
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"
22
89dcccc5
AW
23#define PCI_ANY_ID (~0)
24
78f33d2b
AW
25struct VFIOPCIDevice;
26
c958c51d
AW
27typedef struct VFIOIOEventFD {
28 QLIST_ENTRY(VFIOIOEventFD) next;
29 MemoryRegion *mr;
30 hwaddr addr;
31 unsigned size;
32 uint64_t data;
33 EventNotifier e;
34 VFIORegion *region;
35 hwaddr region_addr;
36 bool dynamic; /* Added runtime, removed on device reset */
2b1dbd0d 37 bool vfio;
c958c51d
AW
38} VFIOIOEventFD;
39
8c4f2348
AW
40typedef struct VFIOQuirk {
41 QLIST_ENTRY(VFIOQuirk) next;
42 void *data;
c958c51d 43 QLIST_HEAD(, VFIOIOEventFD) ioeventfds;
8c4f2348
AW
44 int nr_mem;
45 MemoryRegion *mem;
469d02de 46 void (*reset)(struct VFIOPCIDevice *vdev, struct VFIOQuirk *quirk);
78f33d2b
AW
47} VFIOQuirk;
48
49typedef struct VFIOBAR {
50 VFIORegion region;
3a286732
AW
51 MemoryRegion *mr;
52 size_t size;
53 uint8_t type;
78f33d2b
AW
54 bool ioport;
55 bool mem64;
56 QLIST_HEAD(, VFIOQuirk) quirks;
57} VFIOBAR;
58
59typedef struct VFIOVGARegion {
60 MemoryRegion mem;
61 off_t offset;
62 int nr;
63 QLIST_HEAD(, VFIOQuirk) quirks;
64} VFIOVGARegion;
65
66typedef struct VFIOVGA {
67 off_t fd_offset;
68 int fd;
69 VFIOVGARegion region[QEMU_PCI_VGA_NUM_REGIONS];
70} VFIOVGA;
71
72typedef 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 */
81} VFIOINTx;
82
83typedef struct VFIOMSIVector {
84 /*
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
91 * valid (>= 0) value.
92 */
93 EventNotifier interrupt;
94 EventNotifier kvm_interrupt;
95 struct VFIOPCIDevice *vdev; /* back pointer to device */
96 int virq;
97 bool use;
98} VFIOMSIVector;
99
100enum {
101 VFIO_INT_NONE = 0,
102 VFIO_INT_INTx = 1,
103 VFIO_INT_MSI = 2,
104 VFIO_INT_MSIX = 3,
105};
106
edd09278 107/* Cache of MSI-X setup */
78f33d2b
AW
108typedef struct VFIOMSIXInfo {
109 uint8_t table_bar;
110 uint8_t pba_bar;
111 uint16_t entries;
112 uint32_t table_offset;
113 uint32_t pba_offset;
95239e16 114 unsigned long *pending;
78f33d2b
AW
115} VFIOMSIXInfo;
116
117typedef struct VFIOPCIDevice {
118 PCIDevice pdev;
119 VFIODevice vbasedev;
120 VFIOINTx intx;
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 */
126 void *rom;
127 int msi_cap_size;
128 VFIOMSIVector *msi_vectors;
129 VFIOMSIXInfo *msix;
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 */
2d82f8a3 133 VFIOVGA *vga; /* 0xa0000, 0x3b0, 0x3c0 */
c4c45e94 134 void *igd_opregion;
78f33d2b
AW
135 PCIHostDeviceAddress host;
136 EventNotifier err_notifier;
137 EventNotifier req_notifier;
138 int (*resetfn)(struct VFIOPCIDevice *);
89dcccc5
AW
139 uint32_t vendor_id;
140 uint32_t device_id;
141 uint32_t sub_vendor_id;
142 uint32_t sub_device_id;
78f33d2b
AW
143 uint32_t features;
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)
6ced0bba
AW
148#define VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT 2
149#define VFIO_FEATURE_ENABLE_IGD_OPREGION \
150 (1 << VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT)
a9994687 151 OnOffAuto display;
78f33d2b 152 int32_t bootindex;
c4c45e94 153 uint32_t igd_gms;
89d5202e 154 OffAutoPCIBAR msix_relo;
78f33d2b 155 uint8_t pm_cap;
dfbee78d 156 uint8_t nv_gpudirect_clique;
78f33d2b
AW
157 bool pci_aer;
158 bool req_enabled;
159 bool has_flr;
160 bool has_pm_reset;
161 bool rom_read_failed;
162 bool no_kvm_intx;
163 bool no_kvm_msi;
164 bool no_kvm_msix;
db32d0f4 165 bool no_geforce_quirks;
c958c51d 166 bool no_kvm_ioeventfd;
2b1dbd0d 167 bool no_vfio_ioeventfd;
00195ba7 168 VFIODisplay *dpy;
78f33d2b
AW
169} VFIOPCIDevice;
170
c00d61d8
AW
171uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len);
172void vfio_pci_write_config(PCIDevice *pdev,
173 uint32_t addr, uint32_t val, int len);
174
175uint64_t vfio_vga_read(void *opaque, hwaddr addr, unsigned size);
176void vfio_vga_write(void *opaque, hwaddr addr, uint64_t data, unsigned size);
177
178bool vfio_blacklist_opt_rom(VFIOPCIDevice *vdev);
179void vfio_vga_quirk_setup(VFIOPCIDevice *vdev);
2d82f8a3
AW
180void vfio_vga_quirk_exit(VFIOPCIDevice *vdev);
181void vfio_vga_quirk_finalize(VFIOPCIDevice *vdev);
c00d61d8 182void vfio_bar_quirk_setup(VFIOPCIDevice *vdev, int nr);
2d82f8a3
AW
183void vfio_bar_quirk_exit(VFIOPCIDevice *vdev, int nr);
184void vfio_bar_quirk_finalize(VFIOPCIDevice *vdev, int nr);
c9c50009 185void vfio_setup_resetfn_quirk(VFIOPCIDevice *vdev);
e3f79f3b 186int vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp);
469d02de 187void vfio_quirk_reset(VFIOPCIDevice *vdev);
c00d61d8 188
dfbee78d
AW
189extern const PropertyInfo qdev_prop_nv_gpudirect_clique;
190
cde4279b 191int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp);
e593c021 192
6ced0bba 193int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
7237011d
EA
194 struct vfio_region_info *info,
195 Error **errp);
6ced0bba 196
8983e3e3 197void vfio_display_reset(VFIOPCIDevice *vdev);
a9994687
GH
198int vfio_display_probe(VFIOPCIDevice *vdev, Error **errp);
199void vfio_display_finalize(VFIOPCIDevice *vdev);
200
78f33d2b 201#endif /* HW_VFIO_VFIO_PCI_H */
This page took 0.176167 seconds and 4 git commands to generate.