Skip to contentSkip to conversation

qdev: compat properties.

PATCH In review Gerd Hoffmann 4 participants 13 messages Jul 13, 2009 – Jul 14, 2009

lore
Share & tools
lore
#0 lore raw

v3 cover qdev: compat properties.

Hi,

Respin of the compat property patch series, now using the existing stringify() macro.

cheers,
Gerd

#1 lore raw

PATCH 1/6 cleanup: drop unused struct elements from VirtIOPCIProxy.

---
 hw/virtio-pci.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
hw/virtio-pci.c +0 -6
index 3b9bfd1..0671967 100644
@@ -86,12 +86,6 @@ typedef struct {
     PCIDevice pci_dev;
     VirtIODevice *vdev;
     uint32_t addr;
-
-    uint16_t vendor;
-    uint16_t device;
-    uint16_t subvendor;
-    uint16_t class_code;
-    uint8_t pif;
 } VirtIOPCIProxy;
 
 /* virtio device */
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/6 qdev/compat: compat property infrastructure.

In reply to Gerd Hoffmann
---
 hw/boards.h          |    1 +
 hw/qdev-properties.c |   19 +++++++++++++++++++
 hw/qdev.c            |    1 +
 hw/qdev.h            |   11 +++++++++++
 vl.c                 |    2 ++
 5 files changed, 34 insertions(+), 0 deletions(-)
hw/boards.h +1 -0
index f6733b7..5a07d07 100644
@@ -17,6 +17,7 @@ typedef struct QEMUMachine {
     int use_scsi;
     int max_cpus;
     int is_default;
+    struct CompatProperty *compat_props;
     struct QEMUMachine *next;
 } QEMUMachine;
 
hw/qdev-properties.c +19 -0
index ea937ae..2b1ee7d 100644
@@ -244,3 +244,22 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props)
     }
 }
 
+static CompatProperty *compat_props;
+
+void qdev_register_compat_props(CompatProperty *props)
+{
+    compat_props = props;
+}
+
+void qdev_prop_set_compat(DeviceState *dev)
+{
+    CompatProperty *prop;
+
+    if (!compat_props)
+        return;
+    for (prop = compat_props; prop->driver != NULL; prop++) {
+        if (strcmp(dev->info->name, prop->driver) != 0)
+            continue;
+        qdev_prop_parse(dev, prop->property, prop->value);
+    }
+}
hw/qdev.c +1 -0
index cdb25d4..7ca078d 100644
@@ -98,6 +98,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
     dev->parent_bus = bus;
     qdev_prop_set_defaults(dev, dev->info->props);
     qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
+    qdev_prop_set_compat(dev);
     LIST_INSERT_HEAD(&bus->children, dev, sibling);
     return dev;
 }
hw/qdev.h +11 -0
index e807036..f49f641 100644
@@ -8,6 +8,8 @@ typedef struct Property Property;
 
 typedef struct PropertyInfo PropertyInfo;
 
+typedef struct CompatProperty CompatProperty;
+
 typedef struct DeviceInfo DeviceInfo;
 
 typedef struct BusState BusState;
@@ -71,6 +73,12 @@ struct PropertyInfo {
     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
 };
 
+struct CompatProperty {
+    const char *driver;
+    const char *property;
+    const char *value;
+};
+
 /*** Board API.  This should go away once we have a machine config file.  ***/
 
 DeviceState *qdev_create(BusState *bus, const char *name);
@@ -174,4 +182,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
 
+void qdev_register_compat_props(CompatProperty *props);
+void qdev_prop_set_compat(DeviceState *dev);
+
 #endif
vl.c +2 -0
index cdc7b8a..5402787 100644
@@ -5911,6 +5911,8 @@ int main(int argc, char **argv, char **envp)
 
     module_call_init(MODULE_INIT_DEVICE);
 
+    if (machine->compat_props)
+        qdev_register_compat_props(machine->compat_props);
     machine->init(ram_size, boot_devices,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
Signature · 1 line
1.6.2.5
#3 lore raw

Re: [Qemu-devel] [PATCH 2/6] qdev/compat: compat property infrastructure.

Some coding style comments

Quoted 15 lines · Gerd Hoffmann
---
 hw/boards.h          |    1 +
 hw/qdev-properties.c |   19 +++++++++++++++++++
 hw/qdev.c            |    1 +
 hw/qdev.h            |   11 +++++++++++
 vl.c                 |    2 ++
 5 files changed, 34 insertions(+), 0 deletions(-)
hw/boards.h +0 -0
index f6733b7..5a07d07 100644

hw/boards.h typedef struct QEMUMachine { · line 20

Quoted 4 lines
hw/boards.h +1 -0
@@ -17,6 +17,7 @@ typedef struct QEMUMachine {
     int use_scsi;
     int max_cpus;
     int is_default;
+    struct CompatProperty *compat_props;

use a typedef

Quoted 13 lines
hw/boards.h +0 -0
     struct QEMUMachine *next;
 } QEMUMachine;
 
hw/qdev-properties.c +2 -0
index ea937ae..2b1ee7d 100644
@@ -244,3 +244,22 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props)
     }
 }
 
+static CompatProperty *compat_props;
+

hw/qdev-properties.c void qdev_prop_set_defaults(DeviceState *dev, Property *props) · line 258

Quoted 10 lines
hw/qdev-properties.c +10 -0
+void qdev_register_compat_props(CompatProperty *props)
+{
+    compat_props = props;
+}
+
+void qdev_prop_set_compat(DeviceState *dev)
+{
+    CompatProperty *prop;
+
+    if (!compat_props)

Missing {}

hw/qdev-properties.c void qdev_prop_set_defaults(DeviceState *dev, Property *props) · line 260

Quoted 2 lines
hw/qdev-properties.c +2 -0
+        return;
+    for (prop = compat_props; prop->driver != NULL; prop++) {

!= NULL not needed in if

hw/qdev-properties.c void qdev_prop_set_defaults(DeviceState *dev, Property *props) · line 261

Quoted 1 line
hw/qdev-properties.c +1 -0
+        if (strcmp(dev->info->name, prop->driver) != 0)

!= 0 not needed in if

hw/qdev-properties.c void qdev_prop_set_defaults(DeviceState *dev, Property *props) · line 262

Quoted 1 line
hw/qdev-properties.c +1 -0
+            continue;

Missing {}

hw/qdev-properties.c void qdev_prop_set_defaults(DeviceState *dev, Property *props) · line 263

Quoted 1 line
hw/qdev-properties.c +1 -0
+        qdev_prop_parse(dev, prop->property, prop->value);

check return value?

Quoted 41 lines
hw/qdev-properties.c +2 -0
+    }
+}
hw/qdev.c +1 -0
index cdb25d4..7ca078d 100644
@@ -98,6 +98,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
     dev->parent_bus = bus;
     qdev_prop_set_defaults(dev, dev->info->props);
     qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
+    qdev_prop_set_compat(dev);
     LIST_INSERT_HEAD(&bus->children, dev, sibling);
     return dev;
 }
hw/qdev.h +8 -0
index e807036..f49f641 100644
@@ -8,6 +8,8 @@ typedef struct Property Property;
 
 typedef struct PropertyInfo PropertyInfo;
 
+typedef struct CompatProperty CompatProperty;
+
 typedef struct DeviceInfo DeviceInfo;
 
 typedef struct BusState BusState;
@@ -71,6 +73,12 @@ struct PropertyInfo {
     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
 };
 
+struct CompatProperty {
+    const char *driver;
+    const char *property;
+    const char *value;
+};
+
 /*** Board API.  This should go away once we have a machine config file.  ***/
 
 DeviceState *qdev_create(BusState *bus, const char *name);

hw/qdev.h void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); · line 185

Quoted 4 lines
hw/qdev.h +1 -0
@@ -174,4 +182,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
 
+void qdev_register_compat_props(CompatProperty *props);

qedev_set_compat_props might be a better name.

hw/qdev.h void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); · line 186

Quoted 1 line
hw/qdev.h +1 -0
+void qdev_prop_set_compat(DeviceState *dev);

qdev_parse_compat_props might be a better name.

vl.c int main(int argc, char **argv, char **envp) · line 5914

Quoted 11 lines
hw/qdev.h +1 -0
+
 #endif
vl.c +1 -0
index cdc7b8a..5402787 100644
@@ -5911,6 +5911,8 @@ int main(int argc, char **argv, char **envp)
 
     module_call_init(MODULE_INIT_DEVICE);
 
+    if (machine->compat_props)

Missing {}

Quoted 8 lines
vl.c +1 -0
+        qdev_register_compat_props(machine->compat_props);
     machine->init(ram_size, boot_devices,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
Signature · 1 line
1.6.2.5
#4 lore raw

Re: [Qemu-devel] [PATCH 2/6] qdev/compat: compat property infrastructure.

Quoted 9 lines · Michael S. Tsirkin

Some coding style comments

hw/qdev-properties.c void qdev_prop_set_defaults(DeviceState *dev, Property *props) · line 260

Quoted 2 lines
hw/qdev-properties.c +2 -0
+        return;
+    for (prop = compat_props; prop->driver != NULL; prop++) {

!= NULL not needed in if

Quoted 1 line

+ if (strcmp(dev->info->name, prop->driver) != 0)

!= 0 not needed in if

I still prefer to have it explicitly written as it makes the code more readable IMHO.

Quoted 9 lines
Quoted 3 lines
  void qdev_prop_set_defaults(DeviceState *dev, Property *props);

+void qdev_register_compat_props(CompatProperty *props);

qedev_set_compat_props might be a better name.

Quoted 1 line

+void qdev_prop_set_compat(DeviceState *dev);

qdev_parse_compat_props might be a better name.

Disagree on both. qdev_prop_set_compat intentionally follows the name convention of the other qdev_prop_set_* functions. The qdev_register_compat_props intentionally isn't named something with "set" to avoid confusion with the other ones because it doesn't actually set properties on devices. "register" maybe isn't the best idea, I'm open to better suggestions.

Fixed the other ones.

cheers,
Gerd

#5 lore raw

[Qemu-devel] Re: [PATCH 2/6] qdev/compat: compat property infrastructure.

Quoted 22 lines · Gerd Hoffmann
Quoted 9 lines · Michael S. Tsirkin

Some coding style comments

hw/qdev-properties.c void qdev_prop_set_defaults(DeviceState *dev, Property *props) · line 260

Quoted 2 lines
hw/qdev-properties.c +2 -0
+        return;
+    for (prop = compat_props; prop->driver != NULL; prop++) {

!= NULL not needed in if

Quoted 1 line

+ if (strcmp(dev->info->name, prop->driver) != 0)

!= 0 not needed in if

I still prefer to have it explicitly written as it makes the code more readable IMHO.

Quoted 8 lines
Quoted 3 lines
  void qdev_prop_set_defaults(DeviceState *dev, Property *props);

+void qdev_register_compat_props(CompatProperty *props);

qedev_set_compat_props might be a better name.

Quoted 1 line

+void qdev_prop_set_compat(DeviceState *dev);

Quoted 8 lines
Quoted 1 line

qdev_parse_compat_props might be a better name.

Disagree on both. qdev_prop_set_compat intentionally follows the name convention of the other qdev_prop_set_* functions. The qdev_register_compat_props intentionally isn't named something with "set" to avoid confusion with the other ones because it doesn't actually set properties on devices. "register" maybe isn't the best idea, I'm open to better suggestions.

I didn't liked either. I would prefer to also use qdev_prop_ preffix as the other functions that deal with properties.

+void qdev_prop_register_compat(CompatProperty *props); ???

(I didn't get any good name with [qdev,prop,compat] in it.

Later, Juan.

Quoted 4 lines

Fixed the other ones.

cheers,
Gerd

#6 lore raw

[Qemu-devel] Re: [PATCH 2/6] qdev/compat: compat property infrastructure.

Quoted 1 line · Juan Quintela

+void qdev_prop_register_compat(CompatProperty *props); ???

Looks good to me.

cheers,
Gerd

#7 lore raw

PATCH 3/6 qdev/compat: add pc-0.10 machine type.

In reply to Gerd Hoffmann
---
 hw/pc.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
hw/pc.c +11 -0
index ccd2fed..6ba6b25 100644
@@ -1457,6 +1457,16 @@ static QEMUMachine pc_machine = {
     .is_default = 1,
 };
 
+static QEMUMachine pc_machine_v0_10 = {
+    .name = "pc-0.10",
+    .desc = "Standard PC, qemu 0.10",
+    .init = pc_init_pci,
+    .max_cpus = 255,
+    .compat_props = (CompatProperty[]) {
+        { /* end of list */ }
+    },
+};
+
 static QEMUMachine isapc_machine = {
     .name = "isapc",
     .desc = "ISA-only PC",
@@ -1467,6 +1477,7 @@ static QEMUMachine isapc_machine = {
 static void pc_machine_init(void)
 {
     qemu_register_machine(&pc_machine);
+    qemu_register_machine(&pc_machine_v0_10);
     qemu_register_machine(&isapc_machine);
 }
 
Signature · 1 line
1.6.2.5
#8 lore raw

PATCH 4/6 qdev/compat: virtio-blk-pci 0.10 compatibility.

In reply to Gerd Hoffmann
---
 hw/pc.c         |    5 +++++
 hw/virtio-pci.c |   16 ++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)
hw/pc.c +5 -0
index 6ba6b25..a4000dd 100644
@@ -1463,6 +1463,11 @@ static QEMUMachine pc_machine_v0_10 = {
     .init = pc_init_pci,
     .max_cpus = 255,
     .compat_props = (CompatProperty[]) {
+        {
+            .driver   = "virtio-blk-pci",
+            .property = "class",
+            .value    = stringify(PCI_CLASS_STORAGE_OTHER),
+        },
         { /* end of list */ }
     },
 };
hw/virtio-pci.c +14 -2
index 0671967..41ba574 100644
@@ -86,6 +86,7 @@ typedef struct {
     PCIDevice pci_dev;
     VirtIODevice *vdev;
     uint32_t addr;
+    uint32_t class_code;
 } VirtIOPCIProxy;
 
 /* virtio device */
@@ -425,12 +426,15 @@ static void virtio_blk_init_pci(PCIDevice *pci_dev)
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
 
+    if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
+        proxy->class_code != PCI_CLASS_STORAGE_OTHER)
+        proxy->class_code = PCI_CLASS_STORAGE_SCSI;
+
     vdev = virtio_blk_init(&pci_dev->qdev);
     virtio_init_pci(proxy, vdev,
                     PCI_VENDOR_ID_REDHAT_QUMRANET,
                     PCI_DEVICE_ID_VIRTIO_BLOCK,
-                    PCI_CLASS_STORAGE_OTHER,
-                    0x00);
+                    proxy->class_code, 0x00);
 }
 
 static void virtio_console_init_pci(PCIDevice *pci_dev)
@@ -477,6 +481,14 @@ static PCIDeviceInfo virtio_info[] = {
         .qdev.name = "virtio-blk-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
         .init      = virtio_blk_init_pci,
+        .qdev.props = (Property[]) {
+            {
+                .name   = "class",
+                .info   = &qdev_prop_hex32,
+                .offset = offsetof(VirtIOPCIProxy, class_code),
+            },
+            {/* end of list */}
+        },
     },{
         .qdev.name = "virtio-net-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
Signature · 1 line
1.6.2.5
#9 lore raw

PATCH 5/6 qdev/compat: virtio-console-pci 0.10 compatibility.

In reply to Gerd Hoffmann
---
 hw/pc.c         |    4 ++++
 hw/virtio-pci.c |   16 ++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
hw/pc.c +4 -0
index a4000dd..e1187dd 100644
@@ -1467,6 +1467,10 @@ static QEMUMachine pc_machine_v0_10 = {
             .driver   = "virtio-blk-pci",
             .property = "class",
             .value    = stringify(PCI_CLASS_STORAGE_OTHER),
+        },{
+            .driver   = "virtio-console-pci",
+            .property = "class",
+            .value    = stringify(PCI_CLASS_DISPLAY_OTHER),
         },
         { /* end of list */ }
     },
hw/virtio-pci.c +14 -2
index 41ba574..f186b53 100644
@@ -442,12 +442,16 @@ static void virtio_console_init_pci(PCIDevice *pci_dev)
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
 
+    if (proxy->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
+        proxy->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
+        proxy->class_code != PCI_CLASS_OTHERS)          /* qemu-kvm  */
+        proxy->class_code = PCI_CLASS_COMMUNICATION_OTHER;
+
     vdev = virtio_console_init(&pci_dev->qdev);
     virtio_init_pci(proxy, vdev,
                     PCI_VENDOR_ID_REDHAT_QUMRANET,
                     PCI_DEVICE_ID_VIRTIO_CONSOLE,
-                    PCI_CLASS_DISPLAY_OTHER,
-                    0x00);
+                    proxy->class_code, 0x00);
 }
 
 static void virtio_net_init_pci(PCIDevice *pci_dev)
@@ -497,6 +501,14 @@ static PCIDeviceInfo virtio_info[] = {
         .qdev.name = "virtio-console-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
         .init      = virtio_console_init_pci,
+        .qdev.props = (Property[]) {
+            {
+                .name   = "class",
+                .info   = &qdev_prop_hex32,
+                .offset = offsetof(VirtIOPCIProxy, class_code),
+            },
+            {/* end of list */}
+        },
     },{
         .qdev.name = "virtio-balloon-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
Signature · 1 line
1.6.2.5
#10 lore raw

PATCH 6/6 qdev/compat: virtio-net-pci 0.10 compatibility.

In reply to Gerd Hoffmann
---
 hw/pc.c         |    4 ++++
 hw/virtio-pci.c |   27 ++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 3 deletions(-)
hw/pc.c +4 -0
index e1187dd..da740f4 100644
@@ -1471,6 +1471,10 @@ static QEMUMachine pc_machine_v0_10 = {
             .driver   = "virtio-console-pci",
             .property = "class",
             .value    = stringify(PCI_CLASS_DISPLAY_OTHER),
+        },{
+            .driver   = "virtio-net-pci",
+            .property = "vectors",
+            .value    = stringify(0),
         },
         { /* end of list */ }
     },
hw/virtio-pci.c +24 -3
index f186b53..703f4fe 100644
@@ -19,6 +19,7 @@
 #include "pci.h"
 //#include "sysemu.h"
 #include "msix.h"
+#include "net.h"
 
 /* from Linux's linux/virtio_pci.h */
 
@@ -87,6 +88,7 @@ typedef struct {
     VirtIODevice *vdev;
     uint32_t addr;
     uint32_t class_code;
+    uint32_t nvectors;
 } VirtIOPCIProxy;
 
 /* virtio device */
@@ -460,11 +462,21 @@ static void virtio_net_init_pci(PCIDevice *pci_dev)
     VirtIODevice *vdev;
 
     vdev = virtio_net_init(&pci_dev->qdev);
+
+    /* set nvectors from property, unless the user specified something
+     * via -net nic,model=virtio,vectors=n command line option */
+    if (pci_dev->qdev.nd->nvectors == NIC_NVECTORS_UNSPECIFIED)
+        if (proxy->nvectors != NIC_NVECTORS_UNSPECIFIED)
+            vdev->nvectors = proxy->nvectors;
+
     virtio_init_pci(proxy, vdev,
                     PCI_VENDOR_ID_REDHAT_QUMRANET,
                     PCI_DEVICE_ID_VIRTIO_NET,
                     PCI_CLASS_NETWORK_ETHERNET,
                     0x00);
+
+    /* make the actual value visible */
+    proxy->nvectors = vdev->nvectors;
 }
 
 static void virtio_balloon_init_pci(PCIDevice *pci_dev)
@@ -494,9 +506,18 @@ static PCIDeviceInfo virtio_info[] = {
             {/* end of list */}
         },
     },{
-        .qdev.name = "virtio-net-pci",
-        .qdev.size = sizeof(VirtIOPCIProxy),
-        .init      = virtio_net_init_pci,
+        .qdev.name  = "virtio-net-pci",
+        .qdev.size  = sizeof(VirtIOPCIProxy),
+        .init       = virtio_net_init_pci,
+        .qdev.props = (Property[]) {
+            {
+                .name   = "vectors",
+                .info   = &qdev_prop_uint32,
+                .offset = offsetof(VirtIOPCIProxy, nvectors),
+                .defval = (uint32_t[]) { NIC_NVECTORS_UNSPECIFIED },
+            },
+            {/* end of list */}
+        },
     },{
         .qdev.name = "virtio-console-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
Signature · 1 line
1.6.2.5
#11 lore raw
In reply to Gerd Hoffmann
Quoted 5 lines · Gerd Hoffmann

Hi,

Respin of the compat property patch series, now using the existing stringify() macro.

Did you get the numbering wrong here? It looks like the patches are all N/6.

When posting multiple series like this, it woudl be helpful for each patch to include the rev number (v3) and a common prefix for the subjects. It can get a little confusing especially with three revs of the same series in a couple days.

Regards,

Anthony Liguori

Quoted 6 lines

cheers,
Gerd

#12 lore raw
Quoted 8 lines · Anthony Liguori
Quoted 4 lines · Gerd Hoffmann

Hi,

Respin of the compat property patch series, now using the existing stringify() macro.

Did you get the numbering wrong here? It looks like the patches are all N/6.

Yes, only 6 patches. Copyed the intro message from v2 which had the additional strify patch.

Quoted 3 lines

When posting multiple series like this, it woudl be helpful for each patch to include the rev number (v3) and a common prefix for the subjects.

Ok.

cheers,
Gerd