[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH 62/66] target-ppc: Make host CPU a subclass of the hos
From: |
Alexander Graf |
Subject: |
[Qemu-ppc] [PATCH 62/66] target-ppc: Make host CPU a subclass of the host's CPU model |
Date: |
Fri, 8 Mar 2013 21:07:04 +0100 |
From: Andreas Färber <address@hidden>
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 <address@hidden>
Signed-off-by: Alexander Graf <address@hidden>
---
target-ppc/kvm.c | 66 +++++++++++++++----------------------------
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);
--
1.6.0.2
- [Qemu-ppc] [PATCH 61/66] PPC: xnu kernel expects FLUSH to be cleared on STOP, (continued)
- [Qemu-ppc] [PATCH 61/66] PPC: xnu kernel expects FLUSH to be cleared on STOP, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 53/66] target-ppc: Fix remaining microcontroller typos among models, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 55/66] pseries: Implement h_read hcall, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 44/66] target-ppc: Convert CPU definitions, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 63/66] target-ppc: List alias names alongside CPU models, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 56/66] Save memory allocation in the elf loader, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 60/66] PPC: Fix dma interrupt, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 51/66] target-ppc: Update Coding Style for CPU models, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 64/66] target-ppc: Report CPU aliases for QMP, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 58/66] target-ppc: Synchronize FPU state with KVM, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 62/66] target-ppc: Make host CPU a subclass of the host's CPU model,
Alexander Graf <=
- [Qemu-ppc] [PATCH 57/66] target-ppc: Add mechanism for synchronizing SPRs with KVM, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 65/66] target-ppc: Move CPU aliases out of translate_init.c, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 66/66] pseries: Add compatible property to root of device tree, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 49/66] target-ppc: Turn descriptive CPU family comments into device descriptions, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 48/66] target-ppc: Set remaining fields on CPU family classes, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 45/66] target-ppc: Introduce abstract CPU family types, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 06/66] target-ppc: Inline comma into POWERPC_DEF_SVR() macro, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 50/66] target-ppc: Turn descriptive CPU model comments into device descriptions, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 52/66] target-ppc: Split model definitions out of translate_init.c, Alexander Graf, 2013/03/08
- [Qemu-ppc] [PATCH 46/66] target-ppc: Set instruction flags on CPU family classes, Alexander Graf, 2013/03/08