[SLOF] [PATCH v4 21/23] virtio: 1.0 helper to read 16/32/64 bit value
Nikunj A Dadhania
nikunj at linux.vnet.ibm.com
Thu Jan 28 21:24:22 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
Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
Suggested-by: Thomas Huth <thuth at redhat.com>
---
lib/libvirtio/virtio.c | 30 ++++++++++++++++++++++++++++++
lib/libvirtio/virtio.h | 6 ++++++
2 files changed, 36 insertions(+)
diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c
index fda6c8f..19708da 100644
--- a/lib/libvirtio/virtio.c
+++ b/lib/libvirtio/virtio.c
@@ -107,6 +107,36 @@ static uint64_t virtio_pci_read64(void *addr)
return (hi << 32) | lo;
}
+uint16_t virtio_cpu_to_modern16(struct virtio_device *dev, uint16_t val)
+{
+ return dev->is_modern ? cpu_to_le16(val) : val;
+}
+
+uint32_t virtio_cpu_to_modern32(struct virtio_device *dev, uint32_t val)
+{
+ return dev->is_modern ? cpu_to_le32(val) : val;
+}
+
+uint64_t virtio_cpu_to_modern64(struct virtio_device *dev, uint64_t val)
+{
+ return dev->is_modern ? cpu_to_le64(val) : val;
+}
+
+uint16_t virtio_modern16_to_cpu(struct virtio_device *dev, uint16_t val)
+{
+ return dev->is_modern ? le16_to_cpu(val) : val;
+}
+
+uint32_t virtio_modern32_to_cpu(struct virtio_device *dev, uint32_t val)
+{
+ return dev->is_modern ? le32_to_cpu(val) : val;
+}
+
+uint64_t virtio_modern64_to_cpu(struct virtio_device *dev, uint64_t val)
+{
+ return dev->is_modern ? le64_to_cpu(val) : val;
+}
+
static void virtio_cap_set_base_addr(struct virtio_cap *cap, uint32_t offset)
{
uint64_t addr;
diff --git a/lib/libvirtio/virtio.h b/lib/libvirtio/virtio.h
index 1cbc804..1452d9b 100644
--- a/lib/libvirtio/virtio.h
+++ b/lib/libvirtio/virtio.h
@@ -126,5 +126,11 @@ 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);
+extern uint16_t virtio_cpu_to_modern16(struct virtio_device *dev, uint16_t val);
+extern uint32_t virtio_cpu_to_modern32(struct virtio_device *dev, uint32_t val);
+extern uint64_t virtio_cpu_to_modern64(struct virtio_device *dev, uint64_t val);
+extern uint16_t virtio_modern16_to_cpu(struct virtio_device *dev, uint16_t val);
+extern uint32_t virtio_modern32_to_cpu(struct virtio_device *dev, uint32_t val);
+extern uint64_t virtio_modern64_to_cpu(struct virtio_device *dev, uint64_t val);
#endif /* _LIBVIRTIO_H */
--
2.5.0
More information about the SLOF
mailing list