From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MLGG3-0006UC-4i for qemu-devel@nongnu.org; Mon, 29 Jun 2009 08:46:51 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MLGFv-0006PF-Vw for qemu-devel@nongnu.org; Mon, 29 Jun 2009 08:46:48 -0400 Received: from [199.232.76.173] (port=41126 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MLGFu-0006Ok-Tk for qemu-devel@nongnu.org; Mon, 29 Jun 2009 08:46:43 -0400 Received: from mx2.redhat.com ([66.187.237.31]:36460) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MLGFt-0003s4-PG for qemu-devel@nongnu.org; Mon, 29 Jun 2009 08:46:42 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5TCkfau007118 for ; Mon, 29 Jun 2009 08:46:41 -0400 From: Gerd Hoffmann Date: Mon, 29 Jun 2009 14:46:11 +0200 Message-Id: <1246279581-15749-11-git-send-email-kraxel@redhat.com> In-Reply-To: <1246279581-15749-1-git-send-email-kraxel@redhat.com> References: <1246279581-15749-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 10/20] qdev: convert all vga List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Signed-off-by: Gerd Hoffmann --- 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