Files
acrn-hypervisor/hypervisor/arch/riscv/timer.c
Haicheng Li f6bf0b809d risc-v: initial timer codes
This patch implements risc-v specific timer codes. Basically,
risc-v adapts to acrn timer framework with some specific
behaviors. So far, it enables sstc support in h-mode.

Tracked-On: #8792
Signed-off-by: Haicheng Li <haicheng.li@outlook.com>
Co-developed-by: Yong Li <yong.li@intel.com>
Signed-off-by: Yong Li <yong.li@intel.com>
Co-developed-by: Yi Y Sun <yi.y.sun@intel.com>
Signed-off-by: Yi Y Sun <yi.y.sun@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-17 08:55:12 +08:00

56 lines
945 B
C

/*
* Copyright (C) 2023-2024 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Authors:
* Haicheng Li <haicheng.li@intel.com>
*/
#include <softirq.h>
#include <timer.h>
#include <asm/timer.h>
#include <asm/sbi.h>
#include <asm/qemu.h>
#include <asm/cpu.h>
#define HOST_CPUFREQ 10000000
#define STOP_TIMER 0xFFFFFFFFFFFFFFFF
void timer_irq_handler(void)
{
arch_set_timer_count(STOP_TIMER);
fire_softirq(SOFTIRQ_TIMER);
}
void arch_init_timer(void)
{
return;
}
/* FIXME:
* Such short arch_xxx function need be moved into header file with
* static inline prefix.
*/
uint64_t arch_cpu_ticks(void)
{
uint64_t tick;
asm volatile (
"rdtime %0":"=r"(tick):: "memory");
return tick;
}
uint32_t arch_cpu_tickrate(void)
{
return HOST_CPUFREQ / 1000;
}
void arch_set_timer_count(uint64_t timeout)
{
#ifdef CONFIG_SSTC
cpu_csr_write(stimecmp, timeout);
#else
sbi_set_timer(timeout);
#endif
}