diff options
author | Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> | 2016-02-01 11:18:11 +0530 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2016-02-08 16:40:39 +1100 |
commit | 9d4ff9d75cb483f7b8da30506859c83b45af4913 (patch) | |
tree | bd2100db3a3ef42800bc7a81952d001443cab7b5 /lib | |
parent | f83299621cde03cd406cbb665fc5eb1f348afc9b (diff) | |
download | SLOF-9d4ff9d75cb483f7b8da30506859c83b45af4913.zip SLOF-9d4ff9d75cb483f7b8da30506859c83b45af4913.tar.gz SLOF-9d4ff9d75cb483f7b8da30506859c83b45af4913.tar.bz2 |
virtio: 1.0 helper to read 16/32/64 bit value
To avoid cluttering the driver code with modern/legacy code introduce
virtio_cpu_to_modern{16,32,64} and virtio_modern{16,32,64}_to_cpu in a
separate header file virtio-internal.h.
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Suggested-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libvirtio/virtio-internal.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/libvirtio/virtio-internal.h b/lib/libvirtio/virtio-internal.h new file mode 100644 index 0000000..08662ea --- /dev/null +++ b/lib/libvirtio/virtio-internal.h @@ -0,0 +1,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->is_modern ? cpu_to_le16(val) : val; +} + +static inline uint32_t virtio_cpu_to_modern32(struct virtio_device *dev, uint32_t val) +{ + return dev->is_modern ? cpu_to_le32(val) : val; +} + +static inline uint64_t virtio_cpu_to_modern64(struct virtio_device *dev, uint64_t val) +{ + return dev->is_modern ? cpu_to_le64(val) : val; +} + +static inline uint16_t virtio_modern16_to_cpu(struct virtio_device *dev, uint16_t val) +{ + return dev->is_modern ? le16_to_cpu(val) : val; +} + +static inline uint32_t virtio_modern32_to_cpu(struct virtio_device *dev, uint32_t val) +{ + return dev->is_modern ? le32_to_cpu(val) : val; +} + +static inline uint64_t virtio_modern64_to_cpu(struct virtio_device *dev, uint64_t val) +{ + return dev->is_modern ? le64_to_cpu(val) : val; +} + +#endif /* _LIBVIRTIO_INTERNAL_H */ |