Il 26/06/2014 16:34, Marc MarĂ­ ha scritto:
+static void qvirtio_pci_foreach(uint16_t device_type,
+                void (*func)(QVirtioDevice *d, void *data), void *data)
+{
+    QVirtioPCIForeachData d = { .func = func,
+                                .device_type = device_type,
+                                .user_data = data };
+
+    if (!bus) {
+        bus = qpci_init_pc();

Why not pass this as an argument? .bus_foreach and .device_find need not be part of QVirtioBus.

+    }
+
+    qpci_device_foreach(bus, QVIRTIO_VENDOR_ID, -1,
+                                qvirtio_pci_foreach_callback, &d);
+}
+
+static QVirtioDevice *qvirtio_pci_device_find(uint16_t device_type)

(Also here, qvirtio_pci_device_find would just forward the bus to qvirtio_pci_foreach).

+    fprintf(stderr, "Device position: %x. Device type: %x\n",
+                                    dev->pdev->devfn, dev->vdev.device_type);

You can change these to assertions, and get your first testcase too. :)

You can set the address in the qtest_start argument (like "-device virtio-blk-pci,...,addr=0x0a.0") so you know the expected value.

Otherwise looks good!

Paolo

+{
+    QVirtioPCIDevice *dev;
+
+    dev = g_malloc0(sizeof(*dev));
+    qvirtio_pci_foreach(device_type, qvirtio_pci_assign_device, dev);
+
+    return (QVirtioDevice *)dev;
+}


Reply via email to