qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/4] milkymist: use cpu_physical_memory_map_fast


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH 4/4] milkymist: use cpu_physical_memory_map_fast
Date: Tue, 3 May 2011 18:49:34 +0200

This patch adds proper unmapping of the memory when the addresses
cross multiple memory blocks, and it also uses a single map_fast
operation for the RMW access to the destination frame buffer.

Cc: Michael Walle <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
        Compile-tested only.

 hw/milkymist-tmu2.c |   39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/hw/milkymist-tmu2.c b/hw/milkymist-tmu2.c
index 9cebe31..575fa41 100644
--- a/hw/milkymist-tmu2.c
+++ b/hw/milkymist-tmu2.c
@@ -181,9 +181,9 @@ static void tmu2_start(MilkymistTMU2State *s)
     GLXPbuffer pbuffer;
     GLuint texture;
     void *fb;
-    target_phys_addr_t fb_len;
+    target_phys_addr_t fb_len, fb_len_full;
     void *mesh;
-    target_phys_addr_t mesh_len;
+    target_phys_addr_t mesh_len, mesh_len_full;
     float m;
 
     trace_milkymist_tmu2_start();
@@ -205,8 +205,12 @@ static void tmu2_start(MilkymistTMU2State *s)
     /* Read the QEMU source framebuffer into an OpenGL texture */
     glGenTextures(1, &texture);
     glBindTexture(GL_TEXTURE_2D, texture);
-    fb_len = 2*s->regs[R_TEXHRES]*s->regs[R_TEXVRES];
-    fb = cpu_physical_memory_map(s->regs[R_TEXFBUF], &fb_len, 0);
+    fb_len_full = fb_len = 2*s->regs[R_TEXHRES]*s->regs[R_TEXVRES];
+    fb = cpu_physical_memory_map_fast(s->regs[R_TEXFBUF], &fb_len);
+    if (fb_len < fb_len_full) {
+        cpu_physical_memory_unmap(fb, fb_len, 0, 0);
+        fb = NULL;
+    }
     if (fb == NULL) {
         glDeleteTextures(1, &texture);
         glXMakeContextCurrent(s->dpy, None, None, NULL);
@@ -249,8 +253,12 @@ static void tmu2_start(MilkymistTMU2State *s)
     glColor4f(m, m, m, (float)(s->regs[R_ALPHA] + 1) / 64.0f);
 
     /* Read the QEMU dest. framebuffer into the OpenGL framebuffer */
-    fb_len = 2 * s->regs[R_DSTHRES] * s->regs[R_DSTVRES];
-    fb = cpu_physical_memory_map(s->regs[R_DSTFBUF], &fb_len, 0);
+    fb_len_full = fb_len = 2 * s->regs[R_DSTHRES] * s->regs[R_DSTVRES];
+    fb = cpu_physical_memory_map_fast(s->regs[R_DSTFBUF], &fb_len);
+    if (fb_len < fb_len_full) {
+        cpu_physical_memory_unmap(fb, fb_len, 0, 0);
+        fb = NULL;
+    }
     if (fb == NULL) {
         glDeleteTextures(1, &texture);
         glXMakeContextCurrent(s->dpy, None, None, NULL);
@@ -260,7 +268,6 @@ static void tmu2_start(MilkymistTMU2State *s)
 
     glDrawPixels(s->regs[R_DSTHRES], s->regs[R_DSTVRES], GL_RGB,
             GL_UNSIGNED_SHORT_5_6_5, fb);
-    cpu_physical_memory_unmap(fb, fb_len, 0, fb_len);
     glViewport(0, 0, s->regs[R_DSTHRES], s->regs[R_DSTVRES]);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
@@ -268,9 +275,14 @@ static void tmu2_start(MilkymistTMU2State *s)
     glMatrixMode(GL_MODELVIEW);
 
     /* Map the texture */
-    mesh_len = MESH_MAXSIZE*MESH_MAXSIZE*sizeof(struct vertex);
-    mesh = cpu_physical_memory_map(s->regs[R_VERTICESADDR], &mesh_len, 0);
+    mesh_len_full = mesh_len = MESH_MAXSIZE*MESH_MAXSIZE*sizeof(struct vertex);
+    mesh = cpu_physical_memory_map_fast(s->regs[R_VERTICESADDR], &mesh_len);
+    if (mesh_len < mesh_len_full) {
+        cpu_physical_memory_unmap(mesh, mesh_len, 0, 0);
+        mesh = NULL;
+    }
     if (mesh == NULL) {
+        cpu_physical_memory_unmap(fb, fb_len, 0, fb_len);
         glDeleteTextures(1, &texture);
         glXMakeContextCurrent(s->dpy, None, None, NULL);
         glXDestroyPbuffer(s->dpy, pbuffer);
@@ -285,15 +297,6 @@ static void tmu2_start(MilkymistTMU2State *s)
     cpu_physical_memory_unmap(mesh, mesh_len, 0, mesh_len);
 
     /* Write back the OpenGL framebuffer to the QEMU framebuffer */
-    fb_len = 2 * s->regs[R_DSTHRES] * s->regs[R_DSTVRES];
-    fb = cpu_physical_memory_map(s->regs[R_DSTFBUF], &fb_len, 1);
-    if (fb == NULL) {
-        glDeleteTextures(1, &texture);
-        glXMakeContextCurrent(s->dpy, None, None, NULL);
-        glXDestroyPbuffer(s->dpy, pbuffer);
-        return;
-    }
-
     glReadPixels(0, 0, s->regs[R_DSTHRES], s->regs[R_DSTVRES], GL_RGB,
             GL_UNSIGNED_SHORT_5_6_5, fb);
     cpu_physical_memory_unmap(fb, fb_len, 1, fb_len);
-- 
1.7.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]