+/**@file\r
+ EFI_PEI_STALL implementation for NT32 simulation environment.\r
+ \r
+Copyright (c) 2009, 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
+**/\r
+#include "WinNtPeim.h"\r
+\r
+#include <Ppi/NtThunk.h>\r
+#include <Ppi/Stall.h>\r
+#include <Library/DebugLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI \r
+Stall (\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN CONST EFI_PEI_STALL_PPI *This,\r
+ IN UINTN Microseconds\r
+ );\r
+ \r
+EFI_PEI_STALL_PPI mStallPpi = {1000, Stall};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR mPpiListStall[1] = {\r
+ {\r
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+ &gEfiPeiStallPpiGuid,\r
+ &mStallPpi\r
+ }\r
+};\r
+\r
+\r
+/**\r
+ PEIM's entry point.\r
+ \r
+ This routine installs the simulation instance of EFI_PEI_STALL_PPI based\r
+ on Win API Sleep().\r
+ \r
+ @param FileHandle Handle of the file being invoked. \r
+ @param PeiServices Describes the list of possible PEI Services.\r
+\r
+ @retval EFI_SUCCESS The PEIM executed normally.\r
+ @retval !EFI_SUCCESS The PEIM failed to execute normally.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeStall (\r
+ IN EFI_PEI_FILE_HANDLE FileHandle,\r
+ IN CONST EFI_PEI_SERVICES **PeiServices\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ Status = (*PeiServices)->InstallPpi (PeiServices, &mPpiListStall[0]);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ The Stall() function provides a blocking stall for at least the number \r
+ of microseconds stipulated in the final argument of the API.\r
+\r
+ @param PeiServices An indirect pointer to the PEI Services Table\r
+ published by the PEI Foundation.\r
+ @param This Pointer to the local data for the interface.\r
+ @param Microseconds Number of microseconds for which to stall.\r
+\r
+ @retval EFI_SUCCESS The service provided at least the required delay.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI \r
+Stall (\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN CONST EFI_PEI_STALL_PPI *This,\r
+ IN UINTN Microseconds\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ PEI_NT_THUNK_PPI *PeiNtService;\r
+ EFI_WIN_NT_THUNK_PROTOCOL *NtThunk;\r
+ \r
+ Status = (**PeiServices).LocatePpi (\r
+ (const EFI_PEI_SERVICES **)PeiServices,\r
+ &gPeiNtThunkPpiGuid,\r
+ 0, \r
+ NULL,\r
+ (VOID**)&PeiNtService\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ \r
+ //\r
+ // Calculate the time to sleep. Win API smallest unit to sleep is 1 millisec\r
+ // so micro second units need be divided by 1000 to convert to ms\r
+ //\r
+ NtThunk = (EFI_WIN_NT_THUNK_PROTOCOL*) PeiNtService->NtThunk();\r
+ NtThunk->Sleep ((Microseconds + 999) / 1000); \r
+ \r
+ return EFI_SUCCESS;\r
+}\r
+
\ No newline at end of file