]> git.proxmox.com Git - mirror_edk2.git/blame - PerformancePkg/Library/TscTimerLib/DxeTscTimerLib.c
SignedCapsulePkg: Update EdkiiSystemCapsuleLib to check PCD value
[mirror_edk2.git] / PerformancePkg / Library / TscTimerLib / DxeTscTimerLib.c
CommitLineData
034307a7
SZ
1/** @file\r
2 A Dxe Timer Library implementation which uses the Time Stamp Counter in the processor.\r
3\r
4 For Pentium 4 processors, Intel Xeon processors (family [0FH], models [03H and higher]);\r
5 for Intel Core Solo and Intel Core Duo processors (family [06H], model [0EH]);\r
6 for the Intel Xeon processor 5100 series and Intel Core 2 Duo processors (family [06H], model [0FH]);\r
7 for Intel Core 2 and Intel Xeon processors (family [06H], display_model [17H]);\r
8 for Intel Atom processors (family [06H], display_model [1CH]):\r
9 the time-stamp counter increments at a constant rate.\r
10 That rate may be set by the maximum core-clock to bus-clock ratio of the processor or may be set by\r
11 the maximum resolved frequency at which the processor is booted. The maximum resolved frequency may\r
12 differ from the maximum qualified frequency of the processor.\r
13\r
14 The specific processor configuration determines the behavior. Constant TSC behavior ensures that the\r
15 duration of each clock tick is uniform and supports the use of the TSC as a wall clock timer even if\r
16 the processor core changes frequency. This is the architectural behavior moving forward.\r
17\r
18 A Processor's support for invariant TSC is indicated by CPUID.0x80000007.EDX[8].\r
19\r
20 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
21 This program and the accompanying materials\r
22 are licensed and made available under the terms and conditions of the BSD License\r
23 which accompanies this distribution. The full text of the license may be found at\r
24 http://opensource.org/licenses/bsd-license.php\r
25\r
26 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
27 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
28\r
29**/\r
30\r
31#include <PiDxe.h>\r
32#include <Library/UefiBootServicesTableLib.h>\r
33#include <Library/UefiLib.h>\r
34#include <Library/DebugLib.h>\r
35#include <Guid/TscFrequency.h>\r
36#include "TscTimerLibInternal.h"\r
37\r
38UINT64 mTscFrequency;\r
39\r
40/** The constructor function determines the actual TSC frequency.\r
41\r
42 First, Get TSC frequency from system configuration table with TSC frequency GUID,\r
43 if the table is not found, install it.\r
44 This function will always return EFI_SUCCESS.\r
45\r
46 @param ImageHandle The firmware allocated handle for the EFI image.\r
47 @param SystemTable A pointer to the EFI System Table.\r
48\r
49 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
50\r
51**/\r
52EFI_STATUS\r
53EFIAPI\r
54DxeTscTimerLibConstructor (\r
55 IN EFI_HANDLE ImageHandle,\r
56 IN EFI_SYSTEM_TABLE *SystemTable\r
57 )\r
58{\r
59 EFI_STATUS Status;\r
60 UINT64 *TscFrequency;\r
61\r
d0f65b21 62 TscFrequency = NULL;\r
034307a7
SZ
63 //\r
64 // Get TSC frequency from system configuration table with TSC frequency GUID.\r
65 //\r
66 Status = EfiGetSystemConfigurationTable (&gEfiTscFrequencyGuid, (VOID **) &TscFrequency);\r
67 if (Status == EFI_SUCCESS) {\r
d0f65b21 68 ASSERT (TscFrequency != NULL);\r
034307a7
SZ
69 mTscFrequency = *TscFrequency;\r
70 return EFI_SUCCESS;\r
71 }\r
72\r
73 //\r
74 // TSC frequency GUID system configuration table is not found, install it.\r
75 //\r
76\r
77 Status = gBS->AllocatePool (EfiBootServicesData, sizeof (UINT64), (VOID **) &TscFrequency);\r
78 ASSERT_EFI_ERROR (Status);\r
79\r
80 *TscFrequency = InternalCalculateTscFrequency ();\r
81 //\r
82 // TscFrequency now points to the number of TSC counts per second, install system configuration table for it.\r
83 //\r
84 gBS->InstallConfigurationTable (&gEfiTscFrequencyGuid, TscFrequency);\r
85\r
86 mTscFrequency = *TscFrequency;\r
87 return EFI_SUCCESS;\r
88}\r
89\r
90/** Get TSC frequency.\r
91\r
92 @return The number of TSC counts per second.\r
93\r
94**/\r
95UINT64\r
96InternalGetTscFrequency (\r
97 VOID\r
98 )\r
99{\r
100 return mTscFrequency;\r
101}\r
102\r