Patchwork [v3,034/197] qdev: add isa-device as a subclass of device

login
register
mail settings
Submitter Anthony Liguori
Date Dec. 12, 2011, 8:18 p.m.
Message ID <1323721273-32404-35-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/130824/
State New
Headers show

Comments

Anthony Liguori - Dec. 12, 2011, 8:18 p.m.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/isa-bus.c |   11 ++++++++++-
 hw/isa.h     |   12 ++++++++++++
 hw/pci.c     |    2 +-
 hw/qdev.c    |    9 +++++++--
 hw/qdev.h    |    1 +
 5 files changed, 31 insertions(+), 4 deletions(-)

Patch

diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 7c2c261..0beb1bf 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -126,7 +126,7 @@  void isa_qdev_register(ISADeviceInfo *info)
 {
     info->qdev.init = isa_qdev_init;
     info->qdev.bus_info = &isa_bus_info;
-    qdev_register(&info->qdev);
+    qdev_register_subclass(&info->qdev, TYPE_ISA_DEVICE);
 }
 
 ISADevice *isa_create(const char *name)
@@ -189,9 +189,18 @@  static SysBusDeviceInfo isabus_bridge_info = {
     .qdev.no_user = 1,
 };
 
+static TypeInfo isa_device_type_info = {
+    .name = TYPE_ISA_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(ISADevice),
+    .abstract = true,
+    .class_size = sizeof(ISADeviceClass),
+};
+
 static void isabus_register_devices(void)
 {
     sysbus_register_withprop(&isabus_bridge_info);
+    type_register_static(&isa_device_type_info);
 }
 
 static char *isabus_get_fw_dev_path(DeviceState *dev)
diff --git a/hw/isa.h b/hw/isa.h
index 5eb9c78..af7e3dc 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -13,6 +13,18 @@  typedef struct ISABus ISABus;
 typedef struct ISADevice ISADevice;
 typedef struct ISADeviceInfo ISADeviceInfo;
 
+#define TYPE_ISA_DEVICE "isa-device"
+#define ISA_DEVICE(obj) \
+     OBJECT_CHECK(ISADeviceState, (obj), ISA_TYPE_DEVICE)
+#define ISA_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(ISADeviceClass, (klass), ISA_TYPE_DEVICE)
+#define ISA_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(ISADeviceClass, (obj), ISA_TYPE_DEVICE)
+
+typedef struct ISADeviceClass {
+    DeviceClass parent_class;
+} ISADeviceClass;
+
 struct ISADevice {
     DeviceState qdev;
     uint32_t isairq[2];
diff --git a/hw/pci.c b/hw/pci.c
index 16d676d..9992ea2 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -161,7 +161,7 @@  void pci_device_reset(PCIDevice *dev)
     int r;
     /* TODO: call the below unconditionally once all pci devices
      * are qdevified */
-    if (OBJECT(dev)->type != 0) {
+    if (OBJECT(dev)->class != NULL) {
         qdev_reset_all(DEVICE(dev));
     }
 
diff --git a/hw/qdev.c b/hw/qdev.c
index fed9848..e0c4a40 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -61,7 +61,7 @@  DeviceInfo *qdev_get_info(DeviceState *dev)
     return DEVICE_GET_CLASS(dev)->info;
 }
 
-void qdev_register(DeviceInfo *info)
+void qdev_register_subclass(DeviceInfo *info, const char *parent)
 {
     TypeInfo type_info = {};
 
@@ -69,7 +69,7 @@  void qdev_register(DeviceInfo *info)
     assert(!info->next);
 
     type_info.name = info->name;
-    type_info.parent = TYPE_DEVICE;
+    type_info.parent = parent;
     type_info.instance_size = info->size;
     type_info.class_init = qdev_subclass_init;
     type_info.class_data = info;
@@ -80,6 +80,11 @@  void qdev_register(DeviceInfo *info)
     device_info_list = info;
 }
 
+void qdev_register(DeviceInfo *info)
+{
+    qdev_register_subclass(info, TYPE_DEVICE);
+}
+
 static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
 {
     DeviceInfo *info;
diff --git a/hw/qdev.h b/hw/qdev.h
index cd2eaf2..aab8f42 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -235,6 +235,7 @@  struct DeviceInfo {
 extern DeviceInfo *device_info_list;
 
 void qdev_register(DeviceInfo *info);
+void qdev_register_subclass(DeviceInfo *info, const char *parent);
 
 /* Register device properties.  */
 /* GPIO inputs also double as IRQ sinks.  */