qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 10/20] qdev: convert all vga
Date: Mon, 29 Jun 2009 14:46:11 +0200	[thread overview]
Message-ID: <1246279581-15749-11-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1246279581-15749-1-git-send-email-kraxel@redhat.com>


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/cirrus_vga.c |   85 ++++++++++++++++++++++++++++++------------------------
 hw/vga.c        |   66 ++++++++++++++++++++++++++----------------
 hw/vmware_vga.c |   26 +++++++++++++----
 3 files changed, 108 insertions(+), 69 deletions(-)

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 0a12782..19d3fd9 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 134ad16..063fa5f 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2480,38 +2480,41 @@ static void pci_vga_write_config(PCIDevice *d,
         s->map_addr = 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);
+}
+
 int pci_vga_init(PCIBus *bus,
                  unsigned long vga_bios_offset, int vga_bios_size)
 {
+    PCIDevice *dev;
     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;
+    dev = pci_create_simple(bus, -1, "VGA");
+    d = DO_UPCAST(PCIVGAState, dev, dev);
     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) {
         unsigned int bios_total_size;
         s->bios_offset = vga_bios_offset;
@@ -2521,11 +2524,24 @@ int pci_vga_init(PCIBus *bus,
         while (bios_total_size < vga_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);
     }
     return 0;
 }
 
+static PCIDeviceInfo vga_info = {
+    .qdev.name    = "VGA",
+    .qdev.size    = sizeof(PCIVGAState),
+    .init         = pci_vga_initfn,
+    .config_write = pci_vga_write_config,
+};
+
+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

  parent reply	other threads:[~2009-06-29 12:46 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-29 12:46 [Qemu-devel] [PATCH 0/20] qdev patches Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 01/20] qdev: update pci device registration Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 02/20] qdev: replace bus_type enum with bus_info struct Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 03/20] qdev: remove DeviceType Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 04/20] qdev/core: bus list Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 05/20] qdev/core: add monitor command to list all drivers Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 06/20] qdev/pci: misc fixes Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 07/20] qdev/pci: hook up i440fx Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 08/20] qdev: convert piix-ide Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 09/20] qdev: convert piix acpi Gerd Hoffmann
2009-06-29 12:46 ` Gerd Hoffmann [this message]
2009-06-29 12:46 ` [Qemu-devel] [PATCH 11/20] qdev: convert es1370 Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 12/20] qdev: convert ac97 Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 13/20] qdev: convert uhci Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 14/20] qdev/usb: add usb bus support to qdev, convert drivers Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 15/20] qdev/usb: make qemu aware of usb busses Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 16/20] qdev/usb: print usb dev info Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 17/20] qdev: convert ohci Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 18/20] qdev/scsi: add scsi bus support to qdev, convert drivers Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 19/20] debug/test patch: add ohci controller to pc Gerd Hoffmann
2009-06-29 12:46 ` [Qemu-devel] [PATCH 20/20] debug/test patch: allow specify busnr for -usbdevice Gerd Hoffmann
2009-06-30  0:56 ` [Qemu-devel] [PATCH 0/20] qdev patches Anthony Liguori
2009-06-30  9:26   ` 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=1246279581-15749-11-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).