Skip to content

Commit

Permalink
target-ppc: Slim conversion of model definitions to QOM subclasses
Browse files Browse the repository at this point in the history
Since the model list is highly macrofied, keep ppc_def_t for now and
save a pointer to it in PowerPCCPUClass. This results in a flat list of
subclasses including aliases, to be refined later.

Move cpu_ppc_init() to translate_init.c and drop helper.c.
Long-term the idea is to turn translate_init.c into a standalone cpu.c.

Inline cpu_ppc_usable() into type registration.

Split cpu_ppc_register() in two by code movement into the initfn and
by turning the remaining part into a realizefn.
Move qemu_init_vcpu() call into the new realizefn and adapt
create_ppc_opcodes() to return an Error.

Change ppc_find_by_pvr() -> ppc_cpu_class_by_pvr().
Change ppc_find_by_name() -> ppc_cpu_class_by_name().

Turn -cpu host into its own subclass. This requires to move the
kvm_enabled() check in ppc_cpu_class_by_name() to avoid the class being
found via the normal name lookup in the !kvm_enabled() case.
Turn kvmppc_host_cpu_def() into the class_init and add an initfn that
asserts KVM is in fact enabled.

Implement -cpu ? and the QMP equivalent in terms of subclasses.
This newly exposes -cpu host to the user, ordered last for -cpu ?.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
  • Loading branch information
afaerber authored and agraf committed Jan 7, 2013
1 parent 68c2dd7 commit 2985b86
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 176 deletions.
3 changes: 1 addition & 2 deletions target-ppc/Makefile.objs
@@ -1,7 +1,6 @@
obj-y += translate.o helper.o
obj-y += translate.o
obj-$(CONFIG_SOFTMMU) += machine.o
obj-$(CONFIG_KVM) += kvm.o kvm_ppc.o
obj-y += helper.o
obj-y += excp_helper.o
obj-y += fpu_helper.o
obj-y += int_helper.o
Expand Down
5 changes: 5 additions & 0 deletions target-ppc/cpu-qom.h
Expand Up @@ -50,6 +50,9 @@ typedef struct PowerPCCPUClass {
/*< public >*/

void (*parent_reset)(CPUState *cpu);

/* TODO inline fields here */
ppc_def_t *info;
} PowerPCCPUClass;

/**
Expand All @@ -73,5 +76,7 @@ static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)

#define ENV_GET_CPU(e) CPU(ppc_env_get_cpu(e))

PowerPCCPUClass *ppc_cpu_class_by_pvr(uint32_t pvr);


#endif
4 changes: 0 additions & 4 deletions target-ppc/cpu.h
Expand Up @@ -1158,10 +1158,6 @@ void ppc_store_msr (CPUPPCState *env, target_ulong value);

void ppc_cpu_list (FILE *f, fprintf_function cpu_fprintf);

const ppc_def_t *ppc_find_by_pvr(uint32_t pvr);
const ppc_def_t *cpu_ppc_find_by_name (const char *name);
int cpu_ppc_register_internal (CPUPPCState *env, const ppc_def_t *def);

/* Time-base and decrementer management */
#ifndef NO_CPU_IO_DEFS
uint64_t cpu_ppc_load_tbl (CPUPPCState *env);
Expand Down
50 changes: 0 additions & 50 deletions target-ppc/helper.c

This file was deleted.

37 changes: 30 additions & 7 deletions target-ppc/kvm.c
Expand Up @@ -1230,18 +1230,29 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on)
}
}

const ppc_def_t *kvmppc_host_cpu_def(void)
static void kvmppc_host_cpu_initfn(Object *obj)
{
assert(kvm_enabled());
}

static void kvmppc_host_cpu_class_init(ObjectClass *oc, void *data)
{
PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
uint32_t host_pvr = mfpvr();
const ppc_def_t *base_spec;
PowerPCCPUClass *pvr_pcc;
ppc_def_t *spec;
uint32_t vmx = kvmppc_get_vmx();
uint32_t dfp = kvmppc_get_dfp();

base_spec = ppc_find_by_pvr(host_pvr);

spec = g_malloc0(sizeof(*spec));
memcpy(spec, base_spec, sizeof(*spec));

pvr_pcc = ppc_cpu_class_by_pvr(host_pvr);
if (pvr_pcc != NULL) {
memcpy(spec, pvr_pcc->info, sizeof(*spec));
}
pcc->info = spec;
/* Override the display name for -cpu ? and QMP */
pcc->info->name = "host";

/* Now fix up the spec with information we can query from the host */

Expand All @@ -1254,8 +1265,6 @@ const ppc_def_t *kvmppc_host_cpu_def(void)
/* Only override when we know what the host supports */
alter_insns(&spec->insns_flags2, PPC2_DFP, dfp);
}

return spec;
}

int kvmppc_fixup_cpu(CPUPPCState *env)
Expand Down Expand Up @@ -1285,3 +1294,17 @@ 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)
8 changes: 2 additions & 6 deletions target-ppc/kvm_ppc.h
Expand Up @@ -11,6 +11,8 @@

#include "exec/memory.h"

#define TYPE_HOST_POWERPC_CPU "host-" TYPE_POWERPC_CPU

void kvmppc_init(void);

#ifdef CONFIG_KVM
Expand All @@ -31,7 +33,6 @@ int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size);
int kvmppc_reset_htab(int shift_hint);
uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);
#endif /* !CONFIG_USER_ONLY */
const ppc_def_t *kvmppc_host_cpu_def(void);
int kvmppc_fixup_cpu(CPUPPCState *env);

#else
Expand Down Expand Up @@ -121,11 +122,6 @@ static inline int kvmppc_update_sdr1(CPUPPCState *env)

#endif /* !CONFIG_USER_ONLY */

static inline const ppc_def_t *kvmppc_host_cpu_def(void)
{
return NULL;
}

static inline int kvmppc_fixup_cpu(CPUPPCState *env)
{
return -1;
Expand Down

0 comments on commit 2985b86

Please sign in to comment.