qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.


From: KONRAD Frédéric
Subject: Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.
Date: Wed, 09 Jan 2013 09:45:35 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

On 08/01/2013 18:54, Peter Maydell wrote:
On 7 January 2013 18:40,  <address@hidden> wrote:
From: KONRAD Frederic <address@hidden>

Create the virtio-pci device. This transport device will create a
virtio-pci-bus, so one VirtIODevice can be connected.

Signed-off-by: KONRAD Frederic <address@hidden>
---
  hw/virtio-pci.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  hw/virtio-pci.h |  18 ++++++++
  2 files changed, 145 insertions(+)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 5ff03e8..1f0ecbe 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1163,6 +1163,130 @@ static TypeInfo virtio_scsi_info = {
      .class_init    = virtio_scsi_class_init,
  };

+/*
+ * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
"has"

+ */
+
+/* This is called by virtio-bus just after the device is plugged. */
+static void virtio_pci_device_plugged(DeviceState *d)
+{
+    VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
+    VirtioBusState *bus = proxy->bus;
+    uint8_t *config;
+    uint32_t size;
+
+    /* Put the PCI IDs */
+    switch (virtio_device_get_id(proxy->bus)) {
+
+
+    default:
+        error_report("unknown device id\n");
+        break;
+
+    }
This doesn't have any code in it yet (it gets added in later patches) but
the final result looks very repetitive. I think you'd be better off just having
some arrays:

uint16_t virtio_pci_device_id[] = {
      [VIRTIO_ID_BLOCK] = PCI_DEVICE_ID_VIRTIO_BLOCK,
      [VIRTIO_ID_NET] = PCI_DEVICE_ID_VIRTIO_NET,
(etc)
};

similarly for the class. Then you can just drop the switch statement.

In fact I think you might as well put in the array entries for all
the virtio devices in this patch rather than adding one in each of the
"add virtio-foo device" patches; it will do no harm for them to be
there early and it makes the later patches a little smaller.
And what happen when it is a bad ID ?

Fred


+
+    proxy->vdev = proxy->bus->vdev;
+
+    config = proxy->pci_dev.config;
+    if (proxy->class_code) {
+        pci_config_set_class(config, proxy->class_code);
+    }
+    pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
+                 pci_get_word(config + PCI_VENDOR_ID));
+    pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_device_get_id(proxy->bus));
+    config[PCI_INTERRUPT_PIN] = 1;
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -45,6 +45,22 @@ typedef struct {
      unsigned int users;
  } VirtIOIRQFD;

+/*
+ * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
"has"

+ */
-- PMM





reply via email to

[Prev in Thread] Current Thread [Next in Thread]