summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShumin Qiu <shumin.qiu@intel.com>2013-09-29 05:51:12 +0000
committershenshushi <shenshushi@6f19259b-4bc3-4df7-8a09-765794883524>2013-09-29 05:51:12 +0000
commit6a0d41c090d33387dac72d2b121d31a232960344 (patch)
tree0a6a99b7b6dc4ced09a8a3384475f27ba93e097c
parent571c73b5a43c50218ffa3b927f6e3a6fb9ba5e68 (diff)
downloadedk2-platforms-6a0d41c090d33387dac72d2b121d31a232960344.tar.xz
Add the definition for Timestamp Protocol and a new driver base on TimerLib to produce Timestamp protocol.
Signed-off-by: Shumin Qiu <shumin.qiu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14739 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--MdeModulePkg/MdeModulePkg.dsc1
-rw-r--r--MdeModulePkg/Universal/TimestampDxe/TimestampDxe.c166
-rw-r--r--MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf49
-rw-r--r--MdePkg/Include/Protocol/Timestamp.h101
-rw-r--r--MdePkg/MdePkg.dec3
5 files changed, 320 insertions, 0 deletions
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index a2248697db..f31a4d156b 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -303,6 +303,7 @@
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+ MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
diff --git a/MdeModulePkg/Universal/TimestampDxe/TimestampDxe.c b/MdeModulePkg/Universal/TimestampDxe/TimestampDxe.c
new file mode 100644
index 0000000000..30349b5ec5
--- /dev/null
+++ b/MdeModulePkg/Universal/TimestampDxe/TimestampDxe.c
@@ -0,0 +1,166 @@
+/** @file
+ Implementation of Timestamp Protocol using UEFI APIs.
+
+Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Uefi.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/TimerLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Protocol/Timestamp.h>
+
+//
+// The StartValue in TimerLib
+//
+UINT64 mTimerLibStartValue = 0;
+
+//
+// The EndValue in TimerLib
+//
+UINT64 mTimerLibEndValue = 0;
+
+//
+// The properties of timestamp
+//
+EFI_TIMESTAMP_PROPERTIES mTimestampProperties = {
+ 0,
+ 0
+};
+
+/**
+ Retrieves the current value of a 64-bit free running timestamp counter.
+
+ The counter shall count up in proportion to the amount of time that has passed. The counter value
+ will always roll over to zero. The properties of the counter can be retrieved from GetProperties().
+ The caller should be prepared for the function to return the same value twice across successive calls.
+ The counter value will not go backwards other than when wrapping, as defined by EndValue in GetProperties().
+ The frequency of the returned timestamp counter value must remain constant. Power management operations that
+ affect clocking must not change the returned counter frequency. The quantization of counter value updates may
+ vary as long as the value reflecting time passed remains consistent.
+
+ @retval The current value of the free running timestamp counter.
+
+**/
+UINT64
+EFIAPI
+TimestampDriverGetTimestamp (
+ VOID
+ )
+{
+ //
+ // The timestamp of Timestamp Protocol
+ //
+ UINT64 TimestampValue;
+ TimestampValue = 0;
+
+ //
+ // Get the timestamp
+ //
+ if (mTimerLibStartValue > mTimerLibEndValue) {
+ TimestampValue = mTimerLibStartValue - GetPerformanceCounter();
+ } else {
+ TimestampValue = GetPerformanceCounter() - mTimerLibStartValue;
+ }
+
+ return TimestampValue;
+}
+
+/**
+ Obtains timestamp counter properties including frequency and value limits.
+
+ @param[out] Properties The properties of the timestamp counter.
+
+ @retval EFI_SUCCESS The properties were successfully retrieved.
+ @retval EFI_DEVICE_ERROR An error occurred trying to retrieve the properties of the timestamp
+ counter subsystem. Properties is not pedated.
+ @retval EFI_INVALID_PARAMETER Properties is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+TimestampDriverGetProperties(
+ OUT EFI_TIMESTAMP_PROPERTIES *Properties
+ )
+{
+ if (Properties == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Get timestamp properties
+ //
+ CopyMem((VOID *) Properties, (VOID *) &mTimestampProperties, sizeof (mTimestampProperties));
+
+ return EFI_SUCCESS;
+}
+
+//
+// The Timestamp Protocol instance produced by this driver
+//
+EFI_TIMESTAMP_PROTOCOL mTimestamp = {
+ TimestampDriverGetTimestamp,
+ TimestampDriverGetProperties
+};
+
+/**
+ Entry point of the Timestamp Protocol driver.
+
+ @param ImageHandle The image handle of this driver.
+ @param SystemTable The pointer of EFI_SYSTEM_TABLE.
+
+ @retval EFI_SUCCESS Watchdog Timer Architectural Protocol successfully installed.
+
+**/
+EFI_STATUS
+EFIAPI
+TimestampDriverInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ EFI_HANDLE TimestampHandle;
+ TimestampHandle = NULL;
+
+ //
+ // Get the start value, end value and frequency in Timerlib
+ //
+ mTimestampProperties.Frequency = GetPerformanceCounterProperties(&mTimerLibStartValue, &mTimerLibEndValue);
+
+ //
+ // Set the EndValue
+ //
+ if (mTimerLibEndValue > mTimerLibStartValue) {
+ mTimestampProperties.EndValue = mTimerLibEndValue - mTimerLibStartValue;
+ } else {
+ mTimestampProperties.EndValue = mTimerLibStartValue - mTimerLibEndValue;
+ }
+
+ DEBUG ((EFI_D_INFO, "TimerFrequency:0x%lx, TimerLibStartTime:0x%lx, TimerLibEndtime:0x%lx\n", mTimestampProperties.Frequency, mTimerLibStartValue, mTimerLibEndValue));
+
+ //
+ // Install the Timestamp Protocol onto a new handle
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &TimestampHandle,
+ &gEfiTimestampProtocolGuid,
+ &mTimestamp,
+ NULL
+ );
+
+ ASSERT_EFI_ERROR (Status);
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf b/MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf
new file mode 100644
index 0000000000..95b0a08384
--- /dev/null
+++ b/MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf
@@ -0,0 +1,49 @@
+## @file
+# Generic Timestamp driver produceing Timestamp Protocol using UEFI APIs.
+#
+# Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = TimestampDxe
+ FILE_GUID = C10194E7-DEB2-4AF4-9EEE-BFFDE4D7D4C7
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = TimestampDriverInitialize
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[Sources]
+ TimestampDxe.c
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ UefiDriverEntryPoint
+ TimerLib
+ BaseMemoryLib
+ DebugLib
+
+[Protocols]
+ gEfiTimestampProtocolGuid ## PRODUCES
+
+[depex]
+ TRUE
+
+
diff --git a/MdePkg/Include/Protocol/Timestamp.h b/MdePkg/Include/Protocol/Timestamp.h
new file mode 100644
index 0000000000..9be72426e6
--- /dev/null
+++ b/MdePkg/Include/Protocol/Timestamp.h
@@ -0,0 +1,101 @@
+/** @file
+ EFI Timestamp Protocol as defined in UEFI2.4 Specification.
+ Used to provide a platform independent interface for retrieving a high resolution timestamp counter.
+
+ Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ @par Revision Reference:
+ This Protocol is introduced in UEFI Specification 2.4
+
+**/
+
+#ifndef __EFI_TIME_STAMP_PROTOCOL_H__
+#define __EFI_TIME_STAMP_PROTOCOL_H__
+
+
+#define EFI_TIMESTAMP_PROTOCOL_GUID \
+ { 0xafbfde41, 0x2e6e, 0x4262, {0xba, 0x65, 0x62, 0xb9, 0x23, 0x6e, 0x54, 0x95 } }
+
+///
+/// Declare forward reference for the Time Stamp Protocol
+///
+typedef struct _EFI_TIMESTAMP_PROTOCOL EFI_TIMESTAMP_PROTOCOL;
+
+///
+/// EFI_TIMESTAMP_PROPERTIES
+///
+typedef struct {
+ ///
+ /// The frequency of the timestamp counter in Hz.
+ ///
+ UINT64 Frequency;
+ ///
+ /// The value that the timestamp counter ends with immediately before it rolls over.
+ /// For example, a 64-bit free running counter would have an EndValue of 0xFFFFFFFFFFFFFFFF.
+ /// A 24-bit free running counter would have an EndValue of 0xFFFFFF.
+ ///
+ UINT64 EndValue;
+} EFI_TIMESTAMP_PROPERTIES;
+
+/**
+ Retrieves the current value of a 64-bit free running timestamp counter.
+
+ The counter shall count up in proportion to the amount of time that has passed. The counter value
+ will always roll over to zero. The properties of the counter can be retrieved from GetProperties().
+ The caller should be prepared for the function to return the same value twice across successive calls.
+ The counter value will not go backwards other than when wrapping, as defined by EndValue in GetProperties().
+ The frequency of the returned timestamp counter value must remain constant. Power management operations that
+ affect clocking must not change the returned counter frequency. The quantization of counter value updates may
+ vary as long as the value reflecting time passed remains consistent.
+
+ @param None.
+
+ @retval The current value of the free running timestamp counter.
+
+**/
+typedef
+UINT64
+(EFIAPI *TIMESTAMP_GET)(
+ VOID
+ );
+
+/**
+ Obtains timestamp counter properties including frequency and value limits.
+
+ @param[out] Properties The properties of the timestamp counter.
+
+ @retval EFI_SUCCESS The properties were successfully retrieved.
+ @retval EFI_DEVICE_ERROR An error occurred trying to retrieve the properties of the timestamp
+ counter subsystem. Properties is not pedated.
+ @retval EFI_INVALID_PARAMETER Properties is NULL.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *TIMESTAMP_GET_PROPERTIES)(
+ OUT EFI_TIMESTAMP_PROPERTIES *Properties
+ );
+
+
+
+///
+/// EFI_TIMESTAMP_PROTOCOL
+/// The protocol provides a platform independent interface for retrieving a high resolution
+/// timestamp counter.
+///
+struct _EFI_TIMESTAMP_PROTOCOL {
+ TIMESTAMP_GET GetTimestamp;
+ TIMESTAMP_GET_PROPERTIES GetProperties;
+};
+
+extern EFI_GUID gEfiTimestampProtocolGuid;
+
+#endif
+
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 5c74c58424..916e538774 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -1307,6 +1307,9 @@
## Include/Protocol/DiskIo2.h
gEfiDiskIo2ProtocolGuid = { 0x151c8eae, 0x7f2c, 0x472c, { 0x9e, 0x54, 0x98, 0x28, 0x19, 0x4f, 0x6a, 0x88 }}
+ ## Include/Protocol/Timestamp.h
+ gEfiTimestampProtocolGuid = { 0xafbfde41, 0x2e6e, 0x4262, {0xba, 0x65, 0x62, 0xb9, 0x23, 0x6e, 0x54, 0x95 }}
+
[PcdsFeatureFlag]
## If TRUE, the component name protocol will not be installed.
gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|FALSE|BOOLEAN|0x0000000d