]> git.proxmox.com Git - mirror_edk2.git/commitdiff
InOsEmuPkg: Add TimerLib for PEI, DXE_CORE, and DXE/EFI drivers/applications.
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 21 Jun 2011 23:41:31 +0000 (23:41 +0000)
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 21 Jun 2011 23:41:31 +0000 (23:41 +0000)
Start using MdeModulePkg MetronomeDxe driver. Add PEI and DXE_CORE TimerLibs that just call back to the emulator. Add a DXE/UEFI TimerLib that also does a gBS->WaitForEvent() if the stall is for a long period of time. Change the Thunk API for Sleep to nanoseconds.

Signed-off-by: andrewfish
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11872 6f19259b-4bc3-4df7-8a09-765794883524

16 files changed:
InOsEmuPkg/CpuRuntimeDxe/MpService.c
InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c [new file with mode: 0644]
InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.c [new file with mode: 0644]
InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.inf [new file with mode: 0644]
InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.c [new file with mode: 0644]
InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.inf [new file with mode: 0644]
InOsEmuPkg/MetronomeDxe/Metronome.c [deleted file]
InOsEmuPkg/MetronomeDxe/Metronome.h [deleted file]
InOsEmuPkg/MetronomeDxe/Metronome.inf [deleted file]
InOsEmuPkg/TimerDxe/Timer.c
InOsEmuPkg/Unix/Sec/EmuThunk.c
InOsEmuPkg/Unix/Sec/Gasket.h
InOsEmuPkg/Unix/Sec/SecMain.h
InOsEmuPkg/Unix/UnixX64.dsc
InOsEmuPkg/Unix/UnixX64.fdf

index af3328c50a5a509037affbcdab7b5415c2813d75..7f3b1995f27629f9f703988505b4fa6bd3959e39 100644 (file)
@@ -1221,7 +1221,7 @@ CpuDriverApIdolLoop (
     \r
     // Poll 5 times a seconds, 200ms\r
     // Don't want to burn too many system resources doing nothing.\r
-    gEmuThunk->Sleep (200);\r
+    gEmuThunk->Sleep (200 * 1000);\r
   }\r
   \r
   return 0;\r
diff --git a/InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c b/InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.c
new file mode 100644 (file)
index 0000000..db3b313
--- /dev/null
@@ -0,0 +1,128 @@
+/** @file\r
+  A non-functional instance of the Timer Library.\r
+\r
+  Copyright (c) 2007 - 2010, 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 <PiPei.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/EmuThunkLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#include <Protocol/Timer.h>\r
+\r
+\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of microseconds.\r
+\r
+  Stalls the CPU for the number of microseconds specified by MicroSeconds.\r
+\r
+  @param  MicroSeconds  The minimum number of microseconds to delay.\r
+\r
+  @return The value of MicroSeconds inputted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+MicroSecondDelay (\r
+  IN      UINTN                     MicroSeconds\r
+  )\r
+{\r
+  return NanoSecondDelay (MicroSeconds * 1000);\r
+}\r
+\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of nanoseconds.\r
+\r
+  Stalls the CPU for the number of nanoseconds specified by NanoSeconds.\r
+\r
+  @param  NanoSeconds The minimum number of nanoseconds to delay.\r
+\r
+  @return The value of NanoSeconds inputted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+NanoSecondDelay (\r
+  IN      UINTN                     NanoSeconds\r
+  )\r
+{\r
+  gEmuThunk->Sleep (NanoSeconds);\r
+  return NanoSeconds;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves the current value of a 64-bit free running performance counter.\r
+\r
+  The counter can either count up by 1 or count down by 1. If the physical\r
+  performance counter counts by a larger increment, then the counter values\r
+  must be translated. The properties of the counter can be retrieved from\r
+  GetPerformanceCounterProperties().\r
+\r
+  @return The current value of the free running performance counter.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounter (\r
+  VOID\r
+  )\r
+{\r
+  return gEmuThunk->QueryPerformanceCounter ();\r
+}\r
+\r
+/**\r
+  Retrieves the 64-bit frequency in Hz and the range of performance counter\r
+  values.\r
+\r
+  If StartValue is not NULL, then the value that the performance counter starts\r
+  with immediately after is it rolls over is returned in StartValue. If\r
+  EndValue is not NULL, then the value that the performance counter end with\r
+  immediately before it rolls over is returned in EndValue. The 64-bit\r
+  frequency of the performance counter in Hz is always returned. If StartValue\r
+  is less than EndValue, then the performance counter counts up. If StartValue\r
+  is greater than EndValue, then the performance counter counts down. For\r
+  example, a 64-bit free running counter that counts up would have a StartValue\r
+  of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter\r
+  that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.\r
+\r
+  @param  StartValue  The value the performance counter starts with when it\r
+                      rolls over.\r
+  @param  EndValue    The value that the performance counter ends with before\r
+                      it rolls over.\r
+\r
+  @return The frequency in Hz.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounterProperties (\r
+  OUT      UINT64                    *StartValue,  OPTIONAL\r
+  OUT      UINT64                    *EndValue     OPTIONAL\r
+  )\r
+{\r
+\r
+  if (StartValue != NULL) {\r
+    *StartValue = 0ULL;\r
+  }\r
+  if (EndValue != NULL) {\r
+    *EndValue = (UINT64)-1LL;\r
+  }\r
+  \r
+  return gEmuThunk->QueryPerformanceFrequency ();\r
+}\r
+\r
+\r
diff --git a/InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.inf b/InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.inf
new file mode 100644 (file)
index 0000000..52d8394
--- /dev/null
@@ -0,0 +1,44 @@
+## @file\r
+#  NULL instance of Timer Library as a template.\r
+#\r
+#  A non-functional instance of the Timer Library that can be used as a template\r
+#  for the implementation of a functional timer library instance. This library instance can\r
+#  also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules that require timer\r
+#  services as well as EBC modules that require timer services.\r
+#\r
+#  Copyright (c) 2007 - 2010, 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                      = EmuDxeCodeTimerLib\r
+  FILE_GUID                      = FB184AF4-A2F2-EE4E-8885-E81E5D8B0135\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = TimerLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  DxeCoreTimerLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  EmuThunkLib\r
+  \r
diff --git a/InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.c b/InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.c
new file mode 100644 (file)
index 0000000..14bb17f
--- /dev/null
@@ -0,0 +1,206 @@
+/** @file\r
+  A non-functional instance of the Timer Library.\r
+\r
+  Copyright (c) 2007 - 2010, 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 <PiPei.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/EmuThunkLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#include <Protocol/Timer.h>\r
+\r
+\r
+STATIC UINT64                  gTimerPeriod = 0;\r
+STATIC EFI_TIMER_ARCH_PROTOCOL *gTimerAp = NULL;\r
+STATIC EFI_EVENT               gTimerEvent = NULL;\r
+STATIC VOID                    *gRegistration = NULL;\r
+\r
+VOID\r
+EFIAPI\r
+RegisterTimerArchProtocol (\r
+  IN EFI_EVENT     Event,\r
+  IN VOID          *Context\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  \r
+  Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **)&gTimerAp);\r
+  if (!EFI_ERROR (Status)) {    \r
+    Status = gTimerAp->GetTimerPeriod (gTimerAp, &gTimerPeriod);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    // Convert to Nanoseconds.\r
+    gTimerPeriod = MultU64x32 (gTimerPeriod, 100);\r
+    \r
+    if (gTimerEvent == NULL) {\r
+      Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, (VOID **)&gTimerEvent);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  }\r
+}\r
+\r
+\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of microseconds.\r
+\r
+  Stalls the CPU for the number of microseconds specified by MicroSeconds.\r
+\r
+  @param  MicroSeconds  The minimum number of microseconds to delay.\r
+\r
+  @return The value of MicroSeconds inputted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+MicroSecondDelay (\r
+  IN      UINTN                     MicroSeconds\r
+  )\r
+{\r
+  return NanoSecondDelay (MicroSeconds * 1000);\r
+}\r
+\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of nanoseconds.\r
+\r
+  Stalls the CPU for the number of nanoseconds specified by NanoSeconds.\r
+\r
+  @param  NanoSeconds The minimum number of nanoseconds to delay.\r
+\r
+  @return The value of NanoSeconds inputted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+NanoSecondDelay (\r
+  IN      UINTN                     NanoSeconds\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT64      HundredNanoseconds;\r
+  UINTN       Index;\r
+  \r
+  if ((gTimerPeriod != 0) && \r
+      ((UINT64)NanoSeconds > gTimerPeriod) && \r
+      (EfiGetCurrentTpl () == TPL_APPLICATION)) {\r
+    //\r
+    // This stall is long, so use gBS->WaitForEvent () to yield CPU to DXE Core\r
+    //\r
+    \r
+    HundredNanoseconds = DivU64x32 (NanoSeconds, 100);\r
+    Status = gBS->SetTimer (gTimerEvent, TimerRelative, HundredNanoseconds);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    Status = gBS->WaitForEvent (sizeof (gTimerEvent)/sizeof (EFI_EVENT), &gTimerEvent, &Index);\r
+    ASSERT_EFI_ERROR (Status);\r
+  \r
+  } else {\r
+    gEmuThunk->Sleep (NanoSeconds);\r
+  }\r
+  return NanoSeconds;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves the current value of a 64-bit free running performance counter.\r
+\r
+  The counter can either count up by 1 or count down by 1. If the physical\r
+  performance counter counts by a larger increment, then the counter values\r
+  must be translated. The properties of the counter can be retrieved from\r
+  GetPerformanceCounterProperties().\r
+\r
+  @return The current value of the free running performance counter.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounter (\r
+  VOID\r
+  )\r
+{\r
+  return gEmuThunk->QueryPerformanceCounter ();\r
+}\r
+\r
+/**\r
+  Retrieves the 64-bit frequency in Hz and the range of performance counter\r
+  values.\r
+\r
+  If StartValue is not NULL, then the value that the performance counter starts\r
+  with immediately after is it rolls over is returned in StartValue. If\r
+  EndValue is not NULL, then the value that the performance counter end with\r
+  immediately before it rolls over is returned in EndValue. The 64-bit\r
+  frequency of the performance counter in Hz is always returned. If StartValue\r
+  is less than EndValue, then the performance counter counts up. If StartValue\r
+  is greater than EndValue, then the performance counter counts down. For\r
+  example, a 64-bit free running counter that counts up would have a StartValue\r
+  of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter\r
+  that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.\r
+\r
+  @param  StartValue  The value the performance counter starts with when it\r
+                      rolls over.\r
+  @param  EndValue    The value that the performance counter ends with before\r
+                      it rolls over.\r
+\r
+  @return The frequency in Hz.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounterProperties (\r
+  OUT      UINT64                    *StartValue,  OPTIONAL\r
+  OUT      UINT64                    *EndValue     OPTIONAL\r
+  )\r
+{\r
+\r
+  if (StartValue != NULL) {\r
+    *StartValue = 0ULL;\r
+  }\r
+  if (EndValue != NULL) {\r
+    *EndValue = (UINT64)-1LL;\r
+  }\r
+  \r
+  return gEmuThunk->QueryPerformanceFrequency ();\r
+}\r
+\r
+\r
+/**\r
+  Register for the Timer AP protocol.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeTimerLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EfiCreateProtocolNotifyEvent (\r
+    &gEfiTimerArchProtocolGuid,\r
+    TPL_CALLBACK,\r
+    RegisterTimerArchProtocol,\r
+    NULL,\r
+    &gRegistration\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.inf b/InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.inf
new file mode 100644 (file)
index 0000000..ba1e3e2
--- /dev/null
@@ -0,0 +1,51 @@
+## @file\r
+#  NULL instance of Timer Library as a template.\r
+#\r
+#  A non-functional instance of the Timer Library that can be used as a template\r
+#  for the implementation of a functional timer library instance. This library instance can\r
+#  also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules that require timer\r
+#  services as well as EBC modules that require timer services.\r
+#\r
+#  Copyright (c) 2007 - 2010, 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                      = EmuDxeTimerLib\r
+  FILE_GUID                      = 74B62391-AD0D-1B4D-8784-151404F9D538\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = TimerLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION\r
+\r
+  CONSTRUCTOR                    = DxeTimerLibConstructor\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  DxeTimerLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  EmuThunkLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  \r
+[Protocols]\r
+  gEfiTimerArchProtocolGuid\r
diff --git a/InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.c b/InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.c
new file mode 100644 (file)
index 0000000..caf8a7c
--- /dev/null
@@ -0,0 +1,174 @@
+/** @file\r
+  A non-functional instance of the Timer Library.\r
+\r
+  Copyright (c) 2007 - 2010, 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 <PiPei.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+#include <Ppi/EmuThunk.h>\r
+#include <Protocol/EmuThunk.h>\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of microseconds.\r
+\r
+  Stalls the CPU for the number of microseconds specified by MicroSeconds.\r
+\r
+  @param  MicroSeconds  The minimum number of microseconds to delay.\r
+\r
+  @return The value of MicroSeconds inputted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+MicroSecondDelay (\r
+  IN      UINTN                     MicroSeconds\r
+  )\r
+{\r
+  return NanoSecondDelay (MicroSeconds * 1000);\r
+}\r
+\r
+/**\r
+  Stalls the CPU for at least the given number of nanoseconds.\r
+\r
+  Stalls the CPU for the number of nanoseconds specified by NanoSeconds.\r
+\r
+  @param  NanoSeconds The minimum number of nanoseconds to delay.\r
+\r
+  @return The value of NanoSeconds inputted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+NanoSecondDelay (\r
+  IN      UINTN                     NanoSeconds\r
+  )\r
+{\r
+  EMU_THUNK_PPI           *ThunkPpi;\r
+  EFI_STATUS              Status;\r
+  EMU_THUNK_PROTOCOL      *Thunk;\r
+\r
+  //\r
+  // Locate EmuThunkPpi for \r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+              &gEmuThunkPpiGuid,\r
+              0,\r
+              NULL,\r
+              (VOID **) &ThunkPpi\r
+             );\r
+  if (!EFI_ERROR (Status)) {   \r
+    Thunk  = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();\r
+    Thunk->Sleep (NanoSeconds * 100);\r
+    return NanoSeconds;\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+/**\r
+  Retrieves the current value of a 64-bit free running performance counter.\r
+\r
+  The counter can either count up by 1 or count down by 1. If the physical\r
+  performance counter counts by a larger increment, then the counter values\r
+  must be translated. The properties of the counter can be retrieved from\r
+  GetPerformanceCounterProperties().\r
+\r
+  @return The current value of the free running performance counter.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounter (\r
+  VOID\r
+  )\r
+{\r
+  EMU_THUNK_PPI           *ThunkPpi;\r
+  EFI_STATUS              Status;\r
+  EMU_THUNK_PROTOCOL      *Thunk;\r
+\r
+  //\r
+  // Locate EmuThunkPpi for \r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+              &gEmuThunkPpiGuid,\r
+              0,\r
+              NULL,\r
+              (VOID **) &ThunkPpi\r
+             );\r
+  if (!EFI_ERROR (Status)) {   \r
+    Thunk  = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();\r
+    return  Thunk->QueryPerformanceCounter ();\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+/**\r
+  Retrieves the 64-bit frequency in Hz and the range of performance counter\r
+  values.\r
+\r
+  If StartValue is not NULL, then the value that the performance counter starts\r
+  with immediately after is it rolls over is returned in StartValue. If\r
+  EndValue is not NULL, then the value that the performance counter end with\r
+  immediately before it rolls over is returned in EndValue. The 64-bit\r
+  frequency of the performance counter in Hz is always returned. If StartValue\r
+  is less than EndValue, then the performance counter counts up. If StartValue\r
+  is greater than EndValue, then the performance counter counts down. For\r
+  example, a 64-bit free running counter that counts up would have a StartValue\r
+  of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter\r
+  that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.\r
+\r
+  @param  StartValue  The value the performance counter starts with when it\r
+                      rolls over.\r
+  @param  EndValue    The value that the performance counter ends with before\r
+                      it rolls over.\r
+\r
+  @return The frequency in Hz.\r
+\r
+**/\r
+UINT64\r
+EFIAPI\r
+GetPerformanceCounterProperties (\r
+  OUT      UINT64                    *StartValue,  OPTIONAL\r
+  OUT      UINT64                    *EndValue     OPTIONAL\r
+  )\r
+{\r
+  EMU_THUNK_PPI           *ThunkPpi;\r
+  EFI_STATUS              Status;\r
+  EMU_THUNK_PROTOCOL      *Thunk;\r
+\r
+  //\r
+  // Locate EmuThunkPpi for \r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+              &gEmuThunkPpiGuid,\r
+              0,\r
+              NULL,\r
+              (VOID **) &ThunkPpi\r
+             );\r
+  if (!EFI_ERROR (Status)) {\r
+    if (StartValue != NULL) {\r
+      *StartValue = 0ULL;\r
+    }\r
+    if (EndValue != NULL) {\r
+      *EndValue = (UINT64)-1LL;\r
+    }\r
+    \r
+    Thunk  = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();\r
+    return  Thunk->QueryPerformanceFrequency ();\r
+  }\r
+\r
+  return 0;\r
+}\r
diff --git a/InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.inf b/InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.inf
new file mode 100644 (file)
index 0000000..c9f4858
--- /dev/null
@@ -0,0 +1,47 @@
+## @file\r
+#  NULL instance of Timer Library as a template.\r
+#\r
+#  A non-functional instance of the Timer Library that can be used as a template\r
+#  for the implementation of a functional timer library instance. This library instance can\r
+#  also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules that require timer\r
+#  services as well as EBC modules that require timer services.\r
+#\r
+#  Copyright (c) 2007 - 2010, 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                      = EmuPeiTimerLib\r
+  FILE_GUID                      = 6ABE5FDC-AE4B-474E-8E52-9546C96AE536\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = TimerLib|PEIM PEI_CORE SEC\r
+\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources]\r
+  PeiTimerLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  InOsEmuPkg/InOsEmuPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  PeiServicesLib\r
+\r
+[Ppis]\r
+  gEmuThunkPpiGuid
\ No newline at end of file
diff --git a/InOsEmuPkg/MetronomeDxe/Metronome.c b/InOsEmuPkg/MetronomeDxe/Metronome.c
deleted file mode 100644 (file)
index 34f9469..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*++ @file\r
-  Emu Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
-\r
-Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
-Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.\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
-\r
-#include "Metronome.h"\r
-\r
-\r
-//\r
-// Global Variables\r
-//\r
-EFI_METRONOME_ARCH_PROTOCOL mMetronome = {\r
-  EmuMetronomeDriverWaitForTick,\r
-  TICK_PERIOD\r
-};\r
-\r
-//\r
-// Worker Functions\r
-//\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-EmuMetronomeDriverWaitForTick (\r
-  IN EFI_METRONOME_ARCH_PROTOCOL  *This,\r
-  IN UINT32                       TickNumber\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  The WaitForTick() function waits for the number of ticks specified by\r
-  TickNumber from a known time source in the platform.  If TickNumber of\r
-  ticks are detected, then EFI_SUCCESS is returned.  The actual time passed\r
-  between entry of this function and the first tick is between 0 and\r
-  TickPeriod 100 nS units.  If you want to guarantee that at least TickPeriod\r
-  time has elapsed, wait for two ticks.  This function waits for a hardware\r
-  event to determine when a tick occurs.  It is possible for interrupt\r
-  processing, or exception processing to interrupt the execution of the\r
-  WaitForTick() function.  Depending on the hardware source for the ticks, it\r
-  is possible for a tick to be missed.  This function cannot guarantee that\r
-  ticks will not be missed.  If a timeout occurs waiting for the specified\r
-  number of ticks, then EFI_TIMEOUT is returned.\r
-\r
-Arguments:\r
-\r
-  This       - The EFI_METRONOME_ARCH_PROTOCOL instance.\r
-  TickNumber - Number of ticks to wait.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - The wait for the number of ticks specified by TickNumber\r
-                succeeded.\r
-\r
-**/\r
-{\r
-  UINT64  SleepTime;\r
-\r
-  //\r
-  // Calculate the time to sleep.  Emu smallest unit to sleep is 1 millisec\r
-  // Tick Period is in 100ns units, divide by 10000 to convert to ms\r
-  //\r
-  SleepTime = DivU64x32 (MultU64x32 ((UINT64) TickNumber, TICK_PERIOD) + 9999, 10000);\r
-  gEmuThunk->Sleep (SleepTime);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-EmuMetronomeDriverInitialize (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Initialize the Metronome Architectural Protocol driver\r
-\r
-Arguments:\r
-\r
-  ImageHandle - ImageHandle of the loaded driver\r
-\r
-\r
-  SystemTable - Pointer to the System Table\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS           - Metronome Architectural Protocol created\r
-\r
-  EFI_OUT_OF_RESOURCES  - Not enough resources available to initialize driver.\r
-\r
-  EFI_DEVICE_ERROR      - A device error occured attempting to initialize the driver.\r
-\r
-**/\r
-{\r
-  EFI_STATUS  Status;\r
-  EFI_HANDLE  Handle;\r
-\r
-\r
-  //\r
-  // Install the Metronome Architectural Protocol onto a new handle\r
-  //\r
-  Handle = NULL;\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &Handle,\r
-                  &gEfiMetronomeArchProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &mMetronome\r
-                  );\r
-\r
-  return Status;\r
-}\r
diff --git a/InOsEmuPkg/MetronomeDxe/Metronome.h b/InOsEmuPkg/MetronomeDxe/Metronome.h
deleted file mode 100644 (file)
index 5115e0b..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*++ @file\r
-  Emu Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
-\r
-Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
-Portions copyright (c) 2010 - 2011, Apple Inc. All rights reserved.\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
-#ifndef _EMU_THUNK_METRONOME_H_\r
-#define _EMU_THUNK_METRONOME_H_\r
-\r
-#include <PiDxe.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/EmuThunkLib.h>\r
-\r
-#include <Protocol/Metronome.h>\r
-\r
-\r
-\r
-//\r
-// Period of on tick in 100 nanosecond units\r
-//\r
-#define TICK_PERIOD 2000\r
-\r
-//\r
-// Function Prototypes\r
-//\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-EmuMetronomeDriverInitialize (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-EmuMetronomeDriverWaitForTick (\r
-  IN EFI_METRONOME_ARCH_PROTOCOL  *This,\r
-  IN UINT32                       TickNumber\r
-  );\r
-\r
-#endif\r
diff --git a/InOsEmuPkg/MetronomeDxe/Metronome.inf b/InOsEmuPkg/MetronomeDxe/Metronome.inf
deleted file mode 100644 (file)
index 4befdf3..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-## @file\r
-# Emu Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
-#\r
-# This metronome module simulates metronome by Sleep WinAPI.\r
-# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
-# Portions copyright (c) 2011, Apple Inc. All rights reserved. \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                      = Metronome\r
-  FILE_GUID                      = f348f6fe-8985-11db-b4c3-0040d02b1835\r
-  MODULE_TYPE                    = DXE_DRIVER\r
-  VERSION_STRING                 = 1.0\r
-\r
-  ENTRY_POINT                    = EmuMetronomeDriverInitialize\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
-[Sources]\r
-  Metronome.h\r
-  Metronome.c\r
-\r
-\r
-[Packages]\r
-  MdePkg/MdePkg.dec\r
-  InOsEmuPkg/InOsEmuPkg.dec\r
-  \r
-\r
-[LibraryClasses]\r
-  UefiBootServicesTableLib\r
-  MemoryAllocationLib\r
-  EmuThunkLib\r
-  UefiDriverEntryPoint\r
-  UefiLib\r
-  DebugLib\r
-  BaseLib\r
-\r
-\r
-[Protocols]\r
-  gEfiMetronomeArchProtocolGuid                 # PROTOCOL ALWAYS_PRODUCED\r
-\r
-\r
-[Depex]\r
-  TRUE\r
-\r
index 143591395aac6309da9fe52322b6f08a88da4955..d19ced7dd9ac6a3e6e5cdfa30541c8f05cadbfe8 100644 (file)
@@ -325,6 +325,14 @@ Returns:
   Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (void *)&mCpu);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Start the timer thread at the default timer period\r
+  //\r
+  Status = mTimer.SetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATION);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Install the Timer Architectural Protocol onto a new handle\r
   //\r
@@ -339,13 +347,6 @@ Returns:
     return Status;\r
   }\r
 \r
-  //\r
-  // Start the timer thread at the default timer period\r
-  //\r
-  Status = mTimer.SetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATION);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
index ca8be55a0fd8ba4f1d377670bd501c51343f88e9..194cf137f93fe8531d9ee2b21190e403952d6eaa 100644 (file)
@@ -250,15 +250,15 @@ QueryPerformanceCounter (
 
 VOID
 SecSleep (
-  IN  UINT64 Milliseconds
+  IN  UINT64 Nanoseconds
   )
 {
   struct timespec rq, rm;
   struct timeval  start, end;
   unsigned long  MicroSec;
   
-  rq.tv_sec = Milliseconds / 1000;
-  rq.tv_nsec = (Milliseconds % 1000) * 1000000;
+  rq.tv_sec  = Nanoseconds / 1000000000;
+  rq.tv_nsec = Nanoseconds % 1000000000;
 
   //
   // nanosleep gets interrupted by our timer tic. 
index e5966964c5312fc5c8e32d8dac064c15d6a02aef..725e250eb3af349ab7f2806dfa18da416856ebe1 100644 (file)
@@ -109,7 +109,7 @@ GasketQueryPerformanceCounter (
 VOID\r
 EFIAPI\r
 GasketSecSleep (\r
-  IN  UINT64 Milliseconds\r
+  IN  UINT64 Nanoseconds\r
   );\r
   \r
 VOID\r
index 01254de0c7565e39333d0487e9c4c93b46c6c7e0..68cb007ed838601a7d3083e383d9f492c6415609 100644 (file)
@@ -336,7 +336,7 @@ MapFd0 (
 \r
  \r
 \r
-VOID SecSleep (UINT64 Milliseconds);\r
+VOID SecSleep (UINT64 Nanoseconds);\r
 VOID SecEnableInterrupt (VOID);\r
 VOID SecDisableInterrupt (VOID);\r
 BOOLEAN SecInterruptEanbled (VOID);\r
index 4012acfdebdd951c4d8fdce460bdf3e6d074609b..d6ce60ee3047f8d94ff2066840721f88258058ff 100644 (file)
   SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf\r
   PpiListLib|InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf\r
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
+  TimerLib|InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.inf\r
 \r
 [LibraryClasses.common.USER_DEFINED, LibraryClasses.common.BASE]\r
   DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
   ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf\r
   SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf\r
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
+  TimerLib|InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.inf\r
 \r
 [LibraryClasses.common.PEI_CORE]\r
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
   PeCoffExtraActionLib|InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf\r
   ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf\r
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  TimerLib|InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.inf\r
+  EmuThunkLib|InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.UEFI_APPLICATION]\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   EmuThunkLib|InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.inf\r
   PeCoffExtraActionLib|InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf\r
   ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
+  TimerLib|InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.inf\r
 \r
 [LibraryClasses.common.UEFI_DRIVER]\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
       SerialPortLib|InOsEmuPkg/Library/DxeEmuStdErrSerialPortLib/DxeEmuStdErrSerialPortLib.inf    \r
   }\r
 \r
-  InOsEmuPkg/MetronomeDxe/Metronome.inf\r
+  MdeModulePkg/Universal/Metronome/Metronome.inf\r
   InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf\r
   InOsEmuPkg/ResetRuntimeDxe/Reset.inf\r
   MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
index 1f2fe7e633dbcaa0bcdf3ccadc58fc313e72415d..b6d80a22ea07d28d6c1e0b17cb09c31e39206f6a 100644 (file)
@@ -165,7 +165,7 @@ APRIORI PEI {
   }\r
 APRIORI DXE {\r
   INF  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf\r
-  INF  InOsEmuPkg/MetronomeDxe/Metronome.inf\r
+  INF  MdeModulePkg/Universal/Metronome/Metronome.inf\r
   }\r
 INF  InOsEmuPkg/Sec/Sec.inf\r
 INF  MdeModulePkg/Core/Pei/PeiMain.inf\r
@@ -187,7 +187,7 @@ INF  MdeModulePkg/Core/Dxe/DxeMain.inf
 INF  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf  \r
 INF  MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf\r
 INF  MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf\r
-INF  InOsEmuPkg/MetronomeDxe/Metronome.inf\r
+INF  MdeModulePkg/Universal/Metronome/Metronome.inf\r
 INF  InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf\r
 INF  InOsEmuPkg/ResetRuntimeDxe/Reset.inf\r
 INF  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r