From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1braaq-0007DX-38 for qemu-devel@nongnu.org; Tue, 04 Oct 2016 21:01:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1braan-0002iW-Dx for qemu-devel@nongnu.org; Tue, 04 Oct 2016 21:01:55 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:35871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1braal-0002hR-W5 for qemu-devel@nongnu.org; Tue, 04 Oct 2016 21:01:53 -0400 Date: Wed, 5 Oct 2016 10:26:28 +1100 From: David Gibson Message-ID: <20161004232628.GD18648@umbus.fritz.box> References: <1475583448-21013-1-git-send-email-clg@kaod.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="q9KOos5vDmpwPx9o" Content-Disposition: inline In-Reply-To: <1475583448-21013-1-git-send-email-clg@kaod.org> Subject: Re: [Qemu-devel] [PATCH] qtest: add read/write accessors with a specific endianness List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?C=E9dric?= Le Goater Cc: Peter Maydell , qemu-devel@nongnu.org, Greg Kurz , Laurent Vivier --q9KOos5vDmpwPx9o Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 04, 2016 at 02:17:28PM +0200, C=E9dric 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. >=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=E9dric Le Goater > --- >=20 > tests/libqtest.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++= +++++++ > tests/libqtest.h | 71 ++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 162 insertions(+) >=20 > Index: qemu-aspeed.git/tests/libqtest.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- 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, ...); > =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 > Index: qemu-aspeed.git/tests/libqtest.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- 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" > =20 > #include > @@ -688,6 +689,42 @@ void qtest_writeq(QTestState *s, uint64_ > 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)); Uh.. this surely needs to be qtest_memwrite(). > +} > + > +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)); and here, > +} > + > +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)); here > +} > + > +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)); here > +} > + > +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)); here > +} > + > +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)); 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); > } > =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') { >=20 --=20 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 --q9KOos5vDmpwPx9o Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJX9DqhAAoJEGw4ysog2bOSpjEQAIUjYIMN4u1gXVE5GUxISQCb RTzxcfD+LKzzjuhrcyZb8o2RR9ow3UnJxtliUiGZbRHX5mq6MOquQ/TNUTYrws6P 1KWrMGJV8tMyhPFmmOouEFb+0JDA2xnFFTElDyZ/4D0SX/ZF9SIWOBj3NQsYZxGT mU04l0UV+Xv/9vymx3Bzzx5Vg1yI5znbhiq/Kib4pSkCipynfDf/5pduFcxFOa/o kwsHd4X6AN/jJt60LAd5I0Xr8zTE4okXvA8lg4pEH2ow43YpvQPnBuxH5TwLFvHx /QWbVpekKaf66cKsaVk4jK5tnGi8GNXM/3VG0ReQKBbgPnaJCafZ7YDgYqtdR0Tj ZHRMvSTTshiBBEcdxV6PwmhaZGTMIN/U2ew4EoRUZgPBLsFQfPT3yfQcLBkJzwug sDpkYFMYl3sT2nv3SkURA0ojo3nVhkeCmoon5F4ZGnqnCUuapJoqjMh5Et0wL0bH H3dvAtfqYVkDlox88NLkj1iTa2+XKPkqbdzIDgzxb+uv+msc22yILtu9jrYcWBFp bZhUNVse9iZ4dggPlqBlSPTn4bb57kM1YBV8en3O73/pl1k8YeH36do+pyr5e63g l8+10ZgYLYsN0tqbr5hNa9tbOK/gl5PK5Bm2bbBffpQm1frx0Rb07fxgpQiHjblY dMmpviHqoZgOg/oqyEDa =ct3g -----END PGP SIGNATURE----- --q9KOos5vDmpwPx9o--