On Fri, Feb 21, 2014 at 12:28:11PM +0100, Greg Kurz wrote: > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index aeabf3a..4fd6ac2 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -19,6 +19,9 @@ > #include "hw/virtio/virtio.h" > #include "qemu/atomic.h" > #include "hw/virtio/virtio-bus.h" > +#include "hw/virtio/virtio-access.h" > + > +bool virtio_byteswap; > > /* > * The alignment to use between consumer and producer parts of vring. > @@ -546,6 +549,9 @@ void virtio_reset(void *opaque) > > virtio_set_status(vdev, 0); > > + /* We assume all devices are the same endian. */ > + virtio_byteswap = virtio_get_byteswap(); > + > if (k->reset) { > k->reset(vdev); > }
In the previous version it was pointed out that the global is nasty. A cleaner solution is a per-VirtIODevice enum device_endian value which gets passed to lduw_phys_internal()/stl_phys_internal()/etc. Now the same code can be used for: 1. Host == guest-endian 2. Host != guest-endian 3. "Everything is little-endian" (VIRTIO 1.0) Keeping it per-device means we can have both legacy and VIRTIO 1.0 devices in a guest. That's better than hacking in a global now and having to undo it when VIRTIO 1.0 support gets merged. Stefan