UefiCpuPkg: RISC-V: TimerLib: Fix delay function to use 64-bit

The timer compare register is 64-bit so simplifying the delay
function.

Cc: Andrei Warkentin <andrei.warkentin@intel.com>
Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
This commit is contained in:
Tuan Phan 2023-06-07 10:30:21 -07:00 committed by mergify[bot]
parent 4dba2a9d08
commit ea55bd8f66
2 changed files with 22 additions and 30 deletions

View File

@ -20,6 +20,5 @@
Name: Name:
#define ASM_FUNC(Name) _ASM_FUNC(ASM_PFX(Name), .text. ## Name) #define ASM_FUNC(Name) _ASM_FUNC(ASM_PFX(Name), .text. ## Name)
#define RISCV_TIMER_COMPARE_BITS 32
#endif #endif

View File

@ -22,26 +22,19 @@
@param Delay A period of time to delay in ticks. @param Delay A period of time to delay in ticks.
**/ **/
STATIC
VOID VOID
InternalRiscVTimerDelay ( InternalRiscVTimerDelay (
IN UINT32 Delay IN UINT64 Delay
) )
{ {
UINT32 Ticks; UINT64 Ticks;
UINT32 Times;
Times = Delay >> (RISCV_TIMER_COMPARE_BITS - 2); Ticks = RiscVReadTimer () + Delay;
Delay &= ((1 << (RISCV_TIMER_COMPARE_BITS - 2)) - 1);
do { while (RiscVReadTimer () <= Ticks) {
// CpuPause ();
// The target timer count is calculated here }
//
Ticks = RiscVReadTimer () + Delay;
Delay = 1 << (RISCV_TIMER_COMPARE_BITS - 2);
while (((Ticks - RiscVReadTimer ()) & (1 << (RISCV_TIMER_COMPARE_BITS - 1))) == 0) {
CpuPause ();
}
} while (Times-- > 0);
} }
/** /**
@ -61,13 +54,13 @@ MicroSecondDelay (
) )
{ {
InternalRiscVTimerDelay ( InternalRiscVTimerDelay (
(UINT32)DivU64x32 ( DivU64x32 (
MultU64x32 ( MultU64x32 (
MicroSeconds, MicroSeconds,
PcdGet64 (PcdCpuCoreCrystalClockFrequency) PcdGet64 (PcdCpuCoreCrystalClockFrequency)
), ),
1000000u 1000000u
) )
); );
return MicroSeconds; return MicroSeconds;
} }
@ -89,13 +82,13 @@ NanoSecondDelay (
) )
{ {
InternalRiscVTimerDelay ( InternalRiscVTimerDelay (
(UINT32)DivU64x32 ( DivU64x32 (
MultU64x32 ( MultU64x32 (
NanoSeconds, NanoSeconds,
PcdGet64 (PcdCpuCoreCrystalClockFrequency) PcdGet64 (PcdCpuCoreCrystalClockFrequency)
), ),
1000000000u 1000000000u
) )
); );
return NanoSeconds; return NanoSeconds;
} }