qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/4] exec: extract cpu_physical_memory_map_internal
Date: Tue,  3 May 2011 18:49:31 +0200	[thread overview]
Message-ID: <1304441374-27314-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1304441374-27314-1-git-send-email-pbonzini@redhat.com>

This function performs all the work on the fast path, and returns
enough information for the slow path to pick up the work.  This
will be used later by other functions that only do the fast path.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 exec.c |   77 ++++++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/exec.c b/exec.c
index a718d74..9b2c9e4 100644
--- a/exec.c
+++ b/exec.c
@@ -3898,16 +3898,9 @@ static void cpu_notify_map_clients(void)
     }
 }
 
-/* Map a physical memory region into a host virtual address.
- * May map a subset of the requested range, given by and returned in *plen.
- * May return NULL if resources needed to perform the mapping are exhausted.
- * Use only for reads OR writes - not for read-modify-write operations.
- * Use cpu_register_map_client() to know when retrying the map operation is
- * likely to succeed.
- */
-void *cpu_physical_memory_map(target_phys_addr_t addr,
-                              target_phys_addr_t *plen,
-                              int is_write)
+static void *cpu_physical_memory_map_internal(target_phys_addr_t addr,
+                                              target_phys_addr_t *plen,
+                                              uintptr_t *pd)
 {
     target_phys_addr_t len = *plen;
     target_phys_addr_t done = 0;
@@ -3915,7 +3908,6 @@ void *cpu_physical_memory_map(target_phys_addr_t addr,
     uint8_t *ret = NULL;
     uint8_t *ptr;
     target_phys_addr_t page;
-    unsigned long pd;
     PhysPageDesc *p;
     unsigned long addr1;
 
@@ -3926,26 +3918,16 @@ void *cpu_physical_memory_map(target_phys_addr_t addr,
             l = len;
         p = phys_page_find(page >> TARGET_PAGE_BITS);
         if (!p) {
-            pd = IO_MEM_UNASSIGNED;
-        } else {
-            pd = p->phys_offset;
+            *pd = IO_MEM_UNASSIGNED;
+            break;
         }
 
-        if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
-            if (done || bounce.buffer) {
-                break;
-            }
-            bounce.buffer = qemu_memalign(TARGET_PAGE_SIZE, TARGET_PAGE_SIZE);
-            bounce.addr = addr;
-            bounce.len = l;
-            if (!is_write) {
-                cpu_physical_memory_read(addr, bounce.buffer, l);
-            }
-            ptr = bounce.buffer;
-        } else {
-            addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
-            ptr = qemu_get_ram_ptr(addr1);
+        *pd = p->phys_offset;
+        if ((*pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
+            break;
         }
+        addr1 = (*pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
+        ptr = qemu_get_ram_ptr(addr1);
         if (!done) {
             ret = ptr;
         } else if (ret + done != ptr) {
@@ -3960,6 +3942,45 @@ void *cpu_physical_memory_map(target_phys_addr_t addr,
     return ret;
 }
 
+/* Map a physical memory region into a host virtual address.
+ * May map a subset of the requested range, given by and returned in *plen.
+ * May return NULL if resources needed to perform the mapping are exhausted.
+ * Use only for reads OR writes - not for read-modify-write operations.
+ * Use cpu_register_map_client() to know when retrying the map operation is
+ * likely to succeed.
+ */
+void *cpu_physical_memory_map(target_phys_addr_t addr,
+                              target_phys_addr_t *plen,
+                              int is_write)
+{
+    target_phys_addr_t page;
+    uintptr_t pd = IO_MEM_UNASSIGNED;
+    void *ret;
+    ret = cpu_physical_memory_map_internal(addr, plen, &pd);
+    if (ret) {
+        return ret;
+    }
+
+    assert((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM);
+    if (pd == IO_MEM_UNASSIGNED) {
+        return NULL;
+    }
+    if (bounce.buffer) {
+        return NULL;
+    }
+
+    /* Read at most a page into the temporary buffer.  */
+    page = addr & TARGET_PAGE_MASK;
+    bounce.buffer = qemu_memalign(TARGET_PAGE_SIZE, TARGET_PAGE_SIZE);
+    bounce.addr = addr;
+    bounce.len = MIN(page + TARGET_PAGE_SIZE - addr, *plen);
+    if (!is_write) {
+        cpu_physical_memory_read(addr, bounce.buffer, bounce.len);
+    }
+    *plen = bounce.len;
+    return bounce.buffer;
+}
+
 /* Unmaps a memory region previously mapped by cpu_physical_memory_map().
  * Will also mark the memory as dirty if is_write == 1.  access_len gives
  * the amount of memory that was actually read or written by the caller.
-- 
1.7.4.4

  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 ` Paolo Bonzini [this message]
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 ` [Qemu-devel] [PATCH 4/4] milkymist: " Paolo Bonzini
2011-05-04 21:56   ` 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-2-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --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).