Patchwork [12/14] qbus: move print_dev to DeviceClass

login
register
mail settings
Submitter Anthony Liguori
Date April 18, 2012, 8:56 p.m.
Message ID <1334782613-5421-13-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/153593/
State New
Headers show

Comments

Anthony Liguori - April 18, 2012, 8:56 p.m.
It should have never been a bus method.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/isa-bus.c           |   37 ++++++++--------------
 hw/pci.c               |   79 +++++++++++++++++++++++------------------------
 hw/qdev-monitor.c      |   10 +++---
 hw/qdev.h              |    3 +-
 hw/sysbus.c            |   39 +++++++++--------------
 hw/usb/bus.c           |   35 ++++++++-------------
 hw/virtio-serial-bus.c |   32 +++++++------------
 7 files changed, 99 insertions(+), 136 deletions(-)

Patch

diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 6141515..07a9ae4 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -25,22 +25,12 @@ 
 static ISABus *isabus;
 target_phys_addr_t isa_mem_base = 0;
 
-static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent);
-
 #define TYPE_ISA_BUS "ISA"
 
-static void isa_bus_class_init(ObjectClass *klass, void *data)
-{
-    BusClass *k = BUS_CLASS(klass);
-
-    k->print_dev = isabus_dev_print;
-}
-
 static TypeInfo isa_bus_info = {
     .name = TYPE_ISA_BUS,
     .parent = TYPE_BUS,
     .instance_size = sizeof(ISABus),
-    .class_init = isa_bus_class_init,
 };
 
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io)
@@ -166,19 +156,6 @@  ISADevice *isa_create_simple(ISABus *bus, const char *name)
     return dev;
 }
 
-static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
-{
-    ISADevice *d = ISA_DEVICE(dev);
-
-    if (d->isairq[1] != -1) {
-        monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "",
-                       d->isairq[0], d->isairq[1]);
-    } else if (d->isairq[0] != -1) {
-        monitor_printf(mon, "%*sisa irq %d\n", indent, "",
-                       d->isairq[0]);
-    }
-}
-
 static int isabus_bridge_init(SysBusDevice *dev)
 {
     /* nothing */
@@ -216,12 +193,26 @@  static char *isa_device_get_fw_dev_path(DeviceState *dev)
     return strdup(path);
 }
 
+static void isa_qdev_dev_print(DeviceState *dev, Monitor *mon, int indent)
+{
+    ISADevice *d = ISA_DEVICE(dev);
+
+    if (d->isairq[1] != -1) {
+        monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "",
+                       d->isairq[0], d->isairq[1]);
+    } else if (d->isairq[0] != -1) {
+        monitor_printf(mon, "%*sisa irq %d\n", indent, "",
+                       d->isairq[0]);
+    }
+}
+
 static void isa_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
     k->init = isa_qdev_init;
     k->bus_type = TYPE_ISA_BUS;
     k->get_fw_dev_path = isa_device_get_fw_dev_path;
+    k->print_dev = isa_qdev_dev_print;
 }
 
 static TypeInfo isa_device_type_info = {
diff --git a/hw/pci.c b/hw/pci.c
index 425ceaa..39c44b2 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -39,14 +39,12 @@ 
 # define PCI_DPRINTF(format, ...)       do { } while (0)
 #endif
 
-static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 static int pcibus_reset(BusState *qbus);
 
 static void pci_bus_class_init(ObjectClass *klass, void *data)
 {
     BusClass *k = BUS_CLASS(klass);
 
-    k->print_dev = pcibus_dev_print;
     k->reset = pcibus_reset;
 }
 
@@ -1815,44 +1813,6 @@  uint8_t pci_find_capability(PCIDevice *pdev, uint8_t cap_id)
     return pci_find_capability_list(pdev, cap_id, NULL);
 }
 
-static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
-{
-    PCIDevice *d = (PCIDevice *)dev;
-    const pci_class_desc *desc;
-    char ctxt[64];
-    PCIIORegion *r;
-    int i, class;
-
-    class = pci_get_word(d->config + PCI_CLASS_DEVICE);
-    desc = pci_class_descriptions;
-    while (desc->desc && class != desc->class)
-        desc++;
-    if (desc->desc) {
-        snprintf(ctxt, sizeof(ctxt), "%s", desc->desc);
-    } else {
-        snprintf(ctxt, sizeof(ctxt), "Class %04x", class);
-    }
-
-    monitor_printf(mon, "%*sclass %s, addr %02x:%02x.%x, "
-                   "pci id %04x:%04x (sub %04x:%04x)\n",
-                   indent, "", ctxt, pci_bus_num(d->bus),
-                   PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
-                   pci_get_word(d->config + PCI_VENDOR_ID),
-                   pci_get_word(d->config + PCI_DEVICE_ID),
-                   pci_get_word(d->config + PCI_SUBSYSTEM_VENDOR_ID),
-                   pci_get_word(d->config + PCI_SUBSYSTEM_ID));
-    for (i = 0; i < PCI_NUM_REGIONS; i++) {
-        r = &d->io_regions[i];
-        if (!r->size)
-            continue;
-        monitor_printf(mon, "%*sbar %d: %s at 0x%"FMT_PCIBUS
-                       " [0x%"FMT_PCIBUS"]\n",
-                       indent, "",
-                       i, r->type & PCI_BASE_ADDRESS_SPACE_IO ? "i/o" : "mem",
-                       r->addr, r->addr + r->size - 1);
-    }
-}
-
 static char *pci_dev_fw_name(DeviceState *dev, char *buf, int len)
 {
     PCIDevice *d = (PCIDevice *)dev;
@@ -1989,6 +1949,44 @@  static char *pci_qdev_get_fw_dev_path(DeviceState *dev)
     return strdup(path);
 }
 
+static void pci_qdev_dev_print(DeviceState *dev, Monitor *mon, int indent)
+{
+    PCIDevice *d = PCI_DEVICE(dev);
+    const pci_class_desc *desc;
+    char ctxt[64];
+    PCIIORegion *r;
+    int i, class;
+
+    class = pci_get_word(d->config + PCI_CLASS_DEVICE);
+    desc = pci_class_descriptions;
+    while (desc->desc && class != desc->class)
+        desc++;
+    if (desc->desc) {
+        snprintf(ctxt, sizeof(ctxt), "%s", desc->desc);
+    } else {
+        snprintf(ctxt, sizeof(ctxt), "Class %04x", class);
+    }
+
+    monitor_printf(mon, "%*sclass %s, addr %02x:%02x.%x, "
+                   "pci id %04x:%04x (sub %04x:%04x)\n",
+                   indent, "", ctxt, pci_bus_num(d->bus),
+                   PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
+                   pci_get_word(d->config + PCI_VENDOR_ID),
+                   pci_get_word(d->config + PCI_DEVICE_ID),
+                   pci_get_word(d->config + PCI_SUBSYSTEM_VENDOR_ID),
+                   pci_get_word(d->config + PCI_SUBSYSTEM_ID));
+    for (i = 0; i < PCI_NUM_REGIONS; i++) {
+        r = &d->io_regions[i];
+        if (!r->size)
+            continue;
+        monitor_printf(mon, "%*sbar %d: %s at 0x%"FMT_PCIBUS
+                       " [0x%"FMT_PCIBUS"]\n",
+                       indent, "",
+                       i, r->type & PCI_BASE_ADDRESS_SPACE_IO ? "i/o" : "mem",
+                       r->addr, r->addr + r->size - 1);
+    }
+}
+
 static void pci_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
@@ -1998,6 +1996,7 @@  static void pci_device_class_init(ObjectClass *klass, void *data)
     k->bus_type = TYPE_PCI_BUS;
     k->get_dev_path = pci_qdev_get_dev_path;
     k->get_fw_dev_path = pci_qdev_get_fw_dev_path;
+    k->print_dev = pci_qdev_dev_print;
 }
 
 static Property pci_bus_properties[] = {
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 1f9528e..6b7fe84 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -518,12 +518,12 @@  static void qdev_print_prop(Object *obj, const char *name,
     }
 }
 
-static void bus_print_dev(BusState *bus, Monitor *mon, DeviceState *dev, int indent)
+static void qdev_print_dev(DeviceState *dev, Monitor *mon, int indent)
 {
-    BusClass *bc = BUS_GET_CLASS(bus);
+    DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (bc->print_dev) {
-        bc->print_dev(mon, dev, indent);
+    if (dc->print_dev) {
+        dc->print_dev(dev, mon, indent);
     }
 }
 
@@ -545,7 +545,7 @@  static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
         qdev_printf("gpio-out %d\n", dev->num_gpio_out);
     }
     object_property_foreach(OBJECT(dev), qdev_print_prop, &printer);
-    bus_print_dev(dev->parent_bus, mon, dev, indent + 2);
+    qdev_print_dev(dev, mon, indent + 2);
     QLIST_FOREACH(child, &dev->child_bus, sibling) {
         qbus_print(mon, child, indent + 2);
     }
diff --git a/hw/qdev.h b/hw/qdev.h
index b09a07b..2141bba 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -49,6 +49,7 @@  typedef struct DeviceClass {
     void (*reset)(DeviceState *dev);
     char *(*get_dev_path)(DeviceState *dev);
     char *(*get_fw_dev_path)(DeviceState *dev);
+    void (*print_dev)(DeviceState *dev, Monitor *mon, int indent);
 
     /* device state */
     const VMStateDescription *vmsd;
@@ -95,8 +96,6 @@  struct DeviceState {
 struct BusClass {
     ObjectClass parent_class;
 
-    /* FIXME first arg should be BusState */
-    void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
     int (*reset)(BusState *bus);
 };
 
diff --git a/hw/sysbus.c b/hw/sysbus.c
index 92b86ba..19de287 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -21,20 +21,10 @@ 
 #include "monitor.h"
 #include "exec-memory.h"
 
-static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
-
-static void system_bus_class_init(ObjectClass *klass, void *data)
-{
-    BusClass *k = BUS_CLASS(klass);
-
-    k->print_dev = sysbus_dev_print;
-}
-
 static TypeInfo system_bus_info = {
     .name = TYPE_SYSTEM_BUS,
     .parent = TYPE_BUS,
     .instance_size = sizeof(BusState),
-    .class_init = system_bus_class_init,
 };
 
 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq)
@@ -180,20 +170,6 @@  DeviceState *sysbus_try_create_varargs(const char *name,
     return dev;
 }
 
-static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
-{
-    SysBusDevice *s = sysbus_from_qdev(dev);
-    target_phys_addr_t size;
-    int i;
-
-    monitor_printf(mon, "%*sirq %d\n", indent, "", s->num_irq);
-    for (i = 0; i < s->num_mmio; i++) {
-        size = memory_region_size(s->mmio[i].memory);
-        monitor_printf(mon, "%*smmio " TARGET_FMT_plx "/" TARGET_FMT_plx "\n",
-                       indent, "", s->mmio[i].addr, size);
-    }
-}
-
 void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
                        MemoryRegion *mem)
 {
@@ -246,12 +222,27 @@  static char *sysbus_get_fw_dev_path(DeviceState *dev)
     return strdup(path);
 }
 
+static void sysbus_dev_print(DeviceState *dev, Monitor *mon, int indent)
+{
+    SysBusDevice *s = sysbus_from_qdev(dev);
+    target_phys_addr_t size;
+    int i;
+
+    monitor_printf(mon, "%*sirq %d\n", indent, "", s->num_irq);
+    for (i = 0; i < s->num_mmio; i++) {
+        size = memory_region_size(s->mmio[i].memory);
+        monitor_printf(mon, "%*smmio " TARGET_FMT_plx "/" TARGET_FMT_plx "\n",
+                       indent, "", s->mmio[i].addr, size);
+    }
+}
+
 static void sysbus_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
     k->init = sysbus_device_init;
     k->bus_type = TYPE_SYSTEM_BUS;
     k->get_fw_dev_path = sysbus_get_fw_dev_path;
+    k->print_dev = sysbus_dev_print;
 }
 
 static TypeInfo sysbus_device_type_info = {
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index da39282..b132d0a 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -5,24 +5,14 @@ 
 #include "monitor.h"
 #include "trace.h"
 
-static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
-
 static int usb_qdev_exit(DeviceState *qdev);
 
 #define TYPE_USB_BUS "usb-bus"
 
-static void usb_bus_class_init(ObjectClass *klass, void *data)
-{
-    BusClass *k = BUS_CLASS(klass);
-
-    k->print_dev = usb_bus_dev_print;
-}
-
 static TypeInfo usb_bus_info = {
     .name = TYPE_USB_BUS,
     .parent = TYPE_BUS,
     .instance_size = sizeof(USBBus),
-    .class_init = usb_bus_class_init,
 };
 
 static int next_usb_bus = 0;
@@ -448,18 +438,6 @@  static const char *usb_speed(unsigned int speed)
     return txt[speed];
 }
 
-static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
-{
-    USBDevice *dev = USB_DEVICE(qdev);
-    USBBus *bus = usb_bus_from_device(dev);
-
-    monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n",
-                   indent, "", bus->busnr, dev->addr,
-                   dev->port ? dev->port->path : "-",
-                   usb_speed(dev->speed), dev->product_desc,
-                   dev->attached ? ", attached" : "");
-}
-
 void usb_info(Monitor *mon)
 {
     USBBus *bus;
@@ -573,6 +551,18 @@  static char *usb_qdev_get_fw_dev_path(DeviceState *qdev)
     return fw_path;
 }
 
+static void usb_qdev_dev_print(DeviceState *qdev, Monitor *mon, int indent)
+{
+    USBDevice *dev = USB_DEVICE(qdev);
+    USBBus *bus = usb_bus_from_device(dev);
+
+    monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n",
+                   indent, "", bus->busnr, dev->addr,
+                   dev->port ? dev->port->path : "-",
+                   usb_speed(dev->speed), dev->product_desc,
+                   dev->attached ? ", attached" : "");
+}
+
 static void usb_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
@@ -583,6 +573,7 @@  static void usb_device_class_init(ObjectClass *klass, void *data)
     k->exit     = usb_qdev_exit;
     k->get_dev_path = usb_qdev_get_dev_path;
     k->get_fw_dev_path = usb_qdev_get_fw_dev_path;
+    k->print_dev = usb_qdev_dev_print;
 }
 
 static Property usb_bus_properties[] = {
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index ebb52f7..437f9fc 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -675,34 +675,14 @@  static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
-
 #define TYPE_VIRTIO_SERIAL_BUS "virtio-serial-bus"
 
-static void virtser_bus_class_init(ObjectClass *klass, void *data)
-{
-    BusClass *k = BUS_CLASS(klass);
-    k->print_dev = virtser_bus_dev_print;
-}
-
 static TypeInfo virtser_bus_info = {
     .name = TYPE_VIRTIO_SERIAL_BUS,
     .parent = TYPE_BUS,
     .instance_size = sizeof(VirtIOSerialBus),
-    .class_init = virtser_bus_class_init,
 };
 
-static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
-{
-    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
-
-    monitor_printf(mon, "%*sport %d, guest %s, host %s, throttle %s\n",
-                   indent, "", port->id,
-                   port->guest_connected ? "on" : "off",
-                   port->host_connected ? "on" : "off",
-                   port->throttled ? "on" : "off");
-}
-
 /* This function is only used if a port id is not provided by the user */
 static uint32_t find_free_port_id(VirtIOSerial *vser)
 {
@@ -935,6 +915,17 @@  void virtio_serial_exit(VirtIODevice *vdev)
     virtio_cleanup(vdev);
 }
 
+static void virtio_serial_port_dev_print(DeviceState *qdev, Monitor *mon, int indent)
+{
+    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
+
+    monitor_printf(mon, "%*sport %d, guest %s, host %s, throttle %s\n",
+                   indent, "", port->id,
+                   port->guest_connected ? "on" : "off",
+                   port->host_connected ? "on" : "off",
+                   port->throttled ? "on" : "off");
+}
+
 static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
@@ -942,6 +933,7 @@  static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
     k->bus_type = TYPE_VIRTIO_SERIAL_BUS;
     k->exit = virtser_port_qdev_exit;
     k->unplug = qdev_simple_unplug_cb;
+    k->print_dev = virtio_serial_port_dev_print;
 }
 
 static Property virtser_bus_properties[] = {