Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/284072/?format=api
{ "id": 284072, "url": "http://patchwork.ozlabs.org/api/patches/284072/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1381982022-19291-2-git-send-email-rusty@rustcorp.com.au/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<1381982022-19291-2-git-send-email-rusty@rustcorp.com.au>", "list_archive_url": null, "date": "2013-10-17T03:53:36", "name": "[1/7] virtio_get_byteswap: function for endian-ambivalent targets using virtio.", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "820bde25f5b4d33de0a1ac25fd09b53865b80421", "submitter": { "id": 553, "url": "http://patchwork.ozlabs.org/api/people/553/?format=api", "name": "Rusty Russell", "email": "rusty@rustcorp.com.au" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1381982022-19291-2-git-send-email-rusty@rustcorp.com.au/mbox/", "series": [], "comments": "http://patchwork.ozlabs.org/api/patches/284072/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/284072/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Received": [ "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(Client did not present a certificate)\n\tby ozlabs.org (Postfix) with ESMTPS id 956842C008C\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 17 Oct 2013 14:59:36 +1100 (EST)", "from localhost ([::1]:50206 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1VWekI-0007av-8b\n\tfor incoming@patchwork.ozlabs.org; Wed, 16 Oct 2013 23:59:34 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:59618)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <rusty@ozlabs.org>) id 1VWeji-0007aa-OJ\n\tfor qemu-devel@nongnu.org; Wed, 16 Oct 2013 23:59:00 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <rusty@ozlabs.org>) id 1VWejh-0001EY-FR\n\tfor qemu-devel@nongnu.org; Wed, 16 Oct 2013 23:58:58 -0400", "from ozlabs.org ([2402:b800:7003:1:1::1]:40896)\n\tby eggs.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <rusty@ozlabs.org>) id 1VWejg-0001DW-SD\n\tfor qemu-devel@nongnu.org; Wed, 16 Oct 2013 23:58:57 -0400", "by ozlabs.org (Postfix, from userid 1011)\n\tid AB58E2C00CB; Thu, 17 Oct 2013 14:58:50 +1100 (EST)" ], "From": "Rusty Russell <rusty@rustcorp.com.au>", "To": "\"Marc Zyngier\" <marc.zyngier@arm.com>,\n\tqemu-devel@nongnu.org", "Date": "Thu, 17 Oct 2013 14:23:36 +1030", "Message-Id": "<1381982022-19291-2-git-send-email-rusty@rustcorp.com.au>", "X-Mailer": "git-send-email 1.8.1.2", "In-Reply-To": "<1381982022-19291-1-git-send-email-rusty@rustcorp.com.au>", "References": "<1381982022-19291-1-git-send-email-rusty@rustcorp.com.au>", "X-detected-operating-system": "by eggs.gnu.org: Error: Malformed IPv6 address\n\t(bad octet value).", "X-Received-From": "2402:b800:7003:1:1::1", "Cc": "Rusty Russell <rusty@rustcorp.com.au>", "Subject": "[Qemu-devel] [PATCH 1/7] virtio_get_byteswap: function for\n\tendian-ambivalent targets using virtio.", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.14", "Precedence": "list", "List-Id": "<qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "virtio data structures are defined as \"target endian\", which assumes\nthat's a fixed value. In fact, that actually means it's\nplatform-specific.\n\nThe OASIS virtio 1.0 spec will fix this. Meanwhile, create a hook for\nlittle endian ppc (and potentially ARM). This is called at device\nreset time (which is done before any driver is loaded) since it\nmay involve a system call to get the status when running under kvm.\n\nSigned-off-by: Rusty Russell <rusty@rustcorp.com.au>\n---\n hw/virtio/virtio.c | 6 ++\n include/hw/virtio/virtio-access.h | 133 ++++++++++++++++++++++++++++++++++++++\n include/hw/virtio/virtio.h | 2 +\n stubs/Makefile.objs | 1 +\n stubs/virtio_get_byteswap.c | 6 ++\n 5 files changed, 148 insertions(+)\n create mode 100644 include/hw/virtio/virtio-access.h\n create mode 100644 stubs/virtio_get_byteswap.c", "diff": "diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c\nindex 2f1e73b..7730780 100644\n--- a/hw/virtio/virtio.c\n+++ b/hw/virtio/virtio.c\n@@ -18,6 +18,9 @@\n #include \"hw/virtio/virtio.h\"\n #include \"qemu/atomic.h\"\n #include \"hw/virtio/virtio-bus.h\"\n+#include \"hw/virtio/virtio-access.h\"\n+\n+bool virtio_byteswap = false;\n \n /*\n * The alignment to use between consumer and producer parts of vring.\n@@ -543,6 +546,9 @@ void virtio_reset(void *opaque)\n \n virtio_set_status(vdev, 0);\n \n+ /* We assume all devices are the same endian. */\n+ virtio_byteswap = virtio_get_byteswap();\n+\n if (k->reset) {\n k->reset(vdev);\n }\ndiff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h\nnew file mode 100644\nindex 0000000..2263c9c\n--- /dev/null\n+++ b/include/hw/virtio/virtio-access.h\n@@ -0,0 +1,133 @@\n+/*\n+ * Virtio Accessor Support: In case your target can change endian.\n+ *\n+ * Copyright IBM, Corp. 2013\n+ *\n+ * Authors:\n+ * Rusty Russell <rusty@au.ibm.com>\n+ *\n+ * This work is licensed under the terms of the GNU GPL, version 2. See\n+ * the COPYING file in the top-level directory.\n+ *\n+ */\n+#ifndef _QEMU_VIRTIO_ACCESS_H\n+#define _QEMU_VIRTIO_ACCESS_H\n+#include \"hw/virtio/virtio.h\"\n+\n+/* Initialized by virtio_get_byteswap() at any virtio device reset. */\n+extern bool virtio_byteswap;\n+\n+static inline uint16_t virtio_lduw_phys(hwaddr pa)\n+{\n+ if (virtio_byteswap) {\n+ return bswap16(lduw_phys(pa));\n+ }\n+ return lduw_phys(pa);\n+ \n+}\n+\n+static inline uint32_t virtio_ldl_phys(hwaddr pa)\n+{\n+ if (virtio_byteswap) {\n+ return bswap32(ldl_phys(pa));\n+ }\n+ return ldl_phys(pa);\n+}\n+\n+static inline uint64_t virtio_ldq_phys(hwaddr pa)\n+{\n+ if (virtio_byteswap) {\n+ return bswap64(ldq_phys(pa));\n+ }\n+ return ldq_phys(pa);\n+}\n+\n+static inline void virtio_stw_phys(hwaddr pa, uint16_t value)\n+{\n+ if (virtio_byteswap) {\n+ stw_phys(pa, bswap16(value));\n+ } else {\n+ stw_phys(pa, value);\n+ }\n+}\n+\n+static inline void virtio_stl_phys(hwaddr pa, uint32_t value)\n+{\n+ if (virtio_byteswap) {\n+ stl_phys(pa, bswap32(value));\n+ } else {\n+ stl_phys(pa, value);\n+ }\n+}\n+\n+static inline void virtio_stw_p(void *ptr, uint16_t v)\n+{\n+ if (virtio_byteswap) {\n+ stw_p(ptr, bswap16(v));\n+ } else {\n+ stw_p(ptr, v);\n+ }\n+}\n+\n+static inline void virtio_stl_p(void *ptr, uint32_t v)\n+{\n+ if (virtio_byteswap) {\n+ stl_p(ptr, bswap32(v));\n+ } else {\n+ stl_p(ptr, v);\n+ }\n+}\n+\n+static inline void virtio_stq_p(void *ptr, uint64_t v)\n+{\n+ if (virtio_byteswap) {\n+ stq_p(ptr, bswap64(v));\n+ } else {\n+ stq_p(ptr, v);\n+ }\n+}\n+\n+static inline int virtio_lduw_p(const void *ptr)\n+{\n+ if (virtio_byteswap) {\n+ return bswap16(lduw_p(ptr));\n+ } else {\n+ return lduw_p(ptr);\n+ }\n+}\n+\n+static inline int virtio_ldl_p(const void *ptr)\n+{\n+ if (virtio_byteswap) {\n+ return bswap32(ldl_p(ptr));\n+ } else {\n+ return ldl_p(ptr);\n+ }\n+}\n+\n+static inline uint64_t virtio_ldq_p(const void *ptr)\n+{\n+ if (virtio_byteswap) {\n+ return bswap64(ldq_p(ptr));\n+ } else {\n+ return ldq_p(ptr);\n+ }\n+}\n+\n+static inline uint32_t virtio_tswap32(uint32_t s)\n+{\n+ if (virtio_byteswap) {\n+ return bswap32(tswap32(s));\n+ } else {\n+ return tswap32(s);\n+ }\n+}\n+\n+static inline void virtio_tswap32s(uint32_t *s)\n+{\n+ tswap32s(s);\n+ if (virtio_byteswap) {\n+ *s = bswap32(*s);\n+ }\n+}\n+#endif /* _QEMU_VIRTIO_ACCESS_H */\ndiff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h\nindex a90522d..065e1d9 100644\n--- a/include/hw/virtio/virtio.h\n+++ b/include/hw/virtio/virtio.h\n@@ -249,4 +249,6 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,\n bool set_handler);\n void virtio_queue_notify_vq(VirtQueue *vq);\n void virtio_irq(VirtQueue *vq);\n+\n+extern bool virtio_get_byteswap(void);\n #endif\ndiff --git a/stubs/Makefile.objs b/stubs/Makefile.objs\nindex df92fe5..7e7a9c8 100644\n--- a/stubs/Makefile.objs\n+++ b/stubs/Makefile.objs\n@@ -27,3 +27,4 @@ stub-obj-y += vm-stop.o\n stub-obj-y += vmstate.o\n stub-obj-$(CONFIG_WIN32) += fd-register.o\n stub-obj-y += cpus.o\n+stub-obj-y += virtio_get_byteswap.o\ndiff --git a/stubs/virtio_get_byteswap.c b/stubs/virtio_get_byteswap.c\nnew file mode 100644\nindex 0000000..7cf764d\n--- /dev/null\n+++ b/stubs/virtio_get_byteswap.c\n@@ -0,0 +1,6 @@\n+#include \"hw/virtio/virtio.h\"\n+\n+bool virtio_get_byteswap(void)\n+{\n+ return false;\n+}\n", "prefixes": [ "1/7" ] }