2009-05-18 15:51:59 +02: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include "virtio.h"
|
2010-01-10 12:52:53 +01:00
|
|
|
#include "virtio-blk.h"
|
|
|
|
#include "virtio-net.h"
|
2009-05-18 15:51:59 +02:00
|
|
|
#include "pci.h"
|
2010-02-18 16:24:31 +01:00
|
|
|
#include "qemu-error.h"
|
2009-06-21 18:50:26 +02:00
|
|
|
#include "msix.h"
|
2009-07-15 13:48:25 +02:00
|
|
|
#include "net.h"
|
2009-10-21 15:25:35 +02:00
|
|
|
#include "loader.h"
|
2010-03-17 12:08:13 +01:00
|
|
|
#include "kvm.h"
|
2010-08-24 17:22:24 +02:00
|
|
|
#include "blockdev.h"
|
2009-05-18 15:51:59 +02:00
|
|
|
|
|
|
|
/* from Linux's linux/virtio_pci.h */
|
|
|
|
|
|
|
|
/* A 32-bit r/o bitmask of the features supported by the host */
|
|
|
|
#define VIRTIO_PCI_HOST_FEATURES 0
|
|
|
|
|
|
|
|
/* A 32-bit r/w bitmask of features activated by the guest */
|
|
|
|
#define VIRTIO_PCI_GUEST_FEATURES 4
|
|
|
|
|
|
|
|
/* A 32-bit r/w PFN for the currently selected queue */
|
|
|
|
#define VIRTIO_PCI_QUEUE_PFN 8
|
|
|
|
|
|
|
|
/* A 16-bit r/o queue size for the currently selected queue */
|
|
|
|
#define VIRTIO_PCI_QUEUE_NUM 12
|
|
|
|
|
|
|
|
/* A 16-bit r/w queue selector */
|
|
|
|
#define VIRTIO_PCI_QUEUE_SEL 14
|
|
|
|
|
|
|
|
/* A 16-bit r/w queue notifier */
|
|
|
|
#define VIRTIO_PCI_QUEUE_NOTIFY 16
|
|
|
|
|
|
|
|
/* An 8-bit device status register. */
|
|
|
|
#define VIRTIO_PCI_STATUS 18
|
|
|
|
|
|
|
|
/* An 8-bit r/o interrupt status register. Reading the value will return the
|
|
|
|
* current contents of the ISR and will also clear it. This is effectively
|
|
|
|
* a read-and-acknowledge. */
|
|
|
|
#define VIRTIO_PCI_ISR 19
|
|
|
|
|
2009-06-21 18:50:26 +02:00
|
|
|
/* MSI-X registers: only enabled if MSI-X is enabled. */
|
|
|
|
/* A 16-bit vector for configuration changes. */
|
|
|
|
#define VIRTIO_MSI_CONFIG_VECTOR 20
|
|
|
|
/* A 16-bit vector for selected queue notifications. */
|
|
|
|
#define VIRTIO_MSI_QUEUE_VECTOR 22
|
|
|
|
|
|
|
|
/* Config space size */
|
|
|
|
#define VIRTIO_PCI_CONFIG_NOMSI 20
|
|
|
|
#define VIRTIO_PCI_CONFIG_MSI 24
|
|
|
|
#define VIRTIO_PCI_REGION_SIZE(dev) (msix_present(dev) ? \
|
|
|
|
VIRTIO_PCI_CONFIG_MSI : \
|
|
|
|
VIRTIO_PCI_CONFIG_NOMSI)
|
|
|
|
|
|
|
|
/* The remaining space is defined by each driver as the per-driver
|
|
|
|
* configuration space */
|
|
|
|
#define VIRTIO_PCI_CONFIG(dev) (msix_enabled(dev) ? \
|
|
|
|
VIRTIO_PCI_CONFIG_MSI : \
|
|
|
|
VIRTIO_PCI_CONFIG_NOMSI)
|
2009-05-18 15:51:59 +02:00
|
|
|
|
|
|
|
/* Virtio ABI version, if we increment this, we break the guest driver. */
|
|
|
|
#define VIRTIO_PCI_ABI_VERSION 0
|
|
|
|
|
|
|
|
/* How many bits to shift physical queue address written to QUEUE_PFN.
|
|
|
|
* 12 is historical, and due to x86 page size. */
|
|
|
|
#define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
|
|
|
|
|
2010-12-17 13:01:49 +01:00
|
|
|
/* Flags track per-device state like workarounds for quirks in older guests. */
|
|
|
|
#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG (1 << 0)
|
2010-03-16 19:18:07 +01:00
|
|
|
|
2010-12-17 13:01:50 +01:00
|
|
|
/* Performance improves when virtqueue kick processing is decoupled from the
|
|
|
|
* vcpu thread using ioeventfd for some devices. */
|
|
|
|
#define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
|
|
|
|
#define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
|
|
|
|
|
2009-05-18 15:51:59 +02:00
|
|
|
/* QEMU doesn't strictly need write barriers since everything runs in
|
|
|
|
* lock-step. We'll leave the calls to wmb() in though to make it obvious for
|
|
|
|
* KVM or if kqemu gets SMP support.
|
|
|
|
*/
|
|
|
|
#define wmb() do { } while (0)
|
|
|
|
|
|
|
|
/* PCI bindings. */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PCIDevice pci_dev;
|
|
|
|
VirtIODevice *vdev;
|
2010-12-17 13:01:49 +01:00
|
|
|
uint32_t flags;
|
2009-05-18 15:51:59 +02:00
|
|
|
uint32_t addr;
|
2009-07-15 13:48:23 +02:00
|
|
|
uint32_t class_code;
|
2009-07-15 13:48:25 +02:00
|
|
|
uint32_t nvectors;
|
block: add topology qdev properties
Add three new qdev properties to export block topology information to
the guest. This is needed to get optimal I/O alignment for RAID arrays
or SSDs.
The options are:
- physical_block_size to specify the physical block size of the device,
this is going to increase from 512 bytes to 4096 kilobytes for many
modern storage devices
- min_io_size to specify the minimal I/O size without performance impact,
this is typically set to the RAID chunk size for arrays.
- opt_io_size to specify the optimal sustained I/O size, this is
typically the RAID stripe width for arrays.
I decided to not auto-probe these values from blkid which might easily
be possible as I don't know how to deal with these issues on migration.
Note that we specificly only set the physical_block_size, and not the
logial one which is the unit all I/O is described in. The reason for
that is that IDE does not support increasing the logical block size and
at last for now I want to stick to one meachnisms in queue and allow
for easy switching of transports for a given backing image which would
not be possible if scsi and virtio use real 4k sectors, while ide only
uses the physical block exponent.
To make this more common for the different block drivers introduce a
new BlockConf structure holding all common block properties and a
DEFINE_BLOCK_PROPERTIES macro to add them all together, mirroring
what is done for network drivers. Also switch over all block drivers
to use it, except for the floppy driver which has weird driveA/driveB
properties and probably won't require any advanced block options ever.
Example usage for a virtio device with 4k physical block size and
8k optimal I/O size:
-drive file=scratch.img,media=disk,cache=none,id=scratch \
-device virtio-blk-pci,drive=scratch,physical_block_size=4096,opt_io_size=8192
aliguori: updated patch to take into account BLOCK events
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 23:37:09 +01:00
|
|
|
BlockConf block;
|
2009-10-21 15:25:35 +02:00
|
|
|
NICConf nic;
|
2010-01-10 12:52:53 +01:00
|
|
|
uint32_t host_features;
|
2010-04-29 14:14:44 +02:00
|
|
|
#ifdef CONFIG_LINUX
|
|
|
|
V9fsConf fsconf;
|
|
|
|
#endif
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
/* Max. number of ports we can have for a the virtio-serial device */
|
|
|
|
uint32_t max_virtserial_ports;
|
2010-09-02 17:00:50 +02:00
|
|
|
virtio_net_conf net;
|
2010-12-17 13:01:50 +01:00
|
|
|
bool ioeventfd_disabled;
|
|
|
|
bool ioeventfd_started;
|
2009-05-18 15:51:59 +02:00
|
|
|
} VirtIOPCIProxy;
|
|
|
|
|
|
|
|
/* virtio device */
|
|
|
|
|
2009-06-21 18:50:13 +02:00
|
|
|
static void virtio_pci_notify(void *opaque, uint16_t vector)
|
2009-05-18 15:51:59 +02:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2009-06-21 18:50:26 +02:00
|
|
|
if (msix_enabled(&proxy->pci_dev))
|
|
|
|
msix_notify(&proxy->pci_dev, vector);
|
|
|
|
else
|
|
|
|
qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
|
2009-05-18 15:51:59 +02:00
|
|
|
}
|
|
|
|
|
2009-06-21 18:50:40 +02:00
|
|
|
static void virtio_pci_save_config(void * opaque, QEMUFile *f)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
pci_device_save(&proxy->pci_dev, f);
|
|
|
|
msix_save(&proxy->pci_dev, f);
|
|
|
|
if (msix_present(&proxy->pci_dev))
|
|
|
|
qemu_put_be16(f, proxy->vdev->config_vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
if (msix_present(&proxy->pci_dev))
|
|
|
|
qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_pci_load_config(void * opaque, QEMUFile *f)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
int ret;
|
|
|
|
ret = pci_device_load(&proxy->pci_dev, f);
|
2009-07-05 15:02:34 +02:00
|
|
|
if (ret) {
|
2009-06-21 18:50:40 +02:00
|
|
|
return ret;
|
2009-07-05 15:02:34 +02:00
|
|
|
}
|
2009-06-21 18:50:40 +02:00
|
|
|
msix_load(&proxy->pci_dev, f);
|
2009-07-05 15:02:34 +02:00
|
|
|
if (msix_present(&proxy->pci_dev)) {
|
2009-06-21 18:50:40 +02:00
|
|
|
qemu_get_be16s(f, &proxy->vdev->config_vector);
|
2009-07-05 15:02:34 +02:00
|
|
|
} else {
|
|
|
|
proxy->vdev->config_vector = VIRTIO_NO_VECTOR;
|
|
|
|
}
|
|
|
|
if (proxy->vdev->config_vector != VIRTIO_NO_VECTOR) {
|
|
|
|
return msix_vector_use(&proxy->pci_dev, proxy->vdev->config_vector);
|
|
|
|
}
|
2010-03-16 19:18:07 +01:00
|
|
|
|
|
|
|
/* Try to find out if the guest has bus master disabled, but is
|
|
|
|
in ready state. Then we have a buggy guest OS. */
|
2010-06-17 17:15:02 +02:00
|
|
|
if ((proxy->vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
|
2010-03-16 19:18:07 +01:00
|
|
|
!(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
|
2010-12-17 13:01:49 +01:00
|
|
|
proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
|
2010-03-16 19:18:07 +01:00
|
|
|
}
|
2009-06-21 18:50:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
uint16_t vector;
|
2009-07-05 15:02:34 +02:00
|
|
|
if (msix_present(&proxy->pci_dev)) {
|
|
|
|
qemu_get_be16s(f, &vector);
|
|
|
|
} else {
|
|
|
|
vector = VIRTIO_NO_VECTOR;
|
|
|
|
}
|
2009-06-21 18:50:40 +02:00
|
|
|
virtio_queue_set_vector(proxy->vdev, n, vector);
|
2009-07-05 15:02:34 +02:00
|
|
|
if (vector != VIRTIO_NO_VECTOR) {
|
|
|
|
return msix_vector_use(&proxy->pci_dev, vector);
|
|
|
|
}
|
2009-06-21 18:50:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-17 13:01:50 +01:00
|
|
|
static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
|
|
|
|
int n, bool assign)
|
|
|
|
{
|
|
|
|
VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
|
|
|
|
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
|
|
|
|
int r;
|
|
|
|
if (assign) {
|
|
|
|
r = event_notifier_init(notifier, 1);
|
|
|
|
if (r < 0) {
|
2011-01-11 13:10:15 +01:00
|
|
|
error_report("%s: unable to init event notifier: %d",
|
|
|
|
__func__, r);
|
2010-12-17 13:01:50 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
r = kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier),
|
|
|
|
proxy->addr + VIRTIO_PCI_QUEUE_NOTIFY,
|
|
|
|
n, assign);
|
|
|
|
if (r < 0) {
|
2011-01-11 13:10:15 +01:00
|
|
|
error_report("%s: unable to map ioeventfd: %d",
|
|
|
|
__func__, r);
|
2010-12-17 13:01:50 +01:00
|
|
|
event_notifier_cleanup(notifier);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r = kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier),
|
|
|
|
proxy->addr + VIRTIO_PCI_QUEUE_NOTIFY,
|
|
|
|
n, assign);
|
|
|
|
if (r < 0) {
|
2011-01-11 13:10:15 +01:00
|
|
|
error_report("%s: unable to unmap ioeventfd: %d",
|
|
|
|
__func__, r);
|
2010-12-17 13:01:50 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle the race condition where the guest kicked and we deassigned
|
|
|
|
* before we got around to handling the kick.
|
|
|
|
*/
|
|
|
|
if (event_notifier_test_and_clear(notifier)) {
|
|
|
|
virtio_queue_notify_vq(vq);
|
|
|
|
}
|
|
|
|
|
|
|
|
event_notifier_cleanup(notifier);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_pci_host_notifier_read(void *opaque)
|
|
|
|
{
|
|
|
|
VirtQueue *vq = opaque;
|
|
|
|
EventNotifier *n = virtio_queue_get_host_notifier(vq);
|
|
|
|
if (event_notifier_test_and_clear(n)) {
|
|
|
|
virtio_queue_notify_vq(vq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_pci_set_host_notifier_fd_handler(VirtIOPCIProxy *proxy,
|
|
|
|
int n, bool assign)
|
|
|
|
{
|
|
|
|
VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
|
|
|
|
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
|
|
|
|
if (assign) {
|
|
|
|
qemu_set_fd_handler(event_notifier_get_fd(notifier),
|
|
|
|
virtio_pci_host_notifier_read, NULL, vq);
|
|
|
|
} else {
|
|
|
|
qemu_set_fd_handler(event_notifier_get_fd(notifier),
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-11 13:10:15 +01:00
|
|
|
static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)
|
2010-12-17 13:01:50 +01:00
|
|
|
{
|
|
|
|
int n, r;
|
|
|
|
|
|
|
|
if (!(proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD) ||
|
|
|
|
proxy->ioeventfd_disabled ||
|
|
|
|
proxy->ioeventfd_started) {
|
2011-01-11 13:10:15 +01:00
|
|
|
return;
|
2010-12-17 13:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
|
|
|
|
if (!virtio_queue_get_num(proxy->vdev, n)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = virtio_pci_set_host_notifier_internal(proxy, n, true);
|
|
|
|
if (r < 0) {
|
|
|
|
goto assign_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtio_pci_set_host_notifier_fd_handler(proxy, n, true);
|
|
|
|
}
|
|
|
|
proxy->ioeventfd_started = true;
|
2011-01-11 13:10:15 +01:00
|
|
|
return;
|
2010-12-17 13:01:50 +01:00
|
|
|
|
|
|
|
assign_error:
|
|
|
|
while (--n >= 0) {
|
|
|
|
if (!virtio_queue_get_num(proxy->vdev, n)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtio_pci_set_host_notifier_fd_handler(proxy, n, false);
|
2011-01-11 13:10:15 +01:00
|
|
|
r = virtio_pci_set_host_notifier_internal(proxy, n, false);
|
|
|
|
assert(r >= 0);
|
2010-12-17 13:01:50 +01:00
|
|
|
}
|
|
|
|
proxy->ioeventfd_started = false;
|
2011-01-11 13:10:15 +01:00
|
|
|
error_report("%s: failed. Fallback to a userspace (slower).", __func__);
|
2010-12-17 13:01:50 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 13:10:15 +01:00
|
|
|
static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
|
2010-12-17 13:01:50 +01:00
|
|
|
{
|
2011-01-11 13:10:15 +01:00
|
|
|
int r;
|
2010-12-17 13:01:50 +01:00
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!proxy->ioeventfd_started) {
|
2011-01-11 13:10:15 +01:00
|
|
|
return;
|
2010-12-17 13:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
|
|
|
|
if (!virtio_queue_get_num(proxy->vdev, n)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtio_pci_set_host_notifier_fd_handler(proxy, n, false);
|
2011-01-11 13:10:15 +01:00
|
|
|
r = virtio_pci_set_host_notifier_internal(proxy, n, false);
|
|
|
|
assert(r >= 0);
|
2010-12-17 13:01:50 +01:00
|
|
|
}
|
|
|
|
proxy->ioeventfd_started = false;
|
|
|
|
}
|
|
|
|
|
2009-09-16 12:40:37 +02:00
|
|
|
static void virtio_pci_reset(DeviceState *d)
|
2009-06-21 18:50:13 +02:00
|
|
|
{
|
2009-09-16 12:40:37 +02:00
|
|
|
VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev);
|
2010-12-17 13:01:50 +01:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
2009-06-21 18:50:13 +02:00
|
|
|
virtio_reset(proxy->vdev);
|
2009-06-21 18:50:26 +02:00
|
|
|
msix_reset(&proxy->pci_dev);
|
2010-12-17 13:01:50 +01:00
|
|
|
proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
|
2009-06-21 18:50:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-18 15:51:59 +02:00
|
|
|
static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
VirtIODevice *vdev = proxy->vdev;
|
2009-10-01 23:12:16 +02:00
|
|
|
target_phys_addr_t pa;
|
2009-05-18 15:51:59 +02:00
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case VIRTIO_PCI_GUEST_FEATURES:
|
|
|
|
/* Guest does not negotiate properly? We have to assume nothing. */
|
|
|
|
if (val & (1 << VIRTIO_F_BAD_FEATURE)) {
|
|
|
|
if (vdev->bad_features)
|
2010-01-10 12:52:53 +01:00
|
|
|
val = proxy->host_features & vdev->bad_features(vdev);
|
2009-05-18 15:51:59 +02:00
|
|
|
else
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
if (vdev->set_features)
|
|
|
|
vdev->set_features(vdev, val);
|
2010-01-10 12:52:47 +01:00
|
|
|
vdev->guest_features = val;
|
2009-05-18 15:51:59 +02:00
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_QUEUE_PFN:
|
2009-10-01 23:12:16 +02:00
|
|
|
pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
|
2009-11-24 15:45:35 +01:00
|
|
|
if (pa == 0) {
|
2010-12-17 13:01:50 +01:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
2009-11-24 15:45:35 +01:00
|
|
|
virtio_reset(proxy->vdev);
|
|
|
|
msix_unuse_all_vectors(&proxy->pci_dev);
|
|
|
|
}
|
2009-06-21 18:50:13 +02:00
|
|
|
else
|
|
|
|
virtio_queue_set_addr(vdev, vdev->queue_sel, pa);
|
2009-05-18 15:51:59 +02:00
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_QUEUE_SEL:
|
|
|
|
if (val < VIRTIO_PCI_QUEUE_MAX)
|
|
|
|
vdev->queue_sel = val;
|
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_QUEUE_NOTIFY:
|
|
|
|
virtio_queue_notify(vdev, val);
|
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_STATUS:
|
2010-12-17 13:01:50 +01:00
|
|
|
if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) {
|
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
|
|
|
}
|
|
|
|
|
2010-03-17 12:08:05 +01:00
|
|
|
virtio_set_status(vdev, val & 0xFF);
|
2010-12-17 13:01:50 +01:00
|
|
|
|
|
|
|
if (val & VIRTIO_CONFIG_S_DRIVER_OK) {
|
|
|
|
virtio_pci_start_ioeventfd(proxy);
|
|
|
|
}
|
|
|
|
|
2009-11-24 15:45:35 +01:00
|
|
|
if (vdev->status == 0) {
|
|
|
|
virtio_reset(proxy->vdev);
|
|
|
|
msix_unuse_all_vectors(&proxy->pci_dev);
|
|
|
|
}
|
2010-03-16 19:18:07 +01:00
|
|
|
|
|
|
|
/* Linux before 2.6.34 sets the device as OK without enabling
|
|
|
|
the PCI device bus master bit. In this case we need to disable
|
|
|
|
some safety checks. */
|
|
|
|
if ((val & VIRTIO_CONFIG_S_DRIVER_OK) &&
|
|
|
|
!(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
|
2010-12-17 13:01:49 +01:00
|
|
|
proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
|
2010-03-16 19:18:07 +01:00
|
|
|
}
|
2009-05-18 15:51:59 +02:00
|
|
|
break;
|
2009-06-21 18:50:26 +02: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 21:44:38 +01:00
|
|
|
error_report("%s: unexpected address 0x%x value 0x%x",
|
|
|
|
__func__, addr, val);
|
2009-06-21 18:50:26 +02:00
|
|
|
break;
|
2009-05-18 15:51:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-21 18:50:26 +02:00
|
|
|
static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
|
2009-05-18 15:51:59 +02:00
|
|
|
{
|
|
|
|
VirtIODevice *vdev = proxy->vdev;
|
|
|
|
uint32_t ret = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case VIRTIO_PCI_HOST_FEATURES:
|
2010-01-10 12:52:53 +01:00
|
|
|
ret = proxy->host_features;
|
2009-05-18 15:51:59 +02:00
|
|
|
break;
|
|
|
|
case VIRTIO_PCI_GUEST_FEATURES:
|
2010-01-10 12:52:47 +01:00
|
|
|
ret = vdev->guest_features;
|
2009-05-18 15:51:59 +02: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;
|
2009-06-21 18:50:13 +02:00
|
|
|
qemu_set_irq(proxy->pci_dev.irq[0], 0);
|
2009-05-18 15:51:59 +02:00
|
|
|
break;
|
2009-06-21 18:50:26 +02: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 15:51:59 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t virtio_pci_config_readb(void *opaque, uint32_t addr)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2009-06-21 18:50:26 +02:00
|
|
|
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
|
|
|
|
addr -= proxy->addr;
|
|
|
|
if (addr < config)
|
|
|
|
return virtio_ioport_read(proxy, addr);
|
|
|
|
addr -= config;
|
2009-05-18 15:51:59 +02:00
|
|
|
return virtio_config_readb(proxy->vdev, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t virtio_pci_config_readw(void *opaque, uint32_t addr)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2009-06-21 18:50:26 +02:00
|
|
|
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
|
|
|
|
addr -= proxy->addr;
|
|
|
|
if (addr < config)
|
|
|
|
return virtio_ioport_read(proxy, addr);
|
|
|
|
addr -= config;
|
2009-05-18 15:51:59 +02:00
|
|
|
return virtio_config_readw(proxy->vdev, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t virtio_pci_config_readl(void *opaque, uint32_t addr)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2009-06-21 18:50:26 +02:00
|
|
|
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
|
|
|
|
addr -= proxy->addr;
|
|
|
|
if (addr < config)
|
|
|
|
return virtio_ioport_read(proxy, addr);
|
|
|
|
addr -= config;
|
2009-05-18 15:51:59 +02:00
|
|
|
return virtio_config_readl(proxy->vdev, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_pci_config_writeb(void *opaque, uint32_t addr, uint32_t val)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2009-06-21 18:50:26 +02:00
|
|
|
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
|
|
|
|
addr -= proxy->addr;
|
|
|
|
if (addr < config) {
|
|
|
|
virtio_ioport_write(proxy, addr, val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr -= config;
|
2009-05-18 15:51:59 +02:00
|
|
|
virtio_config_writeb(proxy->vdev, addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_pci_config_writew(void *opaque, uint32_t addr, uint32_t val)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2009-06-21 18:50:26 +02:00
|
|
|
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
|
|
|
|
addr -= proxy->addr;
|
|
|
|
if (addr < config) {
|
|
|
|
virtio_ioport_write(proxy, addr, val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr -= config;
|
2009-05-18 15:51:59 +02:00
|
|
|
virtio_config_writew(proxy->vdev, addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2009-06-21 18:50:26 +02:00
|
|
|
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
|
|
|
|
addr -= proxy->addr;
|
|
|
|
if (addr < config) {
|
|
|
|
virtio_ioport_write(proxy, addr, val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr -= config;
|
2009-05-18 15:51:59 +02:00
|
|
|
virtio_config_writel(proxy->vdev, addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_map(PCIDevice *pci_dev, int region_num,
|
2009-10-30 13:21:08 +01:00
|
|
|
pcibus_t addr, pcibus_t size, int type)
|
2009-05-18 15:51:59 +02:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev);
|
|
|
|
VirtIODevice *vdev = proxy->vdev;
|
2009-06-21 18:50:26 +02:00
|
|
|
unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len;
|
2009-05-18 15:51:59 +02:00
|
|
|
|
|
|
|
proxy->addr = addr;
|
|
|
|
|
2009-06-21 18:50:26 +02:00
|
|
|
register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy);
|
|
|
|
register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy);
|
|
|
|
register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy);
|
|
|
|
register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy);
|
|
|
|
register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy);
|
|
|
|
register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy);
|
2009-05-18 15:51:59 +02:00
|
|
|
|
2009-06-21 18:50:26 +02:00
|
|
|
if (vdev->config_len)
|
2009-05-18 15:51:59 +02:00
|
|
|
vdev->get_config(vdev, vdev->config);
|
2009-06-21 18:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
|
|
|
|
uint32_t val, int len)
|
|
|
|
{
|
2009-09-08 16:49:41 +02:00
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
|
|
|
|
|
|
|
if (PCI_COMMAND == address) {
|
|
|
|
if (!(val & PCI_COMMAND_MASTER)) {
|
2010-12-17 13:01:49 +01:00
|
|
|
if (!(proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG)) {
|
2010-12-17 13:01:50 +01:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
2010-03-17 12:08:05 +01:00
|
|
|
virtio_set_status(proxy->vdev,
|
|
|
|
proxy->vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
|
2010-03-16 19:18:07 +01:00
|
|
|
}
|
2009-09-08 16:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-21 18:50:26 +02:00
|
|
|
pci_default_write_config(pci_dev, address, val, len);
|
2009-09-22 12:35:28 +02:00
|
|
|
msix_write_config(pci_dev, address, val, len);
|
2009-05-18 15:51:59 +02:00
|
|
|
}
|
|
|
|
|
2009-12-08 19:07:48 +01:00
|
|
|
static unsigned virtio_pci_get_features(void *opaque)
|
|
|
|
{
|
2010-01-10 12:52:53 +01:00
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
return proxy->host_features;
|
2009-12-08 19:07:48 +01:00
|
|
|
}
|
|
|
|
|
2010-03-17 12:08:13 +01:00
|
|
|
static void virtio_pci_guest_notifier_read(void *opaque)
|
|
|
|
{
|
|
|
|
VirtQueue *vq = opaque;
|
|
|
|
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
|
|
|
|
if (event_notifier_test_and_clear(n)) {
|
|
|
|
virtio_irq(vq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_pci_set_guest_notifier(void *opaque, int n, bool assign)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
|
|
|
|
EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
|
|
|
|
|
|
|
|
if (assign) {
|
|
|
|
int r = event_notifier_init(notifier, 0);
|
|
|
|
if (r < 0) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
qemu_set_fd_handler(event_notifier_get_fd(notifier),
|
|
|
|
virtio_pci_guest_notifier_read, NULL, vq);
|
|
|
|
} else {
|
|
|
|
qemu_set_fd_handler(event_notifier_get_fd(notifier),
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
event_notifier_cleanup(notifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-01 21:13:42 +01:00
|
|
|
static bool virtio_pci_query_guest_notifiers(void *opaque)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
return msix_enabled(&proxy->pci_dev);
|
|
|
|
}
|
|
|
|
|
2010-10-06 15:20:17 +02:00
|
|
|
static int virtio_pci_set_guest_notifiers(void *opaque, bool assign)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
VirtIODevice *vdev = proxy->vdev;
|
|
|
|
int r, n;
|
|
|
|
|
|
|
|
for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
|
|
|
|
if (!virtio_queue_get_num(vdev, n)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = virtio_pci_set_guest_notifier(opaque, n, assign);
|
|
|
|
if (r < 0) {
|
|
|
|
goto assign_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
assign_error:
|
|
|
|
/* We get here on assignment failure. Recover by undoing for VQs 0 .. n. */
|
|
|
|
while (--n >= 0) {
|
|
|
|
virtio_pci_set_guest_notifier(opaque, n, !assign);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-03-17 12:08:13 +01:00
|
|
|
static int virtio_pci_set_host_notifier(void *opaque, int n, bool assign)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
2010-12-17 13:01:50 +01: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 12:08:13 +01:00
|
|
|
if (assign) {
|
2010-12-17 13:01:50 +01: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. */
|
|
|
|
return virtio_pci_set_host_notifier_internal(proxy, n, assign);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_pci_vmstate_change(void *opaque, bool running)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = opaque;
|
|
|
|
|
|
|
|
if (running) {
|
|
|
|
virtio_pci_start_ioeventfd(proxy);
|
2010-03-17 12:08:13 +01:00
|
|
|
} else {
|
2010-12-17 13:01:50 +01:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
2010-03-17 12:08:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 15:51:59 +02:00
|
|
|
static const VirtIOBindings virtio_pci_bindings = {
|
2009-06-21 18:50:40 +02:00
|
|
|
.notify = virtio_pci_notify,
|
|
|
|
.save_config = virtio_pci_save_config,
|
|
|
|
.load_config = virtio_pci_load_config,
|
|
|
|
.save_queue = virtio_pci_save_queue,
|
|
|
|
.load_queue = virtio_pci_load_queue,
|
2009-12-08 19:07:48 +01:00
|
|
|
.get_features = virtio_pci_get_features,
|
2011-02-01 21:13:42 +01:00
|
|
|
.query_guest_notifiers = virtio_pci_query_guest_notifiers,
|
2010-03-17 12:08:13 +01:00
|
|
|
.set_host_notifier = virtio_pci_set_host_notifier,
|
2010-10-06 15:20:17 +02:00
|
|
|
.set_guest_notifiers = virtio_pci_set_guest_notifiers,
|
2010-12-17 13:01:50 +01:00
|
|
|
.vmstate_change = virtio_pci_vmstate_change,
|
2009-05-18 15:51:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
|
|
|
|
uint16_t vendor, uint16_t device,
|
|
|
|
uint16_t class_code, uint8_t pif)
|
|
|
|
{
|
|
|
|
uint8_t *config;
|
|
|
|
uint32_t size;
|
|
|
|
|
|
|
|
proxy->vdev = vdev;
|
|
|
|
|
|
|
|
config = proxy->pci_dev.config;
|
|
|
|
pci_config_set_vendor_id(config, vendor);
|
|
|
|
pci_config_set_device_id(config, device);
|
|
|
|
|
|
|
|
config[0x08] = VIRTIO_PCI_ABI_VERSION;
|
|
|
|
|
|
|
|
config[0x09] = pif;
|
|
|
|
pci_config_set_class(config, class_code);
|
|
|
|
|
|
|
|
config[0x2c] = vendor & 0xFF;
|
|
|
|
config[0x2d] = (vendor >> 8) & 0xFF;
|
|
|
|
config[0x2e] = vdev->device_id & 0xFF;
|
|
|
|
config[0x2f] = (vdev->device_id >> 8) & 0xFF;
|
|
|
|
|
|
|
|
config[0x3d] = 1;
|
|
|
|
|
2009-09-29 18:53:26 +02:00
|
|
|
if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) {
|
2009-06-21 18:50:26 +02:00
|
|
|
pci_register_bar(&proxy->pci_dev, 1,
|
|
|
|
msix_bar_size(&proxy->pci_dev),
|
2009-10-30 13:21:03 +01:00
|
|
|
PCI_BASE_ADDRESS_SPACE_MEMORY,
|
2009-06-21 18:50:26 +02:00
|
|
|
msix_mmio_map);
|
|
|
|
} else
|
|
|
|
vdev->nvectors = 0;
|
|
|
|
|
2009-09-08 16:49:41 +02:00
|
|
|
proxy->pci_dev.config_write = virtio_write_config;
|
|
|
|
|
2009-06-21 18:50:26 +02:00
|
|
|
size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + vdev->config_len;
|
2009-05-18 15:51:59 +02:00
|
|
|
if (size & (size-1))
|
|
|
|
size = 1 << qemu_fls(size);
|
|
|
|
|
2009-10-30 13:21:03 +01:00
|
|
|
pci_register_bar(&proxy->pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO,
|
2009-05-18 15:51:59 +02:00
|
|
|
virtio_map);
|
|
|
|
|
2010-12-17 13:01:50 +01:00
|
|
|
if (!kvm_has_many_ioeventfds()) {
|
|
|
|
proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
|
|
|
|
}
|
|
|
|
|
2009-05-18 15:51:59 +02:00
|
|
|
virtio_bind_device(vdev, &virtio_pci_bindings, proxy);
|
2010-01-10 12:52:53 +01:00
|
|
|
proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
|
|
|
|
proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
|
|
|
|
proxy->host_features = vdev->get_features(vdev, proxy->host_features);
|
2009-05-18 15:51:59 +02:00
|
|
|
}
|
|
|
|
|
2009-08-14 10:36:05 +02:00
|
|
|
static int virtio_blk_init_pci(PCIDevice *pci_dev)
|
2009-05-18 15:51:59 +02:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
|
|
|
VirtIODevice *vdev;
|
|
|
|
|
2009-07-15 13:48:23 +02:00
|
|
|
if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
|
|
|
|
proxy->class_code != PCI_CLASS_STORAGE_OTHER)
|
|
|
|
proxy->class_code = PCI_CLASS_STORAGE_SCSI;
|
2009-05-18 15:51:59 +02:00
|
|
|
|
block: add topology qdev properties
Add three new qdev properties to export block topology information to
the guest. This is needed to get optimal I/O alignment for RAID arrays
or SSDs.
The options are:
- physical_block_size to specify the physical block size of the device,
this is going to increase from 512 bytes to 4096 kilobytes for many
modern storage devices
- min_io_size to specify the minimal I/O size without performance impact,
this is typically set to the RAID chunk size for arrays.
- opt_io_size to specify the optimal sustained I/O size, this is
typically the RAID stripe width for arrays.
I decided to not auto-probe these values from blkid which might easily
be possible as I don't know how to deal with these issues on migration.
Note that we specificly only set the physical_block_size, and not the
logial one which is the unit all I/O is described in. The reason for
that is that IDE does not support increasing the logical block size and
at last for now I want to stick to one meachnisms in queue and allow
for easy switching of transports for a given backing image which would
not be possible if scsi and virtio use real 4k sectors, while ide only
uses the physical block exponent.
To make this more common for the different block drivers introduce a
new BlockConf structure holding all common block properties and a
DEFINE_BLOCK_PROPERTIES macro to add them all together, mirroring
what is done for network drivers. Also switch over all block drivers
to use it, except for the floppy driver which has weird driveA/driveB
properties and probably won't require any advanced block options ever.
Example usage for a virtio device with 4k physical block size and
8k optimal I/O size:
-drive file=scratch.img,media=disk,cache=none,id=scratch \
-device virtio-blk-pci,drive=scratch,physical_block_size=4096,opt_io_size=8192
aliguori: updated patch to take into account BLOCK events
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 23:37:09 +01:00
|
|
|
vdev = virtio_blk_init(&pci_dev->qdev, &proxy->block);
|
2010-07-06 14:37:42 +02:00
|
|
|
if (!vdev) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-08-12 12:47:24 +02:00
|
|
|
vdev->nvectors = proxy->nvectors;
|
2009-05-18 15:51:59 +02:00
|
|
|
virtio_init_pci(proxy, vdev,
|
|
|
|
PCI_VENDOR_ID_REDHAT_QUMRANET,
|
2009-07-30 12:29:13 +02:00
|
|
|
PCI_DEVICE_ID_VIRTIO_BLOCK,
|
|
|
|
proxy->class_code, 0x00);
|
2009-08-12 12:47:24 +02:00
|
|
|
/* make the actual value visible */
|
|
|
|
proxy->nvectors = vdev->nvectors;
|
2009-08-14 10:36:05 +02:00
|
|
|
return 0;
|
2009-07-07 13:09:58 +02:00
|
|
|
}
|
|
|
|
|
2009-10-05 23:02:20 +02:00
|
|
|
static int virtio_exit_pci(PCIDevice *pci_dev)
|
|
|
|
{
|
|
|
|
return msix_uninit(pci_dev);
|
|
|
|
}
|
|
|
|
|
2009-09-25 21:42:46 +02:00
|
|
|
static int virtio_blk_exit_pci(PCIDevice *pci_dev)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
|
|
|
|
2010-12-17 13:01:50 +01:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
2010-07-20 19:14:22 +02:00
|
|
|
virtio_blk_exit(proxy->vdev);
|
2010-05-05 16:36:52 +02:00
|
|
|
blockdev_mark_auto_del(proxy->block.bs);
|
2009-10-05 23:02:20 +02:00
|
|
|
return virtio_exit_pci(pci_dev);
|
2009-09-25 21:42:46 +02:00
|
|
|
}
|
|
|
|
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
static int virtio_serial_init_pci(PCIDevice *pci_dev)
|
2009-07-07 13:09:58 +02:00
|
|
|
{
|
2009-07-15 13:48:24 +02:00
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
2009-07-30 12:29:13 +02:00
|
|
|
VirtIODevice *vdev;
|
|
|
|
|
2009-07-15 13:48:24 +02:00
|
|
|
if (proxy->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
|
|
|
|
proxy->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
|
|
|
|
proxy->class_code != PCI_CLASS_OTHERS) /* qemu-kvm */
|
|
|
|
proxy->class_code = PCI_CLASS_COMMUNICATION_OTHER;
|
|
|
|
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
vdev = virtio_serial_init(&pci_dev->qdev, proxy->max_virtserial_ports);
|
2009-09-29 12:21:04 +02:00
|
|
|
if (!vdev) {
|
|
|
|
return -1;
|
|
|
|
}
|
2010-02-25 12:54:44 +01:00
|
|
|
vdev->nvectors = proxy->nvectors == DEV_NVECTORS_UNSPECIFIED
|
|
|
|
? proxy->max_virtserial_ports + 1
|
|
|
|
: proxy->nvectors;
|
2009-07-30 12:29:13 +02:00
|
|
|
virtio_init_pci(proxy, vdev,
|
|
|
|
PCI_VENDOR_ID_REDHAT_QUMRANET,
|
|
|
|
PCI_DEVICE_ID_VIRTIO_CONSOLE,
|
|
|
|
proxy->class_code, 0x00);
|
2010-01-19 20:06:58 +01:00
|
|
|
proxy->nvectors = vdev->nvectors;
|
2009-08-14 10:36:05 +02:00
|
|
|
return 0;
|
2009-05-18 15:51:59 +02:00
|
|
|
}
|
|
|
|
|
2010-08-19 03:21:04 +02:00
|
|
|
static int virtio_serial_exit_pci(PCIDevice *pci_dev)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
|
|
|
|
|
|
|
virtio_serial_exit(proxy->vdev);
|
|
|
|
return virtio_exit_pci(pci_dev);
|
|
|
|
}
|
|
|
|
|
2009-08-14 10:36:05 +02:00
|
|
|
static int virtio_net_init_pci(PCIDevice *pci_dev)
|
2009-05-18 15:51:59 +02:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
|
|
|
VirtIODevice *vdev;
|
|
|
|
|
2010-09-02 17:00:50 +02:00
|
|
|
vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic, &proxy->net);
|
2009-07-15 13:48:25 +02:00
|
|
|
|
2009-10-21 15:25:35 +02:00
|
|
|
vdev->nvectors = proxy->nvectors;
|
2009-05-18 15:51:59 +02:00
|
|
|
virtio_init_pci(proxy, vdev,
|
|
|
|
PCI_VENDOR_ID_REDHAT_QUMRANET,
|
|
|
|
PCI_DEVICE_ID_VIRTIO_NET,
|
|
|
|
PCI_CLASS_NETWORK_ETHERNET,
|
|
|
|
0x00);
|
2009-07-15 13:48:25 +02:00
|
|
|
|
|
|
|
/* make the actual value visible */
|
|
|
|
proxy->nvectors = vdev->nvectors;
|
2009-08-14 10:36:05 +02:00
|
|
|
return 0;
|
2009-05-18 15:51:59 +02:00
|
|
|
}
|
|
|
|
|
2009-10-21 15:25:35 +02:00
|
|
|
static int virtio_net_exit_pci(PCIDevice *pci_dev)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
|
|
|
|
2010-12-17 13:01:50 +01:00
|
|
|
virtio_pci_stop_ioeventfd(proxy);
|
2009-10-21 15:25:35 +02:00
|
|
|
virtio_net_exit(proxy->vdev);
|
|
|
|
return virtio_exit_pci(pci_dev);
|
|
|
|
}
|
|
|
|
|
2009-08-14 10:36:05 +02:00
|
|
|
static int virtio_balloon_init_pci(PCIDevice *pci_dev)
|
2009-05-18 15:51:59 +02:00
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
|
|
|
VirtIODevice *vdev;
|
|
|
|
|
|
|
|
vdev = virtio_balloon_init(&pci_dev->qdev);
|
|
|
|
virtio_init_pci(proxy, vdev,
|
|
|
|
PCI_VENDOR_ID_REDHAT_QUMRANET,
|
|
|
|
PCI_DEVICE_ID_VIRTIO_BALLOON,
|
|
|
|
PCI_CLASS_MEMORY_RAM,
|
|
|
|
0x00);
|
2009-08-14 10:36:05 +02:00
|
|
|
return 0;
|
2009-05-18 15:51:59 +02:00
|
|
|
}
|
|
|
|
|
2010-06-14 22:34:41 +02:00
|
|
|
#ifdef CONFIG_VIRTFS
|
2010-04-29 14:14:44 +02:00
|
|
|
static int virtio_9p_init_pci(PCIDevice *pci_dev)
|
|
|
|
{
|
|
|
|
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
|
|
|
|
VirtIODevice *vdev;
|
|
|
|
|
|
|
|
vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
|
2010-11-11 12:59:26 +01:00
|
|
|
vdev->nvectors = proxy->nvectors;
|
2010-04-29 14:14:44 +02:00
|
|
|
virtio_init_pci(proxy, vdev,
|
|
|
|
PCI_VENDOR_ID_REDHAT_QUMRANET,
|
|
|
|
0x1009,
|
|
|
|
0x2,
|
|
|
|
0x00);
|
2010-11-11 12:59:26 +01:00
|
|
|
/* make the actual value visible */
|
|
|
|
proxy->nvectors = vdev->nvectors;
|
2010-04-29 14:14:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-30 14:12:07 +02:00
|
|
|
static PCIDeviceInfo virtio_info[] = {
|
|
|
|
{
|
|
|
|
.qdev.name = "virtio-blk-pci",
|
2010-12-08 12:34:54 +01:00
|
|
|
.qdev.alias = "virtio-blk",
|
2009-06-30 14:12:07 +02:00
|
|
|
.qdev.size = sizeof(VirtIOPCIProxy),
|
|
|
|
.init = virtio_blk_init_pci,
|
2009-09-25 21:42:46 +02:00
|
|
|
.exit = virtio_blk_exit_pci,
|
2009-07-15 13:48:23 +02:00
|
|
|
.qdev.props = (Property[]) {
|
2009-08-03 17:35:45 +02:00
|
|
|
DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
|
block: add topology qdev properties
Add three new qdev properties to export block topology information to
the guest. This is needed to get optimal I/O alignment for RAID arrays
or SSDs.
The options are:
- physical_block_size to specify the physical block size of the device,
this is going to increase from 512 bytes to 4096 kilobytes for many
modern storage devices
- min_io_size to specify the minimal I/O size without performance impact,
this is typically set to the RAID chunk size for arrays.
- opt_io_size to specify the optimal sustained I/O size, this is
typically the RAID stripe width for arrays.
I decided to not auto-probe these values from blkid which might easily
be possible as I don't know how to deal with these issues on migration.
Note that we specificly only set the physical_block_size, and not the
logial one which is the unit all I/O is described in. The reason for
that is that IDE does not support increasing the logical block size and
at last for now I want to stick to one meachnisms in queue and allow
for easy switching of transports for a given backing image which would
not be possible if scsi and virtio use real 4k sectors, while ide only
uses the physical block exponent.
To make this more common for the different block drivers introduce a
new BlockConf structure holding all common block properties and a
DEFINE_BLOCK_PROPERTIES macro to add them all together, mirroring
what is done for network drivers. Also switch over all block drivers
to use it, except for the floppy driver which has weird driveA/driveB
properties and probably won't require any advanced block options ever.
Example usage for a virtio device with 4k physical block size and
8k optimal I/O size:
-drive file=scratch.img,media=disk,cache=none,id=scratch \
-device virtio-blk-pci,drive=scratch,physical_block_size=4096,opt_io_size=8192
aliguori: updated patch to take into account BLOCK events
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 23:37:09 +01:00
|
|
|
DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
|
2010-12-17 13:01:50 +01:00
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
|
|
|
|
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
|
2009-08-12 12:47:24 +02:00
|
|
|
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
|
2010-01-10 12:52:53 +01:00
|
|
|
DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
|
2009-08-03 17:35:45 +02:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2009-07-15 13:48:23 +02:00
|
|
|
},
|
2009-09-16 12:40:37 +02:00
|
|
|
.qdev.reset = virtio_pci_reset,
|
2009-06-30 14:12:07 +02:00
|
|
|
},{
|
2009-07-15 13:48:25 +02:00
|
|
|
.qdev.name = "virtio-net-pci",
|
|
|
|
.qdev.size = sizeof(VirtIOPCIProxy),
|
|
|
|
.init = virtio_net_init_pci,
|
2009-10-21 15:25:35 +02:00
|
|
|
.exit = virtio_net_exit_pci,
|
2009-12-18 12:01:08 +01:00
|
|
|
.romfile = "pxe-virtio.bin",
|
2009-07-15 13:48:25 +02:00
|
|
|
.qdev.props = (Property[]) {
|
2010-12-17 13:01:50 +01:00
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
|
|
|
|
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
|
2009-10-21 15:25:35 +02:00
|
|
|
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
|
2010-01-10 12:52:53 +01:00
|
|
|
DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
|
2009-10-21 15:25:35 +02:00
|
|
|
DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
|
2010-09-02 17:00:50 +02:00
|
|
|
DEFINE_PROP_UINT32("x-txtimer", VirtIOPCIProxy,
|
|
|
|
net.txtimer, TX_TIMER_INTERVAL),
|
2010-09-02 17:00:57 +02:00
|
|
|
DEFINE_PROP_INT32("x-txburst", VirtIOPCIProxy,
|
|
|
|
net.txburst, TX_BURST),
|
2010-09-02 17:01:10 +02:00
|
|
|
DEFINE_PROP_STRING("tx", VirtIOPCIProxy, net.tx),
|
2009-08-03 17:35:45 +02:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2009-07-15 13:48:25 +02:00
|
|
|
},
|
2009-09-16 12:40:37 +02:00
|
|
|
.qdev.reset = virtio_pci_reset,
|
2009-06-30 14:12:07 +02:00
|
|
|
},{
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
.qdev.name = "virtio-serial-pci",
|
|
|
|
.qdev.alias = "virtio-serial",
|
2009-06-30 14:12:07 +02:00
|
|
|
.qdev.size = sizeof(VirtIOPCIProxy),
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
.init = virtio_serial_init_pci,
|
2010-08-19 03:21:04 +02:00
|
|
|
.exit = virtio_serial_exit_pci,
|
2009-07-15 13:48:24 +02:00
|
|
|
.qdev.props = (Property[]) {
|
2010-02-25 12:54:44 +01:00
|
|
|
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
|
|
|
|
DEV_NVECTORS_UNSPECIFIED),
|
2009-08-03 17:35:45 +02:00
|
|
|
DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
|
2010-01-10 12:52:53 +01:00
|
|
|
DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
|
virtio-console: qdev conversion, new virtio-serial-bus
This commit converts the virtio-console device to create a new
virtio-serial bus that can host console and generic serial ports. The
file hosting this code is now called virtio-serial-bus.c.
The virtio console is now a very simple qdev device that sits on the
virtio-serial-bus and communicates between the bus and qemu's chardevs.
This commit also includes a few changes to the virtio backing code for
pci and s390 to spawn the virtio-serial bus.
As a result of the qdev conversion, we get rid of a lot of legacy code.
The old-style way of instantiating a virtio console using
-virtioconsole ...
is maintained, but the new, preferred way is to use
-device virtio-serial -device virtconsole,chardev=...
With this commit, multiple devices as well as multiple ports with a
single device can be supported.
For multiple ports support, each port gets an IO vq pair. Since the
guest needs to know in advance how many vqs a particular device will
need, we have to set this number as a property of the virtio-serial
device and also as a config option.
In addition, we also spawn a pair of control IO vqs. This is an internal
channel meant for guest-host communication for things like port
open/close, sending port properties over to the guest, etc.
This commit is a part of a series of other commits to get the full
implementation of multiport support. Future commits will add other
support as well as ride on the savevm version that we bump up here.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-19 20:06:52 +01:00
|
|
|
DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, max_virtserial_ports,
|
|
|
|
31),
|
2009-08-03 17:35:45 +02:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2009-07-15 13:48:24 +02:00
|
|
|
},
|
2009-09-16 12:40:37 +02:00
|
|
|
.qdev.reset = virtio_pci_reset,
|
2009-06-30 14:12:07 +02:00
|
|
|
},{
|
|
|
|
.qdev.name = "virtio-balloon-pci",
|
|
|
|
.qdev.size = sizeof(VirtIOPCIProxy),
|
|
|
|
.init = virtio_balloon_init_pci,
|
2009-10-05 23:02:20 +02:00
|
|
|
.exit = virtio_exit_pci,
|
2010-01-10 12:52:53 +01:00
|
|
|
.qdev.props = (Property[]) {
|
|
|
|
DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
},
|
2009-09-16 12:40:37 +02:00
|
|
|
.qdev.reset = virtio_pci_reset,
|
2009-06-30 14:12:07 +02:00
|
|
|
},{
|
2010-06-14 22:34:41 +02:00
|
|
|
#ifdef CONFIG_VIRTFS
|
2010-04-29 14:14:44 +02:00
|
|
|
.qdev.name = "virtio-9p-pci",
|
|
|
|
.qdev.size = sizeof(VirtIOPCIProxy),
|
|
|
|
.init = virtio_9p_init_pci,
|
|
|
|
.qdev.props = (Property[]) {
|
2010-11-11 12:59:26 +01:00
|
|
|
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
|
2010-04-29 14:14:44 +02:00
|
|
|
DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
|
|
|
|
DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
|
|
|
|
DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
#endif
|
2009-06-30 14:12:07 +02:00
|
|
|
/* end of list */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-18 15:51:59 +02:00
|
|
|
static void virtio_pci_register_devices(void)
|
|
|
|
{
|
2009-06-30 14:12:07 +02:00
|
|
|
pci_qdev_register_many(virtio_info);
|
2009-05-18 15:51:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
device_init(virtio_pci_register_devices)
|