summaryrefslogtreecommitdiff
path: root/MdePkg/Library/BaseTimerLibLocalApic/Ipf
diff options
context:
space:
mode:
authorbxing <bxing@6f19259b-4bc3-4df7-8a09-765794883524>2006-07-25 07:33:02 +0000
committerbxing <bxing@6f19259b-4bc3-4df7-8a09-765794883524>2006-07-25 07:33:02 +0000
commited384ef31cff0681d724847c684476aed214917c (patch)
tree5ab7db3035f36e556b2b6bdb8dfde327f241d001 /MdePkg/Library/BaseTimerLibLocalApic/Ipf
parent26015d229452d2916521506cad5cd3647474cf8d (diff)
downloadedk2-platforms-ed384ef31cff0681d724847c684476aed214917c.tar.xz
1. Updated declaration of timer functions according to latest MWG.
2. Updated coding style. 3. Updated the algorithm used in delay functions to handle timer counter wrap-around. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1089 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library/BaseTimerLibLocalApic/Ipf')
-rw-r--r--MdePkg/Library/BaseTimerLibLocalApic/Ipf/IpfTimerLib.c106
-rw-r--r--MdePkg/Library/BaseTimerLibLocalApic/Ipf/ReadItc.s11
2 files changed, 88 insertions, 29 deletions
diff --git a/MdePkg/Library/BaseTimerLibLocalApic/Ipf/IpfTimerLib.c b/MdePkg/Library/BaseTimerLibLocalApic/Ipf/IpfTimerLib.c
index 3814534607..800b5258e3 100644
--- a/MdePkg/Library/BaseTimerLibLocalApic/Ipf/IpfTimerLib.c
+++ b/MdePkg/Library/BaseTimerLibLocalApic/Ipf/IpfTimerLib.c
@@ -18,11 +18,6 @@
**/
-UINT64
-ReadItc (
- VOID
- );
-
typedef struct {
UINT64 Status;
UINT64 r9;
@@ -30,6 +25,21 @@ typedef struct {
UINT64 r11;
} PAL_PROC_RETURN;
+/**
+ Performs a PAL call using static calling convention.
+
+ An internal function to perform a PAL call using static calling convention.
+
+ @param PalEntryPoint The entry point address of PAL. The address in ar.kr5
+ would be used if this parameter were NULL on input.
+ @param Arg1 The first argument of a PAL call.
+ @param Arg1 The second argument of a PAL call.
+ @param Arg1 The third argument of a PAL call.
+ @param Arg1 The fourth argument of a PAL call.
+
+ @return The values returned in r8, r9, r10 and r11.
+
+**/
PAL_PROC_RETURN
PalCallStatic (
IN CONST VOID *PalEntryPoint,
@@ -40,13 +50,57 @@ PalCallStatic (
);
/**
+ Returns the current value of ar.itc.
+
+ An internal function to return the current value of ar.itc, which is the
+ timer tick on IPF.
+
+ @return The currect value of ar.itc
+
+**/
+INT64
+InternalIpfReadItc (
+ VOID
+ );
+
+/**
+ Performs a delay measured as number of ticks.
+
+ An internal function to perform a delay measured as number of ticks. It's
+ invoked by MicroSecondDelay() and NanoSecondDelay().
+
+ @param Delay Number of ticks to delay.
+
+**/
+STATIC
+VOID
+InternalIpfDelay (
+ IN INT64 Delay
+ )
+{
+ INT64 Ticks;
+
+ //
+ // The target timer count is calculated here
+ //
+ Ticks = InternalIpfReadItc () + Delay;
+
+ //
+ // Wait until time out
+ // Delay > 2^63 could not be handled by this function
+ // Timer wrap-arounds are handled correctly by this function
+ //
+ while (Ticks - InternalIpfReadItc () >= 0);
+}
+
+/**
Stalls the CPU for at least the given number of microseconds.
Stalls the CPU for the number of microseconds specified by MicroSeconds.
@param MicroSeconds The minimum number of microseconds to delay.
- @return The ticks delayed actually.
+ @return MicroSeconds
**/
UINTN
@@ -55,13 +109,12 @@ MicroSecondDelay (
IN UINTN MicroSeconds
)
{
- UINT64 Ticks;
- UINT64 Delay;
-
- Ticks = GetPerformanceCounter ();
- Delay = GetPerformanceCounterProperties (NULL, NULL) * MicroSeconds / 1000000;
- while (Ticks + Delay >= GetPerformanceCounter ());
- return (UINTN)Delay;
+ InternalIpfDelay (
+ GetPerformanceCounterProperties (NULL, NULL) *
+ MicroSeconds /
+ 1000000
+ );
+ return MicroSeconds;
}
/**
@@ -71,7 +124,7 @@ MicroSecondDelay (
@param NanoSeconds The minimum number of nanoseconds to delay.
- @return The ticks delayed actually.
+ @return NanoSeconds
**/
UINTN
@@ -80,13 +133,12 @@ NanoSecondDelay (
IN UINTN NanoSeconds
)
{
- UINT64 Ticks;
- UINT64 Delay;
-
- Ticks = GetPerformanceCounter ();
- Delay = GetPerformanceCounterProperties (NULL, NULL) * NanoSeconds / 1000000000;
- while (Ticks + Delay >= GetPerformanceCounter ());
- return (UINTN)Delay;
+ InternalIpfDelay (
+ GetPerformanceCounterProperties (NULL, NULL) *
+ NanoSeconds /
+ 1000000000
+ );
+ return NanoSeconds;
}
/**
@@ -107,7 +159,7 @@ GetPerformanceCounter (
VOID
)
{
- return ReadItc ();
+ return InternalIpfReadItc ();
}
/**
@@ -150,7 +202,13 @@ GetPerformanceCounterProperties (
PalRet = PalCallStatic (NULL, 14, 0, 0, 0);
ASSERT (PalRet.Status == 0);
- *StartValue = 0;
- *EndValue = (UINT64)(-1);
+ if (StartValue != NULL) {
+ *StartValue = 0;
+ }
+
+ if (EndValue != NULL) {
+ *EndValue = (UINT64)(-1);
+ }
+
return BaseFrequence * (PalRet.r11 >> 32) / (UINT32)PalRet.r11;
}
diff --git a/MdePkg/Library/BaseTimerLibLocalApic/Ipf/ReadItc.s b/MdePkg/Library/BaseTimerLibLocalApic/Ipf/ReadItc.s
index 383bb242ba..ea94b670e7 100644
--- a/MdePkg/Library/BaseTimerLibLocalApic/Ipf/ReadItc.s
+++ b/MdePkg/Library/BaseTimerLibLocalApic/Ipf/ReadItc.s
@@ -1,5 +1,6 @@
/// @file
-/// Contains an implementation of ReadItc on Itanium-based architecture.
+/// Contains an implementation of InternalIpfReadItc () on Itanium-based
+/// architecture.
///
/// Copyright (c) 2006, Intel Corporation
/// All rights reserved. This program and the accompanying materials
@@ -17,9 +18,9 @@
.auto
.text
-.proc ReadItc
-.type ReadItc, @function
-ReadItc::
+.proc InternalIpfReadItc
+.type InternalIpfReadItc, @function
+InternalIpfReadItc::
mov r8 = ar.itc
br.ret.sptk.many b0
-.endp ReadItc \ No newline at end of file
+.endp InternalIpfReadItc