exec/memory: Use struct Object typedef
[qemu/ar7.git] / hw / virtio / virtio-pci.h
blobd7d5d403a9483f5f7e0f0f9b41108328a537f114
1 /*
2 * Virtio PCI Bindings
4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
7 * Authors:
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Paul Brook <paul@codesourcery.com>
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
15 #ifndef QEMU_VIRTIO_PCI_H
16 #define QEMU_VIRTIO_PCI_H
18 #include "hw/pci/msi.h"
19 #include "hw/virtio/virtio-bus.h"
20 #include "qom/object.h"
23 /* virtio-pci-bus */
25 typedef struct VirtioBusState VirtioPCIBusState;
26 typedef struct VirtioBusClass VirtioPCIBusClass;
28 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
29 DECLARE_OBJ_CHECKERS(VirtioPCIBusState, VirtioPCIBusClass,
30 VIRTIO_PCI_BUS, TYPE_VIRTIO_PCI_BUS)
32 enum {
33 VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT,
34 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT,
35 VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT,
36 VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT,
37 VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT,
38 VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT,
39 VIRTIO_PCI_FLAG_ATS_BIT,
40 VIRTIO_PCI_FLAG_INIT_DEVERR_BIT,
41 VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT,
42 VIRTIO_PCI_FLAG_INIT_PM_BIT,
43 VIRTIO_PCI_FLAG_INIT_FLR_BIT,
44 VIRTIO_PCI_FLAG_AER_BIT,
47 /* Need to activate work-arounds for buggy guests at vmstate load. */
48 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
49 (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
51 /* Performance improves when virtqueue kick processing is decoupled from the
52 * vcpu thread using ioeventfd for some devices. */
53 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
55 /* virtio version flags */
56 #define VIRTIO_PCI_FLAG_DISABLE_PCIE (1 << VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT)
58 /* migrate extra state */
59 #define VIRTIO_PCI_FLAG_MIGRATE_EXTRA (1 << VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT)
61 /* have pio notification for modern device ? */
62 #define VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY \
63 (1 << VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT)
65 /* page per vq flag to be used by split drivers within guests */
66 #define VIRTIO_PCI_FLAG_PAGE_PER_VQ \
67 (1 << VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT)
69 /* address space translation service */
70 #define VIRTIO_PCI_FLAG_ATS (1 << VIRTIO_PCI_FLAG_ATS_BIT)
72 /* Init error enabling flags */
73 #define VIRTIO_PCI_FLAG_INIT_DEVERR (1 << VIRTIO_PCI_FLAG_INIT_DEVERR_BIT)
75 /* Init Link Control register */
76 #define VIRTIO_PCI_FLAG_INIT_LNKCTL (1 << VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT)
78 /* Init Power Management */
79 #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT)
81 /* Init Function Level Reset capability */
82 #define VIRTIO_PCI_FLAG_INIT_FLR (1 << VIRTIO_PCI_FLAG_INIT_FLR_BIT)
84 /* Advanced Error Reporting capability */
85 #define VIRTIO_PCI_FLAG_AER (1 << VIRTIO_PCI_FLAG_AER_BIT)
87 typedef struct {
88 MSIMessage msg;
89 int virq;
90 unsigned int users;
91 } VirtIOIRQFD;
94 * virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
96 #define TYPE_VIRTIO_PCI "virtio-pci"
97 OBJECT_DECLARE_TYPE(VirtIOPCIProxy, VirtioPCIClass, VIRTIO_PCI)
99 struct VirtioPCIClass {
100 PCIDeviceClass parent_class;
101 DeviceRealize parent_dc_realize;
102 void (*realize)(VirtIOPCIProxy *vpci_dev, Error **errp);
105 typedef struct VirtIOPCIRegion {
106 MemoryRegion mr;
107 uint32_t offset;
108 uint32_t size;
109 uint32_t type;
110 } VirtIOPCIRegion;
112 typedef struct VirtIOPCIQueue {
113 uint16_t num;
114 bool enabled;
115 uint32_t desc[2];
116 uint32_t avail[2];
117 uint32_t used[2];
118 } VirtIOPCIQueue;
120 struct VirtIOPCIProxy {
121 PCIDevice pci_dev;
122 MemoryRegion bar;
123 union {
124 struct {
125 VirtIOPCIRegion common;
126 VirtIOPCIRegion isr;
127 VirtIOPCIRegion device;
128 VirtIOPCIRegion notify;
129 VirtIOPCIRegion notify_pio;
131 VirtIOPCIRegion regs[5];
133 MemoryRegion modern_bar;
134 MemoryRegion io_bar;
135 uint32_t legacy_io_bar_idx;
136 uint32_t msix_bar_idx;
137 uint32_t modern_io_bar_idx;
138 uint32_t modern_mem_bar_idx;
139 int config_cap;
140 uint32_t flags;
141 bool disable_modern;
142 bool ignore_backend_features;
143 OnOffAuto disable_legacy;
144 uint32_t class_code;
145 uint32_t nvectors;
146 uint32_t dfselect;
147 uint32_t gfselect;
148 uint32_t guest_features[2];
149 VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX];
151 VirtIOIRQFD *vector_irqfd;
152 int nvqs_with_notifiers;
153 VirtioBusState bus;
156 static inline bool virtio_pci_modern(VirtIOPCIProxy *proxy)
158 return !proxy->disable_modern;
161 static inline bool virtio_pci_legacy(VirtIOPCIProxy *proxy)
163 return proxy->disable_legacy == ON_OFF_AUTO_OFF;
166 static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy)
168 proxy->disable_modern = false;
169 proxy->disable_legacy = ON_OFF_AUTO_ON;
172 static inline void virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
174 proxy->disable_modern = true;
178 * virtio-input-pci: This extends VirtioPCIProxy.
180 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
182 /* Virtio ABI version, if we increment this, we break the guest driver. */
183 #define VIRTIO_PCI_ABI_VERSION 0
185 /* Input for virtio_pci_types_register() */
186 typedef struct VirtioPCIDeviceTypeInfo {
188 * Common base class for the subclasses below.
190 * Required only if transitional_name or non_transitional_name is set.
192 * We need a separate base type instead of making all types
193 * inherit from generic_name for two reasons:
194 * 1) generic_name implements INTERFACE_PCIE_DEVICE, but
195 * transitional_name does not.
196 * 2) generic_name has the "disable-legacy" and "disable-modern"
197 * properties, transitional_name and non_transitional name don't.
199 const char *base_name;
201 * Generic device type. Optional.
203 * Supports both transitional and non-transitional modes,
204 * using the disable-legacy and disable-modern properties.
205 * If disable-legacy=auto, (non-)transitional mode is selected
206 * depending on the bus where the device is plugged.
208 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE,
209 * but PCI Express is supported only in non-transitional mode.
211 * The only type implemented by QEMU 3.1 and older.
213 const char *generic_name;
215 * The transitional device type. Optional.
217 * Implements both INTERFACE_PCIE_DEVICE and INTERFACE_CONVENTIONAL_PCI_DEVICE.
219 const char *transitional_name;
221 * The non-transitional device type. Optional.
223 * Implements INTERFACE_CONVENTIONAL_PCI_DEVICE only.
225 const char *non_transitional_name;
227 /* Parent type. If NULL, TYPE_VIRTIO_PCI is used */
228 const char *parent;
230 /* Same as TypeInfo fields: */
231 size_t instance_size;
232 size_t class_size;
233 void (*instance_init)(Object *obj);
234 void (*class_init)(ObjectClass *klass, void *data);
235 InterfaceInfo *interfaces;
236 } VirtioPCIDeviceTypeInfo;
238 /* Register virtio-pci type(s). @t must be static. */
239 void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
242 * virtio_pci_optimal_num_queues:
243 * @fixed_queues: number of queues that are always present
245 * Returns: The optimal number of queues for a multi-queue device, excluding
246 * @fixed_queues.
248 unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues);
250 #endif