]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c
PcAtChipsetPkg PeiAcpiTimerLib: Add the missing DebugLib header file
[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
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiPei.h>\r
16#include <Library/TimerLib.h>\r
17#include <Library/BaseLib.h>\r
18#include <Library/HobLib.h>\r
8ee7ad90 19#include <Library/DebugLib.h>\r
fd501a79
LG
20\r
21extern GUID mFrequencyHobGuid;\r
22\r
23/**\r
24 Calculate TSC frequency.\r
25\r
26 The TSC counting frequency is determined by comparing how far it counts\r
27 during a 101.4 us period as determined by the ACPI timer.\r
28 The ACPI timer is used because it counts at a known frequency.\r
29 The TSC is sampled, followed by waiting 363 counts of the ACPI timer,\r
30 or 101.4 us. The TSC is then sampled again. The difference multiplied by\r
31 9861 is the TSC frequency. There will be a small error because of the\r
32 overhead of reading the ACPI timer. An attempt is made to determine and\r
33 compensate for this error.\r
34\r
35 @return The number of TSC counts per second.\r
36\r
37**/\r
38UINT64\r
39InternalCalculateTscFrequency (\r
40 VOID\r
41 );\r
42\r
43/**\r
44 Internal function to retrieves the 64-bit frequency in Hz.\r
45\r
46 Internal function to retrieves the 64-bit frequency in Hz.\r
47\r
48 @return The frequency in Hz.\r
49\r
50**/\r
51UINT64\r
52InternalGetPerformanceCounterFrequency (\r
53 VOID\r
54 )\r
55{\r
56 UINT64 *PerformanceCounterFrequency;\r
57 EFI_HOB_GUID_TYPE *GuidHob;\r
58\r
59 PerformanceCounterFrequency = NULL;\r
60 GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);\r
61 if (GuidHob == NULL) {\r
62 PerformanceCounterFrequency = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));\r
63 ASSERT (PerformanceCounterFrequency != NULL);\r
64 *PerformanceCounterFrequency = InternalCalculateTscFrequency ();\r
65 } else {\r
66 PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob);\r
67 }\r
68\r
69 return *PerformanceCounterFrequency;\r
70}\r