2009-05-18 17:51:59 +04: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 20:44:23 +04: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 17:51:59 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2015-02-17 00:36:43 +03:00
|
|
|
#include "standard-headers/linux/virtio_pci.h"
|
2013-02-05 20:06:20 +04: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"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/error-report.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/pci/msi.h"
|
|
|
|
#include "hw/pci/msix.h"
|
|
|
|
#include "hw/loader.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/kvm.h"
|
2014-10-07 15:59:18 +04:00
|
|
|
#include "sysemu/block-backend.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "virtio-pci.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/range.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/virtio/virtio-bus.h"
|
2013-04-14 16:07:00 +04:00
|
|
|
#include "qapi/visitor.h"
|
2009-05-18 17:51:59 +04:00
|
|
|
|
2015-02-17 00:36:43 +03:00
|
|
|
#define VIRTIO_PCI_REGION_SIZE(dev) VIRTIO_PCI_CONFIG_OFF(msix_present(dev))
|
2009-06-21 20:50:26 +04:00
|
|
|
|
|
|
|
/* The remaining space is defined by each driver as the per-driver
|
|
|
|
* configuration space */
|
2015-02-17 00:36:43 +03:00
|
|
|
#define VIRTIO_PCI_CONFIG_SIZE(dev) VIRTIO_PCI_CONFIG_OFF(msix_enabled(dev))
|
2009-05-18 17:51:59 +04:00
|
|
|
|
2013-08-23 22:35:18 +04:00
|
|
|
static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
|
|
|
|
VirtIOPCIProxy *dev);
|
2013-04-24 12:21:18 +04:00
|
|
|
|
2009-05-18 17:51:59 +04:00
|
|
|
/* virtio device */
|
2012-12-17 15:01:07 +04: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 17:51:59 +04:00
|
|
|
|
2012-12-17 15:01:07 +04: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 17:51:59 +04:00
|
|
|
{
|
2012-12-17 15:01:07 +04: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 15:36:40 +04:00
|
|
|
|
2009-06-21 20:50:26 +04:00
|
|
|
if (msix_enabled(&proxy->pci_dev))
|
|
|
|
msix_notify(&proxy->pci_dev, vector);
|
2013-09-20 15:36:40 +04:00
|
|
|
else {
|
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
|
pci_set_irq(&proxy->pci_dev, vdev->isr & 1);
|
|
|
|
}
|
2009-05-18 17:51:59 +04:00
|
|
|
}
|
|
|
|
|
2012-12-17 15:01:07 +04:00
|
|
|
static void virtio_pci_save_config(DeviceState *d, QEMUFile *f)
|
2009-06-21 20:50:40 +04:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
|
|
2009-06-21 20:50:40 +04:00
|
|
|
pci_device_save(&proxy->pci_dev, f);
|
|
|
|
msix_save(&proxy->pci_dev, f);
|
|
|
|
if (msix_present(&proxy->pci_dev))
|
2013-09-20 15:36:40 +04:00
|
|
|
qemu_put_be16(f, vdev->config_vector);
|
2009-06-21 20:50:40 +04:00
|
|
|
}
|
|
|
|
|
2012-12-17 15:01:07 +04:00
|
|
|
static void virtio_pci_save_queue(DeviceState *d, int n, QEMUFile *f)
|
2009-06-21 20:50:40 +04:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
|
|
2009-06-21 20:50:40 +04:00
|
|
|
if (msix_present(&proxy->pci_dev))
|
2013-09-20 15:36:40 +04:00
|
|
|
qemu_put_be16(f, virtio_queue_vector(vdev, n));
|
2009-06-21 20:50:40 +04:00
|
|
|
}
|
|
|
|
|
2012-12-17 15:01:07 +04:00
|
|
|
static int virtio_pci_load_config(DeviceState *d, QEMUFile *f)
|
2009-06-21 20:50:40 +04:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
|
|
2009-06-21 20:50:40 +04:00
|
|
|
int ret;
|
|
|
|
ret = pci_device_load(&proxy->pci_dev, f);
|
2009-07-05 17:02:34 +04:00
|
|
|
if (ret) {
|
2009-06-21 20:50:40 +04:00
|
|
|
return ret;
|
2009-07-05 17:02:34 +04:00
|
|
|
}
|
2012-08-29 20:40:56 +04:00
|
|
|
msix_unuse_all_vectors(&proxy->pci_dev);
|
2009-06-21 20:50:40 +04:00
|
|
|
msix_load(&proxy->pci_dev, f);
|
2009-07-05 17:02:34 +04:00
|
|
|
if (msix_present(&proxy->pci_dev)) {
|
2013-09-20 15:36:40 +04:00
|
|
|
qemu_get_be16s(f, &vdev->config_vector);
|
2009-07-05 17:02:34 +04:00
|
|
|
} else {
|
2013-09-20 15:36:40 +04:00
|
|
|
vdev->config_vector = VIRTIO_NO_VECTOR;
|
2009-07-05 17:02:34 +04:00
|
|
|
}
|
2013-09-20 15:36:40 +04:00
|
|
|
if (vdev->config_vector != VIRTIO_NO_VECTOR) {
|
|
|
|
return msix_vector_use(&proxy->pci_dev, vdev->config_vector);
|
2009-07-05 17:02:34 +04:00
|
|
|
}
|
2009-06-21 20:50:40 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-17 15:01:07 +04:00
|
|
|
static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f)
|
2009-06-21 20:50:40 +04:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
|
|
2009-06-21 20:50:40 +04:00
|
|
|
uint16_t vector;
|
2009-07-05 17:02:34 +04:00
|
|
|
if (msix_present(&proxy->pci_dev)) {
|
|
|
|
qemu_get_be16s(f, &vector);
|
|
|
|
} else {
|
|
|
|
vector = VIRTIO_NO_VECTOR;
|
|
|
|
}
|
2013-09-20 15:36:40 +04:00
|
|
|
virtio_queue_set_vector(vdev, n, vector);
|
2009-07-05 17:02:34 +04:00
|
|
|
if (vector != VIRTIO_NO_VECTOR) {
|
|
|
|
return msix_vector_use(&proxy->pci_dev, vector);
|
|
|
|
}
|
2009-06-21 20:50:40 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-17 15:01:50 +03:00
|
|
|
static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
|
2012-08-06 17:26:14 +04:00
|
|
|
int n, bool assign, bool set_handler)
|
2010-12-17 15:01:50 +03:00
|
|
|
{
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
|
VirtQueue *vq = virtio_get_queue(vdev, n);
|
2010-12-17 15:01:50 +03:00
|
|
|
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
|
2011-08-08 17:09:13 +04:00
|
|
|
int r = 0;
|
|
|
|
|
2010-12-17 15:01:50 +03:00
|
|
|
if (assign) {
|
|
|
|
r = event_notifier_init(notifier, 1);
|
|
|
|
if (r < 0) {
|
2011-01-11 15:10:15 +03:00
|
|
|
error_report("%s: unable to init event notifier: %d",
|
|
|
|
__func__, r);
|
2010-12-17 15:01:50 +03:00
|
|
|
return r;
|
|
|
|
}
|
2012-08-06 17:26:14 +04:00
|
|
|
virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
|
2011-08-08 17:09:13 +04:00
|
|
|
memory_region_add_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
|
2012-07-05 19:16:27 +04:00
|
|
|
true, n, notifier);
|
2010-12-17 15:01:50 +03:00
|
|
|
} else {
|
2011-08-08 17:09:13 +04:00
|
|
|
memory_region_del_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
|
2012-07-05 19:16:27 +04:00
|
|
|
true, n, notifier);
|
2012-08-06 17:26:14 +04:00
|
|
|
virtio_queue_set_host_notifier_fd_handler(vq, false, false);
|
2010-12-17 15:01:50 +03:00
|
|
|
event_notifier_cleanup(notifier);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-01-11 15:10:15 +03:00
|
|
|
static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)
|
2010-12-17 15:01:50 +03:00
|
|
|
{
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2010-12-17 15:01:50 +03:00
|
|
|
int n, r;
|
|
|
|
|
|
|
|
if (!(proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD) ||
|
|
|
|
proxy->ioeventfd_disabled ||
|
|
|
|
proxy->ioeventfd_started) {
|
2011-01-11 15:10:15 +03:00
|
|
|
return;
|
2010-12-17 15:01:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
|
2013-09-20 15:36:40 +04:00
|
|
|
if (!virtio_queue_get_num(vdev, n)) {
|
2010-12-17 15:01:50 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-06 17:26:14 +04:00
|
|
|
r = virtio_pci_set_host_notifier_internal(proxy, n, true, true);
|
2010-12-17 15:01:50 +03:00
|
|
|
if (r < 0) {
|
|
|
|
goto assign_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
proxy->ioeventfd_started = true;
|
2011-01-11 15:10:15 +03:00
|
|
|
return;
|
2010-12-17 15:01:50 +03:00
|
|
|
|
|
|
|
assign_error:
|
|
|
|
while (--n >= 0) {
|
2013-09-20 15:36:40 +04:00
|
|
|
if (!virtio_queue_get_num(vdev, n)) {
|
2010-12-17 15:01:50 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-06 17:26:14 +04:00
|
|
|
r = virtio_pci_set_host_notifier_internal(proxy, n, false, false);
|
2011-01-11 15:10:15 +03:00
|
|
|
assert(r >= 0);
|
2010-12-17 15:01:50 +03:00
|
|
|
}
|
|
|
|
proxy->ioeventfd_started = false;
|
2011-01-11 15:10:15 +03:00
|
|
|
error_report("%s: failed. Fallback to a userspace (slower).", __func__);
|
2010-12-17 15:01:50 +03:00
|
|
|
}
|
|
|
|
|
2011-01-11 15:10:15 +03:00
|
|
|
static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
|
2010-12-17 15:01:50 +03:00
|
|
|
{
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2011-01-11 15:10:15 +03:00
|
|
|
int r;
|
2010-12-17 15:01:50 +03:00
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!proxy->ioeventfd_started) {
|
2011-01-11 15:10:15 +03:00
|
|
|
return;
|
2010-12-17 15:01:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
|
2013-09-20 15:36:40 +04:00
|
|
|
if (!virtio_queue_get_num(vdev, n)) {
|
2010-12-17 15:01:50 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-06 17:26:14 +04:00
|
|
|
r = virtio_pci_set_host_notifier_internal(proxy, n, false, false);
|
2011-01-11 15:10:15 +03:00
|
|
|
assert(r >= 0);
|
2010-12-17 15:01:50 +03:00
|
|
|
}
|
|
|
|
proxy->ioeventfd_started = false;
|
|
|
|
}
|
|
|
|
|
2009-05-18 17:51:59 +04:00
|
|
|
static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pa;
|
2009-05-18 17:51:59 +04:00
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case VIRTIO_PCI_GUEST_FEATURES:
|
2013-04-24 12:21:20 +04: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 16:28:52 +04:00
|
|
|
virtio_set_features(vdev, val);
|
2009-05-18 17:51:59 +04:00
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_QUEUE_PFN:
|
2012-10-23 14:30:10 +04:00
|
|
|
pa = (hwaddr)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
|
2009-11-24 17:45:35 +03:00
|
|
|
if (pa == 0) {
|
2010-12-17 15:01:50 +03:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
2013-09-20 15:36:40 +04:00
|
|
|
virtio_reset(vdev);
|
2009-11-24 17:45:35 +03:00
|
|
|
msix_unuse_all_vectors(&proxy->pci_dev);
|
|
|
|
}
|
2009-06-21 20:50:13 +04:00
|
|
|
else
|
|
|
|
virtio_queue_set_addr(vdev, vdev->queue_sel, pa);
|
2009-05-18 17:51:59 +04:00
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_QUEUE_SEL:
|
|
|
|
if (val < VIRTIO_PCI_QUEUE_MAX)
|
|
|
|
vdev->queue_sel = val;
|
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_QUEUE_NOTIFY:
|
2011-05-09 01:29:07 +04:00
|
|
|
if (val < VIRTIO_PCI_QUEUE_MAX) {
|
|
|
|
virtio_queue_notify(vdev, val);
|
|
|
|
}
|
2009-05-18 17:51:59 +04:00
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_STATUS:
|
2010-12-17 15:01:50 +03:00
|
|
|
if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) {
|
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
|
|
|
}
|
|
|
|
|
2010-03-17 14:08:05 +03:00
|
|
|
virtio_set_status(vdev, val & 0xFF);
|
2010-12-17 15:01:50 +03:00
|
|
|
|
|
|
|
if (val & VIRTIO_CONFIG_S_DRIVER_OK) {
|
|
|
|
virtio_pci_start_ioeventfd(proxy);
|
|
|
|
}
|
|
|
|
|
2009-11-24 17:45:35 +03:00
|
|
|
if (vdev->status == 0) {
|
2013-09-20 15:36:40 +04:00
|
|
|
virtio_reset(vdev);
|
2009-11-24 17:45:35 +03:00
|
|
|
msix_unuse_all_vectors(&proxy->pci_dev);
|
|
|
|
}
|
2010-03-16 21:18:07 +03:00
|
|
|
|
2014-09-11 20:45:33 +04: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 17:51:59 +04:00
|
|
|
break;
|
2009-06-21 20:50:26 +04: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 23:44:38 +03:00
|
|
|
error_report("%s: unexpected address 0x%x value 0x%x",
|
|
|
|
__func__, addr, val);
|
2009-06-21 20:50:26 +04:00
|
|
|
break;
|
2009-05-18 17:51:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-21 20:50:26 +04:00
|
|
|
static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
|
2009-05-18 17:51:59 +04:00
|
|
|
{
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2009-05-18 17:51:59 +04:00
|
|
|
uint32_t ret = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case VIRTIO_PCI_HOST_FEATURES:
|
2010-01-10 14:52:53 +03:00
|
|
|
ret = proxy->host_features;
|
2009-05-18 17:51:59 +04:00
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_GUEST_FEATURES:
|
2010-01-10 14:52:47 +03:00
|
|
|
ret = vdev->guest_features;
|
2009-05-18 17:51:59 +04: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. */
|
|
|
|
ret = vdev->isr;
|
|
|
|
vdev->isr = 0;
|
2013-10-07 11:36:39 +04:00
|
|
|
pci_irq_deassert(&proxy->pci_dev);
|
2009-05-18 17:51:59 +04:00
|
|
|
break;
|
2009-06-21 20:50:26 +04: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 17:51:59 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-08 15:02:30 +04:00
|
|
|
static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
2009-05-18 17:51:59 +04:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2015-02-17 00:36:43 +03:00
|
|
|
uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
|
2012-10-08 15:02:30 +04:00
|
|
|
uint64_t val = 0;
|
2009-06-21 20:50:26 +04:00
|
|
|
if (addr < config) {
|
2012-10-08 15:02:30 +04:00
|
|
|
return virtio_ioport_read(proxy, addr);
|
2009-06-21 20:50:26 +04:00
|
|
|
}
|
|
|
|
addr -= config;
|
2009-05-18 17:51:59 +04:00
|
|
|
|
2012-10-08 15:02:30 +04:00
|
|
|
switch (size) {
|
|
|
|
case 1:
|
2013-09-20 15:36:40 +04:00
|
|
|
val = virtio_config_readb(vdev, addr);
|
2012-10-08 15:02:30 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-09-20 15:36:40 +04:00
|
|
|
val = virtio_config_readw(vdev, addr);
|
2014-06-24 21:38:54 +04:00
|
|
|
if (virtio_is_big_endian(vdev)) {
|
2013-01-06 22:30:17 +04:00
|
|
|
val = bswap16(val);
|
|
|
|
}
|
2012-10-08 15:02:30 +04:00
|
|
|
break;
|
|
|
|
case 4:
|
2013-09-20 15:36:40 +04:00
|
|
|
val = virtio_config_readl(vdev, addr);
|
2014-06-24 21:38:54 +04:00
|
|
|
if (virtio_is_big_endian(vdev)) {
|
2013-01-06 22:30:17 +04:00
|
|
|
val = bswap32(val);
|
|
|
|
}
|
2012-10-08 15:02:30 +04:00
|
|
|
break;
|
2012-01-10 05:35:11 +04:00
|
|
|
}
|
2012-10-08 15:02:30 +04:00
|
|
|
return val;
|
2009-05-18 17:51:59 +04:00
|
|
|
}
|
|
|
|
|
2012-10-08 15:02:30 +04:00
|
|
|
static void virtio_pci_config_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2009-05-18 17:51:59 +04:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2015-02-17 00:36:43 +03:00
|
|
|
uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2009-06-21 20:50:26 +04:00
|
|
|
if (addr < config) {
|
|
|
|
virtio_ioport_write(proxy, addr, val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr -= config;
|
2012-10-08 15:02:30 +04:00
|
|
|
/*
|
|
|
|
* Virtio-PCI is odd. Ioports are LE but config space is target native
|
|
|
|
* endian.
|
|
|
|
*/
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
2013-09-20 15:36:40 +04:00
|
|
|
virtio_config_writeb(vdev, addr, val);
|
2012-10-08 15:02:30 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-06-24 21:38:54 +04:00
|
|
|
if (virtio_is_big_endian(vdev)) {
|
2013-01-06 22:30:17 +04:00
|
|
|
val = bswap16(val);
|
|
|
|
}
|
2013-09-20 15:36:40 +04:00
|
|
|
virtio_config_writew(vdev, addr, val);
|
2012-10-08 15:02:30 +04:00
|
|
|
break;
|
|
|
|
case 4:
|
2014-06-24 21:38:54 +04:00
|
|
|
if (virtio_is_big_endian(vdev)) {
|
2013-01-06 22:30:17 +04:00
|
|
|
val = bswap32(val);
|
|
|
|
}
|
2013-09-20 15:36:40 +04:00
|
|
|
virtio_config_writel(vdev, addr, val);
|
2012-10-08 15:02:30 +04:00
|
|
|
break;
|
2012-01-10 05:35:11 +04:00
|
|
|
}
|
2009-05-18 17:51:59 +04:00
|
|
|
}
|
|
|
|
|
2011-08-08 17:09:13 +04:00
|
|
|
static const MemoryRegionOps virtio_pci_config_ops = {
|
2012-10-08 15:02:30 +04:00
|
|
|
.read = virtio_pci_config_read,
|
|
|
|
.write = virtio_pci_config_write,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
2013-01-06 22:30:17 +04:00
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-08 17:09:13 +04:00
|
|
|
};
|
2009-06-21 20:50:26 +04:00
|
|
|
|
|
|
|
static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
|
|
|
|
uint32_t val, int len)
|
|
|
|
{
|
2009-09-08 18:49:41 +04:00
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2009-09-08 18:49:41 +04:00
|
|
|
|
2011-07-27 12:08:20 +04:00
|
|
|
pci_default_write_config(pci_dev, address, val, len);
|
|
|
|
|
|
|
|
if (range_covers_byte(address, len, PCI_COMMAND) &&
|
2014-10-14 20:40:06 +04:00
|
|
|
!(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
|
2011-07-27 12:08:20 +04:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
2014-09-29 12:27:32 +04:00
|
|
|
virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
|
2009-09-08 18:49:41 +04:00
|
|
|
}
|
2009-05-18 17:51:59 +04:00
|
|
|
}
|
|
|
|
|
2012-12-17 15:01:07 +04:00
|
|
|
static unsigned virtio_pci_get_features(DeviceState *d)
|
2009-12-08 21:07:48 +03:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2010-01-10 14:52:53 +03:00
|
|
|
return proxy->host_features;
|
2009-12-08 21:07:48 +03:00
|
|
|
}
|
|
|
|
|
2012-05-17 17:32:39 +04:00
|
|
|
static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,
|
|
|
|
unsigned int queue_no,
|
|
|
|
unsigned int vector,
|
|
|
|
MSIMessage msg)
|
|
|
|
{
|
|
|
|
VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
|
2012-07-05 19:16:30 +04:00
|
|
|
int ret;
|
2012-05-17 17:32:39 +04:00
|
|
|
|
|
|
|
if (irqfd->users == 0) {
|
|
|
|
ret = kvm_irqchip_add_msi_route(kvm_state, msg);
|
|
|
|
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 02:27:54 +04:00
|
|
|
{
|
|
|
|
VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
|
|
|
|
if (--irqfd->users == 0) {
|
|
|
|
kvm_irqchip_release_virq(kvm_state, irqfd->virq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-24 19:35:27 +04: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 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
|
VirtQueue *vq = virtio_get_queue(vdev, queue_no);
|
2012-12-24 19:35:27 +04:00
|
|
|
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
|
|
|
|
int ret;
|
2013-07-22 13:51:33 +04:00
|
|
|
ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL, irqfd->virq);
|
2012-12-24 19:35:27 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy,
|
|
|
|
unsigned int queue_no,
|
|
|
|
unsigned int vector)
|
2012-05-17 17:32:39 +04:00
|
|
|
{
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
|
VirtQueue *vq = virtio_get_queue(vdev, queue_no);
|
2012-07-05 19:16:30 +04:00
|
|
|
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
|
2012-05-17 17:32:39 +04:00
|
|
|
VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
|
2012-07-05 19:16:30 +04:00
|
|
|
int ret;
|
2012-05-17 17:32:39 +04:00
|
|
|
|
2012-08-20 12:55:56 +04:00
|
|
|
ret = kvm_irqchip_remove_irqfd_notifier(kvm_state, n, irqfd->virq);
|
2012-05-17 17:32:39 +04:00
|
|
|
assert(ret == 0);
|
2012-12-24 19:35:27 +04:00
|
|
|
}
|
2012-05-17 17:32:39 +04:00
|
|
|
|
2012-12-21 02:27:54 +04:00
|
|
|
static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
|
{
|
|
|
|
PCIDevice *dev = &proxy->pci_dev;
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2013-04-24 12:21:20 +04:00
|
|
|
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
2012-12-21 02:27:54 +04:00
|
|
|
unsigned int vector;
|
|
|
|
int ret, queue_no;
|
|
|
|
MSIMessage msg;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
msg = msix_get_message(dev, vector);
|
|
|
|
ret = kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector, msg);
|
|
|
|
if (ret < 0) {
|
|
|
|
goto undo;
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
2012-12-24 19:35:27 +04:00
|
|
|
/* If guest supports masking, set up irqfd now.
|
|
|
|
* Otherwise, delay until unmasked in the frontend.
|
|
|
|
*/
|
2013-04-24 12:21:20 +04:00
|
|
|
if (k->guest_notifier_mask) {
|
2012-12-24 19:35:27 +04: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 17:32:39 +04:00
|
|
|
}
|
|
|
|
return 0;
|
2012-12-21 02:27:54 +04:00
|
|
|
|
|
|
|
undo:
|
|
|
|
while (--queue_no >= 0) {
|
|
|
|
vector = virtio_queue_vector(vdev, queue_no);
|
|
|
|
if (vector >= msix_nr_vectors_allocated(dev)) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-04-24 12:21:20 +04:00
|
|
|
if (k->guest_notifier_mask) {
|
2013-01-15 21:42:38 +04:00
|
|
|
kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
|
2012-12-24 19:35:27 +04:00
|
|
|
}
|
2012-12-21 02:27:54 +04:00
|
|
|
kvm_virtio_pci_vq_vector_release(proxy, vector);
|
|
|
|
}
|
|
|
|
return ret;
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
|
|
|
|
2012-12-21 02:27:54 +04:00
|
|
|
static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
|
{
|
|
|
|
PCIDevice *dev = &proxy->pci_dev;
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2012-12-21 02:27:54 +04:00
|
|
|
unsigned int vector;
|
|
|
|
int queue_no;
|
2013-04-24 12:21:20 +04:00
|
|
|
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
2012-12-21 02:27:54 +04: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 19:35:27 +04:00
|
|
|
/* If guest supports masking, clean up irqfd now.
|
|
|
|
* Otherwise, it was cleaned when masked in the frontend.
|
|
|
|
*/
|
2013-04-24 12:21:20 +04:00
|
|
|
if (k->guest_notifier_mask) {
|
2013-01-15 21:42:38 +04:00
|
|
|
kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
|
2012-12-24 19:35:27 +04:00
|
|
|
}
|
2012-12-21 02:27:54 +04:00
|
|
|
kvm_virtio_pci_vq_vector_release(proxy, vector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:37:08 +04:00
|
|
|
static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
|
|
|
|
unsigned int queue_no,
|
|
|
|
unsigned int vector,
|
|
|
|
MSIMessage msg)
|
2012-12-21 02:27:54 +04:00
|
|
|
{
|
2013-09-20 15:36:40 +04: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 02:27:54 +04:00
|
|
|
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
|
2013-03-13 23:37:08 +04:00
|
|
|
VirtIOIRQFD *irqfd;
|
2013-01-14 23:20:12 +04:00
|
|
|
int ret = 0;
|
2012-12-21 02:27:54 +04:00
|
|
|
|
2013-03-13 23:37:08 +04:00
|
|
|
if (proxy->vector_irqfd) {
|
|
|
|
irqfd = &proxy->vector_irqfd[vector];
|
|
|
|
if (irqfd->msg.data != msg.data || irqfd->msg.address != msg.address) {
|
|
|
|
ret = kvm_irqchip_update_msi_route(kvm_state, irqfd->virq, msg);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-21 02:27:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-24 19:35:27 +04:00
|
|
|
/* If guest supports masking, irqfd is already setup, unmask it.
|
|
|
|
* Otherwise, set it up now.
|
|
|
|
*/
|
2013-04-24 12:21:20 +04:00
|
|
|
if (k->guest_notifier_mask) {
|
2013-09-20 15:36:40 +04:00
|
|
|
k->guest_notifier_mask(vdev, queue_no, false);
|
2012-12-24 19:35:27 +04:00
|
|
|
/* Test after unmasking to avoid losing events. */
|
2013-04-24 12:21:20 +04:00
|
|
|
if (k->guest_notifier_pending &&
|
2013-09-20 15:36:40 +04:00
|
|
|
k->guest_notifier_pending(vdev, queue_no)) {
|
2012-12-24 19:35:27 +04:00
|
|
|
event_notifier_set(n);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector);
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
2012-12-21 02:27:54 +04:00
|
|
|
return ret;
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:37:08 +04:00
|
|
|
static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,
|
2012-05-17 17:32:39 +04:00
|
|
|
unsigned int queue_no,
|
|
|
|
unsigned int vector)
|
|
|
|
{
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
|
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
2013-04-24 12:21:20 +04:00
|
|
|
|
2012-12-24 19:35:27 +04:00
|
|
|
/* If guest supports masking, keep irqfd but mask it.
|
|
|
|
* Otherwise, clean it up now.
|
|
|
|
*/
|
2013-04-24 12:21:20 +04:00
|
|
|
if (k->guest_notifier_mask) {
|
2013-09-20 15:36:40 +04:00
|
|
|
k->guest_notifier_mask(vdev, queue_no, true);
|
2012-12-24 19:35:27 +04:00
|
|
|
} else {
|
2013-01-15 21:42:38 +04:00
|
|
|
kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
|
2012-12-24 19:35:27 +04:00
|
|
|
}
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:37:08 +04:00
|
|
|
static int virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector,
|
|
|
|
MSIMessage msg)
|
2012-05-17 17:32:39 +04:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2015-04-23 09:21:47 +03:00
|
|
|
VirtQueue *vq = virtio_vector_first_queue(vdev, vector);
|
|
|
|
int ret, index, unmasked = 0;
|
2012-05-17 17:32:39 +04:00
|
|
|
|
2015-04-23 09:21:47 +03:00
|
|
|
while (vq) {
|
|
|
|
index = virtio_get_queue_index(vq);
|
|
|
|
if (!virtio_queue_get_num(vdev, index)) {
|
2012-05-17 17:32:39 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-04-23 09:21:47 +03:00
|
|
|
ret = virtio_pci_vq_vector_unmask(proxy, index, vector, msg);
|
2012-05-17 17:32:39 +04:00
|
|
|
if (ret < 0) {
|
|
|
|
goto undo;
|
|
|
|
}
|
2015-04-23 09:21:47 +03:00
|
|
|
vq = virtio_vector_next_queue(vq);
|
|
|
|
++unmasked;
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
2015-04-23 09:21:47 +03:00
|
|
|
|
2012-05-17 17:32:39 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
undo:
|
2015-04-23 09:21:47 +03:00
|
|
|
vq = virtio_vector_first_queue(vdev, vector);
|
|
|
|
while (vq && --unmasked >= 0) {
|
|
|
|
index = virtio_get_queue_index(vq);
|
|
|
|
virtio_pci_vq_vector_mask(proxy, index, vector);
|
|
|
|
vq = virtio_vector_next_queue(vq);
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:37:08 +04:00
|
|
|
static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector)
|
2012-05-17 17:32:39 +04:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2015-04-23 09:21:47 +03:00
|
|
|
VirtQueue *vq = virtio_vector_first_queue(vdev, vector);
|
|
|
|
int index;
|
2012-05-17 17:32:39 +04:00
|
|
|
|
2015-04-23 09:21:47 +03:00
|
|
|
while (vq) {
|
|
|
|
index = virtio_get_queue_index(vq);
|
|
|
|
if (!virtio_queue_get_num(vdev, index)) {
|
2012-05-17 17:32:39 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-04-23 09:21:47 +03:00
|
|
|
virtio_pci_vq_vector_mask(proxy, index, vector);
|
|
|
|
vq = virtio_vector_next_queue(vq);
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:37:08 +04:00
|
|
|
static void virtio_pci_vector_poll(PCIDevice *dev,
|
|
|
|
unsigned int vector_start,
|
|
|
|
unsigned int vector_end)
|
2012-12-18 16:02:46 +04:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2013-04-24 12:21:20 +04:00
|
|
|
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
2012-12-18 16:02:46 +04:00
|
|
|
int queue_no;
|
|
|
|
unsigned int vector;
|
|
|
|
EventNotifier *notifier;
|
|
|
|
VirtQueue *vq;
|
|
|
|
|
2012-12-20 16:28:58 +04:00
|
|
|
for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) {
|
2012-12-18 16:02:46 +04: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 12:21:20 +04:00
|
|
|
if (k->guest_notifier_pending) {
|
|
|
|
if (k->guest_notifier_pending(vdev, queue_no)) {
|
2012-12-24 19:35:27 +04:00
|
|
|
msix_set_pending(dev, vector);
|
|
|
|
}
|
|
|
|
} else if (event_notifier_test_and_clear(notifier)) {
|
2012-12-18 16:02:46 +04: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 14:08:13 +03:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2013-09-20 15:36:40 +04: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 14:08:13 +03: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 16:02:46 +04:00
|
|
|
virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
|
2010-03-17 14:08:13 +03:00
|
|
|
} else {
|
2012-12-18 16:02:46 +04:00
|
|
|
virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
|
2010-03-17 14:08:13 +03:00
|
|
|
event_notifier_cleanup(notifier);
|
|
|
|
}
|
|
|
|
|
2013-05-07 16:49:58 +04:00
|
|
|
if (!msix_enabled(&proxy->pci_dev) && vdc->guest_notifier_mask) {
|
2013-09-20 15:36:40 +04:00
|
|
|
vdc->guest_notifier_mask(vdev, n, !assign);
|
2013-05-07 16:49:58 +04:00
|
|
|
}
|
|
|
|
|
2010-03-17 14:08:13 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-17 15:01:07 +04:00
|
|
|
static bool virtio_pci_query_guest_notifiers(DeviceState *d)
|
2011-02-01 23:13:42 +03:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2011-02-01 23:13:42 +03:00
|
|
|
return msix_enabled(&proxy->pci_dev);
|
|
|
|
}
|
|
|
|
|
2012-12-20 16:28:58 +04:00
|
|
|
static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign)
|
2010-10-06 17:20:17 +04:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2013-04-24 12:21:20 +04:00
|
|
|
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
2010-10-06 17:20:17 +04:00
|
|
|
int r, n;
|
2012-12-18 16:02:46 +04:00
|
|
|
bool with_irqfd = msix_enabled(&proxy->pci_dev) &&
|
|
|
|
kvm_msi_via_irqfd_enabled();
|
2010-10-06 17:20:17 +04:00
|
|
|
|
2012-12-20 16:28:58 +04:00
|
|
|
nvqs = MIN(nvqs, VIRTIO_PCI_QUEUE_MAX);
|
|
|
|
|
|
|
|
/* 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 17:32:39 +04:00
|
|
|
/* Must unset vector notifier while guest notifier is still assigned */
|
2013-04-24 12:21:20 +04:00
|
|
|
if ((proxy->vector_irqfd || k->guest_notifier_mask) && !assign) {
|
2012-05-17 17:32:39 +04:00
|
|
|
msix_unset_vector_notifiers(&proxy->pci_dev);
|
2013-03-13 23:37:08 +04:00
|
|
|
if (proxy->vector_irqfd) {
|
|
|
|
kvm_virtio_pci_vector_release(proxy, nvqs);
|
|
|
|
g_free(proxy->vector_irqfd);
|
|
|
|
proxy->vector_irqfd = NULL;
|
|
|
|
}
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
|
|
|
|
2012-12-20 16:28:58 +04:00
|
|
|
for (n = 0; n < nvqs; n++) {
|
2010-10-06 17:20:17 +04:00
|
|
|
if (!virtio_queue_get_num(vdev, n)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-01 12:03:45 +04:00
|
|
|
r = virtio_pci_set_guest_notifier(d, n, assign, with_irqfd);
|
2010-10-06 17:20:17 +04:00
|
|
|
if (r < 0) {
|
|
|
|
goto assign_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-17 17:32:39 +04:00
|
|
|
/* Must set vector notifier after guest notifier has been assigned */
|
2013-04-24 12:21:20 +04:00
|
|
|
if ((with_irqfd || k->guest_notifier_mask) && assign) {
|
2013-03-13 23:37:08 +04: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 02:27:54 +04:00
|
|
|
}
|
2012-05-17 17:32:39 +04:00
|
|
|
r = msix_set_vector_notifiers(&proxy->pci_dev,
|
2013-03-13 23:37:08 +04:00
|
|
|
virtio_pci_vector_unmask,
|
|
|
|
virtio_pci_vector_mask,
|
|
|
|
virtio_pci_vector_poll);
|
2012-05-17 17:32:39 +04:00
|
|
|
if (r < 0) {
|
2012-12-21 02:27:54 +04:00
|
|
|
goto notifiers_error;
|
2012-05-17 17:32:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-06 17:20:17 +04:00
|
|
|
return 0;
|
|
|
|
|
2012-12-21 02:27:54 +04:00
|
|
|
notifiers_error:
|
2013-03-13 23:37:08 +04:00
|
|
|
if (with_irqfd) {
|
|
|
|
assert(assign);
|
|
|
|
kvm_virtio_pci_vector_release(proxy, nvqs);
|
|
|
|
}
|
2012-12-21 02:27:54 +04:00
|
|
|
|
2010-10-06 17:20:17 +04:00
|
|
|
assign_error:
|
|
|
|
/* We get here on assignment failure. Recover by undoing for VQs 0 .. n. */
|
2012-05-17 17:32:39 +04:00
|
|
|
assert(assign);
|
2010-10-06 17:20:17 +04:00
|
|
|
while (--n >= 0) {
|
2012-12-18 16:02:46 +04:00
|
|
|
virtio_pci_set_guest_notifier(d, n, !assign, with_irqfd);
|
2010-10-06 17:20:17 +04:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-12-17 15:01:07 +04:00
|
|
|
static int virtio_pci_set_host_notifier(DeviceState *d, int n, bool assign)
|
2010-03-17 14:08:13 +03:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2010-12-17 15:01:50 +03:00
|
|
|
|
|
|
|
/* Stop using ioeventfd for virtqueue kick if the device starts using host
|
|
|
|
* notifiers. This makes it easy to avoid stepping on each others' toes.
|
|
|
|
*/
|
|
|
|
proxy->ioeventfd_disabled = assign;
|
2010-03-17 14:08:13 +03:00
|
|
|
if (assign) {
|
2010-12-17 15:01:50 +03:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
|
|
|
}
|
|
|
|
/* We don't need to start here: it's not needed because backend
|
|
|
|
* currently only stops on status change away from ok,
|
|
|
|
* reset, vmstop and such. If we do add code to start here,
|
|
|
|
* need to check vmstate, device state etc. */
|
2012-08-06 17:26:14 +04:00
|
|
|
return virtio_pci_set_host_notifier_internal(proxy, n, assign, false);
|
2010-12-17 15:01:50 +03:00
|
|
|
}
|
|
|
|
|
2012-12-17 15:01:07 +04:00
|
|
|
static void virtio_pci_vmstate_change(DeviceState *d, bool running)
|
2010-12-17 15:01:50 +03:00
|
|
|
{
|
2012-12-17 15:01:07 +04:00
|
|
|
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
|
2013-09-20 15:36:40 +04:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
2010-12-17 15:01:50 +03:00
|
|
|
|
|
|
|
if (running) {
|
2014-10-14 20:40:06 +04: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 12:27:32 +04:00
|
|
|
!(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
|
2014-10-14 20:40:06 +04:00
|
|
|
pci_default_write_config(&proxy->pci_dev, PCI_COMMAND,
|
|
|
|
proxy->pci_dev.config[PCI_COMMAND] |
|
|
|
|
PCI_COMMAND_MASTER, 1);
|
2011-03-19 20:28:19 +03:00
|
|
|
}
|
2010-12-17 15:01:50 +03:00
|
|
|
virtio_pci_start_ioeventfd(proxy);
|
2010-03-17 14:08:13 +03:00
|
|
|
} else {
|
2010-12-17 15:01:50 +03:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
2010-03-17 14:08:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 18:37:49 +04:00
|
|
|
#ifdef CONFIG_VIRTFS
|
2015-02-27 16:52:14 +03:00
|
|
|
static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
2013-02-04 18:37:49 +04:00
|
|
|
{
|
2013-04-23 13:08:41 +04:00
|
|
|
V9fsPCIState *dev = VIRTIO_9P_PCI(vpci_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2013-02-04 18:37:49 +04:00
|
|
|
|
2013-04-23 13:08:41 +04:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
|
2015-02-27 16:52:14 +03:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", errp);
|
2013-02-04 18:37:49 +04:00
|
|
|
}
|
|
|
|
|
2013-04-23 13:08:41 +04:00
|
|
|
static Property virtio_9p_pci_properties[] = {
|
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
|
|
|
|
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
|
2013-02-04 18:37:49 +04:00
|
|
|
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2013-04-23 13:08:41 +04:00
|
|
|
static void virtio_9p_pci_class_init(ObjectClass *klass, void *data)
|
2013-02-04 18:37:49 +04:00
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2013-04-23 13:08:41 +04:00
|
|
|
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
|
|
|
|
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
|
2013-02-04 18:37:49 +04:00
|
|
|
|
2015-02-27 16:52:14 +03:00
|
|
|
k->realize = virtio_9p_pci_realize;
|
2013-04-23 13:08:41 +04: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 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2013-04-23 13:08:41 +04:00
|
|
|
dc->props = virtio_9p_pci_properties;
|
2013-02-04 18:37:49 +04:00
|
|
|
}
|
|
|
|
|
2013-04-23 13:08:41 +04:00
|
|
|
static void virtio_9p_pci_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
V9fsPCIState *dev = VIRTIO_9P_PCI(obj);
|
2014-09-30 10:10:38 +04:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_9P);
|
2013-04-23 13:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_9p_pci_info = {
|
|
|
|
.name = TYPE_VIRTIO_9P_PCI,
|
|
|
|
.parent = TYPE_VIRTIO_PCI,
|
|
|
|
.instance_size = sizeof(V9fsPCIState),
|
|
|
|
.instance_init = virtio_9p_pci_instance_init,
|
|
|
|
.class_init = virtio_9p_pci_class_init,
|
2013-02-04 18:37:49 +04:00
|
|
|
};
|
2013-04-23 13:08:41 +04:00
|
|
|
#endif /* CONFIG_VIRTFS */
|
2013-02-04 18:37:49 +04:00
|
|
|
|
2013-01-15 03:08:04 +04:00
|
|
|
/*
|
|
|
|
* virtio-pci: This is the PCIDevice which has a virtio-pci-bus.
|
|
|
|
*/
|
|
|
|
|
2015-04-23 09:21:46 +03:00
|
|
|
static int virtio_pci_query_nvectors(DeviceState *d)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
|
|
|
|
|
|
|
|
return proxy->nvectors;
|
|
|
|
}
|
|
|
|
|
2013-01-15 03:08:04 +04:00
|
|
|
/* This is called by virtio-bus just after the device is plugged. */
|
|
|
|
static void virtio_pci_device_plugged(DeviceState *d)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
|
|
|
|
VirtioBusState *bus = &proxy->bus;
|
|
|
|
uint8_t *config;
|
|
|
|
uint32_t size;
|
|
|
|
|
|
|
|
config = proxy->pci_dev.config;
|
|
|
|
if (proxy->class_code) {
|
|
|
|
pci_config_set_class(config, proxy->class_code);
|
|
|
|
}
|
|
|
|
pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
|
|
|
|
pci_get_word(config + PCI_VENDOR_ID));
|
|
|
|
pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_bus_get_vdev_id(bus));
|
|
|
|
config[PCI_INTERRUPT_PIN] = 1;
|
|
|
|
|
|
|
|
if (proxy->nvectors &&
|
|
|
|
msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, 1)) {
|
2014-06-23 13:06:25 +04:00
|
|
|
error_report("unable to init msix vectors to %" PRIu32,
|
|
|
|
proxy->nvectors);
|
2013-01-15 03:08:04 +04:00
|
|
|
proxy->nvectors = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
proxy->pci_dev.config_write = virtio_write_config;
|
|
|
|
|
|
|
|
size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev)
|
|
|
|
+ virtio_bus_get_vdev_config_len(bus);
|
|
|
|
if (size & (size - 1)) {
|
|
|
|
size = 1 << qemu_fls(size);
|
|
|
|
}
|
|
|
|
|
2013-06-07 05:25:08 +04:00
|
|
|
memory_region_init_io(&proxy->bar, OBJECT(proxy), &virtio_pci_config_ops,
|
|
|
|
proxy, "virtio-pci", size);
|
2013-01-15 03:08:04 +04:00
|
|
|
pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
|
|
|
|
&proxy->bar);
|
|
|
|
|
|
|
|
if (!kvm_has_many_ioeventfds()) {
|
|
|
|
proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
|
|
|
|
}
|
|
|
|
|
2014-12-11 16:25:05 +03:00
|
|
|
virtio_add_feature(&proxy->host_features, VIRTIO_F_NOTIFY_ON_EMPTY);
|
|
|
|
virtio_add_feature(&proxy->host_features, VIRTIO_F_BAD_FEATURE);
|
2013-01-15 03:08:04 +04:00
|
|
|
proxy->host_features = virtio_bus_get_vdev_features(bus,
|
|
|
|
proxy->host_features);
|
|
|
|
}
|
|
|
|
|
2013-09-20 16:10:26 +04:00
|
|
|
static void virtio_pci_device_unplugged(DeviceState *d)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
|
|
|
|
|
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
|
|
|
}
|
|
|
|
|
2015-02-27 16:52:14 +03:00
|
|
|
static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
|
2013-01-15 03:08:04 +04:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
|
|
|
|
VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev);
|
2015-02-27 16:52:14 +03:00
|
|
|
|
2013-08-23 22:35:18 +04:00
|
|
|
virtio_pci_bus_new(&dev->bus, sizeof(dev->bus), dev);
|
2015-02-27 16:52:14 +03:00
|
|
|
if (k->realize) {
|
|
|
|
k->realize(dev, errp);
|
2013-01-15 03:08:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_pci_exit(PCIDevice *pci_dev)
|
|
|
|
{
|
2014-07-04 13:43:49 +04:00
|
|
|
msix_uninit_exclusive_bar(pci_dev);
|
2013-01-15 03:08:04 +04:00
|
|
|
}
|
|
|
|
|
2013-04-24 12:07:56 +04:00
|
|
|
static void virtio_pci_reset(DeviceState *qdev)
|
2013-01-15 03:08:04 +04:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
|
|
|
|
VirtioBusState *bus = VIRTIO_BUS(&proxy->bus);
|
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
|
|
|
virtio_bus_reset(bus);
|
|
|
|
msix_unuse_all_vectors(&proxy->pci_dev);
|
|
|
|
}
|
|
|
|
|
2014-06-30 20:01:58 +04:00
|
|
|
static Property virtio_pci_properties[] = {
|
2014-10-14 20:40:06 +04:00
|
|
|
DEFINE_PROP_BIT("virtio-pci-bus-master-bug-migration", VirtIOPCIProxy, flags,
|
|
|
|
VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT, false),
|
2014-06-30 20:01:58 +04:00
|
|
|
DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2013-01-15 03:08:04 +04:00
|
|
|
static void virtio_pci_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
|
|
|
|
2014-06-30 20:01:58 +04:00
|
|
|
dc->props = virtio_pci_properties;
|
2015-02-27 16:52:14 +03:00
|
|
|
k->realize = virtio_pci_realize;
|
2013-01-15 03:08:04 +04: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;
|
2013-04-24 12:07:56 +04:00
|
|
|
dc->reset = virtio_pci_reset;
|
2013-01-15 03:08:04 +04: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,
|
|
|
|
};
|
|
|
|
|
2013-03-18 20:37:23 +04:00
|
|
|
/* virtio-blk-pci */
|
|
|
|
|
|
|
|
static Property virtio_blk_pci_properties[] = {
|
2014-02-08 14:01:53 +04:00
|
|
|
DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
|
2013-03-18 20:37:23 +04:00
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
|
|
|
|
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
|
|
|
|
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2015-02-27 16:52:14 +03:00
|
|
|
static void virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
2013-03-18 20:37:23 +04:00
|
|
|
{
|
|
|
|
VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2015-02-27 16:52:14 +03:00
|
|
|
|
2013-03-18 20:37:23 +04:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
|
2015-02-27 16:52:14 +03:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", errp);
|
2013-03-18 20:37:23 +04: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 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2013-03-18 20:37:23 +04:00
|
|
|
dc->props = virtio_blk_pci_properties;
|
2015-02-27 16:52:14 +03:00
|
|
|
k->realize = virtio_blk_pci_realize;
|
2013-03-18 20:37:23 +04: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 10:10:38 +04:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_BLK);
|
2014-06-10 11:03:20 +04:00
|
|
|
object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread",
|
|
|
|
&error_abort);
|
2014-10-07 12:00:32 +04:00
|
|
|
object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
|
|
|
|
"bootindex", &error_abort);
|
2013-03-18 20:37:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_blk_pci_info = {
|
|
|
|
.name = TYPE_VIRTIO_BLK_PCI,
|
|
|
|
.parent = TYPE_VIRTIO_PCI,
|
|
|
|
.instance_size = sizeof(VirtIOBlkPCI),
|
|
|
|
.instance_init = virtio_blk_pci_instance_init,
|
|
|
|
.class_init = virtio_blk_pci_class_init,
|
|
|
|
};
|
|
|
|
|
2013-03-21 18:15:15 +04: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 16:52:14 +03:00
|
|
|
static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
2013-03-21 18:15:15 +04:00
|
|
|
{
|
|
|
|
VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(vpci_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2013-03-29 05:08:15 +04:00
|
|
|
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
|
2013-04-30 18:08:51 +04:00
|
|
|
DeviceState *proxy = DEVICE(vpci_dev);
|
|
|
|
char *bus_name;
|
2013-03-21 18:15:15 +04:00
|
|
|
|
|
|
|
if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
|
2013-03-29 05:08:15 +04:00
|
|
|
vpci_dev->nvectors = vs->conf.num_queues + 3;
|
2013-03-21 18:15:15 +04:00
|
|
|
}
|
|
|
|
|
2013-04-30 18:08:51 +04: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 18:15:15 +04:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
|
2015-02-27 16:52:14 +03:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", errp);
|
2013-03-21 18:15:15 +04: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 16:52:14 +03:00
|
|
|
|
|
|
|
k->realize = virtio_scsi_pci_realize;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2013-03-21 18:15:15 +04: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 10:10:38 +04:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_SCSI);
|
2014-08-06 09:35:06 +04:00
|
|
|
object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev), "iothread",
|
|
|
|
&error_abort);
|
2013-03-21 18:15:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_scsi_pci_info = {
|
|
|
|
.name = TYPE_VIRTIO_SCSI_PCI,
|
|
|
|
.parent = TYPE_VIRTIO_PCI,
|
|
|
|
.instance_size = sizeof(VirtIOSCSIPCI),
|
|
|
|
.instance_init = virtio_scsi_pci_instance_init,
|
|
|
|
.class_init = virtio_scsi_pci_class_init,
|
|
|
|
};
|
|
|
|
|
2013-03-29 05:08:16 +04: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 16:52:14 +03:00
|
|
|
static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
2013-03-29 05:08:16 +04: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 16:52:14 +03:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", errp);
|
2013-03-29 05:08:16 +04: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 16:52:14 +03:00
|
|
|
k->realize = vhost_scsi_pci_realize;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2013-03-29 05:08:16 +04: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 10:10:38 +04:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VHOST_SCSI);
|
2015-01-29 10:08:52 +03:00
|
|
|
object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
|
|
|
|
"bootindex", &error_abort);
|
2013-03-29 05:08:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo vhost_scsi_pci_info = {
|
|
|
|
.name = TYPE_VHOST_SCSI_PCI,
|
|
|
|
.parent = TYPE_VIRTIO_PCI,
|
|
|
|
.instance_size = sizeof(VHostSCSIPCI),
|
|
|
|
.instance_init = vhost_scsi_pci_instance_init,
|
|
|
|
.class_init = vhost_scsi_pci_class_init,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-03-27 13:49:11 +04:00
|
|
|
/* virtio-balloon-pci */
|
|
|
|
|
2013-04-14 16:07:00 +04:00
|
|
|
static void balloon_pci_stats_get_all(Object *obj, struct Visitor *v,
|
|
|
|
void *opaque, const char *name,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
VirtIOBalloonPCI *dev = opaque;
|
|
|
|
object_property_get(OBJECT(&dev->vdev), v, "guest-stats", errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void balloon_pci_stats_get_poll_interval(Object *obj, struct Visitor *v,
|
|
|
|
void *opaque, const char *name,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
VirtIOBalloonPCI *dev = opaque;
|
|
|
|
object_property_get(OBJECT(&dev->vdev), v, "guest-stats-polling-interval",
|
|
|
|
errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void balloon_pci_stats_set_poll_interval(Object *obj, struct Visitor *v,
|
|
|
|
void *opaque, const char *name,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
VirtIOBalloonPCI *dev = opaque;
|
|
|
|
object_property_set(OBJECT(&dev->vdev), v, "guest-stats-polling-interval",
|
|
|
|
errp);
|
|
|
|
}
|
|
|
|
|
2013-03-27 13:49:11 +04:00
|
|
|
static Property virtio_balloon_pci_properties[] = {
|
2014-02-08 14:01:53 +04:00
|
|
|
DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
|
2013-03-27 13:49:11 +04:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2015-02-27 16:52:14 +03:00
|
|
|
static void virtio_balloon_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
2013-03-27 13:49:11 +04: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 16:52:14 +03:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", errp);
|
2013-03-27 13:49:11 +04: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 16:52:14 +03:00
|
|
|
k->realize = virtio_balloon_pci_realize;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
2013-03-27 13:49:11 +04: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-01-29 17:24:41 +03:00
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_BALLOON);
|
2013-04-14 16:07:00 +04:00
|
|
|
object_property_add(obj, "guest-stats", "guest statistics",
|
|
|
|
balloon_pci_stats_get_all, NULL, NULL, dev,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
object_property_add(obj, "guest-stats-polling-interval", "int",
|
|
|
|
balloon_pci_stats_get_poll_interval,
|
|
|
|
balloon_pci_stats_set_poll_interval,
|
|
|
|
NULL, dev, NULL);
|
2013-03-27 13:49:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_balloon_pci_info = {
|
|
|
|
.name = TYPE_VIRTIO_BALLOON_PCI,
|
|
|
|
.parent = TYPE_VIRTIO_PCI,
|
|
|
|
.instance_size = sizeof(VirtIOBalloonPCI),
|
|
|
|
.instance_init = virtio_balloon_pci_instance_init,
|
|
|
|
.class_init = virtio_balloon_pci_class_init,
|
|
|
|
};
|
|
|
|
|
2013-04-09 16:53:31 +04:00
|
|
|
/* virtio-serial-pci */
|
|
|
|
|
2015-02-27 16:52:14 +03:00
|
|
|
static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
2013-04-09 16:53:31 +04:00
|
|
|
{
|
|
|
|
VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(vpci_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2013-04-30 18:08:50 +04:00
|
|
|
DeviceState *proxy = DEVICE(vpci_dev);
|
|
|
|
char *bus_name;
|
2013-04-09 16:53:31 +04: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 18:08:50 +04: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 16:53:31 +04:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
|
2015-02-27 16:52:14 +03:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", errp);
|
2013-04-09 16:53:31 +04: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 14:01:53 +04:00
|
|
|
DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
|
2013-04-09 16:53:31 +04: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 16:52:14 +03:00
|
|
|
k->realize = virtio_serial_pci_realize;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
|
2013-04-09 16:53:31 +04: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 10:10:38 +04:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_SERIAL);
|
2013-04-09 16:53:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_serial_pci_info = {
|
|
|
|
.name = TYPE_VIRTIO_SERIAL_PCI,
|
|
|
|
.parent = TYPE_VIRTIO_PCI,
|
|
|
|
.instance_size = sizeof(VirtIOSerialPCI),
|
|
|
|
.instance_init = virtio_serial_pci_instance_init,
|
|
|
|
.class_init = virtio_serial_pci_class_init,
|
|
|
|
};
|
|
|
|
|
2013-04-11 18:29:58 +04:00
|
|
|
/* virtio-net-pci */
|
|
|
|
|
|
|
|
static Property virtio_net_properties[] = {
|
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
|
|
|
|
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
|
|
|
|
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2015-02-27 16:52:14 +03:00
|
|
|
static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
2013-04-11 18:29:58 +04:00
|
|
|
{
|
2013-05-15 16:12:50 +04:00
|
|
|
DeviceState *qdev = DEVICE(vpci_dev);
|
2013-04-11 18:29:58 +04:00
|
|
|
VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
|
|
|
|
2013-05-15 16:12:50 +04:00
|
|
|
virtio_net_set_netclient_name(&dev->vdev, qdev->id,
|
|
|
|
object_get_typename(OBJECT(qdev)));
|
2013-04-11 18:29:58 +04:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
|
2015-02-27 16:52:14 +03:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", errp);
|
2013-04-11 18:29:58 +04: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 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
|
2013-04-11 18:29:58 +04:00
|
|
|
dc->props = virtio_net_properties;
|
2015-02-27 16:52:14 +03:00
|
|
|
vpciklass->realize = virtio_net_pci_realize;
|
2013-04-11 18:29:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_net_pci_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
VirtIONetPCI *dev = VIRTIO_NET_PCI(obj);
|
2014-09-30 10:10:38 +04:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_NET);
|
2014-10-07 12:00:22 +04:00
|
|
|
object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
|
|
|
|
"bootindex", &error_abort);
|
2013-04-11 18:29:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_net_pci_info = {
|
|
|
|
.name = TYPE_VIRTIO_NET_PCI,
|
|
|
|
.parent = TYPE_VIRTIO_PCI,
|
|
|
|
.instance_size = sizeof(VirtIONetPCI),
|
|
|
|
.instance_init = virtio_net_pci_instance_init,
|
|
|
|
.class_init = virtio_net_pci_class_init,
|
|
|
|
};
|
|
|
|
|
2013-04-24 12:07:56 +04:00
|
|
|
/* virtio-rng-pci */
|
|
|
|
|
|
|
|
static Property virtio_rng_pci_properties[] = {
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2015-02-27 16:52:14 +03:00
|
|
|
static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
|
2013-04-24 12:07:56 +04:00
|
|
|
{
|
|
|
|
VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&vrng->vdev);
|
2015-02-27 16:52:14 +03:00
|
|
|
Error *err = NULL;
|
2013-04-24 12:07:56 +04:00
|
|
|
|
|
|
|
qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
|
2015-02-27 16:52:14 +03:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2013-04-24 12:07:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
object_property_set_link(OBJECT(vrng),
|
2013-05-31 22:12:48 +04:00
|
|
|
OBJECT(vrng->vdev.conf.rng), "rng",
|
2013-04-24 12:07:56 +04: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 16:52:14 +03:00
|
|
|
k->realize = virtio_rng_pci_realize;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
2013-04-24 12:07:56 +04:00
|
|
|
dc->props = virtio_rng_pci_properties;
|
|
|
|
|
|
|
|
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 10:10:38 +04:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_RNG);
|
2014-10-29 13:17:19 +03:00
|
|
|
object_property_add_alias(obj, "rng", OBJECT(&dev->vdev), "rng",
|
|
|
|
&error_abort);
|
2013-04-24 12:07:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_rng_pci_info = {
|
|
|
|
.name = TYPE_VIRTIO_RNG_PCI,
|
|
|
|
.parent = TYPE_VIRTIO_PCI,
|
|
|
|
.instance_size = sizeof(VirtIORngPCI),
|
|
|
|
.instance_init = virtio_rng_initfn,
|
|
|
|
.class_init = virtio_rng_pci_class_init,
|
|
|
|
};
|
|
|
|
|
2013-01-15 03:08:03 +04:00
|
|
|
/* virtio-pci-bus */
|
|
|
|
|
2013-08-23 22:35:18 +04:00
|
|
|
static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
|
|
|
|
VirtIOPCIProxy *dev)
|
2013-01-15 03:08:03 +04:00
|
|
|
{
|
|
|
|
DeviceState *qdev = DEVICE(dev);
|
2013-04-30 18:08:47 +04:00
|
|
|
char virtio_bus_name[] = "virtio-bus";
|
|
|
|
|
2013-08-24 02:02:27 +04:00
|
|
|
qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_PCI_BUS, qdev,
|
2013-04-30 18:08:47 +04:00
|
|
|
virtio_bus_name);
|
2013-01-15 03:08:03 +04: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;
|
|
|
|
k->get_features = virtio_pci_get_features;
|
|
|
|
k->query_guest_notifiers = virtio_pci_query_guest_notifiers;
|
|
|
|
k->set_host_notifier = virtio_pci_set_host_notifier;
|
|
|
|
k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
|
|
|
|
k->vmstate_change = virtio_pci_vmstate_change;
|
2013-01-15 03:08:04 +04:00
|
|
|
k->device_plugged = virtio_pci_device_plugged;
|
2013-09-20 16:10:26 +04:00
|
|
|
k->device_unplugged = virtio_pci_device_unplugged;
|
2015-04-23 09:21:46 +03:00
|
|
|
k->query_nvectors = virtio_pci_query_nvectors;
|
2013-01-15 03:08:03 +04: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 18:20:55 +04:00
|
|
|
static void virtio_pci_register_types(void)
|
2009-05-18 17:51:59 +04:00
|
|
|
{
|
2013-04-24 12:07:56 +04:00
|
|
|
type_register_static(&virtio_rng_pci_info);
|
2013-01-15 03:08:03 +04:00
|
|
|
type_register_static(&virtio_pci_bus_info);
|
2013-01-15 03:08:04 +04:00
|
|
|
type_register_static(&virtio_pci_info);
|
2013-02-04 18:37:49 +04:00
|
|
|
#ifdef CONFIG_VIRTFS
|
2013-04-23 13:08:41 +04:00
|
|
|
type_register_static(&virtio_9p_pci_info);
|
2013-02-04 18:37:49 +04:00
|
|
|
#endif
|
2013-03-18 20:37:23 +04:00
|
|
|
type_register_static(&virtio_blk_pci_info);
|
2013-03-21 18:15:15 +04:00
|
|
|
type_register_static(&virtio_scsi_pci_info);
|
2013-03-27 13:49:11 +04:00
|
|
|
type_register_static(&virtio_balloon_pci_info);
|
2013-04-09 16:53:31 +04:00
|
|
|
type_register_static(&virtio_serial_pci_info);
|
2013-04-11 18:29:58 +04:00
|
|
|
type_register_static(&virtio_net_pci_info);
|
2013-03-29 05:08:16 +04:00
|
|
|
#ifdef CONFIG_VHOST_SCSI
|
|
|
|
type_register_static(&vhost_scsi_pci_info);
|
|
|
|
#endif
|
2009-05-18 17:51:59 +04:00
|
|
|
}
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
type_init(virtio_pci_register_types)
|