aboutsummaryrefslogtreecommitdiff
path: root/lib/libvirtio/virtio-internal.h
blob: fe59c6b9909dfa442ccfafb4a2d096c1e51191c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/******************************************************************************
 * Copyright (c) 2016 IBM Corporation
 * All rights reserved.
 * This program and the accompanying materials
 * are made available under the terms of the BSD License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * Contributors:
 *     IBM Corporation - initial implementation
 *****************************************************************************/

#ifndef _LIBVIRTIO_INTERNAL_H
#define _LIBVIRTIO_INTERNAL_H

#include <byteorder.h>

static inline uint16_t virtio_cpu_to_modern16(struct virtio_device *dev, uint16_t val)
{
	return (dev->features & VIRTIO_F_VERSION_1) ? cpu_to_le16(val) : val;
}

static inline uint32_t virtio_cpu_to_modern32(struct virtio_device *dev, uint32_t val)
{
	return (dev->features & VIRTIO_F_VERSION_1) ? cpu_to_le32(val) : val;
}

static inline uint64_t virtio_cpu_to_modern64(struct virtio_device *dev, uint64_t val)
{
	return (dev->features & VIRTIO_F_VERSION_1) ? cpu_to_le64(val) : val;
}

static inline uint16_t virtio_modern16_to_cpu(struct virtio_device *dev, uint16_t val)
{
	return (dev->features & VIRTIO_F_VERSION_1) ? le16_to_cpu(val) : val;
}

static inline uint32_t virtio_modern32_to_cpu(struct virtio_device *dev, uint32_t val)
{
	return (dev->features & VIRTIO_F_VERSION_1) ? le32_to_cpu(val) : val;
}

static inline uint64_t virtio_modern64_to_cpu(struct virtio_device *dev, uint64_t val)
{
	return (dev->features & VIRTIO_F_VERSION_1) ? le64_to_cpu(val) : val;
}

#endif /* _LIBVIRTIO_INTERNAL_H */