From patchwork Thu Aug 30 07:36:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1386741 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 6BB11DF264 for ; Thu, 30 Aug 2012 07:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751878Ab2H3Hgt (ORCPT ); Thu, 30 Aug 2012 03:36:49 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:53438 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751307Ab2H3Hgr (ORCPT ); Thu, 30 Aug 2012 03:36:47 -0400 Received: by mail-wi0-f172.google.com with SMTP id r5so7463006wic.1 for ; Thu, 30 Aug 2012 00:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=z+JTsOa3TqNWCiLLa1ofWaUvx28QTRiNUMmXh11+O8U=; b=azFkvb1KgyV0l8pNirH0510WzvBYSfFLdMI4yAG/wIdMwJYRmWu7MxxsdBWeqVB+uT J0B6ee6ROlmro25EcOlzXQsWbXr+lgxsRr7ibqFnIusQmGMxYLUtt7mP/SsCi6CRmq5A mjtWYfaY43X2iozpwT5+OXEJ+ZmZJxDXBnuG/9JHTsgJWcaJvGIuyzlHm/t9/f9kkqo6 UZyiWmz1tTcyGs2AvG9W61tmRAMwFhmA3giABitteQG7cPK/ovLA5WlmSE0pw4oMTe+n SyTLj9ej8rgX8qroZC46mbs059voNb2QbDf+nrVf2imX+V4xNIZ/d18Ev9BQKQGFuYEN vozQ== Received: by 10.180.84.169 with SMTP id a9mr9336313wiz.8.1346312206754; Thu, 30 Aug 2012 00:36:46 -0700 (PDT) Received: from lappy.capriciverd.com (20.Red-80-59-140.staticIP.rima-tde.net. [80.59.140.20]) by mx.google.com with ESMTPS id fr4sm2847342wib.8.2012.08.30.00.36.44 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Aug 2012 00:36:45 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 7/7] kvm tools: simplify virtio config handling Date: Thu, 30 Aug 2012 09:36:43 +0200 Message-Id: <1346312203-29456-7-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1346312203-29456-1-git-send-email-levinsasha928@gmail.com> References: <1346312203-29456-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Instead of a get/set for config values, just request the address of the config region, and handle that by simply reading directly from that region. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/virtio.h | 3 +-- tools/kvm/virtio/9p.c | 12 ++---------- tools/kvm/virtio/balloon.c | 12 ++---------- tools/kvm/virtio/blk.c | 12 ++---------- tools/kvm/virtio/console.c | 12 ++---------- tools/kvm/virtio/mmio.c | 6 +++--- tools/kvm/virtio/net.c | 12 ++---------- tools/kvm/virtio/pci.c | 4 ++-- tools/kvm/virtio/rng.c | 8 +------- tools/kvm/virtio/scsi.c | 12 ++---------- 10 files changed, 19 insertions(+), 74 deletions(-) diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h index 71b6bad..5dc2544 100644 --- a/tools/kvm/include/kvm/virtio.h +++ b/tools/kvm/include/kvm/virtio.h @@ -78,8 +78,7 @@ struct virtio_device { }; struct virtio_ops { - void (*set_config)(struct kvm *kvm, void *dev, u8 data, u32 offset); - u8 (*get_config)(struct kvm *kvm, void *dev, u32 offset); + u8 *(*get_config)(struct kvm *kvm, void *dev); u32 (*get_host_features)(struct kvm *kvm, void *dev); void (*set_guest_features)(struct kvm *kvm, void *dev, u32 features); int (*init_vq)(struct kvm *kvm, void *dev, u32 vq, u32 pfn); diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c index d668106..c3f5280 100644 --- a/tools/kvm/virtio/9p.c +++ b/tools/kvm/virtio/9p.c @@ -1250,18 +1250,11 @@ static void virtio_p9_do_io(struct kvm *kvm, void *param) } } -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct p9_dev *p9dev = dev; - ((u8 *)(p9dev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct p9_dev *p9dev = dev; - - return ((u8 *)(p9dev->config))[offset]; + return ((u8 *)(p9dev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -1323,7 +1316,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq) } struct virtio_ops p9_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c index a838ff4..ea64fd4 100644 --- a/tools/kvm/virtio/balloon.c +++ b/tools/kvm/virtio/balloon.c @@ -175,18 +175,11 @@ static void handle_mem(int fd, u32 type, u32 len, u8 *msg) bdev.vdev.ops->signal_config(kvm, &bdev.vdev); } -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct bln_dev *bdev = dev; - ((u8 *)(&bdev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct bln_dev *bdev = dev; - - return ((u8 *)(&bdev->config))[offset]; + return ((u8 *)(&bdev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -241,7 +234,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq) } struct virtio_ops bln_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c index d988365..98f17a2 100644 --- a/tools/kvm/virtio/blk.c +++ b/tools/kvm/virtio/blk.c @@ -134,18 +134,11 @@ static void virtio_blk_do_io(struct kvm *kvm, struct virt_queue *vq, struct blk_ } } -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct blk_dev *bdev = dev; - ((u8 *)(&bdev->blk_config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct blk_dev *bdev = dev; - - return ((u8 *)(&bdev->blk_config))[offset]; + return ((u8 *)(&bdev->blk_config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -230,7 +223,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size) } static struct virtio_ops blk_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c index 4bb1365..e925a54 100644 --- a/tools/kvm/virtio/console.c +++ b/tools/kvm/virtio/console.c @@ -105,18 +105,11 @@ static void virtio_console_handle_callback(struct kvm *kvm, void *param) } -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct con_dev *cdev = dev; - ((u8 *)(&cdev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct con_dev *cdev = dev; - - return ((u8 *)(&cdev->config))[offset]; + return ((u8 *)(&cdev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -174,7 +167,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq) } static struct virtio_ops con_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/mmio.c b/tools/kvm/virtio/mmio.c index 1cf0815..5971922 100644 --- a/tools/kvm/virtio/mmio.c +++ b/tools/kvm/virtio/mmio.c @@ -94,11 +94,11 @@ static void virtio_mmio_device_specific(u64 addr, u8 *data, u32 len, for (i = 0; i < len; i++) { if (is_write) - vdev->ops->set_config(vmmio->kvm, vmmio->dev, - *(u8 *)data + i, addr + i); + vdev->ops->get_config(vmmio->kvm, vmmio->dev)[addr + i] = + *(u8 *)data + i; else data[i] = vdev->ops->get_config(vmmio->kvm, - vmmio->dev, addr + i); + vmmio->dev)[addr + i]; } } diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index 8f3735b..25bc3a4 100644 --- a/tools/kvm/virtio/net.c +++ b/tools/kvm/virtio/net.c @@ -290,18 +290,11 @@ static struct net_dev_operations uip_ops = { .tx = uip_ops_tx, }; -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct net_dev *ndev = dev; - ((u8 *)(&ndev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct net_dev *ndev = dev; - - return ((u8 *)(&ndev->config))[offset]; + return ((u8 *)(&ndev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -448,7 +441,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size) } static struct virtio_ops net_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/pci.c b/tools/kvm/virtio/pci.c index 4dc7916..81f95ae 100644 --- a/tools/kvm/virtio/pci.c +++ b/tools/kvm/virtio/pci.c @@ -86,7 +86,7 @@ static bool virtio_pci__specific_io_in(struct kvm *kvm, struct virtio_device *vd } else if (type == VIRTIO_PCI_O_CONFIG) { u8 cfg; - cfg = vdev->ops->get_config(kvm, vpci->dev, config_offset); + cfg = vdev->ops->get_config(kvm, vpci->dev)[config_offset]; ioport__write8(data, cfg); return true; } @@ -164,7 +164,7 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_device *v return true; } else if (type == VIRTIO_PCI_O_CONFIG) { - vdev->ops->set_config(kvm, vpci->dev, *(u8 *)data, config_offset); + vdev->ops->get_config(kvm, vpci->dev)[config_offset] = *(u8 *)data; return true; } diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c index 5aa632d..2b1ab39 100644 --- a/tools/kvm/virtio/rng.c +++ b/tools/kvm/virtio/rng.c @@ -41,12 +41,7 @@ struct rng_dev { static LIST_HEAD(rdevs); static int compat_id = -1; -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) -{ - /* Unused */ -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { /* Unused */ return 0; @@ -138,7 +133,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq) } static struct virtio_ops rng_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features, diff --git a/tools/kvm/virtio/scsi.c b/tools/kvm/virtio/scsi.c index 8276fb0..c445f08 100644 --- a/tools/kvm/virtio/scsi.c +++ b/tools/kvm/virtio/scsi.c @@ -29,18 +29,11 @@ struct scsi_dev { struct kvm *kvm; }; -static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset) +static u8 *get_config(struct kvm *kvm, void *dev) { struct scsi_dev *sdev = dev; - ((u8 *)(&sdev->config))[offset] = data; -} - -static u8 get_config(struct kvm *kvm, void *dev, u32 offset) -{ - struct scsi_dev *sdev = dev; - - return ((u8 *)(&sdev->config))[offset]; + return ((u8 *)(&sdev->config)); } static u32 get_host_features(struct kvm *kvm, void *dev) @@ -174,7 +167,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size) } static struct virtio_ops scsi_dev_virtio_ops = (struct virtio_ops) { - .set_config = set_config, .get_config = get_config, .get_host_features = get_host_features, .set_guest_features = set_guest_features,