3 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
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
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.
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>
32 NanoSeconds
= MultU64x32 (MicroSeconds
, 1000);
34 while (NanoSeconds
> (UINTN
)-1) {
35 NanoSecondDelay((UINTN
)-1);
36 NanoSeconds
-= (UINTN
)-1;
39 NanoSecondDelay (NanoSeconds
);
56 Delay
= (NanoSeconds
/ PcdGet32(PcdEmbeddedPerformanceCounterPeriodInNanoseconds
)) + 1;
58 StartTime
= MmioRead32 (0);
62 ElapsedTime
= CurrentTime
- StartTime
;
63 } while (ElapsedTime
< Delay
);
65 NanoSeconds
= ElapsedTime
* PcdGet32 (PcdEmbeddedPerformanceCounterPeriodInNanoseconds
);
72 GetPerformanceCounter (
81 GetPerformanceCounterProperties (
82 OUT UINT64
*StartValue
, OPTIONAL
83 OUT UINT64
*EndValue OPTIONAL
86 if (StartValue
!= NULL
) {
87 // Timer starts with the reload value
88 *StartValue
= (UINT64
)0ULL;
91 if (EndValue
!= NULL
) {
92 // Timer counts up to 0xFFFFFFFF
93 *EndValue
= 0xFFFFFFFF;
96 return PcdGet64(PcdEmbeddedPerformanceCounterFrequencyInHz
);