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 |
26 | UINTN\r |
27 | EFIAPI\r |
28 | MicroSecondDelay (\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 |
46 | UINTN\r |
47 | EFIAPI\r |
48 | NanoSecondDelay (\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 |
55bff42e |
58 | Delay = (NanoSeconds / PcdGet32(PcdEmbeddedPerformanceCounterPeriodInNanoseconds)) + 1;\r |
a3f98646 |
59 | \r |
43263288 |
60 | TimerCountRegister = TimerBase(PcdGet32(PcdOmap35xxFreeTimer)) + GPTIMER_TCRR;\r |
a3f98646 |
61 | \r |
43263288 |
62 | StartTime = MmioRead32 (TimerCountRegister);\r |
a3f98646 |
63 | \r |
64 | do \r |
65 | {\r |
43263288 |
66 | CurrentTime = MmioRead32 (TimerCountRegister);\r |
a3f98646 |
67 | ElapsedTime = CurrentTime - StartTime;\r |
68 | } while (ElapsedTime < Delay);\r |
69 | \r |
55bff42e |
70 | NanoSeconds = ElapsedTime * PcdGet32(PcdEmbeddedPerformanceCounterPeriodInNanoseconds);\r |
a3f98646 |
71 | \r |
72 | return NanoSeconds;\r |
73 | }\r |
74 | \r |
75 | UINT64\r |
76 | EFIAPI\r |
77 | GetPerformanceCounter (\r |
78 | VOID\r |
79 | )\r |
80 | { \r |
43263288 |
81 | return (UINT64)MmioRead32 (TimerBase(PcdGet32(PcdOmap35xxFreeTimer)) + GPTIMER_TCRR);\r |
a3f98646 |
82 | }\r |
83 | \r |
84 | UINT64\r |
85 | EFIAPI\r |
86 | GetPerformanceCounterProperties (\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 |
43263288 |
93 | *StartValue = (UINT64)MmioRead32 (TimerBase(PcdGet32(PcdOmap35xxFreeTimer)) + GPTIMER_TLDR);\r |
a3f98646 |
94 | }\r |
95 | \r |
96 | if (EndValue != NULL) {\r |
97 | // Timer counts up to 0xFFFFFFFF\r |
98 | *EndValue = 0xFFFFFFFF;\r |
99 | }\r |
100 | \r |
55bff42e |
101 | return PcdGet64(PcdEmbeddedPerformanceCounterFrequencyInHz);\r |
a3f98646 |
102 | }\r |