NVMe: Only release requested regions
[linux-2.6-block.git] / include / linux / virtio_byteorder.h
CommitLineData
eef960a0
MT
1#ifndef _LINUX_VIRTIO_BYTEORDER_H
2#define _LINUX_VIRTIO_BYTEORDER_H
3#include <linux/types.h>
4#include <uapi/linux/virtio_types.h>
5
7d824109
GK
6static inline bool virtio_legacy_is_little_endian(void)
7{
8#ifdef __LITTLE_ENDIAN
9 return true;
10#else
11 return false;
12#endif
13}
eef960a0
MT
14
15static inline u16 __virtio16_to_cpu(bool little_endian, __virtio16 val)
16{
17 if (little_endian)
18 return le16_to_cpu((__force __le16)val);
19 else
7d824109 20 return be16_to_cpu((__force __be16)val);
eef960a0
MT
21}
22
23static inline __virtio16 __cpu_to_virtio16(bool little_endian, u16 val)
24{
25 if (little_endian)
26 return (__force __virtio16)cpu_to_le16(val);
27 else
7d824109 28 return (__force __virtio16)cpu_to_be16(val);
eef960a0
MT
29}
30
31static inline u32 __virtio32_to_cpu(bool little_endian, __virtio32 val)
32{
33 if (little_endian)
34 return le32_to_cpu((__force __le32)val);
35 else
7d824109 36 return be32_to_cpu((__force __be32)val);
eef960a0
MT
37}
38
39static inline __virtio32 __cpu_to_virtio32(bool little_endian, u32 val)
40{
41 if (little_endian)
42 return (__force __virtio32)cpu_to_le32(val);
43 else
7d824109 44 return (__force __virtio32)cpu_to_be32(val);
eef960a0
MT
45}
46
47static inline u64 __virtio64_to_cpu(bool little_endian, __virtio64 val)
48{
49 if (little_endian)
50 return le64_to_cpu((__force __le64)val);
51 else
7d824109 52 return be64_to_cpu((__force __be64)val);
eef960a0
MT
53}
54
55static inline __virtio64 __cpu_to_virtio64(bool little_endian, u64 val)
56{
57 if (little_endian)
58 return (__force __virtio64)cpu_to_le64(val);
59 else
7d824109 60 return (__force __virtio64)cpu_to_be64(val);
eef960a0
MT
61}
62
63#endif /* _LINUX_VIRTIO_BYTEORDER */