From da9cbe02bc0a0c4ee8148da6238eb7bbd61f17f3 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Thu, 24 Aug 2017 18:31:36 +0200 Subject: nios2: replace cpu_nios2_init() with cpu_generic_init() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cpu_nios2_init() always falls back to TYPE_NIOS2_CPU object regardless of cpu_model. Put fallback logic into nios2_cpu_class_by_name() which would translate any cpu_model into TYPE_NIOS2_CPU class and replace cpu_nios2_init() with cpu_generic_init() Signed-off-by: Igor Mammedov Reviewed-by: Philippe Mathieu-Daudé Message-Id: <1503592308-93913-14-git-send-email-imammedo@redhat.com> Signed-off-by: Eduardo Habkost --- hw/nios2/10m50_devboard.c | 2 +- target/nios2/cpu.c | 9 +++------ target/nios2/cpu.h | 3 +-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c index b6868b8..e4007f6 100644 --- a/hw/nios2/10m50_devboard.c +++ b/hw/nios2/10m50_devboard.c @@ -75,7 +75,7 @@ static void nios2_10m50_ghrd_init(MachineState *machine) phys_ram_alias); /* Create CPU -- FIXME */ - cpu = cpu_nios2_init("nios2"); + cpu = NIOS2_CPU(cpu_generic_init(TYPE_NIOS2_CPU, "nios2")); /* Register: CPU interrupt controller (PIC) */ cpu_irq = nios2_cpu_pic_init(cpu); diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index d56bb72..5b02fb6 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -83,13 +83,9 @@ static void nios2_cpu_initfn(Object *obj) } } -Nios2CPU *cpu_nios2_init(const char *cpu_model) +static ObjectClass *nios2_cpu_class_by_name(const char *cpu_model) { - Nios2CPU *cpu = NIOS2_CPU(object_new(TYPE_NIOS2_CPU)); - - object_property_set_bool(OBJECT(cpu), true, "realized", NULL); - - return cpu; + return object_class_by_name(TYPE_NIOS2_CPU); } static void nios2_cpu_realizefn(DeviceState *dev, Error **errp) @@ -203,6 +199,7 @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) ncc->parent_reset = cc->reset; cc->reset = nios2_cpu_reset; + cc->class_by_name = nios2_cpu_class_by_name; cc->has_work = nios2_cpu_has_work; cc->do_interrupt = nios2_cpu_do_interrupt; cc->cpu_exec_interrupt = nios2_cpu_exec_interrupt; diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h index 13931f3..50d803a 100644 --- a/target/nios2/cpu.h +++ b/target/nios2/cpu.h @@ -212,7 +212,6 @@ static inline Nios2CPU *nios2_env_get_cpu(CPUNios2State *env) #define ENV_OFFSET offsetof(Nios2CPU, env) void nios2_tcg_init(void); -Nios2CPU *cpu_nios2_init(const char *cpu_model); void nios2_cpu_do_interrupt(CPUState *cs); int cpu_nios2_signal_handler(int host_signum, void *pinfo, void *puc); void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUNios2State *env); @@ -229,7 +228,7 @@ void nios2_check_interrupts(CPUNios2State *env); #define TARGET_PHYS_ADDR_SPACE_BITS 32 #define TARGET_VIRT_ADDR_SPACE_BITS 32 -#define cpu_init(cpu_model) CPU(cpu_nios2_init(cpu_model)) +#define cpu_init(cpu_model) cpu_generic_init(TYPE_NIOS2_CPU, cpu_model) #define cpu_gen_code cpu_nios2_gen_code #define cpu_signal_handler cpu_nios2_signal_handler -- cgit v1.1