+/** @file\r
+\r
+ Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
+ \r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/OmapLib.h>\r
+\r
+#include <Omap3530/Omap3530.h>\r
+\r
+UINTN\r
+EFIAPI\r
+MicroSecondDelay (\r
+ IN UINTN MicroSeconds\r
+ )\r
+{\r
+ UINT64 NanoSeconds;\r
+ \r
+ NanoSeconds = MultU64x32(MicroSeconds, 1000);\r
+\r
+ while (NanoSeconds > (UINTN)-1) { \r
+ NanoSecondDelay((UINTN)-1);\r
+ NanoSeconds -= (UINTN)-1;\r
+ }\r
+\r
+ NanoSecondDelay(NanoSeconds);\r
+\r
+ return MicroSeconds;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+NanoSecondDelay (\r
+ IN UINTN NanoSeconds\r
+ )\r
+{\r
+ UINT32 Delay;\r
+ UINT32 StartTime;\r
+ UINT32 CurrentTime;\r
+ UINT32 ElapsedTime;\r
+ UINT32 TimerCountRegister;\r
+\r
+ Delay = (NanoSeconds / PcdGet32(PcdEmbeddedFdPerformanceCounterPeriodInNanoseconds)) + 1;\r
+ \r
+ TimerCountRegister = TimerBase(PcdGet32(PcdOmap35xxFreeTimer)) + GPTIMER_TCRR;\r
+\r
+ StartTime = MmioRead32 (TimerCountRegister);\r
+\r
+ do \r
+ {\r
+ CurrentTime = MmioRead32 (TimerCountRegister);\r
+ ElapsedTime = CurrentTime - StartTime;\r
+ } while (ElapsedTime < Delay);\r
+\r
+ NanoSeconds = ElapsedTime * PcdGet32(PcdEmbeddedFdPerformanceCounterPeriodInNanoseconds);\r
+\r
+ return NanoSeconds;\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounter (\r
+ VOID\r
+ )\r
+{ \r
+ return (UINT64)MmioRead32 (TimerBase(PcdGet32(PcdOmap35xxFreeTimer)) + GPTIMER_TCRR);\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounterProperties (\r
+ OUT UINT64 *StartValue, OPTIONAL\r
+ OUT UINT64 *EndValue OPTIONAL\r
+ )\r
+{\r
+ if (StartValue != NULL) {\r
+ // Timer starts with the reload value\r
+ *StartValue = (UINT64)MmioRead32 (TimerBase(PcdGet32(PcdOmap35xxFreeTimer)) + GPTIMER_TLDR);\r
+ }\r
+ \r
+ if (EndValue != NULL) {\r
+ // Timer counts up to 0xFFFFFFFF\r
+ *EndValue = 0xFFFFFFFF;\r
+ }\r
+ \r
+ return PcdGet64(PcdEmbeddedPerformanceCounterFreqencyInHz);\r
+}\r