summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg/CpuTimerDxeRiscV64
diff options
context:
space:
mode:
authorTuan Phan <tphan@ventanamicro.com>2023-06-07 10:30:20 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-06-15 05:32:51 +0000
commit4dba2a9d08653a25750c9c74822adb6003c38e77 (patch)
tree59b95c8da0b56b491e37ef90d925f1fb2e80e050 /UefiCpuPkg/CpuTimerDxeRiscV64
parentaad98d915abe5ba092e318913028ed47937a9447 (diff)
downloadedk2-4dba2a9d08653a25750c9c74822adb6003c38e77.tar.gz
edk2-4dba2a9d08653a25750c9c74822adb6003c38e77.tar.bz2
edk2-4dba2a9d08653a25750c9c74822adb6003c38e77.zip
UefiCpuPkg: CpuTimerDxeRiscV64: Fix incorrect value sent to SbiSetTimer
SbiSetTimer expects core tick value. Cc: Andrei Warkentin <andrei.warkentin@intel.com> Signed-off-by: Tuan Phan <tphan@ventanamicro.com> Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Diffstat (limited to 'UefiCpuPkg/CpuTimerDxeRiscV64')
-rw-r--r--UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf3
-rw-r--r--UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c26
-rw-r--r--UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h2
3 files changed, 26 insertions, 5 deletions
diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf b/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf
index c76bd96483..aba660186d 100644
--- a/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf
+++ b/UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf
@@ -40,6 +40,9 @@
Timer.h
Timer.c
+[Pcd]
+ gUefiCpuPkgTokenSpaceGuid.PcdCpuCoreCrystalClockFrequency ## CONSUMES
+
[Protocols]
gEfiCpuArchProtocolGuid ## CONSUMES
gEfiTimerArchProtocolGuid ## PRODUCES
diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c
index fa957ba5e3..358057e7c6 100644
--- a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c
+++ b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c
@@ -80,8 +80,15 @@ TimerInterruptHandler (
return;
}
- mLastPeriodStart = PeriodStart;
- SbiSetTimer (PeriodStart += mTimerPeriod);
+ mLastPeriodStart = PeriodStart;
+ PeriodStart += DivU64x32 (
+ MultU64x32 (
+ mTimerPeriod,
+ PcdGet64 (PcdCpuCoreCrystalClockFrequency)
+ ),
+ 1000000u
+ ); // convert to tick
+ SbiSetTimer (PeriodStart);
RiscVEnableTimerInterrupt (); // enable SMode timer int
gBS->RestoreTPL (OriginalTPL);
}
@@ -163,6 +170,8 @@ TimerDriverSetTimerPeriod (
IN UINT64 TimerPeriod
)
{
+ UINT64 PeriodStart;
+
DEBUG ((DEBUG_INFO, "TimerDriverSetTimerPeriod(0x%lx)\n", TimerPeriod));
if (TimerPeriod == 0) {
@@ -171,9 +180,18 @@ TimerDriverSetTimerPeriod (
return EFI_SUCCESS;
}
- mTimerPeriod = TimerPeriod / 10; // convert unit from 100ns to 1us
+ mTimerPeriod = TimerPeriod / 10; // convert unit from 100ns to 1us
+
mLastPeriodStart = RiscVReadTimer ();
- SbiSetTimer (mLastPeriodStart + mTimerPeriod);
+ PeriodStart = mLastPeriodStart;
+ PeriodStart += DivU64x32 (
+ MultU64x32 (
+ mTimerPeriod,
+ PcdGet64 (PcdCpuCoreCrystalClockFrequency)
+ ),
+ 1000000u
+ ); // convert to tick
+ SbiSetTimer (PeriodStart);
mCpu->EnableInterrupt (mCpu);
RiscVEnableTimerInterrupt (); // enable SMode timer int
diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h
index 586eb0cfad..9b3542230c 100644
--- a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h
+++ b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.h
@@ -21,7 +21,7 @@
#include <Library/IoLib.h>
//
-// RISC-V use 100us timer.
+// RISC-V use 100ns timer.
// The default timer tick duration is set to 10 ms = 10 * 1000 * 10 100 ns units
//
#define DEFAULT_TIMER_TICK_DURATION 100000