aboutsummaryrefslogtreecommitdiff
path: root/target/mips/cpu.c
diff options
context:
space:
mode:
authorJiaxun Yang <jiaxun.yang@flygoat.com>2023-05-21 12:35:50 +0200
committerPhilippe Mathieu-Daudé <philmd@linaro.org>2023-07-10 21:53:03 +0200
commitb263688d236bc07266ce393fdce8c9b6bfd9d8d8 (patch)
tree6633ab2068b74ed2bd72ef5019739a40eb730321 /target/mips/cpu.c
parentfcb237e64f9d026c03d635579c7b288d0008a6e5 (diff)
downloadqemu-b263688d236bc07266ce393fdce8c9b6bfd9d8d8.zip
qemu-b263688d236bc07266ce393fdce8c9b6bfd9d8d8.tar.gz
qemu-b263688d236bc07266ce393fdce8c9b6bfd9d8d8.tar.bz2
target/mips: Rework cp0_timer with clock API
Previous implementation of MIPS cp0_timer computes a cp0_count_ns based on input clock. However rounding error of cp0_count_ns can affect precision of cp0_timer. Using clock API and a divider for cp0_timer, so we can use clock_ns_to_ticks/clock_ns_to_ticks to avoid rounding issue. Also workaround the situation that in such handler flow: count = read_c0_count() write_c0_compare(count) If timer had not progressed when compare was written, the interrupt would trigger again. Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20230521110037.90049-1-jiaxun.yang@flygoat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Diffstat (limited to 'target/mips/cpu.c')
-rw-r--r--target/mips/cpu.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index 01e0fbe..b7119cb 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -449,9 +449,9 @@ static void mips_cp0_period_set(MIPSCPU *cpu)
{
CPUMIPSState *env = &cpu->env;
- env->cp0_count_ns = clock_ticks_to_ns(MIPS_CPU(cpu)->clock,
- env->cpu_model->CCRes);
- assert(env->cp0_count_ns);
+ clock_set_mul_div(cpu->count_div, env->cpu_model->CCRes, 1);
+ clock_set_source(cpu->count_div, cpu->clock);
+ clock_set_source(env->count_clock, cpu->count_div);
}
static void mips_cpu_realizefn(DeviceState *dev, Error **errp)
@@ -504,6 +504,8 @@ static void mips_cpu_initfn(Object *obj)
cpu_set_cpustate_pointers(cpu);
cpu->clock = qdev_init_clock_in(DEVICE(obj), "clk-in", NULL, cpu, 0);
+ cpu->count_div = clock_new(OBJECT(obj), "clk-div-count");
+ env->count_clock = clock_new(OBJECT(obj), "clk-count");
env->cpu_model = mcc->cpu_def;
}