Patchwork [17/22] cirrus_vga: Remove unneeded double indirection of PCICirrusVGAState

login
register
mail settings
Submitter Juan Quintela
Date Aug. 24, 2009, 11:03 a.m.
Message ID <89292a7d1d3118e3eee0b65b4a3e6ceda13ce61e.1251111439.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/31918/
State Superseded
Headers show

Comments

Juan Quintela - Aug. 24, 2009, 11:03 a.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/cirrus_vga.c |   30 ++++++++++++------------------
 1 files changed, 12 insertions(+), 18 deletions(-)

Patch

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 95d822a..6f0fb91 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -238,6 +238,7 @@  typedef void (*cirrus_fill_t)(struct CirrusVGAState *s,
                               uint8_t *dst, int dst_pitch, int width, int height);

 typedef struct CirrusVGAState {
+    PCIDevice dev;
     VGACommonState vga;

     int cirrus_linear_io_addr;
@@ -282,11 +283,6 @@  typedef struct CirrusVGAState {
     int bustype;
 } CirrusVGAState;

-typedef struct PCICirrusVGAState {
-    PCIDevice dev;
-    CirrusVGAState cirrus_vga;
-} PCICirrusVGAState;
-
 static uint8_t rop_to_index[256];

 /***************************************
@@ -3125,7 +3121,7 @@  static void cirrus_reset(void *opaque)
 {
     CirrusVGAState *s = opaque;

-    vga_reset(s);
+    vga_reset(&s->vga);
     unmap_linear_vram(s);
     s->vga.sr[0x06] = 0x0f;
     if (s->device_id == CIRRUS_ID_CLGD5446) {
@@ -3263,7 +3259,7 @@  void isa_cirrus_vga_init(void)
 static void cirrus_pci_lfb_map(PCIDevice *d, int region_num,
 			       uint32_t addr, uint32_t size, int type)
 {
-    CirrusVGAState *s = &((PCICirrusVGAState *)d)->cirrus_vga;
+    CirrusVGAState *s = DO_UPCAST(CirrusVGAState, dev, d);

     /* XXX: add byte swapping apertures */
     cpu_register_physical_memory(addr, s->vga.vram_size,
@@ -3284,7 +3280,7 @@  static void cirrus_pci_lfb_map(PCIDevice *d, int region_num,
 static void cirrus_pci_mmio_map(PCIDevice *d, int region_num,
 				uint32_t addr, uint32_t size, int type)
 {
-    CirrusVGAState *s = &((PCICirrusVGAState *)d)->cirrus_vga;
+    CirrusVGAState *s = DO_UPCAST(CirrusVGAState, dev, d);

     cpu_register_physical_memory(addr, CIRRUS_PNPMMIO_SIZE,
 				 s->cirrus_mmio_io_addr);
@@ -3293,26 +3289,24 @@  static void cirrus_pci_mmio_map(PCIDevice *d, int region_num,
 static void pci_cirrus_write_config(PCIDevice *d,
                                     uint32_t address, uint32_t val, int len)
 {
-    PCICirrusVGAState *pvs = container_of(d, PCICirrusVGAState, dev);
-    CirrusVGAState *s = &pvs->cirrus_vga;
+    CirrusVGAState *s = DO_UPCAST(CirrusVGAState, dev, d);

     pci_default_write_config(d, address, val, len);
-    if (s->vga.map_addr && pvs->dev.io_regions[0].addr == -1)
+    if (s->vga.map_addr && s->dev.io_regions[0].addr == -1)
         s->vga.map_addr = 0;
     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;
+     CirrusVGAState *s = DO_UPCAST(CirrusVGAState, dev, dev);
+     uint8_t *pci_conf = s->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.pci_dev = dev;
      s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
                                       s->vga.screen_dump, s->vga.text_update,
                                       &s->vga);
@@ -3328,10 +3322,10 @@  static void pci_cirrus_vga_initfn(PCIDevice *dev)
      /* 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_register_bar(&s->dev, 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_register_bar(&s->dev, 1, CIRRUS_PNPMMIO_SIZE,
                           PCI_ADDRESS_SPACE_MEM, cirrus_pci_mmio_map);
      }
      /* XXX: ROM BIOS */
@@ -3344,7 +3338,7 @@  void pci_cirrus_vga_init(PCIBus *bus)

 static PCIDeviceInfo cirrus_vga_info = {
     .qdev.name    = "Cirrus VGA",
-    .qdev.size    = sizeof(PCICirrusVGAState),
+    .qdev.size    = sizeof(CirrusVGAState),
     .init         = pci_cirrus_vga_initfn,
     .config_write = pci_cirrus_write_config,
 };