From patchwork Mon Aug 10 19:23:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 40471 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7AJOsjL024907 for ; Mon, 10 Aug 2009 19:24:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751897AbZHJTYv (ORCPT ); Mon, 10 Aug 2009 15:24:51 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751887AbZHJTYv (ORCPT ); Mon, 10 Aug 2009 15:24:51 -0400 Received: from mx2.redhat.com ([66.187.237.31]:51129 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751873AbZHJTYv (ORCPT ); Mon, 10 Aug 2009 15:24:51 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7AJOp11012594; Mon, 10 Aug 2009 15:24:51 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n7AJOncN016373; Mon, 10 Aug 2009 15:24:50 -0400 Received: from redhat.com (vpn-6-19.tlv.redhat.com [10.35.6.19]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7AJOlFL001934; Mon, 10 Aug 2009 15:24:48 -0400 Date: Mon, 10 Aug 2009 22:23:36 +0300 From: "Michael S. Tsirkin" To: avi@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH 2/3] qemu/virtio: move features to an inline function Message-ID: <20090810192336.GC16781@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.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org devices should have the final say over which virtio features they support. E.g. indirect entries may or may not make sense in the context of virtio-console. Move the common bits from virtio-pci to an inline function and let each device call it. No functional changes. Signed-off-by: Michael S. Tsirkin --- hw/virtio-balloon.c | 2 +- hw/virtio-blk.c | 2 +- hw/virtio-console.c | 2 +- hw/virtio-net.c | 2 +- hw/virtio-pci.c | 3 --- hw/virtio.h | 10 ++++++++++ 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c index 7ca783e..15b50bb 100644 --- a/hw/virtio-balloon.c +++ b/hw/virtio-balloon.c @@ -127,7 +127,7 @@ static void virtio_balloon_set_config(VirtIODevice *vdev, static uint32_t virtio_balloon_get_features(VirtIODevice *vdev) { - return 0; + return virtio_common_features(); } static ram_addr_t virtio_balloon_to_target(void *opaque, ram_addr_t target) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 2beff52..7d33fee 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -364,7 +364,7 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev) if (strcmp(s->serial_str, "0")) features |= 1 << VIRTIO_BLK_F_IDENTIFY; - return features; + return features | virtio_common_features(); } static void virtio_blk_save(QEMUFile *f, void *opaque) diff --git a/hw/virtio-console.c b/hw/virtio-console.c index 663c8b9..ac25499 100644 --- a/hw/virtio-console.c +++ b/hw/virtio-console.c @@ -53,7 +53,7 @@ static void virtio_console_handle_input(VirtIODevice *vdev, VirtQueue *vq) static uint32_t virtio_console_get_features(VirtIODevice *vdev) { - return 0; + return virtio_common_features(); } static int vcon_can_read(void *opaque) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index ef9e7ff..2e51a6a 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -154,7 +154,7 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev) } #endif - return features; + return features | virtio_common_features(); } static uint32_t virtio_net_bad_features(VirtIODevice *vdev) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 3b9bfd1..90f51be 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -232,9 +232,6 @@ static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr) switch (addr) { case VIRTIO_PCI_HOST_FEATURES: ret = vdev->get_features(vdev); - ret |= (1 << VIRTIO_F_NOTIFY_ON_EMPTY); - ret |= (1 << VIRTIO_RING_F_INDIRECT_DESC); - ret |= (1 << VIRTIO_F_BAD_FEATURE); break; case VIRTIO_PCI_GUEST_FEATURES: ret = vdev->features; diff --git a/hw/virtio.h b/hw/virtio.h index aa55677..de620a7 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -166,4 +166,14 @@ VirtIODevice *virtio_net_init(DeviceState *dev); VirtIODevice *virtio_console_init(DeviceState *dev); VirtIODevice *virtio_balloon_init(DeviceState *dev); +static inline uint32_t virtio_common_features(void) +{ + uint32_t features = 0; + features |= (1 << VIRTIO_F_NOTIFY_ON_EMPTY); + features |= (1 << VIRTIO_RING_F_INDIRECT_DESC); + features |= (1 << VIRTIO_F_BAD_FEATURE); + + return features; +} + #endif