From patchwork Sat Feb 23 16:00:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 2178521 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id B631EDF25A for ; Sat, 23 Feb 2013 16:00:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759131Ab3BWQAa (ORCPT ); Sat, 23 Feb 2013 11:00:30 -0500 Received: from cantor2.suse.de ([195.135.220.15]:41905 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755161Ab3BWQA3 (ORCPT ); Sat, 23 Feb 2013 11:00:29 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7F95BA520D; Sat, 23 Feb 2013 17:00:28 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Cc: ehabkost@redhat.com, imammedo@redhat.com, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Alexander Graf (maintainer:PPC), Gleb Natapov (supporter:Overall), Marcelo Tosatti (supporter:Overall), qemu-ppc@nongnu.org (open list:PowerPC), kvm@vger.kernel.org (open list:Overall) Subject: [PATCH RFT ppc-next] target-ppc: Make host CPU a subclass of the host's CPU model Date: Sat, 23 Feb 2013 17:00:19 +0100 Message-Id: <1361635219-13353-1-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 --- target-ppc/kvm.c | 64 ++++++++++++++++--------------------------- target-ppc/translate_init.c | 15 +++++----- 2 Dateien geändert, 31 Zeilen hinzugefügt(+), 48 Zeilen entfernt(-) diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index e601059..0e892d0 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -80,6 +80,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); @@ -96,6 +98,8 @@ int kvm_arch_init(KVMState *s) "VM to stall at times!\n"); } + kvm_ppc_register_host_cpu_type(); + return 0; } @@ -1262,41 +1266,14 @@ 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) { @@ -1323,6 +1300,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) { @@ -1338,17 +1334,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 a42f81a..547ba8a 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -8236,13 +8236,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') { @@ -8343,6 +8336,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)); @@ -8365,6 +8361,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);