From d338bae33a76d02678ea706622dfcc26b8b8325c Mon Sep 17 00:00:00 2001 From: Gonglei Date: Tue, 12 May 2015 17:27:09 +0800 Subject: cirrus_vga: QOMify QOMify pci-cirrus-vga like isa-cirrus-vga device. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/display/cirrus_vga.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index 8765a7e1d0..5198037d82 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -235,6 +235,10 @@ typedef struct PCICirrusVGAState { CirrusVGAState cirrus_vga; } PCICirrusVGAState; +#define TYPE_PCI_CIRRUS_VGA "cirrus-vga" +#define PCI_CIRRUS_VGA(obj) \ + OBJECT_CHECK(PCICirrusVGAState, (obj), TYPE_PCI_CIRRUS_VGA) + #define TYPE_ISA_CIRRUS_VGA "isa-cirrus-vga" #define ISA_CIRRUS_VGA(obj) \ OBJECT_CHECK(ISACirrusVGAState, (obj), TYPE_ISA_CIRRUS_VGA) @@ -3008,7 +3012,7 @@ static const TypeInfo isa_cirrus_vga_info = { static void pci_cirrus_vga_realize(PCIDevice *dev, Error **errp) { - PCICirrusVGAState *d = DO_UPCAST(PCICirrusVGAState, dev, dev); + PCICirrusVGAState *d = PCI_CIRRUS_VGA(dev); CirrusVGAState *s = &d->cirrus_vga; PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); int16_t device_id = pc->device_id; @@ -3070,7 +3074,7 @@ static void cirrus_vga_class_init(ObjectClass *klass, void *data) } static const TypeInfo cirrus_vga_info = { - .name = "cirrus-vga", + .name = TYPE_PCI_CIRRUS_VGA, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCICirrusVGAState), .class_init = cirrus_vga_class_init, -- cgit v1.2.3 From c69f6c7dcf6164ee0ee3b00bec27dfdec4e8b661 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Tue, 12 May 2015 17:27:10 +0800 Subject: qxl: QOMify Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- hw/display/qxl.c | 44 ++++++++++++++++++++++++++------------------ hw/display/qxl.h | 3 +++ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 0cd314c931..8f40dfb8ac 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -1181,7 +1181,7 @@ static void qxl_hard_reset(PCIQXLDevice *d, int loadvm) static void qxl_reset_handler(DeviceState *dev) { - PCIQXLDevice *d = DO_UPCAST(PCIQXLDevice, pci.qdev, dev); + PCIQXLDevice *d = PCI_QXL(PCI_DEVICE(dev)); qxl_hard_reset(d, 0); } @@ -2026,7 +2026,7 @@ static void qxl_realize_common(PCIQXLDevice *qxl, Error **errp) static void qxl_realize_primary(PCIDevice *dev, Error **errp) { - PCIQXLDevice *qxl = DO_UPCAST(PCIQXLDevice, pci, dev); + PCIQXLDevice *qxl = PCI_QXL(dev); VGACommonState *vga = &qxl->vga; Error *local_err = NULL; @@ -2059,7 +2059,7 @@ static void qxl_realize_primary(PCIDevice *dev, Error **errp) static void qxl_realize_secondary(PCIDevice *dev, Error **errp) { static int device_id = 1; - PCIQXLDevice *qxl = DO_UPCAST(PCIQXLDevice, pci, dev); + PCIQXLDevice *qxl = PCI_QXL(dev); qxl->id = device_id++; qxl_init_ramsize(qxl); @@ -2277,28 +2277,42 @@ static Property qxl_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void qxl_primary_class_init(ObjectClass *klass, void *data) +static void qxl_pci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - k->realize = qxl_realize_primary; - k->romfile = "vgabios-qxl.bin"; k->vendor_id = REDHAT_PCI_VENDOR_ID; k->device_id = QXL_DEVICE_ID_STABLE; - k->class_id = PCI_CLASS_DISPLAY_VGA; set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); - dc->desc = "Spice QXL GPU (primary, vga compatible)"; dc->reset = qxl_reset_handler; dc->vmsd = &qxl_vmstate; dc->props = qxl_properties; +} + +static const TypeInfo qxl_pci_type_info = { + .name = TYPE_PCI_QXL, + .parent = TYPE_PCI_DEVICE, + .instance_size = sizeof(PCIQXLDevice), + .abstract = true, + .class_init = qxl_pci_class_init, +}; + +static void qxl_primary_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + + k->realize = qxl_realize_primary; + k->romfile = "vgabios-qxl.bin"; + k->class_id = PCI_CLASS_DISPLAY_VGA; + dc->desc = "Spice QXL GPU (primary, vga compatible)"; dc->hotpluggable = false; } static const TypeInfo qxl_primary_info = { .name = "qxl-vga", - .parent = TYPE_PCI_DEVICE, - .instance_size = sizeof(PCIQXLDevice), + .parent = TYPE_PCI_QXL, .class_init = qxl_primary_class_init, }; @@ -2308,25 +2322,19 @@ static void qxl_secondary_class_init(ObjectClass *klass, void *data) PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->realize = qxl_realize_secondary; - k->vendor_id = REDHAT_PCI_VENDOR_ID; - k->device_id = QXL_DEVICE_ID_STABLE; k->class_id = PCI_CLASS_DISPLAY_OTHER; - set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); dc->desc = "Spice QXL GPU (secondary)"; - dc->reset = qxl_reset_handler; - dc->vmsd = &qxl_vmstate; - dc->props = qxl_properties; } static const TypeInfo qxl_secondary_info = { .name = "qxl", - .parent = TYPE_PCI_DEVICE, - .instance_size = sizeof(PCIQXLDevice), + .parent = TYPE_PCI_QXL, .class_init = qxl_secondary_class_init, }; static void qxl_register_types(void) { + type_register_static(&qxl_pci_type_info); type_register_static(&qxl_primary_info); type_register_static(&qxl_secondary_info); } diff --git a/hw/display/qxl.h b/hw/display/qxl.h index 412e346b68..deddd54d2f 100644 --- a/hw/display/qxl.h +++ b/hw/display/qxl.h @@ -122,6 +122,9 @@ typedef struct PCIQXLDevice { QEMUBH *update_area_bh; } PCIQXLDevice; +#define TYPE_PCI_QXL "pci-qxl" +#define PCI_QXL(obj) OBJECT_CHECK(PCIQXLDevice, (obj), TYPE_PCI_QXL) + #define PANIC_ON(x) if ((x)) { \ printf("%s: PANIC %s failed\n", __FUNCTION__, #x); \ abort(); \ -- cgit v1.2.3 From 176c324febd76d6f164347583f5af35b3cb4e5fb Mon Sep 17 00:00:00 2001 From: Gonglei Date: Tue, 12 May 2015 17:27:08 +0800 Subject: vga-pci: QOMify Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- 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 aabfc23cd9..ff5dfb2c23 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); } -- cgit v1.2.3