diff options
Diffstat (limited to 'PcAtChipsetPkg/Library/AcpiTimerLib')
4 files changed, 48 insertions, 43 deletions
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c index bcb32545f3..d68eaccf1f 100644 --- a/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/AcpiTimerLib.c @@ -15,7 +15,9 @@ #include <Library/DebugLib.h>
#include <IndustryStandard/Acpi.h>
-GUID mFrequencyHobGuid = { 0x3fca54f6, 0xe1a2, 0x4b20, { 0xbe, 0x76, 0x92, 0x6b, 0x4b, 0x48, 0xbf, 0xaa }};
+GUID mFrequencyHobGuid = {
+ 0x3fca54f6, 0xe1a2, 0x4b20, { 0xbe, 0x76, 0x92, 0x6b, 0x4b, 0x48, 0xbf, 0xaa }
+};
/**
Internal function to retrieves the 64-bit frequency in Hz.
@@ -45,11 +47,11 @@ AcpiTimerLibConstructor ( VOID
)
{
- UINTN Bus;
- UINTN Device;
- UINTN Function;
- UINTN EnableRegister;
- UINT8 EnableMask;
+ UINTN Bus;
+ UINTN Device;
+ UINTN Function;
+ UINTN EnableRegister;
+ UINT8 EnableMask;
//
// ASSERT for the invalid PCD values. They must be configured to the real value.
@@ -69,18 +71,18 @@ AcpiTimerLibConstructor ( //
// ASSERT for the invalid PCD values. They must be configured to the real value.
//
- ASSERT (PcdGet8 (PcdAcpiIoPciDeviceNumber) != 0xFF);
- ASSERT (PcdGet8 (PcdAcpiIoPciFunctionNumber) != 0xFF);
+ ASSERT (PcdGet8 (PcdAcpiIoPciDeviceNumber) != 0xFF);
+ ASSERT (PcdGet8 (PcdAcpiIoPciFunctionNumber) != 0xFF);
ASSERT (PcdGet16 (PcdAcpiIoPciEnableRegisterOffset) != 0xFFFF);
//
// Retrieve the PCD values for the PCI configuration space required to program the ACPI I/O Port Base Address
//
- Bus = PcdGet8 (PcdAcpiIoPciBusNumber);
- Device = PcdGet8 (PcdAcpiIoPciDeviceNumber);
- Function = PcdGet8 (PcdAcpiIoPciFunctionNumber);
+ Bus = PcdGet8 (PcdAcpiIoPciBusNumber);
+ Device = PcdGet8 (PcdAcpiIoPciDeviceNumber);
+ Function = PcdGet8 (PcdAcpiIoPciFunctionNumber);
EnableRegister = PcdGet16 (PcdAcpiIoPciEnableRegisterOffset);
- EnableMask = PcdGet8 (PcdAcpiIoBarEnableMask);
+ EnableMask = PcdGet8 (PcdAcpiIoBarEnableMask);
//
// If ACPI I/O space is not enabled yet, program ACPI I/O base address and enable it.
@@ -122,12 +124,14 @@ InternalAcpiGetAcpiTimerIoPort ( // value other than PcdAcpiIoPortBaseAddress
//
if (PcdGet16 (PcdAcpiIoPciBarRegisterOffset) != 0x0000) {
- Port = PciRead16 (PCI_LIB_ADDRESS (
- PcdGet8 (PcdAcpiIoPciBusNumber),
- PcdGet8 (PcdAcpiIoPciDeviceNumber),
- PcdGet8 (PcdAcpiIoPciFunctionNumber),
- PcdGet16 (PcdAcpiIoPciBarRegisterOffset)
- ));
+ Port = PciRead16 (
+ PCI_LIB_ADDRESS (
+ PcdGet8 (PcdAcpiIoPciBusNumber),
+ PcdGet8 (PcdAcpiIoPciDeviceNumber),
+ PcdGet8 (PcdAcpiIoPciFunctionNumber),
+ PcdGet16 (PcdAcpiIoPciBarRegisterOffset)
+ )
+ );
}
return (Port & PcdGet16 (PcdAcpiIoPortBaseAddressMask)) + PcdGet16 (PcdAcpiPm1TmrOffset);
@@ -147,9 +151,9 @@ InternalAcpiDelay ( IN UINT32 Delay
)
{
- UINT16 Port;
- UINT32 Ticks;
- UINT32 Times;
+ UINT16 Port;
+ UINT32 Ticks;
+ UINT32 Times;
Port = InternalAcpiGetAcpiTimerIoPort ();
Times = Delay >> 22;
@@ -285,6 +289,7 @@ GetPerformanceCounterProperties ( if (EndValue != NULL) {
*EndValue = 0xffffffffffffffffULL;
}
+
return InternalGetPerformanceCounterFrequency ();
}
@@ -324,9 +329,9 @@ GetTimeInNanoSecond ( // Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34,
// i.e. highest bit set in Remainder should <= 33.
//
- Shift = MAX (0, HighBitSet64 (Remainder) - 33);
- Remainder = RShiftU64 (Remainder, (UINTN) Shift);
- Frequency = RShiftU64 (Frequency, (UINTN) Shift);
+ Shift = MAX (0, HighBitSet64 (Remainder) - 33);
+ Remainder = RShiftU64 (Remainder, (UINTN)Shift);
+ Frequency = RShiftU64 (Frequency, (UINTN)Shift);
NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL);
return NanoSeconds;
@@ -352,12 +357,12 @@ InternalCalculateTscFrequency ( VOID
)
{
- UINT64 StartTSC;
- UINT64 EndTSC;
- UINT16 TimerAddr;
- UINT32 Ticks;
- UINT64 TscFrequency;
- BOOLEAN InterruptState;
+ UINT64 StartTSC;
+ UINT64 EndTSC;
+ UINT16 TimerAddr;
+ UINT32 Ticks;
+ UINT64 TscFrequency;
+ BOOLEAN InterruptState;
InterruptState = SaveAndDisableInterrupts ();
@@ -377,8 +382,9 @@ InternalCalculateTscFrequency ( // the while loop will exit.
//
while (((Ticks - IoBitFieldRead32 (TimerAddr, 0, 23)) & BIT23) == 0) {
- CpuPause();
+ CpuPause ();
}
+
EndTSC = AsmReadTsc (); // TSC value 101.4 us later
TscFrequency = MultU64x32 (
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c index 0e401194d0..16ac48938f 100644 --- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c @@ -11,7 +11,7 @@ #include <Library/BaseLib.h>
#include <Library/HobLib.h>
-extern GUID mFrequencyHobGuid;
+extern GUID mFrequencyHobGuid;
/**
The constructor function enables ACPI IO space.
@@ -66,7 +66,7 @@ InternalGetPerformanceCounterFrequency ( VOID
)
{
- return mPerformanceCounterFrequency;
+ return mPerformanceCounterFrequency;
}
/**
@@ -80,7 +80,7 @@ CommonAcpiTimerLibConstructor ( VOID
)
{
- EFI_HOB_GUID_TYPE *GuidHob;
+ EFI_HOB_GUID_TYPE *GuidHob;
//
// Enable ACPI IO space.
@@ -92,7 +92,7 @@ CommonAcpiTimerLibConstructor ( //
GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
if (GuidHob != NULL) {
- mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob);
+ mPerformanceCounterFrequency = *(UINT64 *)GET_GUID_HOB_DATA (GuidHob);
} else {
mPerformanceCounterFrequency = InternalCalculateTscFrequency ();
}
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h index 6015d684e5..455d82a840 100644 --- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h @@ -6,7 +6,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
-
#ifndef _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_
#define _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c index a669794c3b..c2f629486d 100644 --- a/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c +++ b/PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c @@ -12,7 +12,7 @@ #include <Library/HobLib.h>
#include <Library/DebugLib.h>
-extern GUID mFrequencyHobGuid;
+extern GUID mFrequencyHobGuid;
/**
Calculate TSC frequency.
@@ -47,18 +47,18 @@ InternalGetPerformanceCounterFrequency ( VOID
)
{
- UINT64 *PerformanceCounterFrequency;
- EFI_HOB_GUID_TYPE *GuidHob;
+ UINT64 *PerformanceCounterFrequency;
+ EFI_HOB_GUID_TYPE *GuidHob;
PerformanceCounterFrequency = NULL;
- GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
+ GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
if (GuidHob == NULL) {
- PerformanceCounterFrequency = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));
+ PerformanceCounterFrequency = (UINT64 *)BuildGuidHob (&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));
ASSERT (PerformanceCounterFrequency != NULL);
*PerformanceCounterFrequency = InternalCalculateTscFrequency ();
} else {
- PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob);
+ PerformanceCounterFrequency = (UINT64 *)GET_GUID_HOB_DATA (GuidHob);
}
- return *PerformanceCounterFrequency;
+ return *PerformanceCounterFrequency;
}
|