From patchwork Thu May 5 18:34:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 757912 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 p45IZXip029142 for ; Thu, 5 May 2011 18:35:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932101Ab1EESf1 (ORCPT ); Thu, 5 May 2011 14:35:27 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:60713 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932073Ab1EESfZ (ORCPT ); Thu, 5 May 2011 14:35:25 -0400 Received: by mail-ww0-f44.google.com with SMTP id 36so2672274wwa.1 for ; Thu, 05 May 2011 11:35:25 -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=7HK32BZJJigBCOvhXkMZa3d4Ch4qRD0A8iVHPjmZWxM=; b=H0PBcW7qiVcU9yAmi/cEUcA9Qh9ycBZvv2FvBMchZroBPcq4Gp728dcKxKStMhuGu4 M/nbAN96L5zEyqMDCGlteQ+NSgLkuT/xqoQAjLYlqajduPn/rq4kUvblz+/fnnnWaf/I xP90T80tJg/FMVBOYBYw91NiVCeta4OSYBDUk= 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=dt0PFaB3QLcKSSxiAtJYqoBTUst6ZHQlnfhXFIl6SH4u0lwBzQ/QCoBzhMHX3THT/g LrOrIcTCDErrMEyAAzd5zb/S4/txXoCOLu9ylvaaA5EC4dVJU8TlJzcnJ6d73slOamvX rk4yAjFguW4Z3bZS0S7VCyZ+OWecVLO+0lNdo= Received: by 10.227.166.11 with SMTP id k11mr2776423wby.68.1304620524874; Thu, 05 May 2011 11:35:24 -0700 (PDT) Received: from localhost.localdomain ([109.65.211.213]) by mx.google.com with ESMTPS id x13sm1037449wby.25.2011.05.05.11.35.23 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 May 2011 11:35:24 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 5/5] kvm tools: virtio-rng code cleanup Date: Thu, 5 May 2011 21:34:35 +0300 Message-Id: <1304620475-10289-5-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1304620475-10289-1-git-send-email-levinsasha928@gmail.com> References: <1304620475-10289-1-git-send-email-levinsasha928@gmail.com> 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]); Thu, 05 May 2011 18:35:34 +0000 (UTC) Clean coding style and naming within virtio-rng. Signed-off-by: Sasha Levin Acked-by: Ingo Molnar --- tools/kvm/virtio/rng.c | 77 +++++++++++++++++++++++------------------------ 1 files changed, 38 insertions(+), 39 deletions(-) diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c index 65fa48d..61eb27e 100644 --- a/tools/kvm/virtio/rng.c +++ b/tools/kvm/virtio/rng.c @@ -19,36 +19,35 @@ #include #include -#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 -#define PCI_DEVICE_ID_VIRTIO_RNG 0x1004 +#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 +#define PCI_DEVICE_ID_VIRTIO_RNG 0x1004 #define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4 -#define PCI_SUBSYSTEM_ID_VIRTIO_RNG 0x0004 -#define PCI_VIRTIO_RNG_DEVNUM 4 +#define PCI_SUBSYSTEM_ID_VIRTIO_RNG 0x0004 +#define PCI_VIRTIO_RNG_DEVNUM 4 -#define VIRTIO_RNG_IRQ 11 -#define VIRTIO_RNG_PIN 1 +#define VIRTIO_RNG_IRQ 11 +#define VIRTIO_RNG_PIN 1 -#define NUM_VIRT_QUEUES 1 +#define NUM_VIRT_QUEUES 1 +#define VIRTIO_RNG_QUEUE_SIZE 128 -#define VIRTIO_RNG_QUEUE_SIZE 128 - -struct rng_device { - u8 status; - u16 config_vector; +struct rng_dev { + u8 status; + u16 config_vector; int fd_rng; /* virtio queue */ - u16 queue_selector; - struct virt_queue vqs[NUM_VIRT_QUEUES]; - void *jobs[NUM_VIRT_QUEUES]; + u16 queue_selector; + struct virt_queue vqs[NUM_VIRT_QUEUES]; + void *jobs[NUM_VIRT_QUEUES]; }; -static struct rng_device rng_device; +static struct rng_dev rdev; static bool virtio_rng_pci_io_in(struct kvm *kvm, u16 port, void *data, int size, u32 count) { - unsigned long offset; - bool ret = true; + unsigned long offset; + bool ret = true; offset = port - IOPORT_VIRTIO_RNG; @@ -60,20 +59,20 @@ static bool virtio_rng_pci_io_in(struct kvm *kvm, u16 port, void *data, int size ret = false; break; case VIRTIO_PCI_QUEUE_PFN: - ioport__write32(data, rng_device.vqs[rng_device.queue_selector].pfn); + ioport__write32(data, rdev.vqs[rdev.queue_selector].pfn); break; case VIRTIO_PCI_QUEUE_NUM: ioport__write16(data, VIRTIO_RNG_QUEUE_SIZE); break; case VIRTIO_PCI_STATUS: - ioport__write8(data, rng_device.status); + ioport__write8(data, rdev.status); break; case VIRTIO_PCI_ISR: ioport__write8(data, 0x1); kvm__irq_line(kvm, VIRTIO_RNG_IRQ, 0); break; case VIRTIO_MSI_CONFIG_VECTOR: - ioport__write16(data, rng_device.config_vector); + ioport__write16(data, rdev.config_vector); break; default: ret = false; @@ -82,14 +81,14 @@ static bool virtio_rng_pci_io_in(struct kvm *kvm, u16 port, void *data, int size return ret; } -static bool virtio_rng_do_io_request(struct kvm *self, struct virt_queue *queue) +static bool virtio_rng_do_io_request(struct kvm *kvm, struct virt_queue *queue) { struct iovec iov[VIRTIO_RNG_QUEUE_SIZE]; u16 out, in, head; unsigned int len = 0; - head = virt_queue__get_iov(queue, iov, &out, &in, self); - len = readv(rng_device.fd_rng, iov, in); + head = virt_queue__get_iov(queue, iov, &out, &in, kvm); + len = readv(rdev.fd_rng, iov, in); virt_queue__set_used_elem(queue, head, len); return true; @@ -120,51 +119,51 @@ static bool virtio_rng_pci_io_out(struct kvm *kvm, u16 port, void *data, int siz struct virt_queue *queue; void *p; - queue = &rng_device.vqs[rng_device.queue_selector]; + queue = &rdev.vqs[rdev.queue_selector]; queue->pfn = ioport__read32(data); - p = guest_flat_to_host(kvm, queue->pfn << 12); + p = guest_flat_to_host(kvm, queue->pfn << 12); vring_init(&queue->vring, VIRTIO_RNG_QUEUE_SIZE, p, 4096); - rng_device.jobs[rng_device.queue_selector] = + rdev.jobs[rdev.queue_selector] = thread_pool__add_job(kvm, virtio_rng_do_io, queue); break; } case VIRTIO_PCI_QUEUE_SEL: - rng_device.queue_selector = ioport__read16(data); + rdev.queue_selector = ioport__read16(data); break; case VIRTIO_PCI_QUEUE_NOTIFY: { u16 queue_index; queue_index = ioport__read16(data); - thread_pool__do_job(rng_device.jobs[queue_index]); + thread_pool__do_job(rdev.jobs[queue_index]); break; } case VIRTIO_PCI_STATUS: - rng_device.status = ioport__read8(data); + rdev.status = ioport__read8(data); break; case VIRTIO_MSI_CONFIG_VECTOR: - rng_device.config_vector = VIRTIO_MSI_NO_VECTOR; + rdev.config_vector = VIRTIO_MSI_NO_VECTOR; break; default: - ret = false; + ret = false; }; return ret; } static struct ioport_operations virtio_rng_io_ops = { - .io_in = virtio_rng_pci_io_in, - .io_out = virtio_rng_pci_io_out, + .io_in = virtio_rng_pci_io_in, + .io_out = virtio_rng_pci_io_out, }; static struct pci_device_header virtio_rng_pci_device = { .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET, .device_id = PCI_DEVICE_ID_VIRTIO_RNG, - .header_type = PCI_HEADER_TYPE_NORMAL, - .revision_id = 0, + .header_type = PCI_HEADER_TYPE_NORMAL, + .revision_id = 0, .class = 0x010000, - .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, + .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, .subsys_id = PCI_SUBSYSTEM_ID_VIRTIO_RNG, .bar[0] = IOPORT_VIRTIO_RNG | PCI_BASE_ADDRESS_SPACE_IO, .irq_pin = VIRTIO_RNG_PIN, @@ -173,8 +172,8 @@ static struct pci_device_header virtio_rng_pci_device = { void virtio_rng__init(struct kvm *kvm) { - rng_device.fd_rng = open("/dev/urandom", O_RDONLY); - if (rng_device.fd_rng < 0) + rdev.fd_rng = open("/dev/urandom", O_RDONLY); + if (rdev.fd_rng < 0) die("Failed initializing RNG"); pci__register(&virtio_rng_pci_device, PCI_VIRTIO_RNG_DEVNUM);