]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / PcAtChipsetPkg / Library / AcpiTimerLib / DxeStandaloneMmAcpiTimerLib.c
CommitLineData
79a951d1
KQ
1/** @file\r
2 ACPI Timer implements one instance of Timer Library.\r
3\r
4 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include <PiDxe.h>\r
10#include <Library/TimerLib.h>\r
11#include <Library/BaseLib.h>\r
12#include <Library/HobLib.h>\r
13\r
5220bd21 14extern GUID mFrequencyHobGuid;\r
79a951d1
KQ
15\r
16/**\r
17 The constructor function enables ACPI IO space.\r
18\r
19 If ACPI I/O space not enabled, this function will enable it.\r
20 It will always return RETURN_SUCCESS.\r
21\r
22 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
23\r
24**/\r
25RETURN_STATUS\r
26EFIAPI\r
27AcpiTimerLibConstructor (\r
28 VOID\r
29 );\r
30\r
31/**\r
32 Calculate TSC frequency.\r
33\r
34 The TSC counting frequency is determined by comparing how far it counts\r
35 during a 101.4 us period as determined by the ACPI timer.\r
36 The ACPI timer is used because it counts at a known frequency.\r
37 The TSC is sampled, followed by waiting 363 counts of the ACPI timer,\r
38 or 101.4 us. The TSC is then sampled again. The difference multiplied by\r
39 9861 is the TSC frequency. There will be a small error because of the\r
40 overhead of reading the ACPI timer. An attempt is made to determine and\r
41 compensate for this error.\r
42\r
43 @return The number of TSC counts per second.\r
44\r
45**/\r
46UINT64\r
47InternalCalculateTscFrequency (\r
48 VOID\r
49 );\r
50\r
51//\r
52// Cached performance counter frequency\r
53//\r
54UINT64 mPerformanceCounterFrequency = 0;\r
55\r
56/**\r
57 Internal function to retrieves the 64-bit frequency in Hz.\r
58\r
59 Internal function to retrieves the 64-bit frequency in Hz.\r
60\r
61 @return The frequency in Hz.\r
62\r
63**/\r
64UINT64\r
65InternalGetPerformanceCounterFrequency (\r
66 VOID\r
67 )\r
68{\r
5220bd21 69 return mPerformanceCounterFrequency;\r
79a951d1
KQ
70}\r
71\r
72/**\r
73 The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.\r
74\r
75 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
76\r
77**/\r
78EFI_STATUS\r
79CommonAcpiTimerLibConstructor (\r
80 VOID\r
81 )\r
82{\r
5220bd21 83 EFI_HOB_GUID_TYPE *GuidHob;\r
79a951d1
KQ
84\r
85 //\r
86 // Enable ACPI IO space.\r
87 //\r
88 AcpiTimerLibConstructor ();\r
89\r
90 //\r
91 // Initialize PerformanceCounterFrequency\r
92 //\r
93 GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);\r
94 if (GuidHob != NULL) {\r
5220bd21 95 mPerformanceCounterFrequency = *(UINT64 *)GET_GUID_HOB_DATA (GuidHob);\r
79a951d1
KQ
96 } else {\r
97 mPerformanceCounterFrequency = InternalCalculateTscFrequency ();\r
98 }\r
99\r
100 return EFI_SUCCESS;\r
101}\r