Correct PCD Pcd8259LegacyModeMask and Pcd8259LegacyModeEdgeLevel definition in PcAtC...
[mirror_edk2.git] / Omap35xxPkg / Library / BeagleBoardTimerLib / TimerLib.c
CommitLineData
a3f98646 1/** @file\r
2\r
3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
4 \r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Base.h>\r
16\r
17#include <Library/BaseLib.h>\r
18#include <Library/TimerLib.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/PcdLib.h>\r
21#include <Library/IoLib.h>\r
22#include <Library/OmapLib.h>\r
23\r
24#include <Omap3530/Omap3530.h>\r
25\r
26UINTN\r
27EFIAPI\r
28MicroSecondDelay (\r
29 IN UINTN MicroSeconds\r
30 )\r
31{\r
32 UINT64 NanoSeconds;\r
33 \r
34 NanoSeconds = MultU64x32(MicroSeconds, 1000);\r
35\r
36 while (NanoSeconds > (UINTN)-1) { \r
37 NanoSecondDelay((UINTN)-1);\r
38 NanoSeconds -= (UINTN)-1;\r
39 }\r
40\r
41 NanoSecondDelay(NanoSeconds);\r
42\r
43 return MicroSeconds;\r
44}\r
45\r
46UINTN\r
47EFIAPI\r
48NanoSecondDelay (\r
49 IN UINTN NanoSeconds\r
50 )\r
51{\r
52 UINT32 Delay;\r
53 UINT32 StartTime;\r
54 UINT32 CurrentTime;\r
55 UINT32 ElapsedTime;\r
56 UINT32 TimerCountRegister;\r
57\r
58 Delay = (NanoSeconds / PcdGet32(PcdEmbeddedFdPerformanceCounterPeriodInNanoseconds)) + 1;\r
59 \r
60 TimerCountRegister = TimerBase(PcdGet32(PcdBeagleFreeTimer)) + GPTIMER_TCRR;\r
61\r
62 StartTime = MmioRead32(TimerCountRegister);\r
63\r
64 do \r
65 {\r
66 CurrentTime = MmioRead32(TimerCountRegister);\r
67 ElapsedTime = CurrentTime - StartTime;\r
68 } while (ElapsedTime < Delay);\r
69\r
70 NanoSeconds = ElapsedTime * PcdGet32(PcdEmbeddedFdPerformanceCounterPeriodInNanoseconds);\r
71\r
72 return NanoSeconds;\r
73}\r
74\r
75UINT64\r
76EFIAPI\r
77GetPerformanceCounter (\r
78 VOID\r
79 )\r
80{ \r
81 return (UINT64)MmioRead32(TimerBase(PcdGet32(PcdBeagleFreeTimer)) + GPTIMER_TCRR);\r
82}\r
83\r
84UINT64\r
85EFIAPI\r
86GetPerformanceCounterProperties (\r
87 OUT UINT64 *StartValue, OPTIONAL\r
88 OUT UINT64 *EndValue OPTIONAL\r
89 )\r
90{\r
91 if (StartValue != NULL) {\r
92 // Timer starts with the reload value\r
93 *StartValue = (UINT64)MmioRead32(TimerBase(PcdGet32(PcdBeagleFreeTimer)) + GPTIMER_TLDR);\r
94 }\r
95 \r
96 if (EndValue != NULL) {\r
97 // Timer counts up to 0xFFFFFFFF\r
98 *EndValue = 0xFFFFFFFF;\r
99 }\r
100 \r
101 return PcdGet64(PcdEmbeddedPerformanceCounterFreqencyInHz);\r
102}\r