cpu_reset clean-ups for arm, alpha, mips, m68k and tricore
v2 cover cpu_reset clean-ups for arm, alpha, mips, m68k and tricore
We tend to apply cpu_reset inconsistently throughout our various models which leads to unintended ordering dependencies. This got in the way in my last plugins series:
https://patchew.org/QEMU/[email protected]/
where I needed to shuffle things around to ensure that gdb register creation was done after dependant peripherals had created their cpu interfaces.
Regardless of that we do have a proper reset interface now and most architectures have moved to it. This series attempts to clean-up the remaining cases with proper qemu_register_reset() calls so reset is called when we intend to.
v2
I re-span this to address the missing cpu_reset Akihiko found troubling the alpha replay test:
Message-Id: <[email protected]>
Date: Tue, 17 Feb 2026 15:34:28 +0900
Subject: [PATCH 0/2] Reapply "rcu: Unify force quiescent state"
From: Akihiko Odaki <[email protected]>
I also dropped the use of qemu_register_reset in favour of the proper 3-phase APIs.
Alex.
Alex Bennée (14):
target/m68k: clean-up includes in cpu.c target/m68k: initialise pc/sp vector during reset hw/m68k: transition virt machine to multi-phase reset hw/m68k: update nextcube to 3-phase reset hw/m68k: update mcf5208evb to 3-phase reset hw/m68k: update an5206 to 3-phase reset
hw/mips: defer finalising gcr_base until reset time hw/mips: drop cpu_reset in mips_cpu_realizefn target/tricore: move cpu_reset from tricore_cpu_realizefn target/arm: remove extraneous cpu_reset from realizefn hw/alpha: remove unused includes
hw/alpha: add a reset function for the clipper machine target/alpha: move cpu reset into a proper reset function include/hw: expand cpu_reset function docs
include/hw/core/cpu.h | 3 +++ include/hw/mips/cps.h | 14 +++++++++++++- target/alpha/cpu.h | 2 ++ target/m68k/cpu.h | 2 ++ hw/alpha/dp264.c | 12 ++++++++++-- hw/m68k/an5206.c | 23 ++++++++++++++++------- hw/m68k/mcf5208.c | 26 ++++++++++++-------------- hw/m68k/next-cube.c | 23 +++++++++++++++++------ hw/m68k/virt.c | 34 ++++++++++------------------------ hw/mips/cps.c | 26 +++++++++++++++++--------- hw/misc/mips_cmgcr.c | 1 - target/alpha/cpu.c | 10 ++++++---- target/arm/cpu.c | 1 - target/m68k/cpu.c | 41 +++++++++++++++++++++++++++++++++-------- target/mips/cpu.c | 1 - target/tricore/cpu.c | 9 ++++++++- 16 files changed, 149 insertions(+), 79 deletions(-)
Signature · 1 line
2.47.3
RFC PATCH v2 1/14 target/m68k: clean-up includes in cpu.c
We don't need translation-block.h as the TB flags are local and the only bits needed come from cpu-ops.h. The vmstate is a system only concerns so we can guard against including it for linux-user.
Finally tidy up the order to keep things together with the local cpu.h kept at the end.
--- target/m68k/cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
target/m68k/cpu.c +7 -4
@@ -19,12 +19,15 @@*/ #include "qemu/osdep.h" +#include "accel/tcg/cpu-ops.h" +#include "fpu/softfloat.h" #include "qapi/error.h" -#include "cpu.h" + +#ifndef CONFIG_USER_ONLY #include "migration/vmstate.h" -#include "fpu/softfloat.h" -#include "exec/translation-block.h" -#include "accel/tcg/cpu-ops.h" +#endif + +#include "cpu.h" static void m68k_cpu_set_pc (CPUState *cs,vaddr value) {
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 01/14] target/m68k: clean-up includes in cpu.c
Quoted 4 lines · Alex Bennée
We don't need
translation-block.has the TB flags are local and the only bits needed come fromcpu-ops.h. The vmstate is a system only concerns so we can guard against including it for linux-user.
Quoted 8 lines
Finally tidy up the order to keep things together with the local
cpu.hkept at the end.Signed-off-by Alex Bennée <[email protected]>--- target/m68k/cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Re: [RFC PATCH v2 01/14] target/m68k: clean-up includes in cpu.c
In reply to Alex BennéeAm Thu, 19 Feb 2026 17:17:57 +0000
schrieb Alex Bennée <[email protected]>:
Quoted 26 lines
We don't need
translation-block.has the TB flags are local and the only bits needed come fromcpu-ops.h. The vmstate is a system only concerns so we can guard against including it for linux-user.Finally tidy up the order to keep things together with the local
cpu.hkept at the end.Signed-off-by Alex Bennée <[email protected]>--- target/m68k/cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)target/m68k/cpu.c +4
-1@@ -19,12 +19,15 @@*/ #include "qemu/osdep.h" +#include "accel/tcg/cpu-ops.h" +#include "fpu/softfloat.h" #include "qapi/error.h" -#include "cpu.h" + +#ifndef CONFIG_USER_ONLY
target/m68k/cpu.c line 33
Quoted 10 lines
target/m68k/cpu.c +3
-3#include "migration/vmstate.h" -#include "fpu/softfloat.h" -#include "exec/translation-block.h" -#include "accel/tcg/cpu-ops.h" +#endif + +#include "cpu.h" static void m68k_cpu_set_pc (CPUState *cs,vaddr value) {
RFC PATCH v2 2/14 target/m68k: initialise pc/sp vector during reset
In reply to Alex BennéeAll 68k chips should be able to follow the architectural behaviour on reset which is to load the initial sp/pc from the first 8 bytes of the address space.
To avoid any potential issues with un-reset memory controllers we punt the final setting of the register to the exit phase when everything else is guaranteed to have been through the hold phase.
--- target/m68k/cpu.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
target/m68k/cpu.c +21 -4
@@ -25,6 +25,7 @@#ifndef CONFIG_USER_ONLY #include "migration/vmstate.h" +#include "system/memory.h" #endif #include "cpu.h"
@@ -174,9 +175,25 @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type) }cpu_m68k_set_fpcr (env,0 ); env->fpsr =0 ; +} -/* TODO: We should set PC from the interrupt vector. */ - env->pc =0 ; +/* +* We defer the final setting of the PC to the exit phase to ensure +* if any memory controllers need to be reset they are before we read +* the initial reset vector. This is a NOP for user-mode which will +* set the PC in init_main_thread() after the CPU is reset. +*/ +static void m68k_cpu_reset_exit (Object *obj,ResetType type) +{ +#ifndef CONFIG_USER_ONLY +CPUState *cs =CPU (obj); +CPUM68KState *env =cpu_env (cs); + + env->aregs[7 ] =address_space_ldl_be (cs->as,0 , +MEMTXATTRS_UNSPECIFIED ,NULL ); + env->pc =address_space_ldl_be (cs->as,4 , +MEMTXATTRS_UNSPECIFIED ,NULL ); +#endif }static void m68k_cpu_disas_set_info (const CPUState *cs,disassemble_info *info)
@@ -396,7 +413,6 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)m68k_cpu_init_gdb (cpu); -cpu_reset (cs);qemu_init_vcpu (cs); mcc->parent_realize (dev, errp);
@@ -641,7 +657,8 @@ static void m68k_cpu_class_init(ObjectClass *c, const void *data)device_class_set_parent_realize (dc, m68k_cpu_realizefn, &mcc->parent_realize); -resettable_class_set_parent_phases (rc,NULL , m68k_cpu_reset_hold,NULL , +resettable_class_set_parent_phases (rc,NULL , + m68k_cpu_reset_hold, m68k_cpu_reset_exit, &mcc->parent_phases); cc->class_by_name = m68k_cpu_class_by_name;
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 02/14] target/m68k: initialise pc/sp vector during reset
Quoted 4 lines · Alex Bennée
All 68k chips should be able to follow the architectural behaviour on reset which is to load the initial sp/pc from the first 8 bytes of the address space.
Quoted 9 lines
To avoid any potential issues with un-reset memory controllers we punt the final setting of the register to the exit phase when everything else is guaranteed to have been through the hold phase.
Signed-off-by Alex Bennée <[email protected]>--- target/m68k/cpu.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
Re: [RFC PATCH v2 02/14] target/m68k: initialise pc/sp vector during reset
In reply to Alex BennéeAm Thu, 19 Feb 2026 17:17:58 +0000
schrieb Alex Bennée <[email protected]>:
Quoted 4 lines
All 68k chips should be able to follow the architectural behaviour on reset which is to load the initial sp/pc from the first 8 bytes of the address space.
Quoted 8 lines
To avoid any potential issues with un-reset memory controllers we punt the final setting of the register to the exit phase when everything else is guaranteed to have been through the hold phase.
Signed-off-by Alex Bennée <[email protected]>--- target/m68k/cpu.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
Re: [RFC PATCH v2 02/14] target/m68k: initialise pc/sp vector during reset
In reply to Alex BennéeQuoted 8 lines · Alex Bennée
All 68k chips should be able to follow the architectural behaviour on reset which is to load the initial sp/pc from the first 8 bytes of the address space.
To avoid any potential issues with un-reset memory controllers we punt the final setting of the register to the exit phase when everything else is guaranteed to have been through the hold phase.
Unfortunately we can't guarantee that the exit-phase of a CPU's reset happens after everybody else's hold phase, because at the moment CPUs are still reset separately to the rest of the system:
typically some bit of board code calls cpu_reset() on the CPU(s) out of a qemu_register_reset() hook. qemu_register_reset() hooks get called during the "hold" phase of system reset, and if they call cpu_reset() that causes all 3 phases of the CPU object reset to happen immediately, one after the other.
This is why the Arm M-profile handling of "read the PC and SP from memory" is still being done with special case handling for "maybe there's a ROM blob here which hasn't yet been copied into guest RAM" -- look for "Load the initial SP and PC" in target/arm/cpu.c.
I keep meaning to have another look at this for the Arm case, but haven't got round to it yet. This could be done without opening the entire reset can of worms by switching the arm use of qemu_register_reset() to qemu_register_resettable(), which would let you get called back separately for each phase so you could invoke exactly the right CPU object reset phase. (It might be sufficient to pass the CPU object itself to qemu_register_resettable() before calling qemu_register_reset() and rely on resettables being invoked in order.)
thanks
-- PMM
RFC PATCH v2 3/14 hw/m68k: transition virt machine to multi-phase reset
In reply to Alex BennéeWe don't need to re-create the architectural reset behaviour now it is handled in the core m68k CPU reset code. We do however need to add support for direct kernel booting so we stash that value in env->direct_kernel_boot_pc and enhance m68k_cpu_reset_exit() to use it if set.
---
v2
- re-write to use proper 3-phase logic, so dropped all tags
- favour cpu_reset over resettable_reset(cs)
--- target/m68k/cpu.h | 2 ++ hw/m68k/virt.c | 34 ++++++++++------------------------ target/m68k/cpu.c | 5 +++++ 3 files changed, 17 insertions(+), 24 deletions(-)
target/m68k/cpu.h +2 -0
@@ -155,6 +155,8 @@ typedef struct CPUArchState {/* Fields from here on are preserved across CPU reset. */ uint64_t features; +/* Override the normal reset vector with a direct kernel boot */ +uint32_t direct_kernel_boot_pc; } CPUM68KState;/*
hw/m68k/virt.c +10 -24
@@ -87,23 +87,6 @@#define VIRT_VIRTIO_MMIO_BASE 0xff010000/* MMIO: 0xff010000 - 0xff01ffff */ #define VIRT_VIRTIO_IRQ_BASE PIC_IRQ(2, 1)/* PIC: 2, 3, 4, 5, IRQ: ALL */ -typedef struct { -M68kCPU *cpu; -hwaddr initial_pc; -hwaddr initial_stack; -}ResetInfo ; - -static void main_cpu_reset (void *opaque) -{ -ResetInfo *reset_info = opaque; -M68kCPU *cpu = reset_info->cpu; -CPUState *cs =CPU (cpu); - -cpu_reset (cs); - cpu->env.aregs[7 ] = reset_info->initial_stack; - cpu->env.pc = reset_info->initial_pc; -} -static void rerandomize_rng_seed (void *opaque) {struct bi_record *rng_seed = opaque;
@@ -111,6 +94,14 @@ static void rerandomize_rng_seed(void *opaque) be16_to_cpu(*(uint16_t *)rng_seed->data)); } +static void virt_machine_reset (MachineState *ms,ResetType type) +{ +CPUState *cs = first_cpu; + +qemu_devices_reset (type); +cpu_reset (cs); +} +static void virt_init (MachineState *machine) {M68kCPU *cpu =NULL ;
@@ -129,7 +120,6 @@ static void virt_init(MachineState *machine)SysBusDevice *sysbus;hwaddr io_base;int i; -ResetInfo *reset_info;uint8_t rng_seed[32 ];if (ram_size >3399672 * KiB) {
@@ -142,14 +132,9 @@ static void virt_init(MachineState *machine)exit (1 ); } - reset_info =g_new0 (ResetInfo,1 ); -/* init CPUs */ cpu =M68K_CPU (cpu_create (machine->cpu_type)); - reset_info->cpu = cpu; -qemu_register_reset (main_cpu_reset, reset_info); -/* RAM */ memory_region_add_subregion (get_system_memory (),0 , machine->ram);
@@ -235,7 +220,7 @@ static void virt_init(MachineState *machine)error_report ("could not load kernel '%s'" , kernel_filename);exit (1 ); } - reset_info->initial_pc = elf_entry; + cpu->env.direct_kernel_boot_pc = elf_entry; parameters_base = (high +1 ) & ~1 ; param_ptr = param_blob;
@@ -315,6 +300,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)MachineClass *mc =MACHINE_CLASS (oc); mc->desc ="QEMU M68K Virtual Machine" ; mc->init = virt_init; + mc->reset = virt_machine_reset; mc->default_cpu_type =M68K_CPU_TYPE_NAME ("m68040" ); mc->max_cpus =1 ; mc->no_floppy =1 ;
target/m68k/cpu.c +5 -0
@@ -193,6 +193,11 @@ static void m68k_cpu_reset_exit(Object *obj, ResetType type) MEMTXATTRS_UNSPECIFIED, NULL); env->pc =address_space_ldl_be (cs->as,4 ,MEMTXATTRS_UNSPECIFIED ,NULL ); + +/* some machine models support direct kernel boot */ +if (env->direct_kernel_boot_pc) { + env->pc = env->direct_kernel_boot_pc; + }#endif }
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 03/14] hw/m68k: transition virt machine to multi-phase reset
Quoted 12 lines · Alex Bennée
We don't need to re-create the architectural reset behaviour now it is handled in the core m68k CPU reset code. We do however need to add support for direct kernel booting so we stash that value in
env->direct_kernel_boot_pcand enhancem68k_cpu_reset_exit()to use it if set.Signed-off-by Alex Bennée <[email protected]>---
v2
- re-write to use proper 3-phase logic, so dropped all tags
- favourcpu_resetoverresettable_reset(cs)
Quoted 6 lines
--- target/m68k/cpu.h | 2 ++ hw/m68k/virt.c | 34 ++++++++++------------------------ target/m68k/cpu.c | 5 +++++ 3 files changed, 17 insertions(+), 24 deletions(-)
Re: [RFC PATCH v2 03/14] hw/m68k: transition virt machine to multi-phase reset
In reply to Alex BennéeQuoted 7 lines · Alex Bennée
We don't need to re-create the architectural reset behaviour now it is handled in the core m68k CPU reset code. We do however need to add support for direct kernel booting so we stash that value in
env->direct_kernel_boot_pcand enhancem68k_cpu_reset_exit()to use it if set.
Quoted 6 lines
Signed-off-by Alex Bennée <[email protected]>---
v2
- re-write to use proper 3-phase logic, so dropped all tags
- favourcpu_resetoverresettable_reset(cs)
The commit message says it's doing three-phase reset, but the actual code is not:
hw/m68k/virt.c static void rerandomize_rng_seed(void *opaque) · line 102
Quoted 6 lines
hw/m68k/virt.c +6
-0+static void virt_machine_reset (MachineState *ms,ResetType type) +{ +CPUState *cs = first_cpu; + +qemu_devices_reset (type); +cpu_reset (cs);
This first resets the whole system (going through its three phases) and then the CPU (which does its phases separately). Three-phase support would imply having the CPU do its enter phase at the same time as the other devices, its hold phase with the others, and so on.
If you wanted that you could do it by using qemu_register_resettable(OBJECT(cpu)) instead of having a MachineClass::reset method, given that the only two things you're doing in it are the default thing and a cpu_reset() call.
hw/m68k/virt.c static void virt_machine_class_init(ObjectClass *oc, const void *data) · line 306
Quoted 8 lines
hw/m68k/virt.c +1
-0@@ -315,6 +300,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)MachineClass *mc =MACHINE_CLASS (oc); mc->desc ="QEMU M68K Virtual Machine" ; mc->init = virt_init; + mc->reset = virt_machine_reset; mc->default_cpu_type =M68K_CPU_TYPE_NAME ("m68040" ); mc->max_cpus =1 ; mc->no_floppy =1 ;
I did have a plan to look at making MachineClass a subset of Device so that it could be three-phase-reset aware rather than having its own special-snowflake reset method.
thanks
-- PMM
RFC PATCH v2 4/14 hw/m68k: update nextcube to 3-phase reset
In reply to Alex Bennée---
v2
- re-written, tags dropped.
- favour cpu_reset over resettable_reset(cs)
--- hw/m68k/next-cube.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
hw/m68k/next-cube.c +17 -6
@@ -16,6 +16,7 @@#include "exec/cpu-interrupt.h" #include "system/system.h" #include "system/qtest.h" +#include "system/reset.h" #include "hw/core/irq.h" #include "hw/m68k/next-cube.h" #include "hw/core/boards.h"
@@ -1249,6 +1250,19 @@ static const TypeInfo next_pc_info = { .class_init = next_pc_class_init, }; +static void next_cube_reset (MachineState *ms,ResetType type) +{ +CPUState *cs = first_cpu; +M68kCPU *cpu =M68K_CPU (cs); + +qemu_devices_reset (type); +cpu_reset (cs); + +/* Initialize CPU registers. */ + cpu->env.vbr =0 ; + cpu->env.sr =0x2700 ; +} +static void next_cube_init (MachineState *machine) {NeXTState *m =NEXT_MACHINE (machine);
@@ -1266,10 +1280,6 @@ static void next_cube_init(MachineState *machine) } env = &cpu->env; -/* Initialize CPU registers. */ - env->vbr =0 ; - env->sr =0x2700 ; -/* Peripheral Controller */ pcdev =qdev_new (TYPE_NEXT_PC );object_property_set_link (OBJECT (pcdev),"cpu" ,OBJECT (cpu), &error_abort);
@@ -1335,8 +1345,8 @@ static void next_cube_init(MachineState *machine)/* Initial PC is always at offset 4 in firmware binaries */ ptr =rom_ptr (0x01000004 ,4 );g_assert (ptr !=NULL ); - env->pc =ldl_be_p (ptr); -if (env->pc >=0x01020000 ) { + cpu->env.direct_kernel_boot_pc =ldl_be_p (ptr); +if (env->direct_kernel_boot_pc >=0x01020000 ) {error_report ("'%s' does not seem to be a valid firmware image." , bios_name);exit (1 );
@@ -1355,6 +1365,7 @@ static void next_machine_class_init(ObjectClass *oc, const void *data) mc->desc ="NeXT Cube" ; mc->init = next_cube_init; + mc->reset = next_cube_reset; mc->block_default_type =IF_SCSI ; mc->default_ram_size =RAM_SIZE ; mc->default_ram_id ="next.ram" ;
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 04/14] hw/m68k: update nextcube to 3-phase reset
Quoted 10 lines · Alex Bennée
Signed-off-by Alex Bennée <[email protected]>---
v2
- re-written, tags dropped.
- favourcpu_resetoverresettable_reset(cs)--- hw/m68k/next-cube.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
RFC PATCH v2 5/14 hw/m68k: update mcf5208evb to 3-phase reset
In reply to Alex Bennée---
v2
- rewritten
- favour cpu_reset over resettable_reset(cs)
--- hw/m68k/mcf5208.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
hw/m68k/mcf5208.c +12 -14
@@ -27,6 +27,7 @@#include "qemu/timer.h" #include "hw/core/ptimer.h" #include "system/system.h" +#include "system/reset.h" #include "system/qtest.h" #include "net/net.h" #include "hw/core/boards.h"
@@ -274,6 +275,13 @@ static void mcf_fec_init(MemoryRegion *sysmem, hwaddr base, qemu_irq *irqs)memory_region_add_subregion (sysmem, base,sysbus_mmio_get_region (s,0 )); } +static void mcf5208evb_reset (MachineState *ms,ResetType type) +{ +CPUState *cs = first_cpu; +qemu_devices_reset (type); +cpu_reset (cs); +} +static void mcf5208evb_init (MachineState *machine) {ram_addr_t ram_size = machine->ram_size;
@@ -289,11 +297,8 @@ static void mcf5208evb_init(MachineState *machine)MemoryRegion *sram =g_new (MemoryRegion,1 ); cpu =M68K_CPU (cpu_create (machine->cpu_type)); - env = &cpu->env; -/* Initialize CPU registers. */ - env->vbr =0 ; -/* TODO: Configure BARs. */ + env = &cpu->env;/* ROM at 0x00000000 */ memory_region_init_rom (rom,NULL ,"mcf5208.rom" ,ROM_SIZE , &error_fatal);
@@ -343,10 +348,7 @@ static void mcf5208evb_init(MachineState *machine)/* Load firmware */ if (machine->firmware) { -char *fn; -uint8_t *ptr; - - fn =qemu_find_file (QEMU_FILE_TYPE_BIOS , machine->firmware); + g_autofree char *fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, machine->firmware);if (!fn) {error_report ("Could not find ROM image '%s'" , machine->firmware);exit (1 );
@@ -355,11 +357,6 @@ static void mcf5208evb_init(MachineState *machine)error_report ("Could not load ROM image '%s'" , machine->firmware);exit (1 ); } -g_free (fn); -/* Initial PC is always at offset 4 in firmware binaries */ - ptr =rom_ptr (0x4 ,4 ); -assert (ptr !=NULL ); - env->pc =ldl_be_p (ptr); }/* Load kernel. */
@@ -388,13 +385,14 @@ static void mcf5208evb_init(MachineState *machine)exit (1 ); } - env->pc = entry; + env->direct_kernel_boot_pc = entry; }static void mcf5208evb_machine_init (MachineClass *mc) { mc->desc ="MCF5208EVB" ; mc->init = mcf5208evb_init; + mc->reset = mcf5208evb_reset; mc->is_default = true; mc->default_cpu_type =M68K_CPU_TYPE_NAME ("m5208" ); mc->default_ram_id ="mcf5208.ram" ;
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 05/14] hw/m68k: update mcf5208evb to 3-phase reset
Quoted 10 lines · Alex Bennée
Signed-off-by Alex Bennée <[email protected]>---
v2
- rewritten
- favourcpu_resetoverresettable_reset(cs)--- hw/m68k/mcf5208.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
RFC PATCH v2 6/14 hw/m68k: update an5206 to 3-phase reset
In reply to Alex BennéeAs the mbar/rambar0 values are currently fixed we can migrate the setting of them to the reset handler as well.
---
v2
- re-written, dropped tags
- favour cpu_reset over resettable_reset(cs)
--- hw/m68k/an5206.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
hw/m68k/an5206.c +16 -7
@@ -15,11 +15,25 @@#include "elf.h" #include "qemu/error-report.h" #include "system/qtest.h" +#include "system/reset.h" #define KERNEL_LOAD_ADDR 0x10000#define AN5206_MBAR_ADDR 0x10000000#define AN5206_RAMBAR_ADDR 0x20000000 +static void an5206_reset (MachineState *ms,ResetType type) +{ +CPUState *cs = first_cpu; +M68kCPU *cpu =M68K_CPU (cs); + +qemu_devices_reset (type); +cpu_reset (cs); + + cpu->env.vbr =0 ; + cpu->env.mbar =AN5206_MBAR_ADDR |1 ; + cpu->env.rambar0 =AN5206_RAMBAR_ADDR |1 ; +} +static void mcf5206_init (M68kCPU *cpu,MemoryRegion *sysmem,uint32_t base) {DeviceState *dev;
@@ -49,12 +63,6 @@ static void an5206_init(MachineState *machine) cpu =M68K_CPU (cpu_create (machine->cpu_type)); env = &cpu->env; -/* Initialize CPU registers. */ - env->vbr =0 ; -/* TODO: allow changing MBAR and RAMBAR. */ - env->mbar =AN5206_MBAR_ADDR |1 ; - env->rambar0 =AN5206_RAMBAR_ADDR |1 ; -/* DRAM at address zero */ memory_region_add_subregion (address_space_mem,0 , machine->ram);
@@ -90,13 +98,14 @@ static void an5206_init(MachineState *machine)exit (1 ); } - env->pc = entry; + env->direct_kernel_boot_pc = entry; }static void an5206_machine_init (MachineClass *mc) { mc->desc ="Arnewsh 5206" ; mc->init = an5206_init; + mc->reset = an5206_reset; mc->default_cpu_type =M68K_CPU_TYPE_NAME ("m5206" ); mc->default_ram_id ="an5206.ram" ; }
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 06/14] hw/m68k: update an5206 to 3-phase reset
Quoted 5 lines · Alex Bennée
As the mbar/rambar0 values are currently fixed we can migrate the setting of them to the reset handler as well.
Signed-off-by Alex Bennée <[email protected]>
Quoted 8 lines
---
v2
- re-written, dropped tags
- favourcpu_resetoverresettable_reset(cs)--- hw/m68k/an5206.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
RFC PATCH v2 7/14 hw/mips: defer finalising gcr_base until reset time
In reply to Alex BennéeCurrently the cpu_reset() in mips_cpu_realizefn() hides an implicit sequencing requirement when setting gcr_base. Without it we barf because we end up setting the region between 0x0-0x000000001fbfffff which trips over a qtest that accesses the GCR during "memsave 0 4096 /dev/null".
By moving to the reset phase we have to drop the property lest we are admonished for "Attempting to set...after it was realized" but there doesn't seem to be a need to expose the property anyway.
NB: it would be safer if I could guarantee the place in the reset tree but I haven't quite grokked how to do that yet. Currently I see this sequence when testing:
env MALLOC_PERTURB_=43 G_TEST_DBUS_DAEMON=/home/alex/lsrc/qemu.git/tests/dbus-vmstate-daemon.sh UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 QTEST_QEMU_IMG=./qemu-img QTEST_QEMU_BINARY=./qemu-system-mips64el SPEED=thorough MESON_TEST_ITERATION=1 MSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 PYTHON=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 QTEST_QEMU_STORAGE_DAEMON_BINARY=./storage-daemon/qemu-storage-daemon ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 G_TEST_SLOW=1 RUST_BACKTRACE=1 /home/alex/lsrc/qemu.git/builds/all/tests/qtest/test-hmp --tap -p /mips64el/hmp/boston TAP version 14 # random seed: R02S0d3b1a4f1aef5198107851bdee539e7d # Start of mips64el tests # Start of hmp tests # starting QEMU: exec ./qemu-system-mips64el -qtest unix:/tmp/qtest-530181.sock -qtest-log /dev/null -chardev socket,path=/tmp/qtest-530181.qmp,id=char0 -mon chardev=char0,mode=control -display none -audio none -run-with exit-with-parent=on -S -M boston -accel qtest main_cpu_reset: dbg mips_gcr_reset: dbg mps_reset_exit: dbg ok 1 /mips64el/hmp/boston # End of hmp tests # End of mips64el tests 1..1
Cc: Peter Maydell <[email protected]>
Message-ID: <[email protected]>
---
v2
- use proper 3-phase reset
--- include/hw/mips/cps.h | 14 +++++++++++++- hw/mips/cps.c | 26 +++++++++++++++++--------- hw/misc/mips_cmgcr.c | 1 - 3 files changed, 30 insertions(+), 11 deletions(-)
include/hw/mips/cps.h +13 -1
@@ -30,7 +30,7 @@#include "qom/object.h" #define TYPE_MIPS_CPS "mips-cps" -OBJECT_DECLARE_SIMPLE_TYPE(MIPSCPSState, MIPS_CPS) +OBJECT_DECLARE_TYPE(MIPSCPSState, MIPSCPSClass, MIPS_CPS)struct MIPSCPSState {SysBusDevice parent_obj;
@@ -48,6 +48,18 @@ struct MIPSCPSState { Clock *clock; }; +/* +* MIPSCPSClass: +* @parent_phases: The parent class' reset phase handlers. +* +* A Coherent Processing System model. +*/ +struct MIPSCPSClass { +SysBusDeviceClass parent_class; + +ResettablePhases parent_phases; +}; +qemu_irq get_cps_irq (MIPSCPSState *cps,int pin_number);#endif
hw/mips/cps.c +17 -9
@@ -55,6 +55,17 @@ static void main_cpu_reset(void *opaque)cpu_reset (cs); } +static void mps_reset_exit (Object *obj,ResetType type) +{ +MIPSCPSState *s =MIPS_CPS (obj); +hwaddr gcr_base; + +/* Global Configuration Registers - only valid once the CPU has been reset */ + gcr_base =MIPS_CPU (first_cpu)->env.CP0_CMGCRBase <<4 ; +memory_region_add_subregion (&s->container, gcr_base, +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->gcr),0 )); +} +static bool cpu_mips_itu_supported (CPUMIPSState *env) {bool is_mt = (env->CP0_Config5 & (1 <<CP0C5_VP )) ||ase_mt_available (env);
@@ -65,7 +76,6 @@ static bool cpu_mips_itu_supported(CPUMIPSState *env)static void mips_cps_realize (DeviceState *dev,Error **errp) {MIPSCPSState *s =MIPS_CPS (dev); -target_ulong gcr_base;bool itu_present = false;if (!clock_get (s->clock)) {
@@ -144,16 +154,11 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (&s->container,0 ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->gic),0 )); -/* Global Configuration Registers */ - gcr_base =MIPS_CPU (first_cpu)->env.CP0_CMGCRBase <<4 ; -object_initialize_child (OBJECT (dev),"gcr" , &s->gcr,TYPE_MIPS_GCR );object_property_set_uint (OBJECT (&s->gcr),"num-vp" , s->num_vp, &error_abort);object_property_set_int (OBJECT (&s->gcr),"gcr-rev" ,0x800 , &error_abort); -object_property_set_int (OBJECT (&s->gcr),"gcr-base" , gcr_base, - &error_abort);object_property_set_link (OBJECT (&s->gcr),"gic" ,OBJECT (&s->gic.mr), &error_abort); object_property_set_link(OBJECT(&s->gcr), "cpc", OBJECT(&s->cpc.mr),
@@ -161,9 +166,6 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)if (!sysbus_realize (SYS_BUS_DEVICE (&s->gcr), errp)) {return ; } - -memory_region_add_subregion (&s->container, gcr_base, -sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->gcr),0 )); }static const Property mips_cps_properties[] = {
@@ -176,8 +178,13 @@ static const Property mips_cps_properties[] = {static void mips_cps_class_init (ObjectClass *klass,const void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +MIPSCPSClass *mcs =MIPS_CPS_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); dc->realize = mips_cps_realize; + +resettable_class_set_parent_phases (rc,NULL ,NULL , mps_reset_exit, + &mcs->parent_phases);device_class_set_props (dc, mips_cps_properties); }
@@ -187,6 +194,7 @@ static const TypeInfo mips_cps_info = { .instance_size = sizeof(MIPSCPSState), .instance_init = mips_cps_init, .class_init = mips_cps_class_init, + .class_size = sizeof(MIPSCPSClass), };static void mips_cps_register_types (void )
hw/misc/mips_cmgcr.c +0 -1
@@ -214,7 +214,6 @@ static const VMStateDescription vmstate_mips_gcr = {static const Property mips_gcr_properties[] = {DEFINE_PROP_UINT32 ("num-vp" , MIPSGCRState, num_vps,1 ),DEFINE_PROP_INT32 ("gcr-rev" , MIPSGCRState, gcr_rev,0x800 ), -DEFINE_PROP_UINT64 ("gcr-base" , MIPSGCRState, gcr_base,GCR_BASE_ADDR ),DEFINE_PROP_LINK ("gic" , MIPSGCRState, gic_mr,TYPE_MEMORY_REGION , MemoryRegion *), DEFINE_PROP_LINK("cpc", MIPSGCRState, cpc_mr, TYPE_MEMORY_REGION,
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 07/14] hw/mips: defer finalising gcr_base until reset time
Quoted 32 lines · Alex Bennée
Currently the
cpu_reset()inmips_cpu_realizefn()hides an implicit sequencing requirement when settinggcr_base. Without it we barf because we end up setting the region between 0x0-0x000000001fbfffff which trips over a qtest that accesses the GCR during "memsave 0 4096/dev/null".By moving to the reset phase we have to drop the property lest we are admonished for "Attempting to set...after it was realized" but there doesn't seem to be a need to expose the property anyway.
NB: it would be safer if I could guarantee the place in the reset tree but I haven't quite grokked how to do that yet. Currently I see this sequence when testing:
env MALLOC_PERTURB_=43 G_TEST_DBUS_DAEMON=/home/alex/lsrc/qemu.git/tests/dbus-vmstate-daemon.sh UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 QTEST_QEMU_IMG=./qemu-img QTEST_QEMU_BINARY=./qemu-system-mips64el SPEED=thorough MESON_TEST_ITERATION=1 MSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 PYTHON=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 QTEST_QEMU_STORAGE_DAEMON_BINARY=./storage-daemon/qemu-storage-daemon ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 G_TEST_SLOW=1 RUST_BACKTRACE=1 /home/alex/lsrc/qemu.git/builds/all/tests/qtest/test-hmp --tap -p /mips64el/hmp/boston TAP version 14 # random seed: R02S0d3b1a4f1aef5198107851bdee539e7d # Start of mips64el tests # Start of hmp tests # starting QEMU: exec ./qemu-system-mips64el -qtest unix:/tmp/qtest-530181.sock -qtest-log /dev/null -chardev socket,path=/tmp/qtest-530181.qmp,id=char0 -mon chardev=char0,mode=control -display none -audio none -run-with exit-with-parent=on -S -M boston -accel qtest main_cpu_reset: dbg mips_gcr_reset: dbg mps_reset_exit: dbg ok 1 /mips64el/hmp/boston # End of hmp tests # End of mips64el tests 1..1Cc: Peter Maydell <[email protected]>
Message-ID: <[email protected]>Signed-off-by Alex Bennée <[email protected]>
Quoted 9 lines
---
v2
- use proper 3-phase reset--- include/hw/mips/cps.h | 14 +++++++++++++- hw/mips/cps.c | 26 +++++++++++++++++--------- hw/misc/mips_cmgcr.c | 1 - 3 files changed, 30 insertions(+), 11 deletions(-)
Re: [RFC PATCH v2 07/14] hw/mips: defer finalising gcr_base until reset time
In reply to Alex BennéeQuoted 15 lines · Alex Bennée
Currently the
cpu_reset()inmips_cpu_realizefn()hides an implicit sequencing requirement when settinggcr_base. Without it we barf because we end up setting the region between 0x0-0x000000001fbfffff which trips over a qtest that accesses the GCR during "memsave 0 4096/dev/null".By moving to the reset phase we have to drop the property lest we are admonished for "Attempting to set...after it was realized" but there doesn't seem to be a need to expose the property anyway.
NB: it would be safer if I could guarantee the place in the reset tree but I haven't quite grokked how to do that yet. Currently I see this sequence when testing:
Quoted 9 lines
env MALLOC_PERTURB_=43 G_TEST_DBUS_DAEMON=/home/alex/lsrc/qemu.git/tests/dbus-vmstate-daemon.sh UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 QTEST_QEMU_IMG=./qemu-img QTEST_QEMU_BINARY=./qemu-system-mips64el SPEED=thorough MESON_TEST_ITERATION=1 MSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 PYTHON=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 QTEST_QEMU_STORAGE_DAEMON_BINARY=./storage-daemon/qemu-storage-daemon ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 G_TEST_SLOW=1 RUST_BACKTRACE=1 /home/alex/lsrc/qemu.git/builds/all/tests/qtest/test-hmp --tap -p /mips64el/hmp/boston TAP version 14 # random seed: R02S0d3b1a4f1aef5198107851bdee539e7d # Start of mips64el tests # Start of hmp tests # starting QEMU: exec ./qemu-system-mips64el -qtest unix:/tmp/qtest-530181.sock -qtest-log /dev/null -chardev socket,path=/tmp/qtest-530181.qmp,id=char0 -mon chardev=char0,mode=control -display none -audio none -run-with exit-with-parent=on -S -M boston -accel qtest main_cpu_reset: dbg mips_gcr_reset: dbg mps_reset_exit: dbg
This works because we call reset hooks in the order they're registered, and clearly the qemu_register_reset() in mips_cps_realize() gets in first.
To actually get the three-phase ordering so that the 'exit' phase hook you add in this patch definitely runs after the 'hold' phase of the CPU, you would need to stop using cpu_reset() and instead use
use qemu_register_resettable(OBJ(cpu));.
Quoted 57 lines
ok 1 /mips64el/hmp/boston
# End of hmp tests
# End of mips64el tests
1..1Cc: Peter Maydell <[email protected]>
Message-ID: <[email protected]>Signed-off-by Alex Bennée <[email protected]>---
v2
- use proper 3-phase reset--- include/hw/mips/cps.h | 14 +++++++++++++- hw/mips/cps.c | 26 +++++++++++++++++--------- hw/misc/mips_cmgcr.c | 1 - 3 files changed, 30 insertions(+), 11 deletions(-)include/hw/mips/cps.h +13
-1@@ -30,7 +30,7 @@#include "qom/object.h" #define TYPE_MIPS_CPS "mips-cps" -OBJECT_DECLARE_SIMPLE_TYPE(MIPSCPSState, MIPS_CPS) +OBJECT_DECLARE_TYPE(MIPSCPSState, MIPSCPSClass, MIPS_CPS)struct MIPSCPSState {SysBusDevice parent_obj;@@ -48,6 +48,18 @@ struct MIPSCPSState { Clock *clock; }; +/* +* MIPSCPSClass: +* @parent_phases: The parent class' reset phase handlers. +* +* A Coherent Processing System model. +*/ +struct MIPSCPSClass { +SysBusDeviceClass parent_class; + +ResettablePhases parent_phases; +}; +qemu_irq get_cps_irq (MIPSCPSState *cps,int pin_number);#endif hw/mips/cps.c +0
-0@@ -55,6 +55,17 @@ static void main_cpu_reset(void *opaque)cpu_reset (cs); }
hw/mips/cps.c static void main_cpu_reset(void *opaque) · line 66
Quoted 10 lines
hw/mips/cps.c +9
-0+static void mps_reset_exit (Object *obj,ResetType type) +{ +MIPSCPSState *s =MIPS_CPS (obj); +hwaddr gcr_base; + +/* Global Configuration Registers - only valid once the CPU has been reset */ + gcr_base =MIPS_CPU (first_cpu)->env.CP0_CMGCRBase <<4 ; +memory_region_add_subregion (&s->container, gcr_base, +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->gcr),0 ));
It still seems odd to me that we are messing with the GCR device in this CPS reset method. The TYPE_MIPS_GCR device (in hw/misc/mips_cmgcr.c) is the one that owns these memory regions and it has code that adjusts their addresses at runtime based on guest register writes. It would seem more logical to have the CPs code just set things up (e.g. map them at address 0) in realize, and then have the GCR device's reset (exit phase) set the address/enabled of the MRs according to their required state at reset.
thanks
-- PMM
RFC PATCH v2 8/14 hw/mips: drop cpu_reset in mips_cpu_realizefn
In reply to Alex BennéeWe will always do a cpu_reset during mips_cpu_reset_hold().
Message-ID: <[email protected]>
--- target/mips/cpu.c | 1 - 1 file changed, 1 deletion(-)
target/mips/cpu.c +0 -1
@@ -488,7 +488,6 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)fpu_init (env, env->cpu_model);mvp_init (env); -cpu_reset (cs);qemu_init_vcpu (cs); mcc->parent_realize (dev, errp);
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 08/14] hw/mips: drop cpu_reset in mips_cpu_realizefn
Quoted 8 lines · Alex Bennée
We will always do a
cpu_resetduringmips_cpu_reset_hold().Message-ID: <[email protected]>
Signed-off-by Alex Bennée <[email protected]>--- target/mips/cpu.c | 1 - 1 file changed, 1 deletion(-)
RFC PATCH v2 9/14 target/tricore: move cpu_reset from tricore_cpu_realizefn
In reply to Alex BennéeImplement a proper cpu reset handler for tricore cpus.
Message-ID: <[email protected]>
--- target/tricore/cpu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
target/tricore/cpu.c +8 -1
@@ -24,6 +24,7 @@#include "qemu/error-report.h" #include "tcg/debug-assert.h" #include "accel/tcg/cpu-ops.h" +#include "system/reset.h" static inline void set_feature (CPUTriCoreState *env,int feature) {
@@ -81,6 +82,12 @@ static void tricore_cpu_reset_hold(Object *obj, ResetType type)cpu_state_reset (cpu_env (cs)); } +static void tricore_cpu_reset (void *opaque) +{ +CPUState *cs = opaque; +cpu_reset (cs); +} +static bool tricore_cpu_has_work (CPUState *cs) {return true;
@@ -120,8 +127,8 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)if (tricore_has_feature (env,TRICORE_FEATURE_131 )) {set_feature (env,TRICORE_FEATURE_13 ); } -cpu_reset (cs);qemu_init_vcpu (cs); +qemu_register_reset (tricore_cpu_reset, cs); tcc->parent_realize (dev, errp); }
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 09/14] target/tricore: move cpu_reset from tricore_cpu_realizefn
Quoted 8 lines · Alex Bennée
Implement a proper cpu reset handler for tricore cpus.
Message-ID: <[email protected]>
Signed-off-by Alex Bennée <[email protected]>--- target/tricore/cpu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
Re: [RFC PATCH v2 09/14] target/tricore: move cpu_reset from tricore_cpu_realizefn
In reply to Alex BennéeQuoted 13 lines · Alex Bennée
Implement a proper cpu reset handler for tricore cpus.
Message-ID: <[email protected]>
Signed-off-by Alex Bennée <[email protected]>--- target/tricore/cpu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)static bool tricore_cpu_has_work(CPUState *cs) { return true;
target/tricore/cpu.c static void tricore_cpu_realizefn(DeviceState *dev, Error **errp) · line 131
Quoted 6 lines
target/tricore/cpu.c +1
-1@@ -120,8 +127,8 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)if (tricore_has_feature (env,TRICORE_FEATURE_131 )) {set_feature (env,TRICORE_FEATURE_13 ); } -cpu_reset (cs);qemu_init_vcpu (cs); +qemu_register_reset (tricore_cpu_reset, cs);
Per commit 9f1c70a2543 ("hw/core: Add documentation and license comments to reset.h"):
"In general this function should not be used in new code where possible"
Shouldn't we use qemu_register_resettable()?
Re: [RFC PATCH v2 09/14] target/tricore: move cpu_reset from tricore_cpu_realizefn
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Alex Bennée
Implement a proper cpu reset handler for tricore cpus.
Message-ID: <[email protected]>Signed-off-by Alex Bennée <[email protected]>--- target/tricore/cpu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)static bool tricore_cpu_has_work(CPUState *cs) { return true;target/tricore/cpu.c static void tricore_cpu_realizefn(DeviceState *dev, Error **errp) · line 131
Quoted 6 lines
target/tricore/cpu.c +1
-1@@ -120,8 +127,8 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)if (tricore_has_feature (env,TRICORE_FEATURE_131 )) {set_feature (env,TRICORE_FEATURE_13 ); } -cpu_reset (cs);qemu_init_vcpu (cs); +qemu_register_reset (tricore_cpu_reset, cs);Per commit
9f1c70a2543("hw/core: Add documentation and license comments toreset.h"):
Quoted 3 lines
"In general this function should not be used in new code where possible"
Shouldn't we use
qemu_register_resettable()?
Yes - I thought I checked them all but I must of missed tricore - will fix on next iteration.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [RFC PATCH v2 09/14] target/tricore: move cpu_reset from tricore_cpu_realizefn
In reply to Alex BennéeQuoted 35 lines · Alex Bennée
Implement a proper cpu reset handler for tricore cpus.
Message-ID: <[email protected]>
Signed-off-by Alex Bennée <[email protected]>--- target/tricore/cpu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)target/tricore/cpu.c +7
-0@@ -24,6 +24,7 @@#include "qemu/error-report.h" #include "tcg/debug-assert.h" #include "accel/tcg/cpu-ops.h" +#include "system/reset.h" static inline void set_feature (CPUTriCoreState *env,int feature) {@@ -81,6 +82,12 @@ static void tricore_cpu_reset_hold(Object *obj, ResetType type)cpu_state_reset (cpu_env (cs)); } +static void tricore_cpu_reset (void *opaque) +{ +CPUState *cs = opaque; +cpu_reset (cs); +} +static bool tricore_cpu_has_work (CPUState *cs) {return true;
target/tricore/cpu.c static void tricore_cpu_realizefn(DeviceState *dev, Error **errp) · line 131
Quoted 6 lines
target/tricore/cpu.c +1
-1@@ -120,8 +127,8 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)if (tricore_has_feature (env,TRICORE_FEATURE_131 )) {set_feature (env,TRICORE_FEATURE_13 ); } -cpu_reset (cs);qemu_init_vcpu (cs); +qemu_register_reset (tricore_cpu_reset, cs);
We should arrange for CPUs to be reset in the board code, not in the realize function of the CPU itself.
thanks
-- PMM
RFC PATCH v2 10/14 target/arm: remove extraneous cpu_reset from realizefn
In reply to Alex BennéeWe already have do_cpu_reset called when the system is reset so there is no need to do it here.
By removing this we now only do (smp*2)-1 calls to cpu_reset. Once per core as part of qemu_system_reset and then once per secondary core as PSCI calls are made to reset them.
Message-ID: <[email protected]>
--- target/arm/cpu.c | 1 - 1 file changed, 1 deletion(-)
target/arm/cpu.c +0 -1
@@ -2198,7 +2198,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) }qemu_init_vcpu (cs); -cpu_reset (cs); acc->parent_realize (dev, errp); }
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 10/14] target/arm: remove extraneous cpu_reset from realizefn
Quoted 7 lines · Alex Bennée
We already have
do_cpu_resetcalled when the system is reset so there is no need to do it here.By removing this we now only do (smp*2)-1 calls to
cpu_reset. Once per core as part ofqemu_system_resetand then once per secondary core as PSCI calls are made to reset them.
Quoted 6 lines
Message-ID: <[email protected]>
Signed-off-by Alex Bennée <[email protected]>--- target/arm/cpu.c | 1 - 1 file changed, 1 deletion(-)
Re: [RFC PATCH v2 10/14] target/arm: remove extraneous cpu_reset from realizefn
In reply to Alex BennéeQuoted 19 lines · Alex Bennée
We already have
do_cpu_resetcalled when the system is reset so there is no need to do it here.By removing this we now only do (smp*2)-1 calls to
cpu_reset. Once per core as part ofqemu_system_resetand then once per secondary core as PSCI calls are made to reset them.Message-ID: <[email protected]>
Signed-off-by Alex Bennée <[email protected]>--- target/arm/cpu.c | 1 - 1 file changed, 1 deletion(-)target/arm/cpu.c +0
-0
target/arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 2203
Quoted 7 lines
target/arm/cpu.c +0
-1@@ -2198,7 +2198,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) }qemu_init_vcpu (cs); -cpu_reset (cs); acc->parent_realize (dev, errp); }
though it would not surprise me if there was some obscure ordering requirement that we run into by removing this. I guess we'll have to wait for the bug reports :-)
thanks
-- PMM
RFC PATCH v2 11/14 hw/alpha: remove unused includes
In reply to Alex Bennée--- hw/alpha/dp264.c | 2 -- 1 file changed, 2 deletions(-)
hw/alpha/dp264.c +0 -2
@@ -16,8 +16,6 @@#include "hw/rtc/mc146818rtc.h" #include "hw/ide/pci.h" #include "hw/isa/superio.h" -#include "net/net.h" -#include "qemu/cutils.h" #include "qemu/datadir.h" static uint64_t cpu_alpha_superpage_to_phys (void *opaque,uint64_t addr)
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 11/14] hw/alpha: remove unused includes
Quoted 5 lines · Alex Bennée
Signed-off-by Alex Bennée <[email protected]>--- hw/alpha/dp264.c | 2 -- 1 file changed, 2 deletions(-)
RFC PATCH v2 12/14 hw/alpha: add a reset function for the clipper machine
In reply to Alex BennéeOnce this is setup we can move CPU reset to a 3-phase reset handler.
--- hw/alpha/dp264.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/alpha/dp264.c +10 -0
@@ -17,6 +17,7 @@#include "hw/ide/pci.h" #include "hw/isa/superio.h" #include "qemu/datadir.h" +#include "system/reset.h" static uint64_t cpu_alpha_superpage_to_phys (void *opaque,uint64_t addr) {
@@ -42,6 +43,14 @@ static int clipper_pci_map_irq(PCIDevice *d, int irq_num)return (slot +1 ) *4 + irq_num; } +static void clipper_reset (MachineState *ms,ResetType type) +{ +CPUState *cs = first_cpu; + +qemu_devices_reset (type); +cpu_reset (cs); +} +static void clipper_init (MachineState *machine) {ram_addr_t ram_size = machine->ram_size;
@@ -205,6 +214,7 @@ static void clipper_machine_init(MachineClass *mc) { mc->desc ="Alpha DP264/CLIPPER" ; mc->init = clipper_init; + mc->reset = clipper_reset; mc->block_default_type =IF_IDE ; mc->max_cpus =4 ; mc->is_default = true;
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 12/14] hw/alpha: add a reset function for the clipper machine
Quoted 7 lines · Alex Bennée
Once this is setup we can move CPU reset to a 3-phase reset handler.
Signed-off-by Alex Bennée <[email protected]>--- hw/alpha/dp264.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
RFC PATCH v2 13/14 target/alpha: move cpu reset into a proper reset function
In reply to Alex BennéeNow the alpha clipper machine will execute a proper reset we can use the reset mechanisms to reset the CPU.
--- target/alpha/cpu.h | 2 ++ target/alpha/cpu.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-)
target/alpha/cpu.h +2 -0
@@ -269,6 +269,7 @@ struct ArchCPU {/** * AlphaCPUClass: * @parent_realize: The parent class' realize handler. +* @parent_phases: The parent class' reset phase handlers. * * An Alpha CPU model. */
@@ -276,6 +277,7 @@ struct AlphaCPUClass {CPUClass parent_class;DeviceRealize parent_realize; +ResettablePhases parent_phases; };#ifndef CONFIG_USER_ONLY
target/alpha/cpu.c +6 -4
@@ -202,12 +202,10 @@ static void ev67_cpu_initfn(Object *obj)cpu_env (CPU (obj))->amask |=AMASK_CIX |AMASK_PREFETCH ; } -static void alpha_cpu_initfn (Object *obj) +static void alpha_cpu_reset_exit (Object *obj,ResetType type) {CPUAlphaState *env =cpu_env (CPU (obj)); -/* TODO all this should be done in reset, not init */ - env->lock_addr =-1 ;/*
@@ -277,10 +275,15 @@ static void alpha_cpu_class_init(ObjectClass *oc, const void *data)DeviceClass *dc =DEVICE_CLASS (oc);CPUClass *cc =CPU_CLASS (oc);AlphaCPUClass *acc =ALPHA_CPU_CLASS (oc); +ResettableClass *rc =RESETTABLE_CLASS (oc);device_class_set_parent_realize (dc, alpha_cpu_realizefn, &acc->parent_realize); +resettable_class_set_parent_phases (rc, +NULL ,NULL , alpha_cpu_reset_exit, + &acc->parent_phases); + cc->class_by_name = alpha_cpu_class_by_name; cc->dump_state = alpha_cpu_dump_state; cc->set_pc = alpha_cpu_set_pc;
@@ -311,7 +314,6 @@ static const TypeInfo alpha_cpu_type_infos[] = { .parent = TYPE_CPU, .instance_size = sizeof(AlphaCPU), .instance_align = __alignof(AlphaCPU), - .instance_init = alpha_cpu_initfn, .abstract = true, .class_size = sizeof(AlphaCPUClass), .class_init = alpha_cpu_class_init,
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 13/14] target/alpha: move cpu reset into a proper reset function
Quoted 9 lines · Alex Bennée
Now the alpha clipper machine will execute a proper reset we can use the reset mechanisms to reset the CPU.
Signed-off-by Alex Bennée <[email protected]>--- target/alpha/cpu.h | 2 ++ target/alpha/cpu.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-)
Re: [RFC PATCH v2 13/14] target/alpha: move cpu reset into a proper reset function
In reply to Alex BennéeQuoted 3 lines · Alex Bennée
Now the alpha clipper machine will execute a proper reset we can use the reset mechanisms to reset the CPU.
(for fun),
https://www.reddit.com/r/memes/comments/1q97e3d/heard_you_like_the_meme_reset/
:)
Pierrick
Re: [RFC PATCH v2 13/14] target/alpha: move cpu reset into a proper reset function
In reply to Alex BennéeQuoted 12 lines · Alex Bennée
Now the alpha clipper machine will execute a proper reset we can use the reset mechanisms to reset the CPU.
Signed-off-by Alex Bennée <[email protected]>--- target/alpha/cpu.h | 2 ++ target/alpha/cpu.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-)
target/alpha/cpu.c static void ev67_cpu_initfn(Object *obj) · line 205
Quoted 2 lines
target/alpha/cpu.c +1
-1-static void alpha_cpu_initfn (Object *obj) +static void alpha_cpu_reset_exit (Object *obj,ResetType type)
This should be the 'hold' phase, not the 'exit' one. (The general rule is that "most" stuff happens in 'hold'; 'exit' and 'enter' are for special cases.)
thanks
-- PMM
RFC PATCH v2 14/14 include/hw: expand cpu_reset function docs
In reply to Alex BennéeAdd a hint to the developer that this should only be called from a reset chain.
Message-ID: <[email protected]>
--- include/hw/core/cpu.h | 3 +++ 1 file changed, 3 insertions(+)
include/hw/core/cpu.h +3 -0
@@ -815,6 +815,9 @@ void cpu_list_remove(CPUState *cpu);/** * cpu_reset: * @cpu: The CPU whose state is to be reset. +* +* You should refrain from calling this during CPU realization and +* make sure this is called from the reset logic instead. */ void cpu_reset (CPUState *cpu);
Signature · 1 line
2.47.3
Re: [RFC PATCH v2 14/14] include/hw: expand cpu_reset function docs
Quoted 10 lines · Alex Bennée
Add a hint to the developer that this should only be called from a reset chain.
Reviewed-by Richard Henderson <[email protected]>Message-ID: <[email protected]>
Signed-off-by Alex Bennée <[email protected]>--- include/hw/core/cpu.h | 3 +++ 1 file changed, 3 insertions(+)