]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformInitPei/Stall.c
Upload BSD-licensed Vlv2TbltDevicePkg and Vlv2DeviceRefCodePkg to
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformInitPei / Stall.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4
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.
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 Module Name:
17
18 Stall.c
19
20 Abstract:
21
22 Produce Stall Ppi.
23
24 --*/
25
26
27 #include "PlatformEarlyInit.h"
28
29
30 /**
31
32 Waits for at least the given number of microseconds.
33
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.
37
38 @retval EFI_SUCCESS If the desired amount of time was passed.
39
40 */
41 EFI_STATUS
42 EFIAPI
43 Stall (
44 IN CONST EFI_PEI_SERVICES **PeiServices,
45 IN CONST EFI_PEI_STALL_PPI *This,
46 IN UINTN Microseconds
47 )
48 {
49 UINTN Ticks;
50 UINTN Counts;
51 UINT32 CurrentTick;
52 UINT32 OriginalTick;
53 UINT32 RemainingTick;
54
55 if (Microseconds == 0) {
56 return EFI_SUCCESS;
57 }
58
59 OriginalTick = IoRead32 (ACPI_BASE_ADDRESS + R_PCH_ACPI_PM1_TMR);
60 OriginalTick &= (V_PCH_ACPI_PM1_TMR_MAX_VAL - 1);
61 CurrentTick = OriginalTick;
62
63 //
64 // The timer frequency is 3.579545MHz, so 1 ms corresponds to 3.58 clocks
65 //
66 Ticks = Microseconds * 358 / 100 + OriginalTick + 1;
67
68 //
69 // The loops needed for timer overflow
70 //
71 Counts = (UINTN)RShiftU64((UINT64)Ticks, 24);
72
73 //
74 // Remaining clocks within one loop
75 //
76 RemainingTick = Ticks & 0xFFFFFF;
77
78 //
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
81 //
82 while (Counts != 0) {
83 CurrentTick = IoRead32 (ACPI_BASE_ADDRESS + R_PCH_ACPI_PM1_TMR) & B_PCH_ACPI_PM1_TMR_VAL;
84 if (CurrentTick <= OriginalTick) {
85 Counts--;
86 }
87 OriginalTick = CurrentTick;
88 }
89
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;
93 }
94
95 return EFI_SUCCESS;
96 }