[PATCH 3/5] hw/intc/loongarch_extioi: Replace legacy reset callback with new api

Bibo Mao posted 5 patches 8 months, 2 weeks ago
[PATCH 3/5] hw/intc/loongarch_extioi: Replace legacy reset callback with new api
Posted by Bibo Mao 8 months, 2 weeks ago
Replace legacy reset callback register device_class_set_legacy_reset()
with new function resettable_class_set_parent_phases(). With new API,
it will call reset callback of parent object and then itself.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 hw/intc/loongarch_extioi.c         | 12 ++++++++----
 include/hw/intc/loongarch_extioi.h |  1 +
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
index a51a215e6e..0fecc62a09 100644
--- a/hw/intc/loongarch_extioi.c
+++ b/hw/intc/loongarch_extioi.c
@@ -377,11 +377,13 @@ static void loongarch_extioi_unrealize(DeviceState *dev)
     g_free(s->cpu);
 }
 
-static void loongarch_extioi_reset(DeviceState *d)
+static void loongarch_extioi_reset_hold(Object *obj, ResetType type)
 {
-    LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(d);
+    LoongArchExtIOIClass *lec = LOONGARCH_EXTIOI_GET_CLASS(obj);
 
-    s->status = 0;
+    if (lec->parent_phases.hold) {
+        lec->parent_phases.hold(obj, type);
+    }
 }
 
 static int vmstate_extioi_post_load(void *opaque, int version_id)
@@ -406,12 +408,14 @@ static void loongarch_extioi_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     LoongArchExtIOIClass *lec = LOONGARCH_EXTIOI_CLASS(klass);
     LoongArchExtIOICommonClass *lecc = LOONGARCH_EXTIOI_COMMON_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     device_class_set_parent_realize(dc, loongarch_extioi_realize,
                                     &lec->parent_realize);
     device_class_set_parent_unrealize(dc, loongarch_extioi_unrealize,
                                       &lec->parent_unrealize);
-    device_class_set_legacy_reset(dc, loongarch_extioi_reset);
+    resettable_class_set_parent_phases(rc, NULL, loongarch_extioi_reset_hold,
+                                       NULL, &lec->parent_phases);
     lecc->post_load = vmstate_extioi_post_load;
 }
 
diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h
index 351f18afcf..4a6ae903e9 100644
--- a/include/hw/intc/loongarch_extioi.h
+++ b/include/hw/intc/loongarch_extioi.h
@@ -22,6 +22,7 @@ struct LoongArchExtIOIClass {
 
     DeviceRealize parent_realize;
     DeviceUnrealize parent_unrealize;
+    ResettablePhases parent_phases;
 };
 
 #endif /* LOONGARCH_EXTIOI_H */
-- 
2.39.3
Re: [PATCH 3/5] hw/intc/loongarch_extioi: Replace legacy reset callback with new api
Posted by gaosong 8 months ago
在 2025/3/7 下午3:13, Bibo Mao 写道:
> Replace legacy reset callback register device_class_set_legacy_reset()
> with new function resettable_class_set_parent_phases(). With new API,
> it will call reset callback of parent object and then itself.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   hw/intc/loongarch_extioi.c         | 12 ++++++++----
>   include/hw/intc/loongarch_extioi.h |  1 +
>   2 files changed, 9 insertions(+), 4 deletions(-)
Reviewed-by: Song Gao <gaosong@loongson.cn>

thanks.
Song Gao
> diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
> index a51a215e6e..0fecc62a09 100644
> --- a/hw/intc/loongarch_extioi.c
> +++ b/hw/intc/loongarch_extioi.c
> @@ -377,11 +377,13 @@ static void loongarch_extioi_unrealize(DeviceState *dev)
>       g_free(s->cpu);
>   }
>   
> -static void loongarch_extioi_reset(DeviceState *d)
> +static void loongarch_extioi_reset_hold(Object *obj, ResetType type)
>   {
> -    LoongArchExtIOICommonState *s = LOONGARCH_EXTIOI_COMMON(d);
> +    LoongArchExtIOIClass *lec = LOONGARCH_EXTIOI_GET_CLASS(obj);
>   
> -    s->status = 0;
> +    if (lec->parent_phases.hold) {
> +        lec->parent_phases.hold(obj, type);
> +    }
>   }
>   
>   static int vmstate_extioi_post_load(void *opaque, int version_id)
> @@ -406,12 +408,14 @@ static void loongarch_extioi_class_init(ObjectClass *klass, void *data)
>       DeviceClass *dc = DEVICE_CLASS(klass);
>       LoongArchExtIOIClass *lec = LOONGARCH_EXTIOI_CLASS(klass);
>       LoongArchExtIOICommonClass *lecc = LOONGARCH_EXTIOI_COMMON_CLASS(klass);
> +    ResettableClass *rc = RESETTABLE_CLASS(klass);
>   
>       device_class_set_parent_realize(dc, loongarch_extioi_realize,
>                                       &lec->parent_realize);
>       device_class_set_parent_unrealize(dc, loongarch_extioi_unrealize,
>                                         &lec->parent_unrealize);
> -    device_class_set_legacy_reset(dc, loongarch_extioi_reset);
> +    resettable_class_set_parent_phases(rc, NULL, loongarch_extioi_reset_hold,
> +                                       NULL, &lec->parent_phases);
>       lecc->post_load = vmstate_extioi_post_load;
>   }
>   
> diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h
> index 351f18afcf..4a6ae903e9 100644
> --- a/include/hw/intc/loongarch_extioi.h
> +++ b/include/hw/intc/loongarch_extioi.h
> @@ -22,6 +22,7 @@ struct LoongArchExtIOIClass {
>   
>       DeviceRealize parent_realize;
>       DeviceUnrealize parent_unrealize;
> +    ResettablePhases parent_phases;
>   };
>   
>   #endif /* LOONGARCH_EXTIOI_H */