qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Michael Walle <michael@walle.cc>
Subject: [Qemu-devel] [PATCH 4/4] milkymist: use cpu_physical_memory_map_fast
Date: Tue,  3 May 2011 18:49:34 +0200	[thread overview]
Message-ID: <1304441374-27314-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1304441374-27314-1-git-send-email-pbonzini@redhat.com>

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 <michael@walle.cc>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
        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

  parent reply	other threads:[~2011-05-03 16:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-03 16:49 [Qemu-devel] [PATCH 0/4] introduce cpu_physical_memory_map_fast Paolo Bonzini
2011-05-03 16:49 ` [Qemu-devel] [PATCH 1/4] exec: extract cpu_physical_memory_map_internal Paolo Bonzini
2011-05-03 16:49 ` [Qemu-devel] [PATCH 2/4] exec: introduce cpu_physical_memory_map_fast and cpu_physical_memory_map_check Paolo Bonzini
2011-05-03 16:49 ` [Qemu-devel] [PATCH 3/4] virtio: use cpu_physical_memory_map_fast Paolo Bonzini
2011-05-03 16:49 ` Paolo Bonzini [this message]
2011-05-04 21:56   ` [Qemu-devel] [PATCH 4/4] milkymist: " Michael Walle
2011-05-12 14:51 ` [Qemu-devel] [PATCH 0/4] introduce cpu_physical_memory_map_fast Paolo Bonzini
2011-05-31  9:16   ` Paolo Bonzini
2011-06-06 12:27     ` Paolo Bonzini
2011-06-06 12:56       ` Anthony Liguori
2011-06-06 13:09         ` Paolo Bonzini
2011-06-06 15:44           ` Anthony Liguori
2011-06-06 15:55             ` Paolo Bonzini
2011-05-12 15:32 ` Avi Kivity
2011-05-13  6:33   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1304441374-27314-5-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=michael@walle.cc \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).