All of lore.kernel.org
 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] [PATCHv4 08/11] tests: Clean up IO handling in ide-test
Date: Fri, 21 Oct 2016 20:05:35 +1100	[thread overview]
Message-ID: <20161021090535.GA10218@umbus.fritz.box> (raw)
In-Reply-To: <8f01103a-9c90-21d2-131c-1e58828615d4@redhat.com>

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

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, 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(-)
> > 
> > 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;
> >  
> > -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 = { .padding = 0 };
> >      int i;
> > @@ -670,7 +717,8 @@ static void send_scsi_cdb_read10(uint64_t lba, int nblocks)
> >  
> >      /* Send Packet */
> >      for (i = 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]));
> >      }
> >  }
> >  
> ...
> > @@ -780,7 +836,8 @@ static void cdrom_pio_impl(int nblocks)
> >  
> >          /* HP4: Transfer_Data */
> >          for (j = 0; j < MIN((limit / 2), rem); j++) {
> > -            rx[offset + j] = le16_to_cpu(inw(IDE_BASE + reg_data));
> > +            rx[offset + j] = cpu_to_le16(qpci_io_readw(dev,
> > +                                                       ide_base + reg_data));
> >          }
> >      }
> 
> Why do you swap le16_to_cpu() and cpu_to_le16()?

So, obviously le16_to_cpu() and cpu_to_le16() are functionally
identical.  But I think my version is conceptually more correct.

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.

> I think this is not semantically correct and the purpose of this patch
> is only to replace inX()/outX() functions.

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.

-- 
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-21  9:25 UTC|newest]

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

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=20161021090535.GA10218@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.