From nobody Sat Nov 23 22:03:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731053981795294.0110743268639; Fri, 8 Nov 2024 00:19:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9KCX-0001NG-F8; Fri, 08 Nov 2024 03:18:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9KBM-00005y-5S for qemu-devel@nongnu.org; Fri, 08 Nov 2024 03:17:29 -0500 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9KBH-0005gY-23 for qemu-devel@nongnu.org; Fri, 08 Nov 2024 03:17:26 -0500 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8DxmeANyS1nrC85AA--.47061S3; Fri, 08 Nov 2024 16:17:17 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowMDxxsAIyS1nea9MAA--.4604S10; Fri, 08 Nov 2024 16:17:16 +0800 (CST) From: Bibo Mao To: Song Gao Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v2 08/10] hw/intc/loongarch_extioi: Inherit from loongarch_extioi_common Date: Fri, 8 Nov 2024 16:17:10 +0800 Message-Id: <20241108081712.632890-9-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20241108081712.632890-1-maobibo@loongson.cn> References: <20241108081712.632890-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowMDxxsAIyS1nea9MAA--.4604S10 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1731053983875116600 Content-Type: text/plain; charset="utf-8" Set TYPE_LOONGARCH_EXTIOI inherit from TYPE_LOONGARCH_EXTIOI_COMMON object, it shares vmsate and property of TYPE_LOONGARCH_EXTIOI_COMMON, and has its own realize() function. Signed-off-by: Bibo Mao --- hw/intc/loongarch_extioi.c | 37 ++++++++++----------- hw/intc/loongarch_extioi_common.c | 39 ++++++++++++++++++++++- hw/intc/meson.build | 2 +- include/hw/intc/loongarch_extioi.h | 17 ++++++++-- include/hw/intc/loongarch_extioi_common.h | 12 +++++++ 5 files changed, 83 insertions(+), 24 deletions(-) diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c index a6f489b885..adaf9dc2c5 100644 --- a/hw/intc/loongarch_extioi.c +++ b/hw/intc/loongarch_extioi.c @@ -323,17 +323,15 @@ static const MemoryRegionOps extioi_virt_ops =3D { .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 -static int vmstate_extioi_post_load(void *opaque, int version_id); -#include "loongarch_extioi_common.c" - static void loongarch_extioi_realize(DeviceState *dev, Error **errp) { - LoongArchExtIOI *s =3D LOONGARCH_EXTIOI(dev); + LoongArchExtIOICommonState *s =3D LOONGARCH_EXTIOI_COMMON(dev); + LoongArchExtIOIClass *lec =3D LOONGARCH_EXTIOI_GET_CLASS(dev); SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); Error *local_err =3D NULL; int i, pin; =20 - loongarch_extioi_common_realize(dev, &local_err); + lec->parent_realize(dev, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -404,24 +402,23 @@ static int vmstate_extioi_post_load(void *opaque, int= version_id) static void loongarch_extioi_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); + LoongArchExtIOIClass *lec =3D LOONGARCH_EXTIOI_CLASS(klass); + LoongArchExtIOICommonClass *lecc =3D LOONGARCH_EXTIOI_COMMON_CLASS(kla= ss); =20 - dc->realize =3D loongarch_extioi_realize; - dc->unrealize =3D loongarch_extioi_unrealize; + 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); - device_class_set_props(dc, extioi_properties); - dc->vmsd =3D &vmstate_loongarch_extioi; + lecc->post_load =3D vmstate_extioi_post_load; } =20 -static const TypeInfo loongarch_extioi_info =3D { - .name =3D TYPE_LOONGARCH_EXTIOI, - .parent =3D TYPE_SYS_BUS_DEVICE, - .instance_size =3D sizeof(struct LoongArchExtIOI), - .class_init =3D loongarch_extioi_class_init, +static const TypeInfo loongarch_extioi_types[] =3D { + { + .name =3D TYPE_LOONGARCH_EXTIOI, + .parent =3D TYPE_LOONGARCH_EXTIOI_COMMON, + .class_init =3D loongarch_extioi_class_init, + } }; =20 -static void loongarch_extioi_register_types(void) -{ - type_register_static(&loongarch_extioi_info); -} - -type_init(loongarch_extioi_register_types) +DEFINE_TYPES(loongarch_extioi_types) diff --git a/hw/intc/loongarch_extioi_common.c b/hw/intc/loongarch_extioi_c= ommon.c index 13f02fc5ab..af15ec3531 100644 --- a/hw/intc/loongarch_extioi_common.c +++ b/hw/intc/loongarch_extioi_common.c @@ -3,6 +3,12 @@ * Loongson extioi interrupt controller emulation * Copyright (C) 2024 Loongson Technology Corporation Limited */ +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/intc/loongarch_extioi_common.h" +#include "migration/vmstate.h" =20 static void loongarch_extioi_common_realize(DeviceState *dev, Error **errp) { @@ -16,7 +22,14 @@ static void loongarch_extioi_common_realize(DeviceState = *dev, Error **errp) =20 static int loongarch_extioi_common_post_load(void *opaque, int version_id) { - return vmstate_extioi_post_load(opaque, version_id); + LoongArchExtIOICommonState *s =3D (LoongArchExtIOICommonState *)opaque; + LoongArchExtIOICommonClass *lecc =3D LOONGARCH_EXTIOI_COMMON_GET_CLASS= (s); + + if (lecc->post_load) { + return lecc->post_load(s, version_id); + } + + return 0; } =20 static const VMStateDescription vmstate_extioi_core =3D { @@ -61,3 +74,27 @@ static Property extioi_properties[] =3D { features, EXTIOI_HAS_VIRT_EXTENSION, 0), DEFINE_PROP_END_OF_LIST(), }; + +static void loongarch_extioi_common_class_init(ObjectClass *klass, void *d= ata) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + LoongArchExtIOICommonClass *lecc =3D LOONGARCH_EXTIOI_COMMON_CLASS(kla= ss); + + device_class_set_parent_realize(dc, loongarch_extioi_common_realize, + &lecc->parent_realize); + device_class_set_props(dc, extioi_properties); + dc->vmsd =3D &vmstate_loongarch_extioi; +} + +static const TypeInfo loongarch_extioi_common_types[] =3D { + { + .name =3D TYPE_LOONGARCH_EXTIOI_COMMON, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(LoongArchExtIOICommonState), + .class_size =3D sizeof(LoongArchExtIOICommonClass), + .class_init =3D loongarch_extioi_common_class_init, + .abstract =3D true, + } +}; + +DEFINE_TYPES(loongarch_extioi_common_types) diff --git a/hw/intc/meson.build b/hw/intc/meson.build index 6bfdc4eb33..2f936d9f80 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -73,4 +73,4 @@ specific_ss.add(when: 'CONFIG_LOONGSON_IPI', if_true: fil= es('loongson_ipi.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ip= i.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarc= h_pch_pic.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarc= h_pch_msi.c')) -specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch= _extioi.c')) +specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch= _extioi.c', 'loongarch_extioi_common.c')) diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch= _extioi.h index d6747046b4..cc160c52dc 100644 --- a/include/hw/intc/loongarch_extioi.h +++ b/include/hw/intc/loongarch_extioi.h @@ -10,7 +10,20 @@ =20 #include "hw/intc/loongarch_extioi_common.h" =20 -#define LoongArchExtIOI LoongArchExtIOICommonState #define TYPE_LOONGARCH_EXTIOI "loongarch.extioi" -OBJECT_DECLARE_SIMPLE_TYPE(LoongArchExtIOI, LOONGARCH_EXTIOI) +OBJECT_DECLARE_TYPE(LoongArchExtIOIState, LoongArchExtIOIClass, LOONGARCH_= EXTIOI) + +struct LoongArchExtIOIState { + LoongArchExtIOICommonState parent_obj; +}; + +struct LoongArchExtIOIClass { + LoongArchExtIOICommonClass parent_class; + + DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; +}; + +#define LoongArchExtIOI LoongArchExtIOICommonState +#define LOONGARCH_EXTIOI(obj) ((LoongArchExtIOICommonState *)obj) #endif /* LOONGARCH_EXTIOI_H */ diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/lo= ongarch_extioi_common.h index 51243b8092..d45caa45f2 100644 --- a/include/hw/intc/loongarch_extioi_common.h +++ b/include/hw/intc/loongarch_extioi_common.h @@ -7,6 +7,7 @@ #ifndef LOONGARCH_EXTIOI_COMMON_H #define LOONGARCH_EXTIOI_COMMON_H =20 +#include "qom/object.h" #include "hw/sysbus.h" #include "hw/loongarch/virt.h" =20 @@ -56,6 +57,10 @@ #define EXTIOI_VIRT_COREMAP_START (0x40) #define EXTIOI_VIRT_COREMAP_END (0x240) =20 +#define TYPE_LOONGARCH_EXTIOI_COMMON "loongarch_extioi_common" +OBJECT_DECLARE_TYPE(LoongArchExtIOICommonState, + LoongArchExtIOICommonClass, LOONGARCH_EXTIOI_COMMON) + typedef struct ExtIOICore { uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT]; DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS); @@ -82,4 +87,11 @@ struct LoongArchExtIOICommonState { MemoryRegion extioi_system_mem; MemoryRegion virt_extend; }; + +struct LoongArchExtIOICommonClass { + SysBusDeviceClass parent_class; + + DeviceRealize parent_realize; + int (*post_load)(void *s, int version_id); +}; #endif /* LOONGARCH_EXTIOI_H */ --=20 2.39.3