qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: "Marc Marí" <marc.mari.barcelo@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v7 2/7] tests: Add virtio device initialization
Date: Fri, 29 Aug 2014 16:49:36 +0100	[thread overview]
Message-ID: <20140829154936.GA19824@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1409308848-5245-3-git-send-email-marc.mari.barcelo@gmail.com>

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

On Fri, Aug 29, 2014 at 12:40:43PM +0200, Marc Marí wrote:
> +static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, void *addr)
> +{
> +    QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
> +    int i;
> +    union {
> +        uint8_t bytes[8];
> +        uint64_t u64;
> +    } quad;
> +
> +    if (qtest_big_endian()) {
> +        for (i = 0; i < 8; ++i) {
> +            quad.bytes[7-i] = qpci_io_readb(dev->pdev, addr + i);
> +        }
> +    } else {
> +        for (i = 0; i < 8; ++i) {
> +            quad.bytes[i] = qpci_io_readb(dev->pdev, addr + i);
> +        }
> +    }
> +
> +    return quad.u64;
> +}

This assumes that the host is little-endian.  The host could be
big-endian!

qvirtio_pci_config_readq() needs to return a 64-bit value in host CPU
endianness.  So the logic should be:

for (i = 0; i < 8; ++i) {
    quad.bytes[i] = qpci_io_readb(dev->pdev, addr + i);
}
if (qtest_big_endian() != qtest_host_endian()) {
    quad.u64 = bswap64(quad.u64);
}
return quard.u64;

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2014-08-29 15:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-29 10:40 [Qemu-devel] [PATCH v7 0/7] Virtio PCI libqos driver Marc Marí
2014-08-29 10:40 ` [Qemu-devel] [PATCH v7 1/7] tests: Functions bus_foreach and device_find from libqos virtio API Marc Marí
2014-08-29 10:40 ` [Qemu-devel] [PATCH v7 2/7] tests: Add virtio device initialization Marc Marí
2014-08-29 15:49   ` Stefan Hajnoczi [this message]
2014-08-29 15:59     ` Paolo Bonzini
2014-08-29 19:45       ` Marc Marí
2014-09-01 15:22       ` Stefan Hajnoczi
2014-08-29 19:31     ` Marc Marí
2014-08-29 10:40 ` [Qemu-devel] [PATCH v7 3/7] libqos: Added basic virtqueue support to virtio implementation Marc Marí
2014-08-29 10:40 ` [Qemu-devel] [PATCH v7 4/7] libqos: Added indirect descriptor " Marc Marí
2014-08-29 10:40 ` [Qemu-devel] [PATCH v7 5/7] libqos: Added test case for configuration changes in virtio-blk test Marc Marí
2014-08-29 10:40 ` [Qemu-devel] [PATCH v7 6/7] libqos: Added MSI-X support Marc Marí
2014-08-29 10:40 ` [Qemu-devel] [PATCH v7 7/7] libqos: Added EVENT_IDX support Marc Marí

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=20140829154936.GA19824@stefanha-thinkpad.redhat.com \
    --to=stefanha@gmail.com \
    --cc=marc.mari.barcelo@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@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).