On 04/17/2012 01:37 AM, Igor Mammedov wrote:
From: Igor Mammedov<niall...@gmail.com>
Use realize to start a cpu prepared by x86_cpu_initfn.
v2:
Create apic for cpu only once.
Signed-off-by: Igor Mammedov<niall...@gmail.com>
---
hw/pc.c | 35 ++++---------------------
target-i386/cpu.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++-
target-i386/helper.c | 46 +++-----------------------------
3 files changed, 79 insertions(+), 71 deletions(-)
[...]
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 30ae0c2..e4dcf52 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -30,6 +30,8 @@
#include "hyperv.h"
#include "qerror.h"
+#include "hw/qdev.h"
+#include "sysemu.h"
/* feature flags taken from "Intel Processor Identification and the CPUID
* Instruction" and AMD's "CPUID Specification". In cases of disagreement
@@ -1489,16 +1491,73 @@ static void x86_set_cpu_model(Object *obj, const char
*value, Error **errp)
fprintf(stderr, "Unable to find x86 CPU definition\n");
error_set(errp, QERR_INVALID_PARAMETER_COMBINATION);
}
+
+ mce_init(cpu);
+
+ if (((env->cpuid_features& CPUID_APIC) || smp_cpus> 1)&&
!env->apic_state) {
I wonder if it is ok to drop "smp_cpus> 1" here?
Booted linux guest with
-smp 2 -cpu host,-apic
and it sees/initializes only one cpu. So I guess that CPUID_APIC must be
present for smp machine and that makes "smp_cpus> 1" redundant.
+ if (kvm_irqchip_in_kernel()) {
+ env->apic_state = qdev_create(NULL, "kvm-apic");
+ } else {
+ env->apic_state = qdev_create(NULL, "apic");
+ }
+ qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id);
+ qdev_prop_set_ptr(env->apic_state, "cpu_env", env);
+ object_property_add_child(OBJECT(cpu), "apic", OBJECT(env->apic_state),
NULL);
+
+ /* We hard-wire the BSP to the first CPU. */
+ if (env->cpu_index == 0) {
+ apic_designate_bsp(env->apic_state);
+ }
+ }
+}
[...]
-----
Igor