From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxBlB-0000B2-UC for qemu-devel@nongnu.org; Wed, 18 Jun 2014 05:02:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WxBl2-0000Bu-9y for qemu-devel@nongnu.org; Wed, 18 Jun 2014 05:02:25 -0400 Received: from mail-we0-x22b.google.com ([2a00:1450:400c:c03::22b]:41166) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxBl1-0000BS-Vk for qemu-devel@nongnu.org; Wed, 18 Jun 2014 05:02:16 -0400 Received: by mail-we0-f171.google.com with SMTP id q58so508880wes.16 for ; Wed, 18 Jun 2014 02:02:15 -0700 (PDT) Date: Wed, 18 Jun 2014 17:02:06 +0800 From: Stefan Hajnoczi Message-ID: <20140618090206.GA31073@stefanha-thinkpad.redhat.com> References: <1402995768-4282-1-git-send-email-marc.mari.barcelo@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="nFreZHaLTZJo0R7j" Content-Disposition: inline In-Reply-To: <1402995768-4282-1-git-send-email-marc.mari.barcelo@gmail.com> Subject: Re: [Qemu-devel] [RFC] Libqos virtio API List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marc =?iso-8859-1?Q?Mar=ED?= Cc: Paolo Bonzini , Paolo Bonzini , qemu-devel@nongnu.org, Stefan Hajnoczi --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 17, 2014 at 11:02:48AM +0200, Marc Mar=ED wrote: > This is the draft for the libqos virtio API to create test cases for virt= io > devices. I'm looking forward to your comments. >=20 > Signed-off-by: Marc Mar=ED > --- > tests/libqos/virtio.h | 148 +++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 148 insertions(+) > create mode 100644 tests/libqos/virtio.h >=20 > diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h > new file mode 100644 > index 0000000..03f28dc > --- /dev/null > +++ b/tests/libqos/virtio.h > @@ -0,0 +1,148 @@ > +#define VIRTQUEUE_MAX_SIZE 1024 > + > +struct QVirtioBus > +{ > + /* Send a notification IRQ to the device */ > + void (*notify)(QVirtioDevice *d, uint16_t vector); Guest->host notification is not an interrupt. It's a "kick" that's implemented by writing to a hardware register. The argument should be the virtqueue number. > + =20 > + /* Get configuration of the device */ > + void (*get_config)(QVirtioDevice *d, void *config); > + =20 > + /* Set configuration of the device */ > + void (*set_config)(QVirtioDevice *d, void *config); > + =20 > + /* Get features of the device */ > + uint32_t (*get_features)(QVirtioDevice *d); > + =20 > + /* Get status of the device */ > + uint8_t (*get_status)(QVirtioDevice *d); > + =20 > + /* Set status of the device */ > + void (*set_status)(QVirtioDevice *d, uint8_t val); > + =20 > + /* Reset the device */ > + void (*reset)(QVirtioDevice *d); > + =20 > + /* Check pending IRQs */ > + uint8_t (*query_isr)(QVirtioDevice *d); Does this also clear the ISR? > + =20 > + /* Loop all devices, applying a function to all, or the one specifie= d */ > + void (*device_foreach)(QVirtioBus *bus, uint16_t device_id,=20 > + void (*func)(QVirtioDevice *dev, void *data), void *data= ); > + =20 > + /* Find and return a device */ > + QVirtioDevice *(*device_find)(uint16_t device_id, int index); > +}; > + > +QVirtioBus *qvirtio_pci_init(); > +QVirtioBus *qvirtio_mmio_init(); > +QVirtioBus *qvirtio_ccw_init(); In C you should always give an arguments list. Use void if there are no arguments. In C++ fn() means fn(void) but in C it means legacy K&R behavior which no one uses due to lack of type-safety. I don't think it's necessary to provide a function that instantiates a QVirtioBus. QVirtioBus is just a struct of function pointers. It can be declared static const: static const QVirtioBus virtio_pci_bus =3D { .reset =3D virtio_pci_reset, ... }; > + > +struct QVirtioDevice > +{ > + /* Index in all devices of the same type in the bus */ > + int index; > + =20 > + /* Device type */ > + uint16_t device_id; > + =20 > + /* VQs associated with the device */ > + QVirtQueue *vq; > +}; > + > +/* > +I'm not sure what implementation of VirtQueue is better, QEMU's or Linux= 's. I > +think QEMU implementation is better, because it will be easier to connec= t the > +QEMU Virtqueue with the Libaos VirtQueue. > + > +The functions to use the VirtQueue are the ones I think necessary in Lib= qos, but > +probably there are some missing and some others that are not necessary. > +*/ Keep in mind that QEMU only cares about popping elements off the available ring and pushing them onto the used ring. The Linux guest driver implementation is the opposite. It pushes elements onto the available ring and pops them off the used ring. If in doubt, follow the Linux implementation because you are implementing the guest side of the interface, not the host side. --nFreZHaLTZJo0R7j Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJToVWOAAoJEJykq7OBq3PIFIcH/i6nccs+6hlhSJHEeybiEJlG K+1AddLHIJT+yo/R/J5N99cMj2+rjbhOT9/Udz6mXyPDnb6p14PTgg/SwKXWjwIW B6zwCRJ9I6+ZefIxsaidhZNEfJOdSCGTCbgMqLgg2a7dW4oijcwzght7KQIrNfpH FkS6uEejpznz+5r4p6YssL12I2hFUZ+vROx2TdcyJT5tPpMXwlXSlb07kTnS+REf L3hlHf0ft7gKHH3YAZQRGZduElhpXccGRsQz+pMnuQxQ2LpWfvfSq/Ru1r81BeIs KDywM2xGK1AW3soI8tIZjWPyVNJ5zPnZ79lCUot3QETLSlI/yTycoR+7CJti/ss= =lS9J -----END PGP SIGNATURE----- --nFreZHaLTZJo0R7j--