Skip to contentSkip to conversation

ioemu: populate guest videoram

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ioemu: populate guest videoram

This patch applies to qemu-xen-unstable and implements the new way of populating the videoram in the guest and mapping it in qemu. Initially the videoram is populated at the address 0xff000000 in the guest memory address space.

hw/cirrus_vga.c +25 -53
index 8c0c1ff..2af2cc9 100644
@@ -2653,14 +2653,11 @@ static void set_vram_mapping(CirrusVGAState *s, unsigned long begin, unsigned lo
 
     fprintf(logfile,"mapping vram to %lx - %lx\n", begin, end);
 
-    if (!s->vram_mfns)
-        return;
-
     xatp.domid = domid;
-    xatp.space = XENMAPSPACE_mfn;
+    xatp.space = XENMAPSPACE_gmfn;
 
     for (i = 0; i < (end - begin) >> TARGET_PAGE_BITS; i++) {
-        xatp.idx = s->vram_mfns[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) {
@@ -2674,34 +2671,15 @@ static void set_vram_mapping(CirrusVGAState *s, unsigned long begin, unsigned lo
         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->stolen_vram_addr) {
+    if (s->vram_gmfn) {
         /* We can put it there for xend to save it efficiently */
-        set_vram_mapping(s, s->stolen_vram_addr, s->stolen_vram_addr + VGA_RAM_SIZE);
-    } else {
-        /* Old image, we have to unmap them completely */
-        struct xen_remove_from_physmap xrfp;
-        unsigned long i;
-        int rc;
-
-        if (end > begin + VGA_RAM_SIZE)
-            end = begin + VGA_RAM_SIZE;
-
-        fprintf(logfile,"unmapping vram from %lx - %lx\n", begin, end);
-
-        xrfp.domid = domid;
-
-        for (i = 0; i < (end - begin) >> TARGET_PAGE_BITS; i++) {
-            xrfp.gpfn = (begin >> TARGET_PAGE_BITS) + i;
-            rc = xc_memory_op(xc_handle, XENMEM_remove_from_physmap, &xrfp);
-            if (rc) {
-                fprintf(stderr, "remove_from_physmap PFN %"PRI_xen_pfn" failed: %d\n", xrfp.gpfn, rc);
-                return;
-            }
-        }
+        set_vram_mapping(s, 0xff000000, 0xff000000 + VGA_RAM_SIZE);
     }
 }
 
@@ -3165,8 +3143,8 @@ static void cirrus_vga_save(QEMUFile *f, void *opaque)
     /* XXX old versions saved rubbish here, keeping for compatibility */
     qemu_put_be32(f, 0xffffffff);
     qemu_put_be32(f, s->lfb_end);
-    qemu_put_be64s(f, &s->stolen_vram_addr);
-    if (!s->stolen_vram_addr && !vga_acc)
+    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);
 }
@@ -3175,6 +3153,7 @@ static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
 {
     CirrusVGAState *s = opaque;
     uint8_t vga_acc = 0;
+    uint64_t t;
     int ret;
 
     if (version_id > 3)
@@ -3227,25 +3206,22 @@ static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
     /* XXX throwing away 32 bits */
     qemu_get_be32(f);
     qemu_get_be32s(f, &s->lfb_end);
-    if (version_id >= 3) {
-        qemu_get_be64s(f, &s->stolen_vram_addr);
-        if (!s->stolen_vram_addr && !vga_acc) {
-            /* Old guest, VRAM is not mapped, we have to restore it ourselves */
-            qemu_get_buffer(f, s->vram_ptr, VGA_RAM_SIZE);
-            xen_vga_populate_vram(s->lfb_addr);
-        } else
-            xen_vga_vram_map(vga_acc ? s->lfb_addr : s->stolen_vram_addr, 0);
-
-        if (vga_acc) {
-            s->map_addr = s->lfb_addr;
-            s->map_end = s->lfb_end;
-        }
-    } else {
-        /* Old image, we have to populate and restore VRAM ourselves */
-        xen_vga_populate_vram(s->lfb_addr);
-        qemu_get_buffer(f, s->vram_ptr, VGA_RAM_SIZE); 
-        if (vga_acc)
-            cirrus_restart_acc(s);
+
+    if (version_id >= 3)
+        qemu_get_be64s(f, &s->vram_gmfn);
+    t = s->vram_gmfn;
+    if (!s->vram_gmfn) {
+        /* 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_vram_map(s->vram_gmfn);
+    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;
     }
 
     /* force refresh */
@@ -3335,10 +3311,6 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci)
     }
     s->cr[0x27] = device_id;
 
-    /* Win2K seems to assume that the pattern buffer is at 0xff
-       initially ! */
-    memset(s->vram_ptr, 0xff, s->real_vram_size);
-
     s->cirrus_hidden_dac_lockindex = 5;
     s->cirrus_hidden_dac_data = 0;
 
hw/vga.c +20 -57

129 lines not on this page · raw message

hw/vga_int.h +1 -2
index 8e4ec93..bd147e5 100644
@@ -100,8 +100,7 @@ typedef void (* vga_update_retrace_info_fn)(struct VGAState *s);
 
 #define VGA_STATE_COMMON                                                \
     uint8_t *vram_ptr;                                                  \
-    xen_pfn_t *vram_mfns;                                               \
-    uint64_t stolen_vram_addr; /* Address of stolen RAM */              \
+    uint64_t vram_gmfn;                                                 \
     unsigned long vram_offset;                                          \
     unsigned int vram_size;                                             \
     unsigned long bios_offset;                                          \
hw/xen_platform.c +3 -39

74 lines not on this page · raw message

qemu-xen.h +4 -2
index 44467a3..120d5d7 100644
@@ -1,6 +1,9 @@
 #ifndef QEMU_XEN_H
 #define QEMU_XEN_H
 
+/* vl.c */
+extern int restore;
+
 /* xen_machine_fv.c */
 
 #if (defined(__i386__) || defined(__x86_64__)) && !defined(QEMU_TOOL)
@@ -21,9 +24,8 @@ void timeoffset_get(void);
 /* xen_platform.c */
 #ifndef QEMU_TOOL
 void pci_xen_platform_init(PCIBus *bus);
-void xen_vga_stolen_vram_addr(uint64_t vram_addr);
 void xen_vga_populate_vram(uint64_t vram_addr);
-void xen_vga_vram_map(uint64_t vram_addr, int copy);
+void xen_vga_vram_map(uint64_t vram_addr);
 #endif
 
 void ide_unplug_harddisks(void);
vl.c +2 -0
index 9945b27..e60a9cb 100644
@@ -178,6 +178,7 @@
 /* Max number of PCI emulation */
 #define MAX_PCI_EMULATION 32
 
+int restore;
 const char *bios_dir = CONFIG_QEMU_SHAREDIR;
 const char *bios_name = NULL;
 static void *ioport_opaque[MAX_IOPORTS];
@@ -9509,6 +9510,7 @@ int main(int argc, char **argv)
                 break;
 	    case QEMU_OPTION_loadvm:
 		loadvm = optarg;
+                restore = 1;
 		break;
             case QEMU_OPTION_full_screen:
                 full_screen = 1;