[RFC PATCH v2 09/14] target/tricore: move cpu_reset from tricore_cpu_realizefn

Alex Bennée posted 14 patches 1 month, 3 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Thomas Huth <huth@tuxfamily.org>, Laurent Vivier <laurent@vivier.eu>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Peter Maydell <peter.maydell@linaro.org>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Bastian Koppelmann <kbastian@rumtueddeln.de>
[RFC PATCH v2 09/14] target/tricore: move cpu_reset from tricore_cpu_realizefn
Posted by Alex Bennée 1 month, 3 weeks ago
Implement a proper cpu reset handler for tricore cpus.

Message-ID: <20260108143423.1378674-11-alex.bennee@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 target/tricore/cpu.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index 04319e107ba..c3dda9f6a54 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -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);
 }
-- 
2.47.3


Re: [RFC PATCH v2 09/14] target/tricore: move cpu_reset from tricore_cpu_realizefn
Posted by Peter Maydell 1 month, 2 weeks ago
On Thu, 19 Feb 2026 at 17:18, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> Implement a proper cpu reset handler for tricore cpus.
>
> Message-ID: <20260108143423.1378674-11-alex.bennee@linaro.org>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  target/tricore/cpu.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
> index 04319e107ba..c3dda9f6a54 100644
> --- a/target/tricore/cpu.c
> +++ b/target/tricore/cpu.c
> @@ -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);


We should arrange for CPUs to be reset in the board code, not in
the realize function of the CPU itself.

thanks
-- PMM
Re: [RFC PATCH v2 09/14] target/tricore: move cpu_reset from tricore_cpu_realizefn
Posted by Philippe Mathieu-Daudé 1 month, 2 weeks ago
On 19/2/26 18:18, Alex Bennée wrote:
> Implement a proper cpu reset handler for tricore cpus.
> 
> Message-ID: <20260108143423.1378674-11-alex.bennee@linaro.org>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   target/tricore/cpu.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)


>   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);

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
Posted by Alex Bennée 1 month, 2 weeks ago
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> On 19/2/26 18:18, Alex Bennée wrote:
>> Implement a proper cpu reset handler for tricore cpus.
>> Message-ID: <20260108143423.1378674-11-alex.bennee@linaro.org>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>>   target/tricore/cpu.c | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>
>
>>   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);
>
> 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()?

Yes - I thought I checked them all but I must of missed tricore - will
fix on next iteration.

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [RFC PATCH v2 09/14] target/tricore: move cpu_reset from tricore_cpu_realizefn
Posted by Pierrick Bouvier 1 month, 3 weeks ago
On 2/19/26 9:18 AM, Alex Bennée wrote:
> Implement a proper cpu reset handler for tricore cpus.
> 
> Message-ID: <20260108143423.1378674-11-alex.bennee@linaro.org>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   target/tricore/cpu.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>