]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c
PcAtChipsetPkg: Apply uncrustify changes
[mirror_edk2.git] / PcAtChipsetPkg / Library / AcpiTimerLib / PeiAcpiTimerLib.c
CommitLineData
fd501a79
LG
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
e1d302e5 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
fd501a79
LG
6\r
7**/\r
8\r
9#include <PiPei.h>\r
10#include <Library/TimerLib.h>\r
11#include <Library/BaseLib.h>\r
12#include <Library/HobLib.h>\r
8ee7ad90 13#include <Library/DebugLib.h>\r
fd501a79 14\r
5220bd21 15extern GUID mFrequencyHobGuid;\r
fd501a79
LG
16\r
17/**\r
18 Calculate TSC frequency.\r
19\r
20 The TSC counting frequency is determined by comparing how far it counts\r
21 during a 101.4 us period as determined by the ACPI timer.\r
22 The ACPI timer is used because it counts at a known frequency.\r
23 The TSC is sampled, followed by waiting 363 counts of the ACPI timer,\r
24 or 101.4 us. The TSC is then sampled again. The difference multiplied by\r
25 9861 is the TSC frequency. There will be a small error because of the\r
26 overhead of reading the ACPI timer. An attempt is made to determine and\r
27 compensate for this error.\r
28\r
29 @return The number of TSC counts per second.\r
30\r
31**/\r
32UINT64\r
33InternalCalculateTscFrequency (\r
34 VOID\r
35 );\r
36\r
37/**\r
38 Internal function to retrieves the 64-bit frequency in Hz.\r
39\r
40 Internal function to retrieves the 64-bit frequency in Hz.\r
41\r
42 @return The frequency in Hz.\r
43\r
44**/\r
45UINT64\r
46InternalGetPerformanceCounterFrequency (\r
47 VOID\r
48 )\r
49{\r
5220bd21
MK
50 UINT64 *PerformanceCounterFrequency;\r
51 EFI_HOB_GUID_TYPE *GuidHob;\r
fd501a79
LG
52\r
53 PerformanceCounterFrequency = NULL;\r
5220bd21 54 GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);\r
fd501a79 55 if (GuidHob == NULL) {\r
5220bd21 56 PerformanceCounterFrequency = (UINT64 *)BuildGuidHob (&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));\r
fd501a79
LG
57 ASSERT (PerformanceCounterFrequency != NULL);\r
58 *PerformanceCounterFrequency = InternalCalculateTscFrequency ();\r
59 } else {\r
5220bd21 60 PerformanceCounterFrequency = (UINT64 *)GET_GUID_HOB_DATA (GuidHob);\r
fd501a79
LG
61 }\r
62\r
5220bd21 63 return *PerformanceCounterFrequency;\r
fd501a79 64}\r