|
|
9ae3a8 |
From a2c4efbb5b968a80eb552757308c2fb2f28157c6 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Marcel Apfelbaum <marcel.a@redhat.com>
|
|
|
9ae3a8 |
Date: Sun, 19 Jan 2014 13:07:36 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 11/11] exec: separate sections and nodes per address space
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Marcel Apfelbaum <marcel.a@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1390136856-7024-3-git-send-email-marcel.a@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 56811
|
|
|
9ae3a8 |
O-Subject: [RHEL-7 qemu-kvm PATCH v2 2/2] exec: separate sections and nodes per address space
|
|
|
9ae3a8 |
Bugzilla: 1003535
|
|
|
9ae3a8 |
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Every address space has its own nodes and sections, but
|
|
|
9ae3a8 |
it uses the same global arrays of nodes/section.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This limits the number of devices that can be attached
|
|
|
9ae3a8 |
to the guest to 20-30 devices. It happens because:
|
|
|
9ae3a8 |
- The sections array is limited to 2^12 entries.
|
|
|
9ae3a8 |
- The main memory has at least 100 sections.
|
|
|
9ae3a8 |
- Each device address space is actually an alias to
|
|
|
9ae3a8 |
main memory, multiplying its number of nodes/sections.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Remove the limitation by using separate arrays of
|
|
|
9ae3a8 |
nodes and sections for each address space.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Closest upstream commit: 53cb28cbfea038f8ad50132dc8a684e638c7d48b
|
|
|
9ae3a8 |
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
v1 -> v2:
|
|
|
9ae3a8 |
- The series confilcted with Juan's series:
|
|
|
9ae3a8 |
- [RHEL7 qemu-kvm PATCH 00/40] bitmap optmization
|
|
|
9ae3a8 |
- Conflicts solved:
|
|
|
9ae3a8 |
- AddressSpaceDispatch was moved to exec.c
|
|
|
9ae3a8 |
- PhysPageEntry was moved to exec.c
|
|
|
9ae3a8 |
- Moved also PhysPageMap to exec.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
exec.c | 166 ++++++++++++++++++++++++++++++++++-------------------------------
|
|
|
9ae3a8 |
1 file changed, 86 insertions(+), 80 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
exec.c | 166 +++++++++++++++++++++++++++++++++-------------------------------
|
|
|
9ae3a8 |
1 files changed, 86 insertions(+), 80 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/exec.c b/exec.c
|
|
|
9ae3a8 |
index 01c74cd..ce9310c 100644
|
|
|
9ae3a8 |
--- a/exec.c
|
|
|
9ae3a8 |
+++ b/exec.c
|
|
|
9ae3a8 |
@@ -91,25 +91,32 @@ struct PhysPageEntry {
|
|
|
9ae3a8 |
uint16_t ptr : 15;
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+typedef PhysPageEntry Node[L2_SIZE];
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+typedef struct PhysPageMap {
|
|
|
9ae3a8 |
+ unsigned sections_nb;
|
|
|
9ae3a8 |
+ unsigned sections_nb_alloc;
|
|
|
9ae3a8 |
+ unsigned nodes_nb;
|
|
|
9ae3a8 |
+ unsigned nodes_nb_alloc;
|
|
|
9ae3a8 |
+ Node *nodes;
|
|
|
9ae3a8 |
+ MemoryRegionSection *sections;
|
|
|
9ae3a8 |
+} PhysPageMap;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
struct AddressSpaceDispatch {
|
|
|
9ae3a8 |
/* This is a multi-level map on the physical address space.
|
|
|
9ae3a8 |
* The bottom level has pointers to MemoryRegionSections.
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
PhysPageEntry phys_map;
|
|
|
9ae3a8 |
+ PhysPageMap map;
|
|
|
9ae3a8 |
MemoryListener listener;
|
|
|
9ae3a8 |
+ AddressSpace *as;
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static MemoryRegionSection *phys_sections;
|
|
|
9ae3a8 |
-static unsigned phys_sections_nb, phys_sections_nb_alloc;
|
|
|
9ae3a8 |
#define PHYS_SECTION_UNASSIGNED 0
|
|
|
9ae3a8 |
#define PHYS_SECTION_NOTDIRTY 1
|
|
|
9ae3a8 |
#define PHYS_SECTION_ROM 2
|
|
|
9ae3a8 |
#define PHYS_SECTION_WATCH 3
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-/* Simple allocator for PhysPageEntry nodes */
|
|
|
9ae3a8 |
-static PhysPageEntry (*phys_map_nodes)[L2_SIZE];
|
|
|
9ae3a8 |
-static unsigned phys_map_nodes_nb, phys_map_nodes_nb_alloc;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
#define PHYS_MAP_NODE_NIL (((uint16_t)~0) >> 1)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static void io_mem_init(void);
|
|
|
9ae3a8 |
@@ -121,41 +128,38 @@ static MemoryRegion io_mem_watch;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#if !defined(CONFIG_USER_ONLY)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void phys_map_node_reserve(unsigned nodes)
|
|
|
9ae3a8 |
+static void phys_map_node_reserve(PhysPageMap *map, unsigned nodes)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- if (phys_map_nodes_nb + nodes > phys_map_nodes_nb_alloc) {
|
|
|
9ae3a8 |
- typedef PhysPageEntry Node[L2_SIZE];
|
|
|
9ae3a8 |
- phys_map_nodes_nb_alloc = MAX(phys_map_nodes_nb_alloc * 2, 16);
|
|
|
9ae3a8 |
- phys_map_nodes_nb_alloc = MAX(phys_map_nodes_nb_alloc,
|
|
|
9ae3a8 |
- phys_map_nodes_nb + nodes);
|
|
|
9ae3a8 |
- phys_map_nodes = g_renew(Node, phys_map_nodes,
|
|
|
9ae3a8 |
- phys_map_nodes_nb_alloc);
|
|
|
9ae3a8 |
+ if (map->nodes_nb + nodes > map->nodes_nb_alloc) {
|
|
|
9ae3a8 |
+ map->nodes_nb_alloc = MAX(map->nodes_nb_alloc * 2, 16);
|
|
|
9ae3a8 |
+ map->nodes_nb_alloc = MAX(map->nodes_nb_alloc, map->nodes_nb + nodes);
|
|
|
9ae3a8 |
+ map->nodes = g_renew(Node, map->nodes, map->nodes_nb_alloc);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static uint16_t phys_map_node_alloc(void)
|
|
|
9ae3a8 |
+static uint16_t phys_map_node_alloc(PhysPageMap *map)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
unsigned i;
|
|
|
9ae3a8 |
uint16_t ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- ret = phys_map_nodes_nb++;
|
|
|
9ae3a8 |
+ ret = map->nodes_nb++;
|
|
|
9ae3a8 |
assert(ret != PHYS_MAP_NODE_NIL);
|
|
|
9ae3a8 |
- assert(ret != phys_map_nodes_nb_alloc);
|
|
|
9ae3a8 |
+ assert(ret != map->nodes_nb_alloc);
|
|
|
9ae3a8 |
for (i = 0; i < L2_SIZE; ++i) {
|
|
|
9ae3a8 |
- phys_map_nodes[ret][i].is_leaf = 0;
|
|
|
9ae3a8 |
- phys_map_nodes[ret][i].ptr = PHYS_MAP_NODE_NIL;
|
|
|
9ae3a8 |
+ map->nodes[ret][i].is_leaf = 0;
|
|
|
9ae3a8 |
+ map->nodes[ret][i].ptr = PHYS_MAP_NODE_NIL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void phys_map_nodes_reset(void)
|
|
|
9ae3a8 |
+static void phys_map_nodes_reset(PhysPageMap *map)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- phys_map_nodes_nb = 0;
|
|
|
9ae3a8 |
+ map->nodes_nb = 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void phys_page_set_level(PhysPageEntry *lp, hwaddr *index,
|
|
|
9ae3a8 |
- hwaddr *nb, uint16_t leaf,
|
|
|
9ae3a8 |
+static void phys_page_set_level(PhysPageMap *map, PhysPageEntry *lp,
|
|
|
9ae3a8 |
+ hwaddr *index, hwaddr *nb, uint16_t leaf,
|
|
|
9ae3a8 |
int level)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
PhysPageEntry *p;
|
|
|
9ae3a8 |
@@ -163,8 +167,8 @@ static void phys_page_set_level(PhysPageEntry *lp, hwaddr *index,
|
|
|
9ae3a8 |
hwaddr step = (hwaddr)1 << (level * L2_BITS);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (!lp->is_leaf && lp->ptr == PHYS_MAP_NODE_NIL) {
|
|
|
9ae3a8 |
- lp->ptr = phys_map_node_alloc();
|
|
|
9ae3a8 |
- p = phys_map_nodes[lp->ptr];
|
|
|
9ae3a8 |
+ lp->ptr = phys_map_node_alloc(map);
|
|
|
9ae3a8 |
+ p = map->nodes[lp->ptr];
|
|
|
9ae3a8 |
if (level == 0) {
|
|
|
9ae3a8 |
for (i = 0; i < L2_SIZE; i++) {
|
|
|
9ae3a8 |
p[i].is_leaf = 1;
|
|
|
9ae3a8 |
@@ -172,7 +176,7 @@ static void phys_page_set_level(PhysPageEntry *lp, hwaddr *index,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- p = phys_map_nodes[lp->ptr];
|
|
|
9ae3a8 |
+ p = map->nodes[lp->ptr];
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
lp = &p[(*index >> (level * L2_BITS)) & (L2_SIZE - 1)];
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -183,7 +187,7 @@ static void phys_page_set_level(PhysPageEntry *lp, hwaddr *index,
|
|
|
9ae3a8 |
*index += step;
|
|
|
9ae3a8 |
*nb -= step;
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- phys_page_set_level(lp, index, nb, leaf, level - 1);
|
|
|
9ae3a8 |
+ phys_page_set_level(map, lp, index, nb, leaf, level - 1);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
++lp;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -194,9 +198,10 @@ static void phys_page_set(AddressSpaceDispatch *d,
|
|
|
9ae3a8 |
uint16_t leaf)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
/* Wildly overreserve - it doesn't matter much. */
|
|
|
9ae3a8 |
- phys_map_node_reserve(3 * P_L2_LEVELS);
|
|
|
9ae3a8 |
+ phys_map_node_reserve(&d->map, 3 * P_L2_LEVELS);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- phys_page_set_level(&d->phys_map, &index, &nb, leaf, P_L2_LEVELS - 1);
|
|
|
9ae3a8 |
+ phys_page_set_level(&d->map, &d->phys_map, &index,
|
|
|
9ae3a8 |
+ &nb, leaf, P_L2_LEVELS - 1);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr index)
|
|
|
9ae3a8 |
@@ -210,13 +215,13 @@ MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr index)
|
|
|
9ae3a8 |
if (lp.ptr == PHYS_MAP_NODE_NIL) {
|
|
|
9ae3a8 |
goto not_found;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- p = phys_map_nodes[lp.ptr];
|
|
|
9ae3a8 |
+ p = d->map.nodes[lp.ptr];
|
|
|
9ae3a8 |
lp = p[(index >> (i * L2_BITS)) & (L2_SIZE - 1)];
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
s_index = lp.ptr;
|
|
|
9ae3a8 |
not_found:
|
|
|
9ae3a8 |
- return &phys_sections[s_index];
|
|
|
9ae3a8 |
+ return &d->map.sections[s_index];
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
bool memory_region_is_unassigned(MemoryRegion *mr)
|
|
|
9ae3a8 |
@@ -657,7 +662,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
|
|
|
9ae3a8 |
and avoid full address decoding in every device.
|
|
|
9ae3a8 |
We can't use the high bits of pd for this because
|
|
|
9ae3a8 |
IO_MEM_ROMD uses these as a ram address. */
|
|
|
9ae3a8 |
- iotlb = section - phys_sections;
|
|
|
9ae3a8 |
+ iotlb = section - address_space_memory.dispatch->map.sections;
|
|
|
9ae3a8 |
iotlb += memory_region_section_addr(section, paddr);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -683,13 +688,14 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
|
|
|
9ae3a8 |
#define SUBPAGE_IDX(addr) ((addr) & ~TARGET_PAGE_MASK)
|
|
|
9ae3a8 |
typedef struct subpage_t {
|
|
|
9ae3a8 |
MemoryRegion iomem;
|
|
|
9ae3a8 |
+ AddressSpace *as;
|
|
|
9ae3a8 |
hwaddr base;
|
|
|
9ae3a8 |
uint16_t sub_section[TARGET_PAGE_SIZE];
|
|
|
9ae3a8 |
} subpage_t;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,
|
|
|
9ae3a8 |
uint16_t section);
|
|
|
9ae3a8 |
-static subpage_t *subpage_init(hwaddr base);
|
|
|
9ae3a8 |
+static subpage_t *subpage_init(AddressSpace *as, hwaddr base);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static void *(*phys_mem_alloc)(size_t size) = qemu_anon_ram_alloc;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -703,9 +709,9 @@ void phys_mem_set_alloc(void *(*alloc)(size_t))
|
|
|
9ae3a8 |
phys_mem_alloc = alloc;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void destroy_page_desc(uint16_t section_index)
|
|
|
9ae3a8 |
+static void destroy_page_desc(PhysPageMap *map, uint16_t section_index)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- MemoryRegionSection *section = &phys_sections[section_index];
|
|
|
9ae3a8 |
+ MemoryRegionSection *section = &map->sections[section_index];
|
|
|
9ae3a8 |
MemoryRegion *mr = section->mr;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (mr->subpage) {
|
|
|
9ae3a8 |
@@ -715,7 +721,8 @@ static void destroy_page_desc(uint16_t section_index)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void destroy_l2_mapping(PhysPageEntry *lp, unsigned level)
|
|
|
9ae3a8 |
+static void destroy_l2_mapping(PhysPageMap *map, PhysPageEntry *lp,
|
|
|
9ae3a8 |
+ unsigned level)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
unsigned i;
|
|
|
9ae3a8 |
PhysPageEntry *p;
|
|
|
9ae3a8 |
@@ -724,12 +731,12 @@ static void destroy_l2_mapping(PhysPageEntry *lp, unsigned level)
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- p = phys_map_nodes[lp->ptr];
|
|
|
9ae3a8 |
+ p = map->nodes[lp->ptr];
|
|
|
9ae3a8 |
for (i = 0; i < L2_SIZE; ++i) {
|
|
|
9ae3a8 |
if (!p[i].is_leaf) {
|
|
|
9ae3a8 |
- destroy_l2_mapping(&p[i], level - 1);
|
|
|
9ae3a8 |
+ destroy_l2_mapping(map, &p[i], level - 1);
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- destroy_page_desc(p[i].ptr);
|
|
|
9ae3a8 |
+ destroy_page_desc(map, p[i].ptr);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
lp->is_leaf = 0;
|
|
|
9ae3a8 |
@@ -738,24 +745,25 @@ static void destroy_l2_mapping(PhysPageEntry *lp, unsigned level)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static void destroy_all_mappings(AddressSpaceDispatch *d)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- destroy_l2_mapping(&d->phys_map, P_L2_LEVELS - 1);
|
|
|
9ae3a8 |
- phys_map_nodes_reset();
|
|
|
9ae3a8 |
+ destroy_l2_mapping(&d->map, &d->phys_map, P_L2_LEVELS - 1);
|
|
|
9ae3a8 |
+ phys_map_nodes_reset(&d->map);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static uint16_t phys_section_add(MemoryRegionSection *section)
|
|
|
9ae3a8 |
+static uint16_t phys_section_add(PhysPageMap *map,
|
|
|
9ae3a8 |
+ MemoryRegionSection *section)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- if (phys_sections_nb == phys_sections_nb_alloc) {
|
|
|
9ae3a8 |
- phys_sections_nb_alloc = MAX(phys_sections_nb_alloc * 2, 16);
|
|
|
9ae3a8 |
- phys_sections = g_renew(MemoryRegionSection, phys_sections,
|
|
|
9ae3a8 |
- phys_sections_nb_alloc);
|
|
|
9ae3a8 |
+ if (map->sections_nb == map->sections_nb_alloc) {
|
|
|
9ae3a8 |
+ map->sections_nb_alloc = MAX(map->sections_nb_alloc * 2, 16);
|
|
|
9ae3a8 |
+ map->sections = g_renew(MemoryRegionSection, map->sections,
|
|
|
9ae3a8 |
+ map->sections_nb_alloc);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- phys_sections[phys_sections_nb] = *section;
|
|
|
9ae3a8 |
- return phys_sections_nb++;
|
|
|
9ae3a8 |
+ map->sections[map->sections_nb] = *section;
|
|
|
9ae3a8 |
+ return map->sections_nb++;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void phys_sections_clear(void)
|
|
|
9ae3a8 |
+static void phys_sections_clear(PhysPageMap *map)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- phys_sections_nb = 0;
|
|
|
9ae3a8 |
+ map->sections_nb = 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static void register_subpage(AddressSpaceDispatch *d, MemoryRegionSection *section)
|
|
|
9ae3a8 |
@@ -773,16 +781,16 @@ static void register_subpage(AddressSpaceDispatch *d, MemoryRegionSection *secti
|
|
|
9ae3a8 |
assert(existing->mr->subpage || existing->mr == &io_mem_unassigned);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (!(existing->mr->subpage)) {
|
|
|
9ae3a8 |
- subpage = subpage_init(base);
|
|
|
9ae3a8 |
+ subpage = subpage_init(d->as, base);
|
|
|
9ae3a8 |
subsection.mr = &subpage->iomem;
|
|
|
9ae3a8 |
phys_page_set(d, base >> TARGET_PAGE_BITS, 1,
|
|
|
9ae3a8 |
- phys_section_add(&subsection));
|
|
|
9ae3a8 |
+ phys_section_add(&d->map, &subsection));
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
subpage = container_of(existing->mr, subpage_t, iomem);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
start = section->offset_within_address_space & ~TARGET_PAGE_MASK;
|
|
|
9ae3a8 |
end = start + section->size - 1;
|
|
|
9ae3a8 |
- subpage_register(subpage, start, end, phys_section_add(section));
|
|
|
9ae3a8 |
+ subpage_register(subpage, start, end, phys_section_add(&d->map, section));
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -791,7 +799,7 @@ static void register_multipage(AddressSpaceDispatch *d, MemoryRegionSection *sec
|
|
|
9ae3a8 |
hwaddr start_addr = section->offset_within_address_space;
|
|
|
9ae3a8 |
ram_addr_t size = section->size;
|
|
|
9ae3a8 |
hwaddr addr;
|
|
|
9ae3a8 |
- uint16_t section_index = phys_section_add(section);
|
|
|
9ae3a8 |
+ uint16_t section_index = phys_section_add(&d->map, section);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
assert(size);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1619,7 +1627,7 @@ static uint64_t subpage_read(void *opaque, hwaddr addr,
|
|
|
9ae3a8 |
mmio, len, addr, idx);
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- section = &phys_sections[mmio->sub_section[idx]];
|
|
|
9ae3a8 |
+ section = &mmio->as->dispatch->map.sections[mmio->sub_section[idx]];
|
|
|
9ae3a8 |
addr += mmio->base;
|
|
|
9ae3a8 |
addr -= section->offset_within_address_space;
|
|
|
9ae3a8 |
addr += section->offset_within_region;
|
|
|
9ae3a8 |
@@ -1638,7 +1646,7 @@ static void subpage_write(void *opaque, hwaddr addr,
|
|
|
9ae3a8 |
__func__, mmio, len, addr, idx, value);
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- section = &phys_sections[mmio->sub_section[idx]];
|
|
|
9ae3a8 |
+ section = &mmio->as->dispatch->map.sections[mmio->sub_section[idx]];
|
|
|
9ae3a8 |
addr += mmio->base;
|
|
|
9ae3a8 |
addr -= section->offset_within_address_space;
|
|
|
9ae3a8 |
addr += section->offset_within_region;
|
|
|
9ae3a8 |
@@ -1696,10 +1704,10 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,
|
|
|
9ae3a8 |
printf("%s: %p start %08x end %08x idx %08x eidx %08x mem %ld\n", __func__,
|
|
|
9ae3a8 |
mmio, start, end, idx, eidx, memory);
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
- if (memory_region_is_ram(phys_sections[section].mr)) {
|
|
|
9ae3a8 |
- MemoryRegionSection new_section = phys_sections[section];
|
|
|
9ae3a8 |
+ if (memory_region_is_ram(mmio->as->dispatch->map.sections[section].mr)) {
|
|
|
9ae3a8 |
+ MemoryRegionSection new_section = mmio->as->dispatch->map.sections[section];
|
|
|
9ae3a8 |
new_section.mr = &io_mem_subpage_ram;
|
|
|
9ae3a8 |
- section = phys_section_add(&new_section);
|
|
|
9ae3a8 |
+ section = phys_section_add(&mmio->as->dispatch->map, &new_section);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
for (; idx <= eidx; idx++) {
|
|
|
9ae3a8 |
mmio->sub_section[idx] = section;
|
|
|
9ae3a8 |
@@ -1708,12 +1716,13 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static subpage_t *subpage_init(hwaddr base)
|
|
|
9ae3a8 |
+static subpage_t *subpage_init(AddressSpace *as, hwaddr base)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
subpage_t *mmio;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
mmio = g_malloc0(sizeof(subpage_t));
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ mmio->as = as;
|
|
|
9ae3a8 |
mmio->base = base;
|
|
|
9ae3a8 |
memory_region_init_io(&mmio->iomem, &subpage_ops, mmio,
|
|
|
9ae3a8 |
"subpage", TARGET_PAGE_SIZE);
|
|
|
9ae3a8 |
@@ -1727,7 +1736,7 @@ static subpage_t *subpage_init(hwaddr base)
|
|
|
9ae3a8 |
return mmio;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static uint16_t dummy_section(MemoryRegion *mr)
|
|
|
9ae3a8 |
+static uint16_t dummy_section(PhysPageMap *map, MemoryRegion *mr)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
MemoryRegionSection section = {
|
|
|
9ae3a8 |
.mr = mr,
|
|
|
9ae3a8 |
@@ -1736,12 +1745,13 @@ static uint16_t dummy_section(MemoryRegion *mr)
|
|
|
9ae3a8 |
.size = UINT64_MAX,
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- return phys_section_add(§ion);
|
|
|
9ae3a8 |
+ return phys_section_add(map, §ion);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
MemoryRegion *iotlb_to_region(hwaddr index)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- return phys_sections[index & ~TARGET_PAGE_MASK].mr;
|
|
|
9ae3a8 |
+ return address_space_memory.dispatch->map.sections[
|
|
|
9ae3a8 |
+ index & ~TARGET_PAGE_MASK].mr;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static void io_mem_init(void)
|
|
|
9ae3a8 |
@@ -1761,23 +1771,19 @@ static void io_mem_init(void)
|
|
|
9ae3a8 |
static void mem_begin(MemoryListener *listener)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
AddressSpaceDispatch *d = container_of(listener, AddressSpaceDispatch, listener);
|
|
|
9ae3a8 |
+ uint16_t n;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
destroy_all_mappings(d);
|
|
|
9ae3a8 |
d->phys_map.ptr = PHYS_MAP_NODE_NIL;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static void core_begin(MemoryListener *listener)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- uint16_t n;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- phys_sections_clear();
|
|
|
9ae3a8 |
- n = dummy_section(&io_mem_unassigned);
|
|
|
9ae3a8 |
+ phys_sections_clear(&d->map);
|
|
|
9ae3a8 |
+ n = dummy_section(&d->map, &io_mem_unassigned);
|
|
|
9ae3a8 |
assert(n == PHYS_SECTION_UNASSIGNED);
|
|
|
9ae3a8 |
- n = dummy_section(&io_mem_notdirty);
|
|
|
9ae3a8 |
+ n = dummy_section(&d->map, &io_mem_notdirty);
|
|
|
9ae3a8 |
assert(n == PHYS_SECTION_NOTDIRTY);
|
|
|
9ae3a8 |
- n = dummy_section(&io_mem_rom);
|
|
|
9ae3a8 |
+ n = dummy_section(&d->map, &io_mem_rom);
|
|
|
9ae3a8 |
assert(n == PHYS_SECTION_ROM);
|
|
|
9ae3a8 |
- n = dummy_section(&io_mem_watch);
|
|
|
9ae3a8 |
+ n = dummy_section(&d->map, &io_mem_watch);
|
|
|
9ae3a8 |
assert(n == PHYS_SECTION_WATCH);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1822,7 +1828,6 @@ static void io_region_del(MemoryListener *listener,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static MemoryListener core_memory_listener = {
|
|
|
9ae3a8 |
- .begin = core_begin,
|
|
|
9ae3a8 |
.log_global_start = core_log_global_start,
|
|
|
9ae3a8 |
.log_global_stop = core_log_global_stop,
|
|
|
9ae3a8 |
.priority = 1,
|
|
|
9ae3a8 |
@@ -1840,7 +1845,7 @@ static MemoryListener tcg_memory_listener = {
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
void address_space_init_dispatch(AddressSpace *as)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
- AddressSpaceDispatch *d = g_new(AddressSpaceDispatch, 1);
|
|
|
9ae3a8 |
+ AddressSpaceDispatch *d = g_new0(AddressSpaceDispatch, 1);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
d->phys_map = (PhysPageEntry) { .ptr = PHYS_MAP_NODE_NIL, .is_leaf = 0 };
|
|
|
9ae3a8 |
d->listener = (MemoryListener) {
|
|
|
9ae3a8 |
@@ -1849,6 +1854,7 @@ void address_space_init_dispatch(AddressSpace *as)
|
|
|
9ae3a8 |
.region_nop = mem_add,
|
|
|
9ae3a8 |
.priority = 0,
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
+ d->as = as;
|
|
|
9ae3a8 |
as->dispatch = d;
|
|
|
9ae3a8 |
memory_listener_register(&d->listener, as);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1858,7 +1864,7 @@ void address_space_destroy_dispatch(AddressSpace *as)
|
|
|
9ae3a8 |
AddressSpaceDispatch *d = as->dispatch;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
memory_listener_unregister(&d->listener);
|
|
|
9ae3a8 |
- destroy_l2_mapping(&d->phys_map, P_L2_LEVELS - 1);
|
|
|
9ae3a8 |
+ destroy_l2_mapping(&d->map, &d->phys_map, P_L2_LEVELS - 1);
|
|
|
9ae3a8 |
g_free(d);
|
|
|
9ae3a8 |
as->dispatch = NULL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -2446,7 +2452,7 @@ void stl_phys_notdirty(hwaddr addr, uint32_t val)
|
|
|
9ae3a8 |
if (!memory_region_is_ram(section->mr) || section->readonly) {
|
|
|
9ae3a8 |
addr = memory_region_section_addr(section, addr);
|
|
|
9ae3a8 |
if (memory_region_is_ram(section->mr)) {
|
|
|
9ae3a8 |
- section = &phys_sections[PHYS_SECTION_ROM];
|
|
|
9ae3a8 |
+ section = &address_space_memory.dispatch->map.sections[PHYS_SECTION_ROM];
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
io_mem_write(section->mr, addr, val, 4);
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
@@ -2479,7 +2485,7 @@ void stq_phys_notdirty(hwaddr addr, uint64_t val)
|
|
|
9ae3a8 |
if (!memory_region_is_ram(section->mr) || section->readonly) {
|
|
|
9ae3a8 |
addr = memory_region_section_addr(section, addr);
|
|
|
9ae3a8 |
if (memory_region_is_ram(section->mr)) {
|
|
|
9ae3a8 |
- section = &phys_sections[PHYS_SECTION_ROM];
|
|
|
9ae3a8 |
+ section = &address_space_memory.dispatch->map.sections[PHYS_SECTION_ROM];
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
#ifdef TARGET_WORDS_BIGENDIAN
|
|
|
9ae3a8 |
io_mem_write(section->mr, addr, val >> 32, 4);
|
|
|
9ae3a8 |
@@ -2508,7 +2514,7 @@ static inline void stl_phys_internal(hwaddr addr, uint32_t val,
|
|
|
9ae3a8 |
if (!memory_region_is_ram(section->mr) || section->readonly) {
|
|
|
9ae3a8 |
addr = memory_region_section_addr(section, addr);
|
|
|
9ae3a8 |
if (memory_region_is_ram(section->mr)) {
|
|
|
9ae3a8 |
- section = &phys_sections[PHYS_SECTION_ROM];
|
|
|
9ae3a8 |
+ section = &address_space_memory.dispatch->map.sections[PHYS_SECTION_ROM];
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
#if defined(TARGET_WORDS_BIGENDIAN)
|
|
|
9ae3a8 |
if (endian == DEVICE_LITTLE_ENDIAN) {
|
|
|
9ae3a8 |
@@ -2575,7 +2581,7 @@ static inline void stw_phys_internal(hwaddr addr, uint32_t val,
|
|
|
9ae3a8 |
if (!memory_region_is_ram(section->mr) || section->readonly) {
|
|
|
9ae3a8 |
addr = memory_region_section_addr(section, addr);
|
|
|
9ae3a8 |
if (memory_region_is_ram(section->mr)) {
|
|
|
9ae3a8 |
- section = &phys_sections[PHYS_SECTION_ROM];
|
|
|
9ae3a8 |
+ section = &address_space_memory.dispatch->map.sections[PHYS_SECTION_ROM];
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
#if defined(TARGET_WORDS_BIGENDIAN)
|
|
|
9ae3a8 |
if (endian == DEVICE_LITTLE_ENDIAN) {
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|