Skip to contentSkip to conversation

kvm tools: Set correct virtio pci device class code

PATCH New Asias He 1 participant 1 message Oct 27, 2011 KVM

lore
Share & tools
lore

Asias He

author
#0 lore raw

PATCH 1/1 kvm tools: Set correct virtio pci device class code

All the virtio pci device is set to class code 0x010000, this is wrong. This patch sets the correct class code and makes lspci report correct class type. For example, the net device:

Before:

$ lspci
00:03.0 SCSI storage controller: Red Hat, Inc Virtio network device

After:

$ lspci
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
---
 tools/kvm/include/kvm/virtio-pci-dev.h |   10 ++++++++++
 tools/kvm/include/kvm/virtio-pci.h     |    2 +-
 tools/kvm/virtio/9p.c                  |    2 +-
 tools/kvm/virtio/balloon.c             |    2 +-
 tools/kvm/virtio/blk.c                 |    2 +-
 tools/kvm/virtio/console.c             |    2 +-
 tools/kvm/virtio/net.c                 |    2 +-
 tools/kvm/virtio/pci.c                 |    4 ++--
 tools/kvm/virtio/rng.c                 |    2 +-
 9 files changed, 19 insertions(+), 9 deletions(-)
tools/kvm/include/kvm/virtio-pci-dev.h +10 -0
index bfcb076..e692bdd 100644
@@ -24,4 +24,14 @@
 #define PCI_SUBSYSTEM_ID_VESA			0x0004
 #define PCI_SUBSYSTEM_ID_PCI_SHMEM		0x0001
 
+#define PCI_CLASS_BLK				0x018000
+#define PCI_CLASS_NET				0x020000
+#define PCI_CLASS_CONSOLE			0x078000
+/*
+ * 0xFF Device does not fit in any defined classes
+ */
+#define PCI_CLASS_RNG				0xff0000
+#define PCI_CLASS_BLN				0xff0000
+#define PCI_CLASS_P9				0xff0000
+
 #endif /* VIRTIO_PCI_DEV_H_ */
tools/kvm/include/kvm/virtio-pci.h +1 -1
index ce44e84..d6d98df 100644
@@ -52,7 +52,7 @@ struct virtio_pci {
 };
 
 int virtio_pci__init(struct kvm *kvm, struct virtio_pci *vpci, void *dev,
-			int device_id, int subsys_id);
+			int device_id, int subsys_id, int class);
 int virtio_pci__signal_vq(struct kvm *kvm, struct virtio_pci *vpci, u32 vq);
 int virtio_pci__signal_config(struct kvm *kvm, struct virtio_pci *vpci);
 
tools/kvm/virtio/9p.c +1 -1
index 8dbd016..1569bb2 100644
@@ -1193,7 +1193,7 @@ int virtio_9p__init(struct kvm *kvm)
 	struct p9_dev *p9dev;
 
 	list_for_each_entry(p9dev, &devs, list) {
-		virtio_pci__init(kvm, &p9dev->vpci, p9dev, PCI_DEVICE_ID_VIRTIO_P9, VIRTIO_ID_9P);
+		virtio_pci__init(kvm, &p9dev->vpci, p9dev, PCI_DEVICE_ID_VIRTIO_P9, VIRTIO_ID_9P, PCI_CLASS_P9);
 		p9dev->vpci.ops = (struct virtio_pci_ops) {
 			.set_config		= set_config,
 			.get_config		= get_config,
tools/kvm/virtio/balloon.c +1 -1
index 0228686..9a52108 100644
@@ -242,7 +242,7 @@ void virtio_bln__init(struct kvm *kvm)
 	bdev.stat_waitfd	= eventfd(0, 0);
 	memset(&bdev.config, 0, sizeof(struct virtio_balloon_config));
 
-	virtio_pci__init(kvm, &bdev.vpci, &bdev, PCI_DEVICE_ID_VIRTIO_BLN, VIRTIO_ID_BALLOON);
+	virtio_pci__init(kvm, &bdev.vpci, &bdev, PCI_DEVICE_ID_VIRTIO_BLN, VIRTIO_ID_BALLOON, PCI_CLASS_BLN);
 	bdev.vpci.ops = (struct virtio_pci_ops) {
 		.set_config		= set_config,
 		.get_config		= get_config,
tools/kvm/virtio/blk.c +1 -1
index 8605951..6ffa753 100644
@@ -206,7 +206,7 @@ void virtio_blk__init(struct kvm *kvm, struct disk_image *disk)
 		},
 	};
 
-	virtio_pci__init(kvm, &bdev->vpci, bdev, PCI_DEVICE_ID_VIRTIO_BLK, VIRTIO_ID_BLOCK);
+	virtio_pci__init(kvm, &bdev->vpci, bdev, PCI_DEVICE_ID_VIRTIO_BLK, VIRTIO_ID_BLOCK, PCI_CLASS_BLK);
 	bdev->vpci.ops = (struct virtio_pci_ops) {
 		.set_config		= set_config,
 		.get_config		= get_config,
tools/kvm/virtio/console.c +1 -1
index 36997bd..f0e4bf8 100644
@@ -177,7 +177,7 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq)
 
 void virtio_console__init(struct kvm *kvm)
 {
-	virtio_pci__init(kvm, &cdev.vpci, &cdev, PCI_DEVICE_ID_VIRTIO_CONSOLE, VIRTIO_ID_CONSOLE);
+	virtio_pci__init(kvm, &cdev.vpci, &cdev, PCI_DEVICE_ID_VIRTIO_CONSOLE, VIRTIO_ID_CONSOLE, PCI_CLASS_CONSOLE);
 	cdev.vpci.ops = (struct virtio_pci_ops) {
 		.set_config		= set_config,
 		.get_config		= get_config,
tools/kvm/virtio/net.c +1 -1
index bfa2c7b..1b59972 100644
@@ -399,7 +399,7 @@ void virtio_net__init(const struct virtio_net_params *params)
 		ndev->ops = &uip_ops;
 	}
 
-	virtio_pci__init(kvm, &ndev->vpci, ndev, PCI_DEVICE_ID_VIRTIO_NET, VIRTIO_ID_NET);
+	virtio_pci__init(kvm, &ndev->vpci, ndev, PCI_DEVICE_ID_VIRTIO_NET, VIRTIO_ID_NET, PCI_CLASS_NET);
 	ndev->vpci.ops = (struct virtio_pci_ops) {
 		.set_config		= set_config,
 		.get_config		= get_config,
tools/kvm/virtio/pci.c +2 -2
index 73d55a9..fe3f746 100644
@@ -256,7 +256,7 @@ int virtio_pci__signal_config(struct kvm *kvm, struct virtio_pci *vpci)
 }
 
 int virtio_pci__init(struct kvm *kvm, struct virtio_pci *vpci, void *dev,
-			int device_id, int subsys_id)
+			int device_id, int subsys_id, int class)
 {
 	u8 pin, line, ndev;
 
@@ -273,7 +273,7 @@ int virtio_pci__init(struct kvm *kvm, struct virtio_pci *vpci, void *dev,
 		.device_id		= device_id,
 		.header_type		= PCI_HEADER_TYPE_NORMAL,
 		.revision_id		= 0,
-		.class			= 0x010000,
+		.class			= class,
 		.subsys_vendor_id	= PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET,
 		.subsys_id		= subsys_id,
 		.bar[0]			= vpci->base_addr | PCI_BASE_ADDRESS_SPACE_IO,
tools/kvm/virtio/rng.c +1 -1
index c7e7f2d..efb94c9 100644
@@ -150,7 +150,7 @@ void virtio_rng__init(struct kvm *kvm)
 	if (rdev->fd < 0)
 		die("Failed initializing RNG");
 
-	virtio_pci__init(kvm, &rdev->vpci, rdev, PCI_DEVICE_ID_VIRTIO_RNG, VIRTIO_ID_RNG);
+	virtio_pci__init(kvm, &rdev->vpci, rdev, PCI_DEVICE_ID_VIRTIO_RNG, VIRTIO_ID_RNG, PCI_CLASS_RNG);
 	rdev->vpci.ops = (struct virtio_pci_ops) {
 		.set_config		= set_config,
 		.get_config		= get_config,
Signature · 1 line
1.7.7.1