Store and get TSC Frequency with system configuration Table.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11572 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lzeng14 2011-04-20 05:14:00 +00:00
parent 0ec4f1cb6f
commit a176509a7f
2 changed files with 18 additions and 15 deletions

View File

@ -31,12 +31,13 @@
#include <PiDxe.h> #include <PiDxe.h>
#include <Ich/GenericIch.h> #include <Ich/GenericIch.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/TimerLib.h> #include <Library/TimerLib.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/IoLib.h> #include <Library/IoLib.h>
#include <Library/PciLib.h> #include <Library/PciLib.h>
#include <Library/PcdLib.h> #include <Library/PcdLib.h>
#include <Library/HobLib.h> #include <Library/UefiLib.h>
#include <Guid/TscFrequency.h> #include <Guid/TscFrequency.h>
@ -44,8 +45,8 @@ UINT64 mTscFrequency;
/** The constructor function determines the actual TSC frequency. /** The constructor function determines the actual TSC frequency.
First, Get TSC frequency from TSC frequency GUID HOB, First, Get TSC frequency from system configuration table with TSC frequency GUID,
If the HOB is not found, calculate it. if the table is not found, install it.
The TSC counting frequency is determined by comparing how far it counts The TSC counting frequency is determined by comparing how far it counts
during a 1ms period as determined by the ACPI timer. The ACPI timer is during a 1ms period as determined by the ACPI timer. The ACPI timer is
@ -70,25 +71,24 @@ DxeTscTimerLibConstructor (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_HOB_GUID_TYPE *GuidHob; EFI_STATUS Status;
VOID *DataInHob; UINT64 *TscFrequency;
UINT64 StartTSC; UINT64 StartTSC;
UINT64 EndTSC; UINT64 EndTSC;
UINT32 TimerAddr; UINT32 TimerAddr;
UINT32 Ticks; UINT32 Ticks;
// //
// Get TSC frequency from TSC frequency GUID HOB. // Get TSC frequency from system configuration table with TSC frequency GUID.
// //
GuidHob = GetFirstGuidHob (&gEfiTscFrequencyGuid); Status = EfiGetSystemConfigurationTable (&gEfiTscFrequencyGuid, (VOID **) &TscFrequency);
if (GuidHob != NULL) { if (Status == EFI_SUCCESS) {
DataInHob = GET_GUID_HOB_DATA (GuidHob); mTscFrequency = *TscFrequency;
mTscFrequency = * (UINT64 *) DataInHob;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
// //
// TSC frequency GUID HOB is not found, calculate it. // TSC frequency GUID system configuration table is not found, install it.
// //
// //
@ -122,8 +122,10 @@ DxeTscTimerLibConstructor (
1000 // Number of ms in a second 1000 // Number of ms in a second
); );
// //
// mTscFrequency is now equal to the number of TSC counts per second // mTscFrequency is now equal to the number of TSC counts per second, install system configuration table for it.
// //
gBS->InstallConfigurationTable (&gEfiTscFrequencyGuid, &mTscFrequency);
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -43,14 +43,15 @@
[LibraryClasses] [LibraryClasses]
UefiBootServicesTableLib
PcdLib PcdLib
PciLib PciLib
IoLib IoLib
BaseLib BaseLib
HobLib UefiLib
[Guids] [Guids]
gEfiTscFrequencyGuid ## SOMETIMES_CONSUMES ## Hob gEfiTscFrequencyGuid ## CONSUMES ## System Configuration Table
[Pcd.common] [Pcd.common]
gPerformancePkgTokenSpaceGuid.PcdPerfPkgAcpiIoPortBaseAddress gPerformancePkgTokenSpaceGuid.PcdPerfPkgAcpiIoPortBaseAddress