[PATCH][QEMU] Clear bios framebuffer with minimal writes

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH][QEMU] Clear bios framebuffer with minimal writes

Ben Guthro
Support for VGA bios to clear framebuffer with minimal writes.

Signed-off-by: Ben Guthro <[hidden email]>
Signed-off-by: Gary Grebus <[hidden email]>


diff -r abca07dac924 tools/firmware/hvmloader/Makefile
--- a/tools/firmware/hvmloader/Makefile Tue Aug 07 09:24:25 2007 -0400
+++ b/tools/firmware/hvmloader/Makefile Tue Aug 07 09:27:14 2007 -0400
@@ -51,10 +51,10 @@ acpi/acpi.a:
 acpi/acpi.a:
  $(MAKE) -C acpi
 
-roms.h: ../rombios/BIOS-bochs-latest ../vgabios/VGABIOS-lgpl-latest.bin ../vgabios/VGABIOS-lgpl-latest.cirrus.bin ../vmxassist/vmxassist.bin ../etherboot/eb-rtl8139.zrom.h
+roms.h: ../rombios/BIOS-bochs-latest ../vgabios/VGABIOS-lgpl-latest$(DEBUG_ROM).bin ../vgabios/VGABIOS-lgpl-latest.cirrus$(DEBUG_ROM).bin ../vmxassist/vmxassist.bin ../etherboot/eb-rtl8139.zrom.h
  sh ./mkhex rombios ../rombios/BIOS-bochs-latest > roms.h
- sh ./mkhex vgabios_stdvga ../vgabios/VGABIOS-lgpl-latest.bin >> roms.h
- sh ./mkhex vgabios_cirrusvga ../vgabios/VGABIOS-lgpl-latest.cirrus.bin >> roms.h
+ sh ./mkhex vgabios_stdvga ../vgabios/VGABIOS-lgpl-latest$(DEBUG_ROM).bin >> roms.h
+ sh ./mkhex vgabios_cirrusvga ../vgabios/VGABIOS-lgpl-latest.cirrus$(DEBUG_ROM).bin >> roms.h
  sh ./mkhex vmxassist ../vmxassist/vmxassist.bin >> roms.h
  cat ../etherboot/eb-rtl8139.zrom.h >> roms.h
 
diff -r abca07dac924 tools/firmware/vgabios/clext.c
--- a/tools/firmware/vgabios/clext.c Tue Aug 07 09:24:25 2007 -0400
+++ b/tools/firmware/vgabios/clext.c Tue Aug 07 09:24:25 2007 -0400
@@ -1489,19 +1489,31 @@ cirrus_clear_vram_1:
   mov dx, #0x3ce
   out dx, ax
   push ax
-  mov cx, #0xa000
-  mov es, cx
-  xor di, di
+
+;; Windows Vista appears to be emulating this sequence as part of changing
+;; screen resolution, but it generates 4096 writes per iteration.
+;; Instead, use a magic register sequence to write the whole bank.
+;; to avoid
+;;mov cx, #0xa000
+;;mov es, cx
+;;xor di, di
+;;mov ax, si
+;;mov cx, #8192
+;;cld
+;;rep
+;;    stosw
   mov ax, si
-  mov cx, #8192
-  cld
-  rep
-      stosw
+  shl ax, #8
+  mov al, #0xfe
+  out dx, ax ;; Low byte of value to be written to the bank
+  mov ax, si
+  mov al, #0xff  
+  out dx, ax    ;; High byte and trigger the write
+
   pop ax
   inc ah
   cmp ah, bl
   jne cirrus_clear_vram_1
-
   pop es
   popa
   ret
@@ -1628,6 +1640,6 @@ static void cirrus_debugmsg(DI, SI, BP,
   Bit16u DI, SI, BP, SP, BX, DX, CX, AX, ES, DS, FLAGS;
 {
  if((GET_AH()!=0x0E)&&(GET_AH()!=0x02)&&(GET_AH()!=0x09)&&(AX!=0x4F05))
-  printf("vgabios call ah%02x al%02x bx%04x cx%04x dx%04x\n",GET_AH(),GET_AL(),BX,CX,DX);
+  printf("cirrusbios call ah%02x al%02x bx%04x cx%04x dx%04x\n",GET_AH(),GET_AL(),BX,CX,DX);
 }
 #endif
diff -r abca07dac924 tools/ioemu/hw/cirrus_vga.c
--- a/tools/ioemu/hw/cirrus_vga.c Tue Aug 07 09:24:25 2007 -0400
+++ b/tools/ioemu/hw/cirrus_vga.c Tue Aug 07 09:24:25 2007 -0400
@@ -294,6 +294,7 @@ void *shared_vram;
 
 static void cirrus_bitblt_reset(CirrusVGAState *s);
 static void cirrus_update_memory_access(CirrusVGAState *s);
+static void cirrus_vga_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val);
 
 /***************************************
  *
@@ -1497,6 +1498,17 @@ cirrus_hook_write_gr(CirrusVGAState * s,
     case 0x31: // BLT STATUS/START
  cirrus_write_bitblt(s, reg_value);
  break;
+
+ // Extension to allow BIOS to clear 16K VRAM bank in one operation
+    case 0xFE:
+ s->gr[reg_index] = reg_value;  // Lower byte of value to be written
+ break;
+    case 0xFF: {
+ target_phys_addr_t addr;
+ for (addr = 0xa0000; addr < 0xa4000; addr+=2)
+    cirrus_vga_mem_writew(s, addr, (reg_value << 8) | s->gr[0xFE]);
+        }
+ break;
     default:
 #ifdef DEBUG_CIRRUS
  printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index,

_______________________________________________
Xen-devel mailing list
[hidden email]
http://lists.xensource.com/xen-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][QEMU] Clear bios framebuffer with minimal writes

Keir Fraser
On 24/10/07 22:04, "Ben Guthro" <[hidden email]> wrote:

> Support for VGA bios to clear framebuffer with minimal writes.
>
> Signed-off-by: Ben Guthro <[hidden email]>
> Signed-off-by: Gary Grebus <[hidden email]>

Is this really just a workaround for the insane-sounding case of Vista
clearing the screen, as described in one of the comments? Do I understand
correctly, and it looks like Vista does 4096 writes for each iteration of
the rep stosw?

 -- Keir



_______________________________________________
Xen-devel mailing list
[hidden email]
http://lists.xensource.com/xen-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][QEMU] Clear bios framebuffer with minimal writes

Gary Grebus
On Thu, 2007-10-25 at 15:20 +0100, Keir Fraser wrote:

> On 24/10/07 22:04, "Ben Guthro" <[hidden email]> wrote:
>
> > Support for VGA bios to clear framebuffer with minimal writes.
> >
> > Signed-off-by: Ben Guthro <[hidden email]>
> > Signed-off-by: Gary Grebus <[hidden email]>
>
> Is this really just a workaround for the insane-sounding case of Vista
> clearing the screen, as described in one of the comments? Do I understand
> correctly, and it looks like Vista does 4096 writes for each iteration of
> the rep stosw?

Yep.  This happens when resizing the screen in Vista.  It appears to do
this by executing the VGA BIOS code in some sort of emulation, and the
BIOS function to clear the screen (which uses a rep stosw) gets emulated
as 4096 separate writes.

This is so slow that occasionally some watchdog timer in Vista (that was
timing the BIOS emulation) would expire and cause a blue screen.

This fix was a bit of a hack.  It might be possible to speed up VGA
writes enough to make this unnecessary, but that was more of a challenge
than I wanted at the time.

        /gary

--
Gary Grebus
Virtual Iron Software, Inc.



_______________________________________________
Xen-devel mailing list
[hidden email]
http://lists.xensource.com/xen-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][QEMU] Clear bios framebuffer with minimal writes

Keir Fraser
On 25/10/07 16:23, "Gary Grebus" <[hidden email]> wrote:

>> Is this really just a workaround for the insane-sounding case of Vista
>> clearing the screen, as described in one of the comments? Do I understand
>> correctly, and it looks like Vista does 4096 writes for each iteration of
>> the rep stosw?
>
> Yep.  This happens when resizing the screen in Vista.  It appears to do
> this by executing the VGA BIOS code in some sort of emulation, and the
> BIOS function to clear the screen (which uses a rep stosw) gets emulated
> as 4096 separate writes.
>
> This is so slow that occasionally some watchdog timer in Vista (that was
> timing the BIOS emulation) would expire and cause a blue screen.
>
> This fix was a bit of a hack.  It might be possible to speed up VGA
> writes enough to make this unnecessary, but that was more of a challenge
> than I wanted at the time.

Ugh, that is awkward. Did you do this hack before the stdvga
emulation-in-xen and buffered-io patch that you guys also sent out today? I
wonder whether that speeds up vga writes enough, or whether you needed this
hack despite the speedups that other patch achieved? Overall, I guess I'm
not against this patch even though it is a bit sleazy. :-) But obviously
it's even better if the problem goes away by other means...

 -- Keir



_______________________________________________
Xen-devel mailing list
[hidden email]
http://lists.xensource.com/xen-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][QEMU] Clear bios framebuffer with minimal writes

Gary Grebus
On Thu, 2007-10-25 at 16:34 +0100, Keir Fraser wrote:

> Ugh, that is awkward. Did you do this hack before the stdvga
> emulation-in-xen and buffered-io patch that you guys also sent out today? I
> wonder whether that speeds up vga writes enough, or whether you needed this
> hack despite the speedups that other patch achieved? Overall, I guess I'm
> not against this patch even though it is a bit sleazy. :-) But obviously
> it's even better if the problem goes away by other means...
>

This patch predates the stdvga emulation-in-xen and buffered-io changes.
I'll try with only the later changes and see if they are sufficient.

        /gary

--
Gary Grebus
Virtual Iron Software, Inc.



_______________________________________________
Xen-devel mailing list
[hidden email]
http://lists.xensource.com/xen-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][QEMU] Clear bios framebuffer with minimal writes

Gary Grebus
On Thu, 2007-10-25 at 13:14 -0400, Gary Grebus wrote:

> On Thu, 2007-10-25 at 16:34 +0100, Keir Fraser wrote:
>
> > Ugh, that is awkward. Did you do this hack before the stdvga
> > emulation-in-xen and buffered-io patch that you guys also sent out today? I
> > wonder whether that speeds up vga writes enough, or whether you needed this
> > hack despite the speedups that other patch achieved? Overall, I guess I'm
> > not against this patch even though it is a bit sleazy. :-) But obviously
> > it's even better if the problem goes away by other means...
> >
>
> This patch predates the stdvga emulation-in-xen and buffered-io changes.
> I'll try with only the later changes and see if they are sufficient.
>

I tried with only the stdvga and buffered-io patch.  Things got worse,
to the point that Vista no longer boots, encountering a BSOD due to a
timeout in Vista graphics driver.

Apparently the stdvga and buffered-io patch de-optimizes this particular
case, but we didn't notice due to the vgabios patch.

The vgabios patch fixes the intermittent "BSOD on screen resize" problem
either way.  We won't know if it's really necessary until we can fix the
stdvga etc. patch which at the moment looks a little suspect.

        /gary




_______________________________________________
Xen-devel mailing list
[hidden email]
http://lists.xensource.com/xen-devel