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 }
28 
29 static inline void
30 virtio_gpu_bswap_32(void *ptr, size_t size)
31 {
32 #ifdef HOST_WORDS_BIGENDIAN
33 
34     size_t i;
35     struct virtio_gpu_ctrl_hdr *hdr = (struct virtio_gpu_ctrl_hdr *) ptr;
36 
37     virtio_gpu_ctrl_hdr_bswap(hdr);
38 
39     i = sizeof(struct virtio_gpu_ctrl_hdr);
40     while (i < size) {
41         le32_to_cpus((uint32_t *)(ptr + i));
42         i = i + sizeof(uint32_t);
43     }
44 
45 #endif
46 }
47 
48 static inline void
49 virtio_gpu_t2d_bswap(struct virtio_gpu_transfer_to_host_2d *t2d)
50 {
51     virtio_gpu_ctrl_hdr_bswap(&t2d->hdr);
52     le32_to_cpus(&t2d->r.x);
53     le32_to_cpus(&t2d->r.y);
54     le32_to_cpus(&t2d->r.width);
55     le32_to_cpus(&t2d->r.height);
56     le64_to_cpus(&t2d->offset);
57     le32_to_cpus(&t2d->resource_id);
58     le32_to_cpus(&t2d->padding);
59 }
60 
61 static inline void
62 virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_create_blob *cblob)
63 {
64     virtio_gpu_ctrl_hdr_bswap(&cblob->hdr);
65     le32_to_cpus(&cblob->resource_id);
66     le32_to_cpus(&cblob->blob_flags);
67     le64_to_cpus(&cblob->size);
68 }
69 
70 static inline void
71 virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb)
72 {
73     virtio_gpu_bswap_32(ssb, sizeof(*ssb) - sizeof(ssb->offsets[3]));
74     le32_to_cpus(&ssb->offsets[3]);
75 }
76 
77 #endif
78