]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/StallPei/Stall.c
Nt32Pkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Nt32Pkg / StallPei / Stall.c
CommitLineData
ba82cb67 1/**@file\r
2 EFI_PEI_STALL implementation for NT32 simulation environment.\r
3 \r
f66a43b2 4Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
9d2eedba 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
ba82cb67 6\r
7**/\r
8#include "WinNtPeim.h"\r
9\r
10#include <Ppi/NtThunk.h>\r
11#include <Ppi/Stall.h>\r
12#include <Library/DebugLib.h>\r
13\r
14EFI_STATUS\r
15EFIAPI \r
16Stall (\r
17 IN CONST EFI_PEI_SERVICES **PeiServices,\r
18 IN CONST EFI_PEI_STALL_PPI *This,\r
19 IN UINTN Microseconds\r
20 );\r
21 \r
22EFI_PEI_STALL_PPI mStallPpi = {1000, Stall};\r
23\r
24EFI_PEI_PPI_DESCRIPTOR mPpiListStall[1] = {\r
25 {\r
26 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
27 &gEfiPeiStallPpiGuid,\r
28 &mStallPpi\r
29 }\r
30};\r
31\r
32\r
33/**\r
34 PEIM's entry point.\r
35 \r
36 This routine installs the simulation instance of EFI_PEI_STALL_PPI based\r
37 on Win API Sleep().\r
38 \r
39 @param FileHandle Handle of the file being invoked. \r
40 @param PeiServices Describes the list of possible PEI Services.\r
41\r
42 @retval EFI_SUCCESS The PEIM executed normally.\r
43 @retval !EFI_SUCCESS The PEIM failed to execute normally.\r
44**/\r
45EFI_STATUS\r
46EFIAPI\r
47InitializeStall (\r
48 IN EFI_PEI_FILE_HANDLE FileHandle,\r
49 IN CONST EFI_PEI_SERVICES **PeiServices\r
50 )\r
51{\r
52 EFI_STATUS Status;\r
53 Status = (*PeiServices)->InstallPpi (PeiServices, &mPpiListStall[0]);\r
54 ASSERT_EFI_ERROR (Status);\r
55\r
56 return Status;\r
57}\r
58\r
59/**\r
60 The Stall() function provides a blocking stall for at least the number \r
61 of microseconds stipulated in the final argument of the API.\r
62\r
63 @param PeiServices An indirect pointer to the PEI Services Table\r
64 published by the PEI Foundation.\r
65 @param This Pointer to the local data for the interface.\r
66 @param Microseconds Number of microseconds for which to stall.\r
67\r
68 @retval EFI_SUCCESS The service provided at least the required delay.\r
69\r
70**/\r
71EFI_STATUS\r
72EFIAPI \r
73Stall (\r
74 IN CONST EFI_PEI_SERVICES **PeiServices,\r
75 IN CONST EFI_PEI_STALL_PPI *This,\r
76 IN UINTN Microseconds\r
77 )\r
78{\r
79 EFI_STATUS Status;\r
80 PEI_NT_THUNK_PPI *PeiNtService;\r
81 EFI_WIN_NT_THUNK_PROTOCOL *NtThunk;\r
82 \r
83 Status = (**PeiServices).LocatePpi (\r
84 (const EFI_PEI_SERVICES **)PeiServices,\r
85 &gPeiNtThunkPpiGuid,\r
86 0, \r
87 NULL,\r
88 (VOID**)&PeiNtService\r
89 );\r
90 ASSERT_EFI_ERROR (Status);\r
91 \r
92 //\r
93 // Calculate the time to sleep. Win API smallest unit to sleep is 1 millisec\r
94 // so micro second units need be divided by 1000 to convert to ms\r
95 //\r
96 NtThunk = (EFI_WIN_NT_THUNK_PROTOCOL*) PeiNtService->NtThunk();\r
f66a43b2 97 NtThunk->Sleep ((DWORD)((Microseconds + 999) / 1000)); \r
ba82cb67 98 \r
99 return EFI_SUCCESS;\r
100}\r