| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Virtio PCI Bindings | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright IBM, Corp. 2007 | 
					
						
							|  |  |  |  * Copyright (c) 2009 CodeSourcery | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Authors: | 
					
						
							|  |  |  |  *  Anthony Liguori   <aliguori@us.ibm.com> | 
					
						
							|  |  |  |  *  Paul Brook        <paul@codesourcery.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This work is licensed under the terms of the GNU GPL, version 2.  See | 
					
						
							|  |  |  |  * the COPYING file in the top-level directory. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-01-13 17:44:23 +01:00
										 |  |  |  * Contributions after 2012-01-13 are licensed under the terms of the | 
					
						
							|  |  |  |  * GNU GPL, version 2 or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 18:17:07 +00:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-16 22:36:43 +01:00
										 |  |  | #include "standard-headers/linux/virtio_pci.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-05 17:06:20 +01:00
										 |  |  | #include "hw/virtio/virtio.h"
 | 
					
						
							|  |  |  | #include "hw/virtio/virtio-blk.h"
 | 
					
						
							|  |  |  | #include "hw/virtio/virtio-net.h"
 | 
					
						
							|  |  |  | #include "hw/virtio/virtio-serial.h"
 | 
					
						
							|  |  |  | #include "hw/virtio/virtio-scsi.h"
 | 
					
						
							|  |  |  | #include "hw/virtio/virtio-balloon.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:41 +02:00
										 |  |  | #include "hw/virtio/virtio-input.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:40:22 +01:00
										 |  |  | #include "hw/pci/pci.h"
 | 
					
						
							| 
									
										
											  
											
												include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef.  Since then, we've moved to include qemu/osdep.h
everywhere.  Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h.  That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h.  Include qapi/error.h in .c files that need it and don't
get it now.  Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly.  Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h.  Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third.  Unfortunately, the number depending on
qapi-types.h shrinks only a little.  More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
											
										 
											2016-03-14 09:01:28 +01:00
										 |  |  | #include "qapi/error.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-17 18:20:00 +01:00
										 |  |  | #include "qemu/error-report.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:40:22 +01:00
										 |  |  | #include "hw/pci/msi.h"
 | 
					
						
							|  |  |  | #include "hw/pci/msix.h"
 | 
					
						
							|  |  |  | #include "hw/loader.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-17 18:20:04 +01:00
										 |  |  | #include "sysemu/kvm.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-18 17:36:02 +01:00
										 |  |  | #include "virtio-pci.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-17 18:20:00 +01:00
										 |  |  | #include "qemu/range.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-05 17:06:20 +01:00
										 |  |  | #include "hw/virtio/virtio-bus.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-14 14:07:00 +02:00
										 |  |  | #include "qapi/visitor.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-16 22:36:43 +01:00
										 |  |  | #define VIRTIO_PCI_REGION_SIZE(dev)     VIRTIO_PCI_CONFIG_OFF(msix_present(dev))
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:21 +02:00
										 |  |  | #undef VIRTIO_PCI_CONFIG
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  | /* The remaining space is defined by each driver as the per-driver
 | 
					
						
							|  |  |  |  * configuration space */ | 
					
						
							| 
									
										
										
										
											2015-02-16 22:36:43 +01:00
										 |  |  | #define VIRTIO_PCI_CONFIG_SIZE(dev)     VIRTIO_PCI_CONFIG_OFF(msix_enabled(dev))
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-23 20:35:18 +02:00
										 |  |  | static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size, | 
					
						
							|  |  |  |                                VirtIOPCIProxy *dev); | 
					
						
							| 
									
										
										
										
											2016-01-28 16:08:07 +01:00
										 |  |  | static void virtio_pci_reset(DeviceState *qdev); | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | /* virtio device */ | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  | /* DeviceState to VirtIOPCIProxy. For use off data-path. TODO: use QOM. */ | 
					
						
							|  |  |  | static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return container_of(d, VirtIOPCIProxy, pci_dev.qdev); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  | /* DeviceState to VirtIOPCIProxy. Note: used on datapath,
 | 
					
						
							|  |  |  |  * be careful and test performance if you change this. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static inline VirtIOPCIProxy *to_virtio_pci_proxy_fast(DeviceState *d) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  |     return container_of(d, VirtIOPCIProxy, pci_dev.qdev); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_notify(DeviceState *d, uint16_t vector) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy_fast(d); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  |     if (msix_enabled(&proxy->pci_dev)) | 
					
						
							|  |  |  |         msix_notify(&proxy->pci_dev, vector); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     else { | 
					
						
							|  |  |  |         VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2016-11-18 16:07:01 +01:00
										 |  |  |         pci_set_irq(&proxy->pci_dev, atomic_read(&vdev->isr) & 1); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  | static void virtio_pci_save_config(DeviceState *d, QEMUFile *f) | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  |     pci_device_save(&proxy->pci_dev, f); | 
					
						
							|  |  |  |     msix_save(&proxy->pci_dev, f); | 
					
						
							|  |  |  |     if (msix_present(&proxy->pci_dev)) | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         qemu_put_be16(f, vdev->config_vector); | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 17:05:17 +01:00
										 |  |  | static const VMStateDescription vmstate_virtio_pci_modern_queue_state = { | 
					
						
							|  |  |  |     .name = "virtio_pci/modern_queue_state", | 
					
						
							|  |  |  |     .version_id = 1, | 
					
						
							|  |  |  |     .minimum_version_id = 1, | 
					
						
							|  |  |  |     .fields = (VMStateField[]) { | 
					
						
							|  |  |  |         VMSTATE_UINT16(num, VirtIOPCIQueue), | 
					
						
							|  |  |  |         VMSTATE_UNUSED(1), /* enabled was stored as be16 */ | 
					
						
							|  |  |  |         VMSTATE_BOOL(enabled, VirtIOPCIQueue), | 
					
						
							|  |  |  |         VMSTATE_UINT32_ARRAY(desc, VirtIOPCIQueue, 2), | 
					
						
							|  |  |  |         VMSTATE_UINT32_ARRAY(avail, VirtIOPCIQueue, 2), | 
					
						
							|  |  |  |         VMSTATE_UINT32_ARRAY(used, VirtIOPCIQueue, 2), | 
					
						
							|  |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:44 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static bool virtio_pci_modern_state_needed(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = opaque; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 18:28:21 +03:00
										 |  |  |     return virtio_pci_modern(proxy); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:44 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 17:05:17 +01:00
										 |  |  | static const VMStateDescription vmstate_virtio_pci_modern_state_sub = { | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:44 +08:00
										 |  |  |     .name = "virtio_pci/modern_state", | 
					
						
							|  |  |  |     .version_id = 1, | 
					
						
							|  |  |  |     .minimum_version_id = 1, | 
					
						
							|  |  |  |     .needed = &virtio_pci_modern_state_needed, | 
					
						
							|  |  |  |     .fields = (VMStateField[]) { | 
					
						
							| 
									
										
										
										
											2017-09-25 17:05:17 +01:00
										 |  |  |         VMSTATE_UINT32(dfselect, VirtIOPCIProxy), | 
					
						
							|  |  |  |         VMSTATE_UINT32(gfselect, VirtIOPCIProxy), | 
					
						
							|  |  |  |         VMSTATE_UINT32_ARRAY(guest_features, VirtIOPCIProxy, 2), | 
					
						
							|  |  |  |         VMSTATE_STRUCT_ARRAY(vqs, VirtIOPCIProxy, VIRTIO_QUEUE_MAX, 0, | 
					
						
							|  |  |  |                              vmstate_virtio_pci_modern_queue_state, | 
					
						
							|  |  |  |                              VirtIOPCIQueue), | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:44 +08:00
										 |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const VMStateDescription vmstate_virtio_pci = { | 
					
						
							|  |  |  |     .name = "virtio_pci", | 
					
						
							|  |  |  |     .version_id = 1, | 
					
						
							|  |  |  |     .minimum_version_id = 1, | 
					
						
							|  |  |  |     .minimum_version_id_old = 1, | 
					
						
							|  |  |  |     .fields = (VMStateField[]) { | 
					
						
							|  |  |  |         VMSTATE_END_OF_LIST() | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     .subsections = (const VMStateDescription*[]) { | 
					
						
							| 
									
										
										
										
											2017-09-25 17:05:17 +01:00
										 |  |  |         &vmstate_virtio_pci_modern_state_sub, | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:44 +08:00
										 |  |  |         NULL | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-25 17:05:17 +01:00
										 |  |  | static bool virtio_pci_has_extra_state(DeviceState *d) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return proxy->flags & VIRTIO_PCI_FLAG_MIGRATE_EXTRA; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:44 +08:00
										 |  |  | static void virtio_pci_save_extra_state(DeviceState *d, QEMUFile *f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     vmstate_save_state(f, &vmstate_virtio_pci, proxy, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int virtio_pci_load_extra_state(DeviceState *d, QEMUFile *f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return vmstate_load_state(f, &vmstate_virtio_pci, proxy, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  | static void virtio_pci_save_queue(DeviceState *d, int n, QEMUFile *f) | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  |     if (msix_present(&proxy->pci_dev)) | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         qemu_put_be16(f, virtio_queue_vector(vdev, n)); | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  | static int virtio_pci_load_config(DeviceState *d, QEMUFile *f) | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  |     int ret; | 
					
						
							|  |  |  |     ret = pci_device_load(&proxy->pci_dev, f); | 
					
						
							| 
									
										
										
										
											2009-07-05 16:02:34 +03:00
										 |  |  |     if (ret) { | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  |         return ret; | 
					
						
							| 
									
										
										
										
											2009-07-05 16:02:34 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-08-29 19:40:56 +03:00
										 |  |  |     msix_unuse_all_vectors(&proxy->pci_dev); | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  |     msix_load(&proxy->pci_dev, f); | 
					
						
							| 
									
										
										
										
											2009-07-05 16:02:34 +03:00
										 |  |  |     if (msix_present(&proxy->pci_dev)) { | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         qemu_get_be16s(f, &vdev->config_vector); | 
					
						
							| 
									
										
										
										
											2009-07-05 16:02:34 +03:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         vdev->config_vector = VIRTIO_NO_VECTOR; | 
					
						
							| 
									
										
										
										
											2009-07-05 16:02:34 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     if (vdev->config_vector != VIRTIO_NO_VECTOR) { | 
					
						
							|  |  |  |         return msix_vector_use(&proxy->pci_dev, vdev->config_vector); | 
					
						
							| 
									
										
										
										
											2009-07-05 16:02:34 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  | static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f) | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  |     uint16_t vector; | 
					
						
							| 
									
										
										
										
											2009-07-05 16:02:34 +03:00
										 |  |  |     if (msix_present(&proxy->pci_dev)) { | 
					
						
							|  |  |  |         qemu_get_be16s(f, &vector); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         vector = VIRTIO_NO_VECTOR; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     virtio_queue_set_vector(vdev, n, vector); | 
					
						
							| 
									
										
										
										
											2009-07-05 16:02:34 +03:00
										 |  |  |     if (vector != VIRTIO_NO_VECTOR) { | 
					
						
							|  |  |  |         return msix_vector_use(&proxy->pci_dev, vector); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:40 +03:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-21 22:48:08 +02:00
										 |  |  | static bool virtio_pci_ioeventfd_enabled(DeviceState *d) | 
					
						
							| 
									
										
										
										
											2016-06-10 11:04:12 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-21 22:48:08 +02:00
										 |  |  |     return (proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD) != 0; | 
					
						
							| 
									
										
										
										
											2016-06-10 11:04:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:30 +02:00
										 |  |  | #define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 18:02:25 +03:00
										 |  |  | static inline int virtio_pci_queue_mem_mult(struct VirtIOPCIProxy *proxy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return (proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ) ? | 
					
						
							|  |  |  |         QEMU_VIRTIO_PCI_QUEUE_MEM_MULT : 4; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-10 11:04:12 +02:00
										 |  |  | static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier *notifier, | 
					
						
							|  |  |  |                                        int n, bool assign) | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-10 11:04:12 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  |     VirtQueue *vq = virtio_get_queue(vdev, n); | 
					
						
							| 
									
										
										
										
											2016-07-20 18:28:21 +03:00
										 |  |  |     bool legacy = virtio_pci_legacy(proxy); | 
					
						
							|  |  |  |     bool modern = virtio_pci_modern(proxy); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:47 +08:00
										 |  |  |     bool fast_mmio = kvm_ioeventfd_any_length_enabled(); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |     bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:33 +02:00
										 |  |  |     MemoryRegion *modern_mr = &proxy->notify.mr; | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |     MemoryRegion *modern_notify_mr = &proxy->notify_pio.mr; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:30 +02:00
										 |  |  |     MemoryRegion *legacy_mr = &proxy->bar; | 
					
						
							| 
									
										
										
										
											2016-09-07 18:02:25 +03:00
										 |  |  |     hwaddr modern_addr = virtio_pci_queue_mem_mult(proxy) * | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:30 +02:00
										 |  |  |                          virtio_get_queue_index(vq); | 
					
						
							|  |  |  |     hwaddr legacy_addr = VIRTIO_PCI_QUEUE_NOTIFY; | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:13 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  |     if (assign) { | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:30 +02:00
										 |  |  |         if (modern) { | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:47 +08:00
										 |  |  |             if (fast_mmio) { | 
					
						
							|  |  |  |                 memory_region_add_eventfd(modern_mr, modern_addr, 0, | 
					
						
							|  |  |  |                                           false, n, notifier); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 memory_region_add_eventfd(modern_mr, modern_addr, 2, | 
					
						
							|  |  |  |                                           false, n, notifier); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |             if (modern_pio) { | 
					
						
							|  |  |  |                 memory_region_add_eventfd(modern_notify_mr, 0, 2, | 
					
						
							|  |  |  |                                               true, n, notifier); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:30 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (legacy) { | 
					
						
							|  |  |  |             memory_region_add_eventfd(legacy_mr, legacy_addr, 2, | 
					
						
							|  |  |  |                                       true, n, notifier); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:30 +02:00
										 |  |  |         if (modern) { | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:47 +08:00
										 |  |  |             if (fast_mmio) { | 
					
						
							|  |  |  |                 memory_region_del_eventfd(modern_mr, modern_addr, 0, | 
					
						
							|  |  |  |                                           false, n, notifier); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 memory_region_del_eventfd(modern_mr, modern_addr, 2, | 
					
						
							|  |  |  |                                           false, n, notifier); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |             if (modern_pio) { | 
					
						
							|  |  |  |                 memory_region_del_eventfd(modern_notify_mr, 0, 2, | 
					
						
							|  |  |  |                                           true, n, notifier); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:30 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (legacy) { | 
					
						
							|  |  |  |             memory_region_del_eventfd(legacy_mr, legacy_addr, 2, | 
					
						
							|  |  |  |                                       true, n, notifier); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-10 11:04:12 +02:00
										 |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-11 14:10:15 +02:00
										 |  |  | static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy) | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-10 11:04:12 +02:00
										 |  |  |     virtio_bus_start_ioeventfd(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-11 14:10:15 +02:00
										 |  |  | static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy) | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-10 11:04:12 +02:00
										 |  |  |     virtio_bus_stop_ioeventfd(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = opaque; | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  |     hwaddr pa; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     switch (addr) { | 
					
						
							|  |  |  |     case VIRTIO_PCI_GUEST_FEATURES: | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  |         /* Guest does not negotiate properly?  We have to assume nothing. */ | 
					
						
							|  |  |  |         if (val & (1 << VIRTIO_F_BAD_FEATURE)) { | 
					
						
							|  |  |  |             val = virtio_bus_get_vdev_bad_features(&proxy->bus); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-11-24 13:28:52 +01:00
										 |  |  |         virtio_set_features(vdev, val); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_QUEUE_PFN: | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  |         pa = (hwaddr)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT; | 
					
						
							| 
									
										
										
										
											2009-11-24 16:45:35 +02:00
										 |  |  |         if (pa == 0) { | 
					
						
							| 
									
										
										
										
											2016-01-28 16:08:07 +01:00
										 |  |  |             virtio_pci_reset(DEVICE(proxy)); | 
					
						
							| 
									
										
										
										
											2009-11-24 16:45:35 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:13 +03:00
										 |  |  |         else | 
					
						
							|  |  |  |             virtio_queue_set_addr(vdev, vdev->queue_sel, pa); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_QUEUE_SEL: | 
					
						
							| 
									
										
										
										
											2015-05-29 14:15:31 +08:00
										 |  |  |         if (val < VIRTIO_QUEUE_MAX) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |             vdev->queue_sel = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_QUEUE_NOTIFY: | 
					
						
							| 
									
										
										
										
											2015-05-29 14:15:31 +08:00
										 |  |  |         if (val < VIRTIO_QUEUE_MAX) { | 
					
						
							| 
									
										
										
										
											2011-05-08 22:29:07 +01:00
										 |  |  |             virtio_queue_notify(vdev, val); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_STATUS: | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  |         if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) { | 
					
						
							|  |  |  |             virtio_pci_stop_ioeventfd(proxy); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:05 +02:00
										 |  |  |         virtio_set_status(vdev, val & 0xFF); | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (val & VIRTIO_CONFIG_S_DRIVER_OK) { | 
					
						
							|  |  |  |             virtio_pci_start_ioeventfd(proxy); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-24 16:45:35 +02:00
										 |  |  |         if (vdev->status == 0) { | 
					
						
							| 
									
										
										
										
											2016-01-28 16:08:07 +01:00
										 |  |  |             virtio_pci_reset(DEVICE(proxy)); | 
					
						
							| 
									
										
										
										
											2009-11-24 16:45:35 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-16 19:18:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-11 18:45:33 +02:00
										 |  |  |         /* Linux before 2.6.34 drives the device without enabling
 | 
					
						
							|  |  |  |            the PCI device bus master bit. Enable it automatically | 
					
						
							|  |  |  |            for the guest. This is a PCI spec violation but so is | 
					
						
							|  |  |  |            initiating DMA with bus master bit clear. */ | 
					
						
							|  |  |  |         if (val == (VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER)) { | 
					
						
							|  |  |  |             pci_default_write_config(&proxy->pci_dev, PCI_COMMAND, | 
					
						
							|  |  |  |                                      proxy->pci_dev.config[PCI_COMMAND] | | 
					
						
							|  |  |  |                                      PCI_COMMAND_MASTER, 1); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  |     case VIRTIO_MSI_CONFIG_VECTOR: | 
					
						
							|  |  |  |         msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); | 
					
						
							|  |  |  |         /* Make it possible for guest to discover an error took place. */ | 
					
						
							|  |  |  |         if (msix_vector_use(&proxy->pci_dev, val) < 0) | 
					
						
							|  |  |  |             val = VIRTIO_NO_VECTOR; | 
					
						
							|  |  |  |         vdev->config_vector = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_MSI_QUEUE_VECTOR: | 
					
						
							|  |  |  |         msix_vector_unuse(&proxy->pci_dev, | 
					
						
							|  |  |  |                           virtio_queue_vector(vdev, vdev->queue_sel)); | 
					
						
							|  |  |  |         /* Make it possible for guest to discover an error took place. */ | 
					
						
							|  |  |  |         if (msix_vector_use(&proxy->pci_dev, val) < 0) | 
					
						
							|  |  |  |             val = VIRTIO_NO_VECTOR; | 
					
						
							|  |  |  |         virtio_queue_set_vector(vdev, vdev->queue_sel, val); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2010-11-15 20:44:38 +00:00
										 |  |  |         error_report("%s: unexpected address 0x%x value 0x%x", | 
					
						
							|  |  |  |                      __func__, addr, val); | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  | static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |     uint32_t ret = 0xFFFFFFFF; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (addr) { | 
					
						
							|  |  |  |     case VIRTIO_PCI_HOST_FEATURES: | 
					
						
							| 
									
										
										
										
											2015-05-26 16:34:47 +02:00
										 |  |  |         ret = vdev->host_features; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_GUEST_FEATURES: | 
					
						
							| 
									
										
										
										
											2010-01-10 13:52:47 +02:00
										 |  |  |         ret = vdev->guest_features; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_QUEUE_PFN: | 
					
						
							|  |  |  |         ret = virtio_queue_get_addr(vdev, vdev->queue_sel) | 
					
						
							|  |  |  |               >> VIRTIO_PCI_QUEUE_ADDR_SHIFT; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_QUEUE_NUM: | 
					
						
							|  |  |  |         ret = virtio_queue_get_num(vdev, vdev->queue_sel); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_QUEUE_SEL: | 
					
						
							|  |  |  |         ret = vdev->queue_sel; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_STATUS: | 
					
						
							|  |  |  |         ret = vdev->status; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_ISR: | 
					
						
							|  |  |  |         /* reading from the ISR also clears it. */ | 
					
						
							| 
									
										
										
										
											2016-11-18 16:07:01 +01:00
										 |  |  |         ret = atomic_xchg(&vdev->isr, 0); | 
					
						
							| 
									
										
										
										
											2013-10-07 10:36:39 +03:00
										 |  |  |         pci_irq_deassert(&proxy->pci_dev); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  |     case VIRTIO_MSI_CONFIG_VECTOR: | 
					
						
							|  |  |  |         ret = vdev->config_vector; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_MSI_QUEUE_VECTOR: | 
					
						
							|  |  |  |         ret = virtio_queue_vector(vdev, vdev->queue_sel); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  |     default: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  | static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                        unsigned size) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = opaque; | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2015-02-16 22:36:43 +01:00
										 |  |  |     uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev); | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |     uint64_t val = 0; | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  |     if (addr < config) { | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |         return virtio_ioport_read(proxy, addr); | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  |     } | 
					
						
							|  |  |  |     addr -= config; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |     switch (size) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         val = virtio_config_readb(vdev, addr); | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         val = virtio_config_readw(vdev, addr); | 
					
						
							| 
									
										
										
										
											2014-06-24 19:38:54 +02:00
										 |  |  |         if (virtio_is_big_endian(vdev)) { | 
					
						
							| 
									
										
										
										
											2013-01-06 18:30:17 +00:00
										 |  |  |             val = bswap16(val); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 4: | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         val = virtio_config_readl(vdev, addr); | 
					
						
							| 
									
										
										
										
											2014-06-24 19:38:54 +02:00
										 |  |  |         if (virtio_is_big_endian(vdev)) { | 
					
						
							| 
									
										
										
										
											2013-01-06 18:30:17 +00:00
										 |  |  |             val = bswap32(val); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2012-01-10 01:35:11 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |     return val; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  | static void virtio_pci_config_write(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                     uint64_t val, unsigned size) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = opaque; | 
					
						
							| 
									
										
										
										
											2015-02-16 22:36:43 +01:00
										 |  |  |     uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  |     if (addr < config) { | 
					
						
							|  |  |  |         virtio_ioport_write(proxy, addr, val); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     addr -= config; | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * Virtio-PCI is odd. Ioports are LE but config space is target native | 
					
						
							|  |  |  |      * endian. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     switch (size) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         virtio_config_writeb(vdev, addr, val); | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							| 
									
										
										
										
											2014-06-24 19:38:54 +02:00
										 |  |  |         if (virtio_is_big_endian(vdev)) { | 
					
						
							| 
									
										
										
										
											2013-01-06 18:30:17 +00:00
										 |  |  |             val = bswap16(val); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         virtio_config_writew(vdev, addr, val); | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 4: | 
					
						
							| 
									
										
										
										
											2014-06-24 19:38:54 +02:00
										 |  |  |         if (virtio_is_big_endian(vdev)) { | 
					
						
							| 
									
										
										
										
											2013-01-06 18:30:17 +00:00
										 |  |  |             val = bswap32(val); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         virtio_config_writel(vdev, addr, val); | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2012-01-10 01:35:11 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:13 +03:00
										 |  |  | static const MemoryRegionOps virtio_pci_config_ops = { | 
					
						
							| 
									
										
										
										
											2012-10-08 13:02:30 +02:00
										 |  |  |     .read = virtio_pci_config_read, | 
					
						
							|  |  |  |     .write = virtio_pci_config_write, | 
					
						
							|  |  |  |     .impl = { | 
					
						
							|  |  |  |         .min_access_size = 1, | 
					
						
							|  |  |  |         .max_access_size = 4, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2013-01-06 18:30:17 +00:00
										 |  |  |     .endianness = DEVICE_LITTLE_ENDIAN, | 
					
						
							| 
									
										
										
										
											2011-08-08 16:09:13 +03:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  | static MemoryRegion *virtio_address_space_lookup(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                                  hwaddr *off, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  |     VirtIOPCIRegion *reg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (i = 0; i < ARRAY_SIZE(proxy->regs); ++i) { | 
					
						
							|  |  |  |         reg = &proxy->regs[i]; | 
					
						
							|  |  |  |         if (*off >= reg->offset && | 
					
						
							|  |  |  |             *off + len <= reg->offset + reg->size) { | 
					
						
							|  |  |  |             *off -= reg->offset; | 
					
						
							|  |  |  |             return ®->mr; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  | /* Below are generic functions to do memcpy from/to an address space,
 | 
					
						
							|  |  |  |  * without byteswaps, with input validation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * As regular address_space_* APIs all do some kind of byteswap at least for | 
					
						
							|  |  |  |  * some host/target combinations, we are forced to explicitly convert to a | 
					
						
							|  |  |  |  * known-endianness integer value. | 
					
						
							|  |  |  |  * It doesn't really matter which endian format to go through, so the code | 
					
						
							|  |  |  |  * below selects the endian that causes the least amount of work on the given | 
					
						
							|  |  |  |  * host. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note: host pointer must be aligned. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  | void virtio_address_space_write(VirtIOPCIProxy *proxy, hwaddr addr, | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  |                                 const uint8_t *buf, int len) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |     uint64_t val; | 
					
						
							|  |  |  |     MemoryRegion *mr; | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* address_space_* APIs assume an aligned address.
 | 
					
						
							|  |  |  |      * As address is under guest control, handle illegal values. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     addr &= ~(len - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |     mr = virtio_address_space_lookup(proxy, &addr, len); | 
					
						
							|  |  |  |     if (!mr) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  |     /* Make sure caller aligned buf properly */ | 
					
						
							|  |  |  |     assert(!(((uintptr_t)buf) & (len - 1))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (len) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |         val = pci_get_byte(buf); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |         val = cpu_to_le16(pci_get_word(buf)); | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 4: | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |         val = cpu_to_le32(pci_get_long(buf)); | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         /* As length is under guest control, handle illegal values. */ | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |     memory_region_dispatch_write(mr, addr, val, len, MEMTXATTRS_UNSPECIFIED); | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  | virtio_address_space_read(VirtIOPCIProxy *proxy, hwaddr addr, | 
					
						
							|  |  |  |                           uint8_t *buf, int len) | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |     uint64_t val; | 
					
						
							|  |  |  |     MemoryRegion *mr; | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* address_space_* APIs assume an aligned address.
 | 
					
						
							|  |  |  |      * As address is under guest control, handle illegal values. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     addr &= ~(len - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |     mr = virtio_address_space_lookup(proxy, &addr, len); | 
					
						
							|  |  |  |     if (!mr) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  |     /* Make sure caller aligned buf properly */ | 
					
						
							|  |  |  |     assert(!(((uintptr_t)buf) & (len - 1))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |     memory_region_dispatch_read(mr, addr, &val, len, MEMTXATTRS_UNSPECIFIED); | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  |     switch (len) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |         pci_set_byte(buf, val); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |         pci_set_word(buf, le16_to_cpu(val)); | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 4: | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |         pci_set_long(buf, le32_to_cpu(val)); | 
					
						
							| 
									
										
										
										
											2015-07-05 15:08:09 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         /* As length is under guest control, handle illegal values. */ | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-21 19:50:26 +03:00
										 |  |  | static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, | 
					
						
							|  |  |  |                                 uint32_t val, int len) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-08 10:49:41 -04:00
										 |  |  |     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  |     struct virtio_pci_cfg_cap *cfg; | 
					
						
							| 
									
										
										
										
											2009-09-08 10:49:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-27 11:08:20 +03:00
										 |  |  |     pci_default_write_config(pci_dev, address, val, len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (range_covers_byte(address, len, PCI_COMMAND) && | 
					
						
							| 
									
										
										
										
											2014-10-14 19:40:06 +03:00
										 |  |  |         !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { | 
					
						
							| 
									
										
										
										
											2011-07-27 11:08:20 +03:00
										 |  |  |         virtio_pci_stop_ioeventfd(proxy); | 
					
						
							| 
									
										
										
										
											2014-09-29 11:27:32 +03:00
										 |  |  |         virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK); | 
					
						
							| 
									
										
										
										
											2009-09-08 10:49:41 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (proxy->config_cap && | 
					
						
							|  |  |  |         ranges_overlap(address, len, proxy->config_cap + offsetof(struct virtio_pci_cfg_cap, | 
					
						
							|  |  |  |                                                                   pci_cfg_data), | 
					
						
							|  |  |  |                        sizeof cfg->pci_cfg_data)) { | 
					
						
							|  |  |  |         uint32_t off; | 
					
						
							|  |  |  |         uint32_t len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cfg = (void *)(proxy->pci_dev.config + proxy->config_cap); | 
					
						
							|  |  |  |         off = le32_to_cpu(cfg->cap.offset); | 
					
						
							|  |  |  |         len = le32_to_cpu(cfg->cap.length); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 10:32:50 +03:00
										 |  |  |         if (len == 1 || len == 2 || len == 4) { | 
					
						
							|  |  |  |             assert(len <= sizeof cfg->pci_cfg_data); | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |             virtio_address_space_write(proxy, off, cfg->pci_cfg_data, len); | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint32_t virtio_read_config(PCIDevice *pci_dev, | 
					
						
							|  |  |  |                                    uint32_t address, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); | 
					
						
							|  |  |  |     struct virtio_pci_cfg_cap *cfg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (proxy->config_cap && | 
					
						
							|  |  |  |         ranges_overlap(address, len, proxy->config_cap + offsetof(struct virtio_pci_cfg_cap, | 
					
						
							|  |  |  |                                                                   pci_cfg_data), | 
					
						
							|  |  |  |                        sizeof cfg->pci_cfg_data)) { | 
					
						
							|  |  |  |         uint32_t off; | 
					
						
							|  |  |  |         uint32_t len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cfg = (void *)(proxy->pci_dev.config + proxy->config_cap); | 
					
						
							|  |  |  |         off = le32_to_cpu(cfg->cap.offset); | 
					
						
							|  |  |  |         len = le32_to_cpu(cfg->cap.length); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 10:32:50 +03:00
										 |  |  |         if (len == 1 || len == 2 || len == 4) { | 
					
						
							|  |  |  |             assert(len <= sizeof cfg->pci_cfg_data); | 
					
						
							| 
									
										
										
										
											2017-10-09 14:19:41 +11:00
										 |  |  |             virtio_address_space_read(proxy, off, cfg->pci_cfg_data, len); | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return pci_default_read_config(pci_dev, address, len); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                         unsigned int queue_no, | 
					
						
							| 
									
										
										
										
											2016-07-14 13:56:30 +08:00
										 |  |  |                                         unsigned int vector) | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; | 
					
						
							| 
									
										
										
										
											2012-07-05 17:16:30 +02:00
										 |  |  |     int ret; | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (irqfd->users == 0) { | 
					
						
							| 
									
										
										
										
											2016-07-14 13:56:30 +08:00
										 |  |  |         ret = kvm_irqchip_add_msi_route(kvm_state, vector, &proxy->pci_dev); | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |         if (ret < 0) { | 
					
						
							|  |  |  |             return ret; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         irqfd->virq = ret; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     irqfd->users++; | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void kvm_virtio_pci_vq_vector_release(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                              unsigned int vector) | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; | 
					
						
							|  |  |  |     if (--irqfd->users == 0) { | 
					
						
							|  |  |  |         kvm_irqchip_release_virq(kvm_state, irqfd->virq); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  | static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                  unsigned int queue_no, | 
					
						
							|  |  |  |                                  unsigned int vector) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  |     VirtQueue *vq = virtio_get_queue(vdev, queue_no); | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |     EventNotifier *n = virtio_queue_get_guest_notifier(vq); | 
					
						
							| 
									
										
										
										
											2016-06-13 18:57:58 -03:00
										 |  |  |     return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq); | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                       unsigned int queue_no, | 
					
						
							|  |  |  |                                       unsigned int vector) | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  |     VirtQueue *vq = virtio_get_queue(vdev, queue_no); | 
					
						
							| 
									
										
										
										
											2012-07-05 17:16:30 +02:00
										 |  |  |     EventNotifier *n = virtio_queue_get_guest_notifier(vq); | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector]; | 
					
						
							| 
									
										
										
										
											2012-07-05 17:16:30 +02:00
										 |  |  |     int ret; | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 12:15:13 -06:00
										 |  |  |     ret = kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, n, irqfd->virq); | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     assert(ret == 0); | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  | static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PCIDevice *dev = &proxy->pci_dev; | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  |     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |     unsigned int vector; | 
					
						
							|  |  |  |     int ret, queue_no; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (queue_no = 0; queue_no < nvqs; queue_no++) { | 
					
						
							|  |  |  |         if (!virtio_queue_get_num(vdev, queue_no)) { | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         vector = virtio_queue_vector(vdev, queue_no); | 
					
						
							|  |  |  |         if (vector >= msix_nr_vectors_allocated(dev)) { | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-07-14 13:56:30 +08:00
										 |  |  |         ret = kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector); | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |         if (ret < 0) { | 
					
						
							|  |  |  |             goto undo; | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |         /* If guest supports masking, set up irqfd now.
 | 
					
						
							|  |  |  |          * Otherwise, delay until unmasked in the frontend. | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2016-02-18 16:12:23 +02:00
										 |  |  |         if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |             ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector); | 
					
						
							|  |  |  |             if (ret < 0) { | 
					
						
							|  |  |  |                 kvm_virtio_pci_vq_vector_release(proxy, vector); | 
					
						
							|  |  |  |                 goto undo; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     } | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | undo: | 
					
						
							|  |  |  |     while (--queue_no >= 0) { | 
					
						
							|  |  |  |         vector = virtio_queue_vector(vdev, queue_no); | 
					
						
							|  |  |  |         if (vector >= msix_nr_vectors_allocated(dev)) { | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-02-18 16:12:23 +02:00
										 |  |  |         if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { | 
					
						
							| 
									
										
										
										
											2013-01-15 19:42:38 +02:00
										 |  |  |             kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |         kvm_virtio_pci_vq_vector_release(proxy, vector); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  | static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PCIDevice *dev = &proxy->pci_dev; | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |     unsigned int vector; | 
					
						
							|  |  |  |     int queue_no; | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  |     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (queue_no = 0; queue_no < nvqs; queue_no++) { | 
					
						
							|  |  |  |         if (!virtio_queue_get_num(vdev, queue_no)) { | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         vector = virtio_queue_vector(vdev, queue_no); | 
					
						
							|  |  |  |         if (vector >= msix_nr_vectors_allocated(dev)) { | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |         /* If guest supports masking, clean up irqfd now.
 | 
					
						
							|  |  |  |          * Otherwise, it was cleaned when masked in the frontend. | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2016-02-18 16:12:23 +02:00
										 |  |  |         if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { | 
					
						
							| 
									
										
										
										
											2013-01-15 19:42:38 +02:00
										 |  |  |             kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |         kvm_virtio_pci_vq_vector_release(proxy, vector); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  | static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                        unsigned int queue_no, | 
					
						
							|  |  |  |                                        unsigned int vector, | 
					
						
							|  |  |  |                                        MSIMessage msg) | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  |     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); | 
					
						
							|  |  |  |     VirtQueue *vq = virtio_get_queue(vdev, queue_no); | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |     EventNotifier *n = virtio_queue_get_guest_notifier(vq); | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  |     VirtIOIRQFD *irqfd; | 
					
						
							| 
									
										
										
										
											2013-01-14 13:20:12 -06:00
										 |  |  |     int ret = 0; | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  |     if (proxy->vector_irqfd) { | 
					
						
							|  |  |  |         irqfd = &proxy->vector_irqfd[vector]; | 
					
						
							|  |  |  |         if (irqfd->msg.data != msg.data || irqfd->msg.address != msg.address) { | 
					
						
							| 
									
										
										
										
											2015-10-15 16:44:52 +03:00
										 |  |  |             ret = kvm_irqchip_update_msi_route(kvm_state, irqfd->virq, msg, | 
					
						
							|  |  |  |                                                &proxy->pci_dev); | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  |             if (ret < 0) { | 
					
						
							|  |  |  |                 return ret; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-07-14 13:56:33 +08:00
										 |  |  |             kvm_irqchip_commit_routes(kvm_state); | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |     /* If guest supports masking, irqfd is already setup, unmask it.
 | 
					
						
							|  |  |  |      * Otherwise, set it up now. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-18 16:12:23 +02:00
										 |  |  |     if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         k->guest_notifier_mask(vdev, queue_no, false); | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |         /* Test after unmasking to avoid losing events. */ | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  |         if (k->guest_notifier_pending && | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |             k->guest_notifier_pending(vdev, queue_no)) { | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |             event_notifier_set(n); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector); | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  | static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy, | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |                                              unsigned int queue_no, | 
					
						
							|  |  |  |                                              unsigned int vector) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  |     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |     /* If guest supports masking, keep irqfd but mask it.
 | 
					
						
							|  |  |  |      * Otherwise, clean it up now. | 
					
						
							|  |  |  |      */  | 
					
						
							| 
									
										
										
										
											2016-02-18 16:12:23 +02:00
										 |  |  |     if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) { | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         k->guest_notifier_mask(vdev, queue_no, true); | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2013-01-15 19:42:38 +02:00
										 |  |  |         kvm_virtio_pci_irqfd_release(proxy, queue_no, vector); | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  | static int virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector, | 
					
						
							|  |  |  |                                     MSIMessage msg) | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  |     VirtQueue *vq = virtio_vector_first_queue(vdev, vector); | 
					
						
							|  |  |  |     int ret, index, unmasked = 0; | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  |     while (vq) { | 
					
						
							|  |  |  |         index = virtio_get_queue_index(vq); | 
					
						
							|  |  |  |         if (!virtio_queue_get_num(vdev, index)) { | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-27 16:26:07 +08:00
										 |  |  |         if (index < proxy->nvqs_with_notifiers) { | 
					
						
							|  |  |  |             ret = virtio_pci_vq_vector_unmask(proxy, index, vector, msg); | 
					
						
							|  |  |  |             if (ret < 0) { | 
					
						
							|  |  |  |                 goto undo; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             ++unmasked; | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  |         vq = virtio_vector_next_queue(vq); | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | undo: | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  |     vq = virtio_vector_first_queue(vdev, vector); | 
					
						
							| 
									
										
										
										
											2015-05-27 16:26:07 +08:00
										 |  |  |     while (vq && unmasked >= 0) { | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  |         index = virtio_get_queue_index(vq); | 
					
						
							| 
									
										
										
										
											2015-05-27 16:26:07 +08:00
										 |  |  |         if (index < proxy->nvqs_with_notifiers) { | 
					
						
							|  |  |  |             virtio_pci_vq_vector_mask(proxy, index, vector); | 
					
						
							|  |  |  |             --unmasked; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  |         vq = virtio_vector_next_queue(vq); | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     } | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  | static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector) | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  |     VirtQueue *vq = virtio_vector_first_queue(vdev, vector); | 
					
						
							|  |  |  |     int index; | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  |     while (vq) { | 
					
						
							|  |  |  |         index = virtio_get_queue_index(vq); | 
					
						
							|  |  |  |         if (!virtio_queue_get_num(vdev, index)) { | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-27 16:26:07 +08:00
										 |  |  |         if (index < proxy->nvqs_with_notifiers) { | 
					
						
							|  |  |  |             virtio_pci_vq_vector_mask(proxy, index, vector); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:47 +08:00
										 |  |  |         vq = virtio_vector_next_queue(vq); | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  | static void virtio_pci_vector_poll(PCIDevice *dev, | 
					
						
							|  |  |  |                                    unsigned int vector_start, | 
					
						
							|  |  |  |                                    unsigned int vector_end) | 
					
						
							| 
									
										
										
										
											2012-12-18 14:02:46 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  |     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); | 
					
						
							| 
									
										
										
										
											2012-12-18 14:02:46 +02:00
										 |  |  |     int queue_no; | 
					
						
							|  |  |  |     unsigned int vector; | 
					
						
							|  |  |  |     EventNotifier *notifier; | 
					
						
							|  |  |  |     VirtQueue *vq; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 14:28:58 +02:00
										 |  |  |     for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) { | 
					
						
							| 
									
										
										
										
											2012-12-18 14:02:46 +02:00
										 |  |  |         if (!virtio_queue_get_num(vdev, queue_no)) { | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         vector = virtio_queue_vector(vdev, queue_no); | 
					
						
							|  |  |  |         if (vector < vector_start || vector >= vector_end || | 
					
						
							|  |  |  |             !msix_is_masked(dev, vector)) { | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         vq = virtio_get_queue(vdev, queue_no); | 
					
						
							|  |  |  |         notifier = virtio_queue_get_guest_notifier(vq); | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  |         if (k->guest_notifier_pending) { | 
					
						
							|  |  |  |             if (k->guest_notifier_pending(vdev, queue_no)) { | 
					
						
							| 
									
										
										
										
											2012-12-24 17:35:27 +02:00
										 |  |  |                 msix_set_pending(dev, vector); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (event_notifier_test_and_clear(notifier)) { | 
					
						
							| 
									
										
										
										
											2012-12-18 14:02:46 +02:00
										 |  |  |             msix_set_pending(dev, vector); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int virtio_pci_set_guest_notifier(DeviceState *d, int n, bool assign, | 
					
						
							|  |  |  |                                          bool with_irqfd) | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:13 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  |     VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); | 
					
						
							|  |  |  |     VirtQueue *vq = virtio_get_queue(vdev, n); | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:13 +02:00
										 |  |  |     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (assign) { | 
					
						
							|  |  |  |         int r = event_notifier_init(notifier, 0); | 
					
						
							|  |  |  |         if (r < 0) { | 
					
						
							|  |  |  |             return r; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-12-18 14:02:46 +02:00
										 |  |  |         virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:13 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2012-12-18 14:02:46 +02:00
										 |  |  |         virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:13 +02:00
										 |  |  |         event_notifier_cleanup(notifier); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-18 16:12:23 +02:00
										 |  |  |     if (!msix_enabled(&proxy->pci_dev) && | 
					
						
							|  |  |  |         vdev->use_guest_notifier_mask && | 
					
						
							|  |  |  |         vdc->guest_notifier_mask) { | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |         vdc->guest_notifier_mask(vdev, n, !assign); | 
					
						
							| 
									
										
										
										
											2013-05-07 15:49:58 +03:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:13 +02:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  | static bool virtio_pci_query_guest_notifiers(DeviceState *d) | 
					
						
							| 
									
										
										
										
											2011-02-01 22:13:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							| 
									
										
										
										
											2011-02-01 22:13:42 +02:00
										 |  |  |     return msix_enabled(&proxy->pci_dev); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 14:28:58 +02:00
										 |  |  | static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) | 
					
						
							| 
									
										
										
										
											2010-10-06 15:20:17 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  |     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); | 
					
						
							| 
									
										
										
										
											2010-10-06 15:20:17 +02:00
										 |  |  |     int r, n; | 
					
						
							| 
									
										
										
										
											2012-12-18 14:02:46 +02:00
										 |  |  |     bool with_irqfd = msix_enabled(&proxy->pci_dev) && | 
					
						
							|  |  |  |         kvm_msi_via_irqfd_enabled(); | 
					
						
							| 
									
										
										
										
											2010-10-06 15:20:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 14:15:31 +08:00
										 |  |  |     nvqs = MIN(nvqs, VIRTIO_QUEUE_MAX); | 
					
						
							| 
									
										
										
										
											2012-12-20 14:28:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* When deassigning, pass a consistent nvqs value
 | 
					
						
							|  |  |  |      * to avoid leaking notifiers. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     assert(assign || nvqs == proxy->nvqs_with_notifiers); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     proxy->nvqs_with_notifiers = nvqs; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     /* Must unset vector notifier while guest notifier is still assigned */ | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  |     if ((proxy->vector_irqfd || k->guest_notifier_mask) && !assign) { | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |         msix_unset_vector_notifiers(&proxy->pci_dev); | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  |         if (proxy->vector_irqfd) { | 
					
						
							|  |  |  |             kvm_virtio_pci_vector_release(proxy, nvqs); | 
					
						
							|  |  |  |             g_free(proxy->vector_irqfd); | 
					
						
							|  |  |  |             proxy->vector_irqfd = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 14:28:58 +02:00
										 |  |  |     for (n = 0; n < nvqs; n++) { | 
					
						
							| 
									
										
										
										
											2010-10-06 15:20:17 +02:00
										 |  |  |         if (!virtio_queue_get_num(vdev, n)) { | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 11:03:45 +03:00
										 |  |  |         r = virtio_pci_set_guest_notifier(d, n, assign, with_irqfd); | 
					
						
							| 
									
										
										
										
											2010-10-06 15:20:17 +02:00
										 |  |  |         if (r < 0) { | 
					
						
							|  |  |  |             goto assign_error; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     /* Must set vector notifier after guest notifier has been assigned */ | 
					
						
							| 
									
										
										
										
											2013-04-24 10:21:20 +02:00
										 |  |  |     if ((with_irqfd || k->guest_notifier_mask) && assign) { | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  |         if (with_irqfd) { | 
					
						
							|  |  |  |             proxy->vector_irqfd = | 
					
						
							|  |  |  |                 g_malloc0(sizeof(*proxy->vector_irqfd) * | 
					
						
							|  |  |  |                           msix_nr_vectors_allocated(&proxy->pci_dev)); | 
					
						
							|  |  |  |             r = kvm_virtio_pci_vector_use(proxy, nvqs); | 
					
						
							|  |  |  |             if (r < 0) { | 
					
						
							|  |  |  |                 goto assign_error; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |         r = msix_set_vector_notifiers(&proxy->pci_dev, | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  |                                       virtio_pci_vector_unmask, | 
					
						
							|  |  |  |                                       virtio_pci_vector_mask, | 
					
						
							|  |  |  |                                       virtio_pci_vector_poll); | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |         if (r < 0) { | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  |             goto notifiers_error; | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 15:20:17 +02:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  | notifiers_error: | 
					
						
							| 
									
										
										
										
											2013-03-13 21:37:08 +02:00
										 |  |  |     if (with_irqfd) { | 
					
						
							|  |  |  |         assert(assign); | 
					
						
							|  |  |  |         kvm_virtio_pci_vector_release(proxy, nvqs); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-12-21 00:27:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 15:20:17 +02:00
										 |  |  | assign_error: | 
					
						
							|  |  |  |     /* We get here on assignment failure. Recover by undoing for VQs 0 .. n. */ | 
					
						
							| 
									
										
										
										
											2012-05-17 10:32:39 -03:00
										 |  |  |     assert(assign); | 
					
						
							| 
									
										
										
										
											2010-10-06 15:20:17 +02:00
										 |  |  |     while (--n >= 0) { | 
					
						
							| 
									
										
										
										
											2012-12-18 14:02:46 +02:00
										 |  |  |         virtio_pci_set_guest_notifier(d, n, !assign, with_irqfd); | 
					
						
							| 
									
										
										
										
											2010-10-06 15:20:17 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     return r; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 23:12:30 +08:00
										 |  |  | static int virtio_pci_set_host_notifier_mr(DeviceState *d, int n, | 
					
						
							|  |  |  |                                            MemoryRegion *mr, bool assign) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							|  |  |  |     int offset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (n >= VIRTIO_QUEUE_MAX || !virtio_pci_modern(proxy) || | 
					
						
							|  |  |  |         virtio_pci_queue_mem_mult(proxy) != memory_region_size(mr)) { | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (assign) { | 
					
						
							|  |  |  |         offset = virtio_pci_queue_mem_mult(proxy) * n; | 
					
						
							|  |  |  |         memory_region_add_subregion_overlap(&proxy->notify.mr, offset, mr, 1); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         memory_region_del_subregion(&proxy->notify.mr, mr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  | static void virtio_pci_vmstate_change(DeviceState *d, bool running) | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-17 13:01:07 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); | 
					
						
							| 
									
										
										
										
											2013-09-20 13:36:40 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (running) { | 
					
						
							| 
									
										
										
										
											2014-10-14 19:40:06 +03:00
										 |  |  |         /* Old QEMU versions did not set bus master enable on status write.
 | 
					
						
							|  |  |  |          * Detect DRIVER set and enable it. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         if ((proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION) && | 
					
						
							|  |  |  |             (vdev->status & VIRTIO_CONFIG_S_DRIVER) && | 
					
						
							| 
									
										
										
										
											2014-09-29 11:27:32 +03:00
										 |  |  |             !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { | 
					
						
							| 
									
										
										
										
											2014-10-14 19:40:06 +03:00
										 |  |  |             pci_default_write_config(&proxy->pci_dev, PCI_COMMAND, | 
					
						
							|  |  |  |                                      proxy->pci_dev.config[PCI_COMMAND] | | 
					
						
							|  |  |  |                                      PCI_COMMAND_MASTER, 1); | 
					
						
							| 
									
										
										
										
											2011-03-19 19:28:19 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  |         virtio_pci_start_ioeventfd(proxy); | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:13 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-12-17 12:01:50 +00:00
										 |  |  |         virtio_pci_stop_ioeventfd(proxy); | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:13 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | #ifdef CONFIG_VIRTFS
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  |     V9fsPCIState *dev = VIRTIO_9P_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  | static Property virtio_9p_pci_properties[] = { | 
					
						
							|  |  |  |     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), | 
					
						
							|  |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  | static void virtio_9p_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     k->realize = virtio_9p_pci_realize; | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_9P; | 
					
						
							|  |  |  |     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; | 
					
						
							|  |  |  |     pcidev_k->class_id = 0x2; | 
					
						
							| 
									
										
										
										
											2013-07-29 17:17:45 +03:00
										 |  |  |     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  |     dc->props = virtio_9p_pci_properties; | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  | static void virtio_9p_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     V9fsPCIState *dev = VIRTIO_9P_PCI(obj); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:10:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_9P); | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_9p_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name              = TYPE_VIRTIO_9P_PCI, | 
					
						
							|  |  |  |     .generic_name           = "virtio-9p-pci", | 
					
						
							|  |  |  |     .transitional_name      = "virtio-9p-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name  = "virtio-9p-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  |     .instance_size = sizeof(V9fsPCIState), | 
					
						
							|  |  |  |     .instance_init = virtio_9p_pci_instance_init, | 
					
						
							|  |  |  |     .class_init    = virtio_9p_pci_class_init, | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-04-23 11:08:41 +02:00
										 |  |  | #endif /* CONFIG_VIRTFS */
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * virtio-pci: This is the PCIDevice which has a virtio-pci-bus. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:46 +08:00
										 |  |  | static int virtio_pci_query_nvectors(DeviceState *d) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(d); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return proxy->nvectors; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 18:09:10 +08:00
										 |  |  | static AddressSpace *virtio_pci_get_dma_as(DeviceState *d) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(d); | 
					
						
							|  |  |  |     PCIDevice *dev = &proxy->pci_dev; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 11:29:57 +08:00
										 |  |  |     return pci_get_address_space(dev); | 
					
						
							| 
									
										
										
										
											2016-12-30 18:09:10 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  | static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |                                    struct virtio_pci_cap *cap) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PCIDevice *dev = &proxy->pci_dev; | 
					
						
							|  |  |  |     int offset; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 14:16:50 +08:00
										 |  |  |     offset = pci_add_capability(dev, PCI_CAP_ID_VNDR, 0, | 
					
						
							|  |  |  |                                 cap->cap_len, &error_abort); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert(cap->cap_len >= sizeof *cap); | 
					
						
							|  |  |  |     memcpy(dev->config + offset + PCI_CAP_FLAGS, &cap->cap_len, | 
					
						
							|  |  |  |            cap->cap_len - PCI_CAP_FLAGS); | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return offset; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                        unsigned size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = opaque; | 
					
						
							|  |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  |     uint32_t val = 0; | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (addr) { | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_DFSELECT: | 
					
						
							|  |  |  |         val = proxy->dfselect; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_DF: | 
					
						
							|  |  |  |         if (proxy->dfselect <= 1) { | 
					
						
							| 
									
										
										
										
											2016-11-04 12:04:23 +02:00
										 |  |  |             VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             val = (vdev->host_features & ~vdc->legacy_features) >> | 
					
						
							| 
									
										
										
										
											2015-07-22 13:09:25 +03:00
										 |  |  |                 (32 * proxy->dfselect); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_GFSELECT: | 
					
						
							|  |  |  |         val = proxy->gfselect; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_GF: | 
					
						
							| 
									
										
										
										
											2015-06-23 09:53:04 +08:00
										 |  |  |         if (proxy->gfselect < ARRAY_SIZE(proxy->guest_features)) { | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |             val = proxy->guest_features[proxy->gfselect]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_MSIX: | 
					
						
							|  |  |  |         val = vdev->config_vector; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_NUMQ: | 
					
						
							|  |  |  |         for (i = 0; i < VIRTIO_QUEUE_MAX; ++i) { | 
					
						
							|  |  |  |             if (virtio_queue_get_num(vdev, i)) { | 
					
						
							|  |  |  |                 val = i + 1; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_STATUS: | 
					
						
							|  |  |  |         val = vdev->status; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_CFGGENERATION: | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:23 +02:00
										 |  |  |         val = vdev->generation; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_SELECT: | 
					
						
							|  |  |  |         val = vdev->queue_sel; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_SIZE: | 
					
						
							|  |  |  |         val = virtio_queue_get_num(vdev, vdev->queue_sel); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_MSIX: | 
					
						
							|  |  |  |         val = virtio_queue_vector(vdev, vdev->queue_sel); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_ENABLE: | 
					
						
							|  |  |  |         val = proxy->vqs[vdev->queue_sel].enabled; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_NOFF: | 
					
						
							|  |  |  |         /* Simply map queues in order */ | 
					
						
							|  |  |  |         val = vdev->queue_sel; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_DESCLO: | 
					
						
							|  |  |  |         val = proxy->vqs[vdev->queue_sel].desc[0]; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_DESCHI: | 
					
						
							|  |  |  |         val = proxy->vqs[vdev->queue_sel].desc[1]; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_AVAILLO: | 
					
						
							|  |  |  |         val = proxy->vqs[vdev->queue_sel].avail[0]; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_AVAILHI: | 
					
						
							|  |  |  |         val = proxy->vqs[vdev->queue_sel].avail[1]; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_USEDLO: | 
					
						
							|  |  |  |         val = proxy->vqs[vdev->queue_sel].used[0]; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_USEDHI: | 
					
						
							|  |  |  |         val = proxy->vqs[vdev->queue_sel].used[1]; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         val = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_common_write(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                     uint64_t val, unsigned size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = opaque; | 
					
						
							|  |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (addr) { | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_DFSELECT: | 
					
						
							|  |  |  |         proxy->dfselect = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_GFSELECT: | 
					
						
							|  |  |  |         proxy->gfselect = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_GF: | 
					
						
							| 
									
										
										
										
											2015-06-23 09:53:04 +08:00
										 |  |  |         if (proxy->gfselect < ARRAY_SIZE(proxy->guest_features)) { | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |             proxy->guest_features[proxy->gfselect] = val; | 
					
						
							|  |  |  |             virtio_set_features(vdev, | 
					
						
							|  |  |  |                                 (((uint64_t)proxy->guest_features[1]) << 32) | | 
					
						
							|  |  |  |                                 proxy->guest_features[0]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_MSIX: | 
					
						
							|  |  |  |         msix_vector_unuse(&proxy->pci_dev, vdev->config_vector); | 
					
						
							|  |  |  |         /* Make it possible for guest to discover an error took place. */ | 
					
						
							|  |  |  |         if (msix_vector_use(&proxy->pci_dev, val) < 0) { | 
					
						
							|  |  |  |             val = VIRTIO_NO_VECTOR; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         vdev->config_vector = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_STATUS: | 
					
						
							|  |  |  |         if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) { | 
					
						
							|  |  |  |             virtio_pci_stop_ioeventfd(proxy); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtio_set_status(vdev, val & 0xFF); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (val & VIRTIO_CONFIG_S_DRIVER_OK) { | 
					
						
							|  |  |  |             virtio_pci_start_ioeventfd(proxy); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (vdev->status == 0) { | 
					
						
							| 
									
										
										
										
											2016-01-28 16:08:07 +01:00
										 |  |  |             virtio_pci_reset(DEVICE(proxy)); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_SELECT: | 
					
						
							|  |  |  |         if (val < VIRTIO_QUEUE_MAX) { | 
					
						
							|  |  |  |             vdev->queue_sel = val; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_SIZE: | 
					
						
							|  |  |  |         proxy->vqs[vdev->queue_sel].num = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_MSIX: | 
					
						
							|  |  |  |         msix_vector_unuse(&proxy->pci_dev, | 
					
						
							|  |  |  |                           virtio_queue_vector(vdev, vdev->queue_sel)); | 
					
						
							|  |  |  |         /* Make it possible for guest to discover an error took place. */ | 
					
						
							|  |  |  |         if (msix_vector_use(&proxy->pci_dev, val) < 0) { | 
					
						
							|  |  |  |             val = VIRTIO_NO_VECTOR; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         virtio_queue_set_vector(vdev, vdev->queue_sel, val); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_ENABLE: | 
					
						
							|  |  |  |         virtio_queue_set_num(vdev, vdev->queue_sel, | 
					
						
							|  |  |  |                              proxy->vqs[vdev->queue_sel].num); | 
					
						
							|  |  |  |         virtio_queue_set_rings(vdev, vdev->queue_sel, | 
					
						
							|  |  |  |                        ((uint64_t)proxy->vqs[vdev->queue_sel].desc[1]) << 32 | | 
					
						
							|  |  |  |                        proxy->vqs[vdev->queue_sel].desc[0], | 
					
						
							|  |  |  |                        ((uint64_t)proxy->vqs[vdev->queue_sel].avail[1]) << 32 | | 
					
						
							|  |  |  |                        proxy->vqs[vdev->queue_sel].avail[0], | 
					
						
							|  |  |  |                        ((uint64_t)proxy->vqs[vdev->queue_sel].used[1]) << 32 | | 
					
						
							|  |  |  |                        proxy->vqs[vdev->queue_sel].used[0]); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:49 +08:00
										 |  |  |         proxy->vqs[vdev->queue_sel].enabled = 1; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_DESCLO: | 
					
						
							|  |  |  |         proxy->vqs[vdev->queue_sel].desc[0] = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_DESCHI: | 
					
						
							|  |  |  |         proxy->vqs[vdev->queue_sel].desc[1] = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_AVAILLO: | 
					
						
							|  |  |  |         proxy->vqs[vdev->queue_sel].avail[0] = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_AVAILHI: | 
					
						
							|  |  |  |         proxy->vqs[vdev->queue_sel].avail[1] = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_USEDLO: | 
					
						
							|  |  |  |         proxy->vqs[vdev->queue_sel].used[0] = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case VIRTIO_PCI_COMMON_Q_USEDHI: | 
					
						
							|  |  |  |         proxy->vqs[vdev->queue_sel].used[1] = val; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint64_t virtio_pci_notify_read(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                        unsigned size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_notify_write(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                     uint64_t val, unsigned size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIODevice *vdev = opaque; | 
					
						
							| 
									
										
										
										
											2016-09-07 18:02:25 +03:00
										 |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(DEVICE(vdev)->parent_bus->parent); | 
					
						
							|  |  |  |     unsigned queue = addr / virtio_pci_queue_mem_mult(proxy); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (queue < VIRTIO_QUEUE_MAX) { | 
					
						
							|  |  |  |         virtio_queue_notify(vdev, queue); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  | static void virtio_pci_notify_write_pio(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                         uint64_t val, unsigned size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIODevice *vdev = opaque; | 
					
						
							|  |  |  |     unsigned queue = val; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (queue < VIRTIO_QUEUE_MAX) { | 
					
						
							|  |  |  |         virtio_queue_notify(vdev, queue); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  | static uint64_t virtio_pci_isr_read(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                     unsigned size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = opaque; | 
					
						
							|  |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2016-11-18 16:07:01 +01:00
										 |  |  |     uint64_t val = atomic_xchg(&vdev->isr, 0); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |     pci_irq_deassert(&proxy->pci_dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_isr_write(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                  uint64_t val, unsigned size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static uint64_t virtio_pci_device_read(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                        unsigned size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIODevice *vdev = opaque; | 
					
						
							|  |  |  |     uint64_t val = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (size) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:25 +02:00
										 |  |  |         val = virtio_config_modern_readb(vdev, addr); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:25 +02:00
										 |  |  |         val = virtio_config_modern_readw(vdev, addr); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 4: | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:25 +02:00
										 |  |  |         val = virtio_config_modern_readl(vdev, addr); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_device_write(void *opaque, hwaddr addr, | 
					
						
							|  |  |  |                                     uint64_t val, unsigned size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIODevice *vdev = opaque; | 
					
						
							|  |  |  |     switch (size) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:25 +02:00
										 |  |  |         virtio_config_modern_writeb(vdev, addr, val); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:25 +02:00
										 |  |  |         virtio_config_modern_writew(vdev, addr, val); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case 4: | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:25 +02:00
										 |  |  |         virtio_config_modern_writel(vdev, addr, val); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:34 +02:00
										 |  |  | static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     static const MemoryRegionOps common_ops = { | 
					
						
							|  |  |  |         .read = virtio_pci_common_read, | 
					
						
							|  |  |  |         .write = virtio_pci_common_write, | 
					
						
							|  |  |  |         .impl = { | 
					
						
							|  |  |  |             .min_access_size = 1, | 
					
						
							|  |  |  |             .max_access_size = 4, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         .endianness = DEVICE_LITTLE_ENDIAN, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     static const MemoryRegionOps isr_ops = { | 
					
						
							|  |  |  |         .read = virtio_pci_isr_read, | 
					
						
							|  |  |  |         .write = virtio_pci_isr_write, | 
					
						
							|  |  |  |         .impl = { | 
					
						
							|  |  |  |             .min_access_size = 1, | 
					
						
							|  |  |  |             .max_access_size = 4, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         .endianness = DEVICE_LITTLE_ENDIAN, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     static const MemoryRegionOps device_ops = { | 
					
						
							|  |  |  |         .read = virtio_pci_device_read, | 
					
						
							|  |  |  |         .write = virtio_pci_device_write, | 
					
						
							|  |  |  |         .impl = { | 
					
						
							|  |  |  |             .min_access_size = 1, | 
					
						
							|  |  |  |             .max_access_size = 4, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         .endianness = DEVICE_LITTLE_ENDIAN, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     static const MemoryRegionOps notify_ops = { | 
					
						
							|  |  |  |         .read = virtio_pci_notify_read, | 
					
						
							|  |  |  |         .write = virtio_pci_notify_write, | 
					
						
							|  |  |  |         .impl = { | 
					
						
							|  |  |  |             .min_access_size = 1, | 
					
						
							|  |  |  |             .max_access_size = 4, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         .endianness = DEVICE_LITTLE_ENDIAN, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |     static const MemoryRegionOps notify_pio_ops = { | 
					
						
							|  |  |  |         .read = virtio_pci_notify_read, | 
					
						
							|  |  |  |         .write = virtio_pci_notify_write_pio, | 
					
						
							|  |  |  |         .impl = { | 
					
						
							|  |  |  |             .min_access_size = 1, | 
					
						
							|  |  |  |             .max_access_size = 4, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         .endianness = DEVICE_LITTLE_ENDIAN, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     memory_region_init_io(&proxy->common.mr, OBJECT(proxy), | 
					
						
							|  |  |  |                           &common_ops, | 
					
						
							|  |  |  |                           proxy, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |                           "virtio-pci-common", | 
					
						
							|  |  |  |                           proxy->common.size); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:34 +02:00
										 |  |  |     memory_region_init_io(&proxy->isr.mr, OBJECT(proxy), | 
					
						
							|  |  |  |                           &isr_ops, | 
					
						
							|  |  |  |                           proxy, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |                           "virtio-pci-isr", | 
					
						
							|  |  |  |                           proxy->isr.size); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:34 +02:00
										 |  |  |     memory_region_init_io(&proxy->device.mr, OBJECT(proxy), | 
					
						
							|  |  |  |                           &device_ops, | 
					
						
							|  |  |  |                           virtio_bus_get_device(&proxy->bus), | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |                           "virtio-pci-device", | 
					
						
							|  |  |  |                           proxy->device.size); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:34 +02:00
										 |  |  |     memory_region_init_io(&proxy->notify.mr, OBJECT(proxy), | 
					
						
							|  |  |  |                           ¬ify_ops, | 
					
						
							|  |  |  |                           virtio_bus_get_device(&proxy->bus), | 
					
						
							|  |  |  |                           "virtio-pci-notify", | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |                           proxy->notify.size); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     memory_region_init_io(&proxy->notify_pio.mr, OBJECT(proxy), | 
					
						
							|  |  |  |                           ¬ify_pio_ops, | 
					
						
							|  |  |  |                           virtio_bus_get_device(&proxy->bus), | 
					
						
							|  |  |  |                           "virtio-pci-notify-pio", | 
					
						
							| 
									
										
										
										
											2016-09-06 13:36:51 +03:00
										 |  |  |                           proxy->notify_pio.size); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:35 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:36 +02:00
										 |  |  |                                          VirtIOPCIRegion *region, | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |                                          struct virtio_pci_cap *cap, | 
					
						
							|  |  |  |                                          MemoryRegion *mr, | 
					
						
							|  |  |  |                                          uint8_t bar) | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:35 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |     memory_region_add_subregion(mr, region->offset, ®ion->mr); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:37 +02:00
										 |  |  |     cap->cfg_type = region->type; | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |     cap->bar = bar; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:36 +02:00
										 |  |  |     cap->offset = cpu_to_le32(region->offset); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |     cap->length = cpu_to_le32(region->size); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:36 +02:00
										 |  |  |     virtio_pci_add_mem_cap(proxy, cap); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_modern_mem_region_map(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                              VirtIOPCIRegion *region, | 
					
						
							|  |  |  |                                              struct virtio_pci_cap *cap) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     virtio_pci_modern_region_map(proxy, region, cap, | 
					
						
							| 
									
										
										
										
											2016-09-29 12:04:40 +08:00
										 |  |  |                                  &proxy->modern_bar, proxy->modern_mem_bar_idx); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:34 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  | static void virtio_pci_modern_io_region_map(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                             VirtIOPCIRegion *region, | 
					
						
							|  |  |  |                                             struct virtio_pci_cap *cap) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     virtio_pci_modern_region_map(proxy, region, cap, | 
					
						
							| 
									
										
										
										
											2016-09-29 12:04:40 +08:00
										 |  |  |                                  &proxy->io_bar, proxy->modern_io_bar_idx); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_modern_mem_region_unmap(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                                VirtIOPCIRegion *region) | 
					
						
							| 
									
										
										
										
											2015-07-27 11:06:17 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     memory_region_del_subregion(&proxy->modern_bar, | 
					
						
							|  |  |  |                                 ®ion->mr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  | static void virtio_pci_modern_io_region_unmap(VirtIOPCIProxy *proxy, | 
					
						
							|  |  |  |                                               VirtIOPCIRegion *region) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     memory_region_del_subregion(&proxy->io_bar, | 
					
						
							|  |  |  |                                 ®ion->mr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 15:30:30 +02:00
										 |  |  | static void virtio_pci_pre_plugged(DeviceState *d, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(d); | 
					
						
							|  |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (virtio_pci_modern(proxy)) { | 
					
						
							|  |  |  |         virtio_add_feature(&vdev->host_features, VIRTIO_F_VERSION_1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtio_add_feature(&vdev->host_features, VIRTIO_F_BAD_FEATURE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | /* This is called by virtio-bus just after the device is plugged. */ | 
					
						
							| 
									
										
										
										
											2015-05-29 14:15:25 +08:00
										 |  |  | static void virtio_pci_device_plugged(DeviceState *d, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(d); | 
					
						
							|  |  |  |     VirtioBusState *bus = &proxy->bus; | 
					
						
							| 
									
										
										
										
											2016-07-20 18:28:21 +03:00
										 |  |  |     bool legacy = virtio_pci_legacy(proxy); | 
					
						
							| 
									
										
										
										
											2016-09-13 15:30:30 +02:00
										 |  |  |     bool modern; | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |     bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  |     uint8_t *config; | 
					
						
							|  |  |  |     uint32_t size; | 
					
						
							| 
									
										
										
										
											2015-05-26 16:34:47 +02:00
										 |  |  |     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 15:30:30 +02:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * Virtio capabilities present without | 
					
						
							|  |  |  |      * VIRTIO_F_VERSION_1 confuses guests | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-12-14 17:30:35 +01:00
										 |  |  |     if (!proxy->ignore_backend_features && | 
					
						
							|  |  |  |             !virtio_has_feature(vdev->host_features, VIRTIO_F_VERSION_1)) { | 
					
						
							| 
									
										
										
										
											2016-09-13 15:30:30 +02:00
										 |  |  |         virtio_pci_disable_modern(proxy); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!legacy) { | 
					
						
							|  |  |  |             error_setg(errp, "Device doesn't support modern mode, and legacy" | 
					
						
							|  |  |  |                              " mode is disabled"); | 
					
						
							|  |  |  |             error_append_hint(errp, "Set disable-legacy to off\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     modern = virtio_pci_modern(proxy); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  |     config = proxy->pci_dev.config; | 
					
						
							|  |  |  |     if (proxy->class_code) { | 
					
						
							|  |  |  |         pci_config_set_class(config, proxy->class_code); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (legacy) { | 
					
						
							| 
									
										
										
										
											2016-12-30 18:09:10 +08:00
										 |  |  |         if (virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) { | 
					
						
							|  |  |  |             error_setg(errp, "VIRTIO_F_IOMMU_PLATFORM was supported by" | 
					
						
							| 
									
										
										
										
											2018-02-12 15:18:08 +01:00
										 |  |  |                        " neither legacy nor transitional device"); | 
					
						
							| 
									
										
										
										
											2016-12-30 18:09:10 +08:00
										 |  |  |             return ; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-13 09:45:58 +01:00
										 |  |  |         /*
 | 
					
						
							|  |  |  |          * Legacy and transitional devices use specific subsystem IDs. | 
					
						
							|  |  |  |          * Note that the subsystem vendor ID (config + PCI_SUBSYSTEM_VENDOR_ID) | 
					
						
							|  |  |  |          * is set to PCI_SUBVENDOR_ID_REDHAT_QUMRANET by default. | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:26 +02:00
										 |  |  |         pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_bus_get_vdev_id(bus)); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         /* pure virtio-1.0 */ | 
					
						
							|  |  |  |         pci_set_word(config + PCI_VENDOR_ID, | 
					
						
							|  |  |  |                      PCI_VENDOR_ID_REDHAT_QUMRANET); | 
					
						
							|  |  |  |         pci_set_word(config + PCI_DEVICE_ID, | 
					
						
							|  |  |  |                      0x1040 + virtio_bus_get_vdev_id(bus)); | 
					
						
							|  |  |  |         pci_config_set_revision(config, 1); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  |     config[PCI_INTERRUPT_PIN] = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:26 +02:00
										 |  |  |     if (modern) { | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:38 +02:00
										 |  |  |         struct virtio_pci_cap cap = { | 
					
						
							|  |  |  |             .cap_len = sizeof cap, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         }; | 
					
						
							|  |  |  |         struct virtio_pci_notify_cap notify = { | 
					
						
							|  |  |  |             .cap.cap_len = sizeof notify, | 
					
						
							|  |  |  |             .notify_off_multiplier = | 
					
						
							| 
									
										
										
										
											2016-09-07 18:02:25 +03:00
										 |  |  |                 cpu_to_le32(virtio_pci_queue_mem_mult(proxy)), | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  |         struct virtio_pci_cfg_cap cfg = { | 
					
						
							|  |  |  |             .cap.cap_len = sizeof cfg, | 
					
						
							|  |  |  |             .cap.cfg_type = VIRTIO_PCI_CAP_PCI_CFG, | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |         struct virtio_pci_notify_cap notify_pio = { | 
					
						
							|  |  |  |             .cap.cap_len = sizeof notify, | 
					
						
							|  |  |  |             .notify_off_multiplier = cpu_to_le32(0x0), | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |         struct virtio_pci_cfg_cap *cfg_mask; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:34 +02:00
										 |  |  |         virtio_pci_modern_regions_init(proxy); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         virtio_pci_modern_mem_region_map(proxy, &proxy->common, &cap); | 
					
						
							|  |  |  |         virtio_pci_modern_mem_region_map(proxy, &proxy->isr, &cap); | 
					
						
							|  |  |  |         virtio_pci_modern_mem_region_map(proxy, &proxy->device, &cap); | 
					
						
							|  |  |  |         virtio_pci_modern_mem_region_map(proxy, &proxy->notify, ¬ify.cap); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (modern_pio) { | 
					
						
							|  |  |  |             memory_region_init(&proxy->io_bar, OBJECT(proxy), | 
					
						
							|  |  |  |                                "virtio-pci-io", 0x4); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-29 12:04:40 +08:00
										 |  |  |             pci_register_bar(&proxy->pci_dev, proxy->modern_io_bar_idx, | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |                              PCI_BASE_ADDRESS_SPACE_IO, &proxy->io_bar); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             virtio_pci_modern_io_region_map(proxy, &proxy->notify_pio, | 
					
						
							|  |  |  |                                             ¬ify_pio.cap); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-29 12:04:40 +08:00
										 |  |  |         pci_register_bar(&proxy->pci_dev, proxy->modern_mem_bar_idx, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:29 +02:00
										 |  |  |                          PCI_BASE_ADDRESS_SPACE_MEMORY | | 
					
						
							|  |  |  |                          PCI_BASE_ADDRESS_MEM_PREFETCH | | 
					
						
							|  |  |  |                          PCI_BASE_ADDRESS_MEM_TYPE_64, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |                          &proxy->modern_bar); | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         proxy->config_cap = virtio_pci_add_mem_cap(proxy, &cfg.cap); | 
					
						
							|  |  |  |         cfg_mask = (void *)(proxy->pci_dev.wmask + proxy->config_cap); | 
					
						
							|  |  |  |         pci_set_byte(&cfg_mask->cap.bar, ~0x0); | 
					
						
							|  |  |  |         pci_set_long((uint8_t *)&cfg_mask->cap.offset, ~0x0); | 
					
						
							|  |  |  |         pci_set_long((uint8_t *)&cfg_mask->cap.length, ~0x0); | 
					
						
							|  |  |  |         pci_set_long(cfg_mask->pci_cfg_data, ~0x0); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 13:29:51 -07:00
										 |  |  |     if (proxy->nvectors) { | 
					
						
							|  |  |  |         int err = msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, | 
					
						
							| 
									
										
										
										
											2017-01-17 14:18:48 +08:00
										 |  |  |                                           proxy->msix_bar_idx, NULL); | 
					
						
							| 
									
										
										
										
											2015-05-19 13:29:51 -07:00
										 |  |  |         if (err) { | 
					
						
							| 
									
										
										
										
											2017-01-17 14:18:48 +08:00
										 |  |  |             /* Notice when a system that supports MSIx can't initialize it */ | 
					
						
							| 
									
										
										
										
											2015-05-19 13:29:51 -07:00
										 |  |  |             if (err != -ENOTSUP) { | 
					
						
							| 
									
										
										
										
											2018-10-17 10:26:28 +02:00
										 |  |  |                 warn_report("unable to init msix vectors to %" PRIu32, | 
					
						
							|  |  |  |                             proxy->nvectors); | 
					
						
							| 
									
										
										
										
											2015-05-19 13:29:51 -07:00
										 |  |  |             } | 
					
						
							|  |  |  |             proxy->nvectors = 0; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     proxy->pci_dev.config_write = virtio_write_config; | 
					
						
							| 
									
										
										
										
											2015-07-02 14:59:49 +02:00
										 |  |  |     proxy->pci_dev.config_read = virtio_read_config; | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:26 +02:00
										 |  |  |     if (legacy) { | 
					
						
							|  |  |  |         size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) | 
					
						
							|  |  |  |             + virtio_bus_get_vdev_config_len(bus); | 
					
						
							| 
									
										
										
										
											2015-07-24 13:33:08 +01:00
										 |  |  |         size = pow2ceil(size); | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:26 +02:00
										 |  |  |         memory_region_init_io(&proxy->bar, OBJECT(proxy), | 
					
						
							|  |  |  |                               &virtio_pci_config_ops, | 
					
						
							|  |  |  |                               proxy, "virtio-pci", size); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-29 12:04:40 +08:00
										 |  |  |         pci_register_bar(&proxy->pci_dev, proxy->legacy_io_bar_idx, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:28 +02:00
										 |  |  |                          PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:26 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-20 14:10:26 +02:00
										 |  |  | static void virtio_pci_device_unplugged(DeviceState *d) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(d); | 
					
						
							| 
									
										
										
										
											2016-07-20 18:28:21 +03:00
										 |  |  |     bool modern = virtio_pci_modern(proxy); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |     bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; | 
					
						
							| 
									
										
										
										
											2013-09-20 14:10:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_pci_stop_ioeventfd(proxy); | 
					
						
							| 
									
										
										
										
											2015-07-27 11:06:17 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (modern) { | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |         virtio_pci_modern_mem_region_unmap(proxy, &proxy->common); | 
					
						
							|  |  |  |         virtio_pci_modern_mem_region_unmap(proxy, &proxy->isr); | 
					
						
							|  |  |  |         virtio_pci_modern_mem_region_unmap(proxy, &proxy->device); | 
					
						
							|  |  |  |         virtio_pci_modern_mem_region_unmap(proxy, &proxy->notify); | 
					
						
							|  |  |  |         if (modern_pio) { | 
					
						
							|  |  |  |             virtio_pci_modern_io_region_unmap(proxy, &proxy->notify_pio); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-07-27 11:06:17 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-09-20 14:10:26 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev); | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  |     VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev); | 
					
						
							| 
									
										
										
										
											2017-11-29 19:46:27 +11:00
										 |  |  |     bool pcie_port = pci_bus_is_express(pci_get_bus(pci_dev)) && | 
					
						
							|  |  |  |                      !pci_bus_is_root(pci_get_bus(pci_dev)); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-28 19:47:24 +01:00
										 |  |  |     if (kvm_enabled() && !kvm_has_many_ioeventfds()) { | 
					
						
							| 
									
										
										
										
											2016-10-21 22:48:04 +02:00
										 |  |  |         proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * virtio pci bar layout used by default. | 
					
						
							|  |  |  |      * subclasses can re-arrange things if needed. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      *   region 0   --  virtio legacy io bar | 
					
						
							|  |  |  |      *   region 1   --  msi-x bar | 
					
						
							|  |  |  |      *   region 4+5 --  virtio modern memory (64bit) bar | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-09-29 12:04:40 +08:00
										 |  |  |     proxy->legacy_io_bar_idx  = 0; | 
					
						
							|  |  |  |     proxy->msix_bar_idx       = 1; | 
					
						
							|  |  |  |     proxy->modern_io_bar_idx  = 2; | 
					
						
							|  |  |  |     proxy->modern_mem_bar_idx = 4; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     proxy->common.offset = 0x0; | 
					
						
							|  |  |  |     proxy->common.size = 0x1000; | 
					
						
							|  |  |  |     proxy->common.type = VIRTIO_PCI_CAP_COMMON_CFG; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     proxy->isr.offset = 0x1000; | 
					
						
							|  |  |  |     proxy->isr.size = 0x1000; | 
					
						
							|  |  |  |     proxy->isr.type = VIRTIO_PCI_CAP_ISR_CFG; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     proxy->device.offset = 0x2000; | 
					
						
							|  |  |  |     proxy->device.size = 0x1000; | 
					
						
							|  |  |  |     proxy->device.type = VIRTIO_PCI_CAP_DEVICE_CFG; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     proxy->notify.offset = 0x3000; | 
					
						
							| 
									
										
										
										
											2016-09-07 18:02:25 +03:00
										 |  |  |     proxy->notify.size = virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MAX; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |     proxy->notify.type = VIRTIO_PCI_CAP_NOTIFY_CFG; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |     proxy->notify_pio.offset = 0x0; | 
					
						
							|  |  |  |     proxy->notify_pio.size = 0x4; | 
					
						
							|  |  |  |     proxy->notify_pio.type = VIRTIO_PCI_CAP_NOTIFY_CFG; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |     /* subclasses can enforce modern, so do this unconditionally */ | 
					
						
							|  |  |  |     memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci", | 
					
						
							| 
									
										
										
										
											2016-09-07 18:02:25 +03:00
										 |  |  |                        /* PCI BAR regions must be powers of 2 */ | 
					
						
							|  |  |  |                        pow2ceil(proxy->notify.offset + proxy->notify.size)); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 18:28:21 +03:00
										 |  |  |     if (proxy->disable_legacy == ON_OFF_AUTO_AUTO) { | 
					
						
							|  |  |  |         proxy->disable_legacy = pcie_port ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-09 20:56:27 +03:00
										 |  |  |     if (!virtio_pci_modern(proxy) && !virtio_pci_legacy(proxy)) { | 
					
						
							| 
									
										
										
										
											2016-09-09 11:00:59 +02:00
										 |  |  |         error_setg(errp, "device cannot work as neither modern nor legacy mode" | 
					
						
							|  |  |  |                    " is enabled"); | 
					
						
							|  |  |  |         error_append_hint(errp, "Set either disable-modern or disable-legacy" | 
					
						
							|  |  |  |                           " to off\n"); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 18:28:21 +03:00
										 |  |  |     if (pcie_port && pci_is_express(pci_dev)) { | 
					
						
							| 
									
										
										
										
											2015-11-10 13:41:29 +02:00
										 |  |  |         int pos; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         pos = pcie_endpoint_cap_init(pci_dev, 0); | 
					
						
							|  |  |  |         assert(pos > 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 14:16:50 +08:00
										 |  |  |         pos = pci_add_capability(pci_dev, PCI_CAP_ID_PM, 0, | 
					
						
							|  |  |  |                                  PCI_PM_SIZEOF, errp); | 
					
						
							|  |  |  |         if (pos < 0) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:13 +02:00
										 |  |  |         pci_dev->exp.pm_cap = pos; | 
					
						
							| 
									
										
										
										
											2015-11-10 13:41:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /*
 | 
					
						
							|  |  |  |          * Indicates that this function complies with revision 1.2 of the | 
					
						
							|  |  |  |          * PCI Power Management Interface Specification. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         pci_set_word(pci_dev->config + pos + PCI_PM_PMC, 0x3); | 
					
						
							| 
									
										
										
										
											2016-12-30 18:09:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:11 +02:00
										 |  |  |         if (proxy->flags & VIRTIO_PCI_FLAG_INIT_DEVERR) { | 
					
						
							|  |  |  |             /* Init error enabling flags */ | 
					
						
							|  |  |  |             pcie_cap_deverr_init(pci_dev); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:12 +02:00
										 |  |  |         if (proxy->flags & VIRTIO_PCI_FLAG_INIT_LNKCTL) { | 
					
						
							|  |  |  |             /* Init Link Control Register */ | 
					
						
							|  |  |  |             pcie_cap_lnkctl_init(pci_dev); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:13 +02:00
										 |  |  |         if (proxy->flags & VIRTIO_PCI_FLAG_INIT_PM) { | 
					
						
							|  |  |  |             /* Init Power Management Control Register */ | 
					
						
							|  |  |  |             pci_set_word(pci_dev->wmask + pos + PCI_PM_CTRL, | 
					
						
							|  |  |  |                          PCI_PM_CTRL_STATE_MASK); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 18:09:15 +08:00
										 |  |  |         if (proxy->flags & VIRTIO_PCI_FLAG_ATS) { | 
					
						
							|  |  |  |             pcie_ats_init(pci_dev, 256); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 19:49:07 +02:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         /*
 | 
					
						
							|  |  |  |          * make future invocations of pci_is_express() return false | 
					
						
							|  |  |  |          * and pci_config_size() return PCI_CONFIG_SPACE_SIZE. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         pci_dev->cap_present &= ~QEMU_PCI_CAP_EXPRESS; | 
					
						
							| 
									
										
										
										
											2015-11-10 13:41:29 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |     virtio_pci_bus_new(&proxy->bus, sizeof(proxy->bus), proxy); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     if (k->realize) { | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:39 +02:00
										 |  |  |         k->realize(proxy, errp); | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_exit(PCIDevice *pci_dev) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-04 11:43:49 +02:00
										 |  |  |     msix_uninit_exclusive_bar(pci_dev); | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  | static void virtio_pci_reset(DeviceState *qdev) | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev); | 
					
						
							|  |  |  |     VirtioBusState *bus = VIRTIO_BUS(&proxy->bus); | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:11 +02:00
										 |  |  |     PCIDevice *dev = PCI_DEVICE(qdev); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:49 +08:00
										 |  |  |     int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  |     virtio_pci_stop_ioeventfd(proxy); | 
					
						
							|  |  |  |     virtio_bus_reset(bus); | 
					
						
							|  |  |  |     msix_unuse_all_vectors(&proxy->pci_dev); | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (i = 0; i < VIRTIO_QUEUE_MAX; i++) { | 
					
						
							|  |  |  |         proxy->vqs[i].enabled = 0; | 
					
						
							| 
									
										
										
										
											2017-03-14 15:25:05 +08:00
										 |  |  |         proxy->vqs[i].num = 0; | 
					
						
							|  |  |  |         proxy->vqs[i].desc[0] = proxy->vqs[i].desc[1] = 0; | 
					
						
							|  |  |  |         proxy->vqs[i].avail[0] = proxy->vqs[i].avail[1] = 0; | 
					
						
							|  |  |  |         proxy->vqs[i].used[0] = proxy->vqs[i].used[1] = 0; | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:49 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (pci_is_express(dev)) { | 
					
						
							|  |  |  |         pcie_cap_deverr_reset(dev); | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:12 +02:00
										 |  |  |         pcie_cap_lnkctl_reset(dev); | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         pci_set_word(dev->config + dev->exp.pm_cap + PCI_PM_CTRL, 0); | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:11 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-01 00:01:58 +08:00
										 |  |  | static Property virtio_pci_properties[] = { | 
					
						
							| 
									
										
										
										
											2014-10-14 19:40:06 +03:00
										 |  |  |     DEFINE_PROP_BIT("virtio-pci-bus-master-bug-migration", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT, false), | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:44 +08:00
										 |  |  |     DEFINE_PROP_BIT("migrate-extra", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_MIGRATE_EXTRA_BIT, true), | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:48 +08:00
										 |  |  |     DEFINE_PROP_BIT("modern-pio-notify", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY_BIT, false), | 
					
						
							| 
									
										
										
										
											2015-11-10 13:41:29 +02:00
										 |  |  |     DEFINE_PROP_BIT("x-disable-pcie", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_DISABLE_PCIE_BIT, false), | 
					
						
							| 
									
										
										
										
											2016-09-07 18:02:25 +03:00
										 |  |  |     DEFINE_PROP_BIT("page-per-vq", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_PAGE_PER_VQ_BIT, false), | 
					
						
							| 
									
										
										
										
											2016-12-14 17:30:35 +01:00
										 |  |  |     DEFINE_PROP_BOOL("x-ignore-backend-features", VirtIOPCIProxy, | 
					
						
							|  |  |  |                      ignore_backend_features, false), | 
					
						
							| 
									
										
										
										
											2016-12-30 18:09:15 +08:00
										 |  |  |     DEFINE_PROP_BIT("ats", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_ATS_BIT, false), | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:11 +02:00
										 |  |  |     DEFINE_PROP_BIT("x-pcie-deverr-init", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_INIT_DEVERR_BIT, true), | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:12 +02:00
										 |  |  |     DEFINE_PROP_BIT("x-pcie-lnkctl-init", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT, true), | 
					
						
							| 
									
										
										
										
											2017-02-20 22:43:13 +02:00
										 |  |  |     DEFINE_PROP_BIT("x-pcie-pm-init", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_INIT_PM_BIT, true), | 
					
						
							| 
									
										
										
										
											2014-07-01 00:01:58 +08:00
										 |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 19:49:07 +02:00
										 |  |  | static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtioPCIClass *vpciklass = VIRTIO_PCI_GET_CLASS(qdev); | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev); | 
					
						
							|  |  |  |     PCIDevice *pci_dev = &proxy->pci_dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) && | 
					
						
							| 
									
										
										
										
											2016-07-20 18:28:21 +03:00
										 |  |  |         virtio_pci_modern(proxy)) { | 
					
						
							| 
									
										
										
										
											2015-12-02 19:49:07 +02:00
										 |  |  |         pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     vpciklass->parent_dc_realize(qdev, errp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | static void virtio_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2015-12-02 19:49:07 +02:00
										 |  |  |     VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-01 00:01:58 +08:00
										 |  |  |     dc->props = virtio_pci_properties; | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     k->realize = virtio_pci_realize; | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  |     k->exit = virtio_pci_exit; | 
					
						
							|  |  |  |     k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     k->revision = VIRTIO_PCI_ABI_VERSION; | 
					
						
							|  |  |  |     k->class_id = PCI_CLASS_OTHERS; | 
					
						
							| 
									
										
										
										
											2018-01-13 23:04:12 -03:00
										 |  |  |     device_class_set_parent_realize(dc, virtio_pci_dc_realize, | 
					
						
							|  |  |  |                                     &vpciklass->parent_dc_realize); | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  |     dc->reset = virtio_pci_reset; | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const TypeInfo virtio_pci_info = { | 
					
						
							|  |  |  |     .name          = TYPE_VIRTIO_PCI, | 
					
						
							|  |  |  |     .parent        = TYPE_PCI_DEVICE, | 
					
						
							|  |  |  |     .instance_size = sizeof(VirtIOPCIProxy), | 
					
						
							|  |  |  |     .class_init    = virtio_pci_class_init, | 
					
						
							|  |  |  |     .class_size    = sizeof(VirtioPCIClass), | 
					
						
							|  |  |  |     .abstract      = true, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static Property virtio_pci_generic_properties[] = { | 
					
						
							|  |  |  |     DEFINE_PROP_ON_OFF_AUTO("disable-legacy", VirtIOPCIProxy, disable_legacy, | 
					
						
							|  |  |  |                             ON_OFF_AUTO_AUTO), | 
					
						
							|  |  |  |     DEFINE_PROP_BOOL("disable-modern", VirtIOPCIProxy, disable_modern, false), | 
					
						
							|  |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_base_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const VirtioPCIDeviceTypeInfo *t = data; | 
					
						
							|  |  |  |     if (t->class_init) { | 
					
						
							|  |  |  |         t->class_init(klass, NULL); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_generic_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dc->props = virtio_pci_generic_properties; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Used when the generic type and the base type is the same */ | 
					
						
							|  |  |  | static void virtio_pci_generic_base_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     virtio_pci_base_class_init(klass, data); | 
					
						
							|  |  |  |     virtio_pci_generic_class_init(klass, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_transitional_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(obj); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     proxy->disable_legacy = ON_OFF_AUTO_OFF; | 
					
						
							|  |  |  |     proxy->disable_modern = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_non_transitional_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOPCIProxy *proxy = VIRTIO_PCI(obj); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     proxy->disable_legacy = ON_OFF_AUTO_ON; | 
					
						
							|  |  |  |     proxy->disable_modern = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     TypeInfo base_type_info = { | 
					
						
							|  |  |  |         .name          = t->base_name, | 
					
						
							|  |  |  |         .parent        = t->parent ? t->parent : TYPE_VIRTIO_PCI, | 
					
						
							|  |  |  |         .instance_size = t->instance_size, | 
					
						
							|  |  |  |         .instance_init = t->instance_init, | 
					
						
							|  |  |  |         .class_init    = virtio_pci_base_class_init, | 
					
						
							|  |  |  |         .class_data    = (void *)t, | 
					
						
							|  |  |  |         .abstract      = true, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     TypeInfo generic_type_info = { | 
					
						
							|  |  |  |         .name = t->generic_name, | 
					
						
							|  |  |  |         .parent = base_type_info.name, | 
					
						
							|  |  |  |         .class_init = virtio_pci_generic_class_init, | 
					
						
							|  |  |  |         .interfaces = (InterfaceInfo[]) { | 
					
						
							|  |  |  |             { INTERFACE_PCIE_DEVICE }, | 
					
						
							|  |  |  |             { INTERFACE_CONVENTIONAL_PCI_DEVICE }, | 
					
						
							|  |  |  |             { } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!base_type_info.name) { | 
					
						
							|  |  |  |         /* No base type -> register a single generic device type */ | 
					
						
							|  |  |  |         base_type_info.name = t->generic_name; | 
					
						
							|  |  |  |         base_type_info.class_init = virtio_pci_generic_base_class_init; | 
					
						
							|  |  |  |         base_type_info.interfaces = generic_type_info.interfaces; | 
					
						
							|  |  |  |         base_type_info.abstract = false; | 
					
						
							|  |  |  |         generic_type_info.name = NULL; | 
					
						
							|  |  |  |         assert(!t->non_transitional_name); | 
					
						
							|  |  |  |         assert(!t->transitional_name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     type_register(&base_type_info); | 
					
						
							|  |  |  |     if (generic_type_info.name) { | 
					
						
							|  |  |  |         type_register(&generic_type_info); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (t->non_transitional_name) { | 
					
						
							|  |  |  |         const TypeInfo non_transitional_type_info = { | 
					
						
							|  |  |  |             .name          = t->non_transitional_name, | 
					
						
							|  |  |  |             .parent        = base_type_info.name, | 
					
						
							|  |  |  |             .instance_init = virtio_pci_non_transitional_instance_init, | 
					
						
							|  |  |  |             .interfaces = (InterfaceInfo[]) { | 
					
						
							|  |  |  |                 { INTERFACE_PCIE_DEVICE }, | 
					
						
							|  |  |  |                 { INTERFACE_CONVENTIONAL_PCI_DEVICE }, | 
					
						
							|  |  |  |                 { } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         type_register(&non_transitional_type_info); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (t->transitional_name) { | 
					
						
							|  |  |  |         const TypeInfo transitional_type_info = { | 
					
						
							|  |  |  |             .name          = t->transitional_name, | 
					
						
							|  |  |  |             .parent        = base_type_info.name, | 
					
						
							|  |  |  |             .instance_init = virtio_pci_transitional_instance_init, | 
					
						
							|  |  |  |             .interfaces = (InterfaceInfo[]) { | 
					
						
							|  |  |  |                 /*
 | 
					
						
							|  |  |  |                  * Transitional virtio devices work only as Conventional PCI | 
					
						
							|  |  |  |                  * devices because they require PIO ports. | 
					
						
							|  |  |  |                  */ | 
					
						
							|  |  |  |                 { INTERFACE_CONVENTIONAL_PCI_DEVICE }, | 
					
						
							|  |  |  |                 { } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         type_register(&transitional_type_info); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  | /* virtio-blk-pci */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static Property virtio_blk_pci_properties[] = { | 
					
						
							| 
									
										
										
										
											2014-02-08 11:01:53 +01:00
										 |  |  |     DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  |     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), | 
					
						
							| 
									
										
										
										
											2018-02-06 09:35:34 +08:00
										 |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, | 
					
						
							|  |  |  |                        DEV_NVECTORS_UNSPECIFIED), | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | static void virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 09:35:34 +08:00
										 |  |  |     if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | 
					
						
							|  |  |  |         vpci_dev->nvectors = dev->vdev.conf.num_queues + 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_blk_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-29 17:17:45 +03:00
										 |  |  |     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  |     dc->props = virtio_blk_pci_properties; | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     k->realize = virtio_blk_pci_realize; | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK; | 
					
						
							|  |  |  |     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_blk_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(obj); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:10:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_BLK); | 
					
						
							| 
									
										
										
										
											2014-10-07 16:00:32 +08:00
										 |  |  |     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), | 
					
						
							|  |  |  |                               "bootindex", &error_abort); | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_blk_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name              = TYPE_VIRTIO_BLK_PCI, | 
					
						
							|  |  |  |     .generic_name           = "virtio-blk-pci", | 
					
						
							|  |  |  |     .transitional_name      = "virtio-blk-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name  = "virtio-blk-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:23 +01:00
										 |  |  |     .instance_size = sizeof(VirtIOBlkPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_blk_pci_instance_init, | 
					
						
							|  |  |  |     .class_init    = virtio_blk_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												vhost-user-blk: introduce a new vhost-user-blk host device
This commit introduces a new vhost-user device for block, it uses a
chardev to connect with the backend, same with Qemu virito-blk device,
Guest OS still uses the virtio-blk frontend driver.
To use it, start QEMU with command line like this:
qemu-system-x86_64 \
    -chardev socket,id=char0,path=/path/vhost.socket \
    -device vhost-user-blk-pci,chardev=char0,num-queues=2, \
            bootindex=2... \
Users can use different parameters for `num-queues` and `bootindex`.
Different with exist Qemu virtio-blk host device, it makes more easy
for users to implement their own I/O processing logic, such as all
user space I/O stack against hardware block device. It uses the new
vhost messages(VHOST_USER_GET_CONFIG) to get block virtio config
information from backend process.
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
											
										 
											2018-01-04 09:53:32 +08:00
										 |  |  | #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
 | 
					
						
							|  |  |  | /* vhost-user-blk */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static Property vhost_user_blk_pci_properties[] = { | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), | 
					
						
							| 
									
										
										
										
											2018-02-06 09:35:34 +08:00
										 |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, | 
					
						
							|  |  |  |                        DEV_NVECTORS_UNSPECIFIED), | 
					
						
							| 
									
										
											  
											
												vhost-user-blk: introduce a new vhost-user-blk host device
This commit introduces a new vhost-user device for block, it uses a
chardev to connect with the backend, same with Qemu virito-blk device,
Guest OS still uses the virtio-blk frontend driver.
To use it, start QEMU with command line like this:
qemu-system-x86_64 \
    -chardev socket,id=char0,path=/path/vhost.socket \
    -device vhost-user-blk-pci,chardev=char0,num-queues=2, \
            bootindex=2... \
Users can use different parameters for `num-queues` and `bootindex`.
Different with exist Qemu virtio-blk host device, it makes more easy
for users to implement their own I/O processing logic, such as all
user space I/O stack against hardware block device. It uses the new
vhost messages(VHOST_USER_GET_CONFIG) to get block virtio config
information from backend process.
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
											
										 
											2018-01-04 09:53:32 +08:00
										 |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_user_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VHostUserBlkPCI *dev = VHOST_USER_BLK_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 09:35:34 +08:00
										 |  |  |     if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | 
					
						
							|  |  |  |         vpci_dev->nvectors = dev->vdev.num_queues + 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												vhost-user-blk: introduce a new vhost-user-blk host device
This commit introduces a new vhost-user device for block, it uses a
chardev to connect with the backend, same with Qemu virito-blk device,
Guest OS still uses the virtio-blk frontend driver.
To use it, start QEMU with command line like this:
qemu-system-x86_64 \
    -chardev socket,id=char0,path=/path/vhost.socket \
    -device vhost-user-blk-pci,chardev=char0,num-queues=2, \
            bootindex=2... \
Users can use different parameters for `num-queues` and `bootindex`.
Different with exist Qemu virtio-blk host device, it makes more easy
for users to implement their own I/O processing logic, such as all
user space I/O stack against hardware block device. It uses the new
vhost messages(VHOST_USER_GET_CONFIG) to get block virtio config
information from backend process.
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
											
										 
											2018-01-04 09:53:32 +08:00
										 |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							|  |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_user_blk_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | 
					
						
							|  |  |  |     dc->props = vhost_user_blk_pci_properties; | 
					
						
							|  |  |  |     k->realize = vhost_user_blk_pci_realize; | 
					
						
							|  |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK; | 
					
						
							|  |  |  |     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_user_blk_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VHostUserBlkPCI *dev = VHOST_USER_BLK_PCI(obj); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VHOST_USER_BLK); | 
					
						
							|  |  |  |     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), | 
					
						
							|  |  |  |                               "bootindex", &error_abort); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo vhost_user_blk_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name               = TYPE_VHOST_USER_BLK_PCI, | 
					
						
							|  |  |  |     .generic_name            = "vhost-user-blk-pci", | 
					
						
							|  |  |  |     .transitional_name       = "vhost-user-blk-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name   = "vhost-user-blk-pci-non-transitional", | 
					
						
							| 
									
										
											  
											
												vhost-user-blk: introduce a new vhost-user-blk host device
This commit introduces a new vhost-user device for block, it uses a
chardev to connect with the backend, same with Qemu virito-blk device,
Guest OS still uses the virtio-blk frontend driver.
To use it, start QEMU with command line like this:
qemu-system-x86_64 \
    -chardev socket,id=char0,path=/path/vhost.socket \
    -device vhost-user-blk-pci,chardev=char0,num-queues=2, \
            bootindex=2... \
Users can use different parameters for `num-queues` and `bootindex`.
Different with exist Qemu virtio-blk host device, it makes more easy
for users to implement their own I/O processing logic, such as all
user space I/O stack against hardware block device. It uses the new
vhost messages(VHOST_USER_GET_CONFIG) to get block virtio config
information from backend process.
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
											
										 
											2018-01-04 09:53:32 +08:00
										 |  |  |     .instance_size  = sizeof(VHostUserBlkPCI), | 
					
						
							|  |  |  |     .instance_init  = vhost_user_blk_pci_instance_init, | 
					
						
							|  |  |  |     .class_init     = vhost_user_blk_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-21 15:15:15 +01:00
										 |  |  | /* virtio-scsi-pci */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static Property virtio_scsi_pci_properties[] = { | 
					
						
							|  |  |  |     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, | 
					
						
							|  |  |  |                        DEV_NVECTORS_UNSPECIFIED), | 
					
						
							|  |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-03-21 15:15:15 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:15 +00:00
										 |  |  |     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); | 
					
						
							| 
									
										
										
										
											2013-04-30 16:08:51 +02:00
										 |  |  |     DeviceState *proxy = DEVICE(vpci_dev); | 
					
						
							|  |  |  |     char *bus_name; | 
					
						
							| 
									
										
										
										
											2013-03-21 15:15:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:15 +00:00
										 |  |  |         vpci_dev->nvectors = vs->conf.num_queues + 3; | 
					
						
							| 
									
										
										
										
											2013-03-21 15:15:15 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 16:08:51 +02:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * For command line compatibility, this sets the virtio-scsi-device bus | 
					
						
							|  |  |  |      * name as before. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if (proxy->id) { | 
					
						
							|  |  |  |         bus_name = g_strdup_printf("%s.0", proxy->id); | 
					
						
							|  |  |  |         virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name); | 
					
						
							|  |  |  |         g_free(bus_name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-21 15:15:15 +01:00
										 |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							| 
									
										
										
										
											2013-03-21 15:15:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_scsi_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     k->realize = virtio_scsi_pci_realize; | 
					
						
							| 
									
										
										
										
											2013-07-29 17:17:45 +03:00
										 |  |  |     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | 
					
						
							| 
									
										
										
										
											2013-03-21 15:15:15 +01:00
										 |  |  |     dc->props = virtio_scsi_pci_properties; | 
					
						
							|  |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI; | 
					
						
							|  |  |  |     pcidev_k->revision = 0x00; | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_scsi_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(obj); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:10:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_SCSI); | 
					
						
							| 
									
										
										
										
											2013-03-21 15:15:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_scsi_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name              = TYPE_VIRTIO_SCSI_PCI, | 
					
						
							|  |  |  |     .generic_name           = "virtio-scsi-pci", | 
					
						
							|  |  |  |     .transitional_name      = "virtio-scsi-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name  = "virtio-scsi-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2013-03-21 15:15:15 +01:00
										 |  |  |     .instance_size = sizeof(VirtIOSCSIPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_scsi_pci_instance_init, | 
					
						
							|  |  |  |     .class_init    = virtio_scsi_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:16 +00:00
										 |  |  | /* vhost-scsi-pci */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_VHOST_SCSI
 | 
					
						
							|  |  |  | static Property vhost_scsi_pci_properties[] = { | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, | 
					
						
							|  |  |  |                        DEV_NVECTORS_UNSPECIFIED), | 
					
						
							|  |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     VHostSCSIPCI *dev = VHOST_SCSI_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							|  |  |  |     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | 
					
						
							|  |  |  |         vpci_dev->nvectors = vs->conf.num_queues + 3; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_scsi_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     k->realize = vhost_scsi_pci_realize; | 
					
						
							| 
									
										
										
										
											2013-07-29 17:17:45 +03:00
										 |  |  |     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:16 +00:00
										 |  |  |     dc->props = vhost_scsi_pci_properties; | 
					
						
							|  |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI; | 
					
						
							|  |  |  |     pcidev_k->revision = 0x00; | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_scsi_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VHostSCSIPCI *dev = VHOST_SCSI_PCI(obj); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:10:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VHOST_SCSI); | 
					
						
							| 
									
										
										
										
											2015-01-29 15:08:52 +08:00
										 |  |  |     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), | 
					
						
							|  |  |  |                               "bootindex", &error_abort); | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo vhost_scsi_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name             = TYPE_VHOST_SCSI_PCI, | 
					
						
							|  |  |  |     .generic_name          = "vhost-scsi-pci", | 
					
						
							|  |  |  |     .transitional_name     = "vhost-scsi-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name = "vhost-scsi-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:16 +00:00
										 |  |  |     .instance_size = sizeof(VHostSCSIPCI), | 
					
						
							|  |  |  |     .instance_init = vhost_scsi_pci_instance_init, | 
					
						
							|  |  |  |     .class_init    = vhost_scsi_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-03 11:07:46 +02:00
										 |  |  | #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
 | 
					
						
							| 
									
										
										
										
											2017-03-02 10:25:52 -08:00
										 |  |  | /* vhost-user-scsi-pci */ | 
					
						
							|  |  |  | static Property vhost_user_scsi_pci_properties[] = { | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, | 
					
						
							|  |  |  |                        DEV_NVECTORS_UNSPECIFIED), | 
					
						
							|  |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VHostUserSCSIPCI *dev = VHOST_USER_SCSI_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							|  |  |  |     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | 
					
						
							|  |  |  |         vpci_dev->nvectors = vs->conf.num_queues + 3; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							|  |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_user_scsi_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     k->realize = vhost_user_scsi_pci_realize; | 
					
						
							|  |  |  |     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); | 
					
						
							|  |  |  |     dc->props = vhost_user_scsi_pci_properties; | 
					
						
							|  |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI; | 
					
						
							|  |  |  |     pcidev_k->revision = 0x00; | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_user_scsi_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VHostUserSCSIPCI *dev = VHOST_USER_SCSI_PCI(obj); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VHOST_USER_SCSI); | 
					
						
							|  |  |  |     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), | 
					
						
							|  |  |  |                               "bootindex", &error_abort); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo vhost_user_scsi_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name             = TYPE_VHOST_USER_SCSI_PCI, | 
					
						
							|  |  |  |     .generic_name          = "vhost-user-scsi-pci", | 
					
						
							|  |  |  |     .transitional_name     = "vhost-user-scsi-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name = "vhost-user-scsi-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2017-03-02 10:25:52 -08:00
										 |  |  |     .instance_size = sizeof(VHostUserSCSIPCI), | 
					
						
							|  |  |  |     .instance_init = vhost_user_scsi_pci_instance_init, | 
					
						
							|  |  |  |     .class_init    = vhost_user_scsi_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-16 13:27:22 +01:00
										 |  |  | /* vhost-vsock-pci */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_VHOST_VSOCK
 | 
					
						
							|  |  |  | static Property vhost_vsock_pci_properties[] = { | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), | 
					
						
							|  |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VHostVSockPCI *dev = VHOST_VSOCK_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							|  |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_vsock_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     k->realize = vhost_vsock_pci_realize; | 
					
						
							|  |  |  |     set_bit(DEVICE_CATEGORY_MISC, dc->categories); | 
					
						
							|  |  |  |     dc->props = vhost_vsock_pci_properties; | 
					
						
							|  |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK; | 
					
						
							|  |  |  |     pcidev_k->revision = 0x00; | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void vhost_vsock_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VHostVSockPCI *dev = VHOST_VSOCK_PCI(obj); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VHOST_VSOCK); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo vhost_vsock_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name             = TYPE_VHOST_VSOCK_PCI, | 
					
						
							|  |  |  |     .generic_name          = "vhost-vsock-pci", | 
					
						
							|  |  |  |     .transitional_name     = "vhost-vsock-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name = "vhost-vsock-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2016-08-16 13:27:22 +01:00
										 |  |  |     .instance_size = sizeof(VHostVSockPCI), | 
					
						
							|  |  |  |     .instance_init = vhost_vsock_pci_instance_init, | 
					
						
							|  |  |  |     .class_init    = vhost_vsock_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-27 10:49:11 +01:00
										 |  |  | /* virtio-balloon-pci */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static Property virtio_balloon_pci_properties[] = { | 
					
						
							| 
									
										
										
										
											2014-02-08 11:01:53 +01:00
										 |  |  |     DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), | 
					
						
							| 
									
										
										
										
											2013-03-27 10:49:11 +01:00
										 |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | static void virtio_balloon_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-03-27 10:49:11 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (vpci_dev->class_code != PCI_CLASS_OTHERS && | 
					
						
							|  |  |  |         vpci_dev->class_code != PCI_CLASS_MEMORY_RAM) { /* qemu < 1.1 */ | 
					
						
							|  |  |  |         vpci_dev->class_code = PCI_CLASS_OTHERS; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							| 
									
										
										
										
											2013-03-27 10:49:11 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_balloon_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     k->realize = virtio_balloon_pci_realize; | 
					
						
							| 
									
										
										
										
											2013-07-29 17:17:45 +03:00
										 |  |  |     set_bit(DEVICE_CATEGORY_MISC, dc->categories); | 
					
						
							| 
									
										
										
										
											2013-03-27 10:49:11 +01:00
										 |  |  |     dc->props = virtio_balloon_pci_properties; | 
					
						
							|  |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON; | 
					
						
							|  |  |  |     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_OTHERS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_balloon_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj); | 
					
						
							| 
									
										
										
										
											2015-05-11 17:34:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 17:24:41 +03:00
										 |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_BALLOON); | 
					
						
							| 
									
										
										
										
											2015-05-11 17:34:06 +08:00
										 |  |  |     object_property_add_alias(obj, "guest-stats", OBJECT(&dev->vdev), | 
					
						
							|  |  |  |                                   "guest-stats", &error_abort); | 
					
						
							|  |  |  |     object_property_add_alias(obj, "guest-stats-polling-interval", | 
					
						
							|  |  |  |                               OBJECT(&dev->vdev), | 
					
						
							|  |  |  |                               "guest-stats-polling-interval", &error_abort); | 
					
						
							| 
									
										
										
										
											2013-03-27 10:49:11 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_balloon_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name             = TYPE_VIRTIO_BALLOON_PCI, | 
					
						
							|  |  |  |     .generic_name          = "virtio-balloon-pci", | 
					
						
							|  |  |  |     .transitional_name     = "virtio-balloon-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name = "virtio-balloon-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2013-03-27 10:49:11 +01:00
										 |  |  |     .instance_size = sizeof(VirtIOBalloonPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_balloon_pci_instance_init, | 
					
						
							|  |  |  |     .class_init    = virtio_balloon_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 14:53:31 +02:00
										 |  |  | /* virtio-serial-pci */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-04-09 14:53:31 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							| 
									
										
										
										
											2013-04-30 16:08:50 +02:00
										 |  |  |     DeviceState *proxy = DEVICE(vpci_dev); | 
					
						
							|  |  |  |     char *bus_name; | 
					
						
							| 
									
										
										
										
											2013-04-09 14:53:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (vpci_dev->class_code != PCI_CLASS_COMMUNICATION_OTHER && | 
					
						
							|  |  |  |         vpci_dev->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */ | 
					
						
							|  |  |  |         vpci_dev->class_code != PCI_CLASS_OTHERS) {        /* qemu-kvm  */ | 
					
						
							|  |  |  |             vpci_dev->class_code = PCI_CLASS_COMMUNICATION_OTHER; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* backwards-compatibility with machines that were created with
 | 
					
						
							|  |  |  |        DEV_NVECTORS_UNSPECIFIED */ | 
					
						
							|  |  |  |     if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { | 
					
						
							|  |  |  |         vpci_dev->nvectors = dev->vdev.serial.max_virtserial_ports + 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 16:08:50 +02:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * For command line compatibility, this sets the virtio-serial-device bus | 
					
						
							|  |  |  |      * name as before. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if (proxy->id) { | 
					
						
							|  |  |  |         bus_name = g_strdup_printf("%s.0", proxy->id); | 
					
						
							|  |  |  |         virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name); | 
					
						
							|  |  |  |         g_free(bus_name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 14:53:31 +02:00
										 |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							| 
									
										
										
										
											2013-04-09 14:53:31 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static Property virtio_serial_pci_properties[] = { | 
					
						
							|  |  |  |     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, | 
					
						
							|  |  |  |                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), | 
					
						
							|  |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), | 
					
						
							| 
									
										
										
										
											2014-02-08 11:01:53 +01:00
										 |  |  |     DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), | 
					
						
							| 
									
										
										
										
											2013-04-09 14:53:31 +02:00
										 |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_serial_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     k->realize = virtio_serial_pci_realize; | 
					
						
							| 
									
										
										
										
											2013-07-29 17:17:45 +03:00
										 |  |  |     set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | 
					
						
							| 
									
										
										
										
											2013-04-09 14:53:31 +02:00
										 |  |  |     dc->props = virtio_serial_pci_properties; | 
					
						
							|  |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE; | 
					
						
							|  |  |  |     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_serial_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(obj); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:10:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_SERIAL); | 
					
						
							| 
									
										
										
										
											2013-04-09 14:53:31 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_serial_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name             = TYPE_VIRTIO_SERIAL_PCI, | 
					
						
							|  |  |  |     .generic_name          = "virtio-serial-pci", | 
					
						
							|  |  |  |     .transitional_name     = "virtio-serial-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name = "virtio-serial-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2013-04-09 14:53:31 +02:00
										 |  |  |     .instance_size = sizeof(VirtIOSerialPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_serial_pci_instance_init, | 
					
						
							|  |  |  |     .class_init    = virtio_serial_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  | /* virtio-net-pci */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static Property virtio_net_properties[] = { | 
					
						
							|  |  |  |     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, | 
					
						
							| 
									
										
										
										
											2017-01-11 09:38:15 +01:00
										 |  |  |                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), | 
					
						
							|  |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-15 14:12:50 +02:00
										 |  |  |     DeviceState *qdev = DEVICE(vpci_dev); | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  |     VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&dev->vdev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-15 14:12:50 +02:00
										 |  |  |     virtio_net_set_netclient_name(&dev->vdev, qdev->id, | 
					
						
							|  |  |  |                                   object_get_typename(OBJECT(qdev))); | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_net_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     k->romfile = "efi-virtio.rom"; | 
					
						
							|  |  |  |     k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     k->device_id = PCI_DEVICE_ID_VIRTIO_NET; | 
					
						
							|  |  |  |     k->revision = VIRTIO_PCI_ABI_VERSION; | 
					
						
							|  |  |  |     k->class_id = PCI_CLASS_NETWORK_ETHERNET; | 
					
						
							| 
									
										
										
										
											2013-07-29 17:17:45 +03:00
										 |  |  |     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  |     dc->props = virtio_net_properties; | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     vpciklass->realize = virtio_net_pci_realize; | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_net_pci_instance_init(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIONetPCI *dev = VIRTIO_NET_PCI(obj); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:10:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_NET); | 
					
						
							| 
									
										
										
										
											2014-10-07 16:00:22 +08:00
										 |  |  |     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), | 
					
						
							|  |  |  |                               "bootindex", &error_abort); | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_net_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name             = TYPE_VIRTIO_NET_PCI, | 
					
						
							|  |  |  |     .generic_name          = "virtio-net-pci", | 
					
						
							|  |  |  |     .transitional_name     = "virtio-net-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name = "virtio-net-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2013-04-11 16:29:58 +02:00
										 |  |  |     .instance_size = sizeof(VirtIONetPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_net_pci_instance_init, | 
					
						
							|  |  |  |     .class_init    = virtio_net_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  | /* virtio-rng-pci */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  | static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&vrng->vdev); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     Error *err = NULL; | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", &err); | 
					
						
							|  |  |  |     if (err) { | 
					
						
							|  |  |  |         error_propagate(errp, err); | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     object_property_set_link(OBJECT(vrng), | 
					
						
							| 
									
										
										
										
											2013-05-31 14:12:48 -04:00
										 |  |  |                              OBJECT(vrng->vdev.conf.rng), "rng", | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  |                              NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_rng_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 14:52:14 +01:00
										 |  |  |     k->realize = virtio_rng_pci_realize; | 
					
						
							| 
									
										
										
										
											2013-07-29 17:17:45 +03:00
										 |  |  |     set_bit(DEVICE_CATEGORY_MISC, dc->categories); | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; | 
					
						
							|  |  |  |     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG; | 
					
						
							|  |  |  |     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_OTHERS; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_rng_initfn(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj); | 
					
						
							| 
									
										
										
										
											2014-09-30 14:10:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_RNG); | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_rng_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name             = TYPE_VIRTIO_RNG_PCI, | 
					
						
							|  |  |  |     .generic_name          = "virtio-rng-pci", | 
					
						
							|  |  |  |     .transitional_name     = "virtio-rng-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name = "virtio-rng-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2013-04-24 10:07:56 +02:00
										 |  |  |     .instance_size = sizeof(VirtIORngPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_rng_initfn, | 
					
						
							|  |  |  |     .class_init    = virtio_rng_pci_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:41 +02:00
										 |  |  | /* virtio-input-pci */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:45:47 +02:00
										 |  |  | static Property virtio_input_pci_properties[] = { | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  |     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), | 
					
						
							|  |  |  |     DEFINE_PROP_END_OF_LIST(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:41 +02:00
										 |  |  | static void virtio_input_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOInputPCI *vinput = VIRTIO_INPUT_PCI(vpci_dev); | 
					
						
							|  |  |  |     DeviceState *vdev = DEVICE(&vinput->vdev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); | 
					
						
							| 
									
										
										
										
											2016-07-20 18:28:21 +03:00
										 |  |  |     virtio_pci_force_virtio_1(vpci_dev); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:41 +02:00
										 |  |  |     object_property_set_bool(OBJECT(vdev), true, "realized", errp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_input_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							|  |  |  |     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:45:47 +02:00
										 |  |  |     dc->props = virtio_input_pci_properties; | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:41 +02:00
										 |  |  |     k->realize = virtio_input_pci_realize; | 
					
						
							|  |  |  |     set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_INPUT_OTHER; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  | static void virtio_input_hid_kbd_pci_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_INPUT_KEYBOARD; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_input_hid_mouse_pci_class_init(ObjectClass *klass, | 
					
						
							|  |  |  |                                                   void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pcidev_k->class_id = PCI_CLASS_INPUT_MOUSE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_keyboard_initfn(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj); | 
					
						
							| 
									
										
										
										
											2015-06-18 17:45:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_KEYBOARD); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_mouse_initfn(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj); | 
					
						
							| 
									
										
										
										
											2015-06-18 17:45:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_MOUSE); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_tablet_initfn(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj); | 
					
						
							| 
									
										
										
										
											2015-06-18 17:45:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_TABLET); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:41 +02:00
										 |  |  | static const TypeInfo virtio_input_pci_info = { | 
					
						
							|  |  |  |     .name          = TYPE_VIRTIO_INPUT_PCI, | 
					
						
							|  |  |  |     .parent        = TYPE_VIRTIO_PCI, | 
					
						
							|  |  |  |     .instance_size = sizeof(VirtIOInputPCI), | 
					
						
							|  |  |  |     .class_init    = virtio_input_pci_class_init, | 
					
						
							|  |  |  |     .abstract      = true, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  | static const TypeInfo virtio_input_hid_pci_info = { | 
					
						
							|  |  |  |     .name          = TYPE_VIRTIO_INPUT_HID_PCI, | 
					
						
							|  |  |  |     .parent        = TYPE_VIRTIO_INPUT_PCI, | 
					
						
							|  |  |  |     .instance_size = sizeof(VirtIOInputHIDPCI), | 
					
						
							|  |  |  |     .abstract      = true, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_keyboard_pci_info = { | 
					
						
							|  |  |  |     .generic_name  = TYPE_VIRTIO_KEYBOARD_PCI, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  |     .parent        = TYPE_VIRTIO_INPUT_HID_PCI, | 
					
						
							|  |  |  |     .class_init    = virtio_input_hid_kbd_pci_class_init, | 
					
						
							|  |  |  |     .instance_size = sizeof(VirtIOInputHIDPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_keyboard_initfn, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_mouse_pci_info = { | 
					
						
							|  |  |  |     .generic_name  = TYPE_VIRTIO_MOUSE_PCI, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  |     .parent        = TYPE_VIRTIO_INPUT_HID_PCI, | 
					
						
							|  |  |  |     .class_init    = virtio_input_hid_mouse_pci_class_init, | 
					
						
							|  |  |  |     .instance_size = sizeof(VirtIOInputHIDPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_mouse_initfn, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_tablet_pci_info = { | 
					
						
							|  |  |  |     .generic_name  = TYPE_VIRTIO_TABLET_PCI, | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  |     .parent        = TYPE_VIRTIO_INPUT_HID_PCI, | 
					
						
							|  |  |  |     .instance_size = sizeof(VirtIOInputHIDPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_tablet_initfn, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												virtio-input: Fix device introspection on non-Linux hosts
When CONFIG_LINUX is off, devices "virtio-keyboard-device",
"virtio-mouse-device", "virtio-tablet-device" and
"virtio-input-host-device" aren't compiled in, yet
"virtio-keyboard-pci", "virtio-mouse-pci", "virtio-tablet-pci" and
"virtio-input-host-pci" still are.  Attempts to introspect them crash,
e.g.
    $ qemu-system-x86_64 -device virtio-tablet-pci,help
    **
    ERROR:/work/armbru/qemu/qom/object.c:333:object_initialize_with_type: assertion failed: (type != NULL)
Broken in commit 710e2d9 and commit 006a5ed.
Fix by compiling the "virtio-FOO-pci" exactly when compiling the
"virtio-FOO-device": compile "virtio-keyboard-device",
"virtio-mouse-device", "virtio-tablet-device" regardless of
CONFIG_LINUX, and compile "virtio-input-host-pci" only for
CONFIG_LINUX.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Message-Id: <1444320700-26260-3-git-send-email-armbru@redhat.com>
											
										 
											2015-10-08 18:11:40 +02:00
										 |  |  | #ifdef CONFIG_LINUX
 | 
					
						
							|  |  |  | static void virtio_host_initfn(Object *obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     VirtIOInputHostPCI *dev = VIRTIO_INPUT_HOST_PCI(obj); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 
					
						
							|  |  |  |                                 TYPE_VIRTIO_INPUT_HOST); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | static const VirtioPCIDeviceTypeInfo virtio_host_pci_info = { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:04 -02:00
										 |  |  |     .base_name             = TYPE_VIRTIO_INPUT_HOST_PCI, | 
					
						
							|  |  |  |     .generic_name          = "virtio-input-host-pci", | 
					
						
							|  |  |  |     .transitional_name     = "virtio-input-host-pci-transitional", | 
					
						
							|  |  |  |     .non_transitional_name = "virtio-input-host-pci-non-transitional", | 
					
						
							| 
									
										
										
										
											2014-03-28 09:18:47 +01:00
										 |  |  |     .parent        = TYPE_VIRTIO_INPUT_PCI, | 
					
						
							|  |  |  |     .instance_size = sizeof(VirtIOInputHostPCI), | 
					
						
							|  |  |  |     .instance_init = virtio_host_initfn, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
											  
											
												virtio-input: Fix device introspection on non-Linux hosts
When CONFIG_LINUX is off, devices "virtio-keyboard-device",
"virtio-mouse-device", "virtio-tablet-device" and
"virtio-input-host-device" aren't compiled in, yet
"virtio-keyboard-pci", "virtio-mouse-pci", "virtio-tablet-pci" and
"virtio-input-host-pci" still are.  Attempts to introspect them crash,
e.g.
    $ qemu-system-x86_64 -device virtio-tablet-pci,help
    **
    ERROR:/work/armbru/qemu/qom/object.c:333:object_initialize_with_type: assertion failed: (type != NULL)
Broken in commit 710e2d9 and commit 006a5ed.
Fix by compiling the "virtio-FOO-pci" exactly when compiling the
"virtio-FOO-device": compile "virtio-keyboard-device",
"virtio-mouse-device", "virtio-tablet-device" regardless of
CONFIG_LINUX, and compile "virtio-input-host-pci" only for
CONFIG_LINUX.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Message-Id: <1444320700-26260-3-git-send-email-armbru@redhat.com>
											
										 
											2015-10-08 18:11:40 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-03-28 09:18:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:03 +01:00
										 |  |  | /* virtio-pci-bus */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-23 20:35:18 +02:00
										 |  |  | static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size, | 
					
						
							|  |  |  |                                VirtIOPCIProxy *dev) | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:03 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     DeviceState *qdev = DEVICE(dev); | 
					
						
							| 
									
										
										
										
											2013-04-30 16:08:47 +02:00
										 |  |  |     char virtio_bus_name[] = "virtio-bus"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-24 00:02:27 +02:00
										 |  |  |     qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_PCI_BUS, qdev, | 
					
						
							| 
									
										
										
										
											2013-04-30 16:08:47 +02:00
										 |  |  |                         virtio_bus_name); | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:03 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     BusClass *bus_class = BUS_CLASS(klass); | 
					
						
							|  |  |  |     VirtioBusClass *k = VIRTIO_BUS_CLASS(klass); | 
					
						
							|  |  |  |     bus_class->max_dev = 1; | 
					
						
							|  |  |  |     k->notify = virtio_pci_notify; | 
					
						
							|  |  |  |     k->save_config = virtio_pci_save_config; | 
					
						
							|  |  |  |     k->load_config = virtio_pci_load_config; | 
					
						
							|  |  |  |     k->save_queue = virtio_pci_save_queue; | 
					
						
							|  |  |  |     k->load_queue = virtio_pci_load_queue; | 
					
						
							| 
									
										
										
										
											2015-11-06 16:02:44 +08:00
										 |  |  |     k->save_extra_state = virtio_pci_save_extra_state; | 
					
						
							|  |  |  |     k->load_extra_state = virtio_pci_load_extra_state; | 
					
						
							|  |  |  |     k->has_extra_state = virtio_pci_has_extra_state; | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:03 +01:00
										 |  |  |     k->query_guest_notifiers = virtio_pci_query_guest_notifiers; | 
					
						
							|  |  |  |     k->set_guest_notifiers = virtio_pci_set_guest_notifiers; | 
					
						
							| 
									
										
										
										
											2018-04-12 23:12:30 +08:00
										 |  |  |     k->set_host_notifier_mr = virtio_pci_set_host_notifier_mr; | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:03 +01:00
										 |  |  |     k->vmstate_change = virtio_pci_vmstate_change; | 
					
						
							| 
									
										
										
										
											2016-09-13 15:30:30 +02:00
										 |  |  |     k->pre_plugged = virtio_pci_pre_plugged; | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:04 +01:00
										 |  |  |     k->device_plugged = virtio_pci_device_plugged; | 
					
						
							| 
									
										
										
										
											2013-09-20 14:10:26 +02:00
										 |  |  |     k->device_unplugged = virtio_pci_device_unplugged; | 
					
						
							| 
									
										
										
										
											2015-04-23 14:21:46 +08:00
										 |  |  |     k->query_nvectors = virtio_pci_query_nvectors; | 
					
						
							| 
									
										
										
										
											2016-10-21 22:48:08 +02:00
										 |  |  |     k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; | 
					
						
							| 
									
										
										
										
											2016-06-10 11:04:12 +02:00
										 |  |  |     k->ioeventfd_assign = virtio_pci_ioeventfd_assign; | 
					
						
							| 
									
										
										
										
											2016-12-30 18:09:10 +08:00
										 |  |  |     k->get_dma_as = virtio_pci_get_dma_as; | 
					
						
							| 
									
										
										
										
											2013-01-15 00:08:03 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const TypeInfo virtio_pci_bus_info = { | 
					
						
							|  |  |  |     .name          = TYPE_VIRTIO_PCI_BUS, | 
					
						
							|  |  |  |     .parent        = TYPE_VIRTIO_BUS, | 
					
						
							|  |  |  |     .instance_size = sizeof(VirtioPCIBusState), | 
					
						
							|  |  |  |     .class_init    = virtio_pci_bus_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 15:20:55 +01:00
										 |  |  | static void virtio_pci_register_types(void) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  |     /* Base types: */ | 
					
						
							|  |  |  |     type_register_static(&virtio_pci_bus_info); | 
					
						
							|  |  |  |     type_register_static(&virtio_pci_info); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:41 +02:00
										 |  |  |     type_register_static(&virtio_input_pci_info); | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:42 +02:00
										 |  |  |     type_register_static(&virtio_input_hid_pci_info); | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Implementations: */ | 
					
						
							|  |  |  |     virtio_pci_types_register(&virtio_rng_pci_info); | 
					
						
							|  |  |  |     virtio_pci_types_register(&virtio_keyboard_pci_info); | 
					
						
							|  |  |  |     virtio_pci_types_register(&virtio_mouse_pci_info); | 
					
						
							|  |  |  |     virtio_pci_types_register(&virtio_tablet_pci_info); | 
					
						
							| 
									
										
											  
											
												virtio-input: Fix device introspection on non-Linux hosts
When CONFIG_LINUX is off, devices "virtio-keyboard-device",
"virtio-mouse-device", "virtio-tablet-device" and
"virtio-input-host-device" aren't compiled in, yet
"virtio-keyboard-pci", "virtio-mouse-pci", "virtio-tablet-pci" and
"virtio-input-host-pci" still are.  Attempts to introspect them crash,
e.g.
    $ qemu-system-x86_64 -device virtio-tablet-pci,help
    **
    ERROR:/work/armbru/qemu/qom/object.c:333:object_initialize_with_type: assertion failed: (type != NULL)
Broken in commit 710e2d9 and commit 006a5ed.
Fix by compiling the "virtio-FOO-pci" exactly when compiling the
"virtio-FOO-device": compile "virtio-keyboard-device",
"virtio-mouse-device", "virtio-tablet-device" regardless of
CONFIG_LINUX, and compile "virtio-input-host-pci" only for
CONFIG_LINUX.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Message-Id: <1444320700-26260-3-git-send-email-armbru@redhat.com>
											
										 
											2015-10-08 18:11:40 +02:00
										 |  |  | #ifdef CONFIG_LINUX
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  |     virtio_pci_types_register(&virtio_host_pci_info); | 
					
						
							| 
									
										
											  
											
												virtio-input: Fix device introspection on non-Linux hosts
When CONFIG_LINUX is off, devices "virtio-keyboard-device",
"virtio-mouse-device", "virtio-tablet-device" and
"virtio-input-host-device" aren't compiled in, yet
"virtio-keyboard-pci", "virtio-mouse-pci", "virtio-tablet-pci" and
"virtio-input-host-pci" still are.  Attempts to introspect them crash,
e.g.
    $ qemu-system-x86_64 -device virtio-tablet-pci,help
    **
    ERROR:/work/armbru/qemu/qom/object.c:333:object_initialize_with_type: assertion failed: (type != NULL)
Broken in commit 710e2d9 and commit 006a5ed.
Fix by compiling the "virtio-FOO-pci" exactly when compiling the
"virtio-FOO-device": compile "virtio-keyboard-device",
"virtio-mouse-device", "virtio-tablet-device" regardless of
CONFIG_LINUX, and compile "virtio-input-host-pci" only for
CONFIG_LINUX.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Message-Id: <1444320700-26260-3-git-send-email-armbru@redhat.com>
											
										 
											2015-10-08 18:11:40 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | #ifdef CONFIG_VIRTFS
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  |     virtio_pci_types_register(&virtio_9p_pci_info); | 
					
						
							| 
									
										
										
										
											2013-02-04 15:37:49 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  |     virtio_pci_types_register(&virtio_blk_pci_info); | 
					
						
							| 
									
										
											  
											
												vhost-user-blk: introduce a new vhost-user-blk host device
This commit introduces a new vhost-user device for block, it uses a
chardev to connect with the backend, same with Qemu virito-blk device,
Guest OS still uses the virtio-blk frontend driver.
To use it, start QEMU with command line like this:
qemu-system-x86_64 \
    -chardev socket,id=char0,path=/path/vhost.socket \
    -device vhost-user-blk-pci,chardev=char0,num-queues=2, \
            bootindex=2... \
Users can use different parameters for `num-queues` and `bootindex`.
Different with exist Qemu virtio-blk host device, it makes more easy
for users to implement their own I/O processing logic, such as all
user space I/O stack against hardware block device. It uses the new
vhost messages(VHOST_USER_GET_CONFIG) to get block virtio config
information from backend process.
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
											
										 
											2018-01-04 09:53:32 +08:00
										 |  |  | #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  |     virtio_pci_types_register(&vhost_user_blk_pci_info); | 
					
						
							| 
									
										
											  
											
												vhost-user-blk: introduce a new vhost-user-blk host device
This commit introduces a new vhost-user device for block, it uses a
chardev to connect with the backend, same with Qemu virito-blk device,
Guest OS still uses the virtio-blk frontend driver.
To use it, start QEMU with command line like this:
qemu-system-x86_64 \
    -chardev socket,id=char0,path=/path/vhost.socket \
    -device vhost-user-blk-pci,chardev=char0,num-queues=2, \
            bootindex=2... \
Users can use different parameters for `num-queues` and `bootindex`.
Different with exist Qemu virtio-blk host device, it makes more easy
for users to implement their own I/O processing logic, such as all
user space I/O stack against hardware block device. It uses the new
vhost messages(VHOST_USER_GET_CONFIG) to get block virtio config
information from backend process.
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
											
										 
											2018-01-04 09:53:32 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  |     virtio_pci_types_register(&virtio_scsi_pci_info); | 
					
						
							|  |  |  |     virtio_pci_types_register(&virtio_balloon_pci_info); | 
					
						
							|  |  |  |     virtio_pci_types_register(&virtio_serial_pci_info); | 
					
						
							|  |  |  |     virtio_pci_types_register(&virtio_net_pci_info); | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:16 +00:00
										 |  |  | #ifdef CONFIG_VHOST_SCSI
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  |     virtio_pci_types_register(&vhost_scsi_pci_info); | 
					
						
							| 
									
										
										
										
											2013-03-29 01:08:16 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-08-03 11:07:46 +02:00
										 |  |  | #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  |     virtio_pci_types_register(&vhost_user_scsi_pci_info); | 
					
						
							| 
									
										
										
										
											2017-03-02 10:25:52 -08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-08-16 13:27:22 +01:00
										 |  |  | #ifdef CONFIG_VHOST_VSOCK
 | 
					
						
							| 
									
										
										
										
											2018-12-05 17:57:03 -02:00
										 |  |  |     virtio_pci_types_register(&vhost_vsock_pci_info); | 
					
						
							| 
									
										
										
										
											2016-08-16 13:27:22 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:51:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 15:20:55 +01:00
										 |  |  | type_init(virtio_pci_register_types) |