vga: Replace VGA_COMMON with a structure

All VGA devices share a common field subset; currently they do so by
a macro which defines the common fields inline their state structures,
relying on the the common state being placed at offset 0 in the structure.
This makes refactoring the code difficult and requires a lot of error prone
casts.

Replace the macro by a new VGACommonState structure, and the casts by
regular field access and container_of() for upcasts.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff --git a/hw/cirrus_vga_rop2.h b/hw/cirrus_vga_rop2.h
index 137681e..81a5b39 100644
--- a/hw/cirrus_vga_rop2.h
+++ b/hw/cirrus_vga_rop2.h
@@ -48,9 +48,9 @@
     unsigned int col;
     const uint8_t *src1;
 #if DEPTH == 24
-    int skipleft = s->gr[0x2f] & 0x1f;
+    int skipleft = s->vga.gr[0x2f] & 0x1f;
 #else
-    int skipleft = (s->gr[0x2f] & 0x07) * (DEPTH / 8);
+    int skipleft = (s->vga.gr[0x2f] & 0x07) * (DEPTH / 8);
 #endif
 
 #if DEPTH == 8
@@ -105,10 +105,10 @@
     unsigned bitmask;
     unsigned index;
 #if DEPTH == 24
-    int dstskipleft = s->gr[0x2f] & 0x1f;
+    int dstskipleft = s->vga.gr[0x2f] & 0x1f;
     int srcskipleft = dstskipleft / 3;
 #else
-    int srcskipleft = s->gr[0x2f] & 0x07;
+    int srcskipleft = s->vga.gr[0x2f] & 0x07;
     int dstskipleft = srcskipleft * (DEPTH / 8);
 #endif
 
@@ -153,7 +153,7 @@
     unsigned bits;
     unsigned int col;
     unsigned bitmask;
-    int srcskipleft = s->gr[0x2f] & 0x07;
+    int srcskipleft = s->vga.gr[0x2f] & 0x07;
     int dstskipleft = srcskipleft * (DEPTH / 8);
 
     colors[0] = s->cirrus_blt_bgcol;
@@ -188,10 +188,10 @@
     unsigned int bits, bits_xor;
     unsigned int col;
 #if DEPTH == 24
-    int dstskipleft = s->gr[0x2f] & 0x1f;
+    int dstskipleft = s->vga.gr[0x2f] & 0x1f;
     int srcskipleft = dstskipleft / 3;
 #else
-    int srcskipleft = s->gr[0x2f] & 0x07;
+    int srcskipleft = s->vga.gr[0x2f] & 0x07;
     int dstskipleft = srcskipleft * (DEPTH / 8);
 #endif
 
@@ -232,7 +232,7 @@
     int x, y, bitpos, pattern_y;
     unsigned int bits;
     unsigned int col;
-    int srcskipleft = s->gr[0x2f] & 0x07;
+    int srcskipleft = s->vga.gr[0x2f] & 0x07;
     int dstskipleft = srcskipleft * (DEPTH / 8);
 
     colors[0] = s->cirrus_blt_bgcol;