diff mbox

[RFC,2/3] virtio: misc fixes, include linux header

Message ID 1419956898-25297-3-git-send-email-mst@redhat.com
State New
Headers show

Commit Message

Michael S. Tsirkin Dec. 30, 2014, 4:28 p.m. UTC
Tweak virtio core so we can use linux virtio pci header
directly without duplicating code.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/net/virtio-net.c    |  2 +-
 hw/virtio/virtio-pci.c |  3 +++
 hw/virtio/virtio.c     | 13 +++++++++----
 3 files changed, 13 insertions(+), 5 deletions(-)

Comments

Peter Maydell Dec. 30, 2014, 10:25 p.m. UTC | #1
On 30 December 2014 at 16:28, Michael S. Tsirkin <mst@redhat.com> wrote:
> Tweak virtio core so we can use linux virtio pci header
> directly without duplicating code.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 7382705..bc11d3d 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -17,6 +17,7 @@
>
>  #include <inttypes.h>
>
> +#include "linux-headers/linux/virtio_pci.h"

I'm afraid this won't work. You can only pull in the Linux headers
inside CONFIG_KVM ifdefs. Otherwise you're liable to break the
build on non-Linux platforms, because the kernel headers make
no guarantees about being usable on any hosts other than Linux.

Indeed in this specific case MacOSX won't build:

In file included from /Users/pm215/src/qemu/hw/virtio/virtio-pci.c:20:
/Users/pm215/src/qemu/linux-headers/linux/virtio_pci.h:42:10: fatal
error: 'linux/types.h' file not found
#include <linux/types.h>
         ^

If you need the virtio_pci.h header you'll need to make a
portable copy of it in include/hw/virtio/, the same way we
have already for the other headers.

thanks
-- PMM
diff mbox

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index b5dd356..5fff769 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1046,7 +1046,7 @@  static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t
                 return -1;
             error_report("virtio-net unexpected empty queue: "
                     "i %zd mergeable %d offset %zd, size %zd, "
-                    "guest hdr len %zd, host hdr len %zd guest features 0x%lx",
+                    "guest hdr len %zd, host hdr len %zd guest features 0x%"PRIx64,
                     i, n->mergeable_rx_bufs, offset, size,
                     n->guest_hdr_len, n->host_hdr_len, vdev->guest_features);
             exit(1);
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 7382705..bc11d3d 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -17,6 +17,7 @@ 
 
 #include <inttypes.h>
 
+#include "linux-headers/linux/virtio_pci.h"
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-net.h"
@@ -76,6 +77,8 @@ 
                                          VIRTIO_PCI_CONFIG_MSI : \
                                          VIRTIO_PCI_CONFIG_NOMSI)
 
+#undef VIRTIO_PCI_CONFIG
+
 /* The remaining space is defined by each driver as the per-driver
  * configuration space */
 #define VIRTIO_PCI_CONFIG(dev)          (msix_enabled(dev) ? \
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 90eedd3..301b83f 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1033,7 +1033,8 @@  int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
     int i, ret;
     int32_t config_len;
     uint32_t num;
-    uint32_t features;
+    uint32_t features_lo, features_hi;
+    uint64_t features;
     uint64_t supported_features;
     BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
@@ -1057,12 +1058,16 @@  int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
     if (vdev->queue_sel >= VIRTIO_PCI_QUEUE_MAX) {
         return -1;
     }
-    qemu_get_be32s(f, &features);
+    qemu_get_be32s(f, &features_lo);
+
+    //if (features_lo & (1UL << VIRTIO_F_VERSION_1)) {
+        qemu_get_be32s(f, &features_hi);
+    //}
+    features = (((uint64_t)features_hi) << 32) | features_lo;
 
-    /* XXX features >= 32 */
     if (__virtio_set_features(vdev, features) < 0) {
         supported_features = k->get_features(qbus->parent);
-        error_report("Features 0x%x unsupported. Allowed features: 0x%lx",
+        error_report("Features 0x%"PRIx64" unsupported. Allowed features: 0x%"PRIx64,
                      features, supported_features);
         return -1;
     }