=====================================================================
@@ -0,0 +1,40 @@
+#ifndef VIRTIO_PCI_DEV_H_
+#define VIRTIO_PCI_DEV_H_
+
+/*
+ * Virtio PCI device constants and resources
+ * they do use (such as irqs and pins).
+ */
+
+#define PCI_DEVICE_ID_VIRTIO_NET 0x1000
+#define PCI_DEVICE_ID_VIRTIO_BLK 0x1001
+#define PCI_DEVICE_ID_VIRTIO_CONSOLE 0x1003
+#define PCI_DEVICE_ID_VIRTIO_RNG 0x1004
+
+#define PCI_SUBSYSTEM_ID_VIRTIO_NET 0x0001
+#define PCI_SUBSYSTEM_ID_VIRTIO_BLK 0x0002
+#define PCI_SUBSYSTEM_ID_VIRTIO_CONSOLE 0x0003
+#define PCI_SUBSYSTEM_ID_VIRTIO_RNG 0x0004
+
+enum {
+ PCI_VIRTIO_BLK_DEVNUM = 1,
+ PCI_VIRTIO_CONSOLE_DEVNUM = 2,
+ PCI_VIRTIO_NET_DEVNUM = 3,
+ PCI_VIRTIO_RNG_DEVNUM = 4,
+};
+
+enum {
+ VIRTIO_BLK_PIN = 1,
+ VIRTIO_CONSOLE_PIN = 2,
+ VIRTIO_NET_PIN = 3,
+ VIRTIO_RNG_PIN = 4,
+};
+
+enum {
+ VIRTIO_RNG_IRQ = 11,
+ VIRTIO_CONSOLE_IRQ = 13,
+ VIRTIO_NET_IRQ = 14,
+ VIRTIO_BLK_IRQ = 15,
+};
+
+#endif /* VIRTIO_PCI_DEV_H_ */
=====================================================================
@@ -34,26 +34,41 @@
/* A 16-bit r/w queue notifier */
#define VIRTIO_PCI_QUEUE_NOTIFY 16
-/* An 8-bit device status register. */
+/* 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. */
+/*
+ * 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. */
+/*
+ * 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. */
+/* 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 */
+/*
+ * 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 */
=====================================================================
@@ -1,6 +1,7 @@
#include "kvm/virtio-blk.h"
#include "kvm/virtio-pci.h"
+#include "kvm/virtio-pci-dev.h"
#include "kvm/disk-image.h"
#include "kvm/virtio.h"
@@ -17,9 +18,6 @@
#include <inttypes.h>
#include <pthread.h>
-#define VIRTIO_BLK_IRQ 15
-#define VIRTIO_BLK_PIN 1
-
#define NUM_VIRT_QUEUES 1
#define VIRTIO_BLK_QUEUE_SIZE 128
@@ -223,11 +221,6 @@ static struct ioport_operations virtio_b
.io_out = virtio_blk_pci_io_out,
};
-#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
-#define PCI_DEVICE_ID_VIRTIO_BLK 0x1001
-#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4
-#define PCI_SUBSYSTEM_ID_VIRTIO_BLK 0x0002
-
static struct pci_device_header virtio_blk_pci_device = {
.vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
.device_id = PCI_DEVICE_ID_VIRTIO_BLK,
@@ -241,8 +234,6 @@ static struct pci_device_header virtio_b
.irq_line = VIRTIO_BLK_IRQ,
};
-#define PCI_VIRTIO_BLK_DEVNUM 1
-
void virtio_blk__init(struct kvm *self)
{
if (!self->disk_image)
=====================================================================
@@ -1,5 +1,6 @@
#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"
#include "kvm/ioport.h"
@@ -23,14 +24,10 @@
#include <unistd.h>
#include <fcntl.h>
-#define VIRTIO_CONSOLE_IRQ 13
-#define VIRTIO_CONSOLE_PIN 2
-
#define VIRTIO_CONSOLE_QUEUE_SIZE 128
#define VIRTIO_CONSOLE_NUM_QUEUES 2
#define VIRTIO_CONSOLE_RX_QUEUE 0
#define VIRTIO_CONSOLE_TX_QUEUE 1
-#define PCI_VIRTIO_CONSOLE_DEVNUM 2
struct console_device {
pthread_mutex_t mutex;
@@ -227,11 +224,6 @@ static struct ioport_operations virtio_c
.io_out = virtio_console_pci_io_out,
};
-#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
-#define PCI_DEVICE_ID_VIRTIO_CONSOLE 0x1003
-#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4
-#define PCI_SUBSYSTEM_ID_VIRTIO_CONSOLE 0x0003
-
static struct pci_device_header virtio_console_pci_device = {
.vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
.device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE,
=====================================================================
@@ -1,5 +1,6 @@
#include "kvm/virtio-net.h"
#include "kvm/virtio-pci.h"
+#include "kvm/virtio-pci-dev.h"
#include "kvm/virtio.h"
#include "kvm/ioport.h"
#include "kvm/types.h"
@@ -20,14 +21,10 @@
#include <unistd.h>
#include <sys/wait.h>
-#define VIRTIO_NET_IRQ 14
-#define VIRTIO_NET_PIN 3
-
#define VIRTIO_NET_QUEUE_SIZE 128
#define VIRTIO_NET_NUM_QUEUES 2
#define VIRTIO_NET_RX_QUEUE 0
#define VIRTIO_NET_TX_QUEUE 1
-#define PCI_VIRTIO_NET_DEVNUM 3
struct net_device {
pthread_mutex_t mutex;
@@ -263,11 +260,6 @@ static struct ioport_operations virtio_n
.io_out = virtio_net_pci_io_out,
};
-#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
-#define PCI_DEVICE_ID_VIRTIO_NET 0x1000
-#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4
-#define PCI_SUBSYSTEM_ID_VIRTIO_NET 0x0001
-
static struct pci_device_header virtio_net_pci_device = {
.vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
.device_id = PCI_DEVICE_ID_VIRTIO_NET,
=====================================================================
@@ -1,6 +1,7 @@
#include "kvm/virtio-rng.h"
#include "kvm/virtio-pci.h"
+#include "kvm/virtio-pci-dev.h"
#include "kvm/disk-image.h"
#include "kvm/virtio.h"
@@ -20,15 +21,6 @@
#include <inttypes.h>
#include <pthread.h>
-#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 VIRTIO_RNG_IRQ 11
-#define VIRTIO_RNG_PIN 1
-
#define NUM_VIRT_QUEUES 1
#define VIRTIO_RNG_QUEUE_SIZE 128
It's better than have them sprinkled in.c files. Note that pin for ring device is changed so it no longer shared with block device (it is done in a sake of simplicity). Also comment style if a bit tuned up in virtio-pci.h just to be consistent. Reported-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- tools/kvm/include/kvm/virtio-pci-dev.h | 40 +++++++++++++++++++++++++++++++++ tools/kvm/include/kvm/virtio-pci.h | 31 ++++++++++++++++++------- tools/kvm/virtio-blk.c | 11 --------- tools/kvm/virtio-console.c | 10 -------- tools/kvm/virtio-net.c | 10 -------- tools/kvm/virtio-rng.c | 10 -------- 6 files changed, 67 insertions(+), 45 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html