virtio_config: endian conversion for v1.0
authorMichael S. Tsirkin <mst@redhat.com>
Wed, 22 Oct 2014 13:59:01 +0000 (16:59 +0300)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 9 Dec 2014 10:05:25 +0000 (12:05 +0200)
We (ab)use virtio conversion functions for device-specific
config space accesses.

Based on original patches by Cornelia and Rusty.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.com>
include/linux/virtio_config.h

index 02f0acb549d6b5a1ad9c046a0ac33ff38894d304..1fa5faa264403dff14a046f3222fb61f5761a9f0 100644 (file)
@@ -318,12 +318,13 @@ static inline u16 virtio_cread16(struct virtio_device *vdev,
 {
        u16 ret;
        vdev->config->get(vdev, offset, &ret, sizeof(ret));
-       return ret;
+       return virtio16_to_cpu(vdev, (__force __virtio16)ret);
 }
 
 static inline void virtio_cwrite16(struct virtio_device *vdev,
                                   unsigned int offset, u16 val)
 {
+       val = (__force u16)cpu_to_virtio16(vdev, val);
        vdev->config->set(vdev, offset, &val, sizeof(val));
 }
 
@@ -332,12 +333,13 @@ static inline u32 virtio_cread32(struct virtio_device *vdev,
 {
        u32 ret;
        vdev->config->get(vdev, offset, &ret, sizeof(ret));
-       return ret;
+       return virtio32_to_cpu(vdev, (__force __virtio32)ret);
 }
 
 static inline void virtio_cwrite32(struct virtio_device *vdev,
                                   unsigned int offset, u32 val)
 {
+       val = (__force u32)cpu_to_virtio32(vdev, val);
        vdev->config->set(vdev, offset, &val, sizeof(val));
 }
 
@@ -346,12 +348,13 @@ static inline u64 virtio_cread64(struct virtio_device *vdev,
 {
        u64 ret;
        vdev->config->get(vdev, offset, &ret, sizeof(ret));
-       return ret;
+       return virtio64_to_cpu(vdev, (__force __virtio64)ret);
 }
 
 static inline void virtio_cwrite64(struct virtio_device *vdev,
                                   unsigned int offset, u64 val)
 {
+       val = (__force u64)cpu_to_virtio64(vdev, val);
        vdev->config->set(vdev, offset, &val, sizeof(val));
 }