34b321
From 445ec835479fd06142078a59f1a88f2b30708930 Mon Sep 17 00:00:00 2001
e96cb2
From: Gerd Hoffmann <kraxel@redhat.com>
34b321
Date: Thu, 28 Apr 2016 16:07:30 +0200
34b321
Subject: [PATCH 25/27] vga: factor out vga register setup
e96cb2
e96cb2
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
34b321
Message-id: <1461859652-20918-5-git-send-email-kraxel@redhat.com>
34b321
Patchwork-id: 70295
34b321
O-Subject: [virt-devel] [RHEL-7.3 qemu-kvm PATCH 4/6] vga: factor out vga register setup
34b321
Bugzilla: 1331413
e96cb2
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
e96cb2
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
e96cb2
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
e96cb2
e96cb2
When enabling vbe mode qemu will setup a bunch of vga registers to make
e96cb2
sure the vga emulation operates in correct mode for a linear
e96cb2
framebuffer.  Move that code to a separate function so we can call it
e96cb2
from other places too.
e96cb2
e96cb2
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
e96cb2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
e96cb2
---
e96cb2
 hw/display/vga.c | 78 ++++++++++++++++++++++++++++++++------------------------
e96cb2
 1 file changed, 44 insertions(+), 34 deletions(-)
e96cb2
e96cb2
diff --git a/hw/display/vga.c b/hw/display/vga.c
e96cb2
index b694a26..4cc0df5 100644
e96cb2
--- a/hw/display/vga.c
e96cb2
+++ b/hw/display/vga.c
e96cb2
@@ -671,6 +671,49 @@ static void vbe_fixup_regs(VGACommonState *s)
e96cb2
     s->vbe_start_addr  = offset / 4;
e96cb2
 }
e96cb2
 
e96cb2
+/* we initialize the VGA graphic mode */
e96cb2
+static void vbe_update_vgaregs(VGACommonState *s)
e96cb2
+{
e96cb2
+    int h, shift_control;
e96cb2
+
e96cb2
+    if (!vbe_enabled(s)) {
e96cb2
+        /* vbe is turned off -- nothing to do */
e96cb2
+        return;
e96cb2
+    }
e96cb2
+
e96cb2
+    /* graphic mode + memory map 1 */
e96cb2
+    s->gr[VGA_GFX_MISC] = (s->gr[VGA_GFX_MISC] & ~0x0c) | 0x04 |
e96cb2
+        VGA_GR06_GRAPHICS_MODE;
e96cb2
+    s->cr[VGA_CRTC_MODE] |= 3; /* no CGA modes */
e96cb2
+    s->cr[VGA_CRTC_OFFSET] = s->vbe_line_offset >> 3;
e96cb2
+    /* width */
e96cb2
+    s->cr[VGA_CRTC_H_DISP] =
e96cb2
+        (s->vbe_regs[VBE_DISPI_INDEX_XRES] >> 3) - 1;
e96cb2
+    /* height (only meaningful if < 1024) */
e96cb2
+    h = s->vbe_regs[VBE_DISPI_INDEX_YRES] - 1;
e96cb2
+    s->cr[VGA_CRTC_V_DISP_END] = h;
e96cb2
+    s->cr[VGA_CRTC_OVERFLOW] = (s->cr[VGA_CRTC_OVERFLOW] & ~0x42) |
e96cb2
+        ((h >> 7) & 0x02) | ((h >> 3) & 0x40);
e96cb2
+    /* line compare to 1023 */
e96cb2
+    s->cr[VGA_CRTC_LINE_COMPARE] = 0xff;
e96cb2
+    s->cr[VGA_CRTC_OVERFLOW] |= 0x10;
e96cb2
+    s->cr[VGA_CRTC_MAX_SCAN] |= 0x40;
e96cb2
+
e96cb2
+    if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4) {
e96cb2
+        shift_control = 0;
e96cb2
+        s->sr[VGA_SEQ_CLOCK_MODE] &= ~8; /* no double line */
e96cb2
+    } else {
e96cb2
+        shift_control = 2;
e96cb2
+        /* set chain 4 mode */
e96cb2
+        s->sr[VGA_SEQ_MEMORY_MODE] |= VGA_SR04_CHN_4M;
e96cb2
+        /* activate all planes */
e96cb2
+        s->sr[VGA_SEQ_PLANE_WRITE] |= VGA_SR02_ALL_PLANES;
e96cb2
+    }
e96cb2
+    s->gr[VGA_GFX_MODE] = (s->gr[VGA_GFX_MODE] & ~0x60) |
e96cb2
+        (shift_control << 5);
e96cb2
+    s->cr[VGA_CRTC_MAX_SCAN] &= ~0x9f; /* no double scan */
e96cb2
+}
e96cb2
+
e96cb2
 static uint32_t vbe_ioport_read_index(void *opaque, uint32_t addr)
e96cb2
 {
e96cb2
     VGACommonState *s = opaque;
e96cb2
@@ -757,52 +800,19 @@ void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val)
e96cb2
         case VBE_DISPI_INDEX_ENABLE:
e96cb2
             if ((val & VBE_DISPI_ENABLED) &&
e96cb2
                 !(s->vbe_regs[VBE_DISPI_INDEX_ENABLE] & VBE_DISPI_ENABLED)) {
e96cb2
-                int h, shift_control;
e96cb2
 
e96cb2
                 s->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] = 0;
e96cb2
                 s->vbe_regs[VBE_DISPI_INDEX_X_OFFSET] = 0;
e96cb2
                 s->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET] = 0;
e96cb2
                 s->vbe_regs[VBE_DISPI_INDEX_ENABLE] |= VBE_DISPI_ENABLED;
e96cb2
                 vbe_fixup_regs(s);
e96cb2
+                vbe_update_vgaregs(s);
e96cb2
 
e96cb2
                 /* clear the screen */
e96cb2
                 if (!(val & VBE_DISPI_NOCLEARMEM)) {
e96cb2
                     memset(s->vram_ptr, 0,
e96cb2
                            s->vbe_regs[VBE_DISPI_INDEX_YRES] * s->vbe_line_offset);
e96cb2
                 }
e96cb2
-
e96cb2
-                /* we initialize the VGA graphic mode */
e96cb2
-                /* graphic mode + memory map 1 */
e96cb2
-                s->gr[VGA_GFX_MISC] = (s->gr[VGA_GFX_MISC] & ~0x0c) | 0x04 |
e96cb2
-                    VGA_GR06_GRAPHICS_MODE;
e96cb2
-                s->cr[VGA_CRTC_MODE] |= 3; /* no CGA modes */
e96cb2
-                s->cr[VGA_CRTC_OFFSET] = s->vbe_line_offset >> 3;
e96cb2
-                /* width */
e96cb2
-                s->cr[VGA_CRTC_H_DISP] =
e96cb2
-                    (s->vbe_regs[VBE_DISPI_INDEX_XRES] >> 3) - 1;
e96cb2
-                 /* height (only meaningful if < 1024) */
e96cb2
-                h = s->vbe_regs[VBE_DISPI_INDEX_YRES] - 1;
e96cb2
-                s->cr[VGA_CRTC_V_DISP_END] = h;
e96cb2
-                s->cr[VGA_CRTC_OVERFLOW] = (s->cr[VGA_CRTC_OVERFLOW] & ~0x42) |
e96cb2
-                    ((h >> 7) & 0x02) | ((h >> 3) & 0x40);
e96cb2
-                /* line compare to 1023 */
e96cb2
-                s->cr[VGA_CRTC_LINE_COMPARE] = 0xff;
e96cb2
-                s->cr[VGA_CRTC_OVERFLOW] |= 0x10;
e96cb2
-                s->cr[VGA_CRTC_MAX_SCAN] |= 0x40;
e96cb2
-
e96cb2
-                if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4) {
e96cb2
-                    shift_control = 0;
e96cb2
-                    s->sr[VGA_SEQ_CLOCK_MODE] &= ~8; /* no double line */
e96cb2
-                } else {
e96cb2
-                    shift_control = 2;
e96cb2
-                    /* set chain 4 mode */
e96cb2
-                    s->sr[VGA_SEQ_MEMORY_MODE] |= VGA_SR04_CHN_4M;
e96cb2
-                    /* activate all planes */
e96cb2
-                    s->sr[VGA_SEQ_PLANE_WRITE] |= VGA_SR02_ALL_PLANES;
e96cb2
-                }
e96cb2
-                s->gr[VGA_GFX_MODE] = (s->gr[VGA_GFX_MODE] & ~0x60) |
e96cb2
-                    (shift_control << 5);
e96cb2
-                s->cr[VGA_CRTC_MAX_SCAN] &= ~0x9f; /* no double scan */
e96cb2
             } else {
e96cb2
                 s->bank_offset = 0;
e96cb2
             }
e96cb2
-- 
e96cb2
1.8.3.1
e96cb2