Skip to contentSkip to conversation

ioemu: stdvga improvements

PATCH New Stefano Stabellini 1 participant 1 message Jan 13, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ioemu: stdvga improvements

This patch is the "stdvga improvements" patch to qemu-xen-unstable with the due changes for the new videoram allocation system.

hw/cirrus_vga.c +19 -63
index 2af2cc9..d6a9235 100644
@@ -291,8 +291,6 @@ typedef struct CirrusVGAState {
     int last_hw_cursor_y_end;
     int real_vram_size; /* XXX: suppress that */
     CPUWriteMemoryFunc **cirrus_linear_write;
-    uint32_t map_addr;
-    uint32_t map_end;
 } CirrusVGAState;
 
 typedef struct PCICirrusVGAState {
@@ -2642,52 +2640,9 @@ static CPUWriteMemoryFunc *cirrus_linear_bitblt_write[3] = {
 };
 
 
-static void set_vram_mapping(CirrusVGAState *s, unsigned long begin, unsigned long end)
-{
-    unsigned long i;
-    struct xen_add_to_physmap xatp;
-    int rc;
-
-    if (end > begin + VGA_RAM_SIZE)
-        end = begin + VGA_RAM_SIZE;
-
-    fprintf(logfile,"mapping vram to %lx - %lx\n", begin, end);
-
-    xatp.domid = domid;
-    xatp.space = XENMAPSPACE_gmfn;
-
-    for (i = 0; i < (end - begin) >> TARGET_PAGE_BITS; i++) {
-        xatp.idx = (s->vram_gmfn >> TARGET_PAGE_BITS) + i;
-        xatp.gpfn = (begin >> TARGET_PAGE_BITS) + i;
-        rc = xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp);
-        if (rc) {
-            fprintf(stderr, "add_to_physmap MFN %"PRI_xen_pfn" to PFN %"PRI_xen_pfn" failed: %d\n", xatp.idx, xatp.gpfn, rc);
-            return;
-        }
-    }
-
-    (void)xc_domain_pin_memory_cacheattr(
-        xc_handle, domid,
-        begin >> TARGET_PAGE_BITS,
-        end >> TARGET_PAGE_BITS,
-        XEN_DOMCTL_MEM_CACHEATTR_WB);
-
-    s->vram_gmfn = begin;
-}
-
-static void unset_vram_mapping(CirrusVGAState *s, unsigned long begin, unsigned long end)
-{
-    if (s->vram_gmfn) {
-        /* We can put it there for xend to save it efficiently */
-        set_vram_mapping(s, 0xff000000, 0xff000000 + VGA_RAM_SIZE);
-    }
-}
-
 void cirrus_restart_acc(CirrusVGAState *s)
 {
     set_vram_mapping(s, s->lfb_addr, s->lfb_end);
-    s->map_addr = s->lfb_addr;
-    s->map_end = s->lfb_end;
 }
 
 /* Compute the memory access functions */
@@ -2708,19 +2663,16 @@ static void cirrus_update_memory_access(CirrusVGAState *s)
 
 	mode = s->gr[0x05] & 0x7;
 	if (mode < 4 || mode > 5 || ((s->gr[0x0B] & 0x4) == 0)) {
-            if (s->lfb_addr && s->lfb_end && !s->map_addr) {
+            if (s->lfb_addr && s->lfb_end && s->vram_gmfn != s->lfb_addr) {
                 set_vram_mapping(s, s->lfb_addr, s->lfb_end);
-                s->map_addr = s->lfb_addr;
-                s->map_end = s->lfb_end;
             }
             s->cirrus_linear_write[0] = cirrus_linear_mem_writeb;
             s->cirrus_linear_write[1] = cirrus_linear_mem_writew;
             s->cirrus_linear_write[2] = cirrus_linear_mem_writel;
         } else {
         generic_io:
-            if (s->lfb_addr && s->lfb_end && s->map_addr) {
-                unset_vram_mapping(s, s->map_addr, s->map_end);
-                s->map_addr = s->map_end = 0;
+            if (s->lfb_addr && s->lfb_end && s->vram_gmfn != s->lfb_addr) {
+                unset_vram_mapping(s);
             }
             s->cirrus_linear_write[0] = cirrus_linear_writeb;
             s->cirrus_linear_write[1] = cirrus_linear_writew;
@@ -3135,7 +3087,7 @@ static void cirrus_vga_save(QEMUFile *f, void *opaque)
     /* XXX: we do not save the bitblt state - we assume we do not save
        the state when the blitter is active */
 
-    vga_acc = (!!s->map_addr);
+    vga_acc = (s->lfb_addr == s->vram_gmfn);
     qemu_put_8s(f, &vga_acc);
     /* XXX old versions saved rubbish here, keeping for compatibility */
     qemu_put_be32(f, 0xffffffff);
@@ -3146,7 +3098,7 @@ static void cirrus_vga_save(QEMUFile *f, void *opaque)
     qemu_put_be64s(f, &s->vram_gmfn);
     if (!s->vram_gmfn && !vga_acc)
         /* Old guest: VRAM is not mapped, we have to save it ourselves */
-        qemu_put_buffer(f, s->vram_ptr, VGA_RAM_SIZE);
+        qemu_put_buffer(f, s->vram_ptr, s->vram_size);
 }
 
 static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
@@ -3214,15 +3166,11 @@ static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
         /* Old guest, VRAM is not mapped, we have to restore it
          * ourselves */
         s->vram_gmfn = vga_acc ? s->lfb_addr : 0xff000000;
-        xen_vga_populate_vram(s->vram_gmfn);
+        xen_vga_populate_vram(s->vram_gmfn, s->vram_size);
     }
-    xen_vga_vram_map(s->vram_gmfn);
+    xen_vga_vram_map(s->vram_gmfn, s->vram_size);
     if (version_id < 3 || (!vga_acc && !t))
-        qemu_get_buffer(f, s->vram_ptr, VGA_RAM_SIZE);
-    if (vga_acc) {
-        s->map_addr = s->lfb_addr;
-        s->map_end = s->lfb_end;
-    }
+        qemu_get_buffer(f, s->vram_ptr, s->vram_size);
 
     /* force refresh */
     s->graphic_mode = -1;
@@ -3355,6 +3303,11 @@ void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
 
     s = qemu_mallocz(sizeof(CirrusVGAState));
 
+    if (vga_ram_size != 4*1024*1024) {
+        fprintf(stderr, "The -videoram option does not work with the cirrus vga model. Video ram set to 4M. \n");
+        vga_ram_size = 4*1024*1024;
+    }
+
     vga_common_init((VGAState *)s,
                     ds, vga_ram_base, vga_ram_offset, vga_ram_size);
     cirrus_init_common(s, CIRRUS_ID_CLGD5430, 0);
@@ -3376,10 +3329,9 @@ static void cirrus_pci_lfb_map(PCIDevice *d, int region_num,
     cpu_register_physical_memory(addr, s->vram_size,
 				 s->cirrus_linear_io_addr);
     s->lfb_addr = addr;
-    s->lfb_end = addr + VGA_RAM_SIZE;
+    s->lfb_end = addr + s->vram_size;
 
-    if (s->map_addr && (s->lfb_addr != s->map_addr) &&
-        (s->lfb_end != s->map_end))
+    if (s->lfb_addr != s->vram_gmfn)
         fprintf(logfile, "cirrus vga map change while on lfb mode\n");
 
     cpu_register_physical_memory(addr + 0x1000000, 0x400000,
@@ -3425,6 +3377,10 @@ void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
 
     /* setup VGA */
     s = &d->cirrus_vga;
+    if (vga_ram_size != 4*1024*1024) {
+        fprintf(stderr, "The -videoram option does not work with the cirrus vga model. Video ram set to 4M. \n");
+        vga_ram_size = 4*1024*1024;
+    }
     vga_common_init((VGAState *)s,
                     ds, vga_ram_base, vga_ram_offset, vga_ram_size);
     cirrus_init_common(s, device_id, 1);
hw/mips_mipssim.c +1 -1
index bd5266a..4c636db 100644
@@ -194,7 +194,7 @@ QEMUMachine mips_mipssim_machine = {
     .name = "mipssim",
     .desc = "MIPS MIPSsim platform",
     .init = mips_mipssim_init,
-    .ram_require = BIOS_SIZE + VGA_RAM_SIZE /* unused */,
+    .ram_require = BIOS_SIZE /* unused */,
     .nodisk_ok = 1,
     .max_cpus = 1,
 };
hw/mips_r4k.c +1 -1
index 399f452..670a1ea 100644
@@ -285,7 +285,7 @@ QEMUMachine mips_machine = {
     .name = "mips",
     .desc = "mips r4k platform",
     .init = mips_r4k_init,
-    .ram_require = VGA_RAM_SIZE + BIOS_SIZE,
+    .ram_require = BIOS_SIZE,
     .nodisk_ok = 1,
     .max_cpus = 1,
 };
hw/pc.c +2 -2
index a31e4ba..f0492c8 100644
@@ -1186,7 +1186,7 @@ QEMUMachine pc_machine = {
     .name = "pc",
     .desc = "Standard PC",
     .init = pc_init_pci,
-    .ram_require = VGA_RAM_SIZE + PC_MAX_BIOS_SIZE,
+    .ram_require = PC_MAX_BIOS_SIZE,
     .max_cpus = 255,
 };
 
@@ -1194,7 +1194,7 @@ QEMUMachine isapc_machine = {
     .name = "isapc",
     .desc = "ISA-only PC",
     .init = pc_init_isa,
-    .ram_require = VGA_RAM_SIZE + PC_MAX_BIOS_SIZE,
+    .ram_require = PC_MAX_BIOS_SIZE,
     .max_cpus = 1,
 };
 
hw/pc.h +0 -6
index 455306d..a600000 100644
@@ -119,12 +119,6 @@ enum vga_retrace_method {
 
 extern enum vga_retrace_method vga_retrace_method;
 
-#ifndef TARGET_SPARC
-#define VGA_RAM_SIZE (8192 * 1024)
-#else
-#define VGA_RAM_SIZE (9 * 1024 * 1024)
-#endif
-
 int isa_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
                  unsigned long vga_ram_offset, int vga_ram_size);
 int pci_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
hw/ppc_chrp.c +1 -1
index ede2924..da2a0fa 100644
@@ -334,6 +334,6 @@ QEMUMachine core99_machine = {
     .name = "mac99",
     .desc = "Mac99 based PowerMAC",
     .init = ppc_core99_init,
-    .ram_require = BIOS_SIZE + VGA_RAM_SIZE,
+    .ram_require = BIOS_SIZE,
     .max_cpus = 1,
 };
hw/ppc_oldworld.c +1 -1
index 75faeb3..510dd6e 100644
@@ -369,6 +369,6 @@ QEMUMachine heathrow_machine = {
     .name = "g3bw",
     .desc = "Heathrow based PowerMAC",
     .init = ppc_heathrow_init,
-    .ram_require = BIOS_SIZE + VGA_RAM_SIZE,
+    .ram_require = BIOS_SIZE,
     .max_cpus = 1,
 };
hw/ppc_prep.c +1 -1
index 944935d..1e5b3b0 100644
@@ -761,6 +761,6 @@ QEMUMachine prep_machine = {
     .name = "prep",
     .desc = "PowerPC PREP platform",
     .init = ppc_prep_init,
-    .ram_require = BIOS_SIZE + VGA_RAM_SIZE,
+    .ram_require = BIOS_SIZE,
     .max_cpus = 1,
 };
hw/sun4u.c +3 -3
index a70ad20..216629f 100644
@@ -587,7 +587,7 @@ QEMUMachine sun4u_machine = {
     .name = "sun4u",
     .desc = "Sun4u platform",
     .init = sun4u_init,
-    .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE,
+    .ram_require = PROM_SIZE_MAX,
     .nodisk_ok = 1,
     .max_cpus = 16,
 };
@@ -596,7 +596,7 @@ QEMUMachine sun4v_machine = {
     .name = "sun4v",
     .desc = "Sun4v platform",
     .init = sun4v_init,
-    .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE,
+    .ram_require = PROM_SIZE_MAX,
     .nodisk_ok = 1,
     .max_cpus = 16,
 };
@@ -605,7 +605,7 @@ QEMUMachine niagara_machine = {
     .name = "Niagara",
     .desc = "Sun4v platform, Niagara",
     .init = niagara_init,
-    .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE,
+    .ram_require = PROM_SIZE_MAX,
     .nodisk_ok = 1,
     .max_cpus = 16,
 };
hw/vga.c +89 -10

189 lines not on this page · raw message

hw/vga_int.h +35 -32

73 lines not on this page · raw message

hw/xen_machine_fv.c +1 -1
index b85388e..976e7e7 100644
@@ -288,7 +288,7 @@ QEMUMachine xenfv_machine = {
     "xenfv",
     "Xen Fully-virtualized PC",
     xen_init_fv,
-    (VGA_RAM_SIZE + BIOS_SIZE) | RAMSIZE_FIXED,
+    BIOS_SIZE | RAMSIZE_FIXED,
     .max_cpus = 1,
 };
 
hw/xen_machine_pv.c +1 -1
index 9c4e33d..2255247 100644
@@ -77,7 +77,7 @@ QEMUMachine xenpv_machine = {
     "xenpv",
     "Xen Para-virtualized PC",
     xen_init_pv,
-    (VGA_RAM_SIZE + BIOS_SIZE) | RAMSIZE_FIXED,
+    BIOS_SIZE | RAMSIZE_FIXED,
     .max_cpus = 1,
 };
 
qemu-xen.h +5 -2
index 120d5d7..ed6a31e 100644
@@ -3,6 +3,7 @@
 
 /* vl.c */
 extern int restore;
+extern int vga_ram_size;
 
 /* xen_machine_fv.c */
 
@@ -24,8 +25,10 @@ void timeoffset_get(void);
 /* xen_platform.c */
 #ifndef QEMU_TOOL
 void pci_xen_platform_init(PCIBus *bus);
-void xen_vga_populate_vram(uint64_t vram_addr);
-void xen_vga_vram_map(uint64_t vram_addr);
+void xen_vga_populate_vram(uint64_t vram_addr, uint32_t size);
+void xen_vga_vram_map(uint64_t vram_addr, uint32_t size);
+void set_vram_mapping(void *opaque, unsigned long begin, unsigned long end);
+void unset_vram_mapping(void *opaque);
 #endif
 
 void ide_unplug_harddisks(void);
vl.c +24 -3
index e60a9cb..a2ad37d 100644
@@ -190,7 +190,6 @@ DriveInfo drives_table[MAX_DRIVES+1];
 int nb_drives;
 /* point to the block driver where the snapshots are managed */
 static BlockDriverState *bs_snapshots;
-static int vga_ram_size;
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
 static DisplayState display_state;
 int nographic;
@@ -205,7 +204,9 @@ static int rtc_utc = 1;
 static int rtc_date_offset = -1; /* -1 means no change */
 int cirrus_vga_enabled = 1;
 int vmsvga_enabled = 0;
+int vga_ram_size = 4 * 1024 * 1024;
 #ifdef TARGET_SPARC
+vga_ram_size += 1024 * 1024;
 int graphic_width = 1024;
 int graphic_height = 768;
 int graphic_depth = 8;
@@ -8455,6 +8456,7 @@ static void help(int exitcode)
 #ifdef TARGET_I386
            "-std-vga        simulate a standard VGA card with VESA Bochs Extensions\n"
            "                (default is CL-GD5446 PCI VGA)\n"
+           "-videoram       set amount of memory available to virtual video adapter\n"
            "-no-acpi        disable ACPI\n"
 #endif
 #ifdef CONFIG_CURSES
@@ -8549,6 +8551,7 @@ enum {
     QEMU_OPTION_g,
     QEMU_OPTION_vga,
     QEMU_OPTION_std_vga,
+    QEMU_OPTION_videoram,
     QEMU_OPTION_echr,
     QEMU_OPTION_monitor,
     QEMU_OPTION_domainname,
@@ -8661,6 +8664,7 @@ static const QEMUOption qemu_options[] = {
 #endif
     { "localtime", 0, QEMU_OPTION_localtime },
     { "std-vga", 0, QEMU_OPTION_std_vga },
+    { "videoram", HAS_ARG, QEMU_OPTION_videoram },
     { "vga", HAS_ARG, QEMU_OPTION_vga },
     { "echr", HAS_ARG, QEMU_OPTION_echr },
     { "monitor", HAS_ARG, QEMU_OPTION_monitor },
@@ -9080,7 +9084,6 @@ int main(int argc, char **argv)
     cpu_model = NULL;
     initrd_filename = NULL;
     ram_size = 0;
-    vga_ram_size = VGA_RAM_SIZE;
 #ifdef CONFIG_GDBSTUB
     use_gdbstub = 0;
     gdbstub_port = DEFAULT_GDBSTUB_PORT;
@@ -9447,6 +9450,16 @@ int main(int argc, char **argv)
             case QEMU_OPTION_vga:
                 select_vgahw (optarg);
                 break;
+            case QEMU_OPTION_videoram:
+                {
+                    char *ptr;
+                    vga_ram_size = strtol(optarg,&ptr,10);
+                    vga_ram_size *= 1024 * 1024;
+#ifdef TARGET_SPARC
+                    vga_ram_size += (1024 * 1024);
+#endif
+                }
+                break;
             case QEMU_OPTION_g:
                 {
                     const char *p;
@@ -9872,7 +9885,15 @@ int main(int argc, char **argv)
 #endif
 
     /* init the memory */
-    phys_ram_size = machine->ram_require & ~RAMSIZE_FIXED;
+
+    /* If we're on cirrus, set vga_ram_size to 4M whatever the videoram option might have set it to */
+    if ( cirrus_vga_enabled && vga_ram_size != 4 * 1024 * 1024 )
+    {
+       fprintf(stderr,"-videoram option does not work with cirrus vga device model. Videoram set to 4M.\n");
+       vga_ram_size = 4 * 1024 * 1024;
+    }
+
+    phys_ram_size = (machine->ram_require + vga_ram_size) & ~RAMSIZE_FIXED;
 
     if (machine->ram_require & RAMSIZE_FIXED) {
         if (ram_size > 0) {
xenfbfront.c +7 -5
index 3a67ada..69fa494 100644
@@ -24,6 +24,8 @@ static char *kbd_path, *fb_path;
 
 static unsigned char linux2scancode[KEY_MAX + 1];
 
+extern uint32_t vga_ram_size;
+
 int xenfb_connect_vkbd(const char *path)
 {
     kbd_path = strdup(path);
@@ -74,7 +76,7 @@ static void xenfb_pv_resize_shared(DisplayState *ds, int w, int h, int depth, in
         fbfront_resize(fb_dev, ds->width, ds->height, ds->linesize, ds->depth, offset);
     } else {
         ds->data = xs->nonshared_vram;
-        fbfront_resize(fb_dev, w, h, linesize, ds->depth, VGA_RAM_SIZE);
+        fbfront_resize(fb_dev, w, h, linesize, ds->depth, vga_ram_size);
     }
 }
 
@@ -248,8 +250,8 @@ int xenfb_pv_display_init(DisplayState *ds)
 
     create_thread("kbdfront", kbdfront_thread, (void*) xs);
 
-    ds->data = xs->nonshared_vram = qemu_memalign(PAGE_SIZE, VGA_RAM_SIZE);
-    memset(ds->data, 0, VGA_RAM_SIZE);
+    ds->data = xs->nonshared_vram = qemu_memalign(PAGE_SIZE, vga_ram_size);
+    memset(ds->data, 0, vga_ram_size);
     ds->opaque = xs;
     ds->depth = 32;
     ds->bgr = 0;
@@ -271,7 +273,7 @@ int xenfb_pv_display_start(void *data)
     int kbd_fd, fb_fd;
     int offset = 0;
     unsigned long *mfns;
-    int n = VGA_RAM_SIZE / PAGE_SIZE;
+    int n = vga_ram_size / PAGE_SIZE;
     int i;
 
     if (!fb_path || !kbd_path)
@@ -296,7 +298,7 @@ int xenfb_pv_display_start(void *data)
     if (ds->shared_buf) {
         offset = (void*) ds->data - xs->vga_vram;
     } else {
-        offset = VGA_RAM_SIZE;
+        offset = vga_ram_size;
         ds->data = xs->nonshared_vram;
     }
     if (offset)