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.
26 #include "CommonHeader.h"
27 #include "PlatformBaseAddresses.h"
31 Waits for at least the given number of microseconds.
33 @param PeiServices General purpose services available to every PEIM.
34 @param This PPI instance structure.
35 @param Microseconds Desired length of time to wait.
37 @retval EFI_SUCCESS If the desired amount of time was passed.
43 IN CONST EFI_PEI_SERVICES
**PeiServices
,
44 IN CONST EFI_PEI_STALL_PPI
*This
,
54 if (Microseconds
== 0) {
58 OriginalTick
= IoRead32 (ACPI_BASE_ADDRESS
+ R_PCH_ACPI_PM1_TMR
);
59 OriginalTick
&= (V_PCH_ACPI_PM1_TMR_MAX_VAL
- 1);
60 CurrentTick
= OriginalTick
;
63 // The timer frequency is 3.579545MHz, so 1 ms corresponds to 3.58 clocks
65 Ticks
= Microseconds
* 358 / 100 + OriginalTick
+ 1;
68 // The loops needed for timer overflow
70 Counts
= (UINTN
)RShiftU64((UINT64
)Ticks
, 24);
73 // Remaining clocks within one loop
75 RemainingTick
= Ticks
& 0xFFFFFF;
78 // Do not intend to use TMROF_STS bit of register PM1_STS, because this add extra
79 // one I/O operation, and may generate SMI
82 CurrentTick
= IoRead32 (ACPI_BASE_ADDRESS
+ R_PCH_ACPI_PM1_TMR
) & B_PCH_ACPI_PM1_TMR_VAL
;
83 if (CurrentTick
<= OriginalTick
) {
86 OriginalTick
= CurrentTick
;
89 while ((RemainingTick
> CurrentTick
) && (OriginalTick
<= CurrentTick
)) {
90 OriginalTick
= CurrentTick
;
91 CurrentTick
= IoRead32 (ACPI_BASE_ADDRESS
+ R_PCH_ACPI_PM1_TMR
) & B_PCH_ACPI_PM1_TMR_VAL
;