Skip to contentSkip to conversation

VMware SVGA II emulation

PATCH In review andrzej zaborowski 2 participants 4 messages Mar 11, 2007 – Apr 3, 2007 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VMware SVGA II emulation

Hi,
this adds emulation of VMware SVGA II chipset (mostly a proof of concept). It's a pci card that VMware machines use as main display. There's an opensource, crossplatform X driver for it in most distributions and it's autodetected like other cards by some live-cd's. The advantages over standard vga:
* arbitrary resolutions,
* extensible - the guest will use as much hardware acceleration as the card claims to support in the CAPABILITIES flags. 3D acceleration can be easily added (dunno if it's documented).

This implementation only does mouse cursor and rectangle blitting/filling in hardware. The rectangle operations don't work so well and they're only used when moving windows in X. With normal software drawing the animation looks probably smoother (though obviously slower).

I didn't embed a standard VGA card in this card (like in the cirrus), so it doesn't have text mode. It should be easy to add.

Pass "-vmwarevga" to enable.

The defines at the top of the file are for disabling/enablig the acceleration - if anything seems to be broken try disabling HW_RECT_ACCEL. DIRECT_VRAM is for giving direct access to the SDL framebuffer for the guest - currently there are two framebuffers: one in the video ram, in the region pointed to by phys_ram_base and the other one in ds->data, and in case of VMware svga they have the same format, so it would be logical to use only one of them. However ds->data is also used for the qemu virtual consoles. Since I'm using io memory, the drawing is slower with DIRECT_VRAM than without it - when the copying between the framebuffers is done with memcpy - glxgears gave me about 200 FPS with DIRECT_VRAM and 300 FPS without it. It may be worth adding a yet another memory pages type for faster graphics.

VMware svga also does transparent and full colour mouse cursors, and other tircks, but SDL doesn't support that so I didn't add it.

A (not very amusing) screenshot at
http://www.zabor.org/balrog/screen-qemu-vmwaresvga.png

Regards,
Andrew

From 815b17b87659f1d49436f134e26bbdb0f501ad09 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Sun, 11 Mar 2007 15:32:15 +0100
Subject: [PATCH] VMware-SVGA II emulation.

---
 Makefile.target |    2 +-
 hw/pc.c         |    8 +
 hw/vmware_vga.c | 1115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c            |    9 +
 vl.h            |    5 +
 5 files changed, 1138 insertions(+), 1 deletions(-)
Makefile.target +1 -1
index 8eaa8dd..8ba82c7 100644
@@ -371,7 +371,7 @@ ifeq ($(TARGET_BASE_ARCH), i386)
 VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
 VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 VL_OBJS+= cirrus_vga.o mixeng.o apic.o parallel.o acpi.o piix_pci.o
-VL_OBJS+= usb-uhci.o smbus_eeprom.o
+VL_OBJS+= usb-uhci.o smbus_eeprom.o vmware_vga.o
 CPPFLAGS += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), ppc)
hw/pc.c +8 -0
index ba9c2d9..dd25e33 100644
@@ -651,6 +651,14 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
         }
     }
 
+    if (vmsvga_enabled) {
+        if (pci_enabled)
+            pci_vmsvga_init(pci_bus, ds, phys_ram_base + ram_size,
+                            ram_size, vga_ram_size);
+        else
+            fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
+    }
+
     rtc_state = rtc_init(0x70, 8);
 
     register_ioport_read(0x92, 1, 1, ioport92_read, NULL);
hw/vmware_vga.c new file +1115 -0

1,115 lines not on this page · raw message

vl.c +9 -0
index 98fef9d..c5232fd 100644
@@ -154,6 +154,7 @@ QEMUTimer *gui_timer;
 int vm_running;
 int rtc_utc = 1;
 int cirrus_vga_enabled = 1;
+int vmsvga_enabled = 0;
 #ifdef TARGET_SPARC
 int graphic_width = 1024;
 int graphic_height = 768;
@@ -6532,6 +6533,7 @@ enum {
     QEMU_OPTION_k,
     QEMU_OPTION_localtime,
     QEMU_OPTION_cirrusvga,
+    QEMU_OPTION_vmsvga,
     QEMU_OPTION_g,
     QEMU_OPTION_std_vga,
     QEMU_OPTION_echr,
@@ -6638,6 +6640,7 @@ const QEMUOption qemu_options[] = {
     /* temporary options */
     { "usb", 0, QEMU_OPTION_usb },
     { "cirrusvga", 0, QEMU_OPTION_cirrusvga },
+    { "vmwarevga", 0, QEMU_OPTION_vmsvga },
     { "no-acpi", 0, QEMU_OPTION_no_acpi },
     { "no-reboot", 0, QEMU_OPTION_no_reboot },
     { "daemonize", 0, QEMU_OPTION_daemonize },
@@ -7198,9 +7201,15 @@ int main(int argc, char **argv)
                 break;
             case QEMU_OPTION_cirrusvga:
                 cirrus_vga_enabled = 1;
+                vmsvga_enabled = 0;
+                break;
+            case QEMU_OPTION_vmsvga:
+                cirrus_vga_enabled = 0;
+                vmsvga_enabled = 1;
                 break;
             case QEMU_OPTION_std_vga:
                 cirrus_vga_enabled = 0;
+                vmsvga_enabled = 0;
                 break;
             case QEMU_OPTION_g:
                 {
vl.h +5 -0
index 04fe3cc..86e5975 100644
@@ -148,6 +148,7 @@ extern int ram_size;
 extern int bios_size;
 extern int rtc_utc;
 extern int cirrus_vga_enabled;
+extern int vmsvga_enabled;
 extern int graphic_width;
 extern int graphic_height;
 extern int graphic_depth;
@@ -922,6 +923,10 @@ void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
 void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base, 
                          unsigned long vga_ram_offset, int vga_ram_size);
 
+/* vmware_vga.c */
+void pci_vmsvga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
+                     unsigned long vga_ram_offset, int vga_ram_size);
+
 /* sdl.c */
 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
 
Signature · 1 line
1.4.4.3
#1 lore raw

Hi,
I looked at how the embedding of a standard VGA in the VMware SVGA
could be done (mainly out of curiosity) and it wasn't difficult. I had to make small changes in hw/vga.c but I think it's made more flexible now. Attached is a second version of the VMware SVGA patch. This time including the "Host-accelerated mouse cursor support in SDL" patch in the same file. I added a FIFO for buffering screen update requests so as to avoid touching the SDL buffer between scheduled updates, (which could lead to drawing over qemu monitor or even segfaults if the resolution was changed in meantime). I also found what was wrong with the accelerated rectangle filling and fixed a couple of other issues. The palette size was also wrong in the older patch - credits to Anthony Liguori who spotted it.

I have not tested switching between std VGA graphic modes and VMware SVGA mode, but the switching between VGA text mode and VMware SVGA mode worked fine (although the black console background was becoming not exactly black). Savevm/loadvm should also work, including the VGA part.
In this version VMware SVGA is a standalone VGA so we're using only one qemu console, like with "-cirrusvga".

Regards,
Andrew

From 3eccb31262e85ded9edb6decc842c4c9d91c0817 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Wed, 28 Mar 2007 03:37:05 +0200
Subject: [PATCH] VMware-SVGA II emulation.

---
 Makefile.target |    2 +-
 hw/cirrus_vga.c |    3 +
 hw/pc.c         |    6 +
 hw/vga.c        |   12 +-
 hw/vga_int.h    |    4 +
 hw/vmware_vga.c | 1187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sdl.c           |  104 +++++-
 vl.c            |   13 +
 vl.h            |   13 +-
 9 files changed, 1336 insertions(+), 8 deletions(-)
Makefile.target +1 -1
index 8eaa8dd..8ba82c7 100644
@@ -371,7 +371,7 @@ ifeq ($(TARGET_BASE_ARCH), i386)
 VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
 VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 VL_OBJS+= cirrus_vga.o mixeng.o apic.o parallel.o acpi.o piix_pci.o
-VL_OBJS+= usb-uhci.o smbus_eeprom.o
+VL_OBJS+= usb-uhci.o smbus_eeprom.o vmware_vga.o
 CPPFLAGS += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), ppc)
hw/cirrus_vga.c +3 -0
index d8fb37a..2cbafe1 100644
@@ -3193,6 +3193,9 @@ void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
     vga_common_init((VGAState *)s, 
                     ds, vga_ram_base, vga_ram_offset, vga_ram_size);
     cirrus_init_common(s, device_id, 1);
+
+    graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump, s);
+
     s->pci_dev = (PCIDevice *)d;
 
     /* setup memory space */
hw/pc.c +6 -0
index ba9c2d9..91c4174 100644
@@ -641,6 +641,12 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
             isa_cirrus_vga_init(ds, phys_ram_base + vga_ram_addr, 
                                 vga_ram_addr, vga_ram_size);
         }
+    } else if (vmsvga_enabled) {
+        if (pci_enabled)
+            pci_vmsvga_init(pci_bus, ds, phys_ram_base + ram_size,
+                            ram_size, vga_ram_size);
+        else
+            fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
     } else {
         if (pci_enabled) {
             pci_vga_init(pci_bus, ds, phys_ram_base + vga_ram_addr, 
hw/vga.c +9 -3
index 5acacf9..2dadcca 100644
@@ -1788,12 +1788,13 @@ void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
     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);
+    s->update = vga_update_display;
+    s->invalidate = vga_invalidate_display;
+    s->screen_dump = vga_screen_dump;
 }
 
 /* used by both ISA and PCI */
-static void vga_init(VGAState *s)
+void vga_init(VGAState *s)
 {
     int vga_io_memory;
 
@@ -1856,6 +1857,8 @@ int isa_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
     vga_common_init(s, ds, vga_ram_base, vga_ram_offset, vga_ram_size);
     vga_init(s);
 
+    graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump, s);
+
 #ifdef CONFIG_BOCHS_VBE
     /* XXX: use optimized standard vga accesses */
     cpu_register_physical_memory(VBE_DISPI_LFB_PHYSICAL_ADDRESS, 
@@ -1881,6 +1884,9 @@ int pci_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
     
     vga_common_init(s, ds, vga_ram_base, vga_ram_offset, vga_ram_size);
     vga_init(s);
+
+    graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump, s);
+
     s->pci_dev = &d->dev;
     
     pci_conf = d->dev.config;
hw/vga_int.h +4 -0
index 633f344..e7df0f7 100644
@@ -134,6 +134,9 @@
     uint32_t cursor_offset;                                             \
     unsigned int (*rgb_to_pixel)(unsigned int r,                        \
                                  unsigned int g, unsigned b);           \
+    vga_hw_update_ptr update;                                           \
+    vga_hw_invalidate_ptr invalidate;                                   \
+    vga_hw_screen_dump_ptr screen_dump;                                 \
     /* hardware mouse cursor support */                                 \
     uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32];                  \
     void (*cursor_invalidate)(struct VGAState *s);                      \
@@ -157,6 +160,7 @@ static inline int c6_to_8(int v)
 
 void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base, 
                      unsigned long vga_ram_offset, int vga_ram_size);
+void vga_init(VGAState *s);
 uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
 void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
 void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
hw/vmware_vga.c new file +1187 -0

1,187 lines not on this page · raw message

sdl.c +101 -3

148 lines not on this page · raw message

vl.c +13 -0
index e871c8c..c5232fd 100644
@@ -154,6 +154,7 @@ QEMUTimer *gui_timer;
 int vm_running;
 int rtc_utc = 1;
 int cirrus_vga_enabled = 1;
+int vmsvga_enabled = 0;
 #ifdef TARGET_SPARC
 int graphic_width = 1024;
 int graphic_height = 768;
@@ -542,6 +543,10 @@ int kbd_mouse_is_absolute(void)
     return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute;
 }
 
+void (*kbd_mouse_set)(int x, int y, int on) = NULL;
+void (*kbd_cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
+                          uint8_t *image, uint8_t *mask) = NULL;
+
 void do_info_mice(void)
 {
     QEMUPutMouseEntry *cursor;
@@ -6528,6 +6533,7 @@ enum {
     QEMU_OPTION_k,
     QEMU_OPTION_localtime,
     QEMU_OPTION_cirrusvga,
+    QEMU_OPTION_vmsvga,
     QEMU_OPTION_g,
     QEMU_OPTION_std_vga,
     QEMU_OPTION_echr,
@@ -6634,6 +6640,7 @@ const QEMUOption qemu_options[] = {
     /* temporary options */
     { "usb", 0, QEMU_OPTION_usb },
     { "cirrusvga", 0, QEMU_OPTION_cirrusvga },
+    { "vmwarevga", 0, QEMU_OPTION_vmsvga },
     { "no-acpi", 0, QEMU_OPTION_no_acpi },
     { "no-reboot", 0, QEMU_OPTION_no_reboot },
     { "daemonize", 0, QEMU_OPTION_daemonize },
@@ -7194,9 +7201,15 @@ int main(int argc, char **argv)
                 break;
             case QEMU_OPTION_cirrusvga:
                 cirrus_vga_enabled = 1;
+                vmsvga_enabled = 0;
+                break;
+            case QEMU_OPTION_vmsvga:
+                cirrus_vga_enabled = 0;
+                vmsvga_enabled = 1;
                 break;
             case QEMU_OPTION_std_vga:
                 cirrus_vga_enabled = 0;
+                vmsvga_enabled = 0;
                 break;
             case QEMU_OPTION_g:
                 {
vl.h +12 -1
index c7c7d73..67469c8 100644
@@ -148,6 +148,7 @@ extern int ram_size;
 extern int bios_size;
 extern int rtc_utc;
 extern int cirrus_vga_enabled;
+extern int vmsvga_enabled;
 extern int graphic_width;
 extern int graphic_height;
 extern int graphic_depth;
@@ -890,7 +891,13 @@ struct DisplayState {
     void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
     void (*dpy_resize)(struct DisplayState *s, int w, int h);
     void (*dpy_refresh)(struct DisplayState *s);
-    void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y, int dst_x, int dst_y, int w, int h);
+    void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y,
+                     int dst_x, int dst_y, int w, int h);
+    void (*dpy_fill)(struct DisplayState *s, int x, int y,
+                     int w, int h, uint32_t c);
+    void (*mouse_set)(int x, int y, int on);
+    void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
+                          uint8_t *image, uint8_t *mask);
 };
 
 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
@@ -915,6 +922,10 @@ void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
 void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base, 
                          unsigned long vga_ram_offset, int vga_ram_size);
 
+/* vmware_vga.c */
+void pci_vmsvga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
+                     unsigned long vga_ram_offset, int vga_ram_size);
+
 /* sdl.c */
 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
 
Signature · 1 line
1.4.4.3
#2 lore raw
Quoted 14 lines · andrzej zaborowski

Hi,
I looked at how the embedding of a standard VGA in the VMware SVGA
could be done (mainly out of curiosity) and it wasn't difficult. I had to make small changes in hw/vga.c but I think it's made more flexible now. Attached is a second version of the VMware SVGA patch. This time including the "Host-accelerated mouse cursor support in SDL" patch in the same file. I added a FIFO for buffering screen update requests so as to avoid touching the SDL buffer between scheduled updates, (which could lead to drawing over qemu monitor or even segfaults if the resolution was changed in meantime). I also found what was wrong with the accelerated rectangle filling and fixed a couple of other issues. The palette size was also wrong in the older patch - credits to Anthony Liguori who spotted it.

Quoted 7 lines

I have not tested switching between std VGA graphic modes and VMware SVGA mode, but the switching between VGA text mode and VMware SVGA mode worked fine (although the black console background was becoming not exactly black). Savevm/loadvm should also work, including the VGA part.
In this version VMware SVGA is a standalone VGA so we're using only one qemu console, like with "-cirrusvga".

I left the sdl_copy bit out because it broke scrolling of a guest Linux framebuffer in the moment it initialized its virtual consoles. Maybe that's a bug in libsdl 1.2.

Thiemo

#3 lore raw

Hi,

On 02/04/07, Thiemo Seufer <[email protected]> wrote:
[..]

Quoted 3 lines

I left the sdl_copy bit out because it broke scrolling of a guest Linux framebuffer in the moment it initialized its virtual consoles. Maybe that's a bug in libsdl 1.2.

Thanks for checking this. I didn't have any ideas as to what could be affecting the Cirrus VGA in the patch, but yes, the .dpy_copy is used in it.

This is to remove two obsolete variables in vl.c that I have accidentally left in the patch and only noticed it in the commitdiff:

vl.c +0 -0
@@ -543,10 +543,6 @@ int kbd_mouse_is_absolute(void)
    return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute;

}

-void (*kbd_mouse_set)(int x, int y, int on) = NULL;
-void (*kbd_cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
- uint8_t *image, uint8_t *mask) = NULL;
-
void do_info_mice(void)

{
    QEMUPutMouseEntry *cursor;

Cheers,
Andrzej