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