]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm
[mirror_edk2.git] / PcAtChipsetPkg / Library / AcpiTimerLib / DxeAcpiTimerLib.c
CommitLineData
83d1ffb9
LG
1/** @file\r
2 ACPI Timer implements one instance of Timer Library.\r
3\r
5a702acd 4 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
e1d302e5 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
83d1ffb9
LG
6\r
7**/\r
8\r
fd501a79 9#include <PiDxe.h>\r
83d1ffb9
LG
10#include <Library/TimerLib.h>\r
11#include <Library/BaseLib.h>\r
fd501a79
LG
12#include <Library/HobLib.h>\r
13\r
14extern GUID mFrequencyHobGuid;\r
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
83d1ffb9 30\r
62b8b5be
SZ
31/**\r
32 Calculate TSC frequency.\r
33\r
34 The TSC counting frequency is determined by comparing how far it counts\r
a012df5e
SZ
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
62b8b5be
SZ
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
83d1ffb9
LG
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
5a702acd 67 )\r
83d1ffb9 68{\r
fd501a79
LG
69 return mPerformanceCounterFrequency;\r
70}\r
71\r
72/**\r
5a702acd 73 The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.\r
fd501a79
LG
74\r
75 @param ImageHandle The firmware allocated handle for the EFI image.\r
76 @param SystemTable A pointer to the EFI System Table.\r
77\r
78 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
79\r
80**/\r
81EFI_STATUS\r
82EFIAPI\r
83DxeAcpiTimerLibConstructor (\r
84 IN EFI_HANDLE ImageHandle,\r
85 IN EFI_SYSTEM_TABLE *SystemTable\r
86 )\r
87{\r
88 EFI_HOB_GUID_TYPE *GuidHob;\r
89\r
90 //\r
91 // Enable ACPI IO space.\r
92 //\r
93 AcpiTimerLibConstructor ();\r
94\r
95 //\r
96 // Initialize PerformanceCounterFrequency\r
97 //\r
98 GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);\r
99 if (GuidHob != NULL) {\r
100 mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob);\r
101 } else {\r
62b8b5be 102 mPerformanceCounterFrequency = InternalCalculateTscFrequency ();\r
83d1ffb9 103 }\r
fd501a79
LG
104\r
105 return EFI_SUCCESS;\r
83d1ffb9 106}\r