3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
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.
27 #include "PlatformEarlyInit.h"
32 Waits for at least the given number of microseconds.
34 @param PeiServices General purpose services available to every PEIM.
35 @param This PPI instance structure.
36 @param Microseconds Desired length of time to wait.
38 @retval EFI_SUCCESS If the desired amount of time was passed.
44 IN CONST EFI_PEI_SERVICES
**PeiServices
,
45 IN CONST EFI_PEI_STALL_PPI
*This
,
55 if (Microseconds
== 0) {
59 OriginalTick
= IoRead32 (ACPI_BASE_ADDRESS
+ R_PCH_ACPI_PM1_TMR
);
60 OriginalTick
&= (V_PCH_ACPI_PM1_TMR_MAX_VAL
- 1);
61 CurrentTick
= OriginalTick
;
64 // The timer frequency is 3.579545MHz, so 1 ms corresponds to 3.58 clocks
66 Ticks
= Microseconds
* 358 / 100 + OriginalTick
+ 1;
69 // The loops needed for timer overflow
71 Counts
= (UINTN
)RShiftU64((UINT64
)Ticks
, 24);
74 // Remaining clocks within one loop
76 RemainingTick
= Ticks
& 0xFFFFFF;
79 // Do not intend to use TMROF_STS bit of register PM1_STS, because this add extra
80 // one I/O operation, and may generate SMI
83 CurrentTick
= IoRead32 (ACPI_BASE_ADDRESS
+ R_PCH_ACPI_PM1_TMR
) & B_PCH_ACPI_PM1_TMR_VAL
;
84 if (CurrentTick
<= OriginalTick
) {
87 OriginalTick
= CurrentTick
;
90 while ((RemainingTick
> CurrentTick
) && (OriginalTick
<= CurrentTick
)) {
91 OriginalTick
= CurrentTick
;
92 CurrentTick
= IoRead32 (ACPI_BASE_ADDRESS
+ R_PCH_ACPI_PM1_TMR
) & B_PCH_ACPI_PM1_TMR_VAL
;