qemu fixup patch sequence.
First patch adds a second PCI BAR as per the VMware SVGA specification for the fifo instead of using the top of the VRAM BAR.
Patches 2-5 are from Anthony and I just rebased them on top of master.
Patch6: fixes a crasher in vmware when X starts inside the guest.
I've booted these with an F12 LiveCD and all seems to work.
Dave.
PATCH 2/6 Make sure to enable dirty tracking of VBE vram mapping
In reply to Dave AirlieFrom: Anthony Liguori <[email protected]>
Apparently, VBE maps the VGA vram to a fixed physical location. KVM requires that all mappings of the VGA vram have dirty tracking enabled on them. Any access to the VGA vram through the VBE mapping currently fails to result in dirty page tracking updates causing a black screen.
This is the true root cause of VMware VGA not working correctly under KVM and likely also an issue with some of the std-vga black screen issues too.
Cirrus does not enable VBE so it would not be a problem when using Cirrus.
--- hw/vga-isa.c | 6 +----- hw/vga-pci.c | 7 +------ hw/vga.c | 24 ++++++++++++++++++++++++ hw/vga_int.h | 5 +++-- hw/vmware_vga.c | 8 ++------ 5 files changed, 31 insertions(+), 19 deletions(-)
hw/vga-isa.c +1 -5
@@ -42,11 +42,7 @@ int isa_vga_init(void) s->ds =graphic_console_init (s->update, s->invalidate, s->screen_dump, s->text_update, s); -#ifdef CONFIG_BOCHS_VBE -/* XXX: use optimized standard vga accesses */ -cpu_register_physical_memory (VBE_DISPI_LFB_PHYSICAL_ADDRESS , -VGA_RAM_SIZE , s->vram_offset); -#endif +vga_init_vbe (s);/* ROM BIOS */ rom_add_vga (VGABIOS_FILENAME );return 0 ;
hw/vga-pci.c +1 -6
@@ -106,12 +106,7 @@ static int pci_vga_initfn(PCIDevice *dev) PCI_BASE_ADDRESS_MEM_PREFETCH, vga_map); } -#ifdef CONFIG_BOCHS_VBE -/* XXX: use optimized standard vga accesses */ -cpu_register_physical_memory (VBE_DISPI_LFB_PHYSICAL_ADDRESS , -VGA_RAM_SIZE , s->vram_offset); -#endif - +vga_init_vbe (s);/* ROM BIOS */ rom_add_vga (VGABIOS_FILENAME );return 0 ;
hw/vga.c +24 -0
@@ -1581,6 +1581,14 @@ static void vga_sync_dirty_bitmap(VGACommonState *s)cpu_physical_sync_dirty_bitmap (isa_mem_base +0xa0000 ,0xa8000 );cpu_physical_sync_dirty_bitmap (isa_mem_base +0xa8000 ,0xb0000 ); } + +#ifdef CONFIG_BOCHS_VBE +if (s->vbe_mapped) { +cpu_physical_sync_dirty_bitmap (VBE_DISPI_LFB_PHYSICAL_ADDRESS , +VBE_DISPI_LFB_PHYSICAL_ADDRESS + s->vram_size); + } +#endif + }void vga_dirty_log_start (VGACommonState *s)
@@ -1592,6 +1600,13 @@ void vga_dirty_log_start(VGACommonState *s)kvm_log_start (isa_mem_base +0xa0000 ,0x8000 );kvm_log_start (isa_mem_base +0xa8000 ,0x8000 ); } + +#ifdef CONFIG_BOCHS_VBE +if (kvm_enabled () && s->vbe_mapped) { +kvm_log_start (VBE_DISPI_LFB_PHYSICAL_ADDRESS , s->vram_size); + } +#endif + }/*
@@ -2294,6 +2309,15 @@ void vga_init(VGACommonState *s)qemu_register_coalesced_mmio (isa_mem_base +0x000a0000 ,0x20000 ); } +void vga_init_vbe (VGACommonState *s) +{ +#ifdef CONFIG_BOCHS_VBE +/* XXX: use optimized standard vga accesses */ +cpu_register_physical_memory (VBE_DISPI_LFB_PHYSICAL_ADDRESS , +VGA_RAM_SIZE , s->vram_offset); + s->vbe_mapped =1 ; +#endif +}/********************************************************/ /* vga screen dump */
hw/vga_int.h +3 -2
@@ -71,8 +71,8 @@uint16_t vbe_regs[VBE_DISPI_INDEX_NB ]; \uint32_t vbe_start_addr; \uint32_t vbe_line_offset; \ -uint32_t vbe_bank_mask; - +uint32_t vbe_bank_mask; \ +int vbe_mapped;#else #define VGA_STATE_COMMON_BOCHS_VBE
@@ -217,6 +217,7 @@ void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1, unsigned int color_xor);int vga_ioport_invalid (VGACommonState *s,uint32_t addr); +void vga_init_vbe (VGACommonState *s);extern const uint8_t sr_mask[8 ];extern const uint8_t gr_mask[16 ];
hw/vmware_vga.c +2 -6
@@ -1129,12 +1129,8 @@ static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size) vmsvga_screen_dump, vmsvga_text_update, s); -#ifdef CONFIG_BOCHS_VBE -/* XXX: use optimized standard vga accesses */ -cpu_register_physical_memory (VBE_DISPI_LFB_PHYSICAL_ADDRESS , - vga_ram_size, s->vga.vram_offset); -#endif -rom_add_vga (VGABIOS_FILENAME ); +vga_init_vbe (&s->vga); +rom_add_vga (VGABIOS_FILENAME ); } static void pci_vmsvga_map_ioport(PCIDevice *pci_dev, int region_num,
Signature · 1 line
1.6.5.2
PATCH 1/6 vmware: setup PCI BAR 2 for FIFO as per vmware spec
In reply to Dave AirlieFrom: Dave Airlie <[email protected]>
--- hw/vmware_vga.c | 35 ++++++++++++++++++++++++++++++----- 1 files changed, 30 insertions(+), 5 deletions(-)
hw/vmware_vga.c +30 -5
@@ -67,6 +67,11 @@ struct vmsvga_state_s {int syncing;int fb_size; +ram_addr_t fifo_offset; +uint8_t *fifo_ptr; +unsigned int fifo_size; +target_phys_addr_t fifo_base; +union {uint32_t *fifo;struct __attribute__((__packed__ )) {
@@ -680,7 +685,7 @@ static uint32_t vmsvga_value_read(void *opaque, uint32_t address)return 0x0 ;case SVGA_REG_VRAM_SIZE : -return s->vga.vram_size -SVGA_FIFO_SIZE ; +return s->vga.vram_size;case SVGA_REG_FB_SIZE :return s->fb_size;
@@ -701,10 +706,10 @@ static uint32_t vmsvga_value_read(void *opaque, uint32_t address)return caps;case SVGA_REG_MEM_START : -return s->vram_base + s->vga.vram_size -SVGA_FIFO_SIZE ; +return s->fifo_base;case SVGA_REG_MEM_SIZE : -return SVGA_FIFO_SIZE ; +return s->fifo_size;case SVGA_REG_CONFIG_DONE :return s->config;
@@ -790,7 +795,7 @@ static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)case SVGA_REG_CONFIG_DONE :if (value) { - s->fifo = (uint32_t *) &s->vga.vram_ptr[s->vga.vram_size -SVGA_FIFO_SIZE ]; + s->fifo = (uint32_t *) s->fifo_ptr;/* Check range and alignment. */ if ((CMD (min) |CMD (max) |CMD (next_cmd) |CMD (stop)) &3 )
@@ -1059,7 +1064,7 @@ static int vmsvga_post_load(void *opaque, int version_id) s->invalidated =1 ;if (s->config) - s->fifo = (uint32_t *) &s->vga.vram_ptr[s->vga.vram_size -SVGA_FIFO_SIZE ]; + s->fifo = (uint32_t *) s->fifo_ptr;return 0 ; }
@@ -1111,6 +1116,10 @@ static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size)vmsvga_reset (s); + s->fifo_size =SVGA_FIFO_SIZE ; + s->fifo_offset =qemu_ram_alloc (s->fifo_size); + s->fifo_ptr =qemu_get_ram_ptr (s->fifo_offset); +vga_common_init (&s->vga, vga_ram_size);vga_init (&s->vga);vmstate_register (0 , &vmstate_vga_common, &s->vga);
@@ -1166,6 +1175,19 @@ static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num, iomemtype); } +static void pci_vmsvga_map_fifo (PCIDevice *pci_dev,int region_num, +pcibus_t addr,pcibus_t size,int type) +{ +struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev; +struct vmsvga_state_s *s = &d->chip; +ram_addr_t iomemtype; + + s->fifo_base = addr; + iomemtype = s->fifo_offset |IO_MEM_RAM ; +cpu_register_physical_memory (s->fifo_base, s->fifo_size, + iomemtype); +} +static int pci_vmsvga_initfn (PCIDevice *dev) { struct pci_vmsvga_state_s *s =
@@ -1189,6 +1211,9 @@ static int pci_vmsvga_initfn(PCIDevice *dev)pci_register_bar (&s->card,1 ,VGA_RAM_SIZE ,PCI_BASE_ADDRESS_MEM_PREFETCH , pci_vmsvga_map_mem); +pci_register_bar (&s->card,2 ,SVGA_FIFO_SIZE , +PCI_BASE_ADDRESS_MEM_PREFETCH , pci_vmsvga_map_fifo); +vmsvga_init (&s->chip,VGA_RAM_SIZE );return 0 ;
Signature · 1 line
1.6.5.2
PATCH 3/6 Make sure to enable dirty log tracking for VMware VGA
In reply to Dave AirlieFrom: Anthony Liguori <[email protected]>
This is needed for VMware VGA to work properly under KVM.
--- hw/vmware_vga.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
hw/vmware_vga.c +4 -0
@@ -1169,6 +1169,10 @@ static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num,#endif cpu_register_physical_memory (s->vram_base, s->vga.vram_size, iomemtype); + + s->vga.map_addr = addr; + s->vga.map_end = addr + s->vga.vram_size; +vga_dirty_log_start (&s->vga); } static void pci_vmsvga_map_fifo(PCIDevice *pci_dev, int region_num,
Signature · 1 line
1.6.5.2
PATCH 4/6 Fix VMware VGA depth computation
From: Anthony Liguori <[email protected]>
VMware VGA requires that the depth presented to the guest is the same as the DisplaySurface that it renders to. This is because it performs a very simple memcpy() to blit from one surface to another.
We currently hardcode a 24-bit depth. The surface allocator for SDL may, and usually will, allocate a surface with a different depth causing screen corruption.
This changes the code to allocate the DisplaySurface before initializing the device which allows the depth of the DisplaySurface to be used instead of hardcoding something.
--- hw/vmware_vga.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
hw/vmware_vga.c +7 -7
@@ -915,8 +915,8 @@ static void vmsvga_reset(struct vmsvga_state_s *s) s->width =-1 ; s->height =-1 ; s->svgaid =SVGA_ID ; - s->depth =24 ; - s->bypp = (s->depth +7 ) >>3 ; + s->depth =ds_get_bits_per_pixel (s->vga.ds); + s->bypp =ds_get_bytes_per_pixel (s->vga.ds); s->cursor.on =0 ; s->redraw_fifo_first =0 ; s->redraw_fifo_last =0 ;
@@ -1114,6 +1114,11 @@ static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size) s->scratch_size =SVGA_SCRATCH_SIZE ; s->scratch =qemu_malloc (s->scratch_size *4 ); + s->vga.ds =graphic_console_init (vmsvga_update_display, + vmsvga_invalidate_display, + vmsvga_screen_dump, + vmsvga_text_update, s); +vmsvga_reset (s); s->fifo_size =SVGA_FIFO_SIZE ;
@@ -1124,11 +1129,6 @@ static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size)vga_init (&s->vga);vmstate_register (0 , &vmstate_vga_common, &s->vga); - s->vga.ds =graphic_console_init (vmsvga_update_display, - vmsvga_invalidate_display, - vmsvga_screen_dump, - vmsvga_text_update, s); -vga_init_vbe (&s->vga);rom_add_vga (VGABIOS_FILENAME ); }
Signature · 1 line
1.6.5.2
PATCH 5/6 VMware VGA: Only enable dirty log tracking when fifo is disabled
From: Anthony Liguori <[email protected]>
This patch enables dirty log tracking whenever it's needed and disables it when it is not.
We unconditionally enable dirty log tracking on reset, restart dirty log tracking when PCI IO regions are remapped, and disable/enable it based on commands from the guest.
--- hw/vga.c | 22 ++++++++++++++++++++++ hw/vga_int.h | 2 ++ hw/vmware_vga.c | 16 ++++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-)
hw/vga.c +22 -0
@@ -1606,7 +1606,29 @@ void vga_dirty_log_start(VGACommonState *s) kvm_log_start(VBE_DISPI_LFB_PHYSICAL_ADDRESS, s->vram_size); }#endif +} + +void vga_dirty_log_stop (VGACommonState *s) +{ +if (kvm_enabled () && s->map_addr) +kvm_log_stop (s->map_addr, s->map_end - s->map_addr); + +if (kvm_enabled () && s->lfb_vram_mapped) { +kvm_log_stop (isa_mem_base +0xa0000 ,0x80000 ); +kvm_log_stop (isa_mem_base +0xa8000 ,0x80000 ); + } +#ifdef CONFIG_BOCHS_VBE +if (kvm_enabled () && s->vbe_mapped) { +kvm_log_stop (VBE_DISPI_LFB_PHYSICAL_ADDRESS , s->vram_size); + } +#endif +} + +void vga_dirty_log_restart (VGACommonState *s) +{ +vga_dirty_log_stop (s); +vga_dirty_log_start (s); }/*
hw/vga_int.h +2 -0
@@ -194,6 +194,8 @@ void vga_init(VGACommonState *s);void vga_common_reset (VGACommonState *s);void vga_dirty_log_start (VGACommonState *s); +void vga_dirty_log_stop (VGACommonState *s); +void vga_dirty_log_restart (VGACommonState *s);extern const VMStateDescription vmstate_vga_common;uint32_t vga_ioport_read (void *opaque,uint32_t addr);
hw/vmware_vga.c +12 -4
@@ -771,8 +771,12 @@ static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value) s->height =-1 ; s->invalidated =1 ; s->vga.invalidate (&s->vga); -if (s->enable) - s->fb_size = ((s->depth +7 ) >>3 ) * s->new_width * s->new_height; +if (s->enable) { + s->fb_size = ((s->depth +7 ) >>3 ) * s->new_width * s->new_height; +vga_dirty_log_stop (&s->vga); + }else { +vga_dirty_log_start (&s->vga); + }break ;case SVGA_REG_WIDTH :
@@ -948,6 +952,8 @@ static void vmsvga_reset(struct vmsvga_state_s *s)break ; } s->syncing =0 ; + +vga_dirty_log_start (&s->vga); }static void vmsvga_invalidate_display (void *opaque)
@@ -1119,7 +1125,6 @@ static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size) vmsvga_screen_dump, vmsvga_text_update, s); -vmsvga_reset (s); s->fifo_size =SVGA_FIFO_SIZE ; s->fifo_offset =qemu_ram_alloc (s->fifo_size);
@@ -1130,7 +1135,10 @@ static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size)vmstate_register (0 , &vmstate_vga_common, &s->vga);vga_init_vbe (&s->vga); +rom_add_vga (VGABIOS_FILENAME ); + +vmsvga_reset (s); } static void pci_vmsvga_map_ioport(PCIDevice *pci_dev, int region_num,
@@ -1172,7 +1180,7 @@ static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num, s->vga.map_addr = addr; s->vga.map_end = addr + s->vga.vram_size; -vga_dirty_log_start (&s->vga); +vga_dirty_log_restart (&s->vga); } static void pci_vmsvga_map_fifo(PCIDevice *pci_dev, int region_num,
Signature · 1 line
1.6.5.2
PATCH 6/6 vmware: increase cursor buffer size.
From: Dave Airlie <[email protected]>
The cursor pixmap size we calculate later ends up being 4096 dwords long by the looks of it. This boots an F12 LiveCD now.
--- hw/vmware_vga.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/vmware_vga.c +1 -1
@@ -467,7 +467,7 @@ struct vmsvga_cursor_definition_s {int hot_x;int hot_y;uint32_t mask[1024 ]; -uint32_t image[1024 ]; +uint32_t image[4096 ]; };#define SVGA_BITMAP_SIZE (w, h) ((((w) + 31) >> 5) * (h))
Signature · 1 line
1.6.5.2