]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Misc/Stall.c
Clean up DxeCore to remove duplicate memory allocation & device path utility services...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / Stall.c
CommitLineData
23c98c94 1/** @file\r
504214c4 2 UEFI Miscellaneous boot Services Stall service implementation\r
28a00297 3\r
23c98c94 4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
28a00297 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
504214c4 13**/\r
28a00297 14\r
15//\r
16// Include statements\r
17//\r
18\r
9c4ac31c 19#include "DxeMain.h"\r
28a00297 20\r
21\r
28a00297 22\r
162ed594 23/**\r
28a00297 24 Introduces a fine-grained stall.\r
25\r
162ed594 26 @param Microseconds The number of microseconds to stall execution.\r
28a00297 27\r
022c6d45 28 @retval EFI_SUCCESS Execution was stalled for at least the requested\r
29 amount of microseconds.\r
162ed594 30 @retval EFI_NOT_AVAILABLE_YET gMetronome is not available yet\r
28a00297 31\r
162ed594 32**/\r
33EFI_STATUS\r
34EFIAPI\r
35CoreStall (\r
36 IN UINTN Microseconds\r
37 )\r
28a00297 38{\r
39 UINT32 Counter;\r
40 UINT32 Remainder;\r
41\r
42 if (gMetronome == NULL) {\r
43 return EFI_NOT_AVAILABLE_YET;\r
44 }\r
45\r
46 //\r
47 // Calculate the number of ticks by dividing the number of microseconds by\r
48 // the TickPeriod.\r
49 // Calcullation is based on 100ns unit.\r
50 //\r
51 Counter = (UINT32) DivU64x32Remainder (\r
52 Microseconds * 10,\r
53 gMetronome->TickPeriod,\r
54 &Remainder\r
55 );\r
56\r
57 //\r
58 // Call WaitForTick for Counter + 1 ticks to try to guarantee Counter tick\r
59 // periods, thus attempting to ensure Microseconds of stall time.\r
60 //\r
61 if (Remainder != 0) {\r
62 Counter++;\r
63 }\r
64\r
65 gMetronome->WaitForTick (gMetronome, Counter);\r
66\r
67 return EFI_SUCCESS;\r
68}\r