From patchwork Thu Feb 4 15:28:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 77037 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o14FVK4K017796 for ; Thu, 4 Feb 2010 15:31:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932807Ab0BDPbS (ORCPT ); Thu, 4 Feb 2010 10:31:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45142 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932221Ab0BDPbR (ORCPT ); Thu, 4 Feb 2010 10:31:17 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o14FVHDJ004790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 4 Feb 2010 10:31:17 -0500 Received: from redhat.com (vpn2-9-138.ams2.redhat.com [10.36.9.138]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o14FVFlI005162 for ; Thu, 4 Feb 2010 10:31:16 -0500 Date: Thu, 4 Feb 2010 17:28:06 +0200 From: "Michael S. Tsirkin" To: kvm@vger.kernel.org Subject: [PATCH 08/20] virtio: add APIs for queue fields Message-ID: <20100204152806.GI8461@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 04 Feb 2010 15:31:21 +0000 (UTC) diff --git a/hw/virtio.c b/hw/virtio.c index b9411e9..65e59c1 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -73,6 +73,9 @@ struct VirtQueue int inuse; uint16_t vector; void (*handle_output)(VirtIODevice *vdev, VirtQueue *vq); + VirtIODevice *vdev; + EventNotifier guest_notifier; + EventNotifier host_notifier; }; /* virt queue functions */ @@ -592,10 +595,10 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, return &vdev->vq[i]; } -void virtio_irq(VirtIODevice *vdev, VirtQueue *vq) +void virtio_irq(VirtQueue *vq) { - vdev->isr |= 0x01; - virtio_notify_vector(vdev, vq->vector); + vq->vdev->isr |= 0x01; + virtio_notify_vector(vq->vdev, vq->vector); } void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) @@ -606,7 +609,8 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) (vq->inuse || vring_avail_idx(vq) != vq->last_avail_idx))) return; - virtio_irq(vdev, vq); + vdev->isr |= 0x01; + virtio_notify_vector(vdev, vq->vector); } void virtio_notify_config(VirtIODevice *vdev) @@ -740,3 +744,42 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding, vdev->binding = binding; vdev->binding_opaque = opaque; } + +target_phys_addr_t virtio_queue_get_desc(VirtIODevice *vdev, int n) +{ + return vdev->vq[n].vring.desc; +} + +target_phys_addr_t virtio_queue_get_avail(VirtIODevice *vdev, int n) +{ + return vdev->vq[n].vring.avail; +} + +target_phys_addr_t virtio_queue_get_used(VirtIODevice *vdev, int n) +{ + return vdev->vq[n].vring.used; +} + +uint16_t virtio_queue_last_avail_idx(VirtIODevice *vdev, int n) +{ + return vdev->vq[n].last_avail_idx; +} + +void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx) +{ + vdev->vq[n].last_avail_idx = idx; +} + +VirtQueue *virtio_queue(VirtIODevice *vdev, int n) +{ + return vdev->vq + n; +} + +EventNotifier *virtio_queue_guest_notifier(VirtQueue *vq) +{ + return &vq->guest_notifier; +} +EventNotifier *virtio_queue_host_notifier(VirtQueue *vq) +{ + return &vq->host_notifier; +} diff --git a/hw/virtio.h b/hw/virtio.h index 2c298a8..92ad5d1 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -183,5 +183,13 @@ void virtio_net_exit(VirtIODevice *vdev); DEFINE_PROP_BIT("indirect_desc", _state, _field, \ VIRTIO_RING_F_INDIRECT_DESC, true) -void virtio_irq(VirtIODevice *vdev, VirtQueue *vq); +target_phys_addr_t virtio_queue_get_desc(VirtIODevice *vdev, int n); +target_phys_addr_t virtio_queue_get_avail(VirtIODevice *vdev, int n); +target_phys_addr_t virtio_queue_get_used(VirtIODevice *vdev, int n); +uint16_t virtio_queue_last_avail_idx(VirtIODevice *vdev, int n); +void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx); +VirtQueue *virtio_queue(VirtIODevice *vdev, int n); +EventNotifier *virtio_queue_guest_notifier(VirtQueue *vq); +EventNotifier *virtio_queue_host_notifier(VirtQueue *vq); +void virtio_irq(VirtQueue *vq); #endif