qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
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
Subject: Re: [Qemu-devel] [PATCHv2 08/11] tests: Clean up IO handling in ide-test
Date: Thu, 20 Oct 2016 14:24:11 +1100	[thread overview]
Message-ID: <20161020032411.GN11140@umbus.fritz.box> (raw)
In-Reply-To: <d18ff497-f9b9-803c-ef84-86e0b346a226@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2437 bytes --]

On Wed, Oct 19, 2016 at 04:51:41PM +0200, Laurent Vivier wrote:
> 
> 
> On 19/10/2016 16:43, Laurent Vivier wrote:
> > 
> > 
> > On 19/10/2016 14:25, David Gibson wrote:
> >> ide-test uses many explicit inb() / outb() operations for its IO, which
> >> means it's not portable to non-x86 platforms.  This cleans it up to use
> >> the libqos PCI accessors instead.
> >>
> >> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> >> ---
> >>  tests/ide-test.c | 179 ++++++++++++++++++++++++++++++++++++-------------------
> >>  1 file changed, 118 insertions(+), 61 deletions(-)
> > 
> > Could explain why you have swapped the le16_to_cpu() and cpu_to_le16()?
> > 
> > For me, they were correct.
> 
> And I have just finished testing your series on a BE host, and ide-test
> is broken:
> 
> TEST: tests/ide-test... (pid=12472)
>   /i386/ide/identify:                                                  **
> ERROR:/home/laurent/Projects/qemu/tests/ide-test.c:518:test_identify:
> assertion failed: (ret == 0)
> FAIL

Ah, thanks for testing this.

> You should not add the cpu_to_le16():
> 
>      for (i = 0; i < 256; i++) {
> -        data = inb(IDE_BASE + reg_status);
> +        data = qpci_io_readb(dev, ide_base + reg_status);
>          assert_bit_set(data, DRDY | DRQ);
>          assert_bit_clear(data, BSY | DF | ERR);
> 
> -        ((uint16_t*) buf)[i] = inw(IDE_BASE + reg_data);
> +        buf[i] = cpu_to_le16(qpci_io_readw(dev, ide_base + reg_data));
>      }

Urgh, the endianness here is doing my head in.

So, the cpu_to_le16() was supposed to counteract the implicit
conversion from LE inside qpci_io_readw.  We're reading from the data
register here, and those are usually "streaming" style, meaning that
we want byte-order preserving rather than byte-significance
preserving.

But.. the IDENTIFY command describes most of the output in terms of
(16-bit) words, meaning I guess we do want to swap from LE in order to
interpret those.  Except that the string portions seem to be encoded
strangely, which the later string_cpu_to_be16() calls are about.

In summary, I think you're right and the cpu_to_le16() shouldn't be
there.  Seems to work on a BE host, anyway.

-- 
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 --]

  reply	other threads:[~2016-10-20  3:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-19 12:25 [Qemu-devel] [PATCHv2 00/11] Cleanups to qtest PCI handling David Gibson
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 01/11] libqos: Give qvirtio_config_read*() consistent semantics David Gibson
2016-10-19 13:17   ` Laurent Vivier
2016-10-19 13:29   ` Greg Kurz
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 02/11] libqos: Handle PCI IO de-multiplexing in common code David Gibson
2016-10-19 13:20   ` Laurent Vivier
2016-10-19 14:45   ` Greg Kurz
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 03/11] libqos: Move BAR assignment to " David Gibson
2016-10-19 13:22   ` Laurent Vivier
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 04/11] libqos: Better handling of PCI legacy IO David Gibson
2016-10-19 13:33   ` Laurent Vivier
2016-10-20  0:20     ` David Gibson
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 05/11] tests: Adjust tco-test to use qpci_legacy_iomap() David Gibson
2016-10-19 13:35   ` Laurent Vivier
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 06/11] libqos: Add streaming accessors for PCI MMIO David Gibson
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 07/11] libqos: Implement mmio accessors in terms of mem{read, write} David Gibson
2016-10-19 13:38   ` Laurent Vivier
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 08/11] tests: Clean up IO handling in ide-test David Gibson
2016-10-19 14:43   ` Laurent Vivier
2016-10-19 14:51     ` Laurent Vivier
2016-10-20  3:24       ` David Gibson [this message]
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 09/11] libqos: Add 64-bit PCI IO accessors David Gibson
2016-10-19 14:16   ` Laurent Vivier
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 10/11] tests: Use qpci_mem{read, write} in ivshmem-test David Gibson
2016-10-19 14:20   ` Laurent Vivier
2016-10-19 12:25 ` [Qemu-devel] [PATCHv2 11/11] libqos: Change PCI accessors to take opaque BAR handle David Gibson
2016-10-19 14:35   ` Laurent Vivier
2016-10-20  3:34     ` David Gibson

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=20161020032411.GN11140@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=groug@kaod.org \
    --cc=lvivier@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    /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).