qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: <arei.gonglei@huawei.com>
To: qemu-devel@nongnu.org
Cc: Gonglei <arei.gonglei@huawei.com>,
	peter.huangpeng@huawei.com, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 1/3] vga-pci: QOMify
Date: Tue, 12 May 2015 17:27:08 +0800	[thread overview]
Message-ID: <1431422830-10320-2-git-send-email-arei.gonglei@huawei.com> (raw)
In-Reply-To: <1431422830-10320-1-git-send-email-arei.gonglei@huawei.com>

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/display/vga-pci.c | 48 ++++++++++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/hw/display/vga-pci.c b/hw/display/vga-pci.c
index aabfc23..ff5dfb2 100644
--- a/hw/display/vga-pci.c
+++ b/hw/display/vga-pci.c
@@ -59,6 +59,9 @@ typedef struct PCIVGAState {
     MemoryRegion qext;
 } PCIVGAState;
 
+#define TYPE_PCI_VGA "pci-vga"
+#define PCI_VGA(obj) OBJECT_CHECK(PCIVGAState, (obj), TYPE_PCI_VGA)
+
 static const VMStateDescription vmstate_vga_pci = {
     .name = "vga",
     .version_id = 2,
@@ -183,14 +186,14 @@ static void pci_vga_qext_write(void *ptr, hwaddr addr,
 
 static bool vga_get_big_endian_fb(Object *obj, Error **errp)
 {
-    PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, PCI_DEVICE(obj));
+    PCIVGAState *d = PCI_VGA(PCI_DEVICE(obj));
 
     return d->vga.big_endian_fb;
 }
 
 static void vga_set_big_endian_fb(Object *obj, bool value, Error **errp)
 {
-    PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, PCI_DEVICE(obj));
+    PCIVGAState *d = PCI_VGA(PCI_DEVICE(obj));
 
     d->vga.big_endian_fb = value;
 }
@@ -205,7 +208,7 @@ static const MemoryRegionOps pci_vga_qext_ops = {
 
 static void pci_std_vga_realize(PCIDevice *dev, Error **errp)
 {
-    PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
+    PCIVGAState *d = PCI_VGA(dev);
     VGACommonState *s = &d->vga;
 
     /* vga + console init */
@@ -257,7 +260,7 @@ static void pci_std_vga_init(Object *obj)
 
 static void pci_secondary_vga_realize(PCIDevice *dev, Error **errp)
 {
-    PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
+    PCIVGAState *d = PCI_VGA(dev);
     VGACommonState *s = &d->vga;
 
     /* vga + console init */
@@ -297,8 +300,7 @@ static void pci_secondary_vga_init(Object *obj)
 
 static void pci_secondary_vga_reset(DeviceState *dev)
 {
-    PCIVGAState *d = DO_UPCAST(PCIVGAState, dev.qdev, dev);
-
+    PCIVGAState *d = PCI_VGA(PCI_DEVICE(dev));
     vga_common_reset(&d->vga);
 }
 
@@ -317,6 +319,25 @@ static Property secondary_pci_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
+static void vga_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->vendor_id = PCI_VENDOR_ID_QEMU;
+    k->device_id = PCI_DEVICE_ID_QEMU_VGA;
+    dc->vmsd = &vmstate_vga_pci;
+    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
+}
+
+static const TypeInfo vga_pci_type_info = {
+    .name = TYPE_PCI_VGA,
+    .parent = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(PCIVGAState),
+    .abstract = true,
+    .class_init = vga_pci_class_init,
+};
+
 static void vga_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -324,13 +345,9 @@ static void vga_class_init(ObjectClass *klass, void *data)
 
     k->realize = pci_std_vga_realize;
     k->romfile = "vgabios-stdvga.bin";
-    k->vendor_id = PCI_VENDOR_ID_QEMU;
-    k->device_id = PCI_DEVICE_ID_QEMU_VGA;
     k->class_id = PCI_CLASS_DISPLAY_VGA;
-    dc->vmsd = &vmstate_vga_pci;
     dc->props = vga_pci_properties;
     dc->hotpluggable = false;
-    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
 }
 
 static void secondary_class_init(ObjectClass *klass, void *data)
@@ -339,33 +356,28 @@ static void secondary_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->realize = pci_secondary_vga_realize;
-    k->vendor_id = PCI_VENDOR_ID_QEMU;
-    k->device_id = PCI_DEVICE_ID_QEMU_VGA;
     k->class_id = PCI_CLASS_DISPLAY_OTHER;
-    dc->vmsd = &vmstate_vga_pci;
     dc->props = secondary_pci_properties;
     dc->reset = pci_secondary_vga_reset;
-    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
 }
 
 static const TypeInfo vga_info = {
     .name          = "VGA",
-    .parent        = TYPE_PCI_DEVICE,
+    .parent        = TYPE_PCI_VGA,
     .instance_init = pci_std_vga_init,
-    .instance_size = sizeof(PCIVGAState),
     .class_init    = vga_class_init,
 };
 
 static const TypeInfo secondary_info = {
     .name          = "secondary-vga",
-    .parent        = TYPE_PCI_DEVICE,
+    .parent        = TYPE_PCI_VGA,
     .instance_init = pci_secondary_vga_init,
-    .instance_size = sizeof(PCIVGAState),
     .class_init    = secondary_class_init,
 };
 
 static void vga_register_types(void)
 {
+    type_register_static(&vga_pci_type_info);
     type_register_static(&vga_info);
     type_register_static(&secondary_info);
 }
-- 
1.7.12.4

  reply	other threads:[~2015-05-12  9:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-12  9:27 [Qemu-devel] [PATCH 0/3] hw/display: QOMify arei.gonglei
2015-05-12  9:27 ` arei.gonglei [this message]
2015-05-12  9:27 ` [Qemu-devel] [PATCH 2/3] cirrus_vga: QOMify arei.gonglei
2015-05-12  9:27 ` [Qemu-devel] [PATCH 3/3] qxl: QOMify arei.gonglei
2015-05-19  7:48 ` [Qemu-devel] [PATCH 0/3] hw/display: QOMify Gonglei
2015-05-19 10:45   ` Gerd Hoffmann
2015-05-19 11:11     ` Gonglei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431422830-10320-2-git-send-email-arei.gonglei@huawei.com \
    --to=arei.gonglei@huawei.com \
    --cc=kraxel@redhat.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).