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

Nikunj A Dadhania nikunj at linux.vnet.ibm.com
Fri Jan 29 22:19:21 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 +++++++++++++++++++++++++++++++++++++++++
 lib/libvirtio/virtio.h          |  1 -
 2 files changed, 48 insertions(+), 1 deletion(-)
 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 */
diff --git a/lib/libvirtio/virtio.h b/lib/libvirtio/virtio.h
index 0fee4ba..54d91b8 100644
--- a/lib/libvirtio/virtio.h
+++ b/lib/libvirtio/virtio.h
@@ -124,5 +124,4 @@ extern uint64_t virtio_get_config(struct virtio_device *dev, int offset, int siz
 extern int __virtio_read_config(struct virtio_device *dev, void *dst,
 				int offset, int len);
 
-
 #endif /* _LIBVIRTIO_H */
-- 
2.5.0



More information about the SLOF mailing list