[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 03/25] exec: introduce address_space_extend_translati
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 03/25] exec: introduce address_space_extend_translation |
Date: |
Thu, 22 Dec 2016 16:22:38 +0100 |
This extracts the common part of address_space_map and
address_space_cache_init into a new function.
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
exec.c | 50 +++++++++++++++++++++++++++++---------------------
1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/exec.c b/exec.c
index 8568a6f..d4b3656 100644
--- a/exec.c
+++ b/exec.c
@@ -2938,6 +2938,31 @@ bool address_space_access_valid(AddressSpace *as, hwaddr
addr, int len, bool is_
return true;
}
+static hwaddr
+address_space_extend_translation(AddressSpace *as, hwaddr addr, hwaddr
target_len,
+ MemoryRegion *mr, hwaddr base, hwaddr len,
+ bool is_write)
+{
+ hwaddr done = 0;
+ hwaddr xlat;
+ MemoryRegion *this_mr;
+
+ for (;;) {
+ target_len -= len;
+ addr += len;
+ done += len;
+ if (target_len == 0) {
+ return done;
+ }
+
+ len = target_len;
+ this_mr = address_space_translate(as, addr, &xlat, &len, is_write);
+ if (this_mr != mr || xlat != base + done) {
+ return done;
+ }
+ }
+}
+
/* 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.
@@ -2951,9 +2976,8 @@ void *address_space_map(AddressSpace *as,
bool is_write)
{
hwaddr len = *plen;
- hwaddr done = 0;
- hwaddr l, xlat, base;
- MemoryRegion *mr, *this_mr;
+ hwaddr l, xlat;
+ MemoryRegion *mr;
void *ptr;
if (len == 0) {
@@ -2987,26 +3011,10 @@ void *address_space_map(AddressSpace *as,
return bounce.buffer;
}
- base = xlat;
-
- for (;;) {
- len -= l;
- addr += l;
- done += l;
- if (len == 0) {
- break;
- }
-
- l = len;
- this_mr = address_space_translate(as, addr, &xlat, &l, is_write);
- if (this_mr != mr || xlat != base + done) {
- break;
- }
- }
memory_region_ref(mr);
- *plen = done;
- ptr = qemu_ram_ptr_length(mr->ram_block, base, plen);
+ *plen = address_space_extend_translation(as, addr, len, mr, xlat, l,
is_write);
+ ptr = qemu_ram_ptr_length(mr->ram_block, xlat, plen);
rcu_read_unlock();
return ptr;
--
2.9.3
- [Qemu-devel] [PULL 00/25] First round of misc patches for QEMU 2.9, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 01/25] exec: optimize remaining address_space_* cases, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 04/25] exec: introduce MemoryRegionCache, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 02/25] exec: introduce memory_ldst.inc.c, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 03/25] exec: introduce address_space_extend_translation,
Paolo Bonzini <=
- [Qemu-devel] [PULL 05/25] watchdog: 6300esb: add exit function, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 07/25] rules.mak: add more rules to avoid chaining, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 08/25] build-sys: remove libtool left-over, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 06/25] rules.mak: speedup save-vars load-vars, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 09/25] virtio-scsi: introduce virtio_scsi_acquire/release, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 10/25] qemu-timer: check active_timers outside lock/event, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 11/25] timer: fix misleading comment in timer.h, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 12/25] main-loop: update comment for qemu_mutex_lock/unlock_iothread, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 13/25] block: drop remaining legacy aio functions in comment, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 15/25] pc: make smbus configurable, Paolo Bonzini, 2016/12/22