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