From nobody Sat Sep 26 20:03:08 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 1788748795960716.4777149875653; Sun, 6 Sep 2026 19:39:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3PGH-0000eJ-Av; Sun, 06 Sep 2026 22:39:09 -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 1x3PGF-0000dc-LO for qemu-devel@nongnu.org; Sun, 06 Sep 2026 22:39:07 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3PGD-0007vP-4r for qemu-devel@nongnu.org; Sun, 06 Sep 2026 22:39:07 -0400 Received: from loongson.cn (unknown [10.40.46.54]) by gateway (Coremail) with SMTP id _____8AxYdHBI55q_EoJAA--.27085S3; Mon, 07 Sep 2026 10:38:57 +0800 (CST) Received: from fedora.loongson.cn (unknown [10.40.46.54]) by front1 (Coremail) with SMTP id qMiowJBxpMy8I55qtj0cAA--.33287S3; Mon, 07 Sep 2026 10:38:57 +0800 (CST) From: Bibo Mao To: Song Gao <17746591750@163.com> Cc: Xianglai Li , qemu-devel@nongnu.org Subject: [PATCH 1/3] target/loongarch: Rename function name constant_timer with timer Date: Mon, 7 Sep 2026 10:40:10 +0800 Message-ID: <20260907024012.2992255-2-maobibo@loongson.cn> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260907024012.2992255-1-maobibo@loongson.cn> References: <20260907024012.2992255-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBxpMy8I55qtj0cAA--.33287S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxur4fGw1UArW5XrWxXF1fGrX_yoW7JF4xpr Wxury7Kr48trZ8Wa4kt3s8WF1DXr42ga42v3WftrWIkFs7Xrn7W3W8trsFgF45Aa48Wry2 qFn5Z3WUXF47ZwbCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkjb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1Y6r17MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jUsqXUUUUU= 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: 1788748800863154100 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 84a130956d..cba227fd1b 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -762,7 +762,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:03:08 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 1788748768523739.8567365998393; Sun, 6 Sep 2026 19:39:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3PGH-0000ed-LM; Sun, 06 Sep 2026 22:39:09 -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 1x3PGF-0000dZ-Gs for qemu-devel@nongnu.org; Sun, 06 Sep 2026 22:39:07 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3PGD-0007vO-5G for qemu-devel@nongnu.org; Sun, 06 Sep 2026 22:39:07 -0400 Received: from loongson.cn (unknown [10.40.46.54]) by gateway (Coremail) with SMTP id _____8AxYdHCI55qAUsJAA--.27087S3; Mon, 07 Sep 2026 10:38:58 +0800 (CST) Received: from fedora.loongson.cn (unknown [10.40.46.54]) by front1 (Coremail) with SMTP id qMiowJBxpMy8I55qtj0cAA--.33287S4; Mon, 07 Sep 2026 10:38:57 +0800 (CST) From: Bibo Mao To: Song Gao <17746591750@163.com> Cc: Xianglai Li , qemu-devel@nongnu.org Subject: [PATCH 2/3] target/loongarch: Rename filename constant_timer.c with timer.c Date: Mon, 7 Sep 2026 10:40:11 +0800 Message-ID: <20260907024012.2992255-3-maobibo@loongson.cn> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260907024012.2992255-1-maobibo@loongson.cn> References: <20260907024012.2992255-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBxp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r4UMIIF0xvEx4A2jsIEc7CjxV AFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8zwZ7UUUUU== 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: 1788748772908154100 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:03:08 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 1788748786863181.6734509497403; Sun, 6 Sep 2026 19:39:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3PGI-0000eu-8d; Sun, 06 Sep 2026 22:39:10 -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 1x3PGH-0000eT-7d for qemu-devel@nongnu.org; Sun, 06 Sep 2026 22:39:09 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3PGD-0007vN-5u for qemu-devel@nongnu.org; Sun, 06 Sep 2026 22:39:08 -0400 Received: from loongson.cn (unknown [10.40.46.54]) by gateway (Coremail) with SMTP id _____8Ax29HCI55qBEsJAA--.26823S3; Mon, 07 Sep 2026 10:38:58 +0800 (CST) Received: from fedora.loongson.cn (unknown [10.40.46.54]) by front1 (Coremail) with SMTP id qMiowJBxpMy8I55qtj0cAA--.33287S5; Mon, 07 Sep 2026 10:38:58 +0800 (CST) From: Bibo Mao To: Song Gao <17746591750@163.com> Cc: Xianglai Li , qemu-devel@nongnu.org Subject: [PATCH 3/3] target/loongarch: Add CPUTimerState structure Date: Mon, 7 Sep 2026 10:40:12 +0800 Message-ID: <20260907024012.2992255-4-maobibo@loongson.cn> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260907024012.2992255-1-maobibo@loongson.cn> References: <20260907024012.2992255-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TR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Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07j1LvtUUUUU= 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: 1788748790407158500 Content-Type: text/plain; charset="utf-8" Structure CPUTimerState is added here, QEMUTimer and IRQ number is included, also the CPUSysState pointer is in this structure, so it is easy to add another separate timer in guest mode. Signed-off-by: Bibo Mao --- target/loongarch/cpu.c | 10 ++++++++-- target/loongarch/cpu.h | 14 +++++++++++++- target/loongarch/internals.h | 6 +++--- target/loongarch/tcg/csr_helper.c | 7 ++----- target/loongarch/tcg/op_helper.c | 3 +-- target/loongarch/tcg/timer.c | 27 ++++++++++++--------------- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index cba227fd1b..7182b85058 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -758,11 +758,17 @@ static void loongarch_cpu_init(Object *obj) { #ifndef CONFIG_USER_ONLY LoongArchCPU *cpu =3D LOONGARCH_CPU(obj); + CPULoongArchState *env =3D &cpu->env; + CPUTimerState *timer; =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->sys_state =3D &env->sys_states[0]; + 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 97db3b453f..0d7679f3be 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -382,6 +382,13 @@ typedef struct CPUSysState { uint64_t CSR_MSGIE; } CPUSysState; =20 +typedef struct CPUTimerState { + QEMUTimer timer; + int irq; + CPUState *cs; + CPUSysState *sys_state; +} CPUTimerState; + typedef struct CPUArchState { uint64_t gpr[32]; uint64_t pc; @@ -418,6 +425,7 @@ typedef struct CPUArchState { =20 AddressSpace *address_space_iocsr; uint32_t mp_state; + CPUTimerState timer_states[1]; #endif CPUSysState *sys_state; } CPULoongArchState; @@ -438,7 +446,6 @@ struct ArchCPU { CPUState parent_obj; =20 CPULoongArchState env; - QEMUTimer timer; uint32_t phy_id; OnOffAuto lbt; OnOffAuto pmu; @@ -496,6 +503,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->timer_states[0]; +} + 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..bc6511a6f0 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,11 +133,10 @@ 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); int64_t old_v =3D sys->CSR_TCFG; =20 - cpu_loongarch_set_timer_config(cpu, val); + cpu_loongarch_set_timer_config(env_timer(env), val); =20 return old_v; } diff --git a/target/loongarch/tcg/op_helper.c b/target/loongarch/tcg/op_hel= per.c index c090d5b12e..76d7201aea 100644 --- a/target/loongarch/tcg/op_helper.c +++ b/target/loongarch/tcg/op_helper.c @@ -73,7 +73,6 @@ 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); =20 plv =3D FIELD_EX64(sys->CSR_CRMD, CSR_CRMD, PLV); @@ -81,7 +80,7 @@ uint64_t helper_rdtime_d(CPULoongArchState *env) do_raise_exception(env, EXCCODE_IPE, GETPC()); } =20 - return cpu_loongarch_get_timer_counter(cpu); + return cpu_loongarch_get_timer_counter(env_timer(env)); #endif } =20 diff --git a/target/loongarch/tcg/timer.c b/target/loongarch/tcg/timer.c index a25312b9ab..9c5aa6720f 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 timer->sys_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 timer->sys_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 timer->sys_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