public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: penberg@kernel.org, mingo@elte.hu
Cc: asias.hejun@gmail.com, prasadjoshi124@gmail.com,
	kvm@vger.kernel.org, levinsasha928@gmail.com,
	Cyrill Gorcunov <gorcunov@gmail.com>
Subject: [patch 2/2] kvm tools - Cleanup IRQs definitions for virtio pci devices
Date: Thu, 05 May 2011 23:06:41 +0400	[thread overview]
Message-ID: <20110505190733.660393774@gmail.com> (raw)
In-Reply-To: 20110505190639.741709609@gmail.com

[-- Attachment #1: kvm-tools-virtio-pci-irqs --]
[-- Type: text/plain, Size: 4359 bytes --]

This also requires to tune up mptable code. Note the srcbusirq
need to follow specification convention, so we merge device
number and pin into one field inside mptable_set_default_int_src
helper.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 tools/kvm/include/kvm/virtio-pci-dev.h |   16 +++++--
 tools/kvm/mptable.c                    |   67 ++++++++++++++++++++++++---------
 2 files changed, 61 insertions(+), 22 deletions(-)

Index: linux-2.6.git/tools/kvm/include/kvm/virtio-pci-dev.h
=====================================================================
--- linux-2.6.git.orig/tools/kvm/include/kvm/virtio-pci-dev.h
+++ linux-2.6.git/tools/kvm/include/kvm/virtio-pci-dev.h
@@ -30,11 +30,19 @@ enum {
 	VIRTIO_RNG_PIN				= 4,
 };
 
+/*
+ * The IRQ numbers should confirm Linux IRQ numbering
+ * scheme model, which supposes devices to start IRQs
+ * from 32 ... 127, but 0x30-0x3f are used for ISA
+ * interrupts so we choose 0x40 as the origin.
+ */
+#define VIRTIO_PCI_DEV_FIRST_IRQ		0x40
+
 enum {
-	VIRTIO_RNG_IRQ				= 11,
-	VIRTIO_CONSOLE_IRQ			= 13,
-	VIRTIO_NET_IRQ				= 14,
-	VIRTIO_BLK_IRQ				= 15,
+	VIRTIO_RNG_IRQ				= VIRTIO_PCI_DEV_FIRST_IRQ + 0,
+	VIRTIO_CONSOLE_IRQ			= VIRTIO_PCI_DEV_FIRST_IRQ + 1,
+	VIRTIO_NET_IRQ				= VIRTIO_PCI_DEV_FIRST_IRQ + 2,
+	VIRTIO_BLK_IRQ				= VIRTIO_PCI_DEV_FIRST_IRQ + 3,
 };
 
 #endif /* VIRTIO_PCI_DEV_H_ */
Index: linux-2.6.git/tools/kvm/mptable.c
=====================================================================
--- linux-2.6.git.orig/tools/kvm/mptable.c
+++ linux-2.6.git/tools/kvm/mptable.c
@@ -3,6 +3,7 @@
 #include "kvm/apic.h"
 #include "kvm/mptable.h"
 #include "kvm/util.h"
+#include "kvm/virtio-pci-dev.h"
 
 #include <linux/kernel.h>
 #include <string.h>
@@ -60,16 +61,17 @@ static unsigned int gen_cpu_flag(unsigne
  */
 #define MPTABLE_MAX_CPUS	255
 
-static void mptable_add_irq_src(struct mpc_intsrc *mpc_intsrc,
-				u16 srcbusid,	u16 srcbusirq,
-				u16 dstapic,	u16 dstirq)
+static void
+mptable_set_default_int_src(struct mpc_intsrc *dst,
+			    u8 dev, u8 pin, u16 srcbusid,
+			    u16 dstapic, u16 dstirq)
 {
-	*mpc_intsrc = (struct mpc_intsrc) {
+	*dst = (struct mpc_intsrc) {
 		.type		= MP_INTSRC,
 		.irqtype	= mp_INT,
 		.irqflag	= MP_IRQDIR_DEFAULT,
 		.srcbus		= srcbusid,
-		.srcbusirq	= srcbusirq,
+		.srcbusirq	= (dev << 2) | (pin - 1),
 		.dstapic	= dstapic,
 		.dstirq		= dstirq
 	};
@@ -186,28 +188,57 @@ void mptable_setup(struct kvm *kvm, unsi
 	 *
 	 * Also note we use PCI irqs here, no for ISA bus yet.
 	 */
-	mpc_intsrc		= last_addr;
 
-	/* src irq = virtio console irq pin, dst irq = virtio console irq */
-	mptable_add_irq_src(mpc_intsrc, pcibusid, 2, ioapicid, 13);
-	last_addr = (void *)&mpc_intsrc[1];
+	/*
+	 * Virtio console.
+	 */
+	mpc_intsrc		= last_addr;
+	mptable_set_default_int_src(mpc_intsrc,
+				    PCI_VIRTIO_CONSOLE_DEVNUM,
+				    VIRTIO_CONSOLE_PIN,
+				    pcibusid, ioapicid,
+				    VIRTIO_CONSOLE_IRQ);
+	last_addr		= (void *)&mpc_intsrc[1];
 	nentries++;
 
-	/* Currently we define 4 possible virtio-blk devices */
+	/*
+	 * Virtio block devices.
+	 *
+	 * Currently we define 4 possible virtio-blk devices.
+	 */
 	for (i = 0; i < 4; i++) {
-		mpc_intsrc		= last_addr;
-
-		/* src irq = virtio blk irq pin, dst irq = virtio blk irq */
-		mptable_add_irq_src(mpc_intsrc, pcibusid, 1, ioapicid, 9 + i);
-		last_addr = (void *)&mpc_intsrc[1];
+		mpc_intsrc	= last_addr;
+		mptable_set_default_int_src(mpc_intsrc,
+					    PCI_VIRTIO_BLK_DEVNUM,
+					    VIRTIO_BLK_PIN,
+					    pcibusid, ioapicid,
+					    VIRTIO_BLK_IRQ + i);
+		last_addr	= (void *)&mpc_intsrc[1];
 		nentries++;
 	}
 
+	/*
+	 * Virtio net device.
+	 */
 	mpc_intsrc		= last_addr;
+	mptable_set_default_int_src(mpc_intsrc,
+				    PCI_VIRTIO_NET_DEVNUM,
+				    VIRTIO_NET_PIN,
+				    pcibusid, ioapicid,
+				    VIRTIO_NET_IRQ);
+	last_addr		= (void *)&mpc_intsrc[1];
+	nentries++;
 
-	/* src irq = virtio net irq pin, dst irq = virtio net irq */
-	mptable_add_irq_src(mpc_intsrc, pcibusid, 3, ioapicid, 14);
-	last_addr = (void *)&mpc_intsrc[1];
+	/*
+	 * Virtio random number generator.
+	 */
+	mpc_intsrc		= last_addr;
+	mptable_set_default_int_src(mpc_intsrc,
+				    PCI_VIRTIO_RNG_DEVNUM,
+				    VIRTIO_RNG_PIN,
+				    pcibusid, ioapicid,
+				    VIRTIO_RNG_IRQ);
+	last_addr		= (void *)&mpc_intsrc[1];
 	nentries++;
 
 	/*


  parent reply	other threads:[~2011-05-05 19:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-05 19:06 [patch 0/2] kvm-tools -- cleanup Cyrill Gorcunov
2011-05-05 19:06 ` [patch 1/2] kvm tools: Gather Virtio-PCI constants into one place Cyrill Gorcunov
2011-05-05 19:11   ` Cyrill Gorcunov
2011-05-05 20:09   ` Cyrill Gorcunov
2011-05-05 19:06 ` Cyrill Gorcunov [this message]
2011-05-05 20:14   ` [patch 2/2] kvm tools - Cleanup IRQs definitions for virtio pci devices Pekka Enberg
2011-05-05 20:15     ` Cyrill Gorcunov
2011-05-05 20:16       ` Pekka Enberg
2011-05-05 20:19         ` Cyrill Gorcunov
2011-05-05 20:24           ` Pekka Enberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110505190733.660393774@gmail.com \
    --to=gorcunov@gmail.com \
    --cc=asias.hejun@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    --cc=prasadjoshi124@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox