Received: from eggs.gnu.org ([2001:4830:134:3::10]:58478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxpjU-0005lK-4S for qemu-devel@nongnu.org; Sat, 22 Oct 2016 02:24:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxpjQ-0005EK-5h for qemu-devel@nongnu.org; Sat, 22 Oct 2016 02:24:40 -0400 Date: Sat, 22 Oct 2016 15:56:03 +1100 From: David Gibson Message-ID: <20161022045603.GB19629@umbus.fritz.box> References: <1477012792-3326-1-git-send-email-david@gibson.dropbear.id.au> <1477012792-3326-9-git-send-email-david@gibson.dropbear.id.au> <8f01103a-9c90-21d2-131c-1e58828615d4@redhat.com> <20161021090535.GA10218@umbus.fritz.box> <1a90d2e5-22b7-4d0d-d6ba-95bf1a2b8242@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="UHN/qo2QbUvPLonB" Content-Disposition: inline In-Reply-To: <1a90d2e5-22b7-4d0d-d6ba-95bf1a2b8242@redhat.com> Subject: Re: [Qemu-devel] [PATCHv4 08/11] tests: Clean up IO handling in ide-test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, agraf@suse.de, stefanha@redhat.com, mst@redhat.com, aik@ozlabs.ru, mdroth@linux.vnet.ibm.com, groug@kaod.org, thuth@redhat.com --UHN/qo2QbUvPLonB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 21, 2016 at 12:07:28PM +0200, Laurent Vivier wrote: >=20 >=20 > On 21/10/2016 11:05, David Gibson wrote: > > On Fri, Oct 21, 2016 at 10:31:27AM +0200, Laurent Vivier wrote: > >> > >> > >> On 21/10/2016 03:19, David Gibson wrote: > >>> ide-test uses many explicit inb() / outb() operations for its IO, whi= ch > >>> means it's not portable to non-x86 platforms. This cleans it up to u= se > >>> the libqos PCI accessors instead. > >>> > >>> Signed-off-by: David Gibson > >>> --- > >>> tests/ide-test.c | 179 ++++++++++++++++++++++++++++++++++++---------= ---------- > >>> 1 file changed, 118 insertions(+), 61 deletions(-) > >>> > >>> diff --git a/tests/ide-test.c b/tests/ide-test.c > >>> index a8a4081..86c4373 100644 > >>> --- a/tests/ide-test.c > >>> +++ b/tests/ide-test.c > >> ... > >>> @@ -654,7 +700,8 @@ typedef struct Read10CDB { > >>> uint16_t padding; > >>> } __attribute__((__packed__)) Read10CDB; > >>> =20 > >>> -static void send_scsi_cdb_read10(uint64_t lba, int nblocks) > >>> +static void send_scsi_cdb_read10(QPCIDevice *dev, void *ide_base, > >>> + uint64_t lba, int nblocks) > >>> { > >>> Read10CDB pkt =3D { .padding =3D 0 }; > >>> int i; > >>> @@ -670,7 +717,8 @@ static void send_scsi_cdb_read10(uint64_t lba, in= t nblocks) > >>> =20 > >>> /* Send Packet */ > >>> for (i =3D 0; i < sizeof(Read10CDB)/2; i++) { > >>> - outw(IDE_BASE + reg_data, cpu_to_le16(((uint16_t *)&pkt)[i])= ); > >>> + qpci_io_writew(dev, ide_base + reg_data, > >>> + le16_to_cpu(((uint16_t *)&pkt)[i])); > >>> } > >>> } > >>> =20 > >> ... > >>> @@ -780,7 +836,8 @@ static void cdrom_pio_impl(int nblocks) > >>> =20 > >>> /* HP4: Transfer_Data */ > >>> for (j =3D 0; j < MIN((limit / 2), rem); j++) { > >>> - rx[offset + j] =3D le16_to_cpu(inw(IDE_BASE + reg_data)); > >>> + rx[offset + j] =3D cpu_to_le16(qpci_io_readw(dev, > >>> + ide_base + re= g_data)); > >>> } > >>> } > >> > >> Why do you swap le16_to_cpu() and cpu_to_le16()? > >=20 > > So, obviously le16_to_cpu() and cpu_to_le16() are functionally > > identical. But I think my version is conceptually more correct. >=20 > I agree >=20 > >=20 > > This is streaming data via PIO - we're essentially reading a byte > > stream in 16-bit chunks. So, overall we want to preserve byte address > > order. qpci_io_readw() (and inw()) is designed for reading registers > > so it preserves byte significance, rather than address order. So, > > since the IDE registers are LE, that means if implicitly contains an > > le16_to_cpu(). The cpu_to_le16() undoes that so that rx[] ends up > > with the bytestream in the correct order. >=20 > In fact, it has an implicit "le16 to target CPU", so you should not have > a "cpu_to_le16()" but a "qtest_big_endian() !=3D host_big_endian > bswap16()" to swap it. No.. it really is le16_to_cpu(). For memory space accesses, there's an explicit le16_to_cpu in qpci_io_readw() on top of the order-preserving memread backend. For IO space accesses, we call the backend directly. In all likely cases that will be turned into a (non PCI) either inw() or readw(). Both inw() and readw() are defined to access in target endianness (which is stupid, but that argument is in several other threads). So they have an implicit "target_to_host16()". But the PCI versions are defined to be always LE - on BE targets the backend will add an extra swap, changing that target_to_host16() into an le16_to_cpu(). > As this test works only with a little endian guest, the first "LE16 to > target CPU" is a no-op, and the second one does something only on big > endian host so when "qtest_big_endian() !=3D host_big_endian". >=20 > >> I think this is not semantically correct and the purpose of this patch > >> is only to replace inX()/outX() functions. > >=20 > > No, I believe it is correct. And I think the original was technically > > wrong, because inw() reads the register in target endian rather than > > LE. Of course the only common platform with "real" in/out > > instructions is x86, which is LE anyway, so it hardly matters. >=20 > I agree, this is why I think a "qtest_big_endian() !=3D host_big_endian > then bswap16()" is better than a "cpu_to_le16()". No, cpu_to_le16() is correct. Well.. actually using an order-preserving read would be correct, but that's a bit awkward for tne io port case. >=20 > But I also think it should be the purpose of another patch... >=20 > Thanks, > Laurent >=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 --UHN/qo2QbUvPLonB Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYCvFjAAoJEGw4ysog2bOSWZEP/A6iUlMwkUX/K56TGuxHS6Jz sd59bDmMhMrBcnst1IOvRqA8Sx+OH7H/n/Pt3LroLTxlF9qMXhbYmpVX/FCjOX/f 1MQTV9k2CDHQJ0iOSzKHiI28H6aFvHTlTvC+JIKUZS58f4eBiC5OPUZ2kVyS7rT2 WG+aU6QAF3PQVraF7Ihooqs8mOc13V+7P+cCPvlq2UZ6D/dVOZ+j/fSrUNfC2Njq XnQHoJgquchzrYmQ7dPNarUNTj2pYnldUbMXO24OPjRr17nBDJCA27+0+4X4FgY4 ttIFpQ6leOS21+ddTdEoyrRzsyNPtnpsVvDzWmIWWF5dWIRvd4dgFwp4jSn2A3/S rsVDlavaUYuAok2zD9DcUV5F3RMYmk9Vly3V+pI3Urim0+Lobq8v4NgeZS27AJcw oktWJx1I2W9pCBfOgcdrIbdGZlrn1r5qfc05ZBWrk9KSgqKkMqWxZMH6/mo4vFJs TdnptIojXmcJWBjeUCRMaEtTBUB343pOJZ0O8Vbu2uuBWrSIURHurMh/Hx2pMYvg +bTdh7hM2pjm/ZIPyYNCG04ImOgJ7Un7BYjdKUYcZNkYaYSxzEbs7CSFJ+mbPG0d d6cPQADvroLfOmrNpOwAn/9OHB8cpd3gBnyTlpMmQwZaAM3oWPwBe9ORfGvdB//c JS7xM+UnR01LsS4f7RUz =Z1od -----END PGP SIGNATURE----- --UHN/qo2QbUvPLonB--