From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1breyC-0001Jq-LY for qemu-devel@nongnu.org; Wed, 05 Oct 2016 01:42:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brey9-0003hf-C2 for qemu-devel@nongnu.org; Wed, 05 Oct 2016 01:42:20 -0400 Received: from 1.mo1.mail-out.ovh.net ([178.32.127.22]:38497) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brey9-0003hP-3f for qemu-devel@nongnu.org; Wed, 05 Oct 2016 01:42:17 -0400 Received: from player726.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id 95DEFFCC3 for ; Wed, 5 Oct 2016 07:42:13 +0200 (CEST) References: <1475599486-30446-1-git-send-email-lvivier@redhat.com> <1475599486-30446-2-git-send-email-lvivier@redhat.com> From: =?UTF-8?Q?C=c3=a9dric_Le_Goater?= Message-ID: <12b65eb8-365c-e83b-958c-873fe21c14f2@kaod.org> Date: Wed, 5 Oct 2016 07:42:04 +0200 MIME-Version: 1.0 In-Reply-To: <1475599486-30446-2-git-send-email-lvivier@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v5 1/5] qtest: add read/write accessors with a specific endianness List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier , qemu-devel@nongnu.org Cc: thuth@redhat.com, qemu-ppc@nongnu.org, dgibson@redhat.com, Gerd Hoffmann , Greg Kurz On 10/04/2016 06:44 PM, Laurent Vivier wrote: > From: C=C3=A9dric Le Goater >=20 > 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. >=20 > To maintain the endianness of a value, we need a new set of memory > accessor. This can be done in two ways: >=20 > - 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 >=20 > - 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. >=20 > The result is the same and the first method is simpler. >=20 > Signed-off-by: C=C3=A9dric Le Goater > Signed-off-by: Laurent Vivier Hello, There is an issue in my patch in the write ops ... so a v2 is clearly=20 needed. Let's see if there are more comments before doing so.=20 Thanks, C.=20 > --- > tests/libqtest.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > tests/libqtest.h | 71 +++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 162 insertions(+) >=20 > diff --git a/tests/libqtest.c b/tests/libqtest.c > index 6f6bdf1..611f2c3 100644 > --- a/tests/libqtest.c > +++ b/tests/libqtest.c > @@ -15,6 +15,7 @@ > * > */ > #include "qemu/osdep.h" > +#include "qemu/bswap.h" > #include "libqtest.h" > =20 > #include > @@ -688,6 +689,42 @@ void qtest_writeq(QTestState *s, uint64_t addr, ui= nt64_t value) > qtest_write(s, "writeq", addr, value); > } > =20 > +void qtest_writew_be(QTestState *s, uint64_t addr, uint16_t value) > +{ > + value =3D cpu_to_be16(value); > + qtest_memread(s, addr, &value, sizeof(value)); > +} > + > +void qtest_writel_be(QTestState *s, uint64_t addr, uint32_t value) > +{ > + value =3D cpu_to_be32(value); > + qtest_memread(s, addr, &value, sizeof(value)); > +} > + > +void qtest_writeq_be(QTestState *s, uint64_t addr, uint64_t value) > +{ > + value =3D cpu_to_be64(value); > + qtest_memread(s, addr, &value, sizeof(value)); > +} > + > +void qtest_writew_le(QTestState *s, uint64_t addr, uint16_t value) > +{ > + value =3D cpu_to_le16(value); > + qtest_memread(s, addr, &value, sizeof(value)); > +} > + > +void qtest_writel_le(QTestState *s, uint64_t addr, uint32_t value) > +{ > + value =3D cpu_to_le32(value); > + qtest_memread(s, addr, &value, sizeof(value)); > +} > + > +void qtest_writeq_le(QTestState *s, uint64_t addr, uint64_t value) > +{ > + value =3D cpu_to_le64(value); > + qtest_memread(s, addr, &value, sizeof(value)); > +} > + > static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t ad= dr) > { > gchar **args; > @@ -721,6 +758,60 @@ uint64_t qtest_readq(QTestState *s, uint64_t addr) > return qtest_read(s, "readq", addr); > } > =20 > +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 >=3D '0' && ch <=3D '9') { > diff --git a/tests/libqtest.h b/tests/libqtest.h > index f7402e0..d5c25a9 100644 > --- a/tests/libqtest.h > +++ b/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, ...); > =20 > +/* > + * 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 >=20