]> git.proxmox.com Git - mirror_edk2.git/blame - ArmEbPkg/Library/TimerLib/TimerLib.c
A better template, with some build scripts, for ArmEbPkg. New libraries are just...
[mirror_edk2.git] / ArmEbPkg / Library / TimerLib / TimerLib.c
CommitLineData
b76848cb 1/** @file\r
2\r
3 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
4 \r
5 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\r
23\r
24UINTN\r
25EFIAPI\r
26MicroSecondDelay (\r
27 IN UINTN MicroSeconds\r
28 )\r
29{\r
30 UINT64 NanoSeconds;\r
31 \r
32 NanoSeconds = MultU64x32 (MicroSeconds, 1000);\r
33\r
34 while (NanoSeconds > (UINTN)-1) { \r
35 NanoSecondDelay((UINTN)-1);\r
36 NanoSeconds -= (UINTN)-1;\r
37 }\r
38\r
39 NanoSecondDelay (NanoSeconds);\r
40\r
41 return MicroSeconds;\r
42}\r
43\r
44UINTN\r
45EFIAPI\r
46NanoSecondDelay (\r
47 IN UINTN NanoSeconds\r
48 )\r
49{\r
50 UINT32 Delay;\r
51 UINT32 StartTime;\r
52 UINT32 CurrentTime;\r
53 UINT32 ElapsedTime;\r
54\r
55 \r
56 Delay = (NanoSeconds / PcdGet32(PcdEmbeddedPerformanceCounterPeriodInNanoseconds)) + 1;\r
57\r
58 StartTime = MmioRead32 (0);\r
59 do \r
60 {\r
61 CurrentTime = 0ULL;\r
62 ElapsedTime = CurrentTime - StartTime;\r
63 } while (ElapsedTime < Delay);\r
64\r
65 NanoSeconds = ElapsedTime * PcdGet32 (PcdEmbeddedPerformanceCounterPeriodInNanoseconds);\r
66\r
67 return NanoSeconds;\r
68}\r
69\r
70UINT64\r
71EFIAPI\r
72GetPerformanceCounter (\r
73 VOID\r
74 )\r
75{ \r
76 return (UINT64)0ULL;\r
77}\r
78\r
79UINT64\r
80EFIAPI\r
81GetPerformanceCounterProperties (\r
82 OUT UINT64 *StartValue, OPTIONAL\r
83 OUT UINT64 *EndValue OPTIONAL\r
84 )\r
85{\r
86 if (StartValue != NULL) {\r
87 // Timer starts with the reload value\r
88 *StartValue = (UINT64)0ULL;\r
89 }\r
90 \r
91 if (EndValue != NULL) {\r
92 // Timer counts up to 0xFFFFFFFF\r
93 *EndValue = 0xFFFFFFFF;\r
94 }\r
95 \r
96 return PcdGet64(PcdEmbeddedPerformanceCounterFrequencyInHz);\r
97}\r