3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
22 #include "PlatformEarlyInit.h"
27 Waits for at least the given number of microseconds.
29 @param PeiServices General purpose services available to every PEIM.
30 @param This PPI instance structure.
31 @param Microseconds Desired length of time to wait.
33 @retval EFI_SUCCESS If the desired amount of time was passed.
39 IN CONST EFI_PEI_SERVICES
**PeiServices
,
40 IN CONST EFI_PEI_STALL_PPI
*This
,
50 if (Microseconds
== 0) {
54 OriginalTick
= IoRead32 (ACPI_BASE_ADDRESS
+ R_PCH_ACPI_PM1_TMR
);
55 OriginalTick
&= (V_PCH_ACPI_PM1_TMR_MAX_VAL
- 1);
56 CurrentTick
= OriginalTick
;
59 // The timer frequency is 3.579545MHz, so 1 ms corresponds to 3.58 clocks
61 Ticks
= Microseconds
* 358 / 100 + OriginalTick
+ 1;
64 // The loops needed for timer overflow
66 Counts
= (UINTN
)RShiftU64((UINT64
)Ticks
, 24);
69 // Remaining clocks within one loop
71 RemainingTick
= Ticks
& 0xFFFFFF;
74 // Do not intend to use TMROF_STS bit of register PM1_STS, because this add extra
75 // one I/O operation, and may generate SMI
78 CurrentTick
= IoRead32 (ACPI_BASE_ADDRESS
+ R_PCH_ACPI_PM1_TMR
) & B_PCH_ACPI_PM1_TMR_VAL
;
79 if (CurrentTick
<= OriginalTick
) {
82 OriginalTick
= CurrentTick
;
85 while ((RemainingTick
> CurrentTick
) && (OriginalTick
<= CurrentTick
)) {
86 OriginalTick
= CurrentTick
;
87 CurrentTick
= IoRead32 (ACPI_BASE_ADDRESS
+ R_PCH_ACPI_PM1_TMR
) & B_PCH_ACPI_PM1_TMR_VAL
;