]>
Commit | Line | Data |
---|---|---|
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 | |
19 | \r | |
20 | extern GUID mFrequencyHobGuid;\r | |
21 | \r | |
22 | /**\r | |
23 | Calculate TSC frequency.\r | |
24 | \r | |
25 | The TSC counting frequency is determined by comparing how far it counts\r | |
26 | during a 101.4 us period as determined by the ACPI timer.\r | |
27 | The ACPI timer is used because it counts at a known frequency.\r | |
28 | The TSC is sampled, followed by waiting 363 counts of the ACPI timer,\r | |
29 | or 101.4 us. The TSC is then sampled again. The difference multiplied by\r | |
30 | 9861 is the TSC frequency. There will be a small error because of the\r | |
31 | overhead of reading the ACPI timer. An attempt is made to determine and\r | |
32 | compensate for this error.\r | |
33 | \r | |
34 | @return The number of TSC counts per second.\r | |
35 | \r | |
36 | **/\r | |
37 | UINT64\r | |
38 | InternalCalculateTscFrequency (\r | |
39 | VOID\r | |
40 | );\r | |
41 | \r | |
42 | /**\r | |
43 | Internal function to retrieves the 64-bit frequency in Hz.\r | |
44 | \r | |
45 | Internal function to retrieves the 64-bit frequency in Hz.\r | |
46 | \r | |
47 | @return The frequency in Hz.\r | |
48 | \r | |
49 | **/\r | |
50 | UINT64\r | |
51 | InternalGetPerformanceCounterFrequency (\r | |
52 | VOID\r | |
53 | )\r | |
54 | {\r | |
55 | UINT64 *PerformanceCounterFrequency;\r | |
56 | EFI_HOB_GUID_TYPE *GuidHob;\r | |
57 | \r | |
58 | PerformanceCounterFrequency = NULL;\r | |
59 | GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);\r | |
60 | if (GuidHob == NULL) {\r | |
61 | PerformanceCounterFrequency = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));\r | |
62 | ASSERT (PerformanceCounterFrequency != NULL);\r | |
63 | *PerformanceCounterFrequency = InternalCalculateTscFrequency ();\r | |
64 | } else {\r | |
65 | PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob);\r | |
66 | }\r | |
67 | \r | |
68 | return *PerformanceCounterFrequency;\r | |
69 | }\r |