[SLOF] [PATCH v6 21/23] virtio: 1.0 helper to read 16/32/64 bit value

Nikunj A Dadhania nikunj at linux.vnet.ibm.com
Mon Feb 1 16:48:11 AEDT 2016


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 at linux.vnet.ibm.com>
Suggested-by: Thomas Huth <thuth at redhat.com>
Reviewed-by: Thomas Huth <thuth at redhat.com>
---
 lib/libvirtio/virtio-internal.h | 48 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 lib/libvirtio/virtio-internal.h

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 */
-- 
2.5.0



More information about the SLOF mailing list