PcAtChipsetPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the PcAtChipsetPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
Michael Kubacki 2021-12-05 14:54:10 -08:00 committed by mergify[bot]
parent ac0a286f4d
commit 5220bd211d
18 changed files with 663 additions and 606 deletions

View File

@ -22,8 +22,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIdeControllerCompone
/// EFI Component Name 2 Protocol /// EFI Component Name 2 Protocol
/// ///
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerComponentName2 = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) IdeControllerComponentNameGetDriverName, (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)IdeControllerComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) IdeControllerComponentNameGetControllerName, (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)IdeControllerComponentNameGetControllerName,
"en" "en"
}; };

View File

@ -125,7 +125,7 @@ IdeControllerSupported (
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
Controller, Controller,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
(VOID **) &PciIo, (VOID **)&PciIo,
This->DriverBindingHandle, This->DriverBindingHandle,
Controller, Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER EFI_OPEN_PROTOCOL_BY_DRIVER
@ -208,7 +208,7 @@ IdeControllerStart (
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
Controller, Controller,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
(VOID **) &PciIo, (VOID **)&PciIo,
This->DriverBindingHandle, This->DriverBindingHandle,
Controller, Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER EFI_OPEN_PROTOCOL_BY_DRIVER
@ -230,7 +230,8 @@ IdeControllerStart (
// //
return gBS->InstallMultipleProtocolInterfaces ( return gBS->InstallMultipleProtocolInterfaces (
&Controller, &Controller,
&gEfiIdeControllerInitProtocolGuid, &gEfiIdeControllerInit, &gEfiIdeControllerInitProtocolGuid,
&gEfiIdeControllerInit,
NULL NULL
); );
} }
@ -264,7 +265,7 @@ IdeControllerStop (
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
Controller, Controller,
&gEfiIdeControllerInitProtocolGuid, &gEfiIdeControllerInitProtocolGuid,
(VOID **) &IdeControllerInit, (VOID **)&IdeControllerInit,
This->DriverBindingHandle, This->DriverBindingHandle,
Controller, Controller,
EFI_OPEN_PROTOCOL_GET_PROTOCOL EFI_OPEN_PROTOCOL_GET_PROTOCOL
@ -285,7 +286,8 @@ IdeControllerStop (
// //
Status = gBS->UninstallMultipleProtocolInterfaces ( Status = gBS->UninstallMultipleProtocolInterfaces (
Controller, Controller,
&gEfiIdeControllerInitProtocolGuid, &gEfiIdeControllerInit, &gEfiIdeControllerInitProtocolGuid,
&gEfiIdeControllerInit,
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -306,6 +308,7 @@ IdeControllerStop (
// //
// Interface functions of IDE_CONTROLLER_INIT protocol // Interface functions of IDE_CONTROLLER_INIT protocol
// //
/** /**
Returns the information about the specified IDE channel. Returns the information about the specified IDE channel.
@ -565,7 +568,7 @@ IdeInitCalculateMode (
OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes
) )
{ {
if (Channel >= ICH_IDE_MAX_CHANNEL || Device >= ICH_IDE_MAX_DEVICES) { if ((Channel >= ICH_IDE_MAX_CHANNEL) || (Device >= ICH_IDE_MAX_DEVICES)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }

View File

@ -44,6 +44,7 @@ extern EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerComponentName2;
// //
// Driver binding functions declaration // Driver binding functions declaration
// //
/** /**
Register Driver Binding protocol for this driver. Register Driver Binding protocol for this driver.
@ -110,6 +111,7 @@ IdeControllerStop (
// //
// IDE controller init functions declaration // IDE controller init functions declaration
// //
/** /**
Returns the information about the specified IDE channel. Returns the information about the specified IDE channel.
@ -388,6 +390,7 @@ IdeInitSetTiming (
// //
// Forward reference declaration // Forward reference declaration
// //
/** /**
Retrieves a Unicode string that is the user readable name of the EFI Driver. Retrieves a Unicode string that is the user readable name of the EFI Driver.

View File

@ -300,7 +300,9 @@ TimerInterruptHandler (
// //
// Count number of ticks // Count number of ticks
// //
DEBUG_CODE (mNumTicks++;); DEBUG_CODE (
mNumTicks++;
);
// //
// Clear HPET timer interrupt status // Clear HPET timer interrupt status
@ -376,6 +378,7 @@ TimerInterruptHandler (
// //
Delta = (mCounterMask - mPreviousMainCounter) + MainCounter; Delta = (mCounterMask - mPreviousMainCounter) + MainCounter;
} }
TimerPeriod = DivU64x32 ( TimerPeriod = DivU64x32 (
MultU64x32 ( MultU64x32 (
Delta & mCounterMask, Delta & mCounterMask,
@ -437,10 +440,11 @@ TimerDriverRegisterHandler (
// //
// Check for invalid parameters // Check for invalid parameters
// //
if (NotifyFunction == NULL && mTimerNotifyFunction == NULL) { if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (NotifyFunction != NULL && mTimerNotifyFunction != NULL) {
if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {
return EFI_ALREADY_STARTED; return EFI_ALREADY_STARTED;
} }
@ -513,6 +517,7 @@ TimerDriverSetTimerPeriod (
} else { } else {
Delta = MainCounter - mPreviousMainCounter; Delta = MainCounter - mPreviousMainCounter;
} }
if ((Delta & mCounterMask) >= mTimerCount) { if ((Delta & mCounterMask) >= mTimerCount) {
// //
// Interrupt still happens after disable HPET, wait to be processed // Interrupt still happens after disable HPET, wait to be processed
@ -521,7 +526,7 @@ TimerDriverSetTimerPeriod (
CurrentComparator = HpetRead (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE); CurrentComparator = HpetRead (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);
while (CurrentComparator == mPreviousComparator) { while (CurrentComparator == mPreviousComparator) {
CurrentComparator = HpetRead (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE); CurrentComparator = HpetRead (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);
CpuPause(); CpuPause ();
} }
} }
} }
@ -530,7 +535,7 @@ TimerDriverSetTimerPeriod (
// If TimerPeriod is 0, then mask HPET Timer interrupts // If TimerPeriod is 0, then mask HPET Timer interrupts
// //
if (mTimerConfiguration.Bits.MsiInterruptCapability != 0 && FeaturePcdGet (PcdHpetMsiEnable)) { if ((mTimerConfiguration.Bits.MsiInterruptCapability != 0) && FeaturePcdGet (PcdHpetMsiEnable)) {
// //
// Disable HPET MSI interrupt generation // Disable HPET MSI interrupt generation
// //
@ -567,6 +572,7 @@ TimerDriverSetTimerPeriod (
} else { } else {
Delta = (mCounterMask - mPreviousMainCounter) + MainCounter; Delta = (mCounterMask - mPreviousMainCounter) + MainCounter;
} }
if ((Delta & mCounterMask) >= mTimerCount) { if ((Delta & mCounterMask) >= mTimerCount) {
HpetWrite (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE, (MainCounter + 1) & mCounterMask); HpetWrite (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE, (MainCounter + 1) & mCounterMask);
} else { } else {
@ -576,7 +582,7 @@ TimerDriverSetTimerPeriod (
// //
// Enable HPET Timer interrupt generation // Enable HPET Timer interrupt generation
// //
if (mTimerConfiguration.Bits.MsiInterruptCapability != 0 && FeaturePcdGet (PcdHpetMsiEnable)) { if ((mTimerConfiguration.Bits.MsiInterruptCapability != 0) && FeaturePcdGet (PcdHpetMsiEnable)) {
// //
// Program MSI Address and MSI Data values in the selected HPET Timer // Program MSI Address and MSI Data values in the selected HPET Timer
// Program HPET register with APIC ID of current BSP in case BSP has been switched // Program HPET register with APIC ID of current BSP in case BSP has been switched
@ -772,7 +778,7 @@ TimerDriverInitialize (
// //
// Find the CPU architectural protocol. // Find the CPU architectural protocol.
// //
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **) &mCpu); Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&mCpu);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
@ -787,7 +793,7 @@ TimerDriverInitialize (
// //
ASSERT (mHpetGeneralCapabilities.Uint64 != 0); ASSERT (mHpetGeneralCapabilities.Uint64 != 0);
ASSERT (mHpetGeneralCapabilities.Uint64 != 0xFFFFFFFFFFFFFFFFULL); ASSERT (mHpetGeneralCapabilities.Uint64 != 0xFFFFFFFFFFFFFFFFULL);
if (mHpetGeneralCapabilities.Uint64 == 0 || mHpetGeneralCapabilities.Uint64 == 0xFFFFFFFFFFFFFFFFULL) { if ((mHpetGeneralCapabilities.Uint64 == 0) || (mHpetGeneralCapabilities.Uint64 == 0xFFFFFFFFFFFFFFFFULL)) {
DEBUG ((DEBUG_ERROR, "HPET device is not present. Unload HPET driver.\n")); DEBUG ((DEBUG_ERROR, "HPET device is not present. Unload HPET driver.\n"));
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -812,6 +818,7 @@ TimerDriverInitialize (
DEBUG ((DEBUG_INFO, " HPET_TIMER%d_COMPARATOR = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_COMPARATOR_OFFSET + TimerIndex * HPET_TIMER_STRIDE))); DEBUG ((DEBUG_INFO, " HPET_TIMER%d_COMPARATOR = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_COMPARATOR_OFFSET + TimerIndex * HPET_TIMER_STRIDE)));
DEBUG ((DEBUG_INFO, " HPET_TIMER%d_MSI_ROUTE = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_MSI_ROUTE_OFFSET + TimerIndex * HPET_TIMER_STRIDE))); DEBUG ((DEBUG_INFO, " HPET_TIMER%d_MSI_ROUTE = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_MSI_ROUTE_OFFSET + TimerIndex * HPET_TIMER_STRIDE)));
} }
DEBUG_CODE_END (); DEBUG_CODE_END ();
// //
@ -857,7 +864,7 @@ TimerDriverInitialize (
} }
} }
if (FeaturePcdGet (PcdHpetMsiEnable) && MsiTimerIndex != HPET_INVALID_TIMER_INDEX) { if (FeaturePcdGet (PcdHpetMsiEnable) && (MsiTimerIndex != HPET_INVALID_TIMER_INDEX)) {
// //
// Use MSI interrupt if supported // Use MSI interrupt if supported
// //
@ -959,12 +966,13 @@ TimerDriverInitialize (
// Show state of enabled HPET timer // Show state of enabled HPET timer
// //
DEBUG_CODE_BEGIN (); DEBUG_CODE_BEGIN ();
if (mTimerConfiguration.Bits.MsiInterruptCapability != 0 && FeaturePcdGet (PcdHpetMsiEnable)) { if ((mTimerConfiguration.Bits.MsiInterruptCapability != 0) && FeaturePcdGet (PcdHpetMsiEnable)) {
DEBUG ((DEBUG_INFO, "HPET Interrupt Mode MSI\n")); DEBUG ((DEBUG_INFO, "HPET Interrupt Mode MSI\n"));
} else { } else {
DEBUG ((DEBUG_INFO, "HPET Interrupt Mode I/O APIC\n")); DEBUG ((DEBUG_INFO, "HPET Interrupt Mode I/O APIC\n"));
DEBUG ((DEBUG_INFO, "HPET I/O APIC IRQ = 0x%02x\n", mTimerIrq)); DEBUG ((DEBUG_INFO, "HPET I/O APIC IRQ = 0x%02x\n", mTimerIrq));
} }
DEBUG ((DEBUG_INFO, "HPET Interrupt Vector = 0x%02x\n", PcdGet8 (PcdHpetLocalApicVector))); DEBUG ((DEBUG_INFO, "HPET Interrupt Vector = 0x%02x\n", PcdGet8 (PcdHpetLocalApicVector)));
DEBUG ((DEBUG_INFO, "HPET Counter Mask = 0x%016lx\n", mCounterMask)); DEBUG ((DEBUG_INFO, "HPET Counter Mask = 0x%016lx\n", mCounterMask));
DEBUG ((DEBUG_INFO, "HPET Timer Period = %d\n", mTimerPeriod)); DEBUG ((DEBUG_INFO, "HPET Timer Period = %d\n", mTimerPeriod));
@ -976,7 +984,9 @@ TimerDriverInitialize (
// //
// Wait for a few timer interrupts to fire before continuing // Wait for a few timer interrupts to fire before continuing
// //
while (mNumTicks < 10); while (mNumTicks < 10) {
}
DEBUG_CODE_END (); DEBUG_CODE_END ();
// //
@ -984,7 +994,8 @@ TimerDriverInitialize (
// //
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&mTimerHandle, &mTimerHandle,
&gEfiTimerArchProtocolGuid, &mTimer, &gEfiTimerArchProtocolGuid,
&mTimer,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);

View File

@ -8,6 +8,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef __IO_APIC_LIB_H__ #ifndef __IO_APIC_LIB_H__
#define __IO_APIC_LIB_H__ #define __IO_APIC_LIB_H__
@ -96,4 +97,5 @@ IoApicConfigureInterrupt (
IN BOOLEAN LevelTriggered, IN BOOLEAN LevelTriggered,
IN BOOLEAN AssertionLevel IN BOOLEAN AssertionLevel
); );
#endif #endif

View File

@ -37,13 +37,13 @@
/// ///
typedef union { typedef union {
struct { struct {
UINT32 Revision:8; UINT32 Revision : 8;
UINT32 NumberOfTimers:5; UINT32 NumberOfTimers : 5;
UINT32 CounterSize:1; UINT32 CounterSize : 1;
UINT32 Reserved0:1; UINT32 Reserved0 : 1;
UINT32 LegacyRoute:1; UINT32 LegacyRoute : 1;
UINT32 VendorId:16; UINT32 VendorId : 16;
UINT32 CounterClockPeriod:32; UINT32 CounterClockPeriod : 32;
} Bits; } Bits;
UINT64 Uint64; UINT64 Uint64;
} HPET_GENERAL_CAPABILITIES_ID_REGISTER; } HPET_GENERAL_CAPABILITIES_ID_REGISTER;
@ -53,10 +53,10 @@ typedef union {
/// ///
typedef union { typedef union {
struct { struct {
UINT32 MainCounterEnable:1; UINT32 MainCounterEnable : 1;
UINT32 LegacyRouteEnable:1; UINT32 LegacyRouteEnable : 1;
UINT32 Reserved0:30; UINT32 Reserved0 : 30;
UINT32 Reserved1:32; UINT32 Reserved1 : 32;
} Bits; } Bits;
UINT64 Uint64; UINT64 Uint64;
} HPET_GENERAL_CONFIGURATION_REGISTER; } HPET_GENERAL_CONFIGURATION_REGISTER;
@ -66,19 +66,19 @@ typedef union {
/// ///
typedef union { typedef union {
struct { struct {
UINT32 Reserved0:1; UINT32 Reserved0 : 1;
UINT32 LevelTriggeredInterrupt:1; UINT32 LevelTriggeredInterrupt : 1;
UINT32 InterruptEnable:1; UINT32 InterruptEnable : 1;
UINT32 PeriodicInterruptEnable:1; UINT32 PeriodicInterruptEnable : 1;
UINT32 PeriodicInterruptCapability:1; UINT32 PeriodicInterruptCapability : 1;
UINT32 CounterSizeCapability:1; UINT32 CounterSizeCapability : 1;
UINT32 ValueSetEnable:1; UINT32 ValueSetEnable : 1;
UINT32 Reserved1:1; UINT32 Reserved1 : 1;
UINT32 CounterSizeEnable:1; UINT32 CounterSizeEnable : 1;
UINT32 InterruptRoute:5; UINT32 InterruptRoute : 5;
UINT32 MsiInterruptEnable:1; UINT32 MsiInterruptEnable : 1;
UINT32 MsiInterruptCapability:1; UINT32 MsiInterruptCapability : 1;
UINT32 Reserved2:16; UINT32 Reserved2 : 16;
UINT32 InterruptRouteCapability; UINT32 InterruptRouteCapability;
} Bits; } Bits;
UINT64 Uint64; UINT64 Uint64;
@ -89,8 +89,8 @@ typedef union {
/// ///
typedef union { typedef union {
struct { struct {
UINT32 Value:32; UINT32 Value : 32;
UINT32 Address:32; UINT32 Address : 32;
} Bits; } Bits;
UINT64 Uint64; UINT64 Uint64;
} HPET_TIMER_MSI_ROUTE_REGISTER; } HPET_TIMER_MSI_ROUTE_REGISTER;

View File

@ -37,36 +37,36 @@
typedef union { typedef union {
struct { struct {
UINT32 Reserved0:24; UINT32 Reserved0 : 24;
UINT32 Identification:4; UINT32 Identification : 4;
UINT32 Reserved1:4; UINT32 Reserved1 : 4;
} Bits; } Bits;
UINT32 Uint32; UINT32 Uint32;
} IO_APIC_IDENTIFICATION_REGISTER; } IO_APIC_IDENTIFICATION_REGISTER;
typedef union { typedef union {
struct { struct {
UINT32 Version:8; UINT32 Version : 8;
UINT32 Reserved0:8; UINT32 Reserved0 : 8;
UINT32 MaximumRedirectionEntry:8; UINT32 MaximumRedirectionEntry : 8;
UINT32 Reserved1:8; UINT32 Reserved1 : 8;
} Bits; } Bits;
UINT32 Uint32; UINT32 Uint32;
} IO_APIC_VERSION_REGISTER; } IO_APIC_VERSION_REGISTER;
typedef union { typedef union {
struct { struct {
UINT32 Vector: 8; UINT32 Vector : 8;
UINT32 DeliveryMode: 3; UINT32 DeliveryMode : 3;
UINT32 DestinationMode: 1; UINT32 DestinationMode : 1;
UINT32 DeliveryStatus: 1; UINT32 DeliveryStatus : 1;
UINT32 Polarity: 1; UINT32 Polarity : 1;
UINT32 RemoteIRR: 1; UINT32 RemoteIRR : 1;
UINT32 TriggerMode: 1; UINT32 TriggerMode : 1;
UINT32 Mask: 1; UINT32 Mask : 1;
UINT32 Reserved0: 15; UINT32 Reserved0 : 15;
UINT32 Reserved1: 24; UINT32 Reserved1 : 24;
UINT32 DestinationID: 8; UINT32 DestinationID : 8;
} Bits; } Bits;
struct { struct {
UINT32 Low; UINT32 Low;

View File

@ -15,7 +15,9 @@
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <IndustryStandard/Acpi.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. Internal function to retrieves the 64-bit frequency in Hz.
@ -122,12 +124,14 @@ InternalAcpiGetAcpiTimerIoPort (
// value other than PcdAcpiIoPortBaseAddress // value other than PcdAcpiIoPortBaseAddress
// //
if (PcdGet16 (PcdAcpiIoPciBarRegisterOffset) != 0x0000) { if (PcdGet16 (PcdAcpiIoPciBarRegisterOffset) != 0x0000) {
Port = PciRead16 (PCI_LIB_ADDRESS ( Port = PciRead16 (
PCI_LIB_ADDRESS (
PcdGet8 (PcdAcpiIoPciBusNumber), PcdGet8 (PcdAcpiIoPciBusNumber),
PcdGet8 (PcdAcpiIoPciDeviceNumber), PcdGet8 (PcdAcpiIoPciDeviceNumber),
PcdGet8 (PcdAcpiIoPciFunctionNumber), PcdGet8 (PcdAcpiIoPciFunctionNumber),
PcdGet16 (PcdAcpiIoPciBarRegisterOffset) PcdGet16 (PcdAcpiIoPciBarRegisterOffset)
)); )
);
} }
return (Port & PcdGet16 (PcdAcpiIoPortBaseAddressMask)) + PcdGet16 (PcdAcpiPm1TmrOffset); return (Port & PcdGet16 (PcdAcpiIoPortBaseAddressMask)) + PcdGet16 (PcdAcpiPm1TmrOffset);
@ -285,6 +289,7 @@ GetPerformanceCounterProperties (
if (EndValue != NULL) { if (EndValue != NULL) {
*EndValue = 0xffffffffffffffffULL; *EndValue = 0xffffffffffffffffULL;
} }
return InternalGetPerformanceCounterFrequency (); return InternalGetPerformanceCounterFrequency ();
} }
@ -325,8 +330,8 @@ GetTimeInNanoSecond (
// i.e. highest bit set in Remainder should <= 33. // i.e. highest bit set in Remainder should <= 33.
// //
Shift = MAX (0, HighBitSet64 (Remainder) - 33); Shift = MAX (0, HighBitSet64 (Remainder) - 33);
Remainder = RShiftU64 (Remainder, (UINTN) Shift); Remainder = RShiftU64 (Remainder, (UINTN)Shift);
Frequency = RShiftU64 (Frequency, (UINTN) Shift); Frequency = RShiftU64 (Frequency, (UINTN)Shift);
NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL); NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL);
return NanoSeconds; return NanoSeconds;
@ -377,8 +382,9 @@ InternalCalculateTscFrequency (
// the while loop will exit. // the while loop will exit.
// //
while (((Ticks - IoBitFieldRead32 (TimerAddr, 0, 23)) & BIT23) == 0) { while (((Ticks - IoBitFieldRead32 (TimerAddr, 0, 23)) & BIT23) == 0) {
CpuPause(); CpuPause ();
} }
EndTSC = AsmReadTsc (); // TSC value 101.4 us later EndTSC = AsmReadTsc (); // TSC value 101.4 us later
TscFrequency = MultU64x32 ( TscFrequency = MultU64x32 (

View File

@ -92,7 +92,7 @@ CommonAcpiTimerLibConstructor (
// //
GuidHob = GetFirstGuidHob (&mFrequencyHobGuid); GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
if (GuidHob != NULL) { if (GuidHob != NULL) {
mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob); mPerformanceCounterFrequency = *(UINT64 *)GET_GUID_HOB_DATA (GuidHob);
} else { } else {
mPerformanceCounterFrequency = InternalCalculateTscFrequency (); mPerformanceCounterFrequency = InternalCalculateTscFrequency ();
} }

View File

@ -6,7 +6,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_ #ifndef _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_
#define _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_ #define _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_

View File

@ -53,11 +53,11 @@ InternalGetPerformanceCounterFrequency (
PerformanceCounterFrequency = NULL; PerformanceCounterFrequency = NULL;
GuidHob = GetFirstGuidHob (&mFrequencyHobGuid); GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
if (GuidHob == NULL) { if (GuidHob == NULL) {
PerformanceCounterFrequency = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency)); PerformanceCounterFrequency = (UINT64 *)BuildGuidHob (&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));
ASSERT (PerformanceCounterFrequency != NULL); ASSERT (PerformanceCounterFrequency != NULL);
*PerformanceCounterFrequency = InternalCalculateTscFrequency (); *PerformanceCounterFrequency = InternalCalculateTscFrequency ();
} else { } else {
PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob); PerformanceCounterFrequency = (UINT64 *)GET_GUID_HOB_DATA (GuidHob);
} }
return *PerformanceCounterFrequency; return *PerformanceCounterFrequency;

View File

@ -29,7 +29,7 @@ ResetCold (
VOID VOID
) )
{ {
IoWrite8 ((UINTN) PcdGet64 (PcdResetControlRegister), PcdGet8 (PcdResetControlValueColdReset)); IoWrite8 ((UINTN)PcdGet64 (PcdResetControlRegister), PcdGet8 (PcdResetControlValueColdReset));
} }
/** /**
@ -45,7 +45,7 @@ ResetWarm (
VOID VOID
) )
{ {
IoWrite8 ((UINTN) PcdGet64 (PcdResetControlRegister), PcdGet8 (PcdResetControlValueColdReset)); IoWrite8 ((UINTN)PcdGet64 (PcdResetControlRegister), PcdGet8 (PcdResetControlValueColdReset));
} }
/** /**
@ -64,7 +64,6 @@ ResetShutdown (
ASSERT (FALSE); ASSERT (FALSE);
} }
/** /**
This function causes a systemwide reset. The exact type of the reset is This function causes a systemwide reset. The exact type of the reset is
defined by the EFI_GUID that follows the Null-terminated Unicode string passed defined by the EFI_GUID that follows the Null-terminated Unicode string passed

View File

@ -10,9 +10,9 @@
#include <Library/IoLib.h> #include <Library/IoLib.h>
#include <Library/SerialPortLib.h> #include <Library/SerialPortLib.h>
//--------------------------------------------- // ---------------------------------------------
// UART Register Offsets // UART Register Offsets
//--------------------------------------------- // ---------------------------------------------
#define BAUD_LOW_OFFSET 0x00 #define BAUD_LOW_OFFSET 0x00
#define BAUD_HIGH_OFFSET 0x01 #define BAUD_HIGH_OFFSET 0x01
#define IER_OFFSET 0x01 #define IER_OFFSET 0x01
@ -27,9 +27,9 @@
#define LSR_OFFSET 0x05 #define LSR_OFFSET 0x05
#define MSR_OFFSET 0x06 #define MSR_OFFSET 0x06
//--------------------------------------------- // ---------------------------------------------
// UART Register Bit Defines // UART Register Bit Defines
//--------------------------------------------- // ---------------------------------------------
#define LSR_TXRDY 0x20 #define LSR_TXRDY 0x20
#define LSR_RXDA 0x01 #define LSR_RXDA 0x01
#define DLAB 0x01 #define DLAB 0x01
@ -40,9 +40,9 @@
#define MSR_RI 0x40 #define MSR_RI 0x40
#define MSR_DCD 0x80 #define MSR_DCD 0x80
//--------------------------------------------- // ---------------------------------------------
// UART Settings // UART Settings
//--------------------------------------------- // ---------------------------------------------
UINT16 gUartBase = 0x3F8; UINT16 gUartBase = 0x3F8;
UINTN gBps = 115200; UINTN gBps = 115200;
UINT8 gData = 8; UINT8 gData = 8;
@ -74,7 +74,7 @@ SerialPortInitialize (
// //
// Map 5..8 to 0..3 // Map 5..8 to 0..3
// //
Data = (UINT8) (gData - (UINT8) 5); Data = (UINT8)(gData - (UINT8)5);
// //
// Calculate divisor for baud generator // Calculate divisor for baud generator
@ -84,19 +84,19 @@ SerialPortInitialize (
// //
// Set communications format // Set communications format
// //
OutputData = (UINT8) ((DLAB << 7) | (gBreakSet << 6) | (gParity << 3) | (gStop << 2) | Data); OutputData = (UINT8)((DLAB << 7) | (gBreakSet << 6) | (gParity << 3) | (gStop << 2) | Data);
IoWrite8 (gUartBase + LCR_OFFSET, OutputData); IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
// //
// Configure baud rate // Configure baud rate
// //
IoWrite8 (gUartBase + BAUD_HIGH_OFFSET, (UINT8) (Divisor >> 8)); IoWrite8 (gUartBase + BAUD_HIGH_OFFSET, (UINT8)(Divisor >> 8));
IoWrite8 (gUartBase + BAUD_LOW_OFFSET, (UINT8) (Divisor & 0xff)); IoWrite8 (gUartBase + BAUD_LOW_OFFSET, (UINT8)(Divisor & 0xff));
// //
// Switch back to bank 0 // Switch back to bank 0
// //
OutputData = (UINT8) ( (gBreakSet << 6) | (gParity << 3) | (gStop << 2) | Data); OutputData = (UINT8)((gBreakSet << 6) | (gParity << 3) | (gStop << 2) | Data);
IoWrite8 (gUartBase + LCR_OFFSET, OutputData); IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
return RETURN_SUCCESS; return RETURN_SUCCESS;
@ -126,7 +126,7 @@ EFIAPI
SerialPortWrite ( SerialPortWrite (
IN UINT8 *Buffer, IN UINT8 *Buffer,
IN UINTN NumberOfBytes IN UINTN NumberOfBytes
) )
{ {
UINTN Result; UINTN Result;
UINT8 Data; UINT8 Data;
@ -142,15 +142,15 @@ SerialPortWrite (
// Wait for the serial port to be ready. // Wait for the serial port to be ready.
// //
do { do {
Data = IoRead8 ((UINT16) gUartBase + LSR_OFFSET); Data = IoRead8 ((UINT16)gUartBase + LSR_OFFSET);
} while ((Data & LSR_TXRDY) == 0); } while ((Data & LSR_TXRDY) == 0);
IoWrite8 ((UINT16) gUartBase, *Buffer++);
IoWrite8 ((UINT16)gUartBase, *Buffer++);
} }
return Result; return Result;
} }
/** /**
Reads data from a serial device into a buffer. Reads data from a serial device into a buffer.
@ -167,7 +167,7 @@ EFIAPI
SerialPortRead ( SerialPortRead (
OUT UINT8 *Buffer, OUT UINT8 *Buffer,
IN UINTN NumberOfBytes IN UINTN NumberOfBytes
) )
{ {
UINTN Result; UINTN Result;
UINT8 Data; UINT8 Data;
@ -183,10 +183,10 @@ SerialPortRead (
// Wait for the serial port to be ready. // Wait for the serial port to be ready.
// //
do { do {
Data = IoRead8 ((UINT16) gUartBase + LSR_OFFSET); Data = IoRead8 ((UINT16)gUartBase + LSR_OFFSET);
} while ((Data & LSR_RXDA) == 0); } while ((Data & LSR_RXDA) == 0);
*Buffer++ = IoRead8 ((UINT16) gUartBase); *Buffer++ = IoRead8 ((UINT16)gUartBase);
} }
return Result; return Result;
@ -214,9 +214,9 @@ SerialPortPoll (
// //
// Read the serial port status. // Read the serial port status.
// //
Data = IoRead8 ((UINT16) gUartBase + LSR_OFFSET); Data = IoRead8 ((UINT16)gUartBase + LSR_OFFSET);
return (BOOLEAN) ((Data & LSR_RXDA) != 0); return (BOOLEAN)((Data & LSR_RXDA) != 0);
} }
/** /**
@ -247,7 +247,7 @@ SerialPortSetControl (
// //
// Read the Modem Control Register. // Read the Modem Control Register.
// //
Mcr = IoRead8 ((UINT16) gUartBase + MCR_OFFSET); Mcr = IoRead8 ((UINT16)gUartBase + MCR_OFFSET);
Mcr &= (~(MCR_DTRC | MCR_RTS)); Mcr &= (~(MCR_DTRC | MCR_RTS));
if ((Control & EFI_SERIAL_DATA_TERMINAL_READY) == EFI_SERIAL_DATA_TERMINAL_READY) { if ((Control & EFI_SERIAL_DATA_TERMINAL_READY) == EFI_SERIAL_DATA_TERMINAL_READY) {
@ -261,7 +261,7 @@ SerialPortSetControl (
// //
// Write the Modem Control Register. // Write the Modem Control Register.
// //
IoWrite8 ((UINT16) gUartBase + MCR_OFFSET, Mcr); IoWrite8 ((UINT16)gUartBase + MCR_OFFSET, Mcr);
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
@ -291,7 +291,7 @@ SerialPortGetControl (
// //
// Read the Modem Status Register. // Read the Modem Status Register.
// //
Msr = IoRead8 ((UINT16) gUartBase + MSR_OFFSET); Msr = IoRead8 ((UINT16)gUartBase + MSR_OFFSET);
if ((Msr & MSR_CTS) == MSR_CTS) { if ((Msr & MSR_CTS) == MSR_CTS) {
*Control |= EFI_SERIAL_CLEAR_TO_SEND; *Control |= EFI_SERIAL_CLEAR_TO_SEND;
@ -312,7 +312,7 @@ SerialPortGetControl (
// //
// Read the Modem Control Register. // Read the Modem Control Register.
// //
Mcr = IoRead8 ((UINT16) gUartBase + MCR_OFFSET); Mcr = IoRead8 ((UINT16)gUartBase + MCR_OFFSET);
if ((Mcr & MCR_DTRC) == MCR_DTRC) { if ((Mcr & MCR_DTRC) == MCR_DTRC) {
*Control |= EFI_SERIAL_DATA_TERMINAL_READY; *Control |= EFI_SERIAL_DATA_TERMINAL_READY;
@ -325,7 +325,7 @@ SerialPortGetControl (
// //
// Read the Line Status Register. // Read the Line Status Register.
// //
Lsr = IoRead8 ((UINT16) gUartBase + LSR_OFFSET); Lsr = IoRead8 ((UINT16)gUartBase + LSR_OFFSET);
if ((Lsr & LSR_TXRDY) == LSR_TXRDY) { if ((Lsr & LSR_TXRDY) == LSR_TXRDY) {
*Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY; *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY;
@ -414,7 +414,7 @@ SerialPortSetAttributes (
// //
// Map 5..8 to 0..3 // Map 5..8 to 0..3
// //
LcrData = (UINT8) (*DataBits - (UINT8) 5); LcrData = (UINT8)(*DataBits - (UINT8)5);
switch (*Parity) { switch (*Parity) {
case NoParity: case NoParity:
@ -458,26 +458,25 @@ SerialPortSetAttributes (
// //
// Calculate divisor for baud generator // Calculate divisor for baud generator
// //
Divisor = 115200 / (UINTN) *BaudRate; Divisor = 115200 / (UINTN)*BaudRate;
// //
// Set communications format // Set communications format
// //
OutputData = (UINT8) ((DLAB << 7) | (gBreakSet << 6) | (LcrParity << 3) | (LcrStop << 2) | LcrData); OutputData = (UINT8)((DLAB << 7) | (gBreakSet << 6) | (LcrParity << 3) | (LcrStop << 2) | LcrData);
IoWrite8 (gUartBase + LCR_OFFSET, OutputData); IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
// //
// Configure baud rate // Configure baud rate
// //
IoWrite8 (gUartBase + BAUD_HIGH_OFFSET, (UINT8) (Divisor >> 8)); IoWrite8 (gUartBase + BAUD_HIGH_OFFSET, (UINT8)(Divisor >> 8));
IoWrite8 (gUartBase + BAUD_LOW_OFFSET, (UINT8) (Divisor & 0xff)); IoWrite8 (gUartBase + BAUD_LOW_OFFSET, (UINT8)(Divisor & 0xff));
// //
// Switch back to bank 0 // Switch back to bank 0
// //
OutputData = (UINT8) ((gBreakSet << 6) | (LcrParity << 3) | (LcrStop << 2) | LcrData); OutputData = (UINT8)((gBreakSet << 6) | (LcrParity << 3) | (LcrStop << 2) | LcrData);
IoWrite8 (gUartBase + LCR_OFFSET, OutputData); IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }

View File

@ -216,6 +216,7 @@ PcRtcInit (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock); EfiAcquireLock (&Global->RtcLock);
} }
// //
// Initialize RTC Register // Initialize RTC Register
// //
@ -254,8 +255,10 @@ PcRtcInit (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Get the Time/Date/Daylight Savings values. // Get the Time/Date/Daylight Savings values.
// //
@ -293,8 +296,8 @@ PcRtcInit (
&TimerVar &TimerVar
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Time.TimeZone = (INT16) TimerVar; Time.TimeZone = (INT16)TimerVar;
Time.Daylight = (UINT8) (TimerVar >> 16); Time.Daylight = (UINT8)(TimerVar >> 16);
} else { } else {
Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE; Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE;
Time.Daylight = 0; Time.Daylight = 0;
@ -307,6 +310,7 @@ PcRtcInit (
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Status = RtcTimeFieldsValid (&Time); Status = RtcTimeFieldsValid (&Time);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
// //
// Report Status Code to indicate that the RTC has bad date and time // Report Status Code to indicate that the RTC has bad date and time
@ -356,7 +360,7 @@ PcRtcInit (
Time.Year = PcdGet16 (PcdMinimalValidYear); Time.Year = PcdGet16 (PcdMinimalValidYear);
Time.Nanosecond = 0; Time.Nanosecond = 0;
Time.TimeZone = Global->SavedTimeZone; Time.TimeZone = Global->SavedTimeZone;
Time.Daylight = Global->Daylight;; Time.Daylight = Global->Daylight;
// //
// Acquire RTC Lock to make access to RTC atomic // Acquire RTC Lock to make access to RTC atomic
@ -364,6 +368,7 @@ PcRtcInit (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock); EfiAcquireLock (&Global->RtcLock);
} }
// //
// Wait for up to 0.1 seconds for the RTC to be updated // Wait for up to 0.1 seconds for the RTC to be updated
// //
@ -372,6 +377,7 @@ PcRtcInit (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -391,6 +397,7 @@ PcRtcInit (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -419,6 +426,7 @@ PcRtcInit (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -451,14 +459,15 @@ PcRtcGetTime (
// //
if (Time == NULL) { if (Time == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Acquire RTC Lock to make access to RTC atomic // Acquire RTC Lock to make access to RTC atomic
// //
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock); EfiAcquireLock (&Global->RtcLock);
} }
// //
// Wait for up to 0.1 seconds for the RTC to be updated // Wait for up to 0.1 seconds for the RTC to be updated
// //
@ -467,8 +476,10 @@ PcRtcGetTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return Status; return Status;
} }
// //
// Read Register B // Read Register B
// //
@ -504,6 +515,7 @@ PcRtcGetTime (
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Status = RtcTimeFieldsValid (Time); Status = RtcTimeFieldsValid (Time);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -551,6 +563,7 @@ PcRtcSetTime (
if (Time == NULL) { if (Time == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Make sure that the time fields are valid // Make sure that the time fields are valid
// //
@ -567,6 +580,7 @@ PcRtcSetTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock); EfiAcquireLock (&Global->RtcLock);
} }
// //
// Wait for up to 0.1 seconds for the RTC to be updated // Wait for up to 0.1 seconds for the RTC to be updated
// //
@ -575,6 +589,7 @@ PcRtcSetTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return Status; return Status;
} }
@ -594,7 +609,7 @@ PcRtcSetTime (
} }
} else { } else {
TimerVar = Time->Daylight; TimerVar = Time->Daylight;
TimerVar = (UINT32) ((TimerVar << 16) | (UINT16)(Time->TimeZone)); TimerVar = (UINT32)((TimerVar << 16) | (UINT16)(Time->TimeZone));
Status = EfiSetVariable ( Status = EfiSetVariable (
mTimeZoneVariableName, mTimeZoneVariableName,
&gEfiCallerIdGuid, &gEfiCallerIdGuid,
@ -608,6 +623,7 @@ PcRtcSetTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -622,7 +638,7 @@ PcRtcSetTime (
// Store the century value to RTC before converting to BCD format. // Store the century value to RTC before converting to BCD format.
// //
if (Global->CenturyRtcAddress != 0) { if (Global->CenturyRtcAddress != 0) {
RtcWrite (Global->CenturyRtcAddress, DecimalToBcd8 ((UINT8) (RtcTime.Year / 100))); RtcWrite (Global->CenturyRtcAddress, DecimalToBcd8 ((UINT8)(RtcTime.Year / 100)));
} }
ConvertEfiTimeToRtcTime (&RtcTime, RegisterB); ConvertEfiTimeToRtcTime (&RtcTime, RegisterB);
@ -632,7 +648,7 @@ PcRtcSetTime (
RtcWrite (RTC_ADDRESS_HOURS, RtcTime.Hour); RtcWrite (RTC_ADDRESS_HOURS, RtcTime.Hour);
RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH, RtcTime.Day); RtcWrite (RTC_ADDRESS_DAY_OF_THE_MONTH, RtcTime.Day);
RtcWrite (RTC_ADDRESS_MONTH, RtcTime.Month); RtcWrite (RTC_ADDRESS_MONTH, RtcTime.Month);
RtcWrite (RTC_ADDRESS_YEAR, (UINT8) RtcTime.Year); RtcWrite (RTC_ADDRESS_YEAR, (UINT8)RtcTime.Year);
// //
// Allow updates of the RTC registers // Allow updates of the RTC registers
@ -646,6 +662,7 @@ PcRtcSetTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
// //
// Set the variable that contains the TimeZone and Daylight fields // Set the variable that contains the TimeZone and Daylight fields
// //
@ -690,14 +707,15 @@ PcRtcGetWakeupTime (
// //
if ((Enabled == NULL) || (Pending == NULL) || (Time == NULL)) { if ((Enabled == NULL) || (Pending == NULL) || (Time == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Acquire RTC Lock to make access to RTC atomic // Acquire RTC Lock to make access to RTC atomic
// //
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock); EfiAcquireLock (&Global->RtcLock);
} }
// //
// Wait for up to 0.1 seconds for the RTC to be updated // Wait for up to 0.1 seconds for the RTC to be updated
// //
@ -706,8 +724,10 @@ PcRtcGetWakeupTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Read Register B and Register C // Read Register B and Register C
// //
@ -763,6 +783,7 @@ PcRtcGetWakeupTime (
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Status = RtcTimeFieldsValid (Time); Status = RtcTimeFieldsValid (Time);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -800,10 +821,10 @@ PcRtcSetWakeupTime (
ZeroMem (&RtcTime, sizeof (RtcTime)); ZeroMem (&RtcTime, sizeof (RtcTime));
if (Enable) { if (Enable) {
if (Time == NULL) { if (Time == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Make sure that the time fields are valid // Make sure that the time fields are valid
// //
@ -811,6 +832,7 @@ PcRtcSetWakeupTime (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Just support set alarm time within 24 hours // Just support set alarm time within 24 hours
// //
@ -819,21 +841,24 @@ PcRtcSetWakeupTime (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
if (!IsWithinOneDay (&RtcTime, Time)) { if (!IsWithinOneDay (&RtcTime, Time)) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
// //
// Make a local copy of the time and date // Make a local copy of the time and date
// //
CopyMem (&RtcTime, Time, sizeof (EFI_TIME)); CopyMem (&RtcTime, Time, sizeof (EFI_TIME));
} }
// //
// Acquire RTC Lock to make access to RTC atomic // Acquire RTC Lock to make access to RTC atomic
// //
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiAcquireLock (&Global->RtcLock); EfiAcquireLock (&Global->RtcLock);
} }
// //
// Wait for up to 0.1 seconds for the RTC to be updated // Wait for up to 0.1 seconds for the RTC to be updated
// //
@ -842,8 +867,10 @@ PcRtcSetWakeupTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Read Register B // Read Register B
// //
@ -879,6 +906,7 @@ PcRtcSetWakeupTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -897,10 +925,10 @@ PcRtcSetWakeupTime (
RtcWrite (RTC_ADDRESS_HOURS_ALARM, RtcTime.Hour); RtcWrite (RTC_ADDRESS_HOURS_ALARM, RtcTime.Hour);
RegisterB.Bits.Aie = 1; RegisterB.Bits.Aie = 1;
} else { } else {
RegisterB.Bits.Aie = 0; RegisterB.Bits.Aie = 0;
} }
// //
// Allow updates of the RTC registers // Allow updates of the RTC registers
// //
@ -913,10 +941,10 @@ PcRtcSetWakeupTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Checks an 8-bit BCD value, and converts to an 8-bit value if valid. Checks an 8-bit BCD value, and converts to an 8-bit value if valid.
@ -973,10 +1001,10 @@ ConvertRtcTimeToEfiTime (
IsPM = FALSE; IsPM = FALSE;
} }
Time->Hour = (UINT8) (Time->Hour & 0x7f); Time->Hour = (UINT8)(Time->Hour & 0x7f);
if (RegisterB.Bits.Dm == 0) { if (RegisterB.Bits.Dm == 0) {
Time->Year = CheckAndConvertBcd8ToDecimal8 ((UINT8) Time->Year); Time->Year = CheckAndConvertBcd8ToDecimal8 ((UINT8)Time->Year);
Time->Month = CheckAndConvertBcd8ToDecimal8 (Time->Month); Time->Month = CheckAndConvertBcd8ToDecimal8 (Time->Month);
Time->Day = CheckAndConvertBcd8ToDecimal8 (Time->Day); Time->Day = CheckAndConvertBcd8ToDecimal8 (Time->Day);
Time->Hour = CheckAndConvertBcd8ToDecimal8 (Time->Hour); Time->Hour = CheckAndConvertBcd8ToDecimal8 (Time->Hour);
@ -984,8 +1012,9 @@ ConvertRtcTimeToEfiTime (
Time->Second = CheckAndConvertBcd8ToDecimal8 (Time->Second); Time->Second = CheckAndConvertBcd8ToDecimal8 (Time->Second);
} }
if (Time->Year == 0xff || Time->Month == 0xff || Time->Day == 0xff || if ((Time->Year == 0xff) || (Time->Month == 0xff) || (Time->Day == 0xff) ||
Time->Hour == 0xff || Time->Minute == 0xff || Time->Second == 0xff) { (Time->Hour == 0xff) || (Time->Minute == 0xff) || (Time->Second == 0xff))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -994,21 +1023,22 @@ ConvertRtcTimeToEfiTime (
// Century is 19 if RTC year >= 70, // Century is 19 if RTC year >= 70,
// Century is 20 otherwise. // Century is 20 otherwise.
// //
Century = (UINT8) (PcdGet16 (PcdMinimalValidYear) / 100); Century = (UINT8)(PcdGet16 (PcdMinimalValidYear) / 100);
if (Time->Year < PcdGet16 (PcdMinimalValidYear) % 100) { if (Time->Year < PcdGet16 (PcdMinimalValidYear) % 100) {
Century++; Century++;
} }
Time->Year = (UINT16) (Century * 100 + Time->Year);
Time->Year = (UINT16)(Century * 100 + Time->Year);
// //
// If time is in 12 hour format, convert it to 24 hour format // If time is in 12 hour format, convert it to 24 hour format
// //
if (RegisterB.Bits.Mil == 0) { if (RegisterB.Bits.Mil == 0) {
if (IsPM && Time->Hour < 12) { if (IsPM && (Time->Hour < 12)) {
Time->Hour = (UINT8) (Time->Hour + 12); Time->Hour = (UINT8)(Time->Hour + 12);
} }
if (!IsPM && Time->Hour == 12) { if (!IsPM && (Time->Hour == 12)) {
Time->Hour = 0; Time->Hour = 0;
} }
} }
@ -1042,6 +1072,7 @@ RtcWaitToUpdate (
if (RegisterD.Bits.Vrt == 0) { if (RegisterD.Bits.Vrt == 0) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Wait for up to 0.1 seconds for the RTC to be ready. // Wait for up to 0.1 seconds for the RTC to be ready.
// //
@ -1054,7 +1085,7 @@ RtcWaitToUpdate (
} }
RegisterD.Data = RtcRead (RTC_ADDRESS_REGISTER_D); RegisterD.Data = RtcRead (RTC_ADDRESS_REGISTER_D);
if (Timeout == 0 || RegisterD.Bits.Vrt == 0) { if ((Timeout == 0) || (RegisterD.Bits.Vrt == 0)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -1075,17 +1106,18 @@ RtcTimeFieldsValid (
IN EFI_TIME *Time IN EFI_TIME *Time
) )
{ {
if (Time->Year < PcdGet16 (PcdMinimalValidYear) || if ((Time->Year < PcdGet16 (PcdMinimalValidYear)) ||
Time->Year > PcdGet16 (PcdMaximalValidYear) || (Time->Year > PcdGet16 (PcdMaximalValidYear)) ||
Time->Month < 1 || (Time->Month < 1) ||
Time->Month > 12 || (Time->Month > 12) ||
(!DayValid (Time)) || (!DayValid (Time)) ||
Time->Hour > 23 || (Time->Hour > 23) ||
Time->Minute > 59 || (Time->Minute > 59) ||
Time->Second > 59 || (Time->Second > 59) ||
Time->Nanosecond > 999999999 || (Time->Nanosecond > 999999999) ||
(!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) || (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||
((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) != 0)) { ((Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) != 0))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -1108,12 +1140,13 @@ DayValid (
// //
// The validity of Time->Month field should be checked before // The validity of Time->Month field should be checked before
// //
ASSERT (Time->Month >=1); ASSERT (Time->Month >= 1);
ASSERT (Time->Month <=12); ASSERT (Time->Month <= 12);
if (Time->Day < 1 || if ((Time->Day < 1) ||
Time->Day > mDayOfMonth[Time->Month - 1] || (Time->Day > mDayOfMonth[Time->Month - 1]) ||
(Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28)) ((Time->Month == 2) && (!IsLeapYear (Time) && (Time->Day > 28)))
) { )
{
return FALSE; return FALSE;
} }
@ -1177,29 +1210,31 @@ ConvertEfiTimeToRtcTime (
} }
if (Time->Hour >= 13) { if (Time->Hour >= 13) {
Time->Hour = (UINT8) (Time->Hour - 12); Time->Hour = (UINT8)(Time->Hour - 12);
} else if (Time->Hour == 0) { } else if (Time->Hour == 0) {
Time->Hour = 12; Time->Hour = 12;
} }
} }
// //
// Set the Time/Date values. // Set the Time/Date values.
// //
Time->Year = (UINT16) (Time->Year % 100); Time->Year = (UINT16)(Time->Year % 100);
if (RegisterB.Bits.Dm == 0) { if (RegisterB.Bits.Dm == 0) {
Time->Year = DecimalToBcd8 ((UINT8) Time->Year); Time->Year = DecimalToBcd8 ((UINT8)Time->Year);
Time->Month = DecimalToBcd8 (Time->Month); Time->Month = DecimalToBcd8 (Time->Month);
Time->Day = DecimalToBcd8 (Time->Day); Time->Day = DecimalToBcd8 (Time->Day);
Time->Hour = DecimalToBcd8 (Time->Hour); Time->Hour = DecimalToBcd8 (Time->Hour);
Time->Minute = DecimalToBcd8 (Time->Minute); Time->Minute = DecimalToBcd8 (Time->Minute);
Time->Second = DecimalToBcd8 (Time->Second); Time->Second = DecimalToBcd8 (Time->Second);
} }
// //
// If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field. // If we are in 12 hour mode and PM is set, then set bit 7 of the Hour field.
// //
if (RegisterB.Bits.Mil == 0 && IsPM) { if ((RegisterB.Bits.Mil == 0) && IsPM) {
Time->Hour = (UINT8) (Time->Hour | 0x80); Time->Hour = (UINT8)(Time->Hour | 0x80);
} }
} }
@ -1223,7 +1258,8 @@ CompareHMS (
{ {
if ((From->Hour > To->Hour) || if ((From->Hour > To->Hour) ||
((From->Hour == To->Hour) && (From->Minute > To->Minute)) || ((From->Hour == To->Hour) && (From->Minute > To->Minute)) ||
((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second > To->Second))) { ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second > To->Second)))
{
return 1; return 1;
} else if ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second == To->Second)) { } else if ((From->Hour == To->Hour) && (From->Minute == To->Minute) && (From->Second == To->Second)) {
return 0; return 0;
@ -1254,29 +1290,29 @@ IsWithinOneDay (
// //
// The validity of From->Month field should be checked before // The validity of From->Month field should be checked before
// //
ASSERT (From->Month >=1); ASSERT (From->Month >= 1);
ASSERT (From->Month <=12); ASSERT (From->Month <= 12);
if (From->Year == To->Year) { if (From->Year == To->Year) {
if (From->Month == To->Month) { if (From->Month == To->Month) {
if ((From->Day + 1) == To->Day) { if ((From->Day + 1) == To->Day) {
if ((CompareHMS(From, To) >= 0)) { if ((CompareHMS (From, To) >= 0)) {
Adjacent = TRUE; Adjacent = TRUE;
} }
} else if (From->Day == To->Day) { } else if (From->Day == To->Day) {
if ((CompareHMS(From, To) <= 0)) { if ((CompareHMS (From, To) <= 0)) {
Adjacent = TRUE; Adjacent = TRUE;
} }
} }
} else if (((From->Month + 1) == To->Month) && (To->Day == 1)) { } else if (((From->Month + 1) == To->Month) && (To->Day == 1)) {
if ((From->Month == 2) && !IsLeapYear(From)) { if ((From->Month == 2) && !IsLeapYear (From)) {
if (From->Day == 28) { if (From->Day == 28) {
if ((CompareHMS(From, To) >= 0)) { if ((CompareHMS (From, To) >= 0)) {
Adjacent = TRUE; Adjacent = TRUE;
} }
} }
} else if (From->Day == mDayOfMonth[From->Month - 1]) { } else if (From->Day == mDayOfMonth[From->Month - 1]) {
if ((CompareHMS(From, To) >= 0)) { if ((CompareHMS (From, To) >= 0)) {
Adjacent = TRUE; Adjacent = TRUE;
} }
} }
@ -1285,8 +1321,9 @@ IsWithinOneDay (
(From->Month == 12) && (From->Month == 12) &&
(From->Day == 31) && (From->Day == 31) &&
(To->Month == 1) && (To->Month == 1) &&
(To->Day == 1)) { (To->Day == 1))
if ((CompareHMS(From, To) >= 0)) { {
if ((CompareHMS (From, To) >= 0)) {
Adjacent = TRUE; Adjacent = TRUE;
} }
} }
@ -1306,13 +1343,14 @@ GetCenturyRtcAddress (
{ {
EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt; EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;
Fadt = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *) EfiLocateFirstAcpiTable ( Fadt = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *)EfiLocateFirstAcpiTable (
EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
); );
if ((Fadt != NULL) && if ((Fadt != NULL) &&
(Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80) (Fadt->Century > RTC_ADDRESS_REGISTER_D) && (Fadt->Century < 0x80)
) { )
{
return Fadt->Century; return Fadt->Century;
} else { } else {
return 0; return 0;
@ -1346,7 +1384,7 @@ PcRtcAcpiTableChangeCallback (
mModuleGlobal.CenturyRtcAddress = CenturyRtcAddress; mModuleGlobal.CenturyRtcAddress = CenturyRtcAddress;
Status = PcRtcGetTime (&Time, NULL, &mModuleGlobal); Status = PcRtcGetTime (&Time, NULL, &mModuleGlobal);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Century = (UINT8) (Time.Year / 100); Century = (UINT8)(Time.Year / 100);
Century = DecimalToBcd8 (Century); Century = DecimalToBcd8 (Century);
DEBUG ((DEBUG_INFO, "PcRtc: Write 0x%x to CMOS location 0x%x\n", Century, mModuleGlobal.CenturyRtcAddress)); DEBUG ((DEBUG_INFO, "PcRtc: Write 0x%x to CMOS location 0x%x\n", Century, mModuleGlobal.CenturyRtcAddress));
RtcWrite (mModuleGlobal.CenturyRtcAddress, Century); RtcWrite (mModuleGlobal.CenturyRtcAddress, Century);

View File

@ -8,11 +8,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef _RTC_H_ #ifndef _RTC_H_
#define _RTC_H_ #define _RTC_H_
#include <Uefi.h> #include <Uefi.h>
#include <Guid/Acpi.h> #include <Guid/Acpi.h>
@ -282,7 +280,6 @@ ConvertEfiTimeToRtcTime (
IN RTC_REGISTER_B RegisterB IN RTC_REGISTER_B RegisterB
); );
/** /**
Converts time read from RTC to EFI_TIME format defined by UEFI spec. Converts time read from RTC to EFI_TIME format defined by UEFI spec.
@ -371,4 +368,5 @@ PcRtcAcpiTableChangeCallback (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
); );
#endif #endif

View File

@ -87,7 +87,6 @@ PcRtcEfiGetWakeupTime (
return PcRtcGetWakeupTime (Enabled, Pending, Time, &mModuleGlobal); return PcRtcGetWakeupTime (Enabled, Pending, Time, &mModuleGlobal);
} }
/** /**
Sets the system wakeup alarm clock time. Sets the system wakeup alarm clock time.
@ -132,8 +131,8 @@ LibRtcVirtualNotifyEvent (
// stored physical addresses to virtual address. After the OS transitions to // stored physical addresses to virtual address. After the OS transitions to
// calling in virtual mode, all future runtime calls will be made in virtual // calling in virtual mode, all future runtime calls will be made in virtual
// mode. // mode.
EfiConvertPointer (0x0, (VOID**)&mRtcIndexRegister); EfiConvertPointer (0x0, (VOID **)&mRtcIndexRegister);
EfiConvertPointer (0x0, (VOID**)&mRtcTargetRegister); EfiConvertPointer (0x0, (VOID **)&mRtcTargetRegister);
} }
/** /**