]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c
PcAtChipsetPkg: Add PeiAcpiTimerLib to save Frequency in HOB
[mirror_edk2.git] / PcAtChipsetPkg / Library / AcpiTimerLib / BaseAcpiTimerLib.c
CommitLineData
83d1ffb9
LG
1/** @file\r
2 ACPI Timer implements one instance of Timer Library.\r
3\r
62b8b5be 4 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
83d1ffb9
LG
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 <Base.h>\r
16#include <Library/TimerLib.h>\r
17#include <Library/BaseLib.h>\r
18\r
62b8b5be
SZ
19/**\r
20 Calculate TSC frequency.\r
21\r
22 The TSC counting frequency is determined by comparing how far it counts\r
a012df5e
SZ
23 during a 101.4 us period as determined by the ACPI timer.\r
24 The ACPI timer is used because it counts at a known frequency.\r
25 The TSC is sampled, followed by waiting 363 counts of the ACPI timer,\r
26 or 101.4 us. The TSC is then sampled again. The difference multiplied by\r
27 9861 is the TSC frequency. There will be a small error because of the\r
28 overhead of reading the ACPI timer. An attempt is made to determine and\r
29 compensate for this error.\r
62b8b5be
SZ
30\r
31 @return The number of TSC counts per second.\r
32\r
33**/\r
34UINT64\r
35InternalCalculateTscFrequency (\r
36 VOID\r
37 );\r
38\r
83d1ffb9
LG
39/**\r
40 Internal function to retrieves the 64-bit frequency in Hz.\r
41\r
42 Internal function to retrieves the 64-bit frequency in Hz.\r
43\r
44 @return The frequency in Hz.\r
45\r
46**/\r
47UINT64\r
48InternalGetPerformanceCounterFrequency (\r
49 VOID\r
50 ) \r
51{\r
62b8b5be 52 return InternalCalculateTscFrequency ();\r
83d1ffb9 53}\r