~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to hw/virtio/virtio.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "qemu/atomic.h"
20
20
#include "hw/virtio/virtio-bus.h"
21
21
 
22
 
/* The alignment to use between consumer and producer parts of vring.
23
 
 * x86 pagesize again. */
 
22
/*
 
23
 * The alignment to use between consumer and producer parts of vring.
 
24
 * x86 pagesize again. This is the default, used by transports like PCI
 
25
 * which don't provide a means for the guest to tell the host the alignment.
 
26
 */
24
27
#define VIRTIO_PCI_VRING_ALIGN         4096
25
28
 
26
29
typedef struct VRingDesc
54
57
typedef struct VRing
55
58
{
56
59
    unsigned int num;
 
60
    unsigned int align;
57
61
    hwaddr desc;
58
62
    hwaddr avail;
59
63
    hwaddr used;
93
97
    vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc);
94
98
    vq->vring.used = vring_align(vq->vring.avail +
95
99
                                 offsetof(VRingAvail, ring[vq->vring.num]),
96
 
                                 VIRTIO_PCI_VRING_ALIGN);
 
100
                                 vq->vring.align);
97
101
}
98
102
 
99
103
static inline uint64_t vring_desc_addr(hwaddr desc_pa, int i)
373
377
            /* loop over the indirect descriptor table */
374
378
            indirect = 1;
375
379
            max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
 
380
            desc_pa = vring_desc_addr(desc_pa, i);
376
381
            num_bufs = i = 0;
377
 
            desc_pa = vring_desc_addr(desc_pa, i);
378
382
        }
379
383
 
380
384
        do {
667
671
    return vdev->vq[n].pa;
668
672
}
669
673
 
 
674
void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
 
675
{
 
676
    /* Don't allow guest to flip queue between existent and
 
677
     * nonexistent states, or to set it to an invalid size.
 
678
     */
 
679
    if (!!num != !!vdev->vq[n].vring.num ||
 
680
        num > VIRTQUEUE_MAX_SIZE ||
 
681
        num < 0) {
 
682
        return;
 
683
    }
 
684
    vdev->vq[n].vring.num = num;
 
685
    virtqueue_init(&vdev->vq[n]);
 
686
}
 
687
 
670
688
int virtio_queue_get_num(VirtIODevice *vdev, int n)
671
689
{
672
690
    return vdev->vq[n].vring.num;
679
697
    return vq - &vdev->vq[0];
680
698
}
681
699
 
 
700
void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
 
701
{
 
702
    BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
 
703
    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
 
704
 
 
705
    /* Check that the transport told us it was going to do this
 
706
     * (so a buggy transport will immediately assert rather than
 
707
     * silently failing to migrate this state)
 
708
     */
 
709
    assert(k->has_variable_vring_alignment);
 
710
 
 
711
    vdev->vq[n].vring.align = align;
 
712
    virtqueue_init(&vdev->vq[n]);
 
713
}
 
714
 
682
715
void virtio_queue_notify_vq(VirtQueue *vq)
683
716
{
684
717
    if (vq->vring.desc) {
719
752
        abort();
720
753
 
721
754
    vdev->vq[i].vring.num = queue_size;
 
755
    vdev->vq[i].vring.align = VIRTIO_PCI_VRING_ALIGN;
722
756
    vdev->vq[i].handle_output = handle_output;
723
757
 
724
758
    return &vdev->vq[i];
825
859
            break;
826
860
 
827
861
        qemu_put_be32(f, vdev->vq[i].vring.num);
 
862
        if (k->has_variable_vring_alignment) {
 
863
            qemu_put_be32(f, vdev->vq[i].vring.align);
 
864
        }
828
865
        qemu_put_be64(f, vdev->vq[i].pa);
829
866
        qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
830
867
        if (k->save_queue) {
881
918
 
882
919
    for (i = 0; i < num; i++) {
883
920
        vdev->vq[i].vring.num = qemu_get_be32(f);
 
921
        if (k->has_variable_vring_alignment) {
 
922
            vdev->vq[i].vring.align = qemu_get_be32(f);
 
923
        }
884
924
        vdev->vq[i].pa = qemu_get_be64(f);
885
925
        qemu_get_be16s(f, &vdev->vq[i].last_avail_idx);
886
926
        vdev->vq[i].signalled_used_valid = false;
1025
1065
    vdev->vq[n].last_avail_idx = idx;
1026
1066
}
1027
1067
 
 
1068
void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n)
 
1069
{
 
1070
    vdev->vq[n].signalled_used_valid = false;
 
1071
}
 
1072
 
1028
1073
VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n)
1029
1074
{
1030
1075
    return vdev->vq + n;