qdev: register all types natively through QEMU Object Model

This was done in a mostly automated fashion.  I did it in three steps and then
rebased it into a single step which avoids repeatedly touching every file in
the tree.

The first step was a sed-based addition of the parent type to the subclass
registration functions.

The second step was another sed-based removal of subclass registration functions
while also adding virtual functions from the base class into a class_init
function as appropriate.

Finally, a python script was used to convert the DeviceInfo structures and
qdev_register_subclass functions to TypeInfo structures, class_init functions,
and type_register_static calls.

We are almost fully converted to QOM after this commit.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 126fb08..bc96552 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -818,6 +818,7 @@
 
 static void virtio_blk_class_init(ObjectClass *klass, void *data)
 {
+    DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = virtio_blk_init_pci;
@@ -826,15 +827,16 @@
     k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_STORAGE_SCSI;
+    dc->alias = "virtio-blk";
+    dc->reset = virtio_pci_reset;
+    dc->props = virtio_blk_properties;
 }
 
-static DeviceInfo virtio_blk_info = {
-    .name = "virtio-blk-pci",
-    .alias = "virtio-blk",
-    .size = sizeof(VirtIOPCIProxy),
-    .props = virtio_blk_properties,
-    .reset = virtio_pci_reset,
-    .class_init = virtio_blk_class_init,
+static TypeInfo virtio_blk_info = {
+    .name          = "virtio-blk-pci",
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(VirtIOPCIProxy),
+    .class_init    = virtio_blk_class_init,
 };
 
 static Property virtio_net_properties[] = {
@@ -850,6 +852,7 @@
 
 static void virtio_net_class_init(ObjectClass *klass, void *data)
 {
+    DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = virtio_net_init_pci;
@@ -859,15 +862,16 @@
     k->device_id = PCI_DEVICE_ID_VIRTIO_NET;
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+    dc->alias = "virtio-net";
+    dc->reset = virtio_pci_reset;
+    dc->props = virtio_net_properties;
 }
 
-static DeviceInfo virtio_net_info = {
-    .name = "virtio-net-pci",
-    .alias = "virtio-net",
-    .size = sizeof(VirtIOPCIProxy),
-    .props = virtio_net_properties,
-    .reset = virtio_pci_reset,
-    .class_init = virtio_net_class_init,
+static TypeInfo virtio_net_info = {
+    .name          = "virtio-net-pci",
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(VirtIOPCIProxy),
+    .class_init    = virtio_net_class_init,
 };
 
 static Property virtio_serial_properties[] = {
@@ -881,6 +885,7 @@
 
 static void virtio_serial_class_init(ObjectClass *klass, void *data)
 {
+    DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = virtio_serial_init_pci;
@@ -889,15 +894,16 @@
     k->device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE;
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
+    dc->alias = "virtio-serial";
+    dc->reset = virtio_pci_reset;
+    dc->props = virtio_serial_properties;
 }
 
-static DeviceInfo virtio_serial_info = {
-    .name = "virtio-serial-pci",
-    .alias = "virtio-serial",
-    .size = sizeof(VirtIOPCIProxy),
-    .props = virtio_serial_properties,
-    .reset = virtio_pci_reset,
-    .class_init = virtio_serial_class_init,
+static TypeInfo virtio_serial_info = {
+    .name          = "virtio-serial-pci",
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(VirtIOPCIProxy),
+    .class_init    = virtio_serial_class_init,
 };
 
 static Property virtio_balloon_properties[] = {
@@ -907,6 +913,7 @@
 
 static void virtio_balloon_class_init(ObjectClass *klass, void *data)
 {
+    DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = virtio_balloon_init_pci;
@@ -915,23 +922,28 @@
     k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_MEMORY_RAM;
+    dc->alias = "virtio-balloon";
+    dc->reset = virtio_pci_reset;
+    dc->props = virtio_balloon_properties;
 }
 
-static DeviceInfo virtio_balloon_info = {
-    .name = "virtio-balloon-pci",
-    .alias = "virtio-balloon",
-    .size = sizeof(VirtIOPCIProxy),
-    .props = virtio_balloon_properties,
-    .reset = virtio_pci_reset,
-    .class_init = virtio_balloon_class_init,
+static TypeInfo virtio_balloon_info = {
+    .name          = "virtio-balloon-pci",
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(VirtIOPCIProxy),
+    .class_init    = virtio_balloon_class_init,
 };
 
 static void virtio_pci_register_devices(void)
 {
-    pci_qdev_register(&virtio_blk_info);
-    pci_qdev_register(&virtio_net_info);
-    pci_qdev_register(&virtio_serial_info);
-    pci_qdev_register(&virtio_balloon_info);
+    type_register_static(&virtio_blk_info);
+    type_register_static_alias(&virtio_blk_info, "virtio-blk");
+    type_register_static(&virtio_net_info);
+    type_register_static_alias(&virtio_net_info, "virtio-net");
+    type_register_static(&virtio_serial_info);
+    type_register_static_alias(&virtio_serial_info, "virtio-serial");
+    type_register_static(&virtio_balloon_info);
+    type_register_static_alias(&virtio_balloon_info, "virtio-balloon");
 }
 
 device_init(virtio_pci_register_devices)