Patchwork [24/34] vmware_vga: convert to pci_bar_map

login
register
mail settings
Submitter Blue Swirl
Date July 22, 2010, 10 p.m.
Message ID <AANLkTilUJfTjjistoAFkLq01UWX4vobDa_MQDX9C-Htf@mail.gmail.com>
Download mbox | patch
Permalink /patch/59682/
State New
Headers show

Comments

Blue Swirl - July 22, 2010, 10 p.m.
Use pci_bar_map() and post_map_func instead of a mapping function.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 hw/vmware_vga.c |   93 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 57 insertions(+), 36 deletions(-)

     s->vga.map_end = addr + s->vga.vram_size;
@@ -1225,18 +1232,15 @@ static void pci_vmsvga_map_fifo(PCIDevice
*pci_dev, int region_num,
 {
     struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev;
     struct vmsvga_state_s *s = &d->chip;
-    ram_addr_t iomemtype;

     s->fifo_base = addr;
-    iomemtype = s->fifo_offset | IO_MEM_RAM;
-    cpu_register_physical_memory(s->fifo_base, s->fifo_size,
-                    iomemtype);
 }

 static int pci_vmsvga_initfn(PCIDevice *dev)
 {
     struct pci_vmsvga_state_s *s =
         DO_UPCAST(struct pci_vmsvga_state_s, card, dev);
+    ram_addr_t iomemtype;

     pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE);
     pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID);
@@ -1249,16 +1253,33 @@ static int pci_vmsvga_initfn(PCIDevice *dev)
     s->card.config[PCI_SUBSYSTEM_ID + 1] = SVGA_PCI_DEVICE_ID >> 8;
     s->card.config[PCI_INTERRUPT_LINE] = 0xff;		/* End */

-    pci_register_bar(&s->card, 0, 0x10,
-                     PCI_BASE_ADDRESS_SPACE_IO, pci_vmsvga_map_ioport, NULL);
+    pci_register_bar(&s->card, 0, 0x10, PCI_BASE_ADDRESS_SPACE_IO, NULL, NULL);
+    iomemtype = cpu_register_io(vmsvga_index_io_reads, vmsvga_index_io_writes,
+                                4, &s->card);
+    pci_bar_map(&s->card, 0, 0, SVGA_IO_MUL * SVGA_INDEX_PORT, 4, iomemtype);
+    iomemtype = cpu_register_io(vmsvga_value_io_reads, vmsvga_value_io_writes,
+                                4, &s->card);
+    pci_bar_map(&s->card, 0, 0, SVGA_IO_MUL * SVGA_VALUE_PORT, 4, iomemtype);
+    iomemtype = cpu_register_io(vmsvga_bios_io_reads, vmsvga_bios_io_writes,
+                                4, &s->card);
+    pci_bar_map(&s->card, 0, 0, SVGA_IO_MUL * SVGA_BIOS_PORT, 4, iomemtype);
     pci_register_bar(&s->card, 1, VGA_RAM_SIZE,
-                     PCI_BASE_ADDRESS_MEM_PREFETCH, pci_vmsvga_map_mem, NULL);
-
+                     PCI_BASE_ADDRESS_MEM_PREFETCH, NULL, pci_vmsvga_map_mem);
     pci_register_bar(&s->card, 2, SVGA_FIFO_SIZE,
-                     PCI_BASE_ADDRESS_MEM_PREFETCH, pci_vmsvga_map_fifo, NULL);
+                     PCI_BASE_ADDRESS_MEM_PREFETCH, NULL, pci_vmsvga_map_fifo);

     vmsvga_init(&s->chip, VGA_RAM_SIZE);

+#ifdef DIRECT_VRAM
+    iomemtype = cpu_register_io_memory(vmsvga_vram_read,
+                                       vmsvga_vram_write, s);
+#else
+    iomemtype = s->chip.vga.vram_offset | IO_MEM_RAM;
+#endif
+    pci_bar_map(&s->card, 1, 0, 0, s->chip.vga.vram_size, iomemtype);
+    iomemtype = s->chip.fifo_offset | IO_MEM_RAM;
+    pci_bar_map(&s->card, 2, 0, 0, s->chip.fifo_size, iomemtype);
+
     return 0;
 }

Patch

diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index 00fa8fd..1e2d174 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -1178,42 +1178,49 @@  static void vmsvga_init(struct vmsvga_state_s
*s, int vga_ram_size)
     vmsvga_reset(s);
 }

-static void pci_vmsvga_map_ioport(PCIDevice *pci_dev, int region_num,
-                pcibus_t addr, pcibus_t size, int type)
-{
-    struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev;
-    struct vmsvga_state_s *s = &d->chip;
+static IOPortWriteFunc * const vmsvga_index_io_writes[] = {
+    NULL,
+    NULL,
+    vmsvga_index_write,
+};

-    register_ioport_read(addr + SVGA_IO_MUL * SVGA_INDEX_PORT,
-                    1, 4, vmsvga_index_read, s);
-    register_ioport_write(addr + SVGA_IO_MUL * SVGA_INDEX_PORT,
-                    1, 4, vmsvga_index_write, s);
-    register_ioport_read(addr + SVGA_IO_MUL * SVGA_VALUE_PORT,
-                    1, 4, vmsvga_value_read, s);
-    register_ioport_write(addr + SVGA_IO_MUL * SVGA_VALUE_PORT,
-                    1, 4, vmsvga_value_write, s);
-    register_ioport_read(addr + SVGA_IO_MUL * SVGA_BIOS_PORT,
-                    1, 4, vmsvga_bios_read, s);
-    register_ioport_write(addr + SVGA_IO_MUL * SVGA_BIOS_PORT,
-                    1, 4, vmsvga_bios_write, s);
-}
+static IOPortReadFunc * const vmsvga_index_io_reads[] = {
+    NULL,
+    NULL,
+    vmsvga_index_read,
+};
+
+static IOPortWriteFunc * const vmsvga_value_io_writes[] = {
+    NULL,
+    NULL,
+    vmsvga_value_write,
+};
+
+static IOPortReadFunc * const vmsvga_value_io_reads[] = {
+    NULL,
+    NULL,
+    vmsvga_value_read,
+};
+
+static IOPortWriteFunc * const vmsvga_bios_io_writes[] = {
+    NULL,
+    NULL,
+    vmsvga_bios_write,
+};
+
+static IOPortReadFunc * const vmsvga_bios_io_reads[] = {
+    NULL,
+    NULL,
+    vmsvga_bios_read,
+};

 static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num,
                 pcibus_t addr, pcibus_t size, int type)
 {
     struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev;
     struct vmsvga_state_s *s = &d->chip;
-    ram_addr_t iomemtype;

     s->vram_base = addr;
-#ifdef DIRECT_VRAM
-    iomemtype = cpu_register_io_memory(vmsvga_vram_read,
-                    vmsvga_vram_write, s);
-#else
-    iomemtype = s->vga.vram_offset | IO_MEM_RAM;
-#endif
-    cpu_register_physical_memory(s->vram_base, s->vga.vram_size,
-                    iomemtype);

     s->vga.map_addr = addr;