|
|
7711c0 |
From c879b300ff1852e5102a787372cd949f6755f5ce Mon Sep 17 00:00:00 2001
|
|
|
7711c0 |
From: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Date: Fri, 25 Jan 2019 22:50:04 +0100
|
|
|
7711c0 |
Subject: [PATCH 04/23] exec: reintroduce MemoryRegion caching
|
|
|
7711c0 |
|
|
|
7711c0 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Message-id: <20190125225007.8197-5-jsnow@redhat.com>
|
|
|
7711c0 |
Patchwork-id: 84120
|
|
|
7711c0 |
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH v2 4/7] exec: reintroduce MemoryRegion caching
|
|
|
7711c0 |
Bugzilla: 1597482
|
|
|
7711c0 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Peter Xu <peterx@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
MemoryRegionCache was reverted to "normal" address_space_* operations
|
|
|
7711c0 |
for 2.9, due to lack of support for IOMMUs. Reinstate the
|
|
|
7711c0 |
optimizations, caching only the IOMMU translation at address_cache_init
|
|
|
7711c0 |
but not the IOMMU lookup and target AddressSpace translation are not
|
|
|
7711c0 |
cached; now that MemoryRegionCache supports IOMMUs, it becomes more widely
|
|
|
7711c0 |
applicable too.
|
|
|
7711c0 |
|
|
|
7711c0 |
The inlined fast path is defined in memory_ldst_cached.inc.h, while the
|
|
|
7711c0 |
slow path uses memory_ldst.inc.c as before. The smaller fast path causes
|
|
|
7711c0 |
a little code size reduction in MemoryRegionCache users:
|
|
|
7711c0 |
|
|
|
7711c0 |
hw/virtio/virtio.o text size before: 32373
|
|
|
7711c0 |
hw/virtio/virtio.o text size after: 31941
|
|
|
7711c0 |
|
|
|
7711c0 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
7711c0 |
(cherry picked from commit 48564041a73adbbff52834f9edbe3806fceefab7)
|
|
|
7711c0 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
---
|
|
|
7711c0 |
exec.c | 121 ++++++++++++++++++++++++++++++----
|
|
|
7711c0 |
include/exec/cpu-all.h | 6 +-
|
|
|
7711c0 |
include/exec/memory-internal.h | 3 +
|
|
|
7711c0 |
include/exec/memory.h | 58 ++++++++++++++--
|
|
|
7711c0 |
include/exec/memory_ldst_cached.inc.h | 108 ++++++++++++++++++++++++++++++
|
|
|
7711c0 |
memory.c | 4 +-
|
|
|
7711c0 |
6 files changed, 280 insertions(+), 20 deletions(-)
|
|
|
7711c0 |
create mode 100644 include/exec/memory_ldst_cached.inc.h
|
|
|
7711c0 |
|
|
|
7711c0 |
diff --git a/exec.c b/exec.c
|
|
|
7711c0 |
index 1bd0e6c..805a2d4 100644
|
|
|
7711c0 |
--- a/exec.c
|
|
|
7711c0 |
+++ b/exec.c
|
|
|
7711c0 |
@@ -3656,33 +3656,130 @@ int64_t address_space_cache_init(MemoryRegionCache *cache,
|
|
|
7711c0 |
hwaddr len,
|
|
|
7711c0 |
bool is_write)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
- cache->len = len;
|
|
|
7711c0 |
- cache->as = as;
|
|
|
7711c0 |
- cache->xlat = addr;
|
|
|
7711c0 |
- return len;
|
|
|
7711c0 |
+ AddressSpaceDispatch *d;
|
|
|
7711c0 |
+ hwaddr l;
|
|
|
7711c0 |
+ MemoryRegion *mr;
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ assert(len > 0);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ l = len;
|
|
|
7711c0 |
+ cache->fv = address_space_get_flatview(as);
|
|
|
7711c0 |
+ d = flatview_to_dispatch(cache->fv);
|
|
|
7711c0 |
+ cache->mrs = *address_space_translate_internal(d, addr, &cache->xlat, &l, true);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ mr = cache->mrs.mr;
|
|
|
7711c0 |
+ memory_region_ref(mr);
|
|
|
7711c0 |
+ if (memory_access_is_direct(mr, is_write)) {
|
|
|
7711c0 |
+ l = flatview_extend_translation(cache->fv, addr, len, mr,
|
|
|
7711c0 |
+ cache->xlat, l, is_write);
|
|
|
7711c0 |
+ cache->ptr = qemu_ram_ptr_length(mr->ram_block, cache->xlat, &l, true);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ cache->ptr = NULL;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ cache->len = l;
|
|
|
7711c0 |
+ cache->is_write = is_write;
|
|
|
7711c0 |
+ return l;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
void address_space_cache_invalidate(MemoryRegionCache *cache,
|
|
|
7711c0 |
hwaddr addr,
|
|
|
7711c0 |
hwaddr access_len)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
+ assert(cache->is_write);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ invalidate_and_set_dirty(cache->mrs.mr, addr + cache->xlat, access_len);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
void address_space_cache_destroy(MemoryRegionCache *cache)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
- cache->as = NULL;
|
|
|
7711c0 |
+ if (!cache->mrs.mr) {
|
|
|
7711c0 |
+ return;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ if (xen_enabled()) {
|
|
|
7711c0 |
+ xen_invalidate_map_cache_entry(cache->ptr);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+ memory_region_unref(cache->mrs.mr);
|
|
|
7711c0 |
+ flatview_unref(cache->fv);
|
|
|
7711c0 |
+ cache->mrs.mr = NULL;
|
|
|
7711c0 |
+ cache->fv = NULL;
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+/* Called from RCU critical section. This function has the same
|
|
|
7711c0 |
+ * semantics as address_space_translate, but it only works on a
|
|
|
7711c0 |
+ * predefined range of a MemoryRegion that was mapped with
|
|
|
7711c0 |
+ * address_space_cache_init.
|
|
|
7711c0 |
+ */
|
|
|
7711c0 |
+static inline MemoryRegion *address_space_translate_cached(
|
|
|
7711c0 |
+ MemoryRegionCache *cache, hwaddr addr, hwaddr *xlat,
|
|
|
7711c0 |
+ hwaddr *plen, bool is_write)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ MemoryRegionSection section;
|
|
|
7711c0 |
+ MemoryRegion *mr;
|
|
|
7711c0 |
+ IOMMUMemoryRegion *iommu_mr;
|
|
|
7711c0 |
+ AddressSpace *target_as;
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ assert(!cache->ptr);
|
|
|
7711c0 |
+ *xlat = addr + cache->xlat;
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ mr = cache->mrs.mr;
|
|
|
7711c0 |
+ iommu_mr = memory_region_get_iommu(mr);
|
|
|
7711c0 |
+ if (!iommu_mr) {
|
|
|
7711c0 |
+ /* MMIO region. */
|
|
|
7711c0 |
+ return mr;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ section = address_space_translate_iommu(iommu_mr, xlat, plen,
|
|
|
7711c0 |
+ NULL, is_write, true,
|
|
|
7711c0 |
+ &target_as);
|
|
|
7711c0 |
+ return section.mr;
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+/* Called from RCU critical section. address_space_read_cached uses this
|
|
|
7711c0 |
+ * out of line function when the target is an MMIO or IOMMU region.
|
|
|
7711c0 |
+ */
|
|
|
7711c0 |
+void
|
|
|
7711c0 |
+address_space_read_cached_slow(MemoryRegionCache *cache, hwaddr addr,
|
|
|
7711c0 |
+ void *buf, int len)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ hwaddr addr1, l;
|
|
|
7711c0 |
+ MemoryRegion *mr;
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ l = len;
|
|
|
7711c0 |
+ mr = address_space_translate_cached(cache, addr, &addr1, &l, false);
|
|
|
7711c0 |
+ flatview_read_continue(cache->fv,
|
|
|
7711c0 |
+ addr, MEMTXATTRS_UNSPECIFIED, buf, len,
|
|
|
7711c0 |
+ addr1, l, mr);
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+/* Called from RCU critical section. address_space_write_cached uses this
|
|
|
7711c0 |
+ * out of line function when the target is an MMIO or IOMMU region.
|
|
|
7711c0 |
+ */
|
|
|
7711c0 |
+void
|
|
|
7711c0 |
+address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr,
|
|
|
7711c0 |
+ const void *buf, int len)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ hwaddr addr1, l;
|
|
|
7711c0 |
+ MemoryRegion *mr;
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ l = len;
|
|
|
7711c0 |
+ mr = address_space_translate_cached(cache, addr, &addr1, &l, true);
|
|
|
7711c0 |
+ flatview_write_continue(cache->fv,
|
|
|
7711c0 |
+ addr, MEMTXATTRS_UNSPECIFIED, buf, len,
|
|
|
7711c0 |
+ addr1, l, mr);
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
#define ARG1_DECL MemoryRegionCache *cache
|
|
|
7711c0 |
#define ARG1 cache
|
|
|
7711c0 |
-#define SUFFIX _cached
|
|
|
7711c0 |
-#define TRANSLATE(addr, ...) \
|
|
|
7711c0 |
- address_space_translate(cache->as, cache->xlat + (addr), __VA_ARGS__)
|
|
|
7711c0 |
-#define IS_DIRECT(mr, is_write) true
|
|
|
7711c0 |
-#define MAP_RAM(mr, ofs) qemu_map_ram_ptr((mr)->ram_block, ofs)
|
|
|
7711c0 |
+#define SUFFIX _cached_slow
|
|
|
7711c0 |
+#define TRANSLATE(...) address_space_translate_cached(cache, __VA_ARGS__)
|
|
|
7711c0 |
+#define IS_DIRECT(mr, is_write) memory_access_is_direct(mr, is_write)
|
|
|
7711c0 |
+#define MAP_RAM(mr, ofs) (cache->ptr + (ofs - cache->xlat))
|
|
|
7711c0 |
#define INVALIDATE(mr, ofs, len) invalidate_and_set_dirty(mr, ofs, len)
|
|
|
7711c0 |
-#define RCU_READ_LOCK() rcu_read_lock()
|
|
|
7711c0 |
-#define RCU_READ_UNLOCK() rcu_read_unlock()
|
|
|
7711c0 |
+#define RCU_READ_LOCK() ((void)0)
|
|
|
7711c0 |
+#define RCU_READ_UNLOCK() ((void)0)
|
|
|
7711c0 |
#include "memory_ldst.inc.c"
|
|
|
7711c0 |
|
|
|
7711c0 |
/* virtual memory access for debug (includes writing to ROM) */
|
|
|
7711c0 |
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
|
|
|
7711c0 |
index 173edd1..a635f53 100644
|
|
|
7711c0 |
--- a/include/exec/cpu-all.h
|
|
|
7711c0 |
+++ b/include/exec/cpu-all.h
|
|
|
7711c0 |
@@ -175,7 +175,7 @@ extern unsigned long reserved_va;
|
|
|
7711c0 |
#define TARGET_ENDIANNESS
|
|
|
7711c0 |
#include "exec/memory_ldst.inc.h"
|
|
|
7711c0 |
|
|
|
7711c0 |
-#define SUFFIX _cached
|
|
|
7711c0 |
+#define SUFFIX _cached_slow
|
|
|
7711c0 |
#define ARG1 cache
|
|
|
7711c0 |
#define ARG1_DECL MemoryRegionCache *cache
|
|
|
7711c0 |
#define TARGET_ENDIANNESS
|
|
|
7711c0 |
@@ -193,6 +193,10 @@ static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val
|
|
|
7711c0 |
#define TARGET_ENDIANNESS
|
|
|
7711c0 |
#include "exec/memory_ldst_phys.inc.h"
|
|
|
7711c0 |
|
|
|
7711c0 |
+/* Inline fast path for direct RAM access. */
|
|
|
7711c0 |
+#define ENDIANNESS
|
|
|
7711c0 |
+#include "exec/memory_ldst_cached.inc.h"
|
|
|
7711c0 |
+
|
|
|
7711c0 |
#define SUFFIX _cached
|
|
|
7711c0 |
#define ARG1 cache
|
|
|
7711c0 |
#define ARG1_DECL MemoryRegionCache *cache
|
|
|
7711c0 |
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
|
|
|
7711c0 |
index 6a5ee42..58399b9 100644
|
|
|
7711c0 |
--- a/include/exec/memory-internal.h
|
|
|
7711c0 |
+++ b/include/exec/memory-internal.h
|
|
|
7711c0 |
@@ -31,6 +31,9 @@ static inline AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as)
|
|
|
7711c0 |
return flatview_to_dispatch(address_space_to_flatview(as));
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
+FlatView *address_space_get_flatview(AddressSpace *as);
|
|
|
7711c0 |
+void flatview_unref(FlatView *view);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
extern const MemoryRegionOps unassigned_mem_ops;
|
|
|
7711c0 |
|
|
|
7711c0 |
bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr,
|
|
|
7711c0 |
diff --git a/include/exec/memory.h b/include/exec/memory.h
|
|
|
7711c0 |
index 84de0d4..96f1fd8 100644
|
|
|
7711c0 |
--- a/include/exec/memory.h
|
|
|
7711c0 |
+++ b/include/exec/memory.h
|
|
|
7711c0 |
@@ -1715,12 +1715,16 @@ MemTxResult address_space_write(AddressSpace *as, hwaddr addr,
|
|
|
7711c0 |
#include "exec/memory_ldst_phys.inc.h"
|
|
|
7711c0 |
|
|
|
7711c0 |
struct MemoryRegionCache {
|
|
|
7711c0 |
+ void *ptr;
|
|
|
7711c0 |
hwaddr xlat;
|
|
|
7711c0 |
hwaddr len;
|
|
|
7711c0 |
- AddressSpace *as;
|
|
|
7711c0 |
+ FlatView *fv;
|
|
|
7711c0 |
+ MemoryRegionSection mrs;
|
|
|
7711c0 |
+ bool is_write;
|
|
|
7711c0 |
};
|
|
|
7711c0 |
|
|
|
7711c0 |
-#define MEMORY_REGION_CACHE_INVALID ((MemoryRegionCache) { .as = NULL })
|
|
|
7711c0 |
+#define MEMORY_REGION_CACHE_INVALID ((MemoryRegionCache) { .mrs.mr = NULL })
|
|
|
7711c0 |
+
|
|
|
7711c0 |
|
|
|
7711c0 |
/* address_space_ld*_cached: load from a cached #MemoryRegion
|
|
|
7711c0 |
* address_space_st*_cached: store into a cached #MemoryRegion
|
|
|
7711c0 |
@@ -1746,11 +1750,40 @@ struct MemoryRegionCache {
|
|
|
7711c0 |
* if NULL, this information is discarded
|
|
|
7711c0 |
*/
|
|
|
7711c0 |
|
|
|
7711c0 |
-#define SUFFIX _cached
|
|
|
7711c0 |
+#define SUFFIX _cached_slow
|
|
|
7711c0 |
#define ARG1 cache
|
|
|
7711c0 |
#define ARG1_DECL MemoryRegionCache *cache
|
|
|
7711c0 |
#include "exec/memory_ldst.inc.h"
|
|
|
7711c0 |
|
|
|
7711c0 |
+/* Inline fast path for direct RAM access. */
|
|
|
7711c0 |
+static inline uint8_t address_space_ldub_cached(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ assert(addr < cache->len);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ return ldub_p(cache->ptr + addr);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ return address_space_ldub_cached_slow(cache, addr, attrs, result);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+static inline void address_space_stb_cached(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ assert(addr < cache->len);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ stb_p(cache->ptr + addr, val);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ address_space_stb_cached_slow(cache, addr, val, attrs, result);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+#define ENDIANNESS _le
|
|
|
7711c0 |
+#include "exec/memory_ldst_cached.inc.h"
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+#define ENDIANNESS _be
|
|
|
7711c0 |
+#include "exec/memory_ldst_cached.inc.h"
|
|
|
7711c0 |
+
|
|
|
7711c0 |
#define SUFFIX _cached
|
|
|
7711c0 |
#define ARG1 cache
|
|
|
7711c0 |
#define ARG1_DECL MemoryRegionCache *cache
|
|
|
7711c0 |
@@ -1887,6 +1920,13 @@ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr,
|
|
|
7711c0 |
MemoryRegion *mr);
|
|
|
7711c0 |
void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr);
|
|
|
7711c0 |
|
|
|
7711c0 |
+/* Internal functions, part of the implementation of address_space_read_cached
|
|
|
7711c0 |
+ * and address_space_write_cached. */
|
|
|
7711c0 |
+void address_space_read_cached_slow(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, void *buf, int len);
|
|
|
7711c0 |
+void address_space_write_cached_slow(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, const void *buf, int len);
|
|
|
7711c0 |
+
|
|
|
7711c0 |
static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
if (is_write) {
|
|
|
7711c0 |
@@ -1955,7 +1995,11 @@ address_space_read_cached(MemoryRegionCache *cache, hwaddr addr,
|
|
|
7711c0 |
void *buf, int len)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
assert(addr < cache->len && len <= cache->len - addr);
|
|
|
7711c0 |
- address_space_read(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIFIED, buf, len);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ memcpy(buf, cache->ptr + addr, len);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ address_space_read_cached_slow(cache, addr, buf, len);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
/**
|
|
|
7711c0 |
@@ -1971,7 +2015,11 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
|
|
|
7711c0 |
void *buf, int len)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
assert(addr < cache->len && len <= cache->len - addr);
|
|
|
7711c0 |
- address_space_write(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIFIED, buf, len);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ memcpy(cache->ptr + addr, buf, len);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ address_space_write_cached_slow(cache, addr, buf, len);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
#endif
|
|
|
7711c0 |
diff --git a/include/exec/memory_ldst_cached.inc.h b/include/exec/memory_ldst_cached.inc.h
|
|
|
7711c0 |
new file mode 100644
|
|
|
7711c0 |
index 0000000..fd4bbb4
|
|
|
7711c0 |
--- /dev/null
|
|
|
7711c0 |
+++ b/include/exec/memory_ldst_cached.inc.h
|
|
|
7711c0 |
@@ -0,0 +1,108 @@
|
|
|
7711c0 |
+/*
|
|
|
7711c0 |
+ * Memory access templates for MemoryRegionCache
|
|
|
7711c0 |
+ *
|
|
|
7711c0 |
+ * Copyright (c) 2018 Red Hat, Inc.
|
|
|
7711c0 |
+ *
|
|
|
7711c0 |
+ * This library is free software; you can redistribute it and/or
|
|
|
7711c0 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
7711c0 |
+ * License as published by the Free Software Foundation; either
|
|
|
7711c0 |
+ * version 2 of the License, or (at your option) any later version.
|
|
|
7711c0 |
+ *
|
|
|
7711c0 |
+ * This library is distributed in the hope that it will be useful,
|
|
|
7711c0 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7711c0 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
7711c0 |
+ * Lesser General Public License for more details.
|
|
|
7711c0 |
+ *
|
|
|
7711c0 |
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
7711c0 |
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
7711c0 |
+ */
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+#define ADDRESS_SPACE_LD_CACHED(size) \
|
|
|
7711c0 |
+ glue(glue(address_space_ld, size), glue(ENDIANNESS, _cached))
|
|
|
7711c0 |
+#define ADDRESS_SPACE_LD_CACHED_SLOW(size) \
|
|
|
7711c0 |
+ glue(glue(address_space_ld, size), glue(ENDIANNESS, _cached_slow))
|
|
|
7711c0 |
+#define LD_P(size) \
|
|
|
7711c0 |
+ glue(glue(ld, size), glue(ENDIANNESS, _p))
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ assert(addr < cache->len && 4 <= cache->len - addr);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ return LD_P(l)(cache->ptr + addr);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ return ADDRESS_SPACE_LD_CACHED_SLOW(l)(cache, addr, attrs, result);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ assert(addr < cache->len && 8 <= cache->len - addr);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ return LD_P(q)(cache->ptr + addr);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ return ADDRESS_SPACE_LD_CACHED_SLOW(q)(cache, addr, attrs, result);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+static inline uint32_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ assert(addr < cache->len && 2 <= cache->len - addr);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ return LD_P(uw)(cache->ptr + addr);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ return ADDRESS_SPACE_LD_CACHED_SLOW(uw)(cache, addr, attrs, result);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+#undef ADDRESS_SPACE_LD_CACHED
|
|
|
7711c0 |
+#undef ADDRESS_SPACE_LD_CACHED_SLOW
|
|
|
7711c0 |
+#undef LD_P
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+#define ADDRESS_SPACE_ST_CACHED(size) \
|
|
|
7711c0 |
+ glue(glue(address_space_st, size), glue(ENDIANNESS, _cached))
|
|
|
7711c0 |
+#define ADDRESS_SPACE_ST_CACHED_SLOW(size) \
|
|
|
7711c0 |
+ glue(glue(address_space_st, size), glue(ENDIANNESS, _cached_slow))
|
|
|
7711c0 |
+#define ST_P(size) \
|
|
|
7711c0 |
+ glue(glue(st, size), glue(ENDIANNESS, _p))
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ assert(addr < cache->len && 4 <= cache->len - addr);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ ST_P(l)(cache->ptr + addr, val);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ ADDRESS_SPACE_ST_CACHED_SLOW(l)(cache, addr, val, attrs, result);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ assert(addr < cache->len && 2 <= cache->len - addr);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ ST_P(w)(cache->ptr + addr, val);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ ADDRESS_SPACE_ST_CACHED_SLOW(w)(cache, addr, val, attrs, result);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache,
|
|
|
7711c0 |
+ hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result)
|
|
|
7711c0 |
+{
|
|
|
7711c0 |
+ assert(addr < cache->len && 8 <= cache->len - addr);
|
|
|
7711c0 |
+ if (likely(cache->ptr)) {
|
|
|
7711c0 |
+ ST_P(q)(cache->ptr + addr, val);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ ADDRESS_SPACE_ST_CACHED_SLOW(q)(cache, addr, val, attrs, result);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+#undef ADDRESS_SPACE_ST_CACHED
|
|
|
7711c0 |
+#undef ADDRESS_SPACE_ST_CACHED_SLOW
|
|
|
7711c0 |
+#undef ST_P
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+#undef ENDIANNESS
|
|
|
7711c0 |
diff --git a/memory.c b/memory.c
|
|
|
7711c0 |
index 4974f97..1e90912 100644
|
|
|
7711c0 |
--- a/memory.c
|
|
|
7711c0 |
+++ b/memory.c
|
|
|
7711c0 |
@@ -298,7 +298,7 @@ static bool flatview_ref(FlatView *view)
|
|
|
7711c0 |
return atomic_fetch_inc_nonzero(&view->ref) > 0;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
-static void flatview_unref(FlatView *view)
|
|
|
7711c0 |
+void flatview_unref(FlatView *view)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
if (atomic_fetch_dec(&view->ref) == 1) {
|
|
|
7711c0 |
trace_flatview_destroy_rcu(view, view->root);
|
|
|
7711c0 |
@@ -822,7 +822,7 @@ static void address_space_add_del_ioeventfds(AddressSpace *as,
|
|
|
7711c0 |
}
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
-static FlatView *address_space_get_flatview(AddressSpace *as)
|
|
|
7711c0 |
+FlatView *address_space_get_flatview(AddressSpace *as)
|
|
|
7711c0 |
{
|
|
|
7711c0 |
FlatView *view;
|
|
|
7711c0 |
|
|
|
7711c0 |
--
|
|
|
7711c0 |
1.8.3.1
|
|
|
7711c0 |
|