diff mbox series

[PULL,05/18] hw/intc/loongarch_pch: Move some functions to file loongarch_pic_common

Message ID 20241219075502.3164644-6-maobibo@loongson.cn (mailing list archive)
State New
Headers show
Series [PULL,01/18] include: Add loongarch_pic_common header file | expand

Commit Message

Bibo Mao Dec. 19, 2024, 7:54 a.m. UTC
Move some common functions to file loongarch_pic_common.c, the common
functions include loongarch_pic_common_realize(), property structure
loongarch_pic_common_properties and vmstate structure
vmstate_loongarch_pic_common.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Reviewed-by: Song Gao <gaosong@loongson.cn>
---
 hw/intc/loongarch_pch_pic.c    | 37 +-----------------------------
 hw/intc/loongarch_pic_common.c | 41 ++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 36 deletions(-)
 create mode 100644 hw/intc/loongarch_pic_common.c
diff mbox series

Patch

diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c
index 60a1e82253..25c612b366 100644
--- a/hw/intc/loongarch_pch_pic.c
+++ b/hw/intc/loongarch_pch_pic.c
@@ -379,16 +379,7 @@  static void loongarch_pch_pic_reset(DeviceState *d)
     s->int_polarity = 0x0;
 }
 
-static void loongarch_pic_common_realize(DeviceState *dev, Error **errp)
-{
-    LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev);
-
-    if (!s->irq_num || s->irq_num  > VIRT_PCH_PIC_IRQ_NUM) {
-        error_setg(errp, "Invalid 'pic_irq_num'");
-        return;
-    }
-}
-
+#include "loongarch_pic_common.c"
 static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
 {
     LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev);
@@ -417,32 +408,6 @@  static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
 
 }
 
-static const Property loongarch_pic_common_properties[] = {
-    DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static const VMStateDescription vmstate_loongarch_pic_common = {
-    .name = "loongarch_pch_pic",
-    .version_id = 1,
-    .minimum_version_id = 1,
-    .fields = (const VMStateField[]) {
-        VMSTATE_UINT64(int_mask, LoongArchPICCommonState),
-        VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState),
-        VMSTATE_UINT64(intedge, LoongArchPICCommonState),
-        VMSTATE_UINT64(intclr, LoongArchPICCommonState),
-        VMSTATE_UINT64(auto_crtl0, LoongArchPICCommonState),
-        VMSTATE_UINT64(auto_crtl1, LoongArchPICCommonState),
-        VMSTATE_UINT8_ARRAY(route_entry, LoongArchPICCommonState, 64),
-        VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPICCommonState, 64),
-        VMSTATE_UINT64(last_intirr, LoongArchPICCommonState),
-        VMSTATE_UINT64(intirr, LoongArchPICCommonState),
-        VMSTATE_UINT64(intisr, LoongArchPICCommonState),
-        VMSTATE_UINT64(int_polarity, LoongArchPICCommonState),
-        VMSTATE_END_OF_LIST()
-    }
-};
-
 static void loongarch_pch_pic_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
diff --git a/hw/intc/loongarch_pic_common.c b/hw/intc/loongarch_pic_common.c
new file mode 100644
index 0000000000..ff8ebff93f
--- /dev/null
+++ b/hw/intc/loongarch_pic_common.c
@@ -0,0 +1,41 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * QEMU Loongson 7A1000 I/O interrupt controller.
+ * Copyright (C) 2024 Loongson Technology Corporation Limited
+ */
+
+static void loongarch_pic_common_realize(DeviceState *dev, Error **errp)
+{
+    LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev);
+
+    if (!s->irq_num || s->irq_num  > VIRT_PCH_PIC_IRQ_NUM) {
+        error_setg(errp, "Invalid 'pic_irq_num'");
+        return;
+    }
+}
+
+static const Property loongarch_pic_common_properties[] = {
+    DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static const VMStateDescription vmstate_loongarch_pic_common = {
+    .name = "loongarch_pch_pic",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT64(int_mask, LoongArchPICCommonState),
+        VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState),
+        VMSTATE_UINT64(intedge, LoongArchPICCommonState),
+        VMSTATE_UINT64(intclr, LoongArchPICCommonState),
+        VMSTATE_UINT64(auto_crtl0, LoongArchPICCommonState),
+        VMSTATE_UINT64(auto_crtl1, LoongArchPICCommonState),
+        VMSTATE_UINT8_ARRAY(route_entry, LoongArchPICCommonState, 64),
+        VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPICCommonState, 64),
+        VMSTATE_UINT64(last_intirr, LoongArchPICCommonState),
+        VMSTATE_UINT64(intirr, LoongArchPICCommonState),
+        VMSTATE_UINT64(intisr, LoongArchPICCommonState),
+        VMSTATE_UINT64(int_polarity, LoongArchPICCommonState),
+        VMSTATE_END_OF_LIST()
+    }
+};