--- /dev/null
+/** @file\r
+ A Dxe Timer Library implementation which uses the Time Stamp Counter in the processor.\r
+\r
+ For Pentium 4 processors, Intel Xeon processors (family [0FH], models [03H and higher]);\r
+ for Intel Core Solo and Intel Core Duo processors (family [06H], model [0EH]);\r
+ for the Intel Xeon processor 5100 series and Intel Core 2 Duo processors (family [06H], model [0FH]);\r
+ for Intel Core 2 and Intel Xeon processors (family [06H], display_model [17H]);\r
+ for Intel Atom processors (family [06H], display_model [1CH]):\r
+ the time-stamp counter increments at a constant rate.\r
+ That rate may be set by the maximum core-clock to bus-clock ratio of the processor or may be set by\r
+ the maximum resolved frequency at which the processor is booted. The maximum resolved frequency may\r
+ differ from the maximum qualified frequency of the processor.\r
+\r
+ The specific processor configuration determines the behavior. Constant TSC behavior ensures that the\r
+ duration of each clock tick is uniform and supports the use of the TSC as a wall clock timer even if\r
+ the processor core changes frequency. This is the architectural behavior moving forward.\r
+\r
+ A Processor's support for invariant TSC is indicated by CPUID.0x80000007.EDX[8].\r
+\r
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Guid/TscFrequency.h>\r
+#include "TscTimerLibInternal.h"\r
+\r
+UINT64 mTscFrequency;\r
+\r
+/** The constructor function determines the actual TSC frequency.\r
+\r
+ First, Get TSC frequency from system configuration table with TSC frequency GUID,\r
+ if the table is not found, install it.\r
+ This function will always return EFI_SUCCESS.\r
+\r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeTscTimerLibConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINT64 *TscFrequency;\r
+\r
+ //\r
+ // Get TSC frequency from system configuration table with TSC frequency GUID.\r
+ //\r
+ Status = EfiGetSystemConfigurationTable (&gEfiTscFrequencyGuid, (VOID **) &TscFrequency);\r
+ if (Status == EFI_SUCCESS) {\r
+ mTscFrequency = *TscFrequency;\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ //\r
+ // TSC frequency GUID system configuration table is not found, install it.\r
+ //\r
+\r
+ Status = gBS->AllocatePool (EfiBootServicesData, sizeof (UINT64), (VOID **) &TscFrequency);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ *TscFrequency = InternalCalculateTscFrequency ();\r
+ //\r
+ // TscFrequency now points to the number of TSC counts per second, install system configuration table for it.\r
+ //\r
+ gBS->InstallConfigurationTable (&gEfiTscFrequencyGuid, TscFrequency);\r
+\r
+ mTscFrequency = *TscFrequency;\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/** Get TSC frequency.\r
+\r
+ @return The number of TSC counts per second.\r
+\r
+**/\r
+UINT64\r
+InternalGetTscFrequency (\r
+ VOID\r
+ )\r
+{\r
+ return mTscFrequency;\r
+}\r
+\r