]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add the definition for Timestamp Protocol and a new driver base on TimerLib to produ...
authorShumin Qiu <shumin.qiu@intel.com>
Sun, 29 Sep 2013 05:51:12 +0000 (05:51 +0000)
committershenshushi <shenshushi@6f19259b-4bc3-4df7-8a09-765794883524>
Sun, 29 Sep 2013 05:51:12 +0000 (05:51 +0000)
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

MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/Universal/TimestampDxe/TimestampDxe.c [new file with mode: 0644]
MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf [new file with mode: 0644]
MdePkg/Include/Protocol/Timestamp.h [new file with mode: 0644]
MdePkg/MdePkg.dec

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