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