From nobody Sat Nov 15 16:38:22 2025 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 1750323232830913.5355766978566; Thu, 19 Jun 2025 01:53:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uSAzQ-0004PN-Px; Thu, 19 Jun 2025 04:51:21 -0400 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 1uSAzO-0004P0-JA for qemu-devel@nongnu.org; Thu, 19 Jun 2025 04:51:18 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uSAzL-0002w3-DT for qemu-devel@nongnu.org; Thu, 19 Jun 2025 04:51:18 -0400 Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxquB6z1NoerUZAQ--.17776S3; Thu, 19 Jun 2025 16:51:07 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by front1 (Coremail) with SMTP id qMiowMAxDcVtz1NohtwgAQ--.30176S4; Thu, 19 Jun 2025 16:51:06 +0800 (CST) From: Song Gao To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Bibo Mao Subject: [PULL 02/14] hw/intc/loongarch_extioi: Add kernel irqchip save and restore function Date: Thu, 19 Jun 2025 16:28:05 +0800 Message-Id: <20250619082817.1517996-3-gaosong@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20250619082817.1517996-1-gaosong@loongson.cn> References: <20250619082817.1517996-1-gaosong@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowMAxDcVtz1NohtwgAQ--.30176S4 X-CM-SenderInfo: 5jdr20tqj6z05rqj20fqof0/ 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=gaosong@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: 1750323235233116600 Content-Type: text/plain; charset="utf-8" From: Bibo Mao Add save and store funtction if kvm_irqchip_in_kernel() return true, it is to get and set ExtIOI irqchip state from KVM kernel. Reviewed-by: Song Gao Signed-off-by: Bibo Mao Message-ID: <20250606063033.2557365-3-maobibo@loongson.cn> Signed-off-by: Song Gao --- hw/intc/loongarch_extioi.c | 14 +++++ hw/intc/loongarch_extioi_kvm.c | 90 ++++++++++++++++++++++++++++++ include/hw/intc/loongarch_extioi.h | 2 + 3 files changed, 106 insertions(+) diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c index 837f649d6c..7be0685f36 100644 --- a/hw/intc/loongarch_extioi.c +++ b/hw/intc/loongarch_extioi.c @@ -393,11 +393,24 @@ static void loongarch_extioi_reset_hold(Object *obj, = ResetType type) } } =20 +static int vmstate_extioi_pre_save(void *opaque) +{ + if (kvm_irqchip_in_kernel()) { + return kvm_extioi_get(opaque); + } + + return 0; +} + static int vmstate_extioi_post_load(void *opaque, int version_id) { LoongArchExtIOICommonState *s =3D LOONGARCH_EXTIOI_COMMON(opaque); int i, start_irq; =20 + if (kvm_irqchip_in_kernel()) { + return kvm_extioi_put(opaque, version_id); + } + for (i =3D 0; i < (EXTIOI_IRQS / 4); i++) { start_irq =3D i * 4; extioi_update_sw_coremap(s, start_irq, s->coremap[i], false); @@ -423,6 +436,7 @@ static void loongarch_extioi_class_init(ObjectClass *kl= ass, const void *data) &lec->parent_unrealize); resettable_class_set_parent_phases(rc, NULL, loongarch_extioi_reset_ho= ld, NULL, &lec->parent_phases); + lecc->pre_save =3D vmstate_extioi_pre_save; lecc->post_load =3D vmstate_extioi_post_load; } =20 diff --git a/hw/intc/loongarch_extioi_kvm.c b/hw/intc/loongarch_extioi_kvm.c index e6d5dd379a..f4c618ca4c 100644 --- a/hw/intc/loongarch_extioi_kvm.c +++ b/hw/intc/loongarch_extioi_kvm.c @@ -12,6 +12,96 @@ #include "qapi/error.h" #include "system/kvm.h" =20 +static void kvm_extioi_access_reg(int fd, uint64_t addr, void *val, bool w= rite) +{ + kvm_device_access(fd, KVM_DEV_LOONGARCH_EXTIOI_GRP_REGS, + addr, val, write, &error_abort); +} + +static void kvm_extioi_access_sw_state(int fd, uint64_t addr, + void *val, bool write) +{ + kvm_device_access(fd, KVM_DEV_LOONGARCH_EXTIOI_GRP_SW_STATUS, + addr, val, write, &error_abort); +} + +static void kvm_extioi_access_sw_status(void *opaque, bool write) +{ + LoongArchExtIOICommonState *lecs =3D LOONGARCH_EXTIOI_COMMON(opaque); + LoongArchExtIOIState *les =3D LOONGARCH_EXTIOI(opaque); + int addr; + + addr =3D KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_STATE; + kvm_extioi_access_sw_state(les->dev_fd, addr, &lecs->status, write); +} + +static void kvm_extioi_access_regs(void *opaque, bool write) +{ + LoongArchExtIOICommonState *lecs =3D LOONGARCH_EXTIOI_COMMON(opaque); + LoongArchExtIOIState *les =3D LOONGARCH_EXTIOI(opaque); + int fd =3D les->dev_fd; + int addr, offset, cpu; + + for (addr =3D EXTIOI_NODETYPE_START; addr < EXTIOI_NODETYPE_END; addr = +=3D 4) { + offset =3D (addr - EXTIOI_NODETYPE_START) / 4; + kvm_extioi_access_reg(fd, addr, &lecs->nodetype[offset], write); + } + + for (addr =3D EXTIOI_IPMAP_START; addr < EXTIOI_IPMAP_END; addr +=3D 4= ) { + offset =3D (addr - EXTIOI_IPMAP_START) / 4; + kvm_extioi_access_reg(fd, addr, &lecs->ipmap[offset], write); + } + + for (addr =3D EXTIOI_ENABLE_START; addr < EXTIOI_ENABLE_END; addr +=3D= 4) { + offset =3D (addr - EXTIOI_ENABLE_START) / 4; + kvm_extioi_access_reg(fd, addr, &lecs->enable[offset], write); + } + + for (addr =3D EXTIOI_BOUNCE_START; addr < EXTIOI_BOUNCE_END; addr +=3D= 4) { + offset =3D (addr - EXTIOI_BOUNCE_START) / 4; + kvm_extioi_access_reg(fd, addr, &lecs->bounce[offset], write); + } + + for (addr =3D EXTIOI_ISR_START; addr < EXTIOI_ISR_END; addr +=3D 4) { + offset =3D (addr - EXTIOI_ISR_START) / 4; + kvm_extioi_access_reg(fd, addr, &lecs->isr[offset], write); + } + + for (addr =3D EXTIOI_COREMAP_START; addr < EXTIOI_COREMAP_END; addr += =3D 4) { + offset =3D (addr - EXTIOI_COREMAP_START) / 4; + kvm_extioi_access_reg(fd, addr, &lecs->coremap[offset], write); + } + + for (cpu =3D 0; cpu < lecs->num_cpu; cpu++) { + for (addr =3D EXTIOI_COREISR_START; + addr < EXTIOI_COREISR_END; addr +=3D 4) { + offset =3D (addr - EXTIOI_COREISR_START) / 4; + kvm_extioi_access_reg(fd, (cpu << 16) | addr, + &lecs->cpu[cpu].coreisr[offset], write); + } + } +} + +int kvm_extioi_get(void *opaque) +{ + kvm_extioi_access_regs(opaque, false); + kvm_extioi_access_sw_status(opaque, false); + return 0; +} + +int kvm_extioi_put(void *opaque, int version_id) +{ + LoongArchExtIOIState *les =3D LOONGARCH_EXTIOI(opaque); + int fd =3D les->dev_fd; + + kvm_extioi_access_regs(opaque, true); + kvm_extioi_access_sw_status(opaque, true); + kvm_device_access(fd, KVM_DEV_LOONGARCH_EXTIOI_GRP_CTRL, + KVM_DEV_LOONGARCH_EXTIOI_CTRL_LOAD_FINISHED, + NULL, true, &error_abort); + return 0; +} + void kvm_extioi_realize(DeviceState *dev, Error **errp) { LoongArchExtIOICommonState *lecs =3D LOONGARCH_EXTIOI_COMMON(dev); diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch= _extioi.h index 69565e14ab..9be1d736ea 100644 --- a/include/hw/intc/loongarch_extioi.h +++ b/include/hw/intc/loongarch_extioi.h @@ -27,5 +27,7 @@ struct LoongArchExtIOIClass { }; =20 void kvm_extioi_realize(DeviceState *dev, Error **errp); +int kvm_extioi_get(void *opaque); +int kvm_extioi_put(void *opaque, int version_id); =20 #endif /* LOONGARCH_EXTIOI_H */ --=20 2.47.0