From: David Gibson <david@gibson.dropbear.id.au>
To: "Cédric Le Goater" <clg@kaod.org>
Cc: Peter Maydell <peter.maydell@linaro.org>,
qemu-devel@nongnu.org, Greg Kurz <gkurz@linux.vnet.ibm.com>,
Laurent Vivier <lvivier@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] qtest: add read/write accessors with a specific endianness
Date: Wed, 5 Oct 2016 10:26:28 +1100 [thread overview]
Message-ID: <20161004232628.GD18648@umbus.fritz.box> (raw)
In-Reply-To: <1475583448-21013-1-git-send-email-clg@kaod.org>
[-- Attachment #1: Type: text/plain, Size: 7365 bytes --]
On Tue, Oct 04, 2016 at 02:17:28PM +0200, Cédric Le Goater wrote:
> Some test scenarios require to access memory regions using a specific
> endianness, such as a device region, but the current qtest memory
> accessors are done in native endian, which means that the values are
> byteswapped in qtest if the endianness of the guest and the host are
> different.
>
> To maintain the endianness of a value, we need a new set of memory
> accessor. This can be done in two ways:
>
> - first, convert the value to the required endianness in libqtest and
> then use the memread/write routines so that qtest accesses the guest
> memory without doing any supplementary byteswapping
>
> - an alternative method would be to handle the byte swapping on the
> qtest side. For that, we would need to extend the read/write
> protocol with an ending word : "native|le|be" and modify the tswap
> calls accordingly under the qtest_process_command() routine.
>
> The result is the same and the first method is simpler.
>
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---
>
> tests/libqtest.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> tests/libqtest.h | 71 ++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 162 insertions(+)
>
> Index: qemu-aspeed.git/tests/libqtest.h
> ===================================================================
> --- qemu-aspeed.git.orig/tests/libqtest.h
> +++ qemu-aspeed.git/tests/libqtest.h
> @@ -887,4 +887,75 @@ void qmp_fd_send(int fd, const char *fmt
> QDict *qmp_fdv(int fd, const char *fmt, va_list ap);
> QDict *qmp_fd(int fd, const char *fmt, ...);
>
> +/*
> + * BE/LE read/write accessors
> + */
> +uint16_t qtest_readw_be(QTestState *s, uint64_t addr);
> +uint32_t qtest_readl_be(QTestState *s, uint64_t addr);
> +uint64_t qtest_readq_be(QTestState *s, uint64_t addr);
> +
> +static inline uint16_t readw_be(uint64_t addr)
> +{
> + return qtest_readw_be(global_qtest, addr);
> +}
> +static inline uint32_t readl_be(uint64_t addr)
> +{
> + return qtest_readl_be(global_qtest, addr);
> +}
> +static inline uint64_t readq_be(uint64_t addr)
> +{
> + return qtest_readq_be(global_qtest, addr);
> +}
> +
> +void qtest_writew_be(QTestState *s, uint64_t addr, uint16_t value);
> +void qtest_writel_be(QTestState *s, uint64_t addr, uint32_t value);
> +void qtest_writeq_be(QTestState *s, uint64_t addr, uint64_t value);
> +
> +static inline void writew_be(uint64_t addr, uint16_t value)
> +{
> + qtest_writew_be(global_qtest, addr, value);
> +}
> +static inline void writel_be(uint64_t addr, uint32_t value)
> +{
> + qtest_writel_be(global_qtest, addr, value);
> +}
> +static inline void writeq_be(uint64_t addr, uint64_t value)
> +{
> + qtest_writeq_be(global_qtest, addr, value);
> +}
> +
> +uint16_t qtest_readw_le(QTestState *s, uint64_t addr);
> +uint32_t qtest_readl_le(QTestState *s, uint64_t addr);
> +uint64_t qtest_readq_le(QTestState *s, uint64_t addr);
> +
> +static inline uint16_t readw_le(uint64_t addr)
> +{
> + return qtest_readw_le(global_qtest, addr);
> +}
> +static inline uint32_t readl_le(uint64_t addr)
> +{
> + return qtest_readl_le(global_qtest, addr);
> +}
> +static inline uint64_t readq_le(uint64_t addr)
> +{
> + return qtest_readq_le(global_qtest, addr);
> +}
> +
> +void qtest_writew_le(QTestState *s, uint64_t addr, uint16_t value);
> +void qtest_writel_le(QTestState *s, uint64_t addr, uint32_t value);
> +void qtest_writeq_le(QTestState *s, uint64_t addr, uint64_t value);
> +
> +static inline void writew_le(uint64_t addr, uint16_t value)
> +{
> + qtest_writew_le(global_qtest, addr, value);
> +}
> +static inline void writel_le(uint64_t addr, uint32_t value)
> +{
> + qtest_writel_le(global_qtest, addr, value);
> +}
> +static inline void writeq_le(uint64_t addr, uint64_t value)
> +{
> + qtest_writeq_le(global_qtest, addr, value);
> +}
> +
> #endif
> Index: qemu-aspeed.git/tests/libqtest.c
> ===================================================================
> --- qemu-aspeed.git.orig/tests/libqtest.c
> +++ qemu-aspeed.git/tests/libqtest.c
> @@ -15,6 +15,7 @@
> *
> */
> #include "qemu/osdep.h"
> +#include "qemu/bswap.h"
> #include "libqtest.h"
>
> #include <sys/socket.h>
> @@ -688,6 +689,42 @@ void qtest_writeq(QTestState *s, uint64_
> qtest_write(s, "writeq", addr, value);
> }
>
> +void qtest_writew_be(QTestState *s, uint64_t addr, uint16_t value)
> +{
> + value = cpu_to_be16(value);
> + qtest_memread(s, addr, &value, sizeof(value));
Uh.. this surely needs to be qtest_memwrite().
> +}
> +
> +void qtest_writel_be(QTestState *s, uint64_t addr, uint32_t value)
> +{
> + value = cpu_to_be32(value);
> + qtest_memread(s, addr, &value, sizeof(value));
and here,
> +}
> +
> +void qtest_writeq_be(QTestState *s, uint64_t addr, uint64_t value)
> +{
> + value = cpu_to_be64(value);
> + qtest_memread(s, addr, &value, sizeof(value));
here
> +}
> +
> +void qtest_writew_le(QTestState *s, uint64_t addr, uint16_t value)
> +{
> + value = cpu_to_le16(value);
> + qtest_memread(s, addr, &value, sizeof(value));
here
> +}
> +
> +void qtest_writel_le(QTestState *s, uint64_t addr, uint32_t value)
> +{
> + value = cpu_to_le32(value);
> + qtest_memread(s, addr, &value, sizeof(value));
here
> +}
> +
> +void qtest_writeq_le(QTestState *s, uint64_t addr, uint64_t value)
> +{
> + value = cpu_to_le64(value);
> + qtest_memread(s, addr, &value, sizeof(value));
and here
> +}
> +
> static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr)
> {
> gchar **args;
> @@ -721,6 +758,60 @@ uint64_t qtest_readq(QTestState *s, uint
> return qtest_read(s, "readq", addr);
> }
>
> +uint16_t qtest_readw_be(QTestState *s, uint64_t addr)
> +{
> + uint16_t value;
> +
> + qtest_memread(s, addr, &value, sizeof(value));
> +
> + return be16_to_cpu(value);
> +}
> +
> +uint32_t qtest_readl_be(QTestState *s, uint64_t addr)
> +{
> + uint32_t value;
> +
> + qtest_memread(s, addr, &value, sizeof(value));
> +
> + return be32_to_cpu(value);
> +}
> +
> +uint64_t qtest_readq_be(QTestState *s, uint64_t addr)
> +{
> + uint64_t value;
> +
> + qtest_memread(s, addr, &value, sizeof(value));
> +
> + return be64_to_cpu(value);
> +}
> +
> +uint16_t qtest_readw_le(QTestState *s, uint64_t addr)
> +{
> + uint16_t value;
> +
> + qtest_memread(s, addr, &value, sizeof(value));
> +
> + return le16_to_cpu(value);
> +}
> +
> +uint32_t qtest_readl_le(QTestState *s, uint64_t addr)
> +{
> + uint32_t value;
> +
> + qtest_memread(s, addr, &value, sizeof(value));
> +
> + return le32_to_cpu(value);
> +}
> +
> +uint64_t qtest_readq_le(QTestState *s, uint64_t addr)
> +{
> + uint64_t value;
> +
> + qtest_memread(s, addr, &value, sizeof(value));
> +
> + return le64_to_cpu(value);
> +}
> +
> static int hex2nib(char ch)
> {
> if (ch >= '0' && ch <= '9') {
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2016-10-05 1:01 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-04 12:17 [Qemu-devel] [PATCH] qtest: add read/write accessors with a specific endianness Cédric Le Goater
2016-10-04 12:36 ` Peter Maydell
2016-10-04 14:04 ` Laurent Vivier
2016-10-04 14:07 ` Cédric Le Goater
2016-10-04 17:15 ` Paolo Bonzini
2016-10-04 23:43 ` David Gibson
2016-10-05 5:59 ` Cédric Le Goater
2016-10-05 12:31 ` Peter Maydell
2016-10-05 13:49 ` Cédric Le Goater
2016-10-05 13:53 ` Peter Maydell
2016-10-05 14:00 ` Cédric Le Goater
2016-10-05 14:20 ` Peter Maydell
2016-10-05 17:17 ` Cédric Le Goater
2016-10-05 17:32 ` Peter Maydell
2016-10-06 3:45 ` David Gibson
2016-10-06 7:23 ` Paolo Bonzini
2016-10-06 8:37 ` David Gibson
2016-10-06 9:40 ` Paolo Bonzini
2016-10-06 10:44 ` Cédric Le Goater
2016-10-06 10:47 ` Peter Maydell
2016-10-06 23:09 ` David Gibson
2016-10-06 3:40 ` David Gibson
2016-10-06 3:38 ` David Gibson
2016-10-06 6:10 ` David Gibson
2016-10-06 11:03 ` Peter Maydell
2016-10-06 14:11 ` Greg Kurz
2016-10-06 15:36 ` Paolo Bonzini
2016-10-06 15:41 ` Peter Maydell
2016-10-06 15:59 ` Laurent Vivier
2016-10-06 23:34 ` David Gibson
2016-10-07 7:44 ` Laurent Vivier
2016-10-06 15:44 ` Cédric Le Goater
2016-10-06 15:45 ` Paolo Bonzini
2016-10-06 23:43 ` David Gibson
2016-10-06 23:31 ` David Gibson
2016-10-06 23:31 ` David Gibson
2016-10-07 9:52 ` Peter Maydell
2016-10-04 23:26 ` David Gibson [this message]
2016-10-05 5:36 ` Cédric Le Goater
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=20161004232628.GD18648@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=clg@kaod.org \
--cc=gkurz@linux.vnet.ibm.com \
--cc=lvivier@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).