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