Browse Source

Silicon/SiFive: Use mtime CSR library

Use mtime CSR library interface to access mtime
CSR in Timer DXE driver.

Cc: Sunil V L <sunilvl@ventanamicro.com>
Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
Signed-off-by: Abner Chang <abner.chang@hpe.com>
Reviewed-by: Daniel Schaefer <daniel.schaefer@hpe.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Abner Chang 2 years ago
parent
commit
9e5d4246a0

+ 2 - 0
Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc

@@ -148,6 +148,8 @@
   RiscVCpuLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVCpuLib/RiscVCpuLib.inf
   RiscVEdk2SbiLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.inf
   RiscVPlatformTimerLib|Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.inf
+  #MachineModeTimerLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVReadMachineModeTimer/MachineModeTimerLib/MachineModeTimerLib.inf
+  MachineModeTimerLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVReadMachineModeTimer/EmulatedMachineModeTimerLib/EmulatedMachineModeTimerLib.inf
   CpuExceptionHandlerLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVExceptionLib/CpuExceptionHandlerDxeLib.inf
 
 

+ 5 - 9
Platform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/Timer.c

@@ -15,9 +15,6 @@
 #include <sbi/riscv_atomic.h>
 #include <U5Clint.h>
 
-STATIC volatile VOID * const p_mtime = (VOID *)CLINT_REG_MTIME;
-#define MTIME          (*p_mtime)
-#define MTIMECMP(i)    (p_mtimecmp[i])
 BOOLEAN TimerHandlerReentry = FALSE;
 
 //
@@ -73,7 +70,7 @@ TimerInterruptHandler (
     // MMode timer occurred when processing
     // SMode timer handler.
     //
-    RiscvTimer = readq_relaxed(p_mtime);
+    RiscvTimer = RiscVReadMachineTimerInterface();
     SbiSetTimer (RiscvTimer += mTimerPeriod);
     csr_clear(CSR_SIP, MIP_STIP);
     return;
@@ -91,7 +88,7 @@ TimerInterruptHandler (
   if (mTimerNotifyFunction != NULL) {
       mTimerNotifyFunction (mTimerPeriod);
   }
-  RiscvTimer = readq_relaxed(p_mtime);
+  RiscvTimer = RiscVReadMachineTimerInterface();
   SbiSetTimer (RiscvTimer += mTimerPeriod);
   gBS->RestoreTPL (OriginalTPL);
   csr_set(CSR_SIE, MIP_STIP); // enable SMode timer int
@@ -185,10 +182,9 @@ TimerDriverSetTimerPeriod (
     return EFI_SUCCESS;
   }
 
-  mTimerPeriod = TimerPeriod / 10; // convert unit from 100ns to 1us
-
-  RiscvTimer = readq_relaxed(p_mtime);
-  SbiSetTimer(RiscvTimer + mTimerPeriod);
+  mTimerPeriod = TimerPeriod; // convert unit from 100ns to 1us
+  RiscvTimer = RiscVReadMachineTimerInterface();
+  SbiSetTimer(RiscvTimer + mTimerPeriod / 10);
 
   mCpu->EnableInterrupt(mCpu);
   csr_set(CSR_SIE, MIP_STIP); // enable timer int

+ 1 - 0
Platform/SiFive/U5SeriesPkg/Universal/Dxe/TimerDxe/TimerDxe.inf

@@ -30,6 +30,7 @@
   BaseLib
   DebugLib
   IoLib
+  MachineModeTimerLib
   RiscVCpuLib
   RiscVEdk2SbiLib
   UefiBootServicesTableLib