958e1b
From 2e02d49769291dda0436ec3d113c5b4917037f3f Mon Sep 17 00:00:00 2001
91048c
From: Gerd Hoffmann <kraxel@redhat.com>
91048c
Date: Mon, 15 Sep 2014 13:08:20 +0200
958e1b
Subject: [PATCH 1/4] vbe: make bochs dispi interface return the correct memory size with qxl
91048c
91048c
Message-id: <1410786503-19794-2-git-send-email-kraxel@redhat.com>
91048c
Patchwork-id: 61135
91048c
O-Subject: [RHEL-7.1 qemu-kvm PATCH 1/4] vbe: make bochs dispi interface return the correct memory size with qxl
958e1b
Bugzilla: 1139118
91048c
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
91048c
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
91048c
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
91048c
91048c
VgaState->vram_size is the size of the pci bar.  In case of qxl not the
91048c
whole pci bar can be used as vga framebuffer.  Add a new variable
91048c
vbe_size to handle that case.  By default (if unset) it equals
91048c
vram_size, but qxl can set vbe_size to something else.
91048c
91048c
This makes sure VBE_DISPI_INDEX_VIDEO_MEMORY_64K returns correct results
91048c
and sanity checks are done with the correct size too.
91048c
91048c
Cc: qemu-stable@nongnu.org
91048c
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
91048c
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
91048c
(cherry picked from commit 54a85d462447c1cb8a1638578a7fd086350b4d2d)
91048c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
91048c
---
91048c
 hw/display/qxl.c     |    1 +
91048c
 hw/display/vga.c     |    7 +++++--
91048c
 hw/display/vga_int.h |    1 +
91048c
 3 files changed, 7 insertions(+), 2 deletions(-)
91048c
91048c
diff --git a/hw/display/qxl.c b/hw/display/qxl.c
958e1b
index 6f8adc8..f11210c 100644
91048c
--- a/hw/display/qxl.c
91048c
+++ b/hw/display/qxl.c
958e1b
@@ -2056,6 +2056,7 @@ static int qxl_init_primary(PCIDevice *dev)
91048c
 
91048c
     qxl->id = 0;
91048c
     qxl_init_ramsize(qxl);
91048c
+    vga->vbe_size = qxl->vgamem_size;
91048c
     vga->vram_size_mb = qxl->vga.vram_size >> 20;
91048c
     vga_common_init(vga);
91048c
     vga_init(vga, pci_address_space(dev), pci_address_space_io(dev), false);
91048c
diff --git a/hw/display/vga.c b/hw/display/vga.c
91048c
index 21a108d..d703d90 100644
91048c
--- a/hw/display/vga.c
91048c
+++ b/hw/display/vga.c
91048c
@@ -613,7 +613,7 @@ uint32_t vbe_ioport_read_data(void *opaque, uint32_t addr)
91048c
             val = s->vbe_regs[s->vbe_index];
91048c
         }
91048c
     } else if (s->vbe_index == VBE_DISPI_INDEX_VIDEO_MEMORY_64K) {
91048c
-        val = s->vram_size / (64 * 1024);
91048c
+        val = s->vbe_size / (64 * 1024);
91048c
     } else {
91048c
         val = 0;
91048c
     }
91048c
@@ -752,7 +752,7 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
91048c
                     line_offset = w >> 1;
91048c
                 else
91048c
                     line_offset = w * ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3);
91048c
-                h = s->vram_size / line_offset;
91048c
+                h = s->vbe_size / line_offset;
91048c
                 /* XXX: support weird bochs semantics ? */
91048c
                 if (h < s->vbe_regs[VBE_DISPI_INDEX_YRES])
91048c
                     return;
91048c
@@ -2290,6 +2290,9 @@ void vga_common_init(VGACommonState *s)
91048c
         s->vram_size <<= 1;
91048c
     }
91048c
     s->vram_size_mb = s->vram_size >> 20;
91048c
+    if (!s->vbe_size) {
91048c
+        s->vbe_size = s->vram_size;
91048c
+    }
91048c
 
91048c
     s->is_vbe_vmstate = 1;
91048c
     memory_region_init_ram(&s->vram, "vga.vram", s->vram_size);
91048c
diff --git a/hw/display/vga_int.h b/hw/display/vga_int.h
91048c
index 66f9f3c..5a2f466 100644
91048c
--- a/hw/display/vga_int.h
91048c
+++ b/hw/display/vga_int.h
91048c
@@ -93,6 +93,7 @@ typedef struct VGACommonState {
91048c
     MemoryRegion vram_vbe;
91048c
     uint32_t vram_size;
91048c
     uint32_t vram_size_mb; /* property */
91048c
+    uint32_t vbe_size;
91048c
     uint32_t latch;
91048c
     MemoryRegion *chain4_alias;
91048c
     uint8_t sr_index;
91048c
-- 
91048c
1.7.1
91048c