Skip to contentSkip to conversation

pci-ids: virtio cleanup

PATCH In review Gerd Hoffmann 2 participants 7 messages Oct 4, 2022

lore
Share & tools
lore
#0 lore raw

v3 cover pci-ids: virtio cleanup

Drop legacy ids for virtio 1.0 devices, they are not needed and will be overridden anyway by generic virtio pci code.

Improve modern virtio id documentation.

v3:
- add review + test tags
- more verbose commit messages.
- drop vsock (#define needed for bug compatibility reasons).
- added comment to pci.h, trying to avoid this happening again.

Gerd Hoffmann (5):
pci-ids: drop PCI_DEVICE_ID_VIRTIO_IOMMU
pci-ids: drop PCI_DEVICE_ID_VIRTIO_MEM
pci-ids: drop PCI_DEVICE_ID_VIRTIO_PMEM
pci-ids: drop list of modern virtio devices
pci-ids: document modern virtio-pci ids in pci.h too

 docs/specs/pci-ids.txt       | 16 +++++++---------
 include/hw/pci/pci.h         | 13 ++++++++++---
 hw/virtio/virtio-iommu-pci.c |  4 +---
 hw/virtio/virtio-mem-pci.c   |  2 --
 hw/virtio/virtio-pci.c       |  2 +-
 hw/virtio/virtio-pmem-pci.c  |  2 --
 6 files changed, 19 insertions(+), 20 deletions(-)
Signature · 1 line
2.37.3
#1 lore raw

PATCH v3 1/5 pci-ids: drop PCI_DEVICE_ID_VIRTIO_IOMMU

Not needed for a virtio 1.0 device. virtio_pci_device_plugged() overrides them anyway (so no functional change).

---
 include/hw/pci/pci.h         | 1 -
 hw/virtio/virtio-iommu-pci.c | 4 +---
 2 files changed, 1 insertion(+), 4 deletions(-)
include/hw/pci/pci.h +0 -1
index b54b6ef88fc3..89eaca429389 100644
@@ -85,7 +85,6 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
 #define PCI_DEVICE_ID_VIRTIO_VSOCK       0x1012
 #define PCI_DEVICE_ID_VIRTIO_PMEM        0x1013
-#define PCI_DEVICE_ID_VIRTIO_IOMMU       0x1014
 #define PCI_DEVICE_ID_VIRTIO_MEM         0x1015
 
 #define PCI_VENDOR_ID_REDHAT             0x1b36
hw/virtio/virtio-iommu-pci.c +1 -3
index 844d64770406..79ea8334f04e 100644
@@ -74,8 +74,6 @@ static void virtio_iommu_pci_class_init(ObjectClass *klass, void *data)
     k->realize = virtio_iommu_pci_realize;
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     device_class_set_props(dc, virtio_iommu_pci_properties);
-    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_IOMMU;
     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
     pcidev_k->class_id = PCI_CLASS_OTHERS;
     dc->hotpluggable = false;
@@ -90,7 +88,7 @@ static void virtio_iommu_pci_instance_init(Object *obj)
 }
 
 static const VirtioPCIDeviceTypeInfo virtio_iommu_pci_info = {
-    .generic_name          = TYPE_VIRTIO_IOMMU_PCI,
+    .generic_name  = TYPE_VIRTIO_IOMMU_PCI,
     .instance_size = sizeof(VirtIOIOMMUPCI),
     .instance_init = virtio_iommu_pci_instance_init,
     .class_init    = virtio_iommu_pci_class_init,
Signature · 1 line
2.37.3
#2 lore raw

PATCH v3 2/5 pci-ids: drop PCI_DEVICE_ID_VIRTIO_MEM

In reply to Gerd Hoffmann

Not needed for a virtio 1.0 device. virtio_pci_device_plugged() overrides them anyway (so no functional change).

---
 include/hw/pci/pci.h       | 1 -
 hw/virtio/virtio-mem-pci.c | 2 --
 2 files changed, 3 deletions(-)
include/hw/pci/pci.h +0 -1
index 89eaca429389..b6aefb33fb17 100644
@@ -85,7 +85,6 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
 #define PCI_DEVICE_ID_VIRTIO_VSOCK       0x1012
 #define PCI_DEVICE_ID_VIRTIO_PMEM        0x1013
-#define PCI_DEVICE_ID_VIRTIO_MEM         0x1015
 
 #define PCI_VENDOR_ID_REDHAT             0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE      0x0001
hw/virtio/virtio-mem-pci.c +0 -2
index be2383b0c522..5c5c1e3ae3da 100644
@@ -104,8 +104,6 @@ static void virtio_mem_pci_class_init(ObjectClass *klass, void *data)
 
     k->realize = virtio_mem_pci_realize;
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
-    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_MEM;
     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
     pcidev_k->class_id = PCI_CLASS_OTHERS;
 
Signature · 1 line
2.37.3
#3 lore raw

PATCH v3 3/5 pci-ids: drop PCI_DEVICE_ID_VIRTIO_PMEM

In reply to Gerd Hoffmann

Not needed for a virtio 1.0 device. virtio_pci_device_plugged() overrides them anyway (so no functional change).

---
 include/hw/pci/pci.h        | 1 -
 hw/virtio/virtio-pmem-pci.c | 2 --
 2 files changed, 3 deletions(-)
include/hw/pci/pci.h +0 -1
index b6aefb33fb17..42c83cb5ed00 100644
@@ -84,7 +84,6 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_VIRTIO_RNG         0x1005
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
 #define PCI_DEVICE_ID_VIRTIO_VSOCK       0x1012
-#define PCI_DEVICE_ID_VIRTIO_PMEM        0x1013
 
 #define PCI_VENDOR_ID_REDHAT             0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE      0x0001
hw/virtio/virtio-pmem-pci.c +0 -2
index 2b2a0b1eae10..7d9f4ec189b9 100644
@@ -90,8 +90,6 @@ static void virtio_pmem_pci_class_init(ObjectClass *klass, void *data)
 
     k->realize = virtio_pmem_pci_realize;
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
-    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_PMEM;
     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
     pcidev_k->class_id = PCI_CLASS_OTHERS;
 
Signature · 1 line
2.37.3
#4 lore raw

PATCH v3 4/5 pci-ids: drop list of modern virtio devices

In reply to Gerd Hoffmann

Drop the list of modern virtio devices and explain how they are calculated instead.

---
 docs/specs/pci-ids.txt | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
docs/specs/pci-ids.txt +7 -9
index dd6859d039d0..e463c4cb3a22 100644
@@ -22,16 +22,14 @@ maintained as part of the virtio specification.
 1af4:1004  SCSI host bus adapter device (legacy)
 1af4:1005  entropy generator device (legacy)
 1af4:1009  9p filesystem device (legacy)
+1af4:1012  vsock device (bug compatibility)
 
-1af4:1041  network device (modern)
-1af4:1042  block device (modern)
-1af4:1043  console device (modern)
-1af4:1044  entropy generator device (modern)
-1af4:1045  balloon device (modern)
-1af4:1048  SCSI host bus adapter device (modern)
-1af4:1049  9p filesystem device (modern)
-1af4:1050  virtio gpu device (modern)
-1af4:1052  virtio input device (modern)
+1af4:1040  Start of ID range for modern virtio devices.  The PCI device
+   to      ID is calculated from the virtio device ID by adding the
+1af4:10ef  0x1040 offset.  The virtio IDs are defined in the virtio
+           specification.  The Linux kernel has a header file with
+           defines for all virtio IDs (linux/virtio_ids.h), qemu has a
+           copy in include/standard-headers/.
 
 1af4:10f0  Available for experimental usage without registration.  Must get
    to      official ID when the code leaves the test lab (i.e. when seeking
Signature · 1 line
2.37.3
#5 lore raw

PATCH v3 5/5 pci-ids: document modern virtio-pci ids in pci.h too

In reply to Gerd Hoffmann

While being at it add a #define for the magic 0x1040 number.

---
 include/hw/pci/pci.h   | 10 ++++++++++
 hw/virtio/virtio-pci.c |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
include/hw/pci/pci.h +10 -0
index 42c83cb5ed00..d1ac308574f1 100644
@@ -76,6 +76,7 @@ extern bool pci_available;
 #define PCI_SUBVENDOR_ID_REDHAT_QUMRANET 0x1af4
 #define PCI_SUBDEVICE_ID_QEMU            0x1100
 
+/* legacy virtio-pci devices */
 #define PCI_DEVICE_ID_VIRTIO_NET         0x1000
 #define PCI_DEVICE_ID_VIRTIO_BLOCK       0x1001
 #define PCI_DEVICE_ID_VIRTIO_BALLOON     0x1002
@@ -85,6 +86,15 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
 #define PCI_DEVICE_ID_VIRTIO_VSOCK       0x1012
 
+/*
+ * modern virtio-pci devices get their id assigned automatically,
+ * there is no need to add #defines here.  It gets calculated as
+ *
+ * PCI_DEVICE_ID = PCI_DEVICE_ID_VIRTIO_10_BASE +
+ *                 virtio_bus_get_vdev_id(bus)
+ */
+#define PCI_DEVICE_ID_VIRTIO_10_BASE     0x1040
+
 #define PCI_VENDOR_ID_REDHAT             0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE      0x0001
 #define PCI_DEVICE_ID_REDHAT_SERIAL      0x0002
hw/virtio/virtio-pci.c +1 -1
index a50c5a57d7e5..e7d80242b73f 100644
@@ -1688,7 +1688,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
         pci_set_word(config + PCI_VENDOR_ID,
                      PCI_VENDOR_ID_REDHAT_QUMRANET);
         pci_set_word(config + PCI_DEVICE_ID,
-                     0x1040 + virtio_bus_get_vdev_id(bus));
+                     PCI_DEVICE_ID_VIRTIO_10_BASE + virtio_bus_get_vdev_id(bus));
         pci_config_set_revision(config, 1);
     }
     config[PCI_INTERRUPT_PIN] = 1;
Signature · 1 line
2.37.3
Reviewed-by on v3 5/5
#6 lore raw

Re: [PATCH v3 5/5] pci-ids: document modern virtio-pci ids in pci.h too

Hi Gerd,

Quoted 3 lines · Gerd Hoffmann

While being at it add a #define for the magic 0x1040 number.

Thanks

Eric

Quoted 46 lines
---
 include/hw/pci/pci.h   | 10 ++++++++++
 hw/virtio/virtio-pci.c |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
include/hw/pci/pci.h +10 -0
index 42c83cb5ed00..d1ac308574f1 100644
@@ -76,6 +76,7 @@ extern bool pci_available;
 #define PCI_SUBVENDOR_ID_REDHAT_QUMRANET 0x1af4
 #define PCI_SUBDEVICE_ID_QEMU            0x1100
 
+/* legacy virtio-pci devices */
 #define PCI_DEVICE_ID_VIRTIO_NET         0x1000
 #define PCI_DEVICE_ID_VIRTIO_BLOCK       0x1001
 #define PCI_DEVICE_ID_VIRTIO_BALLOON     0x1002
@@ -85,6 +86,15 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
 #define PCI_DEVICE_ID_VIRTIO_VSOCK       0x1012
 
+/*
+ * modern virtio-pci devices get their id assigned automatically,
+ * there is no need to add #defines here.  It gets calculated as
+ *
+ * PCI_DEVICE_ID = PCI_DEVICE_ID_VIRTIO_10_BASE +
+ *                 virtio_bus_get_vdev_id(bus)
+ */
+#define PCI_DEVICE_ID_VIRTIO_10_BASE     0x1040
+
 #define PCI_VENDOR_ID_REDHAT             0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE      0x0001
 #define PCI_DEVICE_ID_REDHAT_SERIAL      0x0002
hw/virtio/virtio-pci.c +1 -1
index a50c5a57d7e5..e7d80242b73f 100644
@@ -1688,7 +1688,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
         pci_set_word(config + PCI_VENDOR_ID,
                      PCI_VENDOR_ID_REDHAT_QUMRANET);
         pci_set_word(config + PCI_DEVICE_ID,
-                     0x1040 + virtio_bus_get_vdev_id(bus));
+                     PCI_DEVICE_ID_VIRTIO_10_BASE + virtio_bus_get_vdev_id(bus));
         pci_config_set_revision(config, 1);
     }
     config[PCI_INTERRUPT_PIN] = 1;