From patchwork Wed May 11 15:17:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 776222 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4BFmIGC028489 for ; Wed, 11 May 2011 15:48:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755137Ab1EKPrd (ORCPT ); Wed, 11 May 2011 11:47:33 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:55962 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754630Ab1EKPrb (ORCPT ); Wed, 11 May 2011 11:47:31 -0400 Received: by wya21 with SMTP id 21so485956wya.19 for ; Wed, 11 May 2011 08:47:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=rjQpPkb53sO4mlvijwRWiWPFqadPg6D2zT5/iPx/Xkg=; b=aJsVJ5Q/ZFa8i0gfpS0cdV2/3SgJtxhbiyHnDUf896IyTcFaN3P6+CQRfKM4C7nhiU FOebQRuoaDuAcud/t5fVopzmHrch1w4UOj0nN+d0x9Q8tI0/1KcY7QJfEJFrYbxt06iG aFUl6old4+Yf6+sGwc6aS2m3dm898CT08vbeU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=oBG9Yr3bViTPKBCX+4sBf7d3TnYtpQo5D08+F2BbJr/WFOyK3IWXcE1lc/MaDGTtCx lPZyImfNOlE7E3bYsM/I1HNgZnjjwfvuvzumynHM/gcNqVXG0hOrw00K8ealORtanHI3 Rpse8vP4KgykAyWh1jK6LqTTJMiticqicNU+k= Received: by 10.227.37.197 with SMTP id y5mr3789767wbd.4.1305127064952; Wed, 11 May 2011 08:17:44 -0700 (PDT) Received: from localhost.localdomain ([188.120.134.217]) by mx.google.com with ESMTPS id w25sm170262wbd.22.2011.05.11.08.17.42 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 11 May 2011 08:17:44 -0700 (PDT) From: levinsasha928@gmail.com To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, prasadjoshi124@gmail.com, avi@redhat.com, gorcunov@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 3/3] kvm tools: Use definitions from kernel headers Date: Wed, 11 May 2011 18:17:25 +0300 Message-Id: <4dcaa898.5925e30a.0f9e.125e@mx.google.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1305127045-3532-1-git-send-email-a> References: <1305127045-3532-1-git-send-email-a> 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.6 (demeter1.kernel.org [140.211.167.41]); Wed, 11 May 2011 15:48:18 +0000 (UTC) From: Sasha Levin Instead of redefining virtio pci constants (or not using them at all), use constants from kernel header. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/virtio-pci-dev.h | 3 + tools/kvm/include/kvm/virtio-pci.h | 74 -------------------------------- tools/kvm/include/kvm/virtio.h | 3 +- tools/kvm/virtio/blk.c | 5 +- tools/kvm/virtio/console.c | 9 ++-- tools/kvm/virtio/net.c | 9 ++-- tools/kvm/virtio/rng.c | 3 +- 7 files changed, 16 insertions(+), 90 deletions(-) delete mode 100644 tools/kvm/include/kvm/virtio-pci.h diff --git a/tools/kvm/include/kvm/virtio-pci-dev.h b/tools/kvm/include/kvm/virtio-pci-dev.h index d2274d0..706ad20 100644 --- a/tools/kvm/include/kvm/virtio-pci-dev.h +++ b/tools/kvm/include/kvm/virtio-pci-dev.h @@ -16,4 +16,7 @@ #define PCI_SUBSYSTEM_ID_VIRTIO_CONSOLE 0x0003 #define PCI_SUBSYSTEM_ID_VIRTIO_RNG 0x0004 +#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 +#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4 + #endif /* VIRTIO_PCI_DEV_H_ */ diff --git a/tools/kvm/include/kvm/virtio-pci.h b/tools/kvm/include/kvm/virtio-pci.h deleted file mode 100644 index b507d1d..0000000 --- a/tools/kvm/include/kvm/virtio-pci.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Virtio PCI driver - * - * This module allows virtio devices to be used over a virtual PCI device. - * This can be used with QEMU based VMMs like KVM or Xen. - * - * Copyright IBM Corp. 2007 - * - * Authors: - * Anthony Liguori - * - * This header is BSD licensed so anyone can use the definitions to implement - * compatible drivers/servers. - */ - -#ifndef _LINUX_VIRTIO_PCI_H -#define _LINUX_VIRTIO_PCI_H - -/* A 32-bit r/o bitmask of the features supported by the host */ -#define VIRTIO_PCI_HOST_FEATURES 0 - -/* A 32-bit r/w bitmask of features activated by the guest */ -#define VIRTIO_PCI_GUEST_FEATURES 4 - -/* A 32-bit r/w PFN for the currently selected queue */ -#define VIRTIO_PCI_QUEUE_PFN 8 - -/* A 16-bit r/o queue size for the currently selected queue */ -#define VIRTIO_PCI_QUEUE_NUM 12 - -/* A 16-bit r/w queue selector */ -#define VIRTIO_PCI_QUEUE_SEL 14 - -/* A 16-bit r/w queue notifier */ -#define VIRTIO_PCI_QUEUE_NOTIFY 16 - -/* An 8-bit device status register */ -#define VIRTIO_PCI_STATUS 18 - -/* - * An 8-bit r/o interrupt status register. - * - * Reading the value will return the current contents of - * the ISR and will also clear it. This is effectively - * a read-and-acknowledge. - */ -#define VIRTIO_PCI_ISR 19 - -/* - * MSI-X registers: only enabled if MSI-X is enabled. - */ - -/* A 16-bit vector for configuration changes */ -#define VIRTIO_MSI_CONFIG_VECTOR 20 - -/* A 16-bit vector for selected queue notifications */ -#define VIRTIO_MSI_QUEUE_VECTOR 22 - -/* Vector value used to disable MSI for queue */ -#define VIRTIO_MSI_NO_VECTOR 0xffff - -/* - * Config space size. - */ -#define VIRTIO_PCI_CONFIG_NOMSI 20 -#define VIRTIO_PCI_CONFIG_MSI 24 - -/* - * Virtio config space constants. - */ -#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 -#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4 - -#endif /* _LINUX_VIRTIO_PCI_H */ diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h index bea63df..66e6fdb 100644 --- a/tools/kvm/include/kvm/virtio.h +++ b/tools/kvm/include/kvm/virtio.h @@ -2,6 +2,7 @@ #define KVM__VIRTIO_H #include +#include #include #include @@ -43,7 +44,7 @@ static inline bool virt_queue__available(struct virt_queue *vq) */ static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn) { - return guest_flat_to_host(kvm, (unsigned long)pfn << 12); + return guest_flat_to_host(kvm, (unsigned long)pfn << VIRTIO_PCI_QUEUE_ADDR_SHIFT); } struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len); diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c index 9f1aa1d..8d480bf 100644 --- a/tools/kvm/virtio/blk.c +++ b/tools/kvm/virtio/blk.c @@ -1,6 +1,5 @@ #include "kvm/virtio-blk.h" -#include "kvm/virtio-pci.h" #include "kvm/virtio-pci-dev.h" #include "kvm/irq.h" #include "kvm/disk-image.h" @@ -58,7 +57,7 @@ static bool virtio_blk_dev_in(struct blk_dev *bdev, void *data, unsigned long of if (size != 1 || count != 1) return false; - ioport__write8(data, config_space[offset - VIRTIO_PCI_CONFIG_NOMSI]); + ioport__write8(data, config_space[offset - VIRTIO_MSI_CONFIG_VECTOR]); return true; } @@ -199,7 +198,7 @@ static bool virtio_blk_pci_io_out(struct kvm *self, u16 port, void *data, int si queue->pfn = ioport__read32(data); p = guest_pfn_to_host(self, queue->pfn); - vring_init(&queue->vring, VIRTIO_BLK_QUEUE_SIZE, p, 4096); + vring_init(&queue->vring, VIRTIO_BLK_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN); *job = (struct blk_dev_job) { .vq = queue, diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c index 87b816a..38f52f9 100644 --- a/tools/kvm/virtio/console.c +++ b/tools/kvm/virtio/console.c @@ -1,5 +1,4 @@ #include "kvm/virtio-console.h" -#include "kvm/virtio-pci.h" #include "kvm/virtio-pci-dev.h" #include "kvm/disk-image.h" #include "kvm/virtio.h" @@ -104,10 +103,10 @@ static bool virtio_console_pci_io_device_specific_in(void *data, unsigned long o if (size != 1 || count != 1) return false; - if ((offset - VIRTIO_PCI_CONFIG_NOMSI) > sizeof(struct virtio_console_config)) - error("config offset is too big: %li", offset - VIRTIO_PCI_CONFIG_NOMSI); + if ((offset - VIRTIO_MSI_CONFIG_VECTOR) > sizeof(struct virtio_console_config)) + error("config offset is too big: %li", offset - VIRTIO_MSI_CONFIG_VECTOR); - ioport__write8(data, config_space[offset - VIRTIO_PCI_CONFIG_NOMSI]); + ioport__write8(data, config_space[offset - VIRTIO_MSI_CONFIG_VECTOR]); return true; } @@ -201,7 +200,7 @@ static bool virtio_console_pci_io_out(struct kvm *self, u16 port, void *data, in queue->pfn = ioport__read32(data); p = guest_pfn_to_host(self, queue->pfn); - vring_init(&queue->vring, VIRTIO_CONSOLE_QUEUE_SIZE, p, 4096); + vring_init(&queue->vring, VIRTIO_CONSOLE_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN); if (cdev.queue_selector == VIRTIO_CONSOLE_TX_QUEUE) cdev.jobs[cdev.queue_selector] = thread_pool__add_job(self, virtio_console_handle_callback, queue); diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index 3f3ee22..2009d4a 100644 --- a/tools/kvm/virtio/net.c +++ b/tools/kvm/virtio/net.c @@ -1,5 +1,4 @@ #include "kvm/virtio-net.h" -#include "kvm/virtio-pci.h" #include "kvm/virtio-pci-dev.h" #include "kvm/virtio.h" #include "kvm/ioport.h" @@ -154,10 +153,10 @@ static bool virtio_net_pci_io_device_specific_in(void *data, unsigned long offse if (size != 1 || count != 1) return false; - if ((offset - VIRTIO_PCI_CONFIG_NOMSI) > sizeof(struct virtio_net_config)) - error("config offset is too big: %li", offset - VIRTIO_PCI_CONFIG_NOMSI); + if ((offset - VIRTIO_MSI_CONFIG_VECTOR) > sizeof(struct virtio_net_config)) + error("config offset is too big: %li", offset - VIRTIO_MSI_CONFIG_VECTOR); - ioport__write8(data, config_space[offset - VIRTIO_PCI_CONFIG_NOMSI]); + ioport__write8(data, config_space[offset - VIRTIO_MSI_CONFIG_VECTOR]); return true; } @@ -247,7 +246,7 @@ static bool virtio_net_pci_io_out(struct kvm *self, u16 port, void *data, int si queue->pfn = ioport__read32(data); p = guest_pfn_to_host(self, queue->pfn); - vring_init(&queue->vring, VIRTIO_NET_QUEUE_SIZE, p, 4096); + vring_init(&queue->vring, VIRTIO_NET_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN); break; } diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c index 1951d0d1c..cf258fa 100644 --- a/tools/kvm/virtio/rng.c +++ b/tools/kvm/virtio/rng.c @@ -1,6 +1,5 @@ #include "kvm/virtio-rng.h" -#include "kvm/virtio-pci.h" #include "kvm/virtio-pci-dev.h" #include "kvm/disk-image.h" @@ -131,7 +130,7 @@ static bool virtio_rng_pci_io_out(struct kvm *kvm, u16 port, void *data, int siz queue->pfn = ioport__read32(data); p = guest_pfn_to_host(kvm, queue->pfn); - vring_init(&queue->vring, VIRTIO_RNG_QUEUE_SIZE, p, 4096); + vring_init(&queue->vring, VIRTIO_RNG_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN); rdev.jobs[rdev.queue_selector] = thread_pool__add_job(kvm, virtio_rng_do_io, queue);