blob: 1b1f2a9dbe227ba26042174555dfe37b99ae5614 [file] [log] [blame]
andrewfisha3f98642010-01-28 21:32:01 +00001/** @file
2
3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
4
5 All rights reserved. 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#include <Library/OmapLib.h>
23
24#include <Omap3530/Omap3530.h>
25
26UINTN
27EFIAPI
28MicroSecondDelay (
29 IN UINTN MicroSeconds
30 )
31{
32 UINT64 NanoSeconds;
33
34 NanoSeconds = MultU64x32(MicroSeconds, 1000);
35
36 while (NanoSeconds > (UINTN)-1) {
37 NanoSecondDelay((UINTN)-1);
38 NanoSeconds -= (UINTN)-1;
39 }
40
41 NanoSecondDelay(NanoSeconds);
42
43 return MicroSeconds;
44}
45
46UINTN
47EFIAPI
48NanoSecondDelay (
49 IN UINTN NanoSeconds
50 )
51{
52 UINT32 Delay;
53 UINT32 StartTime;
54 UINT32 CurrentTime;
55 UINT32 ElapsedTime;
56 UINT32 TimerCountRegister;
57
58 Delay = (NanoSeconds / PcdGet32(PcdEmbeddedFdPerformanceCounterPeriodInNanoseconds)) + 1;
59
andrewfish43263282010-04-03 00:34:19 +000060 TimerCountRegister = TimerBase(PcdGet32(PcdOmap35xxFreeTimer)) + GPTIMER_TCRR;
andrewfisha3f98642010-01-28 21:32:01 +000061
andrewfish43263282010-04-03 00:34:19 +000062 StartTime = MmioRead32 (TimerCountRegister);
andrewfisha3f98642010-01-28 21:32:01 +000063
64 do
65 {
andrewfish43263282010-04-03 00:34:19 +000066 CurrentTime = MmioRead32 (TimerCountRegister);
andrewfisha3f98642010-01-28 21:32:01 +000067 ElapsedTime = CurrentTime - StartTime;
68 } while (ElapsedTime < Delay);
69
70 NanoSeconds = ElapsedTime * PcdGet32(PcdEmbeddedFdPerformanceCounterPeriodInNanoseconds);
71
72 return NanoSeconds;
73}
74
75UINT64
76EFIAPI
77GetPerformanceCounter (
78 VOID
79 )
80{
andrewfish43263282010-04-03 00:34:19 +000081 return (UINT64)MmioRead32 (TimerBase(PcdGet32(PcdOmap35xxFreeTimer)) + GPTIMER_TCRR);
andrewfisha3f98642010-01-28 21:32:01 +000082}
83
84UINT64
85EFIAPI
86GetPerformanceCounterProperties (
87 OUT UINT64 *StartValue, OPTIONAL
88 OUT UINT64 *EndValue OPTIONAL
89 )
90{
91 if (StartValue != NULL) {
92 // Timer starts with the reload value
andrewfish43263282010-04-03 00:34:19 +000093 *StartValue = (UINT64)MmioRead32 (TimerBase(PcdGet32(PcdOmap35xxFreeTimer)) + GPTIMER_TLDR);
andrewfisha3f98642010-01-28 21:32:01 +000094 }
95
96 if (EndValue != NULL) {
97 // Timer counts up to 0xFFFFFFFF
98 *EndValue = 0xFFFFFFFF;
99 }
100
101 return PcdGet64(PcdEmbeddedPerformanceCounterFreqencyInHz);
102}