]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/Library/StallSmmLib/StallSmm.c
Vlv2TbltDevicePkg:Signal EndOfDxe Event.
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / StallSmmLib / StallSmm.c
1 /*++
2
3 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved
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 SmmIo.c
18
19 Abstract:
20
21 SMM I/O access utility implementation file, for Ia32
22
23 --*/
24
25 //
26 // Include files
27 //
28 #include "Library/StallSmmLib.h"
29 #include "Pi/PiSmmCis.h"
30 #include "PiDxe.h"
31 #include <Library/IoLib.h>
32 #include <Library/PcdLib.h>
33 #include "PchAccess.h"
34
35 /**
36 Delay for at least the request number of microseconds.
37 Timer used is ACPI time counter, which has 1us granularity.
38
39 @param Microseconds Number of microseconds to delay.
40
41 @retval None
42
43 **/
44 VOID
45 SmmStall (
46 IN UINTN Microseconds
47 )
48 {
49 UINTN Ticks;
50 UINTN Counts;
51 UINTN CurrentTick;
52 UINTN OriginalTick;
53 UINTN RemainingTick;
54 UINT16 AcpiBaseAddr;
55
56 if (Microseconds == 0) {
57 return;
58 }
59
60 AcpiBaseAddr = PchLpcPciCfg16 (R_PCH_LPC_ACPI_BASE) & B_PCH_LPC_ACPI_BASE_BAR;
61
62 OriginalTick = IoRead32 (AcpiBaseAddr + R_PCH_ACPI_PM1_TMR);
63 CurrentTick = OriginalTick;
64
65 //
66 // The timer frequency is 3.579545 MHz, so 1 ms corresponds 3.58 clocks
67 //
68 Ticks = Microseconds * 358 / 100 + OriginalTick + 1;
69
70 //
71 // The loops needed by timer overflow
72 //
73 Counts = Ticks / V_PCH_ACPI_PM1_TMR_MAX_VAL;
74
75 //
76 // Remaining clocks within one loop
77 //
78 RemainingTick = Ticks % V_PCH_ACPI_PM1_TMR_MAX_VAL;
79
80 //
81 // not intend to use TMROF_STS bit of register PM1_STS, because this adds extra
82 // one I/O operation, and maybe generate SMI
83 //
84 while ((Counts != 0) || (RemainingTick > CurrentTick)) {
85 CurrentTick = IoRead32 (AcpiBaseAddr + R_PCH_ACPI_PM1_TMR);
86 //
87 // Check if timer overflow
88 //
89 if (CurrentTick < OriginalTick) {
90 Counts--;
91 }
92 OriginalTick = CurrentTick;
93 }
94 }