← Prev in month ← Prev in thread
Next in thread → Next in month →

[PATCH 04/16] NOTE: For testing on lgeust/x86, these are BE conversions, not LE conversions!

From
Rusty Russell <>
Date
2013-09-12T10:30:04+00:00
ID
Thread
[PATCH 04/16] NOTE: For testing on lgeust/x86, these are BE conversions, not LE conversions!
From: Rusty Russell <>


Signed-off-by: Rusty Russell <>
---
 include/linux/virtio.h | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 2c3cbd4..a1cf62d 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -153,4 +153,38 @@ void unregister_virtio_driver(struct virtio_driver *drv);
 #define module_virtio_driver(__virtio_driver) \
 	module_driver(__virtio_driver, register_virtio_driver, \
 			unregister_virtio_driver)
+
+/* v1.0 specifies LE headers, legacy was native endian.  So don't use these
+ * if virtio_device_legacy(vdev)!
+ */
+/* THESE ARE BIG_ENDIAN JUST TO TEST!!! */
+static inline u16 virtio_to_cpu_u16(const struct virtio_device *vdev, u16 v)
+{
+	return virtio_device_legacy(vdev) ? v : be16_to_cpu(v);
+}
+
+static inline u32 virtio_to_cpu_u32(const struct virtio_device *vdev, u32 v)
+{
+	return virtio_device_legacy(vdev) ? v : be32_to_cpu(v);
+}
+
+static inline u64 virtio_to_cpu_u64(const struct virtio_device *vdev, u64 v)
+{
+	return virtio_device_legacy(vdev) ? v : be64_to_cpu(v);
+}
+
+static inline u16 cpu_to_virtio_u16(const struct virtio_device *vdev, u16 v)
+{
+	return virtio_device_legacy(vdev) ? v : cpu_to_be16(v);
+}
+
+static inline u32 cpu_to_virtio_u32(const struct virtio_device *vdev, u32 v)
+{
+	return virtio_device_legacy(vdev) ? v : cpu_to_be32(v);
+}
+
+static inline u64 cpu_to_virtio_u64(const struct virtio_device *vdev, u64 v)
+{
+	return virtio_device_legacy(vdev) ? v : cpu_to_be64(v);
+}
 #endif /* _LINUX_VIRTIO_H */
-- 
1.8.1.2
← Prev in month ← Prev in thread
Next in thread → Next in month →