ia64/xen-unstable

changeset 16582:0884e0a5ecc3

ioemu/qemu vga: save and restore vram buffer

The existing stdvga driver from xen-unstable tools/ioemu/hw/vga* does
not save the emulated VGA memory contents. The symptoms include video
malfunction after restore, including black screen (which can often be
fixed by asking the guest to redraw) but also missing font setup etc.
The attached patch fixes this by saving the entire VGA memory buffer,
just like the Xen ioemu Cirrus emulator does.

I have reinterpreted the `is_vbe' byte, which is related to
CONFIG_BOCHS_VBE, as a general flags word. This enables my code to
allow old images to be restored (albeit with loss of VGA memory), by
using another bit in that word to indicate whether the VGA memory dump
is present.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Dec 12 09:53:00 2007 +0000 (2007-12-12)
parents 4054cd60895b
children dad243d08849
files tools/ioemu/hw/vga.c tools/ioemu/hw/vga_int.h
line diff
     1.1 --- a/tools/ioemu/hw/vga.c	Mon Dec 10 13:49:22 2007 +0000
     1.2 +++ b/tools/ioemu/hw/vga.c	Wed Dec 12 09:53:00 2007 +0000
     1.3 @@ -1742,6 +1742,8 @@ static CPUWriteMemoryFunc *vga_mem_write
     1.4  static void vga_save(QEMUFile *f, void *opaque)
     1.5  {
     1.6      VGAState *s = opaque;
     1.7 +    unsigned save_format_flags;
     1.8 +    uint32_t vram_size;
     1.9  #ifdef CONFIG_BOCHS_VBE
    1.10      int i;
    1.11  #endif
    1.12 @@ -1772,8 +1774,9 @@ static void vga_save(QEMUFile *f, void *
    1.13      qemu_put_buffer(f, s->palette, 768);
    1.14  
    1.15      qemu_put_be32s(f, &s->bank_offset);
    1.16 +    save_format_flags = VGA_SAVE_FORMAT_FLAG_VRAM_DATA;
    1.17  #ifdef CONFIG_BOCHS_VBE
    1.18 -    qemu_put_byte(f, 1);
    1.19 +    qemu_put_byte(f, save_format_flags | VGA_SAVE_FORMAT_FLAG_BOCHS_VBE);
    1.20      qemu_put_be16s(f, &s->vbe_index);
    1.21      for(i = 0; i < VBE_DISPI_INDEX_NB; i++)
    1.22          qemu_put_be16s(f, &s->vbe_regs[i]);
    1.23 @@ -1781,17 +1784,19 @@ static void vga_save(QEMUFile *f, void *
    1.24      qemu_put_be32s(f, &s->vbe_line_offset);
    1.25      qemu_put_be32s(f, &s->vbe_bank_mask);
    1.26  #else
    1.27 -    qemu_put_byte(f, 0);
    1.28 +    qemu_put_byte(f, save_format_flags);
    1.29  #endif
    1.30 +    vram_size = s->vram_size;
    1.31 +    qemu_put_be32s(f, &vram_size); 
    1.32 +    qemu_put_buffer(f, s->vram_ptr, s->vram_size); 
    1.33  }
    1.34  
    1.35  static int vga_load(QEMUFile *f, void *opaque, int version_id)
    1.36  {
    1.37      VGAState *s = opaque;
    1.38 -    int is_vbe, ret;
    1.39 -#ifdef CONFIG_BOCHS_VBE
    1.40 -    int i;
    1.41 -#endif
    1.42 +    int ret;
    1.43 +    unsigned int save_format_flags;
    1.44 +    uint32_t vram_size;
    1.45  
    1.46      if (version_id > 2)
    1.47          return -EINVAL;
    1.48 @@ -1825,9 +1830,9 @@ static int vga_load(QEMUFile *f, void *o
    1.49      qemu_get_buffer(f, s->palette, 768);
    1.50  
    1.51      qemu_get_be32s(f, &s->bank_offset);
    1.52 -    is_vbe = qemu_get_byte(f);
    1.53 +    save_format_flags = qemu_get_byte(f);
    1.54  #ifdef CONFIG_BOCHS_VBE
    1.55 -    if (!is_vbe)
    1.56 +    if (!(save_format_flags & VGA_SAVE_FORMAT_FLAG_BOCHS_VBE))
    1.57          return -EINVAL;
    1.58      qemu_get_be16s(f, &s->vbe_index);
    1.59      for(i = 0; i < VBE_DISPI_INDEX_NB; i++)
    1.60 @@ -1836,9 +1841,16 @@ static int vga_load(QEMUFile *f, void *o
    1.61      qemu_get_be32s(f, &s->vbe_line_offset);
    1.62      qemu_get_be32s(f, &s->vbe_bank_mask);
    1.63  #else
    1.64 -    if (is_vbe)
    1.65 +    if (save_format_flags & VGA_SAVE_FORMAT_FLAG_BOCHS_VBE)
    1.66          return -EINVAL;
    1.67  #endif
    1.68 +    if (save_format_flags & VGA_SAVE_FORMAT_FLAG_VRAM_DATA) {
    1.69 +	/* people who restore old images may be lucky ... */
    1.70 +	qemu_get_be32s(f, &vram_size);
    1.71 +	if (vram_size != s->vram_size)
    1.72 +	    return -EINVAL;
    1.73 +	qemu_get_buffer(f, s->vram_ptr, s->vram_size); 
    1.74 +    }
    1.75  
    1.76      /* force refresh */
    1.77      s->graphic_mode = -1;
     2.1 --- a/tools/ioemu/hw/vga_int.h	Mon Dec 10 13:49:22 2007 +0000
     2.2 +++ b/tools/ioemu/hw/vga_int.h	Wed Dec 12 09:53:00 2007 +0000
     2.3 @@ -157,6 +157,9 @@ static inline int c6_to_8(int v)
     2.4      return (v << 2) | (b << 1) | b;
     2.5  }
     2.6  
     2.7 +#define VGA_SAVE_FORMAT_FLAG_BOCHS_VBE  0x01
     2.8 +#define VGA_SAVE_FORMAT_FLAG_VRAM_DATA  0x02
     2.9 +
    2.10  void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base, 
    2.11                       unsigned long vga_ram_offset, int vga_ram_size);
    2.12  uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);