qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v7 2/7] tests: Add virtio device initialization


From: Marc Marí
Subject: Re: [Qemu-devel] [PATCH v7 2/7] tests: Add virtio device initialization
Date: Fri, 29 Aug 2014 21:31:28 +0200

El Fri, 29 Aug 2014 16:49:36 +0100
Stefan Hajnoczi <address@hidden> escribió:
> 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

Sorry, I messed up. These are the things that one is not used to think
about, as this is usally taken for granted because the OS handles it.

Marc



reply via email to

[Prev in Thread] Current Thread [Next in Thread]