]> git.proxmox.com Git - mirror_qemu.git/blame - hw/vfio/pci.h
vfio/pci: Cache vendor and device ID
[mirror_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 <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_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
23struct VFIOPCIDevice;
24
8c4f2348
AW
25typedef struct VFIOQuirk {
26 QLIST_ENTRY(VFIOQuirk) next;
27 void *data;
28 int nr_mem;
29 MemoryRegion *mem;
78f33d2b
AW
30} VFIOQuirk;
31
32typedef struct VFIOBAR {
33 VFIORegion region;
34 bool ioport;
35 bool mem64;
36 QLIST_HEAD(, VFIOQuirk) quirks;
37} VFIOBAR;
38
39typedef struct VFIOVGARegion {
40 MemoryRegion mem;
41 off_t offset;
42 int nr;
43 QLIST_HEAD(, VFIOQuirk) quirks;
44} VFIOVGARegion;
45
46typedef struct VFIOVGA {
47 off_t fd_offset;
48 int fd;
49 VFIOVGARegion region[QEMU_PCI_VGA_NUM_REGIONS];
50} VFIOVGA;
51
52typedef struct VFIOINTx {
53 bool pending; /* interrupt pending */
54 bool kvm_accel; /* set when QEMU bypass through KVM enabled */
55 uint8_t pin; /* which pin to pull for qemu_set_irq */
56 EventNotifier interrupt; /* eventfd triggered on interrupt */
57 EventNotifier unmask; /* eventfd for unmask on QEMU bypass */
58 PCIINTxRoute route; /* routing info for QEMU bypass */
59 uint32_t mmap_timeout; /* delay to re-enable mmaps after interrupt */
60 QEMUTimer *mmap_timer; /* enable mmaps after periods w/o interrupts */
61} VFIOINTx;
62
63typedef struct VFIOMSIVector {
64 /*
65 * Two interrupt paths are configured per vector. The first, is only used
66 * for interrupts injected via QEMU. This is typically the non-accel path,
67 * but may also be used when we want QEMU to handle masking and pending
68 * bits. The KVM path bypasses QEMU and is therefore higher performance,
69 * but requires masking at the device. virq is used to track the MSI route
70 * through KVM, thus kvm_interrupt is only available when virq is set to a
71 * valid (>= 0) value.
72 */
73 EventNotifier interrupt;
74 EventNotifier kvm_interrupt;
75 struct VFIOPCIDevice *vdev; /* back pointer to device */
76 int virq;
77 bool use;
78} VFIOMSIVector;
79
80enum {
81 VFIO_INT_NONE = 0,
82 VFIO_INT_INTx = 1,
83 VFIO_INT_MSI = 2,
84 VFIO_INT_MSIX = 3,
85};
86
87/* Cache of MSI-X setup plus extra mmap and memory region for split BAR map */
88typedef struct VFIOMSIXInfo {
89 uint8_t table_bar;
90 uint8_t pba_bar;
91 uint16_t entries;
92 uint32_t table_offset;
93 uint32_t pba_offset;
94 MemoryRegion mmap_mem;
95 void *mmap;
96} VFIOMSIXInfo;
97
98typedef struct VFIOPCIDevice {
99 PCIDevice pdev;
100 VFIODevice vbasedev;
101 VFIOINTx intx;
102 unsigned int config_size;
103 uint8_t *emulated_config_bits; /* QEMU emulated bits, little-endian */
104 off_t config_offset; /* Offset of config space region within device fd */
105 unsigned int rom_size;
106 off_t rom_offset; /* Offset of ROM region within device fd */
107 void *rom;
108 int msi_cap_size;
109 VFIOMSIVector *msi_vectors;
110 VFIOMSIXInfo *msix;
111 int nr_vectors; /* Number of MSI/MSIX vectors currently in use */
112 int interrupt; /* Current interrupt type */
113 VFIOBAR bars[PCI_NUM_REGIONS - 1]; /* No ROM */
114 VFIOVGA vga; /* 0xa0000, 0x3b0, 0x3c0 */
115 PCIHostDeviceAddress host;
116 EventNotifier err_notifier;
117 EventNotifier req_notifier;
118 int (*resetfn)(struct VFIOPCIDevice *);
ff635e37
AW
119 uint16_t vendor_id;
120 uint16_t device_id;
78f33d2b
AW
121 uint32_t features;
122#define VFIO_FEATURE_ENABLE_VGA_BIT 0
123#define VFIO_FEATURE_ENABLE_VGA (1 << VFIO_FEATURE_ENABLE_VGA_BIT)
124#define VFIO_FEATURE_ENABLE_REQ_BIT 1
125#define VFIO_FEATURE_ENABLE_REQ (1 << VFIO_FEATURE_ENABLE_REQ_BIT)
126 int32_t bootindex;
127 uint8_t pm_cap;
128 bool has_vga;
129 bool pci_aer;
130 bool req_enabled;
131 bool has_flr;
132 bool has_pm_reset;
133 bool rom_read_failed;
134 bool no_kvm_intx;
135 bool no_kvm_msi;
136 bool no_kvm_msix;
137} VFIOPCIDevice;
138
c00d61d8
AW
139uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len);
140void vfio_pci_write_config(PCIDevice *pdev,
141 uint32_t addr, uint32_t val, int len);
142
143uint64_t vfio_vga_read(void *opaque, hwaddr addr, unsigned size);
144void vfio_vga_write(void *opaque, hwaddr addr, uint64_t data, unsigned size);
145
146bool vfio_blacklist_opt_rom(VFIOPCIDevice *vdev);
147void vfio_vga_quirk_setup(VFIOPCIDevice *vdev);
148void vfio_vga_quirk_teardown(VFIOPCIDevice *vdev);
149void vfio_vga_quirk_free(VFIOPCIDevice *vdev);
150void vfio_bar_quirk_setup(VFIOPCIDevice *vdev, int nr);
151void vfio_bar_quirk_teardown(VFIOPCIDevice *vdev, int nr);
152void vfio_bar_quirk_free(VFIOPCIDevice *vdev, int nr);
c9c50009 153void vfio_setup_resetfn_quirk(VFIOPCIDevice *vdev);
c00d61d8 154
78f33d2b 155#endif /* HW_VFIO_VFIO_PCI_H */