]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/MonotonicCounterRuntimeDxe/Metronome.c
add in Metronome.inf
[mirror_edk2.git] / Nt32Pkg / MonotonicCounterRuntimeDxe / Metronome.c
diff --git a/Nt32Pkg/MonotonicCounterRuntimeDxe/Metronome.c b/Nt32Pkg/MonotonicCounterRuntimeDxe/Metronome.c
new file mode 100644 (file)
index 0000000..b02741b
--- /dev/null
@@ -0,0 +1,134 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  Metronome.c\r
+\r
+Abstract:\r
+\r
+  NT Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Metronome.h"\r
+\r
+//\r
+// Global Variables\r
+//\r
+EFI_METRONOME_ARCH_PROTOCOL mMetronome = {\r
+  WinNtMetronomeDriverWaitForTick,\r
+  TICK_PERIOD\r
+};\r
+\r
+//\r
+// Worker Functions\r
+//\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtMetronomeDriverWaitForTick (\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.  Win API 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
+  gWinNt->Sleep ((UINT32) SleepTime);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtMetronomeDriverInitialize (\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