]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
PcAtChipsetPkg: Clean up source files
[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
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
fd501a79 15#include <PiDxe.h>\r
83d1ffb9
LG
16#include <Library/TimerLib.h>\r
17#include <Library/BaseLib.h>\r
fd501a79
LG
18#include <Library/HobLib.h>\r
19\r
20extern GUID mFrequencyHobGuid;\r
21\r
22/**\r
23 The constructor function enables ACPI IO space.\r
24\r
25 If ACPI I/O space not enabled, this function will enable it.\r
26 It will always return RETURN_SUCCESS.\r
27\r
28 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
29\r
30**/\r
31RETURN_STATUS\r
32EFIAPI\r
33AcpiTimerLibConstructor (\r
34 VOID\r
35 );\r
83d1ffb9 36\r
62b8b5be
SZ
37/**\r
38 Calculate TSC frequency.\r
39\r
40 The TSC counting frequency is determined by comparing how far it counts\r
a012df5e
SZ
41 during a 101.4 us period as determined by the ACPI timer.\r
42 The ACPI timer is used because it counts at a known frequency.\r
43 The TSC is sampled, followed by waiting 363 counts of the ACPI timer,\r
44 or 101.4 us. The TSC is then sampled again. The difference multiplied by\r
45 9861 is the TSC frequency. There will be a small error because of the\r
46 overhead of reading the ACPI timer. An attempt is made to determine and\r
47 compensate for this error.\r
62b8b5be
SZ
48\r
49 @return The number of TSC counts per second.\r
50\r
51**/\r
52UINT64\r
53InternalCalculateTscFrequency (\r
54 VOID\r
55 );\r
56\r
83d1ffb9
LG
57//\r
58// Cached performance counter frequency\r
59//\r
60UINT64 mPerformanceCounterFrequency = 0;\r
61\r
62/**\r
63 Internal function to retrieves the 64-bit frequency in Hz.\r
64\r
65 Internal function to retrieves the 64-bit frequency in Hz.\r
66\r
67 @return The frequency in Hz.\r
68\r
69**/\r
70UINT64\r
71InternalGetPerformanceCounterFrequency (\r
72 VOID\r
5a702acd 73 )\r
83d1ffb9 74{\r
fd501a79
LG
75 return mPerformanceCounterFrequency;\r
76}\r
77\r
78/**\r
5a702acd 79 The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.\r
fd501a79
LG
80\r
81 @param ImageHandle The firmware allocated handle for the EFI image.\r
82 @param SystemTable A pointer to the EFI System Table.\r
83\r
84 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
85\r
86**/\r
87EFI_STATUS\r
88EFIAPI\r
89DxeAcpiTimerLibConstructor (\r
90 IN EFI_HANDLE ImageHandle,\r
91 IN EFI_SYSTEM_TABLE *SystemTable\r
92 )\r
93{\r
94 EFI_HOB_GUID_TYPE *GuidHob;\r
95\r
96 //\r
97 // Enable ACPI IO space.\r
98 //\r
99 AcpiTimerLibConstructor ();\r
100\r
101 //\r
102 // Initialize PerformanceCounterFrequency\r
103 //\r
104 GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);\r
105 if (GuidHob != NULL) {\r
106 mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob);\r
107 } else {\r
62b8b5be 108 mPerformanceCounterFrequency = InternalCalculateTscFrequency ();\r
83d1ffb9 109 }\r
fd501a79
LG
110\r
111 return EFI_SUCCESS;\r
83d1ffb9 112}\r