[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 25/46] cpu: refactor cpu_address_space_init()
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 25/46] cpu: refactor cpu_address_space_init() |
Date: |
Wed, 20 Dec 2017 18:14:37 +0100 |
From: Peter Xu <address@hidden>
Normally we create an address space for that CPU and pass that address
space into the function. Let's just do it inside to unify address space
creations. It'll simplify my next patch to rename those address spaces.
Signed-off-by: Peter Xu <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
cpus.c | 5 +----
exec.c | 7 ++++++-
include/exec/exec-all.h | 6 ++++--
target/arm/cpu.c | 13 +++----------
target/i386/cpu.c | 10 ++--------
5 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/cpus.c b/cpus.c
index 3740c4d..83700c1 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1787,11 +1787,8 @@ void qemu_init_vcpu(CPUState *cpu)
/* If the target cpu hasn't set up any address spaces itself,
* give it the default one.
*/
- AddressSpace *as = g_new0(AddressSpace, 1);
-
- address_space_init(as, cpu->memory, "cpu-memory");
cpu->num_ases = 1;
- cpu_address_space_init(cpu, as, 0);
+ cpu_address_space_init(cpu, 0, "cpu-memory", cpu->memory);
}
if (kvm_enabled()) {
diff --git a/exec.c b/exec.c
index 3e7c57e..3ab515e 100644
--- a/exec.c
+++ b/exec.c
@@ -705,9 +705,14 @@ CPUState *qemu_get_cpu(int index)
}
#if !defined(CONFIG_USER_ONLY)
-void cpu_address_space_init(CPUState *cpu, AddressSpace *as, int asidx)
+void cpu_address_space_init(CPUState *cpu, int asidx,
+ const char *prefix, MemoryRegion *mr)
{
CPUAddressSpace *newas;
+ AddressSpace *as = g_new0(AddressSpace, 1);
+
+ assert(mr);
+ address_space_init(as, mr, prefix);
/* Target code should have set num_ases before calling us */
assert(asidx < cpu->num_ases);
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 0f51c92..b37f7d8 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -74,8 +74,9 @@ void cpu_reloading_memory_map(void);
/**
* cpu_address_space_init:
* @cpu: CPU to add this address space to
- * @as: address space to add
* @asidx: integer index of this address space
+ * @prefix: prefix to be used as name of address space
+ * @mr: the root memory region of address space
*
* Add the specified address space to the CPU's cpu_ases list.
* The address space added with @asidx 0 is the one used for the
@@ -89,7 +90,8 @@ void cpu_reloading_memory_map(void);
*
* Note that with KVM only one address space is supported.
*/
-void cpu_address_space_init(CPUState *cpu, AddressSpace *as, int asidx);
+void cpu_address_space_init(CPUState *cpu, int asidx,
+ const char *prefix, MemoryRegion *mr);
#endif
#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 7f7a3d1..cc1856c 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -705,9 +705,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error
**errp)
CPUARMState *env = &cpu->env;
int pagebits;
Error *local_err = NULL;
-#ifndef CONFIG_USER_ONLY
- AddressSpace *as;
-#endif
cpu_exec_realizefn(cs, &local_err);
if (local_err != NULL) {
@@ -912,21 +909,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Error
**errp)
#ifndef CONFIG_USER_ONLY
if (cpu->has_el3 || arm_feature(env, ARM_FEATURE_M_SECURITY)) {
- as = g_new0(AddressSpace, 1);
-
cs->num_ases = 2;
if (!cpu->secure_memory) {
cpu->secure_memory = cs->memory;
}
- address_space_init(as, cpu->secure_memory, "cpu-secure-memory");
- cpu_address_space_init(cs, as, ARMASIdx_S);
+ cpu_address_space_init(cs, ARMASIdx_S, "cpu-secure-memory",
+ cpu->secure_memory);
} else {
cs->num_ases = 1;
}
- as = g_new0(AddressSpace, 1);
- address_space_init(as, cs->memory, "cpu-memory");
- cpu_address_space_init(cs, as, ARMASIdx_NS);
+ cpu_address_space_init(cs, ARMASIdx_NS, "cpu-memory", cs->memory);
#endif
qemu_init_vcpu(cs);
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 325b52e..b069eaf 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -3736,11 +3736,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error
**errp)
#ifndef CONFIG_USER_ONLY
if (tcg_enabled()) {
- AddressSpace *as_normal = g_new0(AddressSpace, 1);
- AddressSpace *as_smm = g_new(AddressSpace, 1);
-
- address_space_init(as_normal, cs->memory, "cpu-memory");
-
cpu->cpu_as_mem = g_new(MemoryRegion, 1);
cpu->cpu_as_root = g_new(MemoryRegion, 1);
@@ -3755,11 +3750,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error
**errp)
get_system_memory(), 0, ~0ull);
memory_region_add_subregion_overlap(cpu->cpu_as_root, 0,
cpu->cpu_as_mem, 0);
memory_region_set_enabled(cpu->cpu_as_mem, true);
- address_space_init(as_smm, cpu->cpu_as_root, "CPU");
cs->num_ases = 2;
- cpu_address_space_init(cs, as_normal, 0);
- cpu_address_space_init(cs, as_smm, 1);
+ cpu_address_space_init(cs, 0, "cpu-memory", cs->memory);
+ cpu_address_space_init(cs, 1, "cpu-smm", cpu->cpu_as_root);
/* ... SMRAM with higher priority, linked from /machine/smram. */
cpu->machine_done.notify = x86_cpu_machine_done;
--
1.8.3.1
- [Qemu-devel] [PULL 18/46] tests/boot-serial-test: Make sure that we check the timeout regularly, (continued)
- [Qemu-devel] [PULL 18/46] tests/boot-serial-test: Make sure that we check the timeout regularly, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 17/46] target/i386: Fix handling of VEX prefixes, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 19/46] tests/boot-serial-test: Add code to allow to specify our own kernel or bios, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 22/46] hw/moxie/moxiesim: Add support for loading a BIOS on moxiesim, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 21/46] tests/boot-serial-test: Add tests for microblaze boards, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 16/46] sockets: remove obsolete code that updated listen address, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 20/46] tests/boot-serial-test: Add support for the mcf5208evb board, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 24/46] tests/boot-serial-test: Add support for the raspi2 machine, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 23/46] tests/boot-serial-test: Add a test for the moxiesim machine, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 26/46] cpu: suffix cpu address spaces with cpu index, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 25/46] cpu: refactor cpu_address_space_init(),
Paolo Bonzini <=
- [Qemu-devel] [PULL 29/46] exec: Don't reuse unassigned_mem_ops for io_mem_rom, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 27/46] block/iscsi: dont leave allocmap in an invalid state on UNMAP failure, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 28/46] block/iscsi: only report an iSCSI Failure if we don't handle it gracefully, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 30/46] hw/mips/boston: Remove workaround for writes to ROM aborting, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 31/46] hw/i386/vmport: replace fprintf() by trace events or LOG_UNIMP, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 33/46] scsi: replace hex constants with #defines, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 32/46] scsi: provide general-purpose functions to manage sense data, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 37/46] i8259: generalize statistics into common code, Paolo Bonzini, 2017/12/20
- [Qemu-devel] [PULL 35/46] i8259: convert DPRINTFs into trace, Paolo Bonzini, 2017/12/20