Allow multiple graphics devices.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1803 c046a42c-6fe2-441c-8c8c-71466251a162
diff --git a/hw/integratorcp.c b/hw/integratorcp.c
index db73efd..1bcd734 100644
--- a/hw/integratorcp.c
+++ b/hw/integratorcp.c
@@ -27,22 +27,6 @@
 {
 }
 
-static void *lcd;
-
-void vga_update_display(void)
-{
-    pl110_update_display(lcd);
-}
-
-void vga_screen_dump(const char *filename)
-{
-}
-
-void vga_invalidate_display(void)
-{
-    pl110_invalidate_display(lcd);
-}
-
 void DMA_run (void)
 {
 }
@@ -1210,7 +1194,7 @@
             exit (1);
         }
     }
-    lcd = pl110_init(ds, 0xc0000000, pic, 22);
+    pl110_init(ds, 0xc0000000, pic, 22, 0);
 
     /* Load the kernel.  */
     if (!kernel_filename) {
diff --git a/hw/pl110.c b/hw/pl110.c
index 2506dfd..839f103 100644
--- a/hw/pl110.c
+++ b/hw/pl110.c
@@ -89,7 +89,7 @@
   return (s->cr & PL110_CR_EN) && (s->cr & PL110_CR_PWR);
 }
 
-void pl110_update_display(void *opaque)
+static void pl110_update_display(void *opaque)
 {
     pl110_state *s = (pl110_state *)opaque;
     drawfn* fntable;
@@ -205,7 +205,7 @@
     dpy_update(s->ds, 0, first, s->cols, last - first + 1);
 }
 
-void pl110_invalidate_display(void * opaque)
+static void pl110_invalidate_display(void * opaque)
 {
     pl110_state *s = (pl110_state *)opaque;
     s->invalidate = 1;
@@ -378,7 +378,8 @@
    pl110_write
 };
 
-void *pl110_init(DisplayState *ds, uint32_t base, void *pic, int irq)
+void *pl110_init(DisplayState *ds, uint32_t base, void *pic, int irq,
+                 int versatile)
 {
     pl110_state *s;
     int iomemtype;
@@ -386,11 +387,13 @@
     s = (pl110_state *)qemu_mallocz(sizeof(pl110_state));
     iomemtype = cpu_register_io_memory(0, pl110_readfn,
                                        pl110_writefn, s);
-    cpu_register_physical_memory(base, 0x007fffff, iomemtype);
+    cpu_register_physical_memory(base, 0x00000fff, iomemtype);
     s->base = base;
     s->ds = ds;
     s->pic = pic;
     s->irq = irq;
+    graphic_console_init(ds, pl110_update_display, pl110_invalidate_display,
+                         NULL, s);
     /* ??? Save/restore.  */
     return s;
 }
diff --git a/hw/sun4m.c b/hw/sun4m.c
index b41ee25..435ac02 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -187,23 +187,6 @@
     slavio_pic_set_irq_cpu(slavio_intctl, irq, level, cpu);
 }
 
-static void *tcx;
-
-void vga_update_display()
-{
-    tcx_update_display(tcx);
-}
-
-void vga_invalidate_display()
-{
-    tcx_invalidate_display(tcx);
-}
-
-void vga_screen_dump(const char *filename)
-{
-    tcx_screen_dump(tcx, filename);
-}
-
 static void *iommu;
 
 uint32_t iommu_translate(uint32_t addr)
@@ -256,7 +239,7 @@
         slavio_intctl_set_cpu(slavio_intctl, i, envs[i]);
     }
 
-    tcx = tcx_init(ds, PHYS_JJ_TCX_FB, phys_ram_base + ram_size, ram_size, vram_size, graphic_width, graphic_height);
+    tcx_init(ds, PHYS_JJ_TCX_FB, phys_ram_base + ram_size, ram_size, vram_size, graphic_width, graphic_height);
     if (nd_table[0].vlan) {
         if (nd_table[0].model == NULL
             || strcmp(nd_table[0].model, "lance") == 0) {
diff --git a/hw/tcx.c b/hw/tcx.c
index c0fddf3..a3a2114 100644
--- a/hw/tcx.c
+++ b/hw/tcx.c
@@ -37,6 +37,8 @@
     uint8_t dac_index, dac_state;
 } TCXState;
 
+static void tcx_screen_dump(void *opaque, const char *filename);
+
 static void tcx_draw_line32(TCXState *s1, uint8_t *d, 
 			    const uint8_t *s, int width)
 {
@@ -81,7 +83,7 @@
 
 /* Fixed line length 1024 allows us to do nice tricks not possible on
    VGA... */
-void tcx_update_display(void *opaque)
+static void tcx_update_display(void *opaque)
 {
     TCXState *ts = opaque;
     uint32_t page;
@@ -158,7 +160,7 @@
     }
 }
 
-void tcx_invalidate_display(void *opaque)
+static void tcx_invalidate_display(void *opaque)
 {
     TCXState *s = opaque;
     int i;
@@ -269,15 +271,15 @@
     tcx_dac_writel,
 };
 
-void *tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
-	       unsigned long vram_offset, int vram_size, int width, int height)
+void tcx_init(DisplayState *ds, uint32_t addr, uint8_t *vram_base,
+	      unsigned long vram_offset, int vram_size, int width, int height)
 {
     TCXState *s;
     int io_memory;
 
     s = qemu_mallocz(sizeof(TCXState));
     if (!s)
-        return NULL;
+        return;
     s->ds = ds;
     s->addr = addr;
     s->vram = vram_base;
@@ -289,14 +291,15 @@
     io_memory = cpu_register_io_memory(0, tcx_dac_read, tcx_dac_write, s);
     cpu_register_physical_memory(addr + 0x200000, TCX_DAC_NREGS, io_memory);
 
+    graphic_console_init(s->ds, tcx_update_display, tcx_invalidate_display,
+                         tcx_screen_dump, s);
     register_savevm("tcx", addr, 1, tcx_save, tcx_load, s);
     qemu_register_reset(tcx_reset, s);
     tcx_reset(s);
     dpy_resize(s->ds, width, height);
-    return s;
 }
 
-void tcx_screen_dump(void *opaque, const char *filename)
+static void tcx_screen_dump(void *opaque, const char *filename)
 {
     TCXState *s = opaque;
     FILE *f;
diff --git a/hw/vga.c b/hw/vga.c
index 49e5b21..a712790 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -146,6 +146,8 @@
 VGAState *vga_state;
 int vga_io_memory;
 
+static void vga_screen_dump(void *opaque, const char *filename);
+
 static uint32_t vga_ioport_read(void *opaque, uint32_t addr)
 {
     VGAState *s = opaque;
@@ -1482,9 +1484,9 @@
 #define GMODE_GRAPH    1
 #define GMODE_BLANK 2 
 
-void vga_update_display(void)
+static void vga_update_display(void *opaque)
 {
-    VGAState *s = vga_state;
+    VGAState *s = (VGAState *)opaque;
     int full_update, graphic_mode;
 
     if (s->ds->depth == 0) {
@@ -1532,9 +1534,9 @@
 }
 
 /* force a full display refresh */
-void vga_invalidate_display(void)
+static void vga_invalidate_display(void *opaque)
 {
-    VGAState *s = vga_state;
+    VGAState *s = (VGAState *)opaque;
     
     s->last_width = -1;
     s->last_height = -1;
@@ -1698,6 +1700,8 @@
     s->get_bpp = vga_get_bpp;
     s->get_offsets = vga_get_offsets;
     s->get_resolution = vga_get_resolution;
+    graphic_console_init(s->ds, vga_update_display, vga_invalidate_display,
+                         vga_screen_dump, s);
     /* XXX: currently needed for display */
     vga_state = s;
 }
@@ -1854,13 +1858,13 @@
 
 /* save the vga display in a PPM image even if no display is
    available */
-void vga_screen_dump(const char *filename)
+static void vga_screen_dump(void *opaque, const char *filename)
 {
-    VGAState *s = vga_state;
+    VGAState *s = (VGAState *)opaque;
     DisplayState *saved_ds, ds1, *ds = &ds1;
     
     /* XXX: this is a little hackish */
-    vga_invalidate_display();
+    vga_invalidate_display(s);
     saved_ds = s->ds;
 
     memset(ds, 0, sizeof(DisplayState));
@@ -1871,7 +1875,7 @@
 
     s->ds = ds;
     s->graphic_mode = -1;
-    vga_update_display();
+    vga_update_display(s);
     
     if (ds->data) {
         ppm_save(filename, ds->data, vga_save_w, vga_save_h,