Commit 3a31f36a07d8d6bf49a7da24c5570153de0fd79e
Committed by
Anthony Liguori
1 parent
15dfcd45
x86: Factor out pc_new_cpu
At this point, this refactoring looks like overkill. But we will need it for CPU hotplugging, and qemu-kvm already carries it. Merging it early would help qemu-kvm when rebasing against upstream. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
22 additions
and
14 deletions
hw/pc.c
... | ... | @@ -1062,6 +1062,25 @@ int cpu_is_bsp(CPUState *env) |
1062 | 1062 | return env->cpuid_apic_id == 0; |
1063 | 1063 | } |
1064 | 1064 | |
1065 | +static CPUState *pc_new_cpu(const char *cpu_model) | |
1066 | +{ | |
1067 | + CPUState *env; | |
1068 | + | |
1069 | + env = cpu_init(cpu_model); | |
1070 | + if (!env) { | |
1071 | + fprintf(stderr, "Unable to find x86 CPU definition\n"); | |
1072 | + exit(1); | |
1073 | + } | |
1074 | + if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) { | |
1075 | + env->cpuid_apic_id = env->cpu_index; | |
1076 | + /* APIC reset callback resets cpu */ | |
1077 | + apic_init(env); | |
1078 | + } else { | |
1079 | + qemu_register_reset((QEMUResetHandler*)cpu_reset, env); | |
1080 | + } | |
1081 | + return env; | |
1082 | +} | |
1083 | + | |
1065 | 1084 | /* PC hardware initialisation */ |
1066 | 1085 | static void pc_init1(ram_addr_t ram_size, |
1067 | 1086 | const char *boot_device, |
... | ... | @@ -1103,20 +1122,9 @@ static void pc_init1(ram_addr_t ram_size, |
1103 | 1122 | cpu_model = "qemu32"; |
1104 | 1123 | #endif |
1105 | 1124 | } |
1106 | - | |
1107 | - for(i = 0; i < smp_cpus; i++) { | |
1108 | - env = cpu_init(cpu_model); | |
1109 | - if (!env) { | |
1110 | - fprintf(stderr, "Unable to find x86 CPU definition\n"); | |
1111 | - exit(1); | |
1112 | - } | |
1113 | - if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) { | |
1114 | - env->cpuid_apic_id = env->cpu_index; | |
1115 | - /* APIC reset callback resets cpu */ | |
1116 | - apic_init(env); | |
1117 | - } else { | |
1118 | - qemu_register_reset((QEMUResetHandler*)cpu_reset, env); | |
1119 | - } | |
1125 | + | |
1126 | + for (i = 0; i < smp_cpus; i++) { | |
1127 | + env = pc_new_cpu(cpu_model); | |
1120 | 1128 | } |
1121 | 1129 | |
1122 | 1130 | vmport_init(); | ... | ... |