qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc Marí" <marc.mari.barcelo@gmail.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v4 07/11] libqos: Added basic virtqueue support to virtio implementation
Date: Wed, 13 Aug 2014 23:59:39 +0200	[thread overview]
Message-ID: <20140813235939.41a28781@crunchbang> (raw)
In-Reply-To: <20140813172740.GK27053@stefanha-thinkpad.redhat.com>

El Wed, 13 Aug 2014 18:27:40 +0100
Stefan Hajnoczi <stefanha@redhat.com> escribió:
> > +void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq,
> > uint64_t addr) +{
> > +    int i;
> > +
> > +    vq->desc = addr;
> > +    vq->avail = vq->desc + vq->size*sizeof(QVRingDesc);
> > +    vq->used = (uint64_t)((vq->avail + sizeof(uint16_t) * (3 +
> > vq->size)
> > +        +vq->align-1) & ~(vq->align - 1));
> > +
> > +    for (i = 0; i < vq->size-1; i++) {
> > +        /* vq->desc[i].addr */
> > +        writew(vq->desc+(16*i), 0);
> > +        /* vq->desc[i].next */
> > +        writew(vq->desc+(16*i)+14, i+1);
> > +    }
> 
> Please use space between operators:
> writew(vq->desc + (16 * i) + 14, i + 1)
> 
> This applies to all patches.
> 
> > +void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d,
> > QVirtQueue *vq,
> > +
> > uint32_t free_head) +{
> > +    /* vq->avail->idx */
> > +    uint16_t idx = readl(vq->avail+2);
> > +
> > +    /* vq->avail->ring[idx % vq->size] */
> > +    writel(vq->avail+4+(2*(idx % vq->size)), free_head);
> 
> If you want to use typed pointers you can.  It will make the code
> nicer to read, just be careful never to dereference them and only to
> access through writel()/readl():
> 
> typedef struct {
> uint16_t foo; /* Forgot what these fields are called and didn't check
> */ uint16_t bar;
> uint16_t ring[];
> } VirtioAvail;
> 
> writel(&vq->avail.ring[idx % vq->size], free_head);
> 
> Now it looks more like normal C and the compiler is doing the address
> calculations for us.

If it is not dereferenced, it can work. But all references will have to
be casted from (void *) to (uint64_t) always which is what readl and
writel expect. I think this is better than calculating the addresses,
but is still a bit ugly.

  reply	other threads:[~2014-08-13 22:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-12 11:41 [Qemu-devel] [PATCH v4 00/11] Virtio PCI libqos driver Marc Marí
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 01/11] tests: Functions bus_foreach and device_find from libqos virtio API Marc Marí
2014-08-13 16:52   ` Stefan Hajnoczi
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 02/11] tests: Add virtio device initialization Marc Marí
2014-08-13 16:52   ` Stefan Hajnoczi
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 03/11] libqtest: add QTEST_LOG for debugging qtest testcases Marc Marí
2014-08-13 16:53   ` Stefan Hajnoczi
2014-08-13 16:56   ` Stefan Hajnoczi
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 04/11] libqos: Correct mask to align size to PAGE_SIZE in malloc-pc Marc Marí
2014-08-13 16:56   ` Stefan Hajnoczi
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 05/11] libqos: Change free function called in malloc Marc Marí
2014-08-13 16:56   ` Stefan Hajnoczi
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 06/11] virtio-blk: Correct bug in support for flexible descriptor layout Marc Marí
2014-08-13 16:56   ` Stefan Hajnoczi
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 07/11] libqos: Added basic virtqueue support to virtio implementation Marc Marí
2014-08-13 17:27   ` Stefan Hajnoczi
2014-08-13 21:59     ` Marc Marí [this message]
2014-08-17  9:37       ` Paolo Bonzini
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 08/11] libqos: Added indirect descriptor " Marc Marí
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 09/11] libqos: Added test case for configuration changes in virtio-blk test Marc Marí
2014-08-13 17:34   ` Stefan Hajnoczi
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 10/11] libqos: Added MSI-X support Marc Marí
2014-08-12 11:41 ` [Qemu-devel] [PATCH v4 11/11] 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=20140813235939.41a28781@crunchbang \
    --to=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).