diff options
author | Andreas Färber <afaerber@suse.de> | 2013-02-23 11:22:12 +0000 |
---|---|---|
committer | Alexander Graf <agraf@suse.de> | 2013-03-08 21:04:53 +0100 |
commit | 5ba4576b858c0d6056f59abb7e17a2b63f7905f3 (patch) | |
tree | 1aa6b8ae3180f0caf46576f5d304b57e530fedf7 /target-ppc | |
parent | 987422bc4a4c6366ca6a7fbfa38a9920fd7ada2f (diff) | |
download | hqemu-5ba4576b858c0d6056f59abb7e17a2b63f7905f3.zip hqemu-5ba4576b858c0d6056f59abb7e17a2b63f7905f3.tar.gz |
target-ppc: Make host CPU a subclass of the host's CPU model
This avoids assigning individual class fields and contributors
forgetting to add field assignments in KVM-only code.
ppc_cpu_class_find_by_pvr() requires the CPU model classes to be
registered, so defer host CPU type registration to kvm_arch_init().
Only register the host CPU type if there is a class with matching PVR.
This lets us drop error handling from instance_init.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'target-ppc')
-rw-r--r-- | target-ppc/kvm.c | 66 | ||||
-rw-r--r-- | target-ppc/translate_init.c | 15 |
2 files changed, 31 insertions, 50 deletions
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 4451159..9dff760 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -81,6 +81,8 @@ static void kvm_kick_cpu(void *opaque) qemu_cpu_kick(CPU(cpu)); } +static int kvm_ppc_register_host_cpu_type(void); + int kvm_arch_init(KVMState *s) { cap_interrupt_unset = kvm_check_extension(s, KVM_CAP_PPC_UNSET_IRQ); @@ -98,6 +100,8 @@ int kvm_arch_init(KVMState *s) "VM to stall at times!\n"); } + kvm_ppc_register_host_cpu_type(); + return 0; } @@ -1488,44 +1492,15 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on) static void kvmppc_host_cpu_initfn(Object *obj) { - PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(obj); - assert(kvm_enabled()); - - if (pcc->pvr != mfpvr()) { - fprintf(stderr, "Your host CPU is unsupported.\n" - "Please choose a supported model instead, see -cpu ?.\n"); - exit(1); - } } static void kvmppc_host_cpu_class_init(ObjectClass *oc, void *data) { PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc); - uint32_t host_pvr = mfpvr(); - PowerPCCPUClass *pvr_pcc; uint32_t vmx = kvmppc_get_vmx(); uint32_t dfp = kvmppc_get_dfp(); - pvr_pcc = ppc_cpu_class_by_pvr(host_pvr); - if (pvr_pcc != NULL) { - pcc->pvr = pvr_pcc->pvr; - pcc->svr = pvr_pcc->svr; - pcc->insns_flags = pvr_pcc->insns_flags; - pcc->insns_flags2 = pvr_pcc->insns_flags2; - pcc->msr_mask = pvr_pcc->msr_mask; - pcc->mmu_model = pvr_pcc->mmu_model; - pcc->excp_model = pvr_pcc->excp_model; - pcc->bus_model = pvr_pcc->bus_model; - pcc->flags = pvr_pcc->flags; - pcc->bfd_mach = pvr_pcc->bfd_mach; -#ifdef TARGET_PPC64 - pcc->sps = pvr_pcc->sps; -#endif - pcc->init_proc = pvr_pcc->init_proc; - pcc->check_pow = pvr_pcc->check_pow; - } - /* Now fix up the class with information we can query from the host */ if (vmx != -1) { @@ -1552,6 +1527,25 @@ int kvmppc_fixup_cpu(PowerPCCPU *cpu) return 0; } +static int kvm_ppc_register_host_cpu_type(void) +{ + TypeInfo type_info = { + .name = TYPE_HOST_POWERPC_CPU, + .instance_init = kvmppc_host_cpu_initfn, + .class_init = kvmppc_host_cpu_class_init, + }; + uint32_t host_pvr = mfpvr(); + PowerPCCPUClass *pvr_pcc; + + pvr_pcc = ppc_cpu_class_by_pvr(host_pvr); + if (pvr_pcc == NULL) { + return -1; + } + type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc)); + type_register(&type_info); + return 0; +} + bool kvm_arch_stop_on_emulation_error(CPUState *cpu) { @@ -1567,17 +1561,3 @@ int kvm_arch_on_sigbus(int code, void *addr) { return 1; } - -static const TypeInfo kvm_host_cpu_type_info = { - .name = TYPE_HOST_POWERPC_CPU, - .parent = TYPE_POWERPC_CPU, - .instance_init = kvmppc_host_cpu_initfn, - .class_init = kvmppc_host_cpu_class_init, -}; - -static void kvm_ppc_register_types(void) -{ - type_register_static(&kvm_host_cpu_type_info); -} - -type_init(kvm_ppc_register_types) diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 1783c22..521cdcc 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -8298,13 +8298,6 @@ static ObjectClass *ppc_cpu_class_by_name(const char *name) const char *p; int i, len; - if (strcasecmp(name, "host") == 0) { - if (kvm_enabled()) { - ret = object_class_by_name(TYPE_HOST_POWERPC_CPU); - } - return ret; - } - /* Check if the given name is a PVR */ len = strlen(name); if (len == 10 && name[0] == '0' && name[1] == 'x') { @@ -8405,6 +8398,9 @@ static void ppc_cpu_list_entry(gpointer data, gpointer user_data) return; } #endif + if (unlikely(strcmp(typename, TYPE_HOST_POWERPC_CPU) == 0)) { + return; + } name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_POWERPC_CPU)); @@ -8427,6 +8423,11 @@ void ppc_cpu_list(FILE *f, fprintf_function cpu_fprintf) g_slist_foreach(list, ppc_cpu_list_entry, &s); g_slist_free(list); +#ifdef CONFIG_KVM + cpu_fprintf(f, "\n"); + cpu_fprintf(f, "PowerPC %-16s\n", "host"); +#endif + cpu_fprintf(f, "\n"); for (i = 0; i < ARRAY_SIZE(ppc_cpu_aliases); i++) { ObjectClass *oc = ppc_cpu_class_by_name(ppc_cpu_aliases[i].model); |