From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 08/13] qdev: convert all vga
Date: Fri, 10 Jul 2009 13:26:14 +0200 [thread overview]
Message-ID: <1247225179-5495-9-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1247225179-5495-1-git-send-email-kraxel@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/cirrus_vga.c | 85 ++++++++++++++++++++++++++---------------------
hw/vga.c | 98 ++++++++++++++++++++++++++++++++++--------------------
hw/vmware_vga.c | 26 +++++++++++---
3 files changed, 129 insertions(+), 80 deletions(-)
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 902b3ee..1d800e9 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -3301,46 +3301,55 @@ static void pci_cirrus_write_config(PCIDevice *d,
cirrus_update_memory_access(s);
}
+static void pci_cirrus_vga_initfn(PCIDevice *dev)
+{
+ PCICirrusVGAState *d = DO_UPCAST(PCICirrusVGAState, dev, dev);
+ CirrusVGAState *s = &d->cirrus_vga;
+ uint8_t *pci_conf = d->dev.config;
+ int device_id = CIRRUS_ID_CLGD5446;
+
+ /* setup VGA */
+ vga_common_init(&s->vga, VGA_RAM_SIZE);
+ cirrus_init_common(s, device_id, 1);
+ s->vga.pci_dev = (PCIDevice *)d;
+ s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
+ s->vga.screen_dump, s->vga.text_update,
+ &s->vga);
+
+ /* setup PCI */
+ pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_CIRRUS);
+ pci_config_set_device_id(pci_conf, device_id);
+ pci_conf[0x04] = PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS;
+ pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
+ pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL;
+
+ /* setup memory space */
+ /* memory #0 LFB */
+ /* memory #1 memory-mapped I/O */
+ /* XXX: s->vga.vram_size must be a power of two */
+ pci_register_bar((PCIDevice *)d, 0, 0x2000000,
+ PCI_ADDRESS_SPACE_MEM_PREFETCH, cirrus_pci_lfb_map);
+ if (device_id == CIRRUS_ID_CLGD5446) {
+ pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
+ PCI_ADDRESS_SPACE_MEM, cirrus_pci_mmio_map);
+ }
+ /* XXX: ROM BIOS */
+}
+
void pci_cirrus_vga_init(PCIBus *bus)
{
- PCICirrusVGAState *d;
- uint8_t *pci_conf;
- CirrusVGAState *s;
- int device_id;
-
- device_id = CIRRUS_ID_CLGD5446;
-
- /* setup PCI configuration registers */
- d = (PCICirrusVGAState *)pci_register_device(bus, "Cirrus VGA",
- sizeof(PCICirrusVGAState),
- -1, NULL, pci_cirrus_write_config);
- pci_conf = d->dev.config;
- pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_CIRRUS);
- pci_config_set_device_id(pci_conf, device_id);
- pci_conf[0x04] = PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS;
- pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
- pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL;
-
- /* setup VGA */
- s = &d->cirrus_vga;
- vga_common_init(&s->vga, VGA_RAM_SIZE);
- cirrus_init_common(s, device_id, 1);
-
- s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
- s->vga.screen_dump, s->vga.text_update,
- &s->vga);
+ pci_create_simple(bus, -1, "Cirrus VGA");
+}
- s->vga.pci_dev = (PCIDevice *)d;
+static PCIDeviceInfo cirrus_vga_info = {
+ .qdev.name = "Cirrus VGA",
+ .qdev.size = sizeof(PCICirrusVGAState),
+ .init = pci_cirrus_vga_initfn,
+ .config_write = pci_cirrus_write_config,
+};
- /* setup memory space */
- /* memory #0 LFB */
- /* memory #1 memory-mapped I/O */
- /* XXX: s->vga.vram_size must be a power of two */
- pci_register_bar((PCIDevice *)d, 0, 0x2000000,
- PCI_ADDRESS_SPACE_MEM_PREFETCH, cirrus_pci_lfb_map);
- if (device_id == CIRRUS_ID_CLGD5446) {
- pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
- PCI_ADDRESS_SPACE_MEM, cirrus_pci_mmio_map);
- }
- /* XXX: ROM BIOS */
+static void cirrus_vga_register(void)
+{
+ pci_qdev_register(&cirrus_vga_info);
}
+device_init(cirrus_vga_register);
diff --git a/hw/vga.c b/hw/vga.c
index 403f6ff..e1a470d 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2480,52 +2480,78 @@ static void pci_vga_write_config(PCIDevice *d,
s->map_addr = 0;
}
-int pci_vga_init(PCIBus *bus,
- unsigned long vga_bios_offset, int vga_bios_size)
-{
- PCIVGAState *d;
- VGAState *s;
- uint8_t *pci_conf;
-
- d = (PCIVGAState *)pci_register_device(bus, "VGA",
- sizeof(PCIVGAState),
- -1, NULL, pci_vga_write_config);
- if (!d)
- return -1;
- s = &d->vga_state;
-
- vga_common_init(s, VGA_RAM_SIZE);
- vga_init(s);
-
- s->ds = graphic_console_init(s->update, s->invalidate,
- s->screen_dump, s->text_update, s);
-
- s->pci_dev = &d->dev;
-
- pci_conf = d->dev.config;
- // dummy VGA (same as Bochs ID)
- pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU);
- pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA);
- pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
- pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
-
- /* XXX: VGA_RAM_SIZE must be a power of two */
- pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
- PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
- if (vga_bios_size != 0) {
+static void pci_vga_initfn(PCIDevice *dev)
+{
+ PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
+ VGAState *s = &d->vga_state;
+ uint8_t *pci_conf = d->dev.config;
+
+ // vga + console init
+ vga_common_init(s, VGA_RAM_SIZE);
+ vga_init(s);
+ s->pci_dev = &d->dev;
+ s->ds = graphic_console_init(s->update, s->invalidate,
+ s->screen_dump, s->text_update, s);
+
+ // dummy VGA (same as Bochs ID)
+ pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU);
+ pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA);
+ pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
+ pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
+
+ /* XXX: VGA_RAM_SIZE must be a power of two */
+ pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
+ PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
+
+ if (s->bios_size) {
unsigned int bios_total_size;
- s->bios_offset = vga_bios_offset;
- s->bios_size = vga_bios_size;
/* must be a power of two */
bios_total_size = 1;
- while (bios_total_size < vga_bios_size)
+ while (bios_total_size < s->bios_size)
bios_total_size <<= 1;
pci_register_bar(&d->dev, PCI_ROM_SLOT, bios_total_size,
- PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
+ PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
}
+}
+
+int pci_vga_init(PCIBus *bus,
+ unsigned long vga_bios_offset, int vga_bios_size)
+{
+ DeviceState *qdev;
+
+ qdev = pci_create("VGA", NULL);
+ qdev_prop_set_uint32(qdev, "bios-offset", vga_bios_offset);
+ qdev_prop_set_uint32(qdev, "bios-size", vga_bios_offset);
+ qdev_init(qdev);
+
return 0;
}
+static PCIDeviceInfo vga_info = {
+ .qdev.name = "VGA",
+ .qdev.size = sizeof(PCIVGAState),
+ .init = pci_vga_initfn,
+ .config_write = pci_vga_write_config,
+ .qdev.props = (Property[]) {
+ {
+ .name = "bios-offset",
+ .info = &qdev_prop_hex32,
+ .offset = offsetof(PCIVGAState, vga_state.bios_offset),
+ },{
+ .name = "bios-size",
+ .info = &qdev_prop_hex32,
+ .offset = offsetof(PCIVGAState, vga_state.bios_size),
+ },
+ {/* end of list */}
+ }
+};
+
+static void vga_register(void)
+{
+ pci_qdev_register(&vga_info);
+}
+device_init(vga_register);
+
/********************************************************/
/* vga screen dump */
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index accdac4..5ceebf1 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -1210,14 +1210,11 @@ static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num,
iomemtype);
}
-void pci_vmsvga_init(PCIBus *bus)
+static void pci_vmsvga_initfn(PCIDevice *dev)
{
- struct pci_vmsvga_state_s *s;
+ struct pci_vmsvga_state_s *s =
+ DO_UPCAST(struct pci_vmsvga_state_s, card, dev);
- /* Setup PCI configuration */
- s = (struct pci_vmsvga_state_s *)
- pci_register_device(bus, "QEMUware SVGA",
- sizeof(struct pci_vmsvga_state_s), -1, NULL, NULL);
pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE);
pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID);
s->card.config[PCI_COMMAND] = 0x07; /* I/O + Memory */
@@ -1240,3 +1237,20 @@ void pci_vmsvga_init(PCIBus *bus)
register_savevm("vmware_vga", 0, 0, pci_vmsvga_save, pci_vmsvga_load, s);
}
+
+void pci_vmsvga_init(PCIBus *bus)
+{
+ pci_create_simple(bus, -1, "QEMUware SVGA");
+}
+
+static PCIDeviceInfo vmsvga_info = {
+ .qdev.name = "QEMUware SVGA",
+ .qdev.size = sizeof(struct pci_vmsvga_state_s),
+ .init = pci_vmsvga_initfn,
+};
+
+static void vmsvga_register(void)
+{
+ pci_qdev_register(&vmsvga_info);
+}
+device_init(vmsvga_register);
--
1.6.2.5
next prev parent reply other threads:[~2009-07-10 11:26 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-10 11:26 [Qemu-devel] [PATCH v2 0/13] qdev patches: properties, -device switch, id=<tag> & more Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 01/13] qdev: rework device properties Gerd Hoffmann
2009-07-10 17:13 ` Paul Brook
2009-07-10 19:28 ` Gerd Hoffmann
2009-07-10 19:42 ` Paul Brook
2009-07-10 20:10 ` Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 02/13] qdev: factor out driver search to qdev_find_info() Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 03/13] qdev/pci: make pci_create return DeviceState instead of PCIDevice Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 04/13] qdev: add generic qdev_device_add() Gerd Hoffmann
2009-07-10 17:23 ` Paul Brook
2009-07-10 20:27 ` Gerd Hoffmann
2009-07-10 20:51 ` Paul Brook
2009-07-14 7:40 ` Gerd Hoffmann
2009-07-14 23:43 ` Markus Armbruster
2009-07-15 1:28 ` Markus Armbruster
2009-07-15 6:26 ` Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 05/13] qdev: add -device command line option Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 06/13] qdev: add no_user, alias and desc Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 07/13] qdev: es1370 description Gerd Hoffmann
2009-07-10 11:26 ` Gerd Hoffmann [this message]
2009-07-10 11:26 ` [Qemu-devel] [PATCH 09/13] qdev/pci: hook up i440fx Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 10/13] qdev: add user-specified identifier to devices Gerd Hoffmann
2009-07-10 17:31 ` Paul Brook
2009-07-10 19:03 ` Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 11/13] switch balloon initialization to -device Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 12/13] qdev: add id= support for pci nics Gerd Hoffmann
2009-07-10 11:26 ` [Qemu-devel] [PATCH 13/13] qdev: print device id in "info pci" Gerd Hoffmann
-- strict thread matches above, loose matches on Subject: below --
2009-07-03 10:22 [Qemu-devel] [PATCH 0/13] qdev patches: properties, -device switch, id=<tag> & more Gerd Hoffmann
2009-07-03 10:22 ` [Qemu-devel] [PATCH 08/13] qdev: convert all vga Gerd Hoffmann
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=1247225179-5495-9-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.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).