virtio-pci: address space translation service (ATS) support
[qemu.git] / hw / virtio / virtio-pci.h
1 /*
2 * Virtio PCI Bindings
3 *
4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
6 *
7 * Authors:
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Paul Brook <paul@codesourcery.com>
10 *
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
13 */
14
15 #ifndef QEMU_VIRTIO_PCI_H
16 #define QEMU_VIRTIO_PCI_H
17
18 #include "hw/pci/msi.h"
19 #include "hw/virtio/virtio-blk.h"
20 #include "hw/virtio/virtio-net.h"
21 #include "hw/virtio/virtio-rng.h"
22 #include "hw/virtio/virtio-serial.h"
23 #include "hw/virtio/virtio-scsi.h"
24 #include "hw/virtio/virtio-balloon.h"
25 #include "hw/virtio/virtio-bus.h"
26 #include "hw/virtio/virtio-input.h"
27 #include "hw/virtio/virtio-gpu.h"
28 #include "hw/virtio/virtio-crypto.h"
29
30 #ifdef CONFIG_VIRTFS
31 #include "hw/9pfs/virtio-9p.h"
32 #endif
33 #ifdef CONFIG_VHOST_SCSI
34 #include "hw/virtio/vhost-scsi.h"
35 #endif
36 #ifdef CONFIG_VHOST_VSOCK
37 #include "hw/virtio/vhost-vsock.h"
38 #endif
39
40 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
41 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
42 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
43 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
44 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
45 typedef struct VirtIONetPCI VirtIONetPCI;
46 typedef struct VHostSCSIPCI VHostSCSIPCI;
47 typedef struct VirtIORngPCI VirtIORngPCI;
48 typedef struct VirtIOInputPCI VirtIOInputPCI;
49 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
50 typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
51 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
52 typedef struct VHostVSockPCI VHostVSockPCI;
53 typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
54
55 /* virtio-pci-bus */
56
57 typedef struct VirtioBusState VirtioPCIBusState;
58 typedef struct VirtioBusClass VirtioPCIBusClass;
59
60 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
61 #define VIRTIO_PCI_BUS(obj) \
62 OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS)
63 #define VIRTIO_PCI_BUS_GET_CLASS(obj) \
64 OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS)
65 #define VIRTIO_PCI_BUS_CLASS(klass) \
66 OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
67
68 enum {
69 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
70 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
71 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
72 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
73 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
74 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
75 VIRTIO_PCI_FLAG_ATS_BIT,
76 };
77
78 /* Need to activate work-arounds for buggy guests at vmstate load. */
79 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
80 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
81
82 /* Performance improves when virtqueue kick processing is decoupled from the
83 * vcpu thread using ioeventfd for some devices. */
84 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
85
86 /* virtio version flags */
87 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
88
89 /* migrate extra state */
90 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
91
92 /* have pio notification for modern device ? */
93 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
94 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
95
96 /* page per vq flag to be used by split drivers within guests */
97 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
98 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
99
100 /* address space translation service */
101 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
102
103 typedef struct {
104 MSIMessage msg;
105 int virq;
106 unsigned int users;
107 } VirtIOIRQFD;
108
109 /*
110 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
111 */
112 #define TYPE_VIRTIO_PCI "virtio-pci"
113 #define VIRTIO_PCI_GET_CLASS(obj) \
114 OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
115 #define VIRTIO_PCI_CLASS(klass) \
116 OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
117 #define VIRTIO_PCI(obj) \
118 OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
119
120 typedef struct VirtioPCIClass {
121 PCIDeviceClass parent_class;
122 DeviceRealize parent_dc_realize;
123 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
124 } VirtioPCIClass;
125
126 typedef struct VirtIOPCIRegion {
127 MemoryRegion mr;
128 uint32_t offset;
129 uint32_t size;
130 uint32_t type;
131 } VirtIOPCIRegion;
132
133 typedef struct VirtIOPCIQueue {
134 uint16_t num;
135 bool enabled;
136 uint32_t desc[2];
137 uint32_t avail[2];
138 uint32_t used[2];
139 } VirtIOPCIQueue;
140
141 struct VirtIOPCIProxy {
142 PCIDevice pci_dev;
143 MemoryRegion bar;
144 VirtIOPCIRegion common;
145 VirtIOPCIRegion isr;
146 VirtIOPCIRegion device;
147 VirtIOPCIRegion notify;
148 VirtIOPCIRegion notify_pio;
149 MemoryRegion modern_bar;
150 MemoryRegion io_bar;
151 MemoryRegion modern_cfg;
152 AddressSpace modern_as;
153 uint32_t legacy_io_bar_idx;
154 uint32_t msix_bar_idx;
155 uint32_t modern_io_bar_idx;
156 uint32_t modern_mem_bar_idx;
157 int config_cap;
158 uint32_t flags;
159 bool disable_modern;
160 bool ignore_backend_features;
161 OnOffAuto disable_legacy;
162 uint32_t class_code;
163 uint32_t nvectors;
164 uint32_t dfselect;
165 uint32_t gfselect;
166 uint32_t guest_features[2];
167 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
168
169 VirtIOIRQFD *vector_irqfd;
170 int nvqs_with_notifiers;
171 VirtioBusState bus;
172 };
173
174 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
175 {
176 return !proxy->disable_modern;
177 }
178
179 static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
180 {
181 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
182 }
183
184 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
185 {
186 proxy->disable_modern = false;
187 proxy->disable_legacy = ON_OFF_AUTO_ON;
188 }
189
190 static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
191 {
192 proxy->disable_modern = true;
193 }
194
195 /*
196 * virtio-scsi-pci: This extends VirtioPCIProxy.
197 */
198 #define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
199 #define VIRTIO_SCSI_PCI(obj) \
200 OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
201
202 struct VirtIOSCSIPCI {
203 VirtIOPCIProxy parent_obj;
204 VirtIOSCSI vdev;
205 };
206
207 #ifdef CONFIG_VHOST_SCSI
208 /*
209 * vhost-scsi-pci: This extends VirtioPCIProxy.
210 */
211 #define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
212 #define VHOST_SCSI_PCI(obj) \
213 OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
214
215 struct VHostSCSIPCI {
216 VirtIOPCIProxy parent_obj;
217 VHostSCSI vdev;
218 };
219 #endif
220
221 /*
222 * virtio-blk-pci: This extends VirtioPCIProxy.
223 */
224 #define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
225 #define VIRTIO_BLK_PCI(obj) \
226 OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
227
228 struct VirtIOBlkPCI {
229 VirtIOPCIProxy parent_obj;
230 VirtIOBlock vdev;
231 };
232
233 /*
234 * virtio-balloon-pci: This extends VirtioPCIProxy.
235 */
236 #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
237 #define VIRTIO_BALLOON_PCI(obj) \
238 OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
239
240 struct VirtIOBalloonPCI {
241 VirtIOPCIProxy parent_obj;
242 VirtIOBalloon vdev;
243 };
244
245 /*
246 * virtio-serial-pci: This extends VirtioPCIProxy.
247 */
248 #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
249 #define VIRTIO_SERIAL_PCI(obj) \
250 OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
251
252 struct VirtIOSerialPCI {
253 VirtIOPCIProxy parent_obj;
254 VirtIOSerial vdev;
255 };
256
257 /*
258 * virtio-net-pci: This extends VirtioPCIProxy.
259 */
260 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
261 #define VIRTIO_NET_PCI(obj) \
262 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
263
264 struct VirtIONetPCI {
265 VirtIOPCIProxy parent_obj;
266 VirtIONet vdev;
267 };
268
269 /*
270 * virtio-9p-pci: This extends VirtioPCIProxy.
271 */
272
273 #ifdef CONFIG_VIRTFS
274
275 #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
276 #define VIRTIO_9P_PCI(obj) \
277 OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
278
279 typedef struct V9fsPCIState {
280 VirtIOPCIProxy parent_obj;
281 V9fsVirtioState vdev;
282 } V9fsPCIState;
283
284 #endif
285
286 /*
287 * virtio-rng-pci: This extends VirtioPCIProxy.
288 */
289 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
290 #define VIRTIO_RNG_PCI(obj) \
291 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
292
293 struct VirtIORngPCI {
294 VirtIOPCIProxy parent_obj;
295 VirtIORNG vdev;
296 };
297
298 /*
299 * virtio-input-pci: This extends VirtioPCIProxy.
300 */
301 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
302 #define VIRTIO_INPUT_PCI(obj) \
303 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
304
305 struct VirtIOInputPCI {
306 VirtIOPCIProxy parent_obj;
307 VirtIOInput vdev;
308 };
309
310 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
311 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
312 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
313 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
314 #define VIRTIO_INPUT_HID_PCI(obj) \
315 OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
316
317 struct VirtIOInputHIDPCI {
318 VirtIOPCIProxy parent_obj;
319 VirtIOInputHID vdev;
320 };
321
322 #ifdef CONFIG_LINUX
323
324 #define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
325 #define VIRTIO_INPUT_HOST_PCI(obj) \
326 OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
327
328 struct VirtIOInputHostPCI {
329 VirtIOPCIProxy parent_obj;
330 VirtIOInputHost vdev;
331 };
332
333 #endif
334
335 /*
336 * virtio-gpu-pci: This extends VirtioPCIProxy.
337 */
338 #define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
339 #define VIRTIO_GPU_PCI(obj) \
340 OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
341
342 struct VirtIOGPUPCI {
343 VirtIOPCIProxy parent_obj;
344 VirtIOGPU vdev;
345 };
346
347 #ifdef CONFIG_VHOST_VSOCK
348 /*
349 * vhost-vsock-pci: This extends VirtioPCIProxy.
350 */
351 #define TYPE_VHOST_VSOCK_PCI "vhost-vsock-pci"
352 #define VHOST_VSOCK_PCI(obj) \
353 OBJECT_CHECK(VHostVSockPCI, (obj), TYPE_VHOST_VSOCK_PCI)
354
355 struct VHostVSockPCI {
356 VirtIOPCIProxy parent_obj;
357 VHostVSock vdev;
358 };
359 #endif
360
361 /*
362 * virtio-crypto-pci: This extends VirtioPCIProxy.
363 */
364 #define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
365 #define VIRTIO_CRYPTO_PCI(obj) \
366 OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
367
368 struct VirtIOCryptoPCI {
369 VirtIOPCIProxy parent_obj;
370 VirtIOCrypto vdev;
371 };
372
373 /* Virtio ABI version, if we increment this, we break the guest driver. */
374 #define VIRTIO_PCI_ABI_VERSION 0
375
376 #endif