0a122b
From 348710ce46ee2ddf02396aad4bd3978c6dfc2a07 Mon Sep 17 00:00:00 2001
0a122b
From: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
Date: Sun, 19 Jan 2014 13:07:35 +0100
0a122b
Subject: [PATCH 10/11] exec: change well-known physical sections to macros
0a122b
0a122b
RH-Author: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
Message-id: <1390136856-7024-2-git-send-email-marcel.a@redhat.com>
0a122b
Patchwork-id: 56810
0a122b
O-Subject: [RHEL-7 qemu-kvm PATCH v2 1/2] exec: change well-known physical sections to macros
0a122b
Bugzilla: 1003535
0a122b
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
0a122b
0a122b
From: Liu Ping Fan <qemulist@gmail.com>
0a122b
0a122b
Sections like phys_section_unassigned always have fixed address
0a122b
in phys_sections.  Declared as macro, so we can use them
0a122b
when having more than one phys_sections array.
0a122b
0a122b
Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
0a122b
Signed-off-by: Liu Ping Fan <qemulist@gmail.com>
0a122b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
(cherry picked from commit b41aac4f0d17000babd815e088699d58e59917b8)
0a122b
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
0a122b
Conflicts:
0a122b
	exec.c
0a122b
0a122b
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
---
0a122b
 exec.c | 42 ++++++++++++++++++++++++------------------
0a122b
 1 file changed, 24 insertions(+), 18 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 exec.c |   42 ++++++++++++++++++++++++------------------
0a122b
 1 files changed, 24 insertions(+), 18 deletions(-)
0a122b
0a122b
diff --git a/exec.c b/exec.c
0a122b
index b16ef4a..01c74cd 100644
0a122b
--- a/exec.c
0a122b
+++ b/exec.c
0a122b
@@ -101,10 +101,10 @@ struct AddressSpaceDispatch {
0a122b
 
0a122b
 static MemoryRegionSection *phys_sections;
0a122b
 static unsigned phys_sections_nb, phys_sections_nb_alloc;
0a122b
-static uint16_t phys_section_unassigned;
0a122b
-static uint16_t phys_section_notdirty;
0a122b
-static uint16_t phys_section_rom;
0a122b
-static uint16_t phys_section_watch;
0a122b
+#define PHYS_SECTION_UNASSIGNED 0
0a122b
+#define PHYS_SECTION_NOTDIRTY 1
0a122b
+#define PHYS_SECTION_ROM 2
0a122b
+#define PHYS_SECTION_WATCH 3
0a122b
 
0a122b
 /* Simple allocator for PhysPageEntry nodes */
0a122b
 static PhysPageEntry (*phys_map_nodes)[L2_SIZE];
0a122b
@@ -168,7 +168,7 @@ static void phys_page_set_level(PhysPageEntry *lp, hwaddr *index,
0a122b
         if (level == 0) {
0a122b
             for (i = 0; i < L2_SIZE; i++) {
0a122b
                 p[i].is_leaf = 1;
0a122b
-                p[i].ptr = phys_section_unassigned;
0a122b
+                p[i].ptr = PHYS_SECTION_UNASSIGNED;
0a122b
             }
0a122b
         }
0a122b
     } else {
0a122b
@@ -204,7 +204,7 @@ MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr index)
0a122b
     PhysPageEntry lp = d->phys_map;
0a122b
     PhysPageEntry *p;
0a122b
     int i;
0a122b
-    uint16_t s_index = phys_section_unassigned;
0a122b
+    uint16_t s_index = PHYS_SECTION_UNASSIGNED;
0a122b
 
0a122b
     for (i = P_L2_LEVELS - 1; i >= 0 && !lp.is_leaf; i--) {
0a122b
         if (lp.ptr == PHYS_MAP_NODE_NIL) {
0a122b
@@ -646,9 +646,9 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
0a122b
         iotlb = (memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK)
0a122b
             + memory_region_section_addr(section, paddr);
0a122b
         if (!section->readonly) {
0a122b
-            iotlb |= phys_section_notdirty;
0a122b
+            iotlb |= PHYS_SECTION_NOTDIRTY;
0a122b
         } else {
0a122b
-            iotlb |= phys_section_rom;
0a122b
+            iotlb |= PHYS_SECTION_ROM;
0a122b
         }
0a122b
     } else {
0a122b
         /* IO handlers are currently passed a physical address.
0a122b
@@ -667,7 +667,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
0a122b
         if (vaddr == (wp->vaddr & TARGET_PAGE_MASK)) {
0a122b
             /* Avoid trapping reads of pages with a write breakpoint. */
0a122b
             if ((prot & PAGE_WRITE) || (wp->flags & BP_MEM_READ)) {
0a122b
-                iotlb = phys_section_watch + paddr;
0a122b
+                iotlb = PHYS_SECTION_WATCH + paddr;
0a122b
                 *address |= TLB_MMIO;
0a122b
                 break;
0a122b
             }
0a122b
@@ -1722,7 +1722,7 @@ static subpage_t *subpage_init(hwaddr base)
0a122b
     printf("%s: %p base " TARGET_FMT_plx " len %08x %d\n", __func__,
0a122b
            mmio, base, TARGET_PAGE_SIZE, subpage_memory);
0a122b
 #endif
0a122b
-    subpage_register(mmio, 0, TARGET_PAGE_SIZE-1, phys_section_unassigned);
0a122b
+    subpage_register(mmio, 0, TARGET_PAGE_SIZE-1, PHYS_SECTION_UNASSIGNED);
0a122b
 
0a122b
     return mmio;
0a122b
 }
0a122b
@@ -1768,11 +1768,17 @@ static void mem_begin(MemoryListener *listener)
0a122b
 
0a122b
 static void core_begin(MemoryListener *listener)
0a122b
 {
0a122b
+    uint16_t n;
0a122b
+
0a122b
     phys_sections_clear();
0a122b
-    phys_section_unassigned = dummy_section(&io_mem_unassigned);
0a122b
-    phys_section_notdirty = dummy_section(&io_mem_notdirty);
0a122b
-    phys_section_rom = dummy_section(&io_mem_rom);
0a122b
-    phys_section_watch = dummy_section(&io_mem_watch);
0a122b
+    n = dummy_section(&io_mem_unassigned);
0a122b
+    assert(n == PHYS_SECTION_UNASSIGNED);
0a122b
+    n = dummy_section(&io_mem_notdirty);
0a122b
+    assert(n == PHYS_SECTION_NOTDIRTY);
0a122b
+    n = dummy_section(&io_mem_rom);
0a122b
+    assert(n == PHYS_SECTION_ROM);
0a122b
+    n = dummy_section(&io_mem_watch);
0a122b
+    assert(n == PHYS_SECTION_WATCH);
0a122b
 }
0a122b
 
0a122b
 static void tcg_commit(MemoryListener *listener)
0a122b
@@ -2440,7 +2446,7 @@ void stl_phys_notdirty(hwaddr addr, uint32_t val)
0a122b
     if (!memory_region_is_ram(section->mr) || section->readonly) {
0a122b
         addr = memory_region_section_addr(section, addr);
0a122b
         if (memory_region_is_ram(section->mr)) {
0a122b
-            section = &phys_sections[phys_section_rom];
0a122b
+            section = &phys_sections[PHYS_SECTION_ROM];
0a122b
         }
0a122b
         io_mem_write(section->mr, addr, val, 4);
0a122b
     } else {
0a122b
@@ -2473,7 +2479,7 @@ void stq_phys_notdirty(hwaddr addr, uint64_t val)
0a122b
     if (!memory_region_is_ram(section->mr) || section->readonly) {
0a122b
         addr = memory_region_section_addr(section, addr);
0a122b
         if (memory_region_is_ram(section->mr)) {
0a122b
-            section = &phys_sections[phys_section_rom];
0a122b
+            section = &phys_sections[PHYS_SECTION_ROM];
0a122b
         }
0a122b
 #ifdef TARGET_WORDS_BIGENDIAN
0a122b
         io_mem_write(section->mr, addr, val >> 32, 4);
0a122b
@@ -2502,7 +2508,7 @@ static inline void stl_phys_internal(hwaddr addr, uint32_t val,
0a122b
     if (!memory_region_is_ram(section->mr) || section->readonly) {
0a122b
         addr = memory_region_section_addr(section, addr);
0a122b
         if (memory_region_is_ram(section->mr)) {
0a122b
-            section = &phys_sections[phys_section_rom];
0a122b
+            section = &phys_sections[PHYS_SECTION_ROM];
0a122b
         }
0a122b
 #if defined(TARGET_WORDS_BIGENDIAN)
0a122b
         if (endian == DEVICE_LITTLE_ENDIAN) {
0a122b
@@ -2569,7 +2575,7 @@ static inline void stw_phys_internal(hwaddr addr, uint32_t val,
0a122b
     if (!memory_region_is_ram(section->mr) || section->readonly) {
0a122b
         addr = memory_region_section_addr(section, addr);
0a122b
         if (memory_region_is_ram(section->mr)) {
0a122b
-            section = &phys_sections[phys_section_rom];
0a122b
+            section = &phys_sections[PHYS_SECTION_ROM];
0a122b
         }
0a122b
 #if defined(TARGET_WORDS_BIGENDIAN)
0a122b
         if (endian == DEVICE_LITTLE_ENDIAN) {
0a122b
-- 
0a122b
1.7.1
0a122b