Message ID | 20200819024220.587612-8-bauerman@linux.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Generalize start-powered-off property from ARM | expand |
On 8/19/20 4:42 AM, Thiago Jung Bauermann wrote: > Instead of setting CPUState::halted to 1 in secondary_cpu_reset(), use the > start-powered-off property which makes cpu_common_reset() initialize it > to 1 in common code. > > This makes secondary_cpu_reset() unnecessary, so remove it. > > Also remove setting of cs->halted from cpu_devinit(), which seems out of > place when compared to similar code in other architectures (e.g., > ppce500_init() in hw/ppc/e500.c). > > Finally, change creation of CPU object from cpu_create() to object_new() > and qdev_realize_and_unref() because cpu_create() realizes the CPU and it's > not possible to set a property after the object is realized. > > Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com> > Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> > --- > hw/sparc/sun4m.c | 21 +++++---------------- > 1 file changed, 5 insertions(+), 16 deletions(-) > > diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c > index 22c51dac8a..1925f415e7 100644 > --- a/hw/sparc/sun4m.c > +++ b/hw/sparc/sun4m.c > @@ -218,15 +218,6 @@ static void dummy_cpu_set_irq(void *opaque, int irq, int level) > { > } > > -static void secondary_cpu_reset(void *opaque) > -{ > - SPARCCPU *cpu = opaque; > - CPUState *cs = CPU(cpu); > - > - cpu_reset(cs); > - cs->halted = 1; > -} > - > static void cpu_halt_signal(void *opaque, int irq, int level) > { > if (level && current_cpu) { > @@ -810,21 +801,19 @@ static const TypeInfo ram_info = { > static void cpu_devinit(const char *cpu_type, unsigned int id, > uint64_t prom_addr, qemu_irq **cpu_irqs) > { > - CPUState *cs; > SPARCCPU *cpu; > CPUSPARCState *env; > > - cpu = SPARC_CPU(cpu_create(cpu_type)); > + cpu = SPARC_CPU(object_new(cpu_type)); > env = &cpu->env; > > cpu_sparc_set_id(env, id); > - if (id != 0) { > - qemu_register_reset(secondary_cpu_reset, cpu); > - cs = CPU(cpu); > - cs->halted = 1; > - } > + object_property_set_bool(OBJECT(cpu), "start-powered-off", id != 0, > + &error_fatal); Why not call here: qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal); ? > *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS); > env->prom_addr = prom_addr; > + > + qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal); > } > > static void dummy_fdc_tc(void *opaque, int irq, int level) >
Hi Philippe, Philippe Mathieu-Daudé <philmd@redhat.com> writes: > On 8/19/20 4:42 AM, Thiago Jung Bauermann wrote: >> Instead of setting CPUState::halted to 1 in secondary_cpu_reset(), use the >> start-powered-off property which makes cpu_common_reset() initialize it >> to 1 in common code. >> >> This makes secondary_cpu_reset() unnecessary, so remove it. >> >> Also remove setting of cs->halted from cpu_devinit(), which seems out of >> place when compared to similar code in other architectures (e.g., >> ppce500_init() in hw/ppc/e500.c). >> >> Finally, change creation of CPU object from cpu_create() to object_new() >> and qdev_realize_and_unref() because cpu_create() realizes the CPU and it's >> not possible to set a property after the object is realized. >> >> Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com> >> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> >> --- >> hw/sparc/sun4m.c | 21 +++++---------------- >> 1 file changed, 5 insertions(+), 16 deletions(-) >> >> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c >> index 22c51dac8a..1925f415e7 100644 >> --- a/hw/sparc/sun4m.c >> +++ b/hw/sparc/sun4m.c >> @@ -218,15 +218,6 @@ static void dummy_cpu_set_irq(void *opaque, int irq, int level) >> { >> } >> >> -static void secondary_cpu_reset(void *opaque) >> -{ >> - SPARCCPU *cpu = opaque; >> - CPUState *cs = CPU(cpu); >> - >> - cpu_reset(cs); >> - cs->halted = 1; >> -} >> - >> static void cpu_halt_signal(void *opaque, int irq, int level) >> { >> if (level && current_cpu) { >> @@ -810,21 +801,19 @@ static const TypeInfo ram_info = { >> static void cpu_devinit(const char *cpu_type, unsigned int id, >> uint64_t prom_addr, qemu_irq **cpu_irqs) >> { >> - CPUState *cs; >> SPARCCPU *cpu; >> CPUSPARCState *env; >> >> - cpu = SPARC_CPU(cpu_create(cpu_type)); >> + cpu = SPARC_CPU(object_new(cpu_type)); >> env = &cpu->env; >> >> cpu_sparc_set_id(env, id); >> - if (id != 0) { >> - qemu_register_reset(secondary_cpu_reset, cpu); >> - cs = CPU(cpu); >> - cs->halted = 1; >> - } >> + object_property_set_bool(OBJECT(cpu), "start-powered-off", id != 0, >> + &error_fatal); > > Why not call here: > > qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal); > > ? I can do that. I was unsure about whether qemu_allocate_irqs() could come after realize, but now that you pointed it out it obviously can since this code was working with cpu_create(). I'll send a v6 with that change. >> *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS); >> env->prom_addr = prom_addr; >> + >> + qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal); >> } >> >> static void dummy_fdc_tc(void *opaque, int irq, int level) >> -- Thiago Jung Bauermann IBM Linux Technology Center
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c index 22c51dac8a..1925f415e7 100644 --- a/hw/sparc/sun4m.c +++ b/hw/sparc/sun4m.c @@ -218,15 +218,6 @@ static void dummy_cpu_set_irq(void *opaque, int irq, int level) { } -static void secondary_cpu_reset(void *opaque) -{ - SPARCCPU *cpu = opaque; - CPUState *cs = CPU(cpu); - - cpu_reset(cs); - cs->halted = 1; -} - static void cpu_halt_signal(void *opaque, int irq, int level) { if (level && current_cpu) { @@ -810,21 +801,19 @@ static const TypeInfo ram_info = { static void cpu_devinit(const char *cpu_type, unsigned int id, uint64_t prom_addr, qemu_irq **cpu_irqs) { - CPUState *cs; SPARCCPU *cpu; CPUSPARCState *env; - cpu = SPARC_CPU(cpu_create(cpu_type)); + cpu = SPARC_CPU(object_new(cpu_type)); env = &cpu->env; cpu_sparc_set_id(env, id); - if (id != 0) { - qemu_register_reset(secondary_cpu_reset, cpu); - cs = CPU(cpu); - cs->halted = 1; - } + object_property_set_bool(OBJECT(cpu), "start-powered-off", id != 0, + &error_fatal); *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS); env->prom_addr = prom_addr; + + qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal); } static void dummy_fdc_tc(void *opaque, int irq, int level)
Instead of setting CPUState::halted to 1 in secondary_cpu_reset(), use the start-powered-off property which makes cpu_common_reset() initialize it to 1 in common code. This makes secondary_cpu_reset() unnecessary, so remove it. Also remove setting of cs->halted from cpu_devinit(), which seems out of place when compared to similar code in other architectures (e.g., ppce500_init() in hw/ppc/e500.c). Finally, change creation of CPU object from cpu_create() to object_new() and qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not possible to set a property after the object is realized. Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> --- hw/sparc/sun4m.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)