All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Rusty Russell" <rusty@rustcorp.com.au>,
	"Alexander Graf" <agraf@suse.de>,
	=?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@fr.ibm.com>,
	"Anthony Liguori" <aliguori@amazon.com>,
	"Greg Kurz" <gkurz@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PULL 27/37] virtio: memory accessors for endian-ambivalent targets
Date: Sun, 29 Jun 2014 19:59:38 +0300	[thread overview]
Message-ID: <1404060115-27410-28-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1404060115-27410-1-git-send-email-mst@redhat.com>

From: Greg Kurz <gkurz@linux.vnet.ibm.com>

This is the virtio-access.h header file taken from Rusty's "endian-ambivalent
targets using legacy virtio" patch. It introduces helpers that should be used
when accessing vring data or by drivers for data that contains headers.
The virtio config space is also target endian, but the current code already
handles that with the virtio_is_big_endian() helper. There is no obvious
benefit at using the virtio accessors in this case.

Now we have two distinct paths: a fast inline one for fixed endian targets,
and a slow out-of-line one for targets that define the new TARGET_IS_BIENDIAN
macro.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
[ relicensed virtio-access.h to GPLv2+ on Rusty's request,
  pass &address_space_memory to physical memory accessors,
  per-device endianness,
  virtio tswap16 and tswap64 helpers,
  faspath for fixed endian targets,
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
Cc: Cédric Le Goater <clg@fr.ibm.com>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/virtio/virtio-access.h | 170 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 170 insertions(+)
 create mode 100644 include/hw/virtio/virtio-access.h

diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h
new file mode 100644
index 0000000..46456fd
--- /dev/null
+++ b/include/hw/virtio/virtio-access.h
@@ -0,0 +1,170 @@
+/*
+ * Virtio Accessor Support: In case your target can change endian.
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Rusty Russell   <rusty@au.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+#ifndef _QEMU_VIRTIO_ACCESS_H
+#define _QEMU_VIRTIO_ACCESS_H
+#include "hw/virtio/virtio.h"
+#include "exec/address-spaces.h"
+
+static inline bool virtio_access_is_big_endian(VirtIODevice *vdev)
+{
+#if defined(TARGET_IS_BIENDIAN)
+    return virtio_is_big_endian(vdev);
+#elif defined(TARGET_WORDS_BIGENDIAN)
+    return true;
+#else
+    return false;
+#endif
+}
+
+static inline uint16_t virtio_lduw_phys(VirtIODevice *vdev, hwaddr pa)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        return lduw_be_phys(&address_space_memory, pa);
+    }
+    return lduw_le_phys(&address_space_memory, pa);
+}
+
+static inline uint32_t virtio_ldl_phys(VirtIODevice *vdev, hwaddr pa)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        return ldl_be_phys(&address_space_memory, pa);
+    }
+    return ldl_le_phys(&address_space_memory, pa);
+}
+
+static inline uint64_t virtio_ldq_phys(VirtIODevice *vdev, hwaddr pa)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        return ldq_be_phys(&address_space_memory, pa);
+    }
+    return ldq_le_phys(&address_space_memory, pa);
+}
+
+static inline void virtio_stw_phys(VirtIODevice *vdev, hwaddr pa,
+                                   uint16_t value)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        stw_be_phys(&address_space_memory, pa, value);
+    } else {
+        stw_le_phys(&address_space_memory, pa, value);
+    }
+}
+
+static inline void virtio_stl_phys(VirtIODevice *vdev, hwaddr pa,
+                                   uint32_t value)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        stl_be_phys(&address_space_memory, pa, value);
+    } else {
+        stl_le_phys(&address_space_memory, pa, value);
+    }
+}
+
+static inline void virtio_stw_p(VirtIODevice *vdev, void *ptr, uint16_t v)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        stw_be_p(ptr, v);
+    } else {
+        stw_le_p(ptr, v);
+    }
+}
+
+static inline void virtio_stl_p(VirtIODevice *vdev, void *ptr, uint32_t v)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        stl_be_p(ptr, v);
+    } else {
+        stl_le_p(ptr, v);
+    }
+}
+
+static inline void virtio_stq_p(VirtIODevice *vdev, void *ptr, uint64_t v)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        stq_be_p(ptr, v);
+    } else {
+        stq_le_p(ptr, v);
+    }
+}
+
+static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        return lduw_be_p(ptr);
+    } else {
+        return lduw_le_p(ptr);
+    }
+}
+
+static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        return ldl_be_p(ptr);
+    } else {
+        return ldl_le_p(ptr);
+    }
+}
+
+static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, const void *ptr)
+{
+    if (virtio_access_is_big_endian(vdev)) {
+        return ldq_be_p(ptr);
+    } else {
+        return ldq_le_p(ptr);
+    }
+}
+
+static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s)
+{
+#ifdef HOST_WORDS_BIGENDIAN
+    return virtio_access_is_big_endian(vdev) ? s : bswap16(s);
+#else
+    return virtio_access_is_big_endian(vdev) ? bswap16(s) : s;
+#endif
+}
+
+static inline void virtio_tswap16s(VirtIODevice *vdev, uint16_t *s)
+{
+    *s = virtio_tswap16(vdev, *s);
+}
+
+static inline uint32_t virtio_tswap32(VirtIODevice *vdev, uint32_t s)
+{
+#ifdef HOST_WORDS_BIGENDIAN
+    return virtio_access_is_big_endian(vdev) ? s : bswap32(s);
+#else
+    return virtio_access_is_big_endian(vdev) ? bswap32(s) : s;
+#endif
+}
+
+static inline void virtio_tswap32s(VirtIODevice *vdev, uint32_t *s)
+{
+    *s = virtio_tswap32(vdev, *s);
+}
+
+static inline uint64_t virtio_tswap64(VirtIODevice *vdev, uint64_t s)
+{
+#ifdef HOST_WORDS_BIGENDIAN
+    return virtio_access_is_big_endian(vdev) ? s : bswap64(s);
+#else
+    return virtio_access_is_big_endian(vdev) ? bswap64(s) : s;
+#endif
+}
+
+static inline void virtio_tswap64s(VirtIODevice *vdev, uint64_t *s)
+{
+    *s = virtio_tswap64(vdev, *s);
+}
+#endif /* _QEMU_VIRTIO_ACCESS_H */
-- 
MST

  parent reply	other threads:[~2014-06-29 16:59 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-29 16:58 [Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 01/37] numa: fix comment Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 02/37] openrisc: " Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 03/37] numa: " Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 04/37] pc: Move q35 compat props to PC_COMPAT_* Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 05/37] pc: Fix "prog_if" typo on PC_COMPAT_2_0 Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 06/37] mc146818rtc: add rtc-reset-reinjection QMP command Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 07/37] vhost-user: fix wrong ids in documentation Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 08/37] pc: make isapc and pc-0.10 to pc-0.13 have 1.7.0 memory layout Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 09/37] Allow mismatched virtio config-len Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 10/37] numa: Keep track of NUMA nodes present on the command-line Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 11/37] numa: Reject duplicate node IDs Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 12/37] numa: Reject configuration if not all node IDs are present Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 13/37] vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 14/37] vhost-user: typo fixups Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 15/37] virtio-net: byteswap virtio-net header Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 16/37] virtio-serial: don't migrate the config space Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 17/37] virtio: introduce device specific migration calls Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 18/37] virtio-net: implement per-device " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 19/37] virtio-blk: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 20/37] virtio-serial: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 21/37] virtio-balloon: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 22/37] virtio-rng: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 23/37] virtio: add subsections to the migration stream Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 24/37] exec: introduce target_words_bigendian() helper Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 25/37] cpu: introduce CPUClass::virtio_is_big_endian() Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 26/37] virtio: add endian-ambivalent support to VirtIODevice Michael S. Tsirkin
2014-06-29 16:59 ` Michael S. Tsirkin [this message]
2014-06-29 16:59 ` [Qemu-devel] [PULL 28/37] virtio: allow byte swapping for vring Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 29/37] virtio-net: use virtio wrappers to access headers Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 30/37] virtio-balloon: use virtio wrappers to access page frame numbers Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 31/37] virtio-blk: use virtio wrappers to access headers Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 32/37] virtio-scsi: " Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 33/37] virtio-serial-bus: " Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 34/37] virtio-9p: " Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 35/37] target-ppc: enable virtio endian ambivalent support Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 36/37] vhost-net: disable when cross-endian Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 37/37] tests: add human format test for string output visitor Michael S. Tsirkin
2014-07-09 19:14   ` Andreas Färber
2014-07-09 19:34     ` Peter Maydell
2014-06-29 17:36 ` [Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements Peter Maydell
2014-06-29 20:34   ` Michael S. Tsirkin
2014-06-29 20:41     ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404060115-27410-28-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=agraf@suse.de \
    --cc=aliguori@amazon.com \
    --cc=clg@fr.ibm.com \
    --cc=gkurz@linux.vnet.ibm.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.