1 /*
2  * Virtio GPU Device
3  *
4  * Copyright Red Hat, Inc. 2013-2014
5  *
6  * Authors:
7  *     Dave Airlie <airlied@redhat.com>
8  *     Gerd Hoffmann <kraxel@redhat.com>
9  *
10  * This work is licensed under the terms of the GNU GPL, version 2 or later.
11  * See the COPYING file in the top-level directory.
12  */
13 
14 #ifndef HW_VIRTIO_GPU_BSWAP_H
15 #define HW_VIRTIO_GPU_BSWAP_H
16 
17 #include "qemu/bswap.h"
18 #include "standard-headers/linux/virtio_gpu.h"
19 
20 static inline void
21 virtio_gpu_ctrl_hdr_bswap(struct virtio_gpu_ctrl_hdr *hdr)
22 {
23     le32_to_cpus(&hdr->type);
24     le32_to_cpus(&hdr->flags);
25     le64_to_cpus(&hdr->fence_id);
26     le32_to_cpus(&hdr->ctx_id);
27     le32_to_cpus(&hdr->padding);
28 }
29 
30 static inline void
31 virtio_gpu_bswap_32(void *ptr, size_t size)
32 {
33 #ifdef HOST_WORDS_BIGENDIAN
34 
35     size_t i;
36     struct virtio_gpu_ctrl_hdr *hdr = (struct virtio_gpu_ctrl_hdr *) ptr;
37 
38     virtio_gpu_ctrl_hdr_bswap(hdr);
39 
40     i = sizeof(struct virtio_gpu_ctrl_hdr);
41     while (i < size) {
42         le32_to_cpus((uint32_t *)(ptr + i));
43         i = i + sizeof(uint32_t);
44     }
45 
46 #endif
47 }
48 
49 static inline void
50 virtio_gpu_t2d_bswap(struct virtio_gpu_transfer_to_host_2d *t2d)
51 {
52     virtio_gpu_ctrl_hdr_bswap(&t2d->hdr);
53     le32_to_cpus(&t2d->r.x);
54     le32_to_cpus(&t2d->r.y);
55     le32_to_cpus(&t2d->r.width);
56     le32_to_cpus(&t2d->r.height);
57     le64_to_cpus(&t2d->offset);
58     le32_to_cpus(&t2d->resource_id);
59     le32_to_cpus(&t2d->padding);
60 }
61 
62 static inline void
63 virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_create_blob *cblob)
64 {
65     virtio_gpu_ctrl_hdr_bswap(&cblob->hdr);
66     le32_to_cpus(&cblob->resource_id);
67     le32_to_cpus(&cblob->blob_flags);
68     le64_to_cpus(&cblob->size);
69 }
70 
71 static inline void
72 virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb)
73 {
74     virtio_gpu_bswap_32(ssb, sizeof(*ssb) - sizeof(ssb->offsets[3]));
75     le32_to_cpus(&ssb->offsets[3]);
76 }
77 
78 #endif
79