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