qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RESEND PATCH v4 1/4] apic: move apic mmio register to each


From: Zhu Guihua
Subject: [Qemu-devel] [RESEND PATCH v4 1/4] apic: move apic mmio register to each apic realizefn
Date: Thu, 30 Apr 2015 09:33:22 +0800

From: Chen Fan <address@hidden>

Due to local apic address is in view of CPU's address space,
so able to move apic mapping to each apic realizefn.

Signed-off-by: Chen Fan <address@hidden>
Signed-off-by: Zhu Guihua <address@hidden>
---
 exec.c                |  5 +++++
 hw/i386/pc.c          |  7 -------
 hw/intc/apic_common.c | 14 ++++++++------
 include/exec/memory.h |  5 +++++
 target-i386/cpu.c     |  1 +
 5 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/exec.c b/exec.c
index 53d59bb..bce36a9 100644
--- a/exec.c
+++ b/exec.c
@@ -2681,6 +2681,11 @@ void address_space_unmap(AddressSpace *as, void *buffer, 
hwaddr len,
     cpu_notify_map_clients();
 }
 
+MemoryRegion *address_space_root_memory_region(AddressSpace *as)
+{
+    return as->root;
+}
+
 void *cpu_physical_memory_map(hwaddr addr,
                               hwaddr *plen,
                               int is_write)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index a8e6be1..a5e2a27 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1089,13 +1089,6 @@ void pc_cpus_init(const char *cpu_model, DeviceState 
*icc_bridge)
         }
     }
 
-    /* map APIC MMIO area if CPU has APIC */
-    if (cpu && cpu->apic_state) {
-        /* XXX: what if the base changes? */
-        sysbus_mmio_map_overlap(SYS_BUS_DEVICE(icc_bridge), 0,
-                                APIC_DEFAULT_ADDRESS, 0x1000);
-    }
-
     /* tell smbios about cpuid version and features */
     smbios_set_cpuid(cpu->env.cpuid_version, cpu->env.features[FEAT_1_EDX]);
 }
diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index 042e960..6978d22 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -306,7 +306,8 @@ static void apic_common_realize(DeviceState *dev, Error 
**errp)
     APICCommonClass *info;
     static DeviceState *vapic;
     static int apic_no;
-    static bool mmio_registered;
+    CPUState *cpu = CPU(s->cpu);
+    MemoryRegion *root;
 
     if (apic_no >= MAX_APICS) {
         error_setg(errp, "%s initialization failed.",
@@ -317,11 +318,12 @@ static void apic_common_realize(DeviceState *dev, Error 
**errp)
 
     info = APIC_COMMON_GET_CLASS(s);
     info->realize(dev, errp);
-    if (!mmio_registered) {
-        ICCBus *b = ICC_BUS(qdev_get_parent_bus(dev));
-        memory_region_add_subregion(b->apic_address_space, 0, &s->io_memory);
-        mmio_registered = true;
-    }
+
+    root = address_space_root_memory_region(cpu->as);
+    memory_region_add_subregion_overlap(root,
+                                        cpu_get_apic_base(dev),
+                                        &s->io_memory,
+                                        0x1000);
 
     /* Note: We need at least 1M to map the VAPIC option ROM */
     if (!vapic && s->vapic_control & VAPIC_ENABLE_MASK &&
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2f386ce..87c8a2f 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1281,6 +1281,11 @@ void *address_space_map(AddressSpace *as, hwaddr addr,
 void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
                          int is_write, hwaddr access_len);
 
+/* address_space_root_memory_region: get root memory region
+ *
+ * @as: #AddressSpace to be accessed
+ */
+MemoryRegion *address_space_root_memory_region(AddressSpace *as);
 
 #endif
 
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 3305e09..06c4d72 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2740,6 +2740,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
     /* TODO: convert to link<> */
     apic = APIC_COMMON(cpu->apic_state);
     apic->cpu = cpu;
+    cpu_set_apic_base(cpu->apic_state, APIC_DEFAULT_ADDRESS);
 }
 
 static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]