File: | hw/virtio/virtio-pci.c |
Location: | line 529, column 62 |
Description: | Access to field 'virq' results in a dereference of a null pointer (loaded from variable 'irqfd') |
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 | * Contributions after 2012-01-13 are licensed under the terms of the | |||
15 | * GNU GPL, version 2 or (at your option) any later version. | |||
16 | */ | |||
17 | ||||
18 | #include <inttypes.h> | |||
19 | ||||
20 | #include "hw/virtio/virtio.h" | |||
21 | #include "hw/virtio/virtio-blk.h" | |||
22 | #include "hw/virtio/virtio-net.h" | |||
23 | #include "hw/virtio/virtio-serial.h" | |||
24 | #include "hw/virtio/virtio-scsi.h" | |||
25 | #include "hw/virtio/virtio-balloon.h" | |||
26 | #include "hw/pci/pci.h" | |||
27 | #include "qemu/error-report.h" | |||
28 | #include "hw/pci/msi.h" | |||
29 | #include "hw/pci/msix.h" | |||
30 | #include "hw/loader.h" | |||
31 | #include "sysemu/kvm.h" | |||
32 | #include "sysemu/blockdev.h" | |||
33 | #include "virtio-pci.h" | |||
34 | #include "qemu/range.h" | |||
35 | #include "hw/virtio/virtio-bus.h" | |||
36 | #include "qapi/visitor.h" | |||
37 | ||||
38 | /* from Linux's linux/virtio_pci.h */ | |||
39 | ||||
40 | /* A 32-bit r/o bitmask of the features supported by the host */ | |||
41 | #define VIRTIO_PCI_HOST_FEATURES0 0 | |||
42 | ||||
43 | /* A 32-bit r/w bitmask of features activated by the guest */ | |||
44 | #define VIRTIO_PCI_GUEST_FEATURES4 4 | |||
45 | ||||
46 | /* A 32-bit r/w PFN for the currently selected queue */ | |||
47 | #define VIRTIO_PCI_QUEUE_PFN8 8 | |||
48 | ||||
49 | /* A 16-bit r/o queue size for the currently selected queue */ | |||
50 | #define VIRTIO_PCI_QUEUE_NUM12 12 | |||
51 | ||||
52 | /* A 16-bit r/w queue selector */ | |||
53 | #define VIRTIO_PCI_QUEUE_SEL14 14 | |||
54 | ||||
55 | /* A 16-bit r/w queue notifier */ | |||
56 | #define VIRTIO_PCI_QUEUE_NOTIFY16 16 | |||
57 | ||||
58 | /* An 8-bit device status register. */ | |||
59 | #define VIRTIO_PCI_STATUS18 18 | |||
60 | ||||
61 | /* An 8-bit r/o interrupt status register. Reading the value will return the | |||
62 | * current contents of the ISR and will also clear it. This is effectively | |||
63 | * a read-and-acknowledge. */ | |||
64 | #define VIRTIO_PCI_ISR19 19 | |||
65 | ||||
66 | /* MSI-X registers: only enabled if MSI-X is enabled. */ | |||
67 | /* A 16-bit vector for configuration changes. */ | |||
68 | #define VIRTIO_MSI_CONFIG_VECTOR20 20 | |||
69 | /* A 16-bit vector for selected queue notifications. */ | |||
70 | #define VIRTIO_MSI_QUEUE_VECTOR22 22 | |||
71 | ||||
72 | /* Config space size */ | |||
73 | #define VIRTIO_PCI_CONFIG_NOMSI20 20 | |||
74 | #define VIRTIO_PCI_CONFIG_MSI24 24 | |||
75 | #define VIRTIO_PCI_REGION_SIZE(dev)(msix_present(dev) ? 24 : 20) (msix_present(dev) ? \ | |||
76 | VIRTIO_PCI_CONFIG_MSI24 : \ | |||
77 | VIRTIO_PCI_CONFIG_NOMSI20) | |||
78 | ||||
79 | /* The remaining space is defined by each driver as the per-driver | |||
80 | * configuration space */ | |||
81 | #define VIRTIO_PCI_CONFIG(dev)(msix_enabled(dev) ? 24 : 20) (msix_enabled(dev) ? \ | |||
82 | VIRTIO_PCI_CONFIG_MSI24 : \ | |||
83 | VIRTIO_PCI_CONFIG_NOMSI20) | |||
84 | ||||
85 | /* How many bits to shift physical queue address written to QUEUE_PFN. | |||
86 | * 12 is historical, and due to x86 page size. */ | |||
87 | #define VIRTIO_PCI_QUEUE_ADDR_SHIFT12 12 | |||
88 | ||||
89 | /* Flags track per-device state like workarounds for quirks in older guests. */ | |||
90 | #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG(1 << 0) (1 << 0) | |||
91 | ||||
92 | /* HACK for virtio to determine if it's running a big endian guest */ | |||
93 | bool_Bool virtio_is_big_endian(void); | |||
94 | ||||
95 | static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size, | |||
96 | VirtIOPCIProxy *dev); | |||
97 | ||||
98 | /* virtio device */ | |||
99 | /* DeviceState to VirtIOPCIProxy. For use off data-path. TODO: use QOM. */ | |||
100 | static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d) | |||
101 | { | |||
102 | return container_of(d, VirtIOPCIProxy, pci_dev.qdev)({ const typeof(((VirtIOPCIProxy *) 0)->pci_dev.qdev) *__mptr = (d); (VirtIOPCIProxy *) ((char *) __mptr - __builtin_offsetof (VirtIOPCIProxy, pci_dev.qdev));}); | |||
103 | } | |||
104 | ||||
105 | /* DeviceState to VirtIOPCIProxy. Note: used on datapath, | |||
106 | * be careful and test performance if you change this. | |||
107 | */ | |||
108 | static inline VirtIOPCIProxy *to_virtio_pci_proxy_fast(DeviceState *d) | |||
109 | { | |||
110 | return container_of(d, VirtIOPCIProxy, pci_dev.qdev)({ const typeof(((VirtIOPCIProxy *) 0)->pci_dev.qdev) *__mptr = (d); (VirtIOPCIProxy *) ((char *) __mptr - __builtin_offsetof (VirtIOPCIProxy, pci_dev.qdev));}); | |||
111 | } | |||
112 | ||||
113 | static void virtio_pci_notify(DeviceState *d, uint16_t vector) | |||
114 | { | |||
115 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy_fast(d); | |||
116 | ||||
117 | if (msix_enabled(&proxy->pci_dev)) | |||
118 | msix_notify(&proxy->pci_dev, vector); | |||
119 | else { | |||
120 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
121 | pci_set_irq(&proxy->pci_dev, vdev->isr & 1); | |||
122 | } | |||
123 | } | |||
124 | ||||
125 | static void virtio_pci_save_config(DeviceState *d, QEMUFile *f) | |||
126 | { | |||
127 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
128 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
129 | ||||
130 | pci_device_save(&proxy->pci_dev, f); | |||
131 | msix_save(&proxy->pci_dev, f); | |||
132 | if (msix_present(&proxy->pci_dev)) | |||
133 | qemu_put_be16(f, vdev->config_vector); | |||
134 | } | |||
135 | ||||
136 | static void virtio_pci_save_queue(DeviceState *d, int n, QEMUFile *f) | |||
137 | { | |||
138 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
139 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
140 | ||||
141 | if (msix_present(&proxy->pci_dev)) | |||
142 | qemu_put_be16(f, virtio_queue_vector(vdev, n)); | |||
143 | } | |||
144 | ||||
145 | static int virtio_pci_load_config(DeviceState *d, QEMUFile *f) | |||
146 | { | |||
147 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
148 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
149 | ||||
150 | int ret; | |||
151 | ret = pci_device_load(&proxy->pci_dev, f); | |||
152 | if (ret) { | |||
153 | return ret; | |||
154 | } | |||
155 | msix_unuse_all_vectors(&proxy->pci_dev); | |||
156 | msix_load(&proxy->pci_dev, f); | |||
157 | if (msix_present(&proxy->pci_dev)) { | |||
158 | qemu_get_be16s(f, &vdev->config_vector); | |||
159 | } else { | |||
160 | vdev->config_vector = VIRTIO_NO_VECTOR0xffff; | |||
161 | } | |||
162 | if (vdev->config_vector != VIRTIO_NO_VECTOR0xffff) { | |||
163 | return msix_vector_use(&proxy->pci_dev, vdev->config_vector); | |||
164 | } | |||
165 | return 0; | |||
166 | } | |||
167 | ||||
168 | static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f) | |||
169 | { | |||
170 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
171 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
172 | ||||
173 | uint16_t vector; | |||
174 | if (msix_present(&proxy->pci_dev)) { | |||
175 | qemu_get_be16s(f, &vector); | |||
176 | } else { | |||
177 | vector = VIRTIO_NO_VECTOR0xffff; | |||
178 | } | |||
179 | virtio_queue_set_vector(vdev, n, vector); | |||
180 | if (vector != VIRTIO_NO_VECTOR0xffff) { | |||
181 | return msix_vector_use(&proxy->pci_dev, vector); | |||
182 | } | |||
183 | return 0; | |||
184 | } | |||
185 | ||||
186 | static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy, | |||
187 | int n, bool_Bool assign, bool_Bool set_handler) | |||
188 | { | |||
189 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
190 | VirtQueue *vq = virtio_get_queue(vdev, n); | |||
191 | EventNotifier *notifier = virtio_queue_get_host_notifier(vq); | |||
192 | int r = 0; | |||
193 | ||||
194 | if (assign) { | |||
195 | r = event_notifier_init(notifier, 1); | |||
196 | if (r < 0) { | |||
197 | error_report("%s: unable to init event notifier: %d", | |||
198 | __func__, r); | |||
199 | return r; | |||
200 | } | |||
201 | virtio_queue_set_host_notifier_fd_handler(vq, true1, set_handler); | |||
202 | memory_region_add_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY16, 2, | |||
203 | true1, n, notifier); | |||
204 | } else { | |||
205 | memory_region_del_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY16, 2, | |||
206 | true1, n, notifier); | |||
207 | virtio_queue_set_host_notifier_fd_handler(vq, false0, false0); | |||
208 | event_notifier_cleanup(notifier); | |||
209 | } | |||
210 | return r; | |||
211 | } | |||
212 | ||||
213 | static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy) | |||
214 | { | |||
215 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
216 | int n, r; | |||
217 | ||||
218 | if (!(proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD(1 << 1)) || | |||
219 | proxy->ioeventfd_disabled || | |||
220 | proxy->ioeventfd_started) { | |||
221 | return; | |||
222 | } | |||
223 | ||||
224 | for (n = 0; n < VIRTIO_PCI_QUEUE_MAX64; n++) { | |||
225 | if (!virtio_queue_get_num(vdev, n)) { | |||
226 | continue; | |||
227 | } | |||
228 | ||||
229 | r = virtio_pci_set_host_notifier_internal(proxy, n, true1, true1); | |||
230 | if (r < 0) { | |||
231 | goto assign_error; | |||
232 | } | |||
233 | } | |||
234 | proxy->ioeventfd_started = true1; | |||
235 | return; | |||
236 | ||||
237 | assign_error: | |||
238 | while (--n >= 0) { | |||
239 | if (!virtio_queue_get_num(vdev, n)) { | |||
240 | continue; | |||
241 | } | |||
242 | ||||
243 | r = virtio_pci_set_host_notifier_internal(proxy, n, false0, false0); | |||
244 | assert(r >= 0)((r >= 0) ? (void) (0) : __assert_fail ("r >= 0", "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 244, __PRETTY_FUNCTION__)); | |||
245 | } | |||
246 | proxy->ioeventfd_started = false0; | |||
247 | error_report("%s: failed. Fallback to a userspace (slower).", __func__); | |||
248 | } | |||
249 | ||||
250 | static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy) | |||
251 | { | |||
252 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
253 | int r; | |||
254 | int n; | |||
255 | ||||
256 | if (!proxy->ioeventfd_started) { | |||
257 | return; | |||
258 | } | |||
259 | ||||
260 | for (n = 0; n < VIRTIO_PCI_QUEUE_MAX64; n++) { | |||
261 | if (!virtio_queue_get_num(vdev, n)) { | |||
262 | continue; | |||
263 | } | |||
264 | ||||
265 | r = virtio_pci_set_host_notifier_internal(proxy, n, false0, false0); | |||
266 | assert(r >= 0)((r >= 0) ? (void) (0) : __assert_fail ("r >= 0", "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 266, __PRETTY_FUNCTION__)); | |||
267 | } | |||
268 | proxy->ioeventfd_started = false0; | |||
269 | } | |||
270 | ||||
271 | static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) | |||
272 | { | |||
273 | VirtIOPCIProxy *proxy = opaque; | |||
274 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
275 | hwaddr pa; | |||
276 | ||||
277 | switch (addr) { | |||
278 | case VIRTIO_PCI_GUEST_FEATURES4: | |||
279 | /* Guest does not negotiate properly? We have to assume nothing. */ | |||
280 | if (val & (1 << VIRTIO_F_BAD_FEATURE30)) { | |||
281 | val = virtio_bus_get_vdev_bad_features(&proxy->bus); | |||
282 | } | |||
283 | virtio_set_features(vdev, val); | |||
284 | break; | |||
285 | case VIRTIO_PCI_QUEUE_PFN8: | |||
286 | pa = (hwaddr)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT12; | |||
287 | if (pa == 0) { | |||
288 | virtio_pci_stop_ioeventfd(proxy); | |||
289 | virtio_reset(vdev); | |||
290 | msix_unuse_all_vectors(&proxy->pci_dev); | |||
291 | } | |||
292 | else | |||
293 | virtio_queue_set_addr(vdev, vdev->queue_sel, pa); | |||
294 | break; | |||
295 | case VIRTIO_PCI_QUEUE_SEL14: | |||
296 | if (val < VIRTIO_PCI_QUEUE_MAX64) | |||
297 | vdev->queue_sel = val; | |||
298 | break; | |||
299 | case VIRTIO_PCI_QUEUE_NOTIFY16: | |||
300 | if (val < VIRTIO_PCI_QUEUE_MAX64) { | |||
301 | virtio_queue_notify(vdev, val); | |||
302 | } | |||
303 | break; | |||
304 | case VIRTIO_PCI_STATUS18: | |||
305 | if (!(val & VIRTIO_CONFIG_S_DRIVER_OK4)) { | |||
306 | virtio_pci_stop_ioeventfd(proxy); | |||
307 | } | |||
308 | ||||
309 | virtio_set_status(vdev, val & 0xFF); | |||
310 | ||||
311 | if (val & VIRTIO_CONFIG_S_DRIVER_OK4) { | |||
312 | virtio_pci_start_ioeventfd(proxy); | |||
313 | } | |||
314 | ||||
315 | if (vdev->status == 0) { | |||
316 | virtio_reset(vdev); | |||
317 | msix_unuse_all_vectors(&proxy->pci_dev); | |||
318 | } | |||
319 | ||||
320 | /* Linux before 2.6.34 sets the device as OK without enabling | |||
321 | the PCI device bus master bit. In this case we need to disable | |||
322 | some safety checks. */ | |||
323 | if ((val & VIRTIO_CONFIG_S_DRIVER_OK4) && | |||
324 | !(proxy->pci_dev.config[PCI_COMMAND0x04] & PCI_COMMAND_MASTER0x4)) { | |||
325 | proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG(1 << 0); | |||
326 | } | |||
327 | break; | |||
328 | case VIRTIO_MSI_CONFIG_VECTOR20: | |||
329 | msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); | |||
330 | /* Make it possible for guest to discover an error took place. */ | |||
331 | if (msix_vector_use(&proxy->pci_dev, val) < 0) | |||
332 | val = VIRTIO_NO_VECTOR0xffff; | |||
333 | vdev->config_vector = val; | |||
334 | break; | |||
335 | case VIRTIO_MSI_QUEUE_VECTOR22: | |||
336 | msix_vector_unuse(&proxy->pci_dev, | |||
337 | virtio_queue_vector(vdev, vdev->queue_sel)); | |||
338 | /* Make it possible for guest to discover an error took place. */ | |||
339 | if (msix_vector_use(&proxy->pci_dev, val) < 0) | |||
340 | val = VIRTIO_NO_VECTOR0xffff; | |||
341 | virtio_queue_set_vector(vdev, vdev->queue_sel, val); | |||
342 | break; | |||
343 | default: | |||
344 | error_report("%s: unexpected address 0x%x value 0x%x", | |||
345 | __func__, addr, val); | |||
346 | break; | |||
347 | } | |||
348 | } | |||
349 | ||||
350 | static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr) | |||
351 | { | |||
352 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
353 | uint32_t ret = 0xFFFFFFFF; | |||
354 | ||||
355 | switch (addr) { | |||
356 | case VIRTIO_PCI_HOST_FEATURES0: | |||
357 | ret = proxy->host_features; | |||
358 | break; | |||
359 | case VIRTIO_PCI_GUEST_FEATURES4: | |||
360 | ret = vdev->guest_features; | |||
361 | break; | |||
362 | case VIRTIO_PCI_QUEUE_PFN8: | |||
363 | ret = virtio_queue_get_addr(vdev, vdev->queue_sel) | |||
364 | >> VIRTIO_PCI_QUEUE_ADDR_SHIFT12; | |||
365 | break; | |||
366 | case VIRTIO_PCI_QUEUE_NUM12: | |||
367 | ret = virtio_queue_get_num(vdev, vdev->queue_sel); | |||
368 | break; | |||
369 | case VIRTIO_PCI_QUEUE_SEL14: | |||
370 | ret = vdev->queue_sel; | |||
371 | break; | |||
372 | case VIRTIO_PCI_STATUS18: | |||
373 | ret = vdev->status; | |||
374 | break; | |||
375 | case VIRTIO_PCI_ISR19: | |||
376 | /* reading from the ISR also clears it. */ | |||
377 | ret = vdev->isr; | |||
378 | vdev->isr = 0; | |||
379 | pci_irq_deassert(&proxy->pci_dev); | |||
380 | break; | |||
381 | case VIRTIO_MSI_CONFIG_VECTOR20: | |||
382 | ret = vdev->config_vector; | |||
383 | break; | |||
384 | case VIRTIO_MSI_QUEUE_VECTOR22: | |||
385 | ret = virtio_queue_vector(vdev, vdev->queue_sel); | |||
386 | break; | |||
387 | default: | |||
388 | break; | |||
389 | } | |||
390 | ||||
391 | return ret; | |||
392 | } | |||
393 | ||||
394 | static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr, | |||
395 | unsigned size) | |||
396 | { | |||
397 | VirtIOPCIProxy *proxy = opaque; | |||
398 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
399 | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev)(msix_enabled(&proxy->pci_dev) ? 24 : 20); | |||
400 | uint64_t val = 0; | |||
401 | if (addr < config) { | |||
402 | return virtio_ioport_read(proxy, addr); | |||
403 | } | |||
404 | addr -= config; | |||
405 | ||||
406 | switch (size) { | |||
407 | case 1: | |||
408 | val = virtio_config_readb(vdev, addr); | |||
409 | break; | |||
410 | case 2: | |||
411 | val = virtio_config_readw(vdev, addr); | |||
412 | if (virtio_is_big_endian()) { | |||
413 | val = bswap16(val); | |||
414 | } | |||
415 | break; | |||
416 | case 4: | |||
417 | val = virtio_config_readl(vdev, addr); | |||
418 | if (virtio_is_big_endian()) { | |||
419 | val = bswap32(val); | |||
420 | } | |||
421 | break; | |||
422 | } | |||
423 | return val; | |||
424 | } | |||
425 | ||||
426 | static void virtio_pci_config_write(void *opaque, hwaddr addr, | |||
427 | uint64_t val, unsigned size) | |||
428 | { | |||
429 | VirtIOPCIProxy *proxy = opaque; | |||
430 | uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev)(msix_enabled(&proxy->pci_dev) ? 24 : 20); | |||
431 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
432 | if (addr < config) { | |||
433 | virtio_ioport_write(proxy, addr, val); | |||
434 | return; | |||
435 | } | |||
436 | addr -= config; | |||
437 | /* | |||
438 | * Virtio-PCI is odd. Ioports are LE but config space is target native | |||
439 | * endian. | |||
440 | */ | |||
441 | switch (size) { | |||
442 | case 1: | |||
443 | virtio_config_writeb(vdev, addr, val); | |||
444 | break; | |||
445 | case 2: | |||
446 | if (virtio_is_big_endian()) { | |||
447 | val = bswap16(val); | |||
448 | } | |||
449 | virtio_config_writew(vdev, addr, val); | |||
450 | break; | |||
451 | case 4: | |||
452 | if (virtio_is_big_endian()) { | |||
453 | val = bswap32(val); | |||
454 | } | |||
455 | virtio_config_writel(vdev, addr, val); | |||
456 | break; | |||
457 | } | |||
458 | } | |||
459 | ||||
460 | static const MemoryRegionOps virtio_pci_config_ops = { | |||
461 | .read = virtio_pci_config_read, | |||
462 | .write = virtio_pci_config_write, | |||
463 | .impl = { | |||
464 | .min_access_size = 1, | |||
465 | .max_access_size = 4, | |||
466 | }, | |||
467 | .endianness = DEVICE_LITTLE_ENDIAN, | |||
468 | }; | |||
469 | ||||
470 | static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, | |||
471 | uint32_t val, int len) | |||
472 | { | |||
473 | VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev)( __extension__ ( { char __attribute__((unused)) offset_must_be_zero [ -__builtin_offsetof(VirtIOPCIProxy, pci_dev)]; ({ const typeof (((VirtIOPCIProxy *) 0)->pci_dev) *__mptr = (pci_dev); (VirtIOPCIProxy *) ((char *) __mptr - __builtin_offsetof(VirtIOPCIProxy, pci_dev ));});})); | |||
474 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
475 | ||||
476 | pci_default_write_config(pci_dev, address, val, len); | |||
477 | ||||
478 | if (range_covers_byte(address, len, PCI_COMMAND0x04) && | |||
479 | !(pci_dev->config[PCI_COMMAND0x04] & PCI_COMMAND_MASTER0x4) && | |||
480 | !(proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG(1 << 0))) { | |||
481 | virtio_pci_stop_ioeventfd(proxy); | |||
482 | virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK4); | |||
483 | } | |||
484 | } | |||
485 | ||||
486 | static unsigned virtio_pci_get_features(DeviceState *d) | |||
487 | { | |||
488 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
489 | return proxy->host_features; | |||
490 | } | |||
491 | ||||
492 | static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy, | |||
493 | unsigned int queue_no, | |||
494 | unsigned int vector, | |||
495 | MSIMessage msg) | |||
496 | { | |||
497 | VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; | |||
498 | int ret; | |||
499 | ||||
500 | if (irqfd->users == 0) { | |||
501 | ret = kvm_irqchip_add_msi_route(kvm_state, msg); | |||
502 | if (ret < 0) { | |||
503 | return ret; | |||
504 | } | |||
505 | irqfd->virq = ret; | |||
506 | } | |||
507 | irqfd->users++; | |||
508 | return 0; | |||
509 | } | |||
510 | ||||
511 | static void kvm_virtio_pci_vq_vector_release(VirtIOPCIProxy *proxy, | |||
512 | unsigned int vector) | |||
513 | { | |||
514 | VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; | |||
515 | if (--irqfd->users == 0) { | |||
516 | kvm_irqchip_release_virq(kvm_state, irqfd->virq); | |||
517 | } | |||
518 | } | |||
519 | ||||
520 | static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy, | |||
521 | unsigned int queue_no, | |||
522 | unsigned int vector) | |||
523 | { | |||
524 | VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; | |||
525 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
526 | VirtQueue *vq = virtio_get_queue(vdev, queue_no); | |||
527 | EventNotifier *n = virtio_queue_get_guest_notifier(vq); | |||
528 | int ret; | |||
529 | ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL((void*)0), irqfd->virq); | |||
| ||||
530 | return ret; | |||
531 | } | |||
532 | ||||
533 | static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy, | |||
534 | unsigned int queue_no, | |||
535 | unsigned int vector) | |||
536 | { | |||
537 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
538 | VirtQueue *vq = virtio_get_queue(vdev, queue_no); | |||
539 | EventNotifier *n = virtio_queue_get_guest_notifier(vq); | |||
540 | VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; | |||
541 | int ret; | |||
542 | ||||
543 | ret = kvm_irqchip_remove_irqfd_notifier(kvm_state, n, irqfd->virq); | |||
544 | assert(ret == 0)((ret == 0) ? (void) (0) : __assert_fail ("ret == 0", "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 544, __PRETTY_FUNCTION__)); | |||
545 | } | |||
546 | ||||
547 | static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs) | |||
548 | { | |||
549 | PCIDevice *dev = &proxy->pci_dev; | |||
550 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
551 | VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev)((VirtioDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)(object_get_class(((Object *)(vdev))))), ("virtio-device") , "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 551, __func__)); | |||
552 | unsigned int vector; | |||
553 | int ret, queue_no; | |||
554 | MSIMessage msg; | |||
555 | ||||
556 | for (queue_no = 0; queue_no < nvqs; queue_no++) { | |||
557 | if (!virtio_queue_get_num(vdev, queue_no)) { | |||
558 | break; | |||
559 | } | |||
560 | vector = virtio_queue_vector(vdev, queue_no); | |||
561 | if (vector >= msix_nr_vectors_allocated(dev)) { | |||
562 | continue; | |||
563 | } | |||
564 | msg = msix_get_message(dev, vector); | |||
565 | ret = kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector, msg); | |||
566 | if (ret < 0) { | |||
567 | goto undo; | |||
568 | } | |||
569 | /* If guest supports masking, set up irqfd now. | |||
570 | * Otherwise, delay until unmasked in the frontend. | |||
571 | */ | |||
572 | if (k->guest_notifier_mask) { | |||
573 | ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector); | |||
574 | if (ret < 0) { | |||
575 | kvm_virtio_pci_vq_vector_release(proxy, vector); | |||
576 | goto undo; | |||
577 | } | |||
578 | } | |||
579 | } | |||
580 | return 0; | |||
581 | ||||
582 | undo: | |||
583 | while (--queue_no >= 0) { | |||
584 | vector = virtio_queue_vector(vdev, queue_no); | |||
585 | if (vector >= msix_nr_vectors_allocated(dev)) { | |||
586 | continue; | |||
587 | } | |||
588 | if (k->guest_notifier_mask) { | |||
589 | kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); | |||
590 | } | |||
591 | kvm_virtio_pci_vq_vector_release(proxy, vector); | |||
592 | } | |||
593 | return ret; | |||
594 | } | |||
595 | ||||
596 | static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs) | |||
597 | { | |||
598 | PCIDevice *dev = &proxy->pci_dev; | |||
599 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
600 | unsigned int vector; | |||
601 | int queue_no; | |||
602 | VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev)((VirtioDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)(object_get_class(((Object *)(vdev))))), ("virtio-device") , "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 602, __func__)); | |||
603 | ||||
604 | for (queue_no = 0; queue_no < nvqs; queue_no++) { | |||
605 | if (!virtio_queue_get_num(vdev, queue_no)) { | |||
606 | break; | |||
607 | } | |||
608 | vector = virtio_queue_vector(vdev, queue_no); | |||
609 | if (vector >= msix_nr_vectors_allocated(dev)) { | |||
610 | continue; | |||
611 | } | |||
612 | /* If guest supports masking, clean up irqfd now. | |||
613 | * Otherwise, it was cleaned when masked in the frontend. | |||
614 | */ | |||
615 | if (k->guest_notifier_mask) { | |||
616 | kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); | |||
617 | } | |||
618 | kvm_virtio_pci_vq_vector_release(proxy, vector); | |||
619 | } | |||
620 | } | |||
621 | ||||
622 | static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy, | |||
623 | unsigned int queue_no, | |||
624 | unsigned int vector, | |||
625 | MSIMessage msg) | |||
626 | { | |||
627 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
628 | VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev)((VirtioDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)(object_get_class(((Object *)(vdev))))), ("virtio-device") , "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 628, __func__)); | |||
629 | VirtQueue *vq = virtio_get_queue(vdev, queue_no); | |||
630 | EventNotifier *n = virtio_queue_get_guest_notifier(vq); | |||
631 | VirtIOIRQFD *irqfd; | |||
632 | int ret = 0; | |||
633 | ||||
634 | if (proxy->vector_irqfd) { | |||
635 | irqfd = &proxy->vector_irqfd[vector]; | |||
636 | if (irqfd->msg.data != msg.data || irqfd->msg.address != msg.address) { | |||
637 | ret = kvm_irqchip_update_msi_route(kvm_state, irqfd->virq, msg); | |||
638 | if (ret < 0) { | |||
639 | return ret; | |||
640 | } | |||
641 | } | |||
642 | } | |||
643 | ||||
644 | /* If guest supports masking, irqfd is already setup, unmask it. | |||
645 | * Otherwise, set it up now. | |||
646 | */ | |||
647 | if (k->guest_notifier_mask) { | |||
648 | k->guest_notifier_mask(vdev, queue_no, false0); | |||
649 | /* Test after unmasking to avoid losing events. */ | |||
650 | if (k->guest_notifier_pending && | |||
651 | k->guest_notifier_pending(vdev, queue_no)) { | |||
652 | event_notifier_set(n); | |||
653 | } | |||
654 | } else { | |||
655 | ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector); | |||
656 | } | |||
657 | return ret; | |||
658 | } | |||
659 | ||||
660 | static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy, | |||
661 | unsigned int queue_no, | |||
662 | unsigned int vector) | |||
663 | { | |||
664 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
665 | VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev)((VirtioDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)(object_get_class(((Object *)(vdev))))), ("virtio-device") , "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 665, __func__)); | |||
666 | ||||
667 | /* If guest supports masking, keep irqfd but mask it. | |||
668 | * Otherwise, clean it up now. | |||
669 | */ | |||
670 | if (k->guest_notifier_mask) { | |||
671 | k->guest_notifier_mask(vdev, queue_no, true1); | |||
672 | } else { | |||
673 | kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); | |||
674 | } | |||
675 | } | |||
676 | ||||
677 | static int virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector, | |||
678 | MSIMessage msg) | |||
679 | { | |||
680 | VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev)({ const typeof(((VirtIOPCIProxy *) 0)->pci_dev) *__mptr = (dev); (VirtIOPCIProxy *) ((char *) __mptr - __builtin_offsetof (VirtIOPCIProxy, pci_dev));}); | |||
681 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
682 | int ret, queue_no; | |||
683 | ||||
684 | for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) { | |||
| ||||
685 | if (!virtio_queue_get_num(vdev, queue_no)) { | |||
686 | break; | |||
687 | } | |||
688 | if (virtio_queue_vector(vdev, queue_no) != vector) { | |||
689 | continue; | |||
690 | } | |||
691 | ret = virtio_pci_vq_vector_unmask(proxy, queue_no, vector, msg); | |||
692 | if (ret < 0) { | |||
693 | goto undo; | |||
694 | } | |||
695 | } | |||
696 | return 0; | |||
697 | ||||
698 | undo: | |||
699 | while (--queue_no >= 0) { | |||
700 | if (virtio_queue_vector(vdev, queue_no) != vector) { | |||
701 | continue; | |||
702 | } | |||
703 | virtio_pci_vq_vector_mask(proxy, queue_no, vector); | |||
704 | } | |||
705 | return ret; | |||
706 | } | |||
707 | ||||
708 | static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector) | |||
709 | { | |||
710 | VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev)({ const typeof(((VirtIOPCIProxy *) 0)->pci_dev) *__mptr = (dev); (VirtIOPCIProxy *) ((char *) __mptr - __builtin_offsetof (VirtIOPCIProxy, pci_dev));}); | |||
711 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
712 | int queue_no; | |||
713 | ||||
714 | for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) { | |||
715 | if (!virtio_queue_get_num(vdev, queue_no)) { | |||
716 | break; | |||
717 | } | |||
718 | if (virtio_queue_vector(vdev, queue_no) != vector) { | |||
719 | continue; | |||
720 | } | |||
721 | virtio_pci_vq_vector_mask(proxy, queue_no, vector); | |||
722 | } | |||
723 | } | |||
724 | ||||
725 | static void virtio_pci_vector_poll(PCIDevice *dev, | |||
726 | unsigned int vector_start, | |||
727 | unsigned int vector_end) | |||
728 | { | |||
729 | VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev)({ const typeof(((VirtIOPCIProxy *) 0)->pci_dev) *__mptr = (dev); (VirtIOPCIProxy *) ((char *) __mptr - __builtin_offsetof (VirtIOPCIProxy, pci_dev));}); | |||
730 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
731 | VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev)((VirtioDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)(object_get_class(((Object *)(vdev))))), ("virtio-device") , "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 731, __func__)); | |||
732 | int queue_no; | |||
733 | unsigned int vector; | |||
734 | EventNotifier *notifier; | |||
735 | VirtQueue *vq; | |||
736 | ||||
737 | for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) { | |||
738 | if (!virtio_queue_get_num(vdev, queue_no)) { | |||
739 | break; | |||
740 | } | |||
741 | vector = virtio_queue_vector(vdev, queue_no); | |||
742 | if (vector < vector_start || vector >= vector_end || | |||
743 | !msix_is_masked(dev, vector)) { | |||
744 | continue; | |||
745 | } | |||
746 | vq = virtio_get_queue(vdev, queue_no); | |||
747 | notifier = virtio_queue_get_guest_notifier(vq); | |||
748 | if (k->guest_notifier_pending) { | |||
749 | if (k->guest_notifier_pending(vdev, queue_no)) { | |||
750 | msix_set_pending(dev, vector); | |||
751 | } | |||
752 | } else if (event_notifier_test_and_clear(notifier)) { | |||
753 | msix_set_pending(dev, vector); | |||
754 | } | |||
755 | } | |||
756 | } | |||
757 | ||||
758 | static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool_Bool assign, | |||
759 | bool_Bool with_irqfd) | |||
760 | { | |||
761 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
762 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
763 | VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev)((VirtioDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)(object_get_class(((Object *)(vdev))))), ("virtio-device") , "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 763, __func__)); | |||
764 | VirtQueue *vq = virtio_get_queue(vdev, n); | |||
765 | EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); | |||
766 | ||||
767 | if (assign) { | |||
768 | int r = event_notifier_init(notifier, 0); | |||
769 | if (r < 0) { | |||
770 | return r; | |||
771 | } | |||
772 | virtio_queue_set_guest_notifier_fd_handler(vq, true1, with_irqfd); | |||
773 | } else { | |||
774 | virtio_queue_set_guest_notifier_fd_handler(vq, false0, with_irqfd); | |||
775 | event_notifier_cleanup(notifier); | |||
776 | } | |||
777 | ||||
778 | if (!msix_enabled(&proxy->pci_dev) && vdc->guest_notifier_mask) { | |||
779 | vdc->guest_notifier_mask(vdev, n, !assign); | |||
780 | } | |||
781 | ||||
782 | return 0; | |||
783 | } | |||
784 | ||||
785 | static bool_Bool virtio_pci_query_guest_notifiers(DeviceState *d) | |||
786 | { | |||
787 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
788 | return msix_enabled(&proxy->pci_dev); | |||
789 | } | |||
790 | ||||
791 | static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool_Bool assign) | |||
792 | { | |||
793 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
794 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
795 | VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev)((VirtioDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)(object_get_class(((Object *)(vdev))))), ("virtio-device") , "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 795, __func__)); | |||
796 | int r, n; | |||
797 | bool_Bool with_irqfd = msix_enabled(&proxy->pci_dev) && | |||
798 | kvm_msi_via_irqfd_enabled()(kvm_msi_via_irqfd_allowed); | |||
799 | ||||
800 | nvqs = MIN(nvqs, VIRTIO_PCI_QUEUE_MAX)(((nvqs) < (64)) ? (nvqs) : (64)); | |||
801 | ||||
802 | /* When deassigning, pass a consistent nvqs value | |||
803 | * to avoid leaking notifiers. | |||
804 | */ | |||
805 | assert(assign || nvqs == proxy->nvqs_with_notifiers)((assign || nvqs == proxy->nvqs_with_notifiers) ? (void) ( 0) : __assert_fail ("assign || nvqs == proxy->nvqs_with_notifiers" , "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 805, __PRETTY_FUNCTION__)); | |||
806 | ||||
807 | proxy->nvqs_with_notifiers = nvqs; | |||
808 | ||||
809 | /* Must unset vector notifier while guest notifier is still assigned */ | |||
810 | if ((proxy->vector_irqfd || k->guest_notifier_mask) && !assign) { | |||
811 | msix_unset_vector_notifiers(&proxy->pci_dev); | |||
812 | if (proxy->vector_irqfd) { | |||
813 | kvm_virtio_pci_vector_release(proxy, nvqs); | |||
814 | g_free(proxy->vector_irqfd); | |||
815 | proxy->vector_irqfd = NULL((void*)0); | |||
816 | } | |||
817 | } | |||
818 | ||||
819 | for (n = 0; n < nvqs; n++) { | |||
820 | if (!virtio_queue_get_num(vdev, n)) { | |||
821 | break; | |||
822 | } | |||
823 | ||||
824 | r = virtio_pci_set_guest_notifier(d, n, assign, with_irqfd); | |||
825 | if (r < 0) { | |||
826 | goto assign_error; | |||
827 | } | |||
828 | } | |||
829 | ||||
830 | /* Must set vector notifier after guest notifier has been assigned */ | |||
831 | if ((with_irqfd || k->guest_notifier_mask) && assign) { | |||
832 | if (with_irqfd) { | |||
833 | proxy->vector_irqfd = | |||
834 | g_malloc0(sizeof(*proxy->vector_irqfd) * | |||
835 | msix_nr_vectors_allocated(&proxy->pci_dev)); | |||
836 | r = kvm_virtio_pci_vector_use(proxy, nvqs); | |||
837 | if (r < 0) { | |||
838 | goto assign_error; | |||
839 | } | |||
840 | } | |||
841 | r = msix_set_vector_notifiers(&proxy->pci_dev, | |||
842 | virtio_pci_vector_unmask, | |||
843 | virtio_pci_vector_mask, | |||
844 | virtio_pci_vector_poll); | |||
845 | if (r < 0) { | |||
846 | goto notifiers_error; | |||
847 | } | |||
848 | } | |||
849 | ||||
850 | return 0; | |||
851 | ||||
852 | notifiers_error: | |||
853 | if (with_irqfd) { | |||
854 | assert(assign)((assign) ? (void) (0) : __assert_fail ("assign", "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 854, __PRETTY_FUNCTION__)); | |||
855 | kvm_virtio_pci_vector_release(proxy, nvqs); | |||
856 | } | |||
857 | ||||
858 | assign_error: | |||
859 | /* We get here on assignment failure. Recover by undoing for VQs 0 .. n. */ | |||
860 | assert(assign)((assign) ? (void) (0) : __assert_fail ("assign", "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 860, __PRETTY_FUNCTION__)); | |||
861 | while (--n >= 0) { | |||
862 | virtio_pci_set_guest_notifier(d, n, !assign, with_irqfd); | |||
863 | } | |||
864 | return r; | |||
865 | } | |||
866 | ||||
867 | static int virtio_pci_set_host_notifier(DeviceState *d, int n, bool_Bool assign) | |||
868 | { | |||
869 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
870 | ||||
871 | /* Stop using ioeventfd for virtqueue kick if the device starts using host | |||
872 | * notifiers. This makes it easy to avoid stepping on each others' toes. | |||
873 | */ | |||
874 | proxy->ioeventfd_disabled = assign; | |||
875 | if (assign) { | |||
876 | virtio_pci_stop_ioeventfd(proxy); | |||
877 | } | |||
878 | /* We don't need to start here: it's not needed because backend | |||
879 | * currently only stops on status change away from ok, | |||
880 | * reset, vmstop and such. If we do add code to start here, | |||
881 | * need to check vmstate, device state etc. */ | |||
882 | return virtio_pci_set_host_notifier_internal(proxy, n, assign, false0); | |||
883 | } | |||
884 | ||||
885 | static void virtio_pci_vmstate_change(DeviceState *d, bool_Bool running) | |||
886 | { | |||
887 | VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | |||
888 | VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | |||
889 | ||||
890 | if (running) { | |||
891 | /* Try to find out if the guest has bus master disabled, but is | |||
892 | in ready state. Then we have a buggy guest OS. */ | |||
893 | if ((vdev->status & VIRTIO_CONFIG_S_DRIVER_OK4) && | |||
894 | !(proxy->pci_dev.config[PCI_COMMAND0x04] & PCI_COMMAND_MASTER0x4)) { | |||
895 | proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG(1 << 0); | |||
896 | } | |||
897 | virtio_pci_start_ioeventfd(proxy); | |||
898 | } else { | |||
899 | virtio_pci_stop_ioeventfd(proxy); | |||
900 | } | |||
901 | } | |||
902 | ||||
903 | #ifdef CONFIG_VIRTFS1 | |||
904 | static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev) | |||
905 | { | |||
906 | V9fsPCIState *dev = VIRTIO_9P_PCI(vpci_dev)((V9fsPCIState *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("virtio-9p-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 906, __func__)); | |||
907 | DeviceState *vdev = DEVICE(&dev->vdev)((DeviceState *)object_dynamic_cast_assert(((Object *)((& dev->vdev))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 907, __func__)); | |||
908 | ||||
909 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)((BusState *)object_dynamic_cast_assert(((Object *)((&vpci_dev ->bus))), ("bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 909, __func__))); | |||
910 | if (qdev_init(vdev) < 0) { | |||
911 | return -1; | |||
912 | } | |||
913 | return 0; | |||
914 | } | |||
915 | ||||
916 | static Property virtio_9p_pci_properties[] = { | |||
917 | DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,{ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)1, } | |||
918 | VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true){ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
919 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2){ .name = ("vectors"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOPCIProxy, nvectors) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->nvectors)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)2, }, | |||
920 | DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features){ .name = ("indirect_desc"), .info = &(qdev_prop_bit), .bitnr = (28), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("event_idx"), .info = &(qdev_prop_bit), .bitnr = (29), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
921 | DEFINE_VIRTIO_9P_PROPERTIES(V9fsPCIState, vdev.fsconf){ .name = ("mount_tag"), .info = &(qdev_prop_string), .offset = __builtin_offsetof(V9fsPCIState, vdev.fsconf.tag) + ((char **)0 - (typeof(((V9fsPCIState *)0)->vdev.fsconf.tag)*)0), } , { .name = ("fsdev"), .info = &(qdev_prop_string), .offset = __builtin_offsetof(V9fsPCIState, vdev.fsconf.fsdev_id) + ( (char**)0 - (typeof(((V9fsPCIState *)0)->vdev.fsconf.fsdev_id )*)0), }, | |||
922 | DEFINE_PROP_END_OF_LIST(){}, | |||
923 | }; | |||
924 | ||||
925 | static void virtio_9p_pci_class_init(ObjectClass *klass, void *data) | |||
926 | { | |||
927 | DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 927, __func__)); | |||
928 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass)((PCIDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 928, __func__)); | |||
929 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass)((VirtioPCIClass *)object_class_dynamic_cast_assert(((ObjectClass *)(klass)), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 929, __func__)); | |||
930 | ||||
931 | k->init = virtio_9p_init_pci; | |||
932 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET0x1af4; | |||
933 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_9P0x1009; | |||
934 | pcidev_k->revision = VIRTIO_PCI_ABI_VERSION0; | |||
935 | pcidev_k->class_id = 0x2; | |||
936 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | |||
937 | dc->props = virtio_9p_pci_properties; | |||
938 | } | |||
939 | ||||
940 | static void virtio_9p_pci_instance_init(Object *obj) | |||
941 | { | |||
942 | V9fsPCIState *dev = VIRTIO_9P_PCI(obj)((V9fsPCIState *)object_dynamic_cast_assert(((Object *)((obj) )), ("virtio-9p-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 942, __func__)); | |||
943 | object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_9P"virtio-9p-device"); | |||
944 | object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev)((Object *)(&dev->vdev)), NULL((void*)0)); | |||
945 | } | |||
946 | ||||
947 | static const TypeInfo virtio_9p_pci_info = { | |||
948 | .name = TYPE_VIRTIO_9P_PCI"virtio-9p-pci", | |||
949 | .parent = TYPE_VIRTIO_PCI"virtio-pci", | |||
950 | .instance_size = sizeof(V9fsPCIState), | |||
951 | .instance_init = virtio_9p_pci_instance_init, | |||
952 | .class_init = virtio_9p_pci_class_init, | |||
953 | }; | |||
954 | #endif /* CONFIG_VIRTFS */ | |||
955 | ||||
956 | /* | |||
957 | * virtio-pci: This is the PCIDevice which has a virtio-pci-bus. | |||
958 | */ | |||
959 | ||||
960 | /* This is called by virtio-bus just after the device is plugged. */ | |||
961 | static void virtio_pci_device_plugged(DeviceState *d) | |||
962 | { | |||
963 | VirtIOPCIProxy *proxy = VIRTIO_PCI(d)((VirtIOPCIProxy *)object_dynamic_cast_assert(((Object *)((d) )), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 963, __func__)); | |||
964 | VirtioBusState *bus = &proxy->bus; | |||
965 | uint8_t *config; | |||
966 | uint32_t size; | |||
967 | ||||
968 | config = proxy->pci_dev.config; | |||
969 | if (proxy->class_code) { | |||
970 | pci_config_set_class(config, proxy->class_code); | |||
971 | } | |||
972 | pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID0x2c, | |||
973 | pci_get_word(config + PCI_VENDOR_ID0x00)); | |||
974 | pci_set_word(config + PCI_SUBSYSTEM_ID0x2e, virtio_bus_get_vdev_id(bus)); | |||
975 | config[PCI_INTERRUPT_PIN0x3d] = 1; | |||
976 | ||||
977 | if (proxy->nvectors && | |||
978 | msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, 1)) { | |||
979 | proxy->nvectors = 0; | |||
980 | } | |||
981 | ||||
982 | proxy->pci_dev.config_write = virtio_write_config; | |||
983 | ||||
984 | size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev)(msix_present(&proxy->pci_dev) ? 24 : 20) | |||
985 | + virtio_bus_get_vdev_config_len(bus); | |||
986 | if (size & (size - 1)) { | |||
987 | size = 1 << qemu_fls(size); | |||
988 | } | |||
989 | ||||
990 | memory_region_init_io(&proxy->bar, OBJECT(proxy)((Object *)(proxy)), &virtio_pci_config_ops, | |||
991 | proxy, "virtio-pci", size); | |||
992 | pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO0x01, | |||
993 | &proxy->bar); | |||
994 | ||||
995 | if (!kvm_has_many_ioeventfds()) { | |||
996 | proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD(1 << 1); | |||
997 | } | |||
998 | ||||
999 | proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY24; | |||
1000 | proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE30; | |||
1001 | proxy->host_features = virtio_bus_get_vdev_features(bus, | |||
1002 | proxy->host_features); | |||
1003 | } | |||
1004 | ||||
1005 | static void virtio_pci_device_unplugged(DeviceState *d) | |||
1006 | { | |||
1007 | PCIDevice *pci_dev = PCI_DEVICE(d)((PCIDevice *)object_dynamic_cast_assert(((Object *)((d))), ( "pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1007, __func__)); | |||
1008 | VirtIOPCIProxy *proxy = VIRTIO_PCI(d)((VirtIOPCIProxy *)object_dynamic_cast_assert(((Object *)((d) )), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1008, __func__)); | |||
1009 | ||||
1010 | virtio_pci_stop_ioeventfd(proxy); | |||
1011 | msix_uninit_exclusive_bar(pci_dev); | |||
1012 | } | |||
1013 | ||||
1014 | static int virtio_pci_init(PCIDevice *pci_dev) | |||
1015 | { | |||
1016 | VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev)((VirtIOPCIProxy *)object_dynamic_cast_assert(((Object *)((pci_dev ))), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1016, __func__)); | |||
1017 | VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev)((VirtioPCIClass *)object_class_dynamic_cast_assert(((ObjectClass *)(object_get_class(((Object *)(pci_dev))))), ("virtio-pci") , "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1017, __func__)); | |||
1018 | virtio_pci_bus_new(&dev->bus, sizeof(dev->bus), dev); | |||
1019 | if (k->init != NULL((void*)0)) { | |||
1020 | return k->init(dev); | |||
1021 | } | |||
1022 | return 0; | |||
1023 | } | |||
1024 | ||||
1025 | static void virtio_pci_exit(PCIDevice *pci_dev) | |||
1026 | { | |||
1027 | VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev)((VirtIOPCIProxy *)object_dynamic_cast_assert(((Object *)((pci_dev ))), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1027, __func__)); | |||
1028 | memory_region_destroy(&proxy->bar); | |||
1029 | } | |||
1030 | ||||
1031 | static void virtio_pci_reset(DeviceState *qdev) | |||
1032 | { | |||
1033 | VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev)((VirtIOPCIProxy *)object_dynamic_cast_assert(((Object *)((qdev ))), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1033, __func__)); | |||
1034 | VirtioBusState *bus = VIRTIO_BUS(&proxy->bus)((VirtioBusState *)object_dynamic_cast_assert(((Object *)((& proxy->bus))), ("virtio-bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1034, __func__)); | |||
1035 | virtio_pci_stop_ioeventfd(proxy); | |||
1036 | virtio_bus_reset(bus); | |||
1037 | msix_unuse_all_vectors(&proxy->pci_dev); | |||
1038 | proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG(1 << 0); | |||
1039 | } | |||
1040 | ||||
1041 | static void virtio_pci_class_init(ObjectClass *klass, void *data) | |||
1042 | { | |||
1043 | DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1043, __func__)); | |||
1044 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass)((PCIDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1044, __func__)); | |||
1045 | ||||
1046 | k->init = virtio_pci_init; | |||
1047 | k->exit = virtio_pci_exit; | |||
1048 | k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET0x1af4; | |||
1049 | k->revision = VIRTIO_PCI_ABI_VERSION0; | |||
1050 | k->class_id = PCI_CLASS_OTHERS0xff; | |||
1051 | dc->reset = virtio_pci_reset; | |||
1052 | } | |||
1053 | ||||
1054 | static const TypeInfo virtio_pci_info = { | |||
1055 | .name = TYPE_VIRTIO_PCI"virtio-pci", | |||
1056 | .parent = TYPE_PCI_DEVICE"pci-device", | |||
1057 | .instance_size = sizeof(VirtIOPCIProxy), | |||
1058 | .class_init = virtio_pci_class_init, | |||
1059 | .class_size = sizeof(VirtioPCIClass), | |||
1060 | .abstract = true1, | |||
1061 | }; | |||
1062 | ||||
1063 | /* virtio-blk-pci */ | |||
1064 | ||||
1065 | static Property virtio_blk_pci_properties[] = { | |||
1066 | DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0){ .name = ("class"), .info = &(qdev_prop_hex32), .offset = __builtin_offsetof(VirtIOPCIProxy, class_code) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->class_code)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)0, }, | |||
1067 | DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,{ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)1, } | |||
1068 | VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true){ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1069 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2){ .name = ("vectors"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOPCIProxy, nvectors) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->nvectors)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)2, }, | |||
1070 | #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE$(CONFIG_VIRTIO) | |||
1071 | DEFINE_PROP_BIT("x-data-plane", VirtIOBlkPCI, blk.data_plane, 0, false){ .name = ("x-data-plane"), .info = &(qdev_prop_bit), .bitnr = (0), .offset = __builtin_offsetof(VirtIOBlkPCI, blk.data_plane ) + ((uint32_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.data_plane )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)0, }, | |||
1072 | #endif | |||
1073 | DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features){ .name = ("indirect_desc"), .info = &(qdev_prop_bit), .bitnr = (28), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("event_idx"), .info = &(qdev_prop_bit), .bitnr = (29), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1074 | DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkPCI, blk){ .name = ("drive"), .info = &(qdev_prop_drive), .offset = __builtin_offsetof(VirtIOBlkPCI, blk.conf.bs) + ((BlockDriverState **)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf.bs)*)0), }, { .name = ("logical_block_size"), .info = &(qdev_prop_blocksize ), .offset = __builtin_offsetof(VirtIOBlkPCI, blk.conf.logical_block_size ) + ((uint16_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf. logical_block_size)*)0), .qtype = QTYPE_QINT, .defval = (uint16_t )512, }, { .name = ("physical_block_size"), .info = &(qdev_prop_blocksize ), .offset = __builtin_offsetof(VirtIOBlkPCI, blk.conf.physical_block_size ) + ((uint16_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf. physical_block_size)*)0), .qtype = QTYPE_QINT, .defval = (uint16_t )512, }, { .name = ("min_io_size"), .info = &(qdev_prop_uint16 ), .offset = __builtin_offsetof(VirtIOBlkPCI, blk.conf.min_io_size ) + ((uint16_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf. min_io_size)*)0), .qtype = QTYPE_QINT, .defval = (uint16_t)0, }, { .name = ("opt_io_size"), .info = &(qdev_prop_uint32 ), .offset = __builtin_offsetof(VirtIOBlkPCI, blk.conf.opt_io_size ) + ((uint32_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf. opt_io_size)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)0, }, { .name = ("bootindex"), .info = &(qdev_prop_int32), . offset = __builtin_offsetof(VirtIOBlkPCI, blk.conf.bootindex) + ((int32_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf.bootindex )*)0), .qtype = QTYPE_QINT, .defval = (int32_t)-1, }, { .name = ("discard_granularity"), .info = &(qdev_prop_uint32), . offset = __builtin_offsetof(VirtIOBlkPCI, blk.conf.discard_granularity ) + ((uint32_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf. discard_granularity)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t )-1, }, { .name = ("cyls"), .info = &(qdev_prop_uint32), . offset = __builtin_offsetof(VirtIOBlkPCI, blk.conf.cyls) + (( uint32_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf.cyls)* )0), .qtype = QTYPE_QINT, .defval = (uint32_t)0, }, { .name = ("heads"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof (VirtIOBlkPCI, blk.conf.heads) + ((uint32_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf.heads)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)0, }, { .name = ("secs"), .info = &(qdev_prop_uint32 ), .offset = __builtin_offsetof(VirtIOBlkPCI, blk.conf.secs) + ((uint32_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.conf.secs )*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)0, }, { .name = ("serial"), .info = &(qdev_prop_string), .offset = __builtin_offsetof (VirtIOBlkPCI, blk.serial) + ((char**)0 - (typeof(((VirtIOBlkPCI *)0)->blk.serial)*)0), }, { .name = ("config-wce"), .info = &(qdev_prop_bit), .bitnr = (0), .offset = __builtin_offsetof (VirtIOBlkPCI, blk.config_wce) + ((uint32_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk.config_wce)*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("scsi"), .info = &(qdev_prop_bit ), .bitnr = (0), .offset = __builtin_offsetof(VirtIOBlkPCI, blk .scsi) + ((uint32_t*)0 - (typeof(((VirtIOBlkPCI *)0)->blk. scsi)*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1075 | DEFINE_PROP_END_OF_LIST(){}, | |||
1076 | }; | |||
1077 | ||||
1078 | static int virtio_blk_pci_init(VirtIOPCIProxy *vpci_dev) | |||
1079 | { | |||
1080 | VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev)((VirtIOBlkPCI *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("virtio-blk-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1080, __func__)); | |||
1081 | DeviceState *vdev = DEVICE(&dev->vdev)((DeviceState *)object_dynamic_cast_assert(((Object *)((& dev->vdev))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1081, __func__)); | |||
1082 | virtio_blk_set_conf(vdev, &(dev->blk)); | |||
1083 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)((BusState *)object_dynamic_cast_assert(((Object *)((&vpci_dev ->bus))), ("bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1083, __func__))); | |||
1084 | if (qdev_init(vdev) < 0) { | |||
1085 | return -1; | |||
1086 | } | |||
1087 | return 0; | |||
1088 | } | |||
1089 | ||||
1090 | static void virtio_blk_pci_class_init(ObjectClass *klass, void *data) | |||
1091 | { | |||
1092 | DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1092, __func__)); | |||
1093 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass)((VirtioPCIClass *)object_class_dynamic_cast_assert(((ObjectClass *)(klass)), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1093, __func__)); | |||
1094 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass)((PCIDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1094, __func__)); | |||
1095 | ||||
1096 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | |||
1097 | dc->props = virtio_blk_pci_properties; | |||
1098 | k->init = virtio_blk_pci_init; | |||
1099 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET0x1af4; | |||
1100 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK0x1001; | |||
1101 | pcidev_k->revision = VIRTIO_PCI_ABI_VERSION0; | |||
1102 | pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI0x0100; | |||
1103 | } | |||
1104 | ||||
1105 | static void virtio_blk_pci_instance_init(Object *obj) | |||
1106 | { | |||
1107 | VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(obj)((VirtIOBlkPCI *)object_dynamic_cast_assert(((Object *)((obj) )), ("virtio-blk-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1107, __func__)); | |||
1108 | object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BLK"virtio-blk-device"); | |||
1109 | object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev)((Object *)(&dev->vdev)), NULL((void*)0)); | |||
1110 | } | |||
1111 | ||||
1112 | static const TypeInfo virtio_blk_pci_info = { | |||
1113 | .name = TYPE_VIRTIO_BLK_PCI"virtio-blk-pci", | |||
1114 | .parent = TYPE_VIRTIO_PCI"virtio-pci", | |||
1115 | .instance_size = sizeof(VirtIOBlkPCI), | |||
1116 | .instance_init = virtio_blk_pci_instance_init, | |||
1117 | .class_init = virtio_blk_pci_class_init, | |||
1118 | }; | |||
1119 | ||||
1120 | /* virtio-scsi-pci */ | |||
1121 | ||||
1122 | static Property virtio_scsi_pci_properties[] = { | |||
1123 | DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,{ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)1, } | |||
1124 | VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true){ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1125 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,{ .name = ("vectors"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOPCIProxy, nvectors) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->nvectors)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)DEV_NVECTORS_UNSPECIFIED, } | |||
1126 | DEV_NVECTORS_UNSPECIFIED){ .name = ("vectors"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOPCIProxy, nvectors) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->nvectors)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)DEV_NVECTORS_UNSPECIFIED, }, | |||
1127 | DEFINE_VIRTIO_SCSI_FEATURES(VirtIOPCIProxy, host_features){ .name = ("indirect_desc"), .info = &(qdev_prop_bit), .bitnr = (28), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("event_idx"), .info = &(qdev_prop_bit), .bitnr = (29), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("hotplug"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ((uint32_t *)0 - (typeof(((VirtIOPCIProxy *)0)->host_features)*)0), . qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("param_change" ), .info = &(qdev_prop_bit), .bitnr = (2), .offset = __builtin_offsetof (VirtIOPCIProxy, host_features) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features)*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1128 | DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSIPCI, vdev.parent_obj.conf){ .name = ("num_queues"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOSCSIPCI, vdev.parent_obj.conf.num_queues ) + ((uint32_t*)0 - (typeof(((VirtIOSCSIPCI *)0)->vdev.parent_obj .conf.num_queues)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t )1, }, { .name = ("max_sectors"), .info = &(qdev_prop_uint32 ), .offset = __builtin_offsetof(VirtIOSCSIPCI, vdev.parent_obj .conf.max_sectors) + ((uint32_t*)0 - (typeof(((VirtIOSCSIPCI * )0)->vdev.parent_obj.conf.max_sectors)*)0), .qtype = QTYPE_QINT , .defval = (uint32_t)0xFFFF, }, { .name = ("cmd_per_lun"), . info = &(qdev_prop_uint32), .offset = __builtin_offsetof( VirtIOSCSIPCI, vdev.parent_obj.conf.cmd_per_lun) + ((uint32_t *)0 - (typeof(((VirtIOSCSIPCI *)0)->vdev.parent_obj.conf.cmd_per_lun )*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)128, }, | |||
1129 | DEFINE_PROP_END_OF_LIST(){}, | |||
1130 | }; | |||
1131 | ||||
1132 | static int virtio_scsi_pci_init_pci(VirtIOPCIProxy *vpci_dev) | |||
1133 | { | |||
1134 | VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(vpci_dev)((VirtIOSCSIPCI *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("virtio-scsi-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1134, __func__)); | |||
1135 | DeviceState *vdev = DEVICE(&dev->vdev)((DeviceState *)object_dynamic_cast_assert(((Object *)((& dev->vdev))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1135, __func__)); | |||
1136 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev)((VirtIOSCSICommon *)object_dynamic_cast_assert(((Object *)(( vdev))), ("virtio-scsi-common"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1136, __func__)); | |||
1137 | DeviceState *proxy = DEVICE(vpci_dev)((DeviceState *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1137, __func__)); | |||
1138 | char *bus_name; | |||
1139 | ||||
1140 | if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | |||
1141 | vpci_dev->nvectors = vs->conf.num_queues + 3; | |||
1142 | } | |||
1143 | ||||
1144 | /* | |||
1145 | * For command line compatibility, this sets the virtio-scsi-device bus | |||
1146 | * name as before. | |||
1147 | */ | |||
1148 | if (proxy->id) { | |||
1149 | bus_name = g_strdup_printf("%s.0", proxy->id); | |||
1150 | virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev)((VirtIODevice *)object_dynamic_cast_assert(((Object *)((vdev ))), ("virtio-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1150, __func__)), bus_name); | |||
1151 | g_free(bus_name); | |||
1152 | } | |||
1153 | ||||
1154 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)((BusState *)object_dynamic_cast_assert(((Object *)((&vpci_dev ->bus))), ("bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1154, __func__))); | |||
1155 | if (qdev_init(vdev) < 0) { | |||
1156 | return -1; | |||
1157 | } | |||
1158 | return 0; | |||
1159 | } | |||
1160 | ||||
1161 | static void virtio_scsi_pci_class_init(ObjectClass *klass, void *data) | |||
1162 | { | |||
1163 | DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1163, __func__)); | |||
1164 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass)((VirtioPCIClass *)object_class_dynamic_cast_assert(((ObjectClass *)(klass)), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1164, __func__)); | |||
1165 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass)((PCIDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1165, __func__)); | |||
1166 | k->init = virtio_scsi_pci_init_pci; | |||
1167 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | |||
1168 | dc->props = virtio_scsi_pci_properties; | |||
1169 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET0x1af4; | |||
1170 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI0x1004; | |||
1171 | pcidev_k->revision = 0x00; | |||
1172 | pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI0x0100; | |||
1173 | } | |||
1174 | ||||
1175 | static void virtio_scsi_pci_instance_init(Object *obj) | |||
1176 | { | |||
1177 | VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(obj)((VirtIOSCSIPCI *)object_dynamic_cast_assert(((Object *)((obj ))), ("virtio-scsi-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1177, __func__)); | |||
1178 | object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_SCSI"virtio-scsi-device"); | |||
1179 | object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev)((Object *)(&dev->vdev)), NULL((void*)0)); | |||
1180 | } | |||
1181 | ||||
1182 | static const TypeInfo virtio_scsi_pci_info = { | |||
1183 | .name = TYPE_VIRTIO_SCSI_PCI"virtio-scsi-pci", | |||
1184 | .parent = TYPE_VIRTIO_PCI"virtio-pci", | |||
1185 | .instance_size = sizeof(VirtIOSCSIPCI), | |||
1186 | .instance_init = virtio_scsi_pci_instance_init, | |||
1187 | .class_init = virtio_scsi_pci_class_init, | |||
1188 | }; | |||
1189 | ||||
1190 | /* vhost-scsi-pci */ | |||
1191 | ||||
1192 | #ifdef CONFIG_VHOST_SCSI1 | |||
1193 | static Property vhost_scsi_pci_properties[] = { | |||
1194 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,{ .name = ("vectors"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOPCIProxy, nvectors) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->nvectors)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)DEV_NVECTORS_UNSPECIFIED, } | |||
1195 | DEV_NVECTORS_UNSPECIFIED){ .name = ("vectors"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOPCIProxy, nvectors) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->nvectors)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)DEV_NVECTORS_UNSPECIFIED, }, | |||
1196 | DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features){ .name = ("indirect_desc"), .info = &(qdev_prop_bit), .bitnr = (28), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("event_idx"), .info = &(qdev_prop_bit), .bitnr = (29), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1197 | DEFINE_VHOST_SCSI_PROPERTIES(VHostSCSIPCI, vdev.parent_obj.conf){ .name = ("vhostfd"), .info = &(qdev_prop_string), .offset = __builtin_offsetof(VHostSCSIPCI, vdev.parent_obj.conf.vhostfd ) + ((char**)0 - (typeof(((VHostSCSIPCI *)0)->vdev.parent_obj .conf.vhostfd)*)0), }, { .name = ("wwpn"), .info = &(qdev_prop_string ), .offset = __builtin_offsetof(VHostSCSIPCI, vdev.parent_obj .conf.wwpn) + ((char**)0 - (typeof(((VHostSCSIPCI *)0)->vdev .parent_obj.conf.wwpn)*)0), }, { .name = ("num_queues"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VHostSCSIPCI , vdev.parent_obj.conf.num_queues) + ((uint32_t*)0 - (typeof( ((VHostSCSIPCI *)0)->vdev.parent_obj.conf.num_queues)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)1, }, { .name = ("max_sectors" ), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof (VHostSCSIPCI, vdev.parent_obj.conf.max_sectors) + ((uint32_t *)0 - (typeof(((VHostSCSIPCI *)0)->vdev.parent_obj.conf.max_sectors )*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)0xFFFF, }, { . name = ("cmd_per_lun"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VHostSCSIPCI, vdev.parent_obj.conf.cmd_per_lun ) + ((uint32_t*)0 - (typeof(((VHostSCSIPCI *)0)->vdev.parent_obj .conf.cmd_per_lun)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t )128, }, | |||
1198 | DEFINE_PROP_END_OF_LIST(){}, | |||
1199 | }; | |||
1200 | ||||
1201 | static int vhost_scsi_pci_init_pci(VirtIOPCIProxy *vpci_dev) | |||
1202 | { | |||
1203 | VHostSCSIPCI *dev = VHOST_SCSI_PCI(vpci_dev)((VHostSCSIPCI *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("vhost-scsi-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1203, __func__)); | |||
1204 | DeviceState *vdev = DEVICE(&dev->vdev)((DeviceState *)object_dynamic_cast_assert(((Object *)((& dev->vdev))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1204, __func__)); | |||
1205 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev)((VirtIOSCSICommon *)object_dynamic_cast_assert(((Object *)(( vdev))), ("virtio-scsi-common"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1205, __func__)); | |||
1206 | ||||
1207 | if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | |||
1208 | vpci_dev->nvectors = vs->conf.num_queues + 3; | |||
1209 | } | |||
1210 | ||||
1211 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)((BusState *)object_dynamic_cast_assert(((Object *)((&vpci_dev ->bus))), ("bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1211, __func__))); | |||
1212 | if (qdev_init(vdev) < 0) { | |||
1213 | return -1; | |||
1214 | } | |||
1215 | return 0; | |||
1216 | } | |||
1217 | ||||
1218 | static void vhost_scsi_pci_class_init(ObjectClass *klass, void *data) | |||
1219 | { | |||
1220 | DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1220, __func__)); | |||
1221 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass)((VirtioPCIClass *)object_class_dynamic_cast_assert(((ObjectClass *)(klass)), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1221, __func__)); | |||
1222 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass)((PCIDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1222, __func__)); | |||
1223 | k->init = vhost_scsi_pci_init_pci; | |||
1224 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | |||
1225 | dc->props = vhost_scsi_pci_properties; | |||
1226 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET0x1af4; | |||
1227 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI0x1004; | |||
1228 | pcidev_k->revision = 0x00; | |||
1229 | pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI0x0100; | |||
1230 | } | |||
1231 | ||||
1232 | static void vhost_scsi_pci_instance_init(Object *obj) | |||
1233 | { | |||
1234 | VHostSCSIPCI *dev = VHOST_SCSI_PCI(obj)((VHostSCSIPCI *)object_dynamic_cast_assert(((Object *)((obj) )), ("vhost-scsi-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1234, __func__)); | |||
1235 | object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VHOST_SCSI"vhost-scsi"); | |||
1236 | object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev)((Object *)(&dev->vdev)), NULL((void*)0)); | |||
1237 | } | |||
1238 | ||||
1239 | static const TypeInfo vhost_scsi_pci_info = { | |||
1240 | .name = TYPE_VHOST_SCSI_PCI"vhost-scsi-pci", | |||
1241 | .parent = TYPE_VIRTIO_PCI"virtio-pci", | |||
1242 | .instance_size = sizeof(VHostSCSIPCI), | |||
1243 | .instance_init = vhost_scsi_pci_instance_init, | |||
1244 | .class_init = vhost_scsi_pci_class_init, | |||
1245 | }; | |||
1246 | #endif | |||
1247 | ||||
1248 | /* virtio-balloon-pci */ | |||
1249 | ||||
1250 | static void balloon_pci_stats_get_all(Object *obj, struct Visitor *v, | |||
1251 | void *opaque, const char *name, | |||
1252 | Error **errp) | |||
1253 | { | |||
1254 | VirtIOBalloonPCI *dev = opaque; | |||
1255 | object_property_get(OBJECT(&dev->vdev)((Object *)(&dev->vdev)), v, "guest-stats", errp); | |||
1256 | } | |||
1257 | ||||
1258 | static void balloon_pci_stats_get_poll_interval(Object *obj, struct Visitor *v, | |||
1259 | void *opaque, const char *name, | |||
1260 | Error **errp) | |||
1261 | { | |||
1262 | VirtIOBalloonPCI *dev = opaque; | |||
1263 | object_property_get(OBJECT(&dev->vdev)((Object *)(&dev->vdev)), v, "guest-stats-polling-interval", | |||
1264 | errp); | |||
1265 | } | |||
1266 | ||||
1267 | static void balloon_pci_stats_set_poll_interval(Object *obj, struct Visitor *v, | |||
1268 | void *opaque, const char *name, | |||
1269 | Error **errp) | |||
1270 | { | |||
1271 | VirtIOBalloonPCI *dev = opaque; | |||
1272 | object_property_set(OBJECT(&dev->vdev)((Object *)(&dev->vdev)), v, "guest-stats-polling-interval", | |||
1273 | errp); | |||
1274 | } | |||
1275 | ||||
1276 | static Property virtio_balloon_pci_properties[] = { | |||
1277 | DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features){ .name = ("indirect_desc"), .info = &(qdev_prop_bit), .bitnr = (28), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("event_idx"), .info = &(qdev_prop_bit), .bitnr = (29), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1278 | DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0){ .name = ("class"), .info = &(qdev_prop_hex32), .offset = __builtin_offsetof(VirtIOPCIProxy, class_code) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->class_code)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)0, }, | |||
1279 | DEFINE_PROP_END_OF_LIST(){}, | |||
1280 | }; | |||
1281 | ||||
1282 | static int virtio_balloon_pci_init(VirtIOPCIProxy *vpci_dev) | |||
1283 | { | |||
1284 | VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev)((VirtIOBalloonPCI *)object_dynamic_cast_assert(((Object *)(( vpci_dev))), ("virtio-balloon-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1284, __func__)); | |||
1285 | DeviceState *vdev = DEVICE(&dev->vdev)((DeviceState *)object_dynamic_cast_assert(((Object *)((& dev->vdev))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1285, __func__)); | |||
1286 | ||||
1287 | if (vpci_dev->class_code != PCI_CLASS_OTHERS0xff && | |||
1288 | vpci_dev->class_code != PCI_CLASS_MEMORY_RAM0x0500) { /* qemu < 1.1 */ | |||
1289 | vpci_dev->class_code = PCI_CLASS_OTHERS0xff; | |||
1290 | } | |||
1291 | ||||
1292 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)((BusState *)object_dynamic_cast_assert(((Object *)((&vpci_dev ->bus))), ("bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1292, __func__))); | |||
1293 | if (qdev_init(vdev) < 0) { | |||
1294 | return -1; | |||
1295 | } | |||
1296 | return 0; | |||
1297 | } | |||
1298 | ||||
1299 | static void virtio_balloon_pci_class_init(ObjectClass *klass, void *data) | |||
1300 | { | |||
1301 | DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1301, __func__)); | |||
1302 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass)((VirtioPCIClass *)object_class_dynamic_cast_assert(((ObjectClass *)(klass)), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1302, __func__)); | |||
1303 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass)((PCIDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1303, __func__)); | |||
1304 | k->init = virtio_balloon_pci_init; | |||
1305 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); | |||
1306 | dc->props = virtio_balloon_pci_properties; | |||
1307 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET0x1af4; | |||
1308 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON0x1002; | |||
1309 | pcidev_k->revision = VIRTIO_PCI_ABI_VERSION0; | |||
1310 | pcidev_k->class_id = PCI_CLASS_OTHERS0xff; | |||
1311 | } | |||
1312 | ||||
1313 | static void virtio_balloon_pci_instance_init(Object *obj) | |||
1314 | { | |||
1315 | VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj)((VirtIOBalloonPCI *)object_dynamic_cast_assert(((Object *)(( obj))), ("virtio-balloon-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1315, __func__)); | |||
1316 | object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BALLOON"virtio-balloon-device"); | |||
1317 | object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev)((Object *)(&dev->vdev)), NULL((void*)0)); | |||
1318 | ||||
1319 | object_property_add(obj, "guest-stats", "guest statistics", | |||
1320 | balloon_pci_stats_get_all, NULL((void*)0), NULL((void*)0), dev, | |||
1321 | NULL((void*)0)); | |||
1322 | ||||
1323 | object_property_add(obj, "guest-stats-polling-interval", "int", | |||
1324 | balloon_pci_stats_get_poll_interval, | |||
1325 | balloon_pci_stats_set_poll_interval, | |||
1326 | NULL((void*)0), dev, NULL((void*)0)); | |||
1327 | } | |||
1328 | ||||
1329 | static const TypeInfo virtio_balloon_pci_info = { | |||
1330 | .name = TYPE_VIRTIO_BALLOON_PCI"virtio-balloon-pci", | |||
1331 | .parent = TYPE_VIRTIO_PCI"virtio-pci", | |||
1332 | .instance_size = sizeof(VirtIOBalloonPCI), | |||
1333 | .instance_init = virtio_balloon_pci_instance_init, | |||
1334 | .class_init = virtio_balloon_pci_class_init, | |||
1335 | }; | |||
1336 | ||||
1337 | /* virtio-serial-pci */ | |||
1338 | ||||
1339 | static int virtio_serial_pci_init(VirtIOPCIProxy *vpci_dev) | |||
1340 | { | |||
1341 | VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(vpci_dev)((VirtIOSerialPCI *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("virtio-serial-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1341, __func__)); | |||
1342 | DeviceState *vdev = DEVICE(&dev->vdev)((DeviceState *)object_dynamic_cast_assert(((Object *)((& dev->vdev))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1342, __func__)); | |||
1343 | DeviceState *proxy = DEVICE(vpci_dev)((DeviceState *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1343, __func__)); | |||
1344 | char *bus_name; | |||
1345 | ||||
1346 | if (vpci_dev->class_code != PCI_CLASS_COMMUNICATION_OTHER0x0780 && | |||
1347 | vpci_dev->class_code != PCI_CLASS_DISPLAY_OTHER0x0380 && /* qemu 0.10 */ | |||
1348 | vpci_dev->class_code != PCI_CLASS_OTHERS0xff) { /* qemu-kvm */ | |||
1349 | vpci_dev->class_code = PCI_CLASS_COMMUNICATION_OTHER0x0780; | |||
1350 | } | |||
1351 | ||||
1352 | /* backwards-compatibility with machines that were created with | |||
1353 | DEV_NVECTORS_UNSPECIFIED */ | |||
1354 | if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | |||
1355 | vpci_dev->nvectors = dev->vdev.serial.max_virtserial_ports + 1; | |||
1356 | } | |||
1357 | ||||
1358 | /* | |||
1359 | * For command line compatibility, this sets the virtio-serial-device bus | |||
1360 | * name as before. | |||
1361 | */ | |||
1362 | if (proxy->id) { | |||
1363 | bus_name = g_strdup_printf("%s.0", proxy->id); | |||
1364 | virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev)((VirtIODevice *)object_dynamic_cast_assert(((Object *)((vdev ))), ("virtio-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1364, __func__)), bus_name); | |||
1365 | g_free(bus_name); | |||
1366 | } | |||
1367 | ||||
1368 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)((BusState *)object_dynamic_cast_assert(((Object *)((&vpci_dev ->bus))), ("bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1368, __func__))); | |||
1369 | if (qdev_init(vdev) < 0) { | |||
1370 | return -1; | |||
1371 | } | |||
1372 | return 0; | |||
1373 | } | |||
1374 | ||||
1375 | static Property virtio_serial_pci_properties[] = { | |||
1376 | DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,{ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)1, } | |||
1377 | VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true){ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1378 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2){ .name = ("vectors"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOPCIProxy, nvectors) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->nvectors)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)2, }, | |||
1379 | DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0){ .name = ("class"), .info = &(qdev_prop_hex32), .offset = __builtin_offsetof(VirtIOPCIProxy, class_code) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->class_code)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)0, }, | |||
1380 | DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features){ .name = ("indirect_desc"), .info = &(qdev_prop_bit), .bitnr = (28), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("event_idx"), .info = &(qdev_prop_bit), .bitnr = (29), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1381 | DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOSerialPCI, vdev.serial){ .name = ("max_ports"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOSerialPCI, vdev.serial.max_virtserial_ports ) + ((uint32_t*)0 - (typeof(((VirtIOSerialPCI *)0)->vdev.serial .max_virtserial_ports)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t )31, }, | |||
1382 | DEFINE_PROP_END_OF_LIST(){}, | |||
1383 | }; | |||
1384 | ||||
1385 | static void virtio_serial_pci_class_init(ObjectClass *klass, void *data) | |||
1386 | { | |||
1387 | DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1387, __func__)); | |||
1388 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass)((VirtioPCIClass *)object_class_dynamic_cast_assert(((ObjectClass *)(klass)), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1388, __func__)); | |||
1389 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass)((PCIDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1389, __func__)); | |||
1390 | k->init = virtio_serial_pci_init; | |||
1391 | set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | |||
1392 | dc->props = virtio_serial_pci_properties; | |||
1393 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET0x1af4; | |||
1394 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE0x1003; | |||
1395 | pcidev_k->revision = VIRTIO_PCI_ABI_VERSION0; | |||
1396 | pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER0x0780; | |||
1397 | } | |||
1398 | ||||
1399 | static void virtio_serial_pci_instance_init(Object *obj) | |||
1400 | { | |||
1401 | VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(obj)((VirtIOSerialPCI *)object_dynamic_cast_assert(((Object *)((obj ))), ("virtio-serial-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1401, __func__)); | |||
1402 | object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_SERIAL"virtio-serial-device"); | |||
1403 | object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev)((Object *)(&dev->vdev)), NULL((void*)0)); | |||
1404 | } | |||
1405 | ||||
1406 | static const TypeInfo virtio_serial_pci_info = { | |||
1407 | .name = TYPE_VIRTIO_SERIAL_PCI"virtio-serial-pci", | |||
1408 | .parent = TYPE_VIRTIO_PCI"virtio-pci", | |||
1409 | .instance_size = sizeof(VirtIOSerialPCI), | |||
1410 | .instance_init = virtio_serial_pci_instance_init, | |||
1411 | .class_init = virtio_serial_pci_class_init, | |||
1412 | }; | |||
1413 | ||||
1414 | /* virtio-net-pci */ | |||
1415 | ||||
1416 | static Property virtio_net_properties[] = { | |||
1417 | DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,{ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)0, } | |||
1418 | VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false){ .name = ("ioeventfd"), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof(VirtIOPCIProxy, flags) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->flags)*)0) , .qtype = QTYPE_QBOOL, .defval = (_Bool)0, }, | |||
1419 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3){ .name = ("vectors"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIOPCIProxy, nvectors) + ((uint32_t* )0 - (typeof(((VirtIOPCIProxy *)0)->nvectors)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)3, }, | |||
1420 | DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features){ .name = ("indirect_desc"), .info = &(qdev_prop_bit), .bitnr = (28), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("event_idx"), .info = &(qdev_prop_bit), .bitnr = (29), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("any_layout"), .info = &(qdev_prop_bit), .bitnr = (27), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("csum"), .info = &(qdev_prop_bit), .bitnr = (0), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ((uint32_t *)0 - (typeof(((VirtIOPCIProxy *)0)->host_features)*)0), . qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("guest_csum" ), .info = &(qdev_prop_bit), .bitnr = (1), .offset = __builtin_offsetof (VirtIOPCIProxy, host_features) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features)*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("gso"), .info = &(qdev_prop_bit) , .bitnr = (6), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("guest_tso4"), .info = &(qdev_prop_bit), .bitnr = (7), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("guest_tso6"), .info = &(qdev_prop_bit), .bitnr = (8), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("guest_ecn"), .info = &(qdev_prop_bit), .bitnr = (9), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("guest_ufo"), .info = &(qdev_prop_bit), .bitnr = (10), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("host_tso4"), .info = &(qdev_prop_bit), .bitnr = (11), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("host_tso6"), .info = &(qdev_prop_bit), .bitnr = (12), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("host_ecn"), .info = &(qdev_prop_bit), .bitnr = (13), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("host_ufo"), .info = &(qdev_prop_bit), .bitnr = (14), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("mrg_rxbuf"), .info = &(qdev_prop_bit), .bitnr = (15), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("status"), .info = &(qdev_prop_bit), .bitnr = (16), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ((uint32_t *)0 - (typeof(((VirtIOPCIProxy *)0)->host_features)*)0), . qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("ctrl_vq" ), .info = &(qdev_prop_bit), .bitnr = (17), .offset = __builtin_offsetof (VirtIOPCIProxy, host_features) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features)*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("ctrl_rx"), .info = &(qdev_prop_bit ), .bitnr = (18), .offset = __builtin_offsetof(VirtIOPCIProxy , host_features) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy * )0)->host_features)*)0), .qtype = QTYPE_QBOOL, .defval = ( _Bool)1, }, { .name = ("ctrl_vlan"), .info = &(qdev_prop_bit ), .bitnr = (19), .offset = __builtin_offsetof(VirtIOPCIProxy , host_features) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy * )0)->host_features)*)0), .qtype = QTYPE_QBOOL, .defval = ( _Bool)1, }, { .name = ("ctrl_rx_extra"), .info = &(qdev_prop_bit ), .bitnr = (20), .offset = __builtin_offsetof(VirtIOPCIProxy , host_features) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy * )0)->host_features)*)0), .qtype = QTYPE_QBOOL, .defval = ( _Bool)1, }, { .name = ("ctrl_mac_addr"), .info = &(qdev_prop_bit ), .bitnr = (23), .offset = __builtin_offsetof(VirtIOPCIProxy , host_features) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy * )0)->host_features)*)0), .qtype = QTYPE_QBOOL, .defval = ( _Bool)1, }, { .name = ("ctrl_guest_offloads"), .info = &( qdev_prop_bit), .bitnr = (2), .offset = __builtin_offsetof(VirtIOPCIProxy , host_features) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy * )0)->host_features)*)0), .qtype = QTYPE_QBOOL, .defval = ( _Bool)1, }, { .name = ("mq"), .info = &(qdev_prop_bit), . bitnr = (22), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)0, }, | |||
1421 | DEFINE_NIC_PROPERTIES(VirtIONetPCI, vdev.nic_conf){ .name = ("mac"), .info = &(qdev_prop_macaddr), .offset = __builtin_offsetof(VirtIONetPCI, vdev.nic_conf.macaddr) + (( MACAddr*)0 - (typeof(((VirtIONetPCI *)0)->vdev.nic_conf.macaddr )*)0), }, { .name = ("vlan"), .info = &(qdev_prop_vlan), . offset = __builtin_offsetof(VirtIONetPCI, vdev.nic_conf.peers ) + ((NICPeers*)0 - (typeof(((VirtIONetPCI *)0)->vdev.nic_conf .peers)*)0), }, { .name = ("netdev"), .info = &(qdev_prop_netdev ), .offset = __builtin_offsetof(VirtIONetPCI, vdev.nic_conf.peers ) + ((NICPeers*)0 - (typeof(((VirtIONetPCI *)0)->vdev.nic_conf .peers)*)0), }, { .name = ("bootindex"), .info = &(qdev_prop_int32 ), .offset = __builtin_offsetof(VirtIONetPCI, vdev.nic_conf.bootindex ) + ((int32_t*)0 - (typeof(((VirtIONetPCI *)0)->vdev.nic_conf .bootindex)*)0), .qtype = QTYPE_QINT, .defval = (int32_t)-1, }, | |||
1422 | DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetPCI, vdev.net_conf){ .name = ("x-txtimer"), .info = &(qdev_prop_uint32), .offset = __builtin_offsetof(VirtIONetPCI, vdev.net_conf.txtimer) + ( (uint32_t*)0 - (typeof(((VirtIONetPCI *)0)->vdev.net_conf. txtimer)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)150000 , }, { .name = ("x-txburst"), .info = &(qdev_prop_int32), .offset = __builtin_offsetof(VirtIONetPCI, vdev.net_conf.txburst ) + ((int32_t*)0 - (typeof(((VirtIONetPCI *)0)->vdev.net_conf .txburst)*)0), .qtype = QTYPE_QINT, .defval = (int32_t)256, } , { .name = ("tx"), .info = &(qdev_prop_string), .offset = __builtin_offsetof(VirtIONetPCI, vdev.net_conf.tx) + ((char* *)0 - (typeof(((VirtIONetPCI *)0)->vdev.net_conf.tx)*)0), }, | |||
1423 | DEFINE_PROP_END_OF_LIST(){}, | |||
1424 | }; | |||
1425 | ||||
1426 | static int virtio_net_pci_init(VirtIOPCIProxy *vpci_dev) | |||
1427 | { | |||
1428 | DeviceState *qdev = DEVICE(vpci_dev)((DeviceState *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1428, __func__)); | |||
1429 | VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev)((VirtIONetPCI *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("virtio-net-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1429, __func__)); | |||
1430 | DeviceState *vdev = DEVICE(&dev->vdev)((DeviceState *)object_dynamic_cast_assert(((Object *)((& dev->vdev))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1430, __func__)); | |||
1431 | ||||
1432 | virtio_net_set_config_size(&dev->vdev, vpci_dev->host_features); | |||
1433 | virtio_net_set_netclient_name(&dev->vdev, qdev->id, | |||
1434 | object_get_typename(OBJECT(qdev)((Object *)(qdev)))); | |||
1435 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)((BusState *)object_dynamic_cast_assert(((Object *)((&vpci_dev ->bus))), ("bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1435, __func__))); | |||
1436 | if (qdev_init(vdev) < 0) { | |||
1437 | return -1; | |||
1438 | } | |||
1439 | return 0; | |||
1440 | } | |||
1441 | ||||
1442 | static void virtio_net_pci_class_init(ObjectClass *klass, void *data) | |||
1443 | { | |||
1444 | DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1444, __func__)); | |||
1445 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass)((PCIDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1445, __func__)); | |||
1446 | VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass)((VirtioPCIClass *)object_class_dynamic_cast_assert(((ObjectClass *)(klass)), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1446, __func__)); | |||
1447 | ||||
1448 | k->romfile = "efi-virtio.rom"; | |||
1449 | k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET0x1af4; | |||
1450 | k->device_id = PCI_DEVICE_ID_VIRTIO_NET0x1000; | |||
1451 | k->revision = VIRTIO_PCI_ABI_VERSION0; | |||
1452 | k->class_id = PCI_CLASS_NETWORK_ETHERNET0x0200; | |||
1453 | set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); | |||
1454 | dc->props = virtio_net_properties; | |||
1455 | vpciklass->init = virtio_net_pci_init; | |||
1456 | } | |||
1457 | ||||
1458 | static void virtio_net_pci_instance_init(Object *obj) | |||
1459 | { | |||
1460 | VirtIONetPCI *dev = VIRTIO_NET_PCI(obj)((VirtIONetPCI *)object_dynamic_cast_assert(((Object *)((obj) )), ("virtio-net-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1460, __func__)); | |||
1461 | object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_NET"virtio-net-device"); | |||
1462 | object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev)((Object *)(&dev->vdev)), NULL((void*)0)); | |||
1463 | } | |||
1464 | ||||
1465 | static const TypeInfo virtio_net_pci_info = { | |||
1466 | .name = TYPE_VIRTIO_NET_PCI"virtio-net-pci", | |||
1467 | .parent = TYPE_VIRTIO_PCI"virtio-pci", | |||
1468 | .instance_size = sizeof(VirtIONetPCI), | |||
1469 | .instance_init = virtio_net_pci_instance_init, | |||
1470 | .class_init = virtio_net_pci_class_init, | |||
1471 | }; | |||
1472 | ||||
1473 | /* virtio-rng-pci */ | |||
1474 | ||||
1475 | static Property virtio_rng_pci_properties[] = { | |||
1476 | DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features){ .name = ("indirect_desc"), .info = &(qdev_prop_bit), .bitnr = (28), .offset = __builtin_offsetof(VirtIOPCIProxy, host_features ) + ((uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, { .name = ("event_idx"), .info = &(qdev_prop_bit), .bitnr = (29), . offset = __builtin_offsetof(VirtIOPCIProxy, host_features) + ( (uint32_t*)0 - (typeof(((VirtIOPCIProxy *)0)->host_features )*)0), .qtype = QTYPE_QBOOL, .defval = (_Bool)1, }, | |||
1477 | DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORngPCI, vdev.conf){ .name = ("max-bytes"), .info = &(qdev_prop_uint64), .offset = __builtin_offsetof(VirtIORngPCI, vdev.conf.max_bytes) + (( uint64_t*)0 - (typeof(((VirtIORngPCI *)0)->vdev.conf.max_bytes )*)0), .qtype = QTYPE_QINT, .defval = (uint64_t)(9223372036854775807L ), }, { .name = ("period"), .info = &(qdev_prop_uint32), . offset = __builtin_offsetof(VirtIORngPCI, vdev.conf.period_ms ) + ((uint32_t*)0 - (typeof(((VirtIORngPCI *)0)->vdev.conf .period_ms)*)0), .qtype = QTYPE_QINT, .defval = (uint32_t)1 << 16, }, | |||
1478 | DEFINE_PROP_END_OF_LIST(){}, | |||
1479 | }; | |||
1480 | ||||
1481 | static int virtio_rng_pci_init(VirtIOPCIProxy *vpci_dev) | |||
1482 | { | |||
1483 | VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev)((VirtIORngPCI *)object_dynamic_cast_assert(((Object *)((vpci_dev ))), ("virtio-rng-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1483, __func__)); | |||
1484 | DeviceState *vdev = DEVICE(&vrng->vdev)((DeviceState *)object_dynamic_cast_assert(((Object *)((& vrng->vdev))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1484, __func__)); | |||
1485 | ||||
1486 | qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)((BusState *)object_dynamic_cast_assert(((Object *)((&vpci_dev ->bus))), ("bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1486, __func__))); | |||
1487 | if (qdev_init(vdev) < 0) { | |||
1488 | return -1; | |||
1489 | } | |||
1490 | ||||
1491 | object_property_set_link(OBJECT(vrng)((Object *)(vrng)), | |||
1492 | OBJECT(vrng->vdev.conf.rng)((Object *)(vrng->vdev.conf.rng)), "rng", | |||
1493 | NULL((void*)0)); | |||
1494 | ||||
1495 | return 0; | |||
1496 | } | |||
1497 | ||||
1498 | static void virtio_rng_pci_class_init(ObjectClass *klass, void *data) | |||
1499 | { | |||
1500 | DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1500, __func__)); | |||
1501 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass)((VirtioPCIClass *)object_class_dynamic_cast_assert(((ObjectClass *)(klass)), ("virtio-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1501, __func__)); | |||
1502 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass)((PCIDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass *)((klass))), ("pci-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1502, __func__)); | |||
1503 | ||||
1504 | k->init = virtio_rng_pci_init; | |||
1505 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); | |||
1506 | dc->props = virtio_rng_pci_properties; | |||
1507 | ||||
1508 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET0x1af4; | |||
1509 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG0x1005; | |||
1510 | pcidev_k->revision = VIRTIO_PCI_ABI_VERSION0; | |||
1511 | pcidev_k->class_id = PCI_CLASS_OTHERS0xff; | |||
1512 | } | |||
1513 | ||||
1514 | static void virtio_rng_initfn(Object *obj) | |||
1515 | { | |||
1516 | VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj)((VirtIORngPCI *)object_dynamic_cast_assert(((Object *)((obj) )), ("virtio-rng-pci"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1516, __func__)); | |||
1517 | object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_RNG"virtio-rng-device"); | |||
1518 | object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev)((Object *)(&dev->vdev)), NULL((void*)0)); | |||
1519 | object_property_add_link(obj, "rng", TYPE_RNG_BACKEND"rng-backend", | |||
1520 | (Object **)&dev->vdev.conf.rng, NULL((void*)0)); | |||
1521 | ||||
1522 | } | |||
1523 | ||||
1524 | static const TypeInfo virtio_rng_pci_info = { | |||
1525 | .name = TYPE_VIRTIO_RNG_PCI"virtio-rng-pci", | |||
1526 | .parent = TYPE_VIRTIO_PCI"virtio-pci", | |||
1527 | .instance_size = sizeof(VirtIORngPCI), | |||
1528 | .instance_init = virtio_rng_initfn, | |||
1529 | .class_init = virtio_rng_pci_class_init, | |||
1530 | }; | |||
1531 | ||||
1532 | /* virtio-pci-bus */ | |||
1533 | ||||
1534 | static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size, | |||
1535 | VirtIOPCIProxy *dev) | |||
1536 | { | |||
1537 | DeviceState *qdev = DEVICE(dev)((DeviceState *)object_dynamic_cast_assert(((Object *)((dev)) ), ("device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1537, __func__)); | |||
1538 | BusState *qbus; | |||
1539 | char virtio_bus_name[] = "virtio-bus"; | |||
1540 | ||||
1541 | qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_PCI_BUS"virtio-pci-bus", qdev, | |||
1542 | virtio_bus_name); | |||
1543 | qbus = BUS(bus)((BusState *)object_dynamic_cast_assert(((Object *)((bus))), ( "bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1543, __func__)); | |||
1544 | qbus->allow_hotplug = 1; | |||
1545 | } | |||
1546 | ||||
1547 | static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) | |||
1548 | { | |||
1549 | BusClass *bus_class = BUS_CLASS(klass)((BusClass *)object_class_dynamic_cast_assert(((ObjectClass * )((klass))), ("bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1549, __func__)); | |||
1550 | VirtioBusClass *k = VIRTIO_BUS_CLASS(klass)((VirtioBusClass *)object_class_dynamic_cast_assert(((ObjectClass *)(klass)), ("virtio-bus"), "/home/stefan/src/qemu/qemu.org/qemu/hw/virtio/virtio-pci.c" , 1550, __func__)); | |||
1551 | bus_class->max_dev = 1; | |||
1552 | k->notify = virtio_pci_notify; | |||
1553 | k->save_config = virtio_pci_save_config; | |||
1554 | k->load_config = virtio_pci_load_config; | |||
1555 | k->save_queue = virtio_pci_save_queue; | |||
1556 | k->load_queue = virtio_pci_load_queue; | |||
1557 | k->get_features = virtio_pci_get_features; | |||
1558 | k->query_guest_notifiers = virtio_pci_query_guest_notifiers; | |||
1559 | k->set_host_notifier = virtio_pci_set_host_notifier; | |||
1560 | k->set_guest_notifiers = virtio_pci_set_guest_notifiers; | |||
1561 | k->vmstate_change = virtio_pci_vmstate_change; | |||
1562 | k->device_plugged = virtio_pci_device_plugged; | |||
1563 | k->device_unplugged = virtio_pci_device_unplugged; | |||
1564 | } | |||
1565 | ||||
1566 | static const TypeInfo virtio_pci_bus_info = { | |||
1567 | .name = TYPE_VIRTIO_PCI_BUS"virtio-pci-bus", | |||
1568 | .parent = TYPE_VIRTIO_BUS"virtio-bus", | |||
1569 | .instance_size = sizeof(VirtioPCIBusState), | |||
1570 | .class_init = virtio_pci_bus_class_init, | |||
1571 | }; | |||
1572 | ||||
1573 | static void virtio_pci_register_types(void) | |||
1574 | { | |||
1575 | type_register_static(&virtio_rng_pci_info); | |||
1576 | type_register_static(&virtio_pci_bus_info); | |||
1577 | type_register_static(&virtio_pci_info); | |||
1578 | #ifdef CONFIG_VIRTFS1 | |||
1579 | type_register_static(&virtio_9p_pci_info); | |||
1580 | #endif | |||
1581 | type_register_static(&virtio_blk_pci_info); | |||
1582 | type_register_static(&virtio_scsi_pci_info); | |||
1583 | type_register_static(&virtio_balloon_pci_info); | |||
1584 | type_register_static(&virtio_serial_pci_info); | |||
1585 | type_register_static(&virtio_net_pci_info); | |||
1586 | #ifdef CONFIG_VHOST_SCSI1 | |||
1587 | type_register_static(&vhost_scsi_pci_info); | |||
1588 | #endif | |||
1589 | } | |||
1590 | ||||
1591 | type_init(virtio_pci_register_types)static void __attribute__((constructor)) do_qemu_init_virtio_pci_register_types (void) { register_module_init(virtio_pci_register_types, MODULE_INIT_QOM ); } |