diff options
author | oliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-06-03 09:33:35 +0000 |
---|---|---|
committer | oliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-06-03 09:33:35 +0000 |
commit | ce9cc403bdd8f8d7f8aeebdac40485bf8e0d7be6 (patch) | |
tree | 15c193ef2b04d71b9c579e9a677d37edd281ec18 | |
parent | 23792dea0ca521e8696c7994e9cc6d04581f0b2c (diff) | |
download | edk2-platforms-ce9cc403bdd8f8d7f8aeebdac40485bf8e0d7be6.tar.xz |
ArmPlatformPkg/SP804Timer: Introduce gArmPlatformTokenSpaceGuid.PcdSP804FrequencyInMHz
This PCD defines the speed of the SP804 timer. The default value is 1MHz.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11745 6f19259b-4bc3-4df7-8a09-765794883524
5 files changed, 32 insertions, 11 deletions
diff --git a/ArmPlatformPkg/ArmPlatformPkg.dec b/ArmPlatformPkg/ArmPlatformPkg.dec index 9240efa2f6..66ec195054 100644 --- a/ArmPlatformPkg/ArmPlatformPkg.dec +++ b/ArmPlatformPkg/ArmPlatformPkg.dec @@ -61,3 +61,8 @@ # Size of the region reserved for fixed address allocations (Reserved 128MB by default) gArmPlatformTokenSpaceGuid.PcdSystemMemoryFixRegionSize|0x08000000|UINT32|0x00000014 + # + # ARM Primecells + # + gArmPlatformTokenSpaceGuid.PcdSP804FrequencyInMHz|1|UINT32|0x0000001D + diff --git a/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804Timer.c b/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804Timer.c index c7fb50dd0e..7e47891981 100644 --- a/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804Timer.c +++ b/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804Timer.c @@ -218,6 +218,7 @@ TimerDriverSetTimerPeriod ( } else { // Convert TimerPeriod into 1MHz clock counts (us units = 100ns units / 10) TimerTicks = DivU64x32 (TimerPeriod, 10); + TimerTicks = MultU64x32 (TimerTicks, PcdGet32(PcdSP804FrequencyInMHz)); // if it's larger than 32-bits, pin to highest value if (TimerTicks > 0xffffffff) { diff --git a/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf b/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf index 5b65f26499..a1765cc78c 100644 --- a/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf +++ b/ArmPlatformPkg/Drivers/SP804TimerDxe/SP804TimerDxe.inf @@ -48,6 +48,7 @@ gHardwareInterruptProtocolGuid [Pcd.common] + gArmPlatformTokenSpaceGuid.PcdSP804FrequencyInMHz gEmbeddedTokenSpaceGuid.PcdTimerPeriod [Depex] diff --git a/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.c b/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.c index 96c43aa042..2508897391 100644 --- a/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.c +++ b/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.c @@ -74,11 +74,16 @@ MicroSecondDelay ( IN UINTN MicroSeconds ) { - // load the timer count register - MmioWrite32 (SP804_TIMER2_BASE + SP804_TIMER_LOAD_REG, MicroSeconds); + UINTN Index; - while (MmioRead32 (SP804_TIMER2_BASE + SP804_TIMER_CURRENT_REG) > 0) { - ; + // Reload the counter for each 1Mhz to avoid an overflow in the load value + for (Index = 0; Index < (UINTN)PcdGet32(PcdSP804FrequencyInMHz); Index++) { + // load the timer count register + MmioWrite32 (SP804_TIMER2_BASE + SP804_TIMER_LOAD_REG, MicroSeconds); + + while (MmioRead32 (SP804_TIMER2_BASE + SP804_TIMER_CURRENT_REG) > 0) { + ; + } } return MicroSeconds; @@ -100,17 +105,21 @@ NanoSecondDelay ( IN UINTN NanoSeconds ) { - UINT32 MicroSeconds; + UINTN Index; + UINT32 MicroSeconds; // Round up to 1us Tick Number MicroSeconds = (UINT32)NanoSeconds / 1000; MicroSeconds += ((UINT32)NanoSeconds % 1000) == 0 ? 0 : 1; - // load the timer count register - MmioWrite32 (SP804_TIMER2_BASE + SP804_TIMER_LOAD_REG, MicroSeconds); + // Reload the counter for each 1Mhz to avoid an overflow in the load value + for (Index = 0; Index < (UINTN)PcdGet32(PcdSP804FrequencyInMHz); Index++) { + // load the timer count register + MmioWrite32 (SP804_TIMER2_BASE + SP804_TIMER_LOAD_REG, MicroSeconds); - while (MmioRead32 (SP804_TIMER2_BASE + SP804_TIMER_CURRENT_REG) > 0) { - ; + while (MmioRead32 (SP804_TIMER2_BASE + SP804_TIMER_CURRENT_REG) > 0) { + ; + } } return NanoSeconds; @@ -182,5 +191,5 @@ GetPerformanceCounterProperties ( *EndValue = 0xFFFFFFFF; } - return 1000000; + return PcdGet64 (PcdEmbeddedPerformanceCounterFrequencyInHz); } diff --git a/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf b/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf index 7481236c2f..1cbb32ecb6 100644 --- a/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf +++ b/ArmPlatformPkg/Library/SP804TimerLib/SP804TimerLib.inf @@ -2,7 +2,7 @@ # Timer library implementation # # -# Copyright (c) 2010, ARM Ltd. All rights reserved.<BR> +# Copyright (c) 2011, ARM Ltd. All rights reserved.<BR> # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -30,8 +30,13 @@ MdePkg/MdePkg.dec ArmPkg/ArmPkg.dec ArmPlatformPkg/ArmPlatformPkg.dec + EmbeddedPkg/EmbeddedPkg.dec [LibraryClasses] DebugLib IoLib BaseLib + +[Pcd] + gArmPlatformTokenSpaceGuid.PcdSP804FrequencyInMHz + gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz |