Add reset support with ipi object, register reset callback and clear
internal registers when virt machine resets.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
hw/intc/loongarch_ipi.c | 29 +++++++++++++++++++++++++++++
include/hw/intc/loongarch_ipi.h | 1 +
2 files changed, 30 insertions(+)
diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c
index b10641dd03..f12c0549f3 100644
--- a/hw/intc/loongarch_ipi.c
+++ b/hw/intc/loongarch_ipi.c
@@ -93,6 +93,32 @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp)
}
}
+static void loongarch_ipi_reset_hold(Object *obj, ResetType type)
+{
+ int i;
+ LoongarchIPIClass *lic = LOONGARCH_IPI_GET_CLASS(obj);
+ LoongsonIPICommonState *lics = LOONGSON_IPI_COMMON(obj);
+ IPICore *core;
+
+ if (lic->parent_phases.hold) {
+ lic->parent_phases.hold(obj, type);
+ }
+
+ for (i = 0; i < lics->num_cpu; i++) {
+ core = lics->cpu + i;
+ /* IPI with targeted CPU available however not present */
+ if (!core->cpu) {
+ continue;
+ }
+
+ core->status = 0;
+ core->en = 0;
+ core->set = 0;
+ core->clear = 0;
+ memset(core->buf, 0, sizeof(core->buf));
+ }
+}
+
static void loongarch_ipi_cpu_plug(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
{
@@ -145,10 +171,13 @@ static void loongarch_ipi_class_init(ObjectClass *klass, void *data)
LoongsonIPICommonClass *licc = LOONGSON_IPI_COMMON_CLASS(klass);
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
LoongarchIPIClass *lic = LOONGARCH_IPI_CLASS(klass);
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
device_class_set_parent_realize(dc, loongarch_ipi_realize,
&lic->parent_realize);
+ resettable_class_set_parent_phases(rc, NULL, loongarch_ipi_reset_hold,
+ NULL, &lic->parent_phases);
licc->get_iocsr_as = get_iocsr_as;
licc->cpu_by_arch_id = loongarch_cpu_by_arch_id;
hc->plug = loongarch_ipi_cpu_plug;
diff --git a/include/hw/intc/loongarch_ipi.h b/include/hw/intc/loongarch_ipi.h
index 923bf21ecb..a7c6bf85d3 100644
--- a/include/hw/intc/loongarch_ipi.h
+++ b/include/hw/intc/loongarch_ipi.h
@@ -21,6 +21,7 @@ struct LoongarchIPIState {
struct LoongarchIPIClass {
LoongsonIPICommonClass parent_class;
DeviceRealize parent_realize;
+ ResettablePhases parent_phases;
};
#endif
--
2.39.3
在 2025/3/7 下午3:13, Bibo Mao 写道:
> Add reset support with ipi object, register reset callback and clear
> internal registers when virt machine resets.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> hw/intc/loongarch_ipi.c | 29 +++++++++++++++++++++++++++++
> include/hw/intc/loongarch_ipi.h | 1 +
> 2 files changed, 30 insertions(+)
Reviewed-by: Song Gao <gaosong@loongson.cn>
Thanks.
Song Gao
> diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c
> index b10641dd03..f12c0549f3 100644
> --- a/hw/intc/loongarch_ipi.c
> +++ b/hw/intc/loongarch_ipi.c
> @@ -93,6 +93,32 @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp)
> }
> }
>
> +static void loongarch_ipi_reset_hold(Object *obj, ResetType type)
> +{
> + int i;
> + LoongarchIPIClass *lic = LOONGARCH_IPI_GET_CLASS(obj);
> + LoongsonIPICommonState *lics = LOONGSON_IPI_COMMON(obj);
> + IPICore *core;
> +
> + if (lic->parent_phases.hold) {
> + lic->parent_phases.hold(obj, type);
> + }
> +
> + for (i = 0; i < lics->num_cpu; i++) {
> + core = lics->cpu + i;
> + /* IPI with targeted CPU available however not present */
> + if (!core->cpu) {
> + continue;
> + }
> +
> + core->status = 0;
> + core->en = 0;
> + core->set = 0;
> + core->clear = 0;
> + memset(core->buf, 0, sizeof(core->buf));
> + }
> +}
> +
> static void loongarch_ipi_cpu_plug(HotplugHandler *hotplug_dev,
> DeviceState *dev, Error **errp)
> {
> @@ -145,10 +171,13 @@ static void loongarch_ipi_class_init(ObjectClass *klass, void *data)
> LoongsonIPICommonClass *licc = LOONGSON_IPI_COMMON_CLASS(klass);
> HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
> LoongarchIPIClass *lic = LOONGARCH_IPI_CLASS(klass);
> + ResettableClass *rc = RESETTABLE_CLASS(klass);
> DeviceClass *dc = DEVICE_CLASS(klass);
>
> device_class_set_parent_realize(dc, loongarch_ipi_realize,
> &lic->parent_realize);
> + resettable_class_set_parent_phases(rc, NULL, loongarch_ipi_reset_hold,
> + NULL, &lic->parent_phases);
> licc->get_iocsr_as = get_iocsr_as;
> licc->cpu_by_arch_id = loongarch_cpu_by_arch_id;
> hc->plug = loongarch_ipi_cpu_plug;
> diff --git a/include/hw/intc/loongarch_ipi.h b/include/hw/intc/loongarch_ipi.h
> index 923bf21ecb..a7c6bf85d3 100644
> --- a/include/hw/intc/loongarch_ipi.h
> +++ b/include/hw/intc/loongarch_ipi.h
> @@ -21,6 +21,7 @@ struct LoongarchIPIState {
> struct LoongarchIPIClass {
> LoongsonIPICommonClass parent_class;
> DeviceRealize parent_realize;
> + ResettablePhases parent_phases;
> };
>
> #endif
© 2016 - 2025 Red Hat, Inc.