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 19static inline void 20virtio_gpu_ctrl_hdr_bswap(struct virtio_gpu_ctrl_hdr *hdr) 21{ 22 le32_to_cpus(&hdr->type); 23 le32_to_cpus(&hdr->flags); 24 le64_to_cpus(&hdr->fence_id); 25 le32_to_cpus(&hdr->ctx_id); 26 le32_to_cpus(&hdr->padding); 27} 28 29static inline void 30virtio_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 48static inline void 49virtio_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#endif 62