root / hw / virtio-pci.c @ 77047bb7
History | View | Annotate | Download (18 kB)
1 | 53c25cea | Paul Brook | /*
|
---|---|---|---|
2 | 53c25cea | Paul Brook | * Virtio PCI Bindings
|
3 | 53c25cea | Paul Brook | *
|
4 | 53c25cea | Paul Brook | * Copyright IBM, Corp. 2007
|
5 | 53c25cea | Paul Brook | * Copyright (c) 2009 CodeSourcery
|
6 | 53c25cea | Paul Brook | *
|
7 | 53c25cea | Paul Brook | * Authors:
|
8 | 53c25cea | Paul Brook | * Anthony Liguori <aliguori@us.ibm.com>
|
9 | 53c25cea | Paul Brook | * Paul Brook <paul@codesourcery.com>
|
10 | 53c25cea | Paul Brook | *
|
11 | 53c25cea | Paul Brook | * This work is licensed under the terms of the GNU GPL, version 2. See
|
12 | 53c25cea | Paul Brook | * the COPYING file in the top-level directory.
|
13 | 53c25cea | Paul Brook | *
|
14 | 53c25cea | Paul Brook | */
|
15 | 53c25cea | Paul Brook | |
16 | 53c25cea | Paul Brook | #include <inttypes.h> |
17 | 53c25cea | Paul Brook | |
18 | 53c25cea | Paul Brook | #include "virtio.h" |
19 | 53c25cea | Paul Brook | #include "pci.h" |
20 | d176c495 | Gerd Hoffmann | #include "sysemu.h" |
21 | aba800a3 | Michael S. Tsirkin | #include "msix.h" |
22 | a1e0fea5 | Gerd Hoffmann | #include "net.h" |
23 | 97b15621 | Gerd Hoffmann | #include "loader.h" |
24 | 53c25cea | Paul Brook | |
25 | 53c25cea | Paul Brook | /* from Linux's linux/virtio_pci.h */
|
26 | 53c25cea | Paul Brook | |
27 | 53c25cea | Paul Brook | /* A 32-bit r/o bitmask of the features supported by the host */
|
28 | 53c25cea | Paul Brook | #define VIRTIO_PCI_HOST_FEATURES 0 |
29 | 53c25cea | Paul Brook | |
30 | 53c25cea | Paul Brook | /* A 32-bit r/w bitmask of features activated by the guest */
|
31 | 53c25cea | Paul Brook | #define VIRTIO_PCI_GUEST_FEATURES 4 |
32 | 53c25cea | Paul Brook | |
33 | 53c25cea | Paul Brook | /* A 32-bit r/w PFN for the currently selected queue */
|
34 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_PFN 8 |
35 | 53c25cea | Paul Brook | |
36 | 53c25cea | Paul Brook | /* A 16-bit r/o queue size for the currently selected queue */
|
37 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_NUM 12 |
38 | 53c25cea | Paul Brook | |
39 | 53c25cea | Paul Brook | /* A 16-bit r/w queue selector */
|
40 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_SEL 14 |
41 | 53c25cea | Paul Brook | |
42 | 53c25cea | Paul Brook | /* A 16-bit r/w queue notifier */
|
43 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_NOTIFY 16 |
44 | 53c25cea | Paul Brook | |
45 | 53c25cea | Paul Brook | /* An 8-bit device status register. */
|
46 | 53c25cea | Paul Brook | #define VIRTIO_PCI_STATUS 18 |
47 | 53c25cea | Paul Brook | |
48 | 53c25cea | Paul Brook | /* An 8-bit r/o interrupt status register. Reading the value will return the
|
49 | 53c25cea | Paul Brook | * current contents of the ISR and will also clear it. This is effectively
|
50 | 53c25cea | Paul Brook | * a read-and-acknowledge. */
|
51 | 53c25cea | Paul Brook | #define VIRTIO_PCI_ISR 19 |
52 | 53c25cea | Paul Brook | |
53 | aba800a3 | Michael S. Tsirkin | /* MSI-X registers: only enabled if MSI-X is enabled. */
|
54 | aba800a3 | Michael S. Tsirkin | /* A 16-bit vector for configuration changes. */
|
55 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_MSI_CONFIG_VECTOR 20 |
56 | aba800a3 | Michael S. Tsirkin | /* A 16-bit vector for selected queue notifications. */
|
57 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_MSI_QUEUE_VECTOR 22 |
58 | aba800a3 | Michael S. Tsirkin | |
59 | aba800a3 | Michael S. Tsirkin | /* Config space size */
|
60 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_PCI_CONFIG_NOMSI 20 |
61 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_PCI_CONFIG_MSI 24 |
62 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_PCI_REGION_SIZE(dev) (msix_present(dev) ? \
|
63 | aba800a3 | Michael S. Tsirkin | VIRTIO_PCI_CONFIG_MSI : \ |
64 | aba800a3 | Michael S. Tsirkin | VIRTIO_PCI_CONFIG_NOMSI) |
65 | aba800a3 | Michael S. Tsirkin | |
66 | aba800a3 | Michael S. Tsirkin | /* The remaining space is defined by each driver as the per-driver
|
67 | aba800a3 | Michael S. Tsirkin | * configuration space */
|
68 | aba800a3 | Michael S. Tsirkin | #define VIRTIO_PCI_CONFIG(dev) (msix_enabled(dev) ? \
|
69 | aba800a3 | Michael S. Tsirkin | VIRTIO_PCI_CONFIG_MSI : \ |
70 | aba800a3 | Michael S. Tsirkin | VIRTIO_PCI_CONFIG_NOMSI) |
71 | 53c25cea | Paul Brook | |
72 | 53c25cea | Paul Brook | /* Virtio ABI version, if we increment this, we break the guest driver. */
|
73 | 53c25cea | Paul Brook | #define VIRTIO_PCI_ABI_VERSION 0 |
74 | 53c25cea | Paul Brook | |
75 | 53c25cea | Paul Brook | /* How many bits to shift physical queue address written to QUEUE_PFN.
|
76 | 53c25cea | Paul Brook | * 12 is historical, and due to x86 page size. */
|
77 | 53c25cea | Paul Brook | #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12 |
78 | 53c25cea | Paul Brook | |
79 | 53c25cea | Paul Brook | /* QEMU doesn't strictly need write barriers since everything runs in
|
80 | 53c25cea | Paul Brook | * lock-step. We'll leave the calls to wmb() in though to make it obvious for
|
81 | 53c25cea | Paul Brook | * KVM or if kqemu gets SMP support.
|
82 | 53c25cea | Paul Brook | */
|
83 | 53c25cea | Paul Brook | #define wmb() do { } while (0) |
84 | 53c25cea | Paul Brook | |
85 | 53c25cea | Paul Brook | /* PCI bindings. */
|
86 | 53c25cea | Paul Brook | |
87 | 53c25cea | Paul Brook | typedef struct { |
88 | 53c25cea | Paul Brook | PCIDevice pci_dev; |
89 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
90 | 53c25cea | Paul Brook | uint32_t addr; |
91 | ab73ff29 | Gerd Hoffmann | uint32_t class_code; |
92 | a1e0fea5 | Gerd Hoffmann | uint32_t nvectors; |
93 | d176c495 | Gerd Hoffmann | DriveInfo *dinfo; |
94 | 97b15621 | Gerd Hoffmann | NICConf nic; |
95 | 53c25cea | Paul Brook | } VirtIOPCIProxy; |
96 | 53c25cea | Paul Brook | |
97 | 53c25cea | Paul Brook | /* virtio device */
|
98 | 53c25cea | Paul Brook | |
99 | 7055e687 | Michael S. Tsirkin | static void virtio_pci_notify(void *opaque, uint16_t vector) |
100 | 53c25cea | Paul Brook | { |
101 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
102 | aba800a3 | Michael S. Tsirkin | if (msix_enabled(&proxy->pci_dev))
|
103 | aba800a3 | Michael S. Tsirkin | msix_notify(&proxy->pci_dev, vector); |
104 | aba800a3 | Michael S. Tsirkin | else
|
105 | aba800a3 | Michael S. Tsirkin | qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1); |
106 | 53c25cea | Paul Brook | } |
107 | 53c25cea | Paul Brook | |
108 | ff24bd58 | Michael S. Tsirkin | static void virtio_pci_save_config(void * opaque, QEMUFile *f) |
109 | ff24bd58 | Michael S. Tsirkin | { |
110 | ff24bd58 | Michael S. Tsirkin | VirtIOPCIProxy *proxy = opaque; |
111 | ff24bd58 | Michael S. Tsirkin | pci_device_save(&proxy->pci_dev, f); |
112 | ff24bd58 | Michael S. Tsirkin | msix_save(&proxy->pci_dev, f); |
113 | ff24bd58 | Michael S. Tsirkin | if (msix_present(&proxy->pci_dev))
|
114 | ff24bd58 | Michael S. Tsirkin | qemu_put_be16(f, proxy->vdev->config_vector); |
115 | ff24bd58 | Michael S. Tsirkin | } |
116 | ff24bd58 | Michael S. Tsirkin | |
117 | ff24bd58 | Michael S. Tsirkin | static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f) |
118 | ff24bd58 | Michael S. Tsirkin | { |
119 | ff24bd58 | Michael S. Tsirkin | VirtIOPCIProxy *proxy = opaque; |
120 | ff24bd58 | Michael S. Tsirkin | if (msix_present(&proxy->pci_dev))
|
121 | ff24bd58 | Michael S. Tsirkin | qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n)); |
122 | ff24bd58 | Michael S. Tsirkin | } |
123 | ff24bd58 | Michael S. Tsirkin | |
124 | ff24bd58 | Michael S. Tsirkin | static int virtio_pci_load_config(void * opaque, QEMUFile *f) |
125 | ff24bd58 | Michael S. Tsirkin | { |
126 | ff24bd58 | Michael S. Tsirkin | VirtIOPCIProxy *proxy = opaque; |
127 | ff24bd58 | Michael S. Tsirkin | int ret;
|
128 | ff24bd58 | Michael S. Tsirkin | ret = pci_device_load(&proxy->pci_dev, f); |
129 | e6da7680 | Michael S. Tsirkin | if (ret) {
|
130 | ff24bd58 | Michael S. Tsirkin | return ret;
|
131 | e6da7680 | Michael S. Tsirkin | } |
132 | ff24bd58 | Michael S. Tsirkin | msix_load(&proxy->pci_dev, f); |
133 | e6da7680 | Michael S. Tsirkin | if (msix_present(&proxy->pci_dev)) {
|
134 | ff24bd58 | Michael S. Tsirkin | qemu_get_be16s(f, &proxy->vdev->config_vector); |
135 | e6da7680 | Michael S. Tsirkin | } else {
|
136 | e6da7680 | Michael S. Tsirkin | proxy->vdev->config_vector = VIRTIO_NO_VECTOR; |
137 | e6da7680 | Michael S. Tsirkin | } |
138 | e6da7680 | Michael S. Tsirkin | if (proxy->vdev->config_vector != VIRTIO_NO_VECTOR) {
|
139 | e6da7680 | Michael S. Tsirkin | return msix_vector_use(&proxy->pci_dev, proxy->vdev->config_vector);
|
140 | e6da7680 | Michael S. Tsirkin | } |
141 | ff24bd58 | Michael S. Tsirkin | return 0; |
142 | ff24bd58 | Michael S. Tsirkin | } |
143 | ff24bd58 | Michael S. Tsirkin | |
144 | ff24bd58 | Michael S. Tsirkin | static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f) |
145 | ff24bd58 | Michael S. Tsirkin | { |
146 | ff24bd58 | Michael S. Tsirkin | VirtIOPCIProxy *proxy = opaque; |
147 | ff24bd58 | Michael S. Tsirkin | uint16_t vector; |
148 | e6da7680 | Michael S. Tsirkin | if (msix_present(&proxy->pci_dev)) {
|
149 | e6da7680 | Michael S. Tsirkin | qemu_get_be16s(f, &vector); |
150 | e6da7680 | Michael S. Tsirkin | } else {
|
151 | e6da7680 | Michael S. Tsirkin | vector = VIRTIO_NO_VECTOR; |
152 | e6da7680 | Michael S. Tsirkin | } |
153 | ff24bd58 | Michael S. Tsirkin | virtio_queue_set_vector(proxy->vdev, n, vector); |
154 | e6da7680 | Michael S. Tsirkin | if (vector != VIRTIO_NO_VECTOR) {
|
155 | e6da7680 | Michael S. Tsirkin | return msix_vector_use(&proxy->pci_dev, vector);
|
156 | e6da7680 | Michael S. Tsirkin | } |
157 | ff24bd58 | Michael S. Tsirkin | return 0; |
158 | ff24bd58 | Michael S. Tsirkin | } |
159 | ff24bd58 | Michael S. Tsirkin | |
160 | e489030d | Michael S. Tsirkin | static void virtio_pci_reset(DeviceState *d) |
161 | 7055e687 | Michael S. Tsirkin | { |
162 | e489030d | Michael S. Tsirkin | VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev); |
163 | 7055e687 | Michael S. Tsirkin | virtio_reset(proxy->vdev); |
164 | aba800a3 | Michael S. Tsirkin | msix_reset(&proxy->pci_dev); |
165 | 7055e687 | Michael S. Tsirkin | } |
166 | 7055e687 | Michael S. Tsirkin | |
167 | 53c25cea | Paul Brook | static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
168 | 53c25cea | Paul Brook | { |
169 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
170 | 53c25cea | Paul Brook | VirtIODevice *vdev = proxy->vdev; |
171 | c227f099 | Anthony Liguori | target_phys_addr_t pa; |
172 | 53c25cea | Paul Brook | |
173 | 53c25cea | Paul Brook | switch (addr) {
|
174 | 53c25cea | Paul Brook | case VIRTIO_PCI_GUEST_FEATURES:
|
175 | 53c25cea | Paul Brook | /* Guest does not negotiate properly? We have to assume nothing. */
|
176 | 53c25cea | Paul Brook | if (val & (1 << VIRTIO_F_BAD_FEATURE)) { |
177 | 53c25cea | Paul Brook | if (vdev->bad_features)
|
178 | 53c25cea | Paul Brook | val = vdev->bad_features(vdev); |
179 | 53c25cea | Paul Brook | else
|
180 | 53c25cea | Paul Brook | val = 0;
|
181 | 53c25cea | Paul Brook | } |
182 | 53c25cea | Paul Brook | if (vdev->set_features)
|
183 | 53c25cea | Paul Brook | vdev->set_features(vdev, val); |
184 | 53c25cea | Paul Brook | vdev->features = val; |
185 | 53c25cea | Paul Brook | break;
|
186 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_PFN:
|
187 | c227f099 | Anthony Liguori | pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT; |
188 | 1b8e9b27 | Michael S. Tsirkin | if (pa == 0) { |
189 | 1b8e9b27 | Michael S. Tsirkin | virtio_reset(proxy->vdev); |
190 | 1b8e9b27 | Michael S. Tsirkin | msix_unuse_all_vectors(&proxy->pci_dev); |
191 | 1b8e9b27 | Michael S. Tsirkin | } |
192 | 7055e687 | Michael S. Tsirkin | else
|
193 | 7055e687 | Michael S. Tsirkin | virtio_queue_set_addr(vdev, vdev->queue_sel, pa); |
194 | 53c25cea | Paul Brook | break;
|
195 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_SEL:
|
196 | 53c25cea | Paul Brook | if (val < VIRTIO_PCI_QUEUE_MAX)
|
197 | 53c25cea | Paul Brook | vdev->queue_sel = val; |
198 | 53c25cea | Paul Brook | break;
|
199 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_NOTIFY:
|
200 | 53c25cea | Paul Brook | virtio_queue_notify(vdev, val); |
201 | 53c25cea | Paul Brook | break;
|
202 | 53c25cea | Paul Brook | case VIRTIO_PCI_STATUS:
|
203 | 53c25cea | Paul Brook | vdev->status = val & 0xFF;
|
204 | 1b8e9b27 | Michael S. Tsirkin | if (vdev->status == 0) { |
205 | 1b8e9b27 | Michael S. Tsirkin | virtio_reset(proxy->vdev); |
206 | 1b8e9b27 | Michael S. Tsirkin | msix_unuse_all_vectors(&proxy->pci_dev); |
207 | 1b8e9b27 | Michael S. Tsirkin | } |
208 | 53c25cea | Paul Brook | break;
|
209 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_CONFIG_VECTOR:
|
210 | aba800a3 | Michael S. Tsirkin | msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); |
211 | aba800a3 | Michael S. Tsirkin | /* Make it possible for guest to discover an error took place. */
|
212 | aba800a3 | Michael S. Tsirkin | if (msix_vector_use(&proxy->pci_dev, val) < 0) |
213 | aba800a3 | Michael S. Tsirkin | val = VIRTIO_NO_VECTOR; |
214 | aba800a3 | Michael S. Tsirkin | vdev->config_vector = val; |
215 | aba800a3 | Michael S. Tsirkin | break;
|
216 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_QUEUE_VECTOR:
|
217 | aba800a3 | Michael S. Tsirkin | msix_vector_unuse(&proxy->pci_dev, |
218 | aba800a3 | Michael S. Tsirkin | virtio_queue_vector(vdev, vdev->queue_sel)); |
219 | aba800a3 | Michael S. Tsirkin | /* Make it possible for guest to discover an error took place. */
|
220 | aba800a3 | Michael S. Tsirkin | if (msix_vector_use(&proxy->pci_dev, val) < 0) |
221 | aba800a3 | Michael S. Tsirkin | val = VIRTIO_NO_VECTOR; |
222 | aba800a3 | Michael S. Tsirkin | virtio_queue_set_vector(vdev, vdev->queue_sel, val); |
223 | aba800a3 | Michael S. Tsirkin | break;
|
224 | aba800a3 | Michael S. Tsirkin | default:
|
225 | aba800a3 | Michael S. Tsirkin | fprintf(stderr, "%s: unexpected address 0x%x value 0x%x\n",
|
226 | aba800a3 | Michael S. Tsirkin | __func__, addr, val); |
227 | aba800a3 | Michael S. Tsirkin | break;
|
228 | 53c25cea | Paul Brook | } |
229 | 53c25cea | Paul Brook | } |
230 | 53c25cea | Paul Brook | |
231 | aba800a3 | Michael S. Tsirkin | static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
|
232 | 53c25cea | Paul Brook | { |
233 | 53c25cea | Paul Brook | VirtIODevice *vdev = proxy->vdev; |
234 | 53c25cea | Paul Brook | uint32_t ret = 0xFFFFFFFF;
|
235 | 53c25cea | Paul Brook | |
236 | 53c25cea | Paul Brook | switch (addr) {
|
237 | 53c25cea | Paul Brook | case VIRTIO_PCI_HOST_FEATURES:
|
238 | 53c25cea | Paul Brook | ret = vdev->get_features(vdev); |
239 | 6d74ca5a | Michael S. Tsirkin | ret |= vdev->binding->get_features(proxy); |
240 | 53c25cea | Paul Brook | break;
|
241 | 53c25cea | Paul Brook | case VIRTIO_PCI_GUEST_FEATURES:
|
242 | 53c25cea | Paul Brook | ret = vdev->features; |
243 | 53c25cea | Paul Brook | break;
|
244 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_PFN:
|
245 | 53c25cea | Paul Brook | ret = virtio_queue_get_addr(vdev, vdev->queue_sel) |
246 | 53c25cea | Paul Brook | >> VIRTIO_PCI_QUEUE_ADDR_SHIFT; |
247 | 53c25cea | Paul Brook | break;
|
248 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_NUM:
|
249 | 53c25cea | Paul Brook | ret = virtio_queue_get_num(vdev, vdev->queue_sel); |
250 | 53c25cea | Paul Brook | break;
|
251 | 53c25cea | Paul Brook | case VIRTIO_PCI_QUEUE_SEL:
|
252 | 53c25cea | Paul Brook | ret = vdev->queue_sel; |
253 | 53c25cea | Paul Brook | break;
|
254 | 53c25cea | Paul Brook | case VIRTIO_PCI_STATUS:
|
255 | 53c25cea | Paul Brook | ret = vdev->status; |
256 | 53c25cea | Paul Brook | break;
|
257 | 53c25cea | Paul Brook | case VIRTIO_PCI_ISR:
|
258 | 53c25cea | Paul Brook | /* reading from the ISR also clears it. */
|
259 | 53c25cea | Paul Brook | ret = vdev->isr; |
260 | 53c25cea | Paul Brook | vdev->isr = 0;
|
261 | 7055e687 | Michael S. Tsirkin | qemu_set_irq(proxy->pci_dev.irq[0], 0); |
262 | 53c25cea | Paul Brook | break;
|
263 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_CONFIG_VECTOR:
|
264 | aba800a3 | Michael S. Tsirkin | ret = vdev->config_vector; |
265 | aba800a3 | Michael S. Tsirkin | break;
|
266 | aba800a3 | Michael S. Tsirkin | case VIRTIO_MSI_QUEUE_VECTOR:
|
267 | aba800a3 | Michael S. Tsirkin | ret = virtio_queue_vector(vdev, vdev->queue_sel); |
268 | aba800a3 | Michael S. Tsirkin | break;
|
269 | 53c25cea | Paul Brook | default:
|
270 | 53c25cea | Paul Brook | break;
|
271 | 53c25cea | Paul Brook | } |
272 | 53c25cea | Paul Brook | |
273 | 53c25cea | Paul Brook | return ret;
|
274 | 53c25cea | Paul Brook | } |
275 | 53c25cea | Paul Brook | |
276 | 53c25cea | Paul Brook | static uint32_t virtio_pci_config_readb(void *opaque, uint32_t addr) |
277 | 53c25cea | Paul Brook | { |
278 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
279 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
280 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
281 | aba800a3 | Michael S. Tsirkin | if (addr < config)
|
282 | aba800a3 | Michael S. Tsirkin | return virtio_ioport_read(proxy, addr);
|
283 | aba800a3 | Michael S. Tsirkin | addr -= config; |
284 | 53c25cea | Paul Brook | return virtio_config_readb(proxy->vdev, addr);
|
285 | 53c25cea | Paul Brook | } |
286 | 53c25cea | Paul Brook | |
287 | 53c25cea | Paul Brook | static uint32_t virtio_pci_config_readw(void *opaque, uint32_t addr) |
288 | 53c25cea | Paul Brook | { |
289 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
290 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
291 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
292 | aba800a3 | Michael S. Tsirkin | if (addr < config)
|
293 | aba800a3 | Michael S. Tsirkin | return virtio_ioport_read(proxy, addr);
|
294 | aba800a3 | Michael S. Tsirkin | addr -= config; |
295 | 53c25cea | Paul Brook | return virtio_config_readw(proxy->vdev, addr);
|
296 | 53c25cea | Paul Brook | } |
297 | 53c25cea | Paul Brook | |
298 | 53c25cea | Paul Brook | static uint32_t virtio_pci_config_readl(void *opaque, uint32_t addr) |
299 | 53c25cea | Paul Brook | { |
300 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
301 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
302 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
303 | aba800a3 | Michael S. Tsirkin | if (addr < config)
|
304 | aba800a3 | Michael S. Tsirkin | return virtio_ioport_read(proxy, addr);
|
305 | aba800a3 | Michael S. Tsirkin | addr -= config; |
306 | 53c25cea | Paul Brook | return virtio_config_readl(proxy->vdev, addr);
|
307 | 53c25cea | Paul Brook | } |
308 | 53c25cea | Paul Brook | |
309 | 53c25cea | Paul Brook | static void virtio_pci_config_writeb(void *opaque, uint32_t addr, uint32_t val) |
310 | 53c25cea | Paul Brook | { |
311 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
312 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
313 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
314 | aba800a3 | Michael S. Tsirkin | if (addr < config) {
|
315 | aba800a3 | Michael S. Tsirkin | virtio_ioport_write(proxy, addr, val); |
316 | aba800a3 | Michael S. Tsirkin | return;
|
317 | aba800a3 | Michael S. Tsirkin | } |
318 | aba800a3 | Michael S. Tsirkin | addr -= config; |
319 | 53c25cea | Paul Brook | virtio_config_writeb(proxy->vdev, addr, val); |
320 | 53c25cea | Paul Brook | } |
321 | 53c25cea | Paul Brook | |
322 | 53c25cea | Paul Brook | static void virtio_pci_config_writew(void *opaque, uint32_t addr, uint32_t val) |
323 | 53c25cea | Paul Brook | { |
324 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
325 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
326 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
327 | aba800a3 | Michael S. Tsirkin | if (addr < config) {
|
328 | aba800a3 | Michael S. Tsirkin | virtio_ioport_write(proxy, addr, val); |
329 | aba800a3 | Michael S. Tsirkin | return;
|
330 | aba800a3 | Michael S. Tsirkin | } |
331 | aba800a3 | Michael S. Tsirkin | addr -= config; |
332 | 53c25cea | Paul Brook | virtio_config_writew(proxy->vdev, addr, val); |
333 | 53c25cea | Paul Brook | } |
334 | 53c25cea | Paul Brook | |
335 | 53c25cea | Paul Brook | static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val) |
336 | 53c25cea | Paul Brook | { |
337 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = opaque; |
338 | aba800a3 | Michael S. Tsirkin | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev); |
339 | aba800a3 | Michael S. Tsirkin | addr -= proxy->addr; |
340 | aba800a3 | Michael S. Tsirkin | if (addr < config) {
|
341 | aba800a3 | Michael S. Tsirkin | virtio_ioport_write(proxy, addr, val); |
342 | aba800a3 | Michael S. Tsirkin | return;
|
343 | aba800a3 | Michael S. Tsirkin | } |
344 | aba800a3 | Michael S. Tsirkin | addr -= config; |
345 | 53c25cea | Paul Brook | virtio_config_writel(proxy->vdev, addr, val); |
346 | 53c25cea | Paul Brook | } |
347 | 53c25cea | Paul Brook | |
348 | 53c25cea | Paul Brook | static void virtio_map(PCIDevice *pci_dev, int region_num, |
349 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type)
|
350 | 53c25cea | Paul Brook | { |
351 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev); |
352 | 53c25cea | Paul Brook | VirtIODevice *vdev = proxy->vdev; |
353 | aba800a3 | Michael S. Tsirkin | unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len;
|
354 | 53c25cea | Paul Brook | |
355 | 53c25cea | Paul Brook | proxy->addr = addr; |
356 | 53c25cea | Paul Brook | |
357 | aba800a3 | Michael S. Tsirkin | register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy);
|
358 | aba800a3 | Michael S. Tsirkin | register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy);
|
359 | aba800a3 | Michael S. Tsirkin | register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy);
|
360 | aba800a3 | Michael S. Tsirkin | register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy);
|
361 | aba800a3 | Michael S. Tsirkin | register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy);
|
362 | aba800a3 | Michael S. Tsirkin | register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy);
|
363 | 53c25cea | Paul Brook | |
364 | aba800a3 | Michael S. Tsirkin | if (vdev->config_len)
|
365 | 53c25cea | Paul Brook | vdev->get_config(vdev, vdev->config); |
366 | aba800a3 | Michael S. Tsirkin | } |
367 | aba800a3 | Michael S. Tsirkin | |
368 | aba800a3 | Michael S. Tsirkin | static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, |
369 | aba800a3 | Michael S. Tsirkin | uint32_t val, int len)
|
370 | aba800a3 | Michael S. Tsirkin | { |
371 | ed757e14 | Yan Vugenfirer | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
372 | ed757e14 | Yan Vugenfirer | |
373 | ed757e14 | Yan Vugenfirer | if (PCI_COMMAND == address) {
|
374 | ed757e14 | Yan Vugenfirer | if (!(val & PCI_COMMAND_MASTER)) {
|
375 | ed757e14 | Yan Vugenfirer | proxy->vdev->status &= !VIRTIO_CONFIG_S_DRIVER_OK; |
376 | ed757e14 | Yan Vugenfirer | } |
377 | ed757e14 | Yan Vugenfirer | } |
378 | ed757e14 | Yan Vugenfirer | |
379 | aba800a3 | Michael S. Tsirkin | pci_default_write_config(pci_dev, address, val, len); |
380 | 85352471 | Michael S. Tsirkin | msix_write_config(pci_dev, address, val, len); |
381 | 53c25cea | Paul Brook | } |
382 | 53c25cea | Paul Brook | |
383 | 6d74ca5a | Michael S. Tsirkin | static unsigned virtio_pci_get_features(void *opaque) |
384 | 6d74ca5a | Michael S. Tsirkin | { |
385 | 6d74ca5a | Michael S. Tsirkin | unsigned ret = 0; |
386 | 6d74ca5a | Michael S. Tsirkin | ret |= (1 << VIRTIO_F_NOTIFY_ON_EMPTY);
|
387 | 6d74ca5a | Michael S. Tsirkin | ret |= (1 << VIRTIO_RING_F_INDIRECT_DESC);
|
388 | 6d74ca5a | Michael S. Tsirkin | ret |= (1 << VIRTIO_F_BAD_FEATURE);
|
389 | 6d74ca5a | Michael S. Tsirkin | return ret;
|
390 | 6d74ca5a | Michael S. Tsirkin | } |
391 | 6d74ca5a | Michael S. Tsirkin | |
392 | 53c25cea | Paul Brook | static const VirtIOBindings virtio_pci_bindings = { |
393 | ff24bd58 | Michael S. Tsirkin | .notify = virtio_pci_notify, |
394 | ff24bd58 | Michael S. Tsirkin | .save_config = virtio_pci_save_config, |
395 | ff24bd58 | Michael S. Tsirkin | .load_config = virtio_pci_load_config, |
396 | ff24bd58 | Michael S. Tsirkin | .save_queue = virtio_pci_save_queue, |
397 | ff24bd58 | Michael S. Tsirkin | .load_queue = virtio_pci_load_queue, |
398 | 6d74ca5a | Michael S. Tsirkin | .get_features = virtio_pci_get_features, |
399 | 53c25cea | Paul Brook | }; |
400 | 53c25cea | Paul Brook | |
401 | 53c25cea | Paul Brook | static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, |
402 | 53c25cea | Paul Brook | uint16_t vendor, uint16_t device, |
403 | 53c25cea | Paul Brook | uint16_t class_code, uint8_t pif) |
404 | 53c25cea | Paul Brook | { |
405 | 53c25cea | Paul Brook | uint8_t *config; |
406 | 53c25cea | Paul Brook | uint32_t size; |
407 | 53c25cea | Paul Brook | |
408 | 53c25cea | Paul Brook | proxy->vdev = vdev; |
409 | 53c25cea | Paul Brook | |
410 | 53c25cea | Paul Brook | config = proxy->pci_dev.config; |
411 | 53c25cea | Paul Brook | pci_config_set_vendor_id(config, vendor); |
412 | 53c25cea | Paul Brook | pci_config_set_device_id(config, device); |
413 | 53c25cea | Paul Brook | |
414 | 53c25cea | Paul Brook | config[0x08] = VIRTIO_PCI_ABI_VERSION;
|
415 | 53c25cea | Paul Brook | |
416 | 53c25cea | Paul Brook | config[0x09] = pif;
|
417 | 53c25cea | Paul Brook | pci_config_set_class(config, class_code); |
418 | 53c25cea | Paul Brook | config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; |
419 | 53c25cea | Paul Brook | |
420 | 53c25cea | Paul Brook | config[0x2c] = vendor & 0xFF; |
421 | 53c25cea | Paul Brook | config[0x2d] = (vendor >> 8) & 0xFF; |
422 | 53c25cea | Paul Brook | config[0x2e] = vdev->device_id & 0xFF; |
423 | 53c25cea | Paul Brook | config[0x2f] = (vdev->device_id >> 8) & 0xFF; |
424 | 53c25cea | Paul Brook | |
425 | 53c25cea | Paul Brook | config[0x3d] = 1; |
426 | 53c25cea | Paul Brook | |
427 | 5a1fc5e8 | Michael S. Tsirkin | if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) { |
428 | aba800a3 | Michael S. Tsirkin | pci_register_bar(&proxy->pci_dev, 1,
|
429 | aba800a3 | Michael S. Tsirkin | msix_bar_size(&proxy->pci_dev), |
430 | 0392a017 | Isaku Yamahata | PCI_BASE_ADDRESS_SPACE_MEMORY, |
431 | aba800a3 | Michael S. Tsirkin | msix_mmio_map); |
432 | aba800a3 | Michael S. Tsirkin | } else
|
433 | aba800a3 | Michael S. Tsirkin | vdev->nvectors = 0;
|
434 | aba800a3 | Michael S. Tsirkin | |
435 | ed757e14 | Yan Vugenfirer | proxy->pci_dev.config_write = virtio_write_config; |
436 | ed757e14 | Yan Vugenfirer | |
437 | aba800a3 | Michael S. Tsirkin | size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + vdev->config_len; |
438 | 53c25cea | Paul Brook | if (size & (size-1)) |
439 | 53c25cea | Paul Brook | size = 1 << qemu_fls(size);
|
440 | 53c25cea | Paul Brook | |
441 | 0392a017 | Isaku Yamahata | pci_register_bar(&proxy->pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO,
|
442 | 53c25cea | Paul Brook | virtio_map); |
443 | 53c25cea | Paul Brook | |
444 | 53c25cea | Paul Brook | virtio_bind_device(vdev, &virtio_pci_bindings, proxy); |
445 | 53c25cea | Paul Brook | } |
446 | 53c25cea | Paul Brook | |
447 | 81a322d4 | Gerd Hoffmann | static int virtio_blk_init_pci(PCIDevice *pci_dev) |
448 | 53c25cea | Paul Brook | { |
449 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
450 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
451 | 53c25cea | Paul Brook | |
452 | ab73ff29 | Gerd Hoffmann | if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
|
453 | ab73ff29 | Gerd Hoffmann | proxy->class_code != PCI_CLASS_STORAGE_OTHER) |
454 | ab73ff29 | Gerd Hoffmann | proxy->class_code = PCI_CLASS_STORAGE_SCSI; |
455 | 53c25cea | Paul Brook | |
456 | d176c495 | Gerd Hoffmann | if (!proxy->dinfo) {
|
457 | 84fc5589 | Gerd Hoffmann | qemu_error("virtio-blk-pci: drive property not set\n");
|
458 | 81a322d4 | Gerd Hoffmann | return -1; |
459 | d176c495 | Gerd Hoffmann | } |
460 | d176c495 | Gerd Hoffmann | vdev = virtio_blk_init(&pci_dev->qdev, proxy->dinfo); |
461 | 177539e0 | Gerd Hoffmann | vdev->nvectors = proxy->nvectors; |
462 | 53c25cea | Paul Brook | virtio_init_pci(proxy, vdev, |
463 | 53c25cea | Paul Brook | PCI_VENDOR_ID_REDHAT_QUMRANET, |
464 | 85c2c735 | Mark McLoughlin | PCI_DEVICE_ID_VIRTIO_BLOCK, |
465 | 85c2c735 | Mark McLoughlin | proxy->class_code, 0x00);
|
466 | 177539e0 | Gerd Hoffmann | /* make the actual value visible */
|
467 | 177539e0 | Gerd Hoffmann | proxy->nvectors = vdev->nvectors; |
468 | 81a322d4 | Gerd Hoffmann | return 0; |
469 | 21d58b57 | Mark McLoughlin | } |
470 | 21d58b57 | Mark McLoughlin | |
471 | 0f457d91 | Michael S. Tsirkin | static int virtio_exit_pci(PCIDevice *pci_dev) |
472 | 0f457d91 | Michael S. Tsirkin | { |
473 | 0f457d91 | Michael S. Tsirkin | return msix_uninit(pci_dev);
|
474 | 0f457d91 | Michael S. Tsirkin | } |
475 | 0f457d91 | Michael S. Tsirkin | |
476 | 56a14938 | Gerd Hoffmann | static int virtio_blk_exit_pci(PCIDevice *pci_dev) |
477 | 56a14938 | Gerd Hoffmann | { |
478 | 56a14938 | Gerd Hoffmann | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
479 | 56a14938 | Gerd Hoffmann | |
480 | 56a14938 | Gerd Hoffmann | drive_uninit(proxy->dinfo); |
481 | 0f457d91 | Michael S. Tsirkin | return virtio_exit_pci(pci_dev);
|
482 | 56a14938 | Gerd Hoffmann | } |
483 | 56a14938 | Gerd Hoffmann | |
484 | 81a322d4 | Gerd Hoffmann | static int virtio_console_init_pci(PCIDevice *pci_dev) |
485 | 21d58b57 | Mark McLoughlin | { |
486 | d6beee99 | Gerd Hoffmann | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
487 | 85c2c735 | Mark McLoughlin | VirtIODevice *vdev; |
488 | 85c2c735 | Mark McLoughlin | |
489 | d6beee99 | Gerd Hoffmann | if (proxy->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
|
490 | d6beee99 | Gerd Hoffmann | proxy->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
|
491 | d6beee99 | Gerd Hoffmann | proxy->class_code != PCI_CLASS_OTHERS) /* qemu-kvm */
|
492 | d6beee99 | Gerd Hoffmann | proxy->class_code = PCI_CLASS_COMMUNICATION_OTHER; |
493 | d6beee99 | Gerd Hoffmann | |
494 | 85c2c735 | Mark McLoughlin | vdev = virtio_console_init(&pci_dev->qdev); |
495 | 25fe3654 | Amit Shah | if (!vdev) {
|
496 | 25fe3654 | Amit Shah | return -1; |
497 | 25fe3654 | Amit Shah | } |
498 | 85c2c735 | Mark McLoughlin | virtio_init_pci(proxy, vdev, |
499 | 85c2c735 | Mark McLoughlin | PCI_VENDOR_ID_REDHAT_QUMRANET, |
500 | 85c2c735 | Mark McLoughlin | PCI_DEVICE_ID_VIRTIO_CONSOLE, |
501 | 85c2c735 | Mark McLoughlin | proxy->class_code, 0x00);
|
502 | 81a322d4 | Gerd Hoffmann | return 0; |
503 | 53c25cea | Paul Brook | } |
504 | 53c25cea | Paul Brook | |
505 | 81a322d4 | Gerd Hoffmann | static int virtio_net_init_pci(PCIDevice *pci_dev) |
506 | 53c25cea | Paul Brook | { |
507 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
508 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
509 | 53c25cea | Paul Brook | |
510 | 97b15621 | Gerd Hoffmann | vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic); |
511 | a1e0fea5 | Gerd Hoffmann | |
512 | 97b15621 | Gerd Hoffmann | vdev->nvectors = proxy->nvectors; |
513 | 53c25cea | Paul Brook | virtio_init_pci(proxy, vdev, |
514 | 53c25cea | Paul Brook | PCI_VENDOR_ID_REDHAT_QUMRANET, |
515 | 53c25cea | Paul Brook | PCI_DEVICE_ID_VIRTIO_NET, |
516 | 53c25cea | Paul Brook | PCI_CLASS_NETWORK_ETHERNET, |
517 | 53c25cea | Paul Brook | 0x00);
|
518 | a1e0fea5 | Gerd Hoffmann | |
519 | a1e0fea5 | Gerd Hoffmann | /* make the actual value visible */
|
520 | a1e0fea5 | Gerd Hoffmann | proxy->nvectors = vdev->nvectors; |
521 | 81a322d4 | Gerd Hoffmann | return 0; |
522 | 53c25cea | Paul Brook | } |
523 | 53c25cea | Paul Brook | |
524 | 97b15621 | Gerd Hoffmann | static int virtio_net_exit_pci(PCIDevice *pci_dev) |
525 | 97b15621 | Gerd Hoffmann | { |
526 | 97b15621 | Gerd Hoffmann | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
527 | 97b15621 | Gerd Hoffmann | |
528 | 97b15621 | Gerd Hoffmann | virtio_net_exit(proxy->vdev); |
529 | 97b15621 | Gerd Hoffmann | return virtio_exit_pci(pci_dev);
|
530 | 97b15621 | Gerd Hoffmann | } |
531 | 97b15621 | Gerd Hoffmann | |
532 | 81a322d4 | Gerd Hoffmann | static int virtio_balloon_init_pci(PCIDevice *pci_dev) |
533 | 53c25cea | Paul Brook | { |
534 | 53c25cea | Paul Brook | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); |
535 | 53c25cea | Paul Brook | VirtIODevice *vdev; |
536 | 53c25cea | Paul Brook | |
537 | 53c25cea | Paul Brook | vdev = virtio_balloon_init(&pci_dev->qdev); |
538 | 53c25cea | Paul Brook | virtio_init_pci(proxy, vdev, |
539 | 53c25cea | Paul Brook | PCI_VENDOR_ID_REDHAT_QUMRANET, |
540 | 53c25cea | Paul Brook | PCI_DEVICE_ID_VIRTIO_BALLOON, |
541 | 53c25cea | Paul Brook | PCI_CLASS_MEMORY_RAM, |
542 | 53c25cea | Paul Brook | 0x00);
|
543 | 81a322d4 | Gerd Hoffmann | return 0; |
544 | 53c25cea | Paul Brook | } |
545 | 53c25cea | Paul Brook | |
546 | 0aab0d3a | Gerd Hoffmann | static PCIDeviceInfo virtio_info[] = {
|
547 | 0aab0d3a | Gerd Hoffmann | { |
548 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "virtio-blk-pci",
|
549 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
550 | 0aab0d3a | Gerd Hoffmann | .init = virtio_blk_init_pci, |
551 | 56a14938 | Gerd Hoffmann | .exit = virtio_blk_exit_pci, |
552 | ab73ff29 | Gerd Hoffmann | .qdev.props = (Property[]) { |
553 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), |
554 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_DRIVE("drive", VirtIOPCIProxy, dinfo),
|
555 | 177539e0 | Gerd Hoffmann | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), |
556 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
557 | ab73ff29 | Gerd Hoffmann | }, |
558 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
559 | 0aab0d3a | Gerd Hoffmann | },{ |
560 | a1e0fea5 | Gerd Hoffmann | .qdev.name = "virtio-net-pci",
|
561 | a1e0fea5 | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
562 | a1e0fea5 | Gerd Hoffmann | .init = virtio_net_init_pci, |
563 | 97b15621 | Gerd Hoffmann | .exit = virtio_net_exit_pci, |
564 | 8c52c8f3 | Gerd Hoffmann | .romfile = "pxe-virtio.bin",
|
565 | a1e0fea5 | Gerd Hoffmann | .qdev.props = (Property[]) { |
566 | 97b15621 | Gerd Hoffmann | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), |
567 | 97b15621 | Gerd Hoffmann | DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic), |
568 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
569 | a1e0fea5 | Gerd Hoffmann | }, |
570 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
571 | 0aab0d3a | Gerd Hoffmann | },{ |
572 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "virtio-console-pci",
|
573 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
574 | 0aab0d3a | Gerd Hoffmann | .init = virtio_console_init_pci, |
575 | 0f457d91 | Michael S. Tsirkin | .exit = virtio_exit_pci, |
576 | d6beee99 | Gerd Hoffmann | .qdev.props = (Property[]) { |
577 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), |
578 | 72c61d0b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
579 | d6beee99 | Gerd Hoffmann | }, |
580 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
581 | 0aab0d3a | Gerd Hoffmann | },{ |
582 | 0aab0d3a | Gerd Hoffmann | .qdev.name = "virtio-balloon-pci",
|
583 | 0aab0d3a | Gerd Hoffmann | .qdev.size = sizeof(VirtIOPCIProxy),
|
584 | 0aab0d3a | Gerd Hoffmann | .init = virtio_balloon_init_pci, |
585 | 0f457d91 | Michael S. Tsirkin | .exit = virtio_exit_pci, |
586 | e489030d | Michael S. Tsirkin | .qdev.reset = virtio_pci_reset, |
587 | 0aab0d3a | Gerd Hoffmann | },{ |
588 | 0aab0d3a | Gerd Hoffmann | /* end of list */
|
589 | 0aab0d3a | Gerd Hoffmann | } |
590 | 0aab0d3a | Gerd Hoffmann | }; |
591 | 0aab0d3a | Gerd Hoffmann | |
592 | 53c25cea | Paul Brook | static void virtio_pci_register_devices(void) |
593 | 53c25cea | Paul Brook | { |
594 | 0aab0d3a | Gerd Hoffmann | pci_qdev_register_many(virtio_info); |
595 | 53c25cea | Paul Brook | } |
596 | 53c25cea | Paul Brook | |
597 | 53c25cea | Paul Brook | device_init(virtio_pci_register_devices) |