From nobody Sat Nov 15 16:07:33 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 1749779694626117.12733330763797; Thu, 12 Jun 2025 18:54:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPtcf-0006Cv-D8; Thu, 12 Jun 2025 21:54:25 -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 1uPtcd-0006Cc-Ig for qemu-devel@nongnu.org; Thu, 12 Jun 2025 21:54:23 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPtcb-0007C5-KE for qemu-devel@nongnu.org; Thu, 12 Jun 2025 21:54:23 -0400 Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxGHHJhEto12oVAQ--.53910S3; Fri, 13 Jun 2025 09:54:17 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by front1 (Coremail) with SMTP id qMiowMBxb8evhEtoiJIYAQ--.6626S3; Fri, 13 Jun 2025 09:54:16 +0800 (CST) From: Xianglai Li To: qemu-devel@nongnu.org Cc: Bibo Mao , Song Gao , Jiaxun Yang Subject: [PATCH V1 1/2] hw/rtc: Fixed loongson rtc emulation errors Date: Fri, 13 Jun 2025 09:31:15 +0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowMBxb8evhEtoiJIYAQ--.6626S3 X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ 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=lixianglai@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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1749779697553116600 Content-Type: text/plain; charset="utf-8" The expire time is sent to the timer only when the expire Time is greater than 0 or greater than now. Otherwise, the timer will trigger interruption continuously. Timer interrupts are sent using pulse functions. Signed-off-by: Xianglai Li --- Cc: Bibo Mao Cc: Song Gao Cc: Jiaxun Yang Cc: Xianglai Li hw/loongarch/virt-fdt-build.c | 11 +++++++++-- hw/rtc/ls7a_rtc.c | 26 +++++++++++++++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c index 728ce46699..c613131a07 100644 --- a/hw/loongarch/virt-fdt-build.c +++ b/hw/loongarch/virt-fdt-build.c @@ -17,6 +17,11 @@ #include "system/reset.h" #include "target/loongarch/cpu.h" =20 +#define FDT_IRQ_FLAGS_EDGE_LO_HI 1 +#define FDT_IRQ_FLAGS_EDGE_HI_LO 2 +#define FDT_IRQ_FLAGS_LEVEL_HI 4 +#define FDT_IRQ_FLAGS_LEVEL_LO 8 + static void create_fdt(LoongArchVirtMachineState *lvms) { MachineState *ms =3D MACHINE(lvms); @@ -416,7 +421,8 @@ static void fdt_add_uart_node(LoongArchVirtMachineState= *lvms, if (chosen) { qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", nodenam= e); } - qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", irq, 0x4); + qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", irq, + FDT_IRQ_FLAGS_LEVEL_HI); qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent", *pch_pic_phandle); g_free(nodename); @@ -436,7 +442,8 @@ static void fdt_add_rtc_node(LoongArchVirtMachineState = *lvms, "loongson,ls7a-rtc"); qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, siz= e); qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", - VIRT_RTC_IRQ - VIRT_GSI_BASE , 0x4); + VIRT_RTC_IRQ - VIRT_GSI_BASE , + FDT_IRQ_FLAGS_EDGE_LO_HI); qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent", *pch_pic_phandle); g_free(nodename); diff --git a/hw/rtc/ls7a_rtc.c b/hw/rtc/ls7a_rtc.c index 10097b2db7..7eca75a42a 100644 --- a/hw/rtc/ls7a_rtc.c +++ b/hw/rtc/ls7a_rtc.c @@ -145,20 +145,24 @@ static void toymatch_write(LS7ARtcState *s, uint64_t = val, int num) now =3D qemu_clock_get_ms(rtc_clock); toymatch_val_to_time(s, val, &tm); expire_time =3D now + (qemu_timedate_diff(&tm) - s->offset_toy) * = 1000; - timer_mod(s->toy_timer[num], expire_time); + if (expire_time > now) { + timer_mod(s->toy_timer[num], expire_time); + } } } =20 static void rtcmatch_write(LS7ARtcState *s, uint64_t val, int num) { - uint64_t expire_ns; + int64_t expire_ns; =20 /* it do not support write when toy disabled */ if (rtc_enabled(s)) { s->rtcmatch[num] =3D val; /* calculate expire time */ expire_ns =3D ticks_to_ns(val) - ticks_to_ns(s->offset_rtc); - timer_mod_ns(s->rtc_timer[num], expire_ns); + if (expire_ns > 0) { + timer_mod_ns(s->rtc_timer[num], expire_ns); + } } } =20 @@ -185,7 +189,7 @@ static void ls7a_rtc_stop(LS7ARtcState *s) static void ls7a_toy_start(LS7ARtcState *s) { int i; - uint64_t expire_time, now; + int64_t expire_time, now; struct tm tm =3D {}; =20 now =3D qemu_clock_get_ms(rtc_clock); @@ -194,19 +198,23 @@ static void ls7a_toy_start(LS7ARtcState *s) for (i =3D 0; i < TIMER_NUMS; i++) { toymatch_val_to_time(s, s->toymatch[i], &tm); expire_time =3D now + (qemu_timedate_diff(&tm) - s->offset_toy) * = 1000; - timer_mod(s->toy_timer[i], expire_time); + if (expire_time > now) { + timer_mod(s->toy_timer[i], expire_time); + } } } =20 static void ls7a_rtc_start(LS7ARtcState *s) { int i; - uint64_t expire_time; + int64_t expire_time; =20 /* recalculate expire time and enable timer */ for (i =3D 0; i < TIMER_NUMS; i++) { expire_time =3D ticks_to_ns(s->rtcmatch[i]) - ticks_to_ns(s->offse= t_rtc); - timer_mod_ns(s->rtc_timer[i], expire_time); + if (expire_time > 0) { + timer_mod_ns(s->rtc_timer[i], expire_time); + } } } =20 @@ -370,7 +378,7 @@ static void toy_timer_cb(void *opaque) LS7ARtcState *s =3D opaque; =20 if (toy_enabled(s)) { - qemu_irq_raise(s->irq); + qemu_irq_pulse(s->irq); } } =20 @@ -379,7 +387,7 @@ static void rtc_timer_cb(void *opaque) LS7ARtcState *s =3D opaque; =20 if (rtc_enabled(s)) { - qemu_irq_raise(s->irq); + qemu_irq_pulse(s->irq); } } =20 --=20 2.39.1 From nobody Sat Nov 15 16:07:33 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 1749779716783845.7222788041174; Thu, 12 Jun 2025 18:55:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPtcr-0006Eb-HC; Thu, 12 Jun 2025 21:54:37 -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 1uPtcp-0006EA-Ca for qemu-devel@nongnu.org; Thu, 12 Jun 2025 21:54:35 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPtcn-0007DJ-H0 for qemu-devel@nongnu.org; Thu, 12 Jun 2025 21:54:35 -0400 Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxjazXhEto4GoVAQ--.17864S3; Fri, 13 Jun 2025 09:54:31 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by front1 (Coremail) with SMTP id qMiowMBxb8evhEtoiJIYAQ--.6626S4; Fri, 13 Jun 2025 09:54:30 +0800 (CST) From: Xianglai Li To: qemu-devel@nongnu.org Cc: Bibo Mao , Song Gao , Jiaxun Yang Subject: [PATCH V1 2/2] hw/loongarch: add rtc acpi table Date: Fri, 13 Jun 2025 09:31:16 +0800 Message-Id: <49c55c9e6c49a89ec4438725ebf178e458572229.1749777563.git.lixianglai@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowMBxb8evhEtoiJIYAQ--.6626S4 X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ 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=lixianglai@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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1749779717115116600 Content-Type: text/plain; charset="utf-8" Add the acpi table to the loongson rtc hardware so that the virtual machine kernel can use the loongson RTC-related drivers. Signed-off-by: Xianglai Li Reviewed-by: Bibo Mao --- Cc: Bibo Mao Cc: Song Gao Cc: Jiaxun Yang Cc: Xianglai Li hw/loongarch/virt-acpi-build.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hw/loongarch/virt-acpi-build.c b/hw/loongarch/virt-acpi-build.c index 2cd2d9d842..2cfc5421c5 100644 --- a/hw/loongarch/virt-acpi-build.c +++ b/hw/loongarch/virt-acpi-build.c @@ -473,6 +473,29 @@ static void acpi_dsdt_add_tpm(Aml *scope, LoongArchVir= tMachineState *vms) } #endif =20 +static void acpi_dsdt_add_rtc(Aml *scope) +{ + uint32_t rtc_irq =3D VIRT_RTC_IRQ; + Aml *dev =3D aml_device("RTC"); + + aml_append(dev, aml_name_decl("_HID", aml_string("LOON0001"))); + aml_append(dev, aml_name_decl("_UID", aml_int(0))); + + Aml *crs =3D aml_resource_template(); + aml_append(crs, + aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED, + AML_NON_CACHEABLE, AML_READ_WRITE, + 0, VIRT_RTC_REG_BASE, + VIRT_RTC_REG_BASE + VIRT_RTC_LEN - 1, + 0, VIRT_RTC_LEN)); + aml_append(crs, + aml_interrupt(AML_CONSUMER, AML_EDGE, AML_ACTIVE_HIGH, + AML_EXCLUSIVE, &rtc_irq, 1)); + + aml_append(dev, aml_name_decl("_CRS", crs)); + aml_append(scope, dev); +} + /* build DSDT */ static void build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine) @@ -488,6 +511,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, Mach= ineState *machine) for (i =3D 0; i < VIRT_UART_COUNT; i++) { build_uart_device_aml(dsdt, i); } + acpi_dsdt_add_rtc(dsdt); build_pci_device_aml(dsdt, lvms); build_la_ged_aml(dsdt, machine); build_flash_aml(dsdt, lvms); --=20 2.39.1