From nobody Sat Sep 26 20:02:32 2026 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17890263637071001.1362708040308; Thu, 10 Sep 2026 00:46:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZT1-00059L-7O; Thu, 10 Sep 2026 03:45:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x4ZT0-00058q-3b for qemu-devel@nongnu.org; Thu, 10 Sep 2026 03:45:06 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZSw-00072a-N2 for qemu-devel@nongnu.org; Thu, 10 Sep 2026 03:45:05 -0400 Received: from loongson.cn (unknown [10.40.46.54]) by gateway (Coremail) with SMTP id _____8CxfdL2X6Jq6HcKAA--.30236S3; Thu, 10 Sep 2026 15:44:54 +0800 (CST) Received: from fedora.loongson.cn (unknown [10.40.46.54]) by front1 (Coremail) with SMTP id qMiowJBx5cz1X6JqCW0eAA--.38445S3; Thu, 10 Sep 2026 15:44:53 +0800 (CST) From: Bibo Mao To: Song Gao <17746591750@163.com> Cc: Xianglai Li , qemu-devel@nongnu.org Subject: [PATCH v2 1/3] target/loongarch: Rename function name constant_timer with timer Date: Thu, 10 Sep 2026 15:46:11 +0800 Message-ID: <20260910074613.3486127-2-maobibo@loongson.cn> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260910074613.3486127-1-maobibo@loongson.cn> References: <20260910074613.3486127-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBx5cz1X6JqCW0eAA--.38445S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxur4fGw1UArW5XrWxXF1fGrX_yoW7JF4xpr Wxury7Kr48trZ8Wa4kt3s8WF1DXr42ga42v3WftrWIkrs7Xrn7Ww18trsFgF45Aa48Wry2 qFn5Z3WUXF47ZwbCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8j-e5UUUUU== 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=lists1p.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, 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: qemu development 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: 1789026366771158500 Content-Type: text/plain; charset="utf-8" There is only one timer type on LoongArch, its frequency is fixed at 100MHZ. Here rename function name constant_timer_xxx with timer_xxx for simplity. Signed-off-by: Bibo Mao --- target/loongarch/cpu.c | 2 +- target/loongarch/internals.h | 9 ++++----- target/loongarch/tcg/constant_timer.c | 9 ++++----- target/loongarch/tcg/csr_helper.c | 4 ++-- target/loongarch/tcg/op_helper.c | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index 18d73ebc1b..eb143800e0 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -724,7 +724,7 @@ static void loongarch_cpu_init(Object *obj) qdev_init_gpio_in(DEVICE(cpu), loongarch_cpu_set_irq, N_IRQS); #ifdef CONFIG_TCG timer_init_ns(&cpu->timer, QEMU_CLOCK_VIRTUAL, - &loongarch_constant_timer_cb, cpu); + &cpu_loongarch_timer_cb, cpu); #endif #endif } diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h index 0b670f9466..8c5f095782 100644 --- a/target/loongarch/internals.h +++ b/target/loongarch/internals.h @@ -34,11 +34,10 @@ extern const VMStateDescription vmstate_loongarch_cpu; void loongarch_cpu_update_irq(LoongArchCPU *cpu, uint64_t old); void loongarch_cpu_set_irq(void *opaque, int irq, int level); =20 -void loongarch_constant_timer_cb(void *opaque); -uint64_t cpu_loongarch_get_constant_timer_counter(LoongArchCPU *cpu); -uint64_t cpu_loongarch_get_constant_timer_ticks(LoongArchCPU *cpu); -void cpu_loongarch_store_constant_timer_config(LoongArchCPU *cpu, - uint64_t value); +void cpu_loongarch_timer_cb(void *opaque); +uint64_t cpu_loongarch_get_timer_counter(LoongArchCPU *cpu); +uint64_t cpu_loongarch_get_timer_ticks(LoongArchCPU *cpu); +void cpu_loongarch_set_timer_config(LoongArchCPU *cpu, uint64_t value); bool loongarch_cpu_has_work(CPUState *cs); bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env); #endif /* !CONFIG_USER_ONLY */ diff --git a/target/loongarch/tcg/constant_timer.c b/target/loongarch/tcg/c= onstant_timer.c index b91ad1de69..a25312b9ab 100644 --- a/target/loongarch/tcg/constant_timer.c +++ b/target/loongarch/tcg/constant_timer.c @@ -15,12 +15,12 @@ #define CONSTANT_TIMER_TICK_MASK 0xfffffffffffcUL #define CONSTANT_TIMER_ENABLE 0x1UL =20 -uint64_t cpu_loongarch_get_constant_timer_counter(LoongArchCPU *cpu) +uint64_t cpu_loongarch_get_timer_counter(LoongArchCPU *cpu) { return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / TIMER_PERIOD; } =20 -uint64_t cpu_loongarch_get_constant_timer_ticks(LoongArchCPU *cpu) +uint64_t cpu_loongarch_get_timer_ticks(LoongArchCPU *cpu) { CPULoongArchState *env =3D &cpu->env; CPUSysState *sys =3D env_sys(env); @@ -36,8 +36,7 @@ uint64_t cpu_loongarch_get_constant_timer_ticks(LoongArch= CPU *cpu) return sys->CSR_TVAL; } =20 -void cpu_loongarch_store_constant_timer_config(LoongArchCPU *cpu, - uint64_t value) +void cpu_loongarch_set_timer_config(LoongArchCPU *cpu, uint64_t value) { CPULoongArchState *env =3D &cpu->env; CPUSysState *sys =3D env_sys(env); @@ -55,7 +54,7 @@ void cpu_loongarch_store_constant_timer_config(LoongArchC= PU *cpu, } } =20 -void loongarch_constant_timer_cb(void *opaque) +void cpu_loongarch_timer_cb(void *opaque) { LoongArchCPU *cpu =3D opaque; CPULoongArchState *env =3D &cpu->env; diff --git a/target/loongarch/tcg/csr_helper.c b/target/loongarch/tcg/csr_h= elper.c index 155482efc6..b1a0b005e9 100644 --- a/target/loongarch/tcg/csr_helper.c +++ b/target/loongarch/tcg/csr_helper.c @@ -74,7 +74,7 @@ target_ulong helper_csrrd_tval(CPULoongArchState *env) { LoongArchCPU *cpu =3D env_archcpu(env); =20 - return cpu_loongarch_get_constant_timer_ticks(cpu); + return cpu_loongarch_get_timer_ticks(cpu); } =20 target_ulong helper_csrrd_msgir(CPULoongArchState *env) @@ -139,7 +139,7 @@ target_ulong helper_csrwr_tcfg(CPULoongArchState *env, = target_ulong val) CPUSysState *sys =3D env_sys(env); int64_t old_v =3D sys->CSR_TCFG; =20 - cpu_loongarch_store_constant_timer_config(cpu, val); + cpu_loongarch_set_timer_config(cpu, val); =20 return old_v; } diff --git a/target/loongarch/tcg/op_helper.c b/target/loongarch/tcg/op_hel= per.c index f41f0cb1e6..c090d5b12e 100644 --- a/target/loongarch/tcg/op_helper.c +++ b/target/loongarch/tcg/op_helper.c @@ -81,7 +81,7 @@ uint64_t helper_rdtime_d(CPULoongArchState *env) do_raise_exception(env, EXCCODE_IPE, GETPC()); } =20 - return cpu_loongarch_get_constant_timer_counter(cpu); + return cpu_loongarch_get_timer_counter(cpu); #endif } =20 --=20 2.54.0 From nobody Sat Sep 26 20:02:32 2026 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789026362724956.3998757646541; Thu, 10 Sep 2026 00:46:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZT2-00059o-35; Thu, 10 Sep 2026 03:45:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x4ZSz-00058V-QE for qemu-devel@nongnu.org; Thu, 10 Sep 2026 03:45:05 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZSw-00072W-3A for qemu-devel@nongnu.org; Thu, 10 Sep 2026 03:45:05 -0400 Received: from loongson.cn (unknown [10.40.46.54]) by gateway (Coremail) with SMTP id _____8CxvtL2X6Jq6ncKAA--.30209S3; Thu, 10 Sep 2026 15:44:54 +0800 (CST) Received: from fedora.loongson.cn (unknown [10.40.46.54]) by front1 (Coremail) with SMTP id qMiowJBx5cz1X6JqCW0eAA--.38445S4; Thu, 10 Sep 2026 15:44:54 +0800 (CST) From: Bibo Mao To: Song Gao <17746591750@163.com> Cc: Xianglai Li , qemu-devel@nongnu.org Subject: [PATCH v2 2/3] target/loongarch: Rename filename constant_timer.c with timer.c Date: Thu, 10 Sep 2026 15:46:12 +0800 Message-ID: <20260910074613.3486127-3-maobibo@loongson.cn> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260910074613.3486127-1-maobibo@loongson.cn> References: <20260910074613.3486127-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBx5cz1X6JqCW0eAA--.38445S4 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj9xXoWruw4rGw47JF1UAFW3Gr4fCrX_yoWDXrX_WF 4xJF1kCrsrW3WIq3yYv3y5Jws8Jr18KFnakFWUWF4xGas8Ka1YkrWDK3WkCFyYyr45ZFs8 A39aqryruF1YyosvyTuYvTs0mTUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUb7kYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwA2z4x0Y4vEx4A2jsIE14v26F4j6r4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc 02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAF wI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7V AKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUXVWUAwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x 0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxU2nYFDUUUU 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=lists1p.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, 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: qemu development 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: 1789026365603158500 Content-Type: text/plain; charset="utf-8" For simplity rename filename constant_timer.c with timer.c on LoongArch. Signed-off-by: Bibo Mao --- target/loongarch/tcg/meson.build | 2 +- target/loongarch/tcg/{constant_timer.c =3D> timer.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename target/loongarch/tcg/{constant_timer.c =3D> timer.c} (100%) diff --git a/target/loongarch/tcg/meson.build b/target/loongarch/tcg/meson.= build index b7adfe46f1..0b013875cc 100644 --- a/target/loongarch/tcg/meson.build +++ b/target/loongarch/tcg/meson.build @@ -13,7 +13,7 @@ loongarch_ss.add(files( )) =20 loongarch_system_ss.add(files( - 'constant_timer.c', + 'timer.c', 'csr_helper.c', 'iocsr_helper.c', 'tlb_helper.c', diff --git a/target/loongarch/tcg/constant_timer.c b/target/loongarch/tcg/t= imer.c similarity index 100% rename from target/loongarch/tcg/constant_timer.c rename to target/loongarch/tcg/timer.c --=20 2.54.0 From nobody Sat Sep 26 20:02:32 2026 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789026368226474.77637616883953; Thu, 10 Sep 2026 00:46:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZT1-00059i-Kx; Thu, 10 Sep 2026 03:45:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x4ZSy-00057p-SW for qemu-devel@nongnu.org; Thu, 10 Sep 2026 03:45:04 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZSv-00072d-OX for qemu-devel@nongnu.org; Thu, 10 Sep 2026 03:45:04 -0400 Received: from loongson.cn (unknown [10.40.46.54]) by gateway (Coremail) with SMTP id _____8DxjdL3X6Jq63cKAA--.30002S3; Thu, 10 Sep 2026 15:44:55 +0800 (CST) Received: from fedora.loongson.cn (unknown [10.40.46.54]) by front1 (Coremail) with SMTP id qMiowJBx5cz1X6JqCW0eAA--.38445S5; Thu, 10 Sep 2026 15:44:54 +0800 (CST) From: Bibo Mao To: Song Gao <17746591750@163.com> Cc: Xianglai Li , qemu-devel@nongnu.org Subject: [PATCH v2 3/3] target/loongarch: Add CPUTimerState structure Date: Thu, 10 Sep 2026 15:46:13 +0800 Message-ID: <20260910074613.3486127-4-maobibo@loongson.cn> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260910074613.3486127-1-maobibo@loongson.cn> References: <20260910074613.3486127-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBx5cz1X6JqCW0eAA--.38445S5 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxKFWUJrykuw4xur45ur4UGFX_yoWfGw1Dpr W2kry7Kr18JrZrJwn7ta98WF1DXr17Ww129a1SyrWIkan7Jr48ua4kt39FgFWUu3yrWrWa qFn5Aa15XFW7XacCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8wNVDUUUUU== 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=lists1p.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, 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: qemu development 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: 1789026370807158500 Content-Type: text/plain; charset="utf-8" Structure CPUTimerState is added in structure CPUSysState, QEMUTimer and IRQ number is included, so it is easy to add another separate timer if LVZ feature is supported. Signed-off-by: Bibo Mao --- target/loongarch/cpu.c | 12 ++++++++++-- target/loongarch/cpu.h | 15 ++++++++++++++- target/loongarch/internals.h | 6 +++--- target/loongarch/tcg/csr_helper.c | 14 ++++++-------- target/loongarch/tcg/op_helper.c | 6 +++--- target/loongarch/tcg/timer.c | 27 ++++++++++++--------------- 6 files changed, 48 insertions(+), 32 deletions(-) diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index eb143800e0..81dacbbaec 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -720,11 +720,19 @@ static void loongarch_cpu_init(Object *obj) { #ifndef CONFIG_USER_ONLY LoongArchCPU *cpu =3D LOONGARCH_CPU(obj); +#ifdef CONFIG_TCG + CPULoongArchState *env =3D &cpu->env; + CPUTimerState *timer; +#endif + =20 qdev_init_gpio_in(DEVICE(cpu), loongarch_cpu_set_irq, N_IRQS); #ifdef CONFIG_TCG - timer_init_ns(&cpu->timer, QEMU_CLOCK_VIRTUAL, - &cpu_loongarch_timer_cb, cpu); + timer =3D env_timer(env); + timer->irq =3D IRQ_TIMER; + timer->cs =3D CPU(obj); + timer_init_ns(&timer->timer, QEMU_CLOCK_VIRTUAL, + &cpu_loongarch_timer_cb, timer); #endif #endif } diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index d83dcef6f8..c592f69885 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -315,6 +315,12 @@ typedef struct LoongArchBT { uint32_t ftop; } lbt_t; =20 +typedef struct CPUTimerState { + QEMUTimer timer; + int irq; + CPUState *cs; +} CPUTimerState; + #define CPU_VENDOR_LOONGSON "Loongson" #define CPU_MODEL_3A5000 "3A5000" #define CPU_MODEL_1C101 "1C101" @@ -384,6 +390,9 @@ typedef struct CPUSysState { uint64_t CSR_PRCFG1; uint64_t CSR_PRCFG2; uint64_t CSR_PRCFG3; +#ifdef CONFIG_TCG + CPUTimerState timer_state; +#endif } CPUSysState; =20 typedef struct CPUArchState { @@ -446,7 +455,6 @@ struct ArchCPU { CPUState parent_obj; =20 CPULoongArchState env; - QEMUTimer timer; uint32_t phy_id; OnOffAuto lbt; OnOffAuto pmu; @@ -504,6 +512,11 @@ static inline void set_sys_state(CPULoongArchState *en= v, CPUSysState *sys) env->sys_state =3D sys; } =20 +static inline CPUTimerState *env_timer(CPULoongArchState *env) +{ + return &env->sys_states[0].timer_state; +} + static inline bool is_la64(CPULoongArchState *env) { return FIELD_EX32(env->cpucfg[1], CPUCFG1, ARCH) =3D=3D CPUCFG1_ARCH_L= A64; diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h index 8c5f095782..f9a0680fe0 100644 --- a/target/loongarch/internals.h +++ b/target/loongarch/internals.h @@ -35,9 +35,9 @@ void loongarch_cpu_update_irq(LoongArchCPU *cpu, uint64_t= old); void loongarch_cpu_set_irq(void *opaque, int irq, int level); =20 void cpu_loongarch_timer_cb(void *opaque); -uint64_t cpu_loongarch_get_timer_counter(LoongArchCPU *cpu); -uint64_t cpu_loongarch_get_timer_ticks(LoongArchCPU *cpu); -void cpu_loongarch_set_timer_config(LoongArchCPU *cpu, uint64_t value); +uint64_t cpu_loongarch_get_timer_counter(CPUTimerState *timer); +uint64_t cpu_loongarch_get_timer_ticks(CPUTimerState *timer); +void cpu_loongarch_set_timer_config(CPUTimerState *timer, uint64_t value); bool loongarch_cpu_has_work(CPUState *cs); bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env); #endif /* !CONFIG_USER_ONLY */ diff --git a/target/loongarch/tcg/csr_helper.c b/target/loongarch/tcg/csr_h= elper.c index b1a0b005e9..88656b5344 100644 --- a/target/loongarch/tcg/csr_helper.c +++ b/target/loongarch/tcg/csr_helper.c @@ -72,9 +72,7 @@ target_ulong helper_csrrd_cpuid(CPULoongArchState *env) =20 target_ulong helper_csrrd_tval(CPULoongArchState *env) { - LoongArchCPU *cpu =3D env_archcpu(env); - - return cpu_loongarch_get_timer_ticks(cpu); + return cpu_loongarch_get_timer_ticks(env_timer(env)); } =20 target_ulong helper_csrrd_msgir(CPULoongArchState *env) @@ -135,23 +133,23 @@ target_ulong helper_csrwr_asid(CPULoongArchState *env= , target_ulong val) =20 target_ulong helper_csrwr_tcfg(CPULoongArchState *env, target_ulong val) { - LoongArchCPU *cpu =3D env_archcpu(env); - CPUSysState *sys =3D env_sys(env); + CPUTimerState *timer =3D env_timer(env); + CPUSysState *sys =3D container_of(timer, CPUSysState, timer_state); int64_t old_v =3D sys->CSR_TCFG; =20 - cpu_loongarch_set_timer_config(cpu, val); + cpu_loongarch_set_timer_config(timer, val); =20 return old_v; } =20 target_ulong helper_csrwr_ticlr(CPULoongArchState *env, target_ulong val) { - LoongArchCPU *cpu =3D env_archcpu(env); + CPUTimerState *timer =3D env_timer(env); int64_t old_v =3D 0; =20 if (val & 0x1) { bql_lock(); - loongarch_cpu_set_irq(cpu, IRQ_TIMER, 0); + loongarch_cpu_set_irq(LOONGARCH_CPU(timer->cs), timer->irq, 0); bql_unlock(); } return old_v; diff --git a/target/loongarch/tcg/op_helper.c b/target/loongarch/tcg/op_hel= per.c index c090d5b12e..f98fe4d4a1 100644 --- a/target/loongarch/tcg/op_helper.c +++ b/target/loongarch/tcg/op_helper.c @@ -73,15 +73,15 @@ uint64_t helper_rdtime_d(CPULoongArchState *env) return cpu_get_host_ticks(); #else uint64_t plv; - LoongArchCPU *cpu =3D env_archcpu(env); - CPUSysState *sys =3D env_sys(env); + CPUTimerState *timer =3D env_timer(env); + CPUSysState *sys =3D container_of(timer, CPUSysState, timer_state); =20 plv =3D FIELD_EX64(sys->CSR_CRMD, CSR_CRMD, PLV); if (extract64(sys->CSR_MISC, R_CSR_MISC_DRDTL_SHIFT + plv, 1)) { do_raise_exception(env, EXCCODE_IPE, GETPC()); } =20 - return cpu_loongarch_get_timer_counter(cpu); + return cpu_loongarch_get_timer_counter(timer); #endif } =20 diff --git a/target/loongarch/tcg/timer.c b/target/loongarch/tcg/timer.c index a25312b9ab..6a96dfd429 100644 --- a/target/loongarch/tcg/timer.c +++ b/target/loongarch/tcg/timer.c @@ -15,60 +15,57 @@ #define CONSTANT_TIMER_TICK_MASK 0xfffffffffffcUL #define CONSTANT_TIMER_ENABLE 0x1UL =20 -uint64_t cpu_loongarch_get_timer_counter(LoongArchCPU *cpu) +uint64_t cpu_loongarch_get_timer_counter(CPUTimerState *timer) { return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / TIMER_PERIOD; } =20 -uint64_t cpu_loongarch_get_timer_ticks(LoongArchCPU *cpu) +uint64_t cpu_loongarch_get_timer_ticks(CPUTimerState *timer) { - CPULoongArchState *env =3D &cpu->env; - CPUSysState *sys =3D env_sys(env); + CPUSysState *sys =3D container_of(timer, CPUSysState, timer_state); uint64_t now, expire; =20 if ((sys->CSR_TCFG & CONSTANT_TIMER_ENABLE) && (sys->CSR_TVAL < sys->CSR_TCFG)) { now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - expire =3D timer_expire_time_ns(&cpu->timer); + expire =3D timer_expire_time_ns(&timer->timer); sys->CSR_TVAL =3D (expire - now) / TIMER_PERIOD; } =20 return sys->CSR_TVAL; } =20 -void cpu_loongarch_set_timer_config(LoongArchCPU *cpu, uint64_t value) +void cpu_loongarch_set_timer_config(CPUTimerState *timer, uint64_t value) { - CPULoongArchState *env =3D &cpu->env; - CPUSysState *sys =3D env_sys(env); + CPUSysState *sys =3D container_of(timer, CPUSysState, timer_state); uint64_t now, next; =20 sys->CSR_TCFG =3D value; if (value & CONSTANT_TIMER_ENABLE) { now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); next =3D now + (value & CONSTANT_TIMER_TICK_MASK) * TIMER_PERIOD; - timer_mod(&cpu->timer, next); + timer_mod(&timer->timer, next); sys->CSR_TVAL =3D sys->CSR_TCFG & CONSTANT_TIMER_TICK_MASK; } else { - timer_del(&cpu->timer); + timer_del(&timer->timer); sys->CSR_TVAL =3D 0; } } =20 void cpu_loongarch_timer_cb(void *opaque) { - LoongArchCPU *cpu =3D opaque; - CPULoongArchState *env =3D &cpu->env; - CPUSysState *sys =3D env_sys(env); + CPUTimerState *timer =3D opaque; + CPUSysState *sys =3D container_of(timer, CPUSysState, timer_state); uint64_t now, next; =20 if (FIELD_EX64(sys->CSR_TCFG, CSR_TCFG, PERIODIC)) { now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); next =3D now + (sys->CSR_TCFG & CONSTANT_TIMER_TICK_MASK) * TIMER_= PERIOD; - timer_mod(&cpu->timer, next); + timer_mod(&timer->timer, next); sys->CSR_TVAL =3D sys->CSR_TCFG & CONSTANT_TIMER_TICK_MASK; } else { sys->CSR_TVAL =3D CONSTANT_TIMER_TICK_MASK; } =20 - loongarch_cpu_set_irq(opaque, IRQ_TIMER, 1); + loongarch_cpu_set_irq(LOONGARCH_CPU(timer->cs), timer->irq, 1); } --=20 2.54.0