diff mbox

[RFT,ppc-next] target-ppc: Make host CPU a subclass of the host's CPU model

Message ID 1361635219-13353-1-git-send-email-afaerber@suse.de (mailing list archive)
State New, archived
Headers show

Commit Message

Andreas Färber Feb. 23, 2013, 4 p.m. UTC
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>
---
 target-ppc/kvm.c            |   64 ++++++++++++++++---------------------------
 target-ppc/translate_init.c |   15 +++++-----
 2 Dateien geändert, 31 Zeilen hinzugefügt(+), 48 Zeilen entfernt(-)
diff mbox

Patch

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);