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

@ -21,16 +21,16 @@ 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"
}; };
// //
/// Driver Name Strings /// Driver Name Strings
/// ///
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIdeControllerDriverNameTable[] = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIdeControllerDriverNameTable[] = {
{ {
"eng;en", "eng;en",
(CHAR16 *)L"IDE Controller Init Driver" (CHAR16 *)L"IDE Controller Init Driver"
@ -44,7 +44,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIdeControllerDriverNameT
/// ///
/// Controller Name Strings /// Controller Name Strings
/// ///
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIdeControllerControllerNameTable[] = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIdeControllerControllerNameTable[] = {
{ {
"eng;en", "eng;en",
(CHAR16 *)L"PCAT IDE Controller" (CHAR16 *)L"PCAT IDE Controller"
@ -136,14 +136,14 @@ IdeControllerComponentNameGetDriverName (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeControllerComponentNameGetControllerName ( IdeControllerComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
// //
// Make sure this driver is currently managing ControllHandle // Make sure this driver is currently managing ControllHandle
@ -162,10 +162,10 @@ IdeControllerComponentNameGetControllerName (
} }
return LookupUnicodeString2 ( return LookupUnicodeString2 (
Language, Language,
This->SupportedLanguages, This->SupportedLanguages,
mIdeControllerControllerNameTable, mIdeControllerControllerNameTable,
ControllerName, ControllerName,
(BOOLEAN)(This == &gIdeControllerComponentName) (BOOLEAN)(This == &gIdeControllerComponentName)
); );
} }

View File

@ -13,7 +13,7 @@
/// ///
/// EFI_DRIVER_BINDING_PROTOCOL instance /// EFI_DRIVER_BINDING_PROTOCOL instance
/// ///
EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding = { EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding = {
IdeControllerSupported, IdeControllerSupported,
IdeControllerStart, IdeControllerStart,
IdeControllerStop, IdeControllerStop,
@ -73,8 +73,8 @@ EFI_ATA_COLLECTIVE_MODE gEfiAtaCollectiveModeTemplate = {
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InitializeIdeControllerDriver ( InitializeIdeControllerDriver (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -109,15 +109,15 @@ InitializeIdeControllerDriver (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeControllerSupported ( IdeControllerSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller, IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT8 PciClass; UINT8 PciClass;
UINT8 PciSubClass; UINT8 PciSubClass;
// //
// Attempt to Open PCI I/O Protocol // Attempt to Open PCI I/O Protocol
@ -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
@ -169,11 +169,11 @@ IdeControllerSupported (
Done: Done:
gBS->CloseProtocol ( gBS->CloseProtocol (
Controller, Controller,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
This->DriverBindingHandle, This->DriverBindingHandle,
Controller Controller
); );
return Status; return Status;
} }
@ -194,9 +194,9 @@ Done:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeControllerStart ( IdeControllerStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller, IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -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
); );
} }
@ -249,10 +250,10 @@ IdeControllerStart (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeControllerStop ( IdeControllerStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller, IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren, IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer IN EFI_HANDLE *ChildHandleBuffer
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -264,13 +265,13 @@ 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
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
// //
@ -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.
@ -345,10 +348,10 @@ IdeControllerStop (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeInitGetChannelInfo ( IdeInitGetChannelInfo (
IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
IN UINT8 Channel, IN UINT8 Channel,
OUT BOOLEAN *Enabled, OUT BOOLEAN *Enabled,
OUT UINT8 *MaxDevices OUT UINT8 *MaxDevices
) )
{ {
// //
@ -391,9 +394,9 @@ IdeInitGetChannelInfo (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeInitNotifyPhase ( IdeInitNotifyPhase (
IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase, IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,
IN UINT8 Channel IN UINT8 Channel
) )
{ {
return EFI_SUCCESS; return EFI_SUCCESS;
@ -441,10 +444,10 @@ IdeInitNotifyPhase (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeInitSubmitData ( IdeInitSubmitData (
IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
IN UINT8 Channel, IN UINT8 Channel,
IN UINT8 Device, IN UINT8 Device,
IN EFI_IDENTIFY_DATA *IdentifyData IN EFI_IDENTIFY_DATA *IdentifyData
) )
{ {
return EFI_SUCCESS; return EFI_SUCCESS;
@ -493,10 +496,10 @@ IdeInitSubmitData (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeInitDisqualifyMode ( IdeInitDisqualifyMode (
IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
IN UINT8 Channel, IN UINT8 Channel,
IN UINT8 Device, IN UINT8 Device,
IN EFI_ATA_COLLECTIVE_MODE *BadModes IN EFI_ATA_COLLECTIVE_MODE *BadModes
) )
{ {
return EFI_SUCCESS; return EFI_SUCCESS;
@ -559,13 +562,13 @@ IdeInitDisqualifyMode (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeInitCalculateMode ( IdeInitCalculateMode (
IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
IN UINT8 Channel, IN UINT8 Channel,
IN UINT8 Device, IN UINT8 Device,
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;
} }
@ -603,10 +606,10 @@ IdeInitCalculateMode (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeInitSetTiming ( IdeInitSetTiming (
IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
IN UINT8 Channel, IN UINT8 Channel,
IN UINT8 Device, IN UINT8 Device,
IN EFI_ATA_COLLECTIVE_MODE *Modes IN EFI_ATA_COLLECTIVE_MODE *Modes
) )
{ {
return EFI_SUCCESS; return EFI_SUCCESS;

View File

@ -26,24 +26,25 @@
// //
// Global Variables definitions // Global Variables definitions
// //
extern EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding; extern EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gIdeControllerComponentName; extern EFI_COMPONENT_NAME_PROTOCOL gIdeControllerComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerComponentName2; extern EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerComponentName2;
/// ///
/// Supports 2 channel max /// Supports 2 channel max
/// ///
#define ICH_IDE_MAX_CHANNEL 0x02 #define ICH_IDE_MAX_CHANNEL 0x02
/// ///
/// Supports 2 devices max /// Supports 2 devices max
/// ///
#define ICH_IDE_MAX_DEVICES 0x02 #define ICH_IDE_MAX_DEVICES 0x02
#define ICH_IDE_ENUMER_ALL FALSE #define ICH_IDE_ENUMER_ALL FALSE
// //
// Driver binding functions declaration // Driver binding functions declaration
// //
/** /**
Register Driver Binding protocol for this driver. Register Driver Binding protocol for this driver.
@ -58,9 +59,9 @@ extern EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerComponentName2;
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeControllerSupported ( IdeControllerSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller, IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
) )
; ;
@ -80,9 +81,9 @@ IdeControllerSupported (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeControllerStart ( IdeControllerStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller, IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
) )
; ;
@ -100,16 +101,17 @@ IdeControllerStart (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeControllerStop ( IdeControllerStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller, IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren, IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer IN EFI_HANDLE *ChildHandleBuffer
) )
; ;
// //
// 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.
@ -149,10 +151,10 @@ IdeControllerStop (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeInitGetChannelInfo ( IdeInitGetChannelInfo (
IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
IN UINT8 Channel, IN UINT8 Channel,
OUT BOOLEAN *Enabled, OUT BOOLEAN *Enabled,
OUT UINT8 *MaxDevices OUT UINT8 *MaxDevices
) )
; ;
@ -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.
@ -461,11 +464,11 @@ IdeControllerComponentNameGetDriverName (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
IdeControllerComponentNameGetControllerName ( IdeControllerComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
) )
; ;

View File

@ -120,8 +120,8 @@ TimerDriverSetTimerPeriod (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TimerDriverGetTimerPeriod ( TimerDriverGetTimerPeriod (
IN EFI_TIMER_ARCH_PROTOCOL *This, IN EFI_TIMER_ARCH_PROTOCOL *This,
OUT UINT64 *TimerPeriod OUT UINT64 *TimerPeriod
); );
/** /**
@ -149,7 +149,7 @@ TimerDriverGenerateSoftInterrupt (
/// ///
/// The handle onto which the Timer Architectural Protocol will be installed. /// The handle onto which the Timer Architectural Protocol will be installed.
/// ///
EFI_HANDLE mTimerHandle = NULL; EFI_HANDLE mTimerHandle = NULL;
/// ///
/// The Timer Architectural Protocol that this driver produces. /// The Timer Architectural Protocol that this driver produces.
@ -288,8 +288,8 @@ HpetEnable (
VOID VOID
EFIAPI EFIAPI
TimerInterruptHandler ( TimerInterruptHandler (
IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_SYSTEM_CONTEXT SystemContext IN EFI_SYSTEM_CONTEXT SystemContext
) )
{ {
UINT64 MainCounter; UINT64 MainCounter;
@ -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
@ -642,8 +648,8 @@ TimerDriverSetTimerPeriod (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TimerDriverGetTimerPeriod ( TimerDriverGetTimerPeriod (
IN EFI_TIMER_ARCH_PROTOCOL *This, IN EFI_TIMER_ARCH_PROTOCOL *This,
OUT UINT64 *TimerPeriod OUT UINT64 *TimerPeriod
) )
{ {
if (TimerPeriod == NULL) { if (TimerPeriod == NULL) {
@ -757,10 +763,10 @@ TimerDriverInitialize (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN TimerIndex; UINTN TimerIndex;
UINTN MsiTimerIndex; UINTN MsiTimerIndex;
HPET_TIMER_MSI_ROUTE_REGISTER HpetTimerMsiRoute; HPET_TIMER_MSI_ROUTE_REGISTER HpetTimerMsiRoute;
DEBUG ((DEBUG_INFO, "Init HPET Timer Driver\n")); DEBUG ((DEBUG_INFO, "Init HPET Timer Driver\n"));
@ -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;
} }
@ -801,17 +807,18 @@ TimerDriverInitialize (
// Dump HPET Configuration Information // Dump HPET Configuration Information
// //
DEBUG_CODE_BEGIN (); DEBUG_CODE_BEGIN ();
DEBUG ((DEBUG_INFO, "HPET Base Address = 0x%08x\n", PcdGet32 (PcdHpetBaseAddress))); DEBUG ((DEBUG_INFO, "HPET Base Address = 0x%08x\n", PcdGet32 (PcdHpetBaseAddress)));
DEBUG ((DEBUG_INFO, " HPET_GENERAL_CAPABILITIES_ID = 0x%016lx\n", mHpetGeneralCapabilities)); DEBUG ((DEBUG_INFO, " HPET_GENERAL_CAPABILITIES_ID = 0x%016lx\n", mHpetGeneralCapabilities));
DEBUG ((DEBUG_INFO, " HPET_GENERAL_CONFIGURATION = 0x%016lx\n", mHpetGeneralConfiguration.Uint64)); DEBUG ((DEBUG_INFO, " HPET_GENERAL_CONFIGURATION = 0x%016lx\n", mHpetGeneralConfiguration.Uint64));
DEBUG ((DEBUG_INFO, " HPET_GENERAL_INTERRUPT_STATUS = 0x%016lx\n", HpetRead (HPET_GENERAL_INTERRUPT_STATUS_OFFSET))); DEBUG ((DEBUG_INFO, " HPET_GENERAL_INTERRUPT_STATUS = 0x%016lx\n", HpetRead (HPET_GENERAL_INTERRUPT_STATUS_OFFSET)));
DEBUG ((DEBUG_INFO, " HPET_MAIN_COUNTER = 0x%016lx\n", HpetRead (HPET_MAIN_COUNTER_OFFSET))); DEBUG ((DEBUG_INFO, " HPET_MAIN_COUNTER = 0x%016lx\n", HpetRead (HPET_MAIN_COUNTER_OFFSET)));
DEBUG ((DEBUG_INFO, " HPET Main Counter Period = %d (fs)\n", mHpetGeneralCapabilities.Bits.CounterClockPeriod)); DEBUG ((DEBUG_INFO, " HPET Main Counter Period = %d (fs)\n", mHpetGeneralCapabilities.Bits.CounterClockPeriod));
for (TimerIndex = 0; TimerIndex <= mHpetGeneralCapabilities.Bits.NumberOfTimers; TimerIndex++) { for (TimerIndex = 0; TimerIndex <= mHpetGeneralCapabilities.Bits.NumberOfTimers; TimerIndex++) {
DEBUG ((DEBUG_INFO, " HPET_TIMER%d_CONFIGURATION = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + TimerIndex * HPET_TIMER_STRIDE))); DEBUG ((DEBUG_INFO, " HPET_TIMER%d_CONFIGURATION = 0x%016lx\n", TimerIndex, HpetRead (HPET_TIMER_CONFIGURATION_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_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,11 +864,11 @@ 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
// //
mTimerIndex = MsiTimerIndex; mTimerIndex = MsiTimerIndex;
// //
// Program MSI Address and MSI Data values in the selected HPET Timer // Program MSI Address and MSI Data values in the selected HPET Timer
@ -874,7 +881,7 @@ TimerDriverInitialize (
// Read the HPET Timer Capabilities and Configuration register and initialize for MSI mode // Read the HPET Timer Capabilities and Configuration register and initialize for MSI mode
// Clear LevelTriggeredInterrupt to use edge triggered interrupts when in MSI mode // Clear LevelTriggeredInterrupt to use edge triggered interrupts when in MSI mode
// //
mTimerConfiguration.Uint64 = HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE); mTimerConfiguration.Uint64 = HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);
mTimerConfiguration.Bits.LevelTriggeredInterrupt = 0; mTimerConfiguration.Bits.LevelTriggeredInterrupt = 0;
} else { } else {
// //
@ -898,7 +905,7 @@ TimerDriverInitialize (
// Set LevelTriggeredInterrupt to use level triggered interrupts when in I/O APIC mode // Set LevelTriggeredInterrupt to use level triggered interrupts when in I/O APIC mode
// Set InterruptRoute field based in mTimerIrq // Set InterruptRoute field based in mTimerIrq
// //
mTimerConfiguration.Uint64 = HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE); mTimerConfiguration.Uint64 = HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE);
mTimerConfiguration.Bits.LevelTriggeredInterrupt = 1; mTimerConfiguration.Bits.LevelTriggeredInterrupt = 1;
mTimerConfiguration.Bits.InterruptRoute = mTimerIrq; mTimerConfiguration.Bits.InterruptRoute = mTimerIrq;
} }
@ -959,24 +966,27 @@ 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 Counter Mask = 0x%016lx\n", mCounterMask)); DEBUG ((DEBUG_INFO, "HPET Interrupt Vector = 0x%02x\n", PcdGet8 (PcdHpetLocalApicVector)));
DEBUG ((DEBUG_INFO, "HPET Timer Period = %d\n", mTimerPeriod)); DEBUG ((DEBUG_INFO, "HPET Counter Mask = 0x%016lx\n", mCounterMask));
DEBUG ((DEBUG_INFO, "HPET Timer Count = 0x%016lx\n", mTimerCount)); DEBUG ((DEBUG_INFO, "HPET Timer Period = %d\n", mTimerPeriod));
DEBUG ((DEBUG_INFO, "HPET_TIMER%d_CONFIGURATION = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE))); DEBUG ((DEBUG_INFO, "HPET Timer Count = 0x%016lx\n", mTimerCount));
DEBUG ((DEBUG_INFO, "HPET_TIMER%d_COMPARATOR = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE))); DEBUG ((DEBUG_INFO, "HPET_TIMER%d_CONFIGURATION = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_CONFIGURATION_OFFSET + mTimerIndex * HPET_TIMER_STRIDE)));
DEBUG ((DEBUG_INFO, "HPET_TIMER%d_MSI_ROUTE = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_MSI_ROUTE_OFFSET + mTimerIndex * HPET_TIMER_STRIDE))); DEBUG ((DEBUG_INFO, "HPET_TIMER%d_COMPARATOR = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_COMPARATOR_OFFSET + mTimerIndex * HPET_TIMER_STRIDE)));
DEBUG ((DEBUG_INFO, "HPET_TIMER%d_MSI_ROUTE = 0x%016lx\n", mTimerIndex, HpetRead (HPET_TIMER_MSI_ROUTE_OFFSET + mTimerIndex * HPET_TIMER_STRIDE)));
//
// Wait for a few timer interrupts to fire before continuing
//
while (mNumTicks < 10) {
}
//
// Wait for a few timer interrupts to fire before continuing
//
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

@ -14,6 +14,6 @@
0x326ae723, 0xae32, 0x4589, { 0x98, 0xb8, 0xca, 0xc2, 0x3c, 0xdc, 0xc1, 0xb1 } \ 0x326ae723, 0xae32, 0x4589, { 0x98, 0xb8, 0xca, 0xc2, 0x3c, 0xdc, 0xc1, 0xb1 } \
} }
extern EFI_GUID gPcAtChipsetPkgTokenSpaceGuid; extern EFI_GUID gPcAtChipsetPkgTokenSpaceGuid;
#endif #endif

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

@ -20,15 +20,15 @@
/// ///
/// HPET Timer Register Offsets /// HPET Timer Register Offsets
/// ///
#define HPET_MAIN_COUNTER_OFFSET 0x0F0 #define HPET_MAIN_COUNTER_OFFSET 0x0F0
#define HPET_TIMER_CONFIGURATION_OFFSET 0x100 #define HPET_TIMER_CONFIGURATION_OFFSET 0x100
#define HPET_TIMER_COMPARATOR_OFFSET 0x108 #define HPET_TIMER_COMPARATOR_OFFSET 0x108
#define HPET_TIMER_MSI_ROUTE_OFFSET 0x110 #define HPET_TIMER_MSI_ROUTE_OFFSET 0x110
/// ///
/// Stride between sets of HPET Timer Registers /// Stride between sets of HPET Timer Registers
/// ///
#define HPET_TIMER_STRIDE 0x20 #define HPET_TIMER_STRIDE 0x20
#pragma pack(1) #pragma pack(1)
@ -37,15 +37,15 @@
/// ///
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,12 +53,12 @@ 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,22 +66,22 @@ 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;
} HPET_TIMER_CONFIGURATION_REGISTER; } HPET_TIMER_CONFIGURATION_REGISTER;
/// ///
@ -89,10 +89,10 @@ 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;
#pragma pack() #pragma pack()

View File

@ -37,42 +37,42 @@
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;
UINT32 High; UINT32 High;
} Uint32; } Uint32;
UINT64 Uint64; UINT64 Uint64;
} IO_APIC_REDIRECTION_TABLE_ENTRY; } IO_APIC_REDIRECTION_TABLE_ENTRY;
#pragma pack() #pragma pack()

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.
@ -45,11 +47,11 @@ AcpiTimerLibConstructor (
VOID VOID
) )
{ {
UINTN Bus; UINTN Bus;
UINTN Device; UINTN Device;
UINTN Function; UINTN Function;
UINTN EnableRegister; UINTN EnableRegister;
UINT8 EnableMask; UINT8 EnableMask;
// //
// ASSERT for the invalid PCD values. They must be configured to the real value. // 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 for the invalid PCD values. They must be configured to the real value.
// //
ASSERT (PcdGet8 (PcdAcpiIoPciDeviceNumber) != 0xFF); ASSERT (PcdGet8 (PcdAcpiIoPciDeviceNumber) != 0xFF);
ASSERT (PcdGet8 (PcdAcpiIoPciFunctionNumber) != 0xFF); ASSERT (PcdGet8 (PcdAcpiIoPciFunctionNumber) != 0xFF);
ASSERT (PcdGet16 (PcdAcpiIoPciEnableRegisterOffset) != 0xFFFF); ASSERT (PcdGet16 (PcdAcpiIoPciEnableRegisterOffset) != 0xFFFF);
// //
// Retrieve the PCD values for the PCI configuration space required to program the ACPI I/O Port Base Address // Retrieve the PCD values for the PCI configuration space required to program the ACPI I/O Port Base Address
// //
Bus = PcdGet8 (PcdAcpiIoPciBusNumber); Bus = PcdGet8 (PcdAcpiIoPciBusNumber);
Device = PcdGet8 (PcdAcpiIoPciDeviceNumber); Device = PcdGet8 (PcdAcpiIoPciDeviceNumber);
Function = PcdGet8 (PcdAcpiIoPciFunctionNumber); Function = PcdGet8 (PcdAcpiIoPciFunctionNumber);
EnableRegister = PcdGet16 (PcdAcpiIoPciEnableRegisterOffset); 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. // 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 // value other than PcdAcpiIoPortBaseAddress
// //
if (PcdGet16 (PcdAcpiIoPciBarRegisterOffset) != 0x0000) { if (PcdGet16 (PcdAcpiIoPciBarRegisterOffset) != 0x0000) {
Port = PciRead16 (PCI_LIB_ADDRESS ( Port = PciRead16 (
PcdGet8 (PcdAcpiIoPciBusNumber), PCI_LIB_ADDRESS (
PcdGet8 (PcdAcpiIoPciDeviceNumber), PcdGet8 (PcdAcpiIoPciBusNumber),
PcdGet8 (PcdAcpiIoPciFunctionNumber), PcdGet8 (PcdAcpiIoPciDeviceNumber),
PcdGet16 (PcdAcpiIoPciBarRegisterOffset) PcdGet8 (PcdAcpiIoPciFunctionNumber),
)); PcdGet16 (PcdAcpiIoPciBarRegisterOffset)
)
);
} }
return (Port & PcdGet16 (PcdAcpiIoPortBaseAddressMask)) + PcdGet16 (PcdAcpiPm1TmrOffset); return (Port & PcdGet16 (PcdAcpiIoPortBaseAddressMask)) + PcdGet16 (PcdAcpiPm1TmrOffset);
@ -147,9 +151,9 @@ InternalAcpiDelay (
IN UINT32 Delay IN UINT32 Delay
) )
{ {
UINT16 Port; UINT16 Port;
UINT32 Ticks; UINT32 Ticks;
UINT32 Times; UINT32 Times;
Port = InternalAcpiGetAcpiTimerIoPort (); Port = InternalAcpiGetAcpiTimerIoPort ();
Times = Delay >> 22; Times = Delay >> 22;
@ -285,6 +289,7 @@ GetPerformanceCounterProperties (
if (EndValue != NULL) { if (EndValue != NULL) {
*EndValue = 0xffffffffffffffffULL; *EndValue = 0xffffffffffffffffULL;
} }
return InternalGetPerformanceCounterFrequency (); return InternalGetPerformanceCounterFrequency ();
} }
@ -324,9 +329,9 @@ GetTimeInNanoSecond (
// Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34, // 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. // 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;
@ -352,12 +357,12 @@ InternalCalculateTscFrequency (
VOID VOID
) )
{ {
UINT64 StartTSC; UINT64 StartTSC;
UINT64 EndTSC; UINT64 EndTSC;
UINT16 TimerAddr; UINT16 TimerAddr;
UINT32 Ticks; UINT32 Ticks;
UINT64 TscFrequency; UINT64 TscFrequency;
BOOLEAN InterruptState; BOOLEAN InterruptState;
InterruptState = SaveAndDisableInterrupts (); InterruptState = SaveAndDisableInterrupts ();
@ -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

@ -11,7 +11,7 @@
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/HobLib.h> #include <Library/HobLib.h>
extern GUID mFrequencyHobGuid; extern GUID mFrequencyHobGuid;
/** /**
The constructor function enables ACPI IO space. The constructor function enables ACPI IO space.
@ -66,7 +66,7 @@ InternalGetPerformanceCounterFrequency (
VOID VOID
) )
{ {
return mPerformanceCounterFrequency; return mPerformanceCounterFrequency;
} }
/** /**
@ -80,7 +80,7 @@ CommonAcpiTimerLibConstructor (
VOID VOID
) )
{ {
EFI_HOB_GUID_TYPE *GuidHob; EFI_HOB_GUID_TYPE *GuidHob;
// //
// Enable ACPI IO space. // Enable ACPI IO space.
@ -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

@ -12,7 +12,7 @@
#include <Library/HobLib.h> #include <Library/HobLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
extern GUID mFrequencyHobGuid; extern GUID mFrequencyHobGuid;
/** /**
Calculate TSC frequency. Calculate TSC frequency.
@ -47,18 +47,18 @@ InternalGetPerformanceCounterFrequency (
VOID VOID
) )
{ {
UINT64 *PerformanceCounterFrequency; UINT64 *PerformanceCounterFrequency;
EFI_HOB_GUID_TYPE *GuidHob; EFI_HOB_GUID_TYPE *GuidHob;
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

@ -86,7 +86,7 @@ IoApicEnableInterrupt (
ASSERT (Irq <= Version.Bits.MaximumRedirectionEntry); ASSERT (Irq <= Version.Bits.MaximumRedirectionEntry);
Entry.Uint32.Low = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2); Entry.Uint32.Low = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2);
Entry.Bits.Mask = Enable ? 0 : 1; Entry.Bits.Mask = Enable ? 0 : 1;
IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2, Entry.Uint32.Low); IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2, Entry.Uint32.Low);
} }
@ -137,7 +137,7 @@ IoApicConfigureInterrupt (
ASSERT (Vector <= 0xFF); ASSERT (Vector <= 0xFF);
ASSERT (DeliveryMode < 8 && DeliveryMode != 6 && DeliveryMode != 3); ASSERT (DeliveryMode < 8 && DeliveryMode != 6 && DeliveryMode != 3);
Entry.Uint32.Low = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2); Entry.Uint32.Low = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2);
Entry.Bits.Vector = (UINT8)Vector; Entry.Bits.Vector = (UINT8)Vector;
Entry.Bits.DeliveryMode = (UINT32)DeliveryMode; Entry.Bits.DeliveryMode = (UINT32)DeliveryMode;
Entry.Bits.DestinationMode = 0; Entry.Bits.DestinationMode = 0;
@ -146,7 +146,7 @@ IoApicConfigureInterrupt (
Entry.Bits.Mask = 1; Entry.Bits.Mask = 1;
IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2, Entry.Uint32.Low); IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2, Entry.Uint32.Low);
Entry.Uint32.High = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2 + 1); Entry.Uint32.High = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2 + 1);
Entry.Bits.DestinationID = GetApicId (); Entry.Bits.DestinationID = GetApicId ();
IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2 + 1, Entry.Uint32.High); IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2 + 1, Entry.Uint32.High);
} }

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
@ -79,8 +78,8 @@ ResetShutdown (
VOID VOID
EFIAPI EFIAPI
ResetPlatformSpecific ( ResetPlatformSpecific (
IN UINTN DataSize, IN UINTN DataSize,
IN VOID *ResetData IN VOID *ResetData
) )
{ {
ResetCold (); ResetCold ();
@ -101,30 +100,30 @@ ResetPlatformSpecific (
VOID VOID
EFIAPI EFIAPI
ResetSystem ( ResetSystem (
IN EFI_RESET_TYPE ResetType, IN EFI_RESET_TYPE ResetType,
IN EFI_STATUS ResetStatus, IN EFI_STATUS ResetStatus,
IN UINTN DataSize, IN UINTN DataSize,
IN VOID *ResetData OPTIONAL IN VOID *ResetData OPTIONAL
) )
{ {
switch (ResetType) { switch (ResetType) {
case EfiResetWarm: case EfiResetWarm:
ResetWarm (); ResetWarm ();
break; break;
case EfiResetCold: case EfiResetCold:
ResetCold (); ResetCold ();
break; break;
case EfiResetShutdown: case EfiResetShutdown:
ResetShutdown (); ResetShutdown ();
return; return;
case EfiResetPlatformSpecific: case EfiResetPlatformSpecific:
ResetPlatformSpecific (DataSize, ResetData); ResetPlatformSpecific (DataSize, ResetData);
return; return;
default: default:
return; return;
} }
} }

View File

@ -10,39 +10,39 @@
#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
#define LCR_SHADOW_OFFSET 0x01 #define LCR_SHADOW_OFFSET 0x01
#define FCR_SHADOW_OFFSET 0x02 #define FCR_SHADOW_OFFSET 0x02
#define IR_CONTROL_OFFSET 0x02 #define IR_CONTROL_OFFSET 0x02
#define FCR_OFFSET 0x02 #define FCR_OFFSET 0x02
#define EIR_OFFSET 0x02 #define EIR_OFFSET 0x02
#define BSR_OFFSET 0x03 #define BSR_OFFSET 0x03
#define LCR_OFFSET 0x03 #define LCR_OFFSET 0x03
#define MCR_OFFSET 0x04 #define MCR_OFFSET 0x04
#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
#define MCR_DTRC 0x01 #define MCR_DTRC 0x01
#define MCR_RTS 0x02 #define MCR_RTS 0x02
#define MSR_CTS 0x10 #define MSR_CTS 0x10
#define MSR_DSR 0x20 #define MSR_DSR 0x20
#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;
@ -124,9 +124,9 @@ SerialPortInitialize (
UINTN UINTN
EFIAPI 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.
@ -165,9 +165,9 @@ SerialPortWrite (
UINTN UINTN
EFIAPI 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);
} }
/** /**
@ -232,10 +232,10 @@ SerialPortPoll (
RETURN_STATUS RETURN_STATUS
EFIAPI EFIAPI
SerialPortSetControl ( SerialPortSetControl (
IN UINT32 Control IN UINT32 Control
) )
{ {
UINT8 Mcr; UINT8 Mcr;
// //
// First determine the parameter is invalid. // First determine the parameter is invalid.
@ -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;
} }
@ -279,19 +279,19 @@ SerialPortSetControl (
RETURN_STATUS RETURN_STATUS
EFIAPI EFIAPI
SerialPortGetControl ( SerialPortGetControl (
OUT UINT32 *Control OUT UINT32 *Control
) )
{ {
UINT8 Msr; UINT8 Msr;
UINT8 Mcr; UINT8 Mcr;
UINT8 Lsr; UINT8 Lsr;
*Control = 0; *Control = 0;
// //
// 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;
@ -374,19 +374,19 @@ SerialPortGetControl (
RETURN_STATUS RETURN_STATUS
EFIAPI EFIAPI
SerialPortSetAttributes ( SerialPortSetAttributes (
IN OUT UINT64 *BaudRate, IN OUT UINT64 *BaudRate,
IN OUT UINT32 *ReceiveFifoDepth, IN OUT UINT32 *ReceiveFifoDepth,
IN OUT UINT32 *Timeout, IN OUT UINT32 *Timeout,
IN OUT EFI_PARITY_TYPE *Parity, IN OUT EFI_PARITY_TYPE *Parity,
IN OUT UINT8 *DataBits, IN OUT UINT8 *DataBits,
IN OUT EFI_STOP_BITS_TYPE *StopBits IN OUT EFI_STOP_BITS_TYPE *StopBits
) )
{ {
UINTN Divisor; UINTN Divisor;
UINT8 OutputData; UINT8 OutputData;
UINT8 LcrData; UINT8 LcrData;
UINT8 LcrParity; UINT8 LcrParity;
UINT8 LcrStop; UINT8 LcrStop;
// //
// Check for default settings and fill in actual values. // Check for default settings and fill in actual values.
@ -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

@ -17,12 +17,12 @@ extern UINTN mRtcTargetRegister;
// //
// Days of month. // Days of month.
// //
UINTN mDayOfMonth[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; UINTN mDayOfMonth[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
// //
// The name of NV variable to store the timezone and daylight saving information. // The name of NV variable to store the timezone and daylight saving information.
// //
CHAR16 mTimeZoneVariableName[] = L"RTC"; CHAR16 mTimeZoneVariableName[] = L"RTC";
/** /**
Compare the Hour, Minute and Second of the From time and the To time. Compare the Hour, Minute and Second of the From time and the To time.
@ -38,8 +38,8 @@ CHAR16 mTimeZoneVariableName[] = L"RTC";
**/ **/
INTN INTN
CompareHMS ( CompareHMS (
IN EFI_TIME *From, IN EFI_TIME *From,
IN EFI_TIME *To IN EFI_TIME *To
); );
/** /**
@ -53,8 +53,8 @@ CompareHMS (
**/ **/
BOOLEAN BOOLEAN
IsWithinOneDay ( IsWithinOneDay (
IN EFI_TIME *From, IN EFI_TIME *From,
IN EFI_TIME *To IN EFI_TIME *To
); );
/** /**
@ -68,7 +68,7 @@ IsWithinOneDay (
STATIC STATIC
UINT8 UINT8
IoRtcRead ( IoRtcRead (
IN UINTN Address IN UINTN Address
) )
{ {
IoWrite8 ( IoWrite8 (
@ -89,8 +89,8 @@ IoRtcRead (
STATIC STATIC
VOID VOID
IoRtcWrite ( IoRtcWrite (
IN UINTN Address, IN UINTN Address,
IN UINT8 Data IN UINT8 Data
) )
{ {
IoWrite8 ( IoWrite8 (
@ -111,7 +111,7 @@ IoRtcWrite (
STATIC STATIC
UINT8 UINT8
MmioRtcRead ( MmioRtcRead (
IN UINTN Address IN UINTN Address
) )
{ {
MmioWrite8 ( MmioWrite8 (
@ -132,8 +132,8 @@ MmioRtcRead (
STATIC STATIC
VOID VOID
MmioRtcWrite ( MmioRtcWrite (
IN UINTN Address, IN UINTN Address,
IN UINT8 Data IN UINT8 Data
) )
{ {
MmioWrite8 ( MmioWrite8 (
@ -154,7 +154,7 @@ MmioRtcWrite (
STATIC STATIC
UINT8 UINT8
RtcRead ( RtcRead (
IN UINTN Address IN UINTN Address
) )
{ {
if (FeaturePcdGet (PcdRtcUseMmio)) { if (FeaturePcdGet (PcdRtcUseMmio)) {
@ -175,8 +175,8 @@ RtcRead (
STATIC STATIC
VOID VOID
RtcWrite ( RtcWrite (
IN UINTN Address, IN UINTN Address,
IN UINT8 Data IN UINT8 Data
) )
{ {
if (FeaturePcdGet (PcdRtcUseMmio)) { if (FeaturePcdGet (PcdRtcUseMmio)) {
@ -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.
// //
@ -285,16 +288,16 @@ PcRtcInit (
// stored in NV variable during previous boot. // stored in NV variable during previous boot.
// //
DataSize = sizeof (UINT32); DataSize = sizeof (UINT32);
Status = EfiGetVariable ( Status = EfiGetVariable (
mTimeZoneVariableName, mTimeZoneVariableName,
&gEfiCallerIdGuid, &gEfiCallerIdGuid,
NULL, NULL,
&DataSize, &DataSize,
&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
@ -315,15 +319,15 @@ PcRtcInit (
EFI_ERROR_CODE | EFI_ERROR_MINOR, EFI_ERROR_CODE | EFI_ERROR_MINOR,
(EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_BAD_DATE_TIME) (EFI_SOFTWARE_DXE_RT_DRIVER | EFI_SW_EC_BAD_DATE_TIME)
); );
Time.Second = RTC_INIT_SECOND; Time.Second = RTC_INIT_SECOND;
Time.Minute = RTC_INIT_MINUTE; Time.Minute = RTC_INIT_MINUTE;
Time.Hour = RTC_INIT_HOUR; Time.Hour = RTC_INIT_HOUR;
Time.Day = RTC_INIT_DAY; Time.Day = RTC_INIT_DAY;
Time.Month = RTC_INIT_MONTH; Time.Month = RTC_INIT_MONTH;
Time.Year = PcdGet16 (PcdMinimalValidYear); Time.Year = PcdGet16 (PcdMinimalValidYear);
Time.Nanosecond = 0; Time.Nanosecond = 0;
Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE; Time.TimeZone = EFI_UNSPECIFIED_TIMEZONE;
Time.Daylight = 0; Time.Daylight = 0;
} }
// //
@ -348,15 +352,15 @@ PcRtcInit (
// When wakeup time is disabled and invalid, reset wakeup time register to valid state // When wakeup time is disabled and invalid, reset wakeup time register to valid state
// but keep wakeup alarm disabled. // but keep wakeup alarm disabled.
// //
Time.Second = RTC_INIT_SECOND; Time.Second = RTC_INIT_SECOND;
Time.Minute = RTC_INIT_MINUTE; Time.Minute = RTC_INIT_MINUTE;
Time.Hour = RTC_INIT_HOUR; Time.Hour = RTC_INIT_HOUR;
Time.Day = RTC_INIT_DAY; Time.Day = RTC_INIT_DAY;
Time.Month = RTC_INIT_MONTH; Time.Month = RTC_INIT_MONTH;
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,14 +368,16 @@ 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
// //
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
@ -391,13 +397,14 @@ PcRtcInit (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Inhibit updates of the RTC // Inhibit updates of the RTC
// //
RegisterB.Bits.Set = 1; RegisterB.Bits.Set = 1;
RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);
// //
@ -419,6 +426,7 @@ PcRtcInit (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -451,24 +459,27 @@ 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
// //
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return Status; return Status;
} }
// //
// Read Register B // Read Register B
// //
@ -477,12 +488,12 @@ PcRtcGetTime (
// //
// Get the Time/Date/Daylight Savings values. // Get the Time/Date/Daylight Savings values.
// //
Time->Second = RtcRead (RTC_ADDRESS_SECONDS); Time->Second = RtcRead (RTC_ADDRESS_SECONDS);
Time->Minute = RtcRead (RTC_ADDRESS_MINUTES); Time->Minute = RtcRead (RTC_ADDRESS_MINUTES);
Time->Hour = RtcRead (RTC_ADDRESS_HOURS); Time->Hour = RtcRead (RTC_ADDRESS_HOURS);
Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);
Time->Month = RtcRead (RTC_ADDRESS_MONTH); Time->Month = RtcRead (RTC_ADDRESS_MONTH);
Time->Year = RtcRead (RTC_ADDRESS_YEAR); Time->Year = RtcRead (RTC_ADDRESS_YEAR);
// //
// Release RTC Lock. // Release RTC Lock.
@ -494,8 +505,8 @@ PcRtcGetTime (
// //
// Get the variable that contains the TimeZone and Daylight fields // Get the variable that contains the TimeZone and Daylight fields
// //
Time->TimeZone = Global->SavedTimeZone; Time->TimeZone = Global->SavedTimeZone;
Time->Daylight = Global->Daylight; Time->Daylight = Global->Daylight;
// //
// Make sure all field values are in correct range // Make sure all field values are in correct range
@ -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;
} }
@ -539,8 +551,8 @@ PcRtcGetTime (
**/ **/
EFI_STATUS EFI_STATUS
PcRtcSetTime ( PcRtcSetTime (
IN EFI_TIME *Time, IN EFI_TIME *Time,
IN PC_RTC_MODULE_GLOBALS *Global IN PC_RTC_MODULE_GLOBALS *Global
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -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,14 +580,16 @@ 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
// //
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return Status; return Status;
} }
@ -594,35 +609,36 @@ 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,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
sizeof (TimerVar), sizeof (TimerVar),
&TimerVar &TimerVar
); );
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Read Register B, and inhibit updates of the RTC // Read Register B, and inhibit updates of the RTC
// //
RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);
RegisterB.Bits.Set = 1; RegisterB.Bits.Set = 1;
RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);
// //
// 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,29 +707,32 @@ 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
// //
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
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
// //
RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B); RegisterB.Data = RtcRead (RTC_ADDRESS_REGISTER_B);
RegisterC.Data = RtcRead (RTC_ADDRESS_REGISTER_C); RegisterC.Data = RtcRead (RTC_ADDRESS_REGISTER_C);
// //
// Get the Time/Date/Daylight Savings values. // Get the Time/Date/Daylight Savings values.
@ -720,12 +740,12 @@ PcRtcGetWakeupTime (
*Enabled = RegisterB.Bits.Aie; *Enabled = RegisterB.Bits.Aie;
*Pending = RegisterC.Bits.Af; *Pending = RegisterC.Bits.Af;
Time->Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM); Time->Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM);
Time->Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM); Time->Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM);
Time->Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM); Time->Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM);
Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); Time->Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);
Time->Month = RtcRead (RTC_ADDRESS_MONTH); Time->Month = RtcRead (RTC_ADDRESS_MONTH);
Time->Year = RtcRead (RTC_ADDRESS_YEAR); Time->Year = RtcRead (RTC_ADDRESS_YEAR);
Time->TimeZone = Global->SavedTimeZone; Time->TimeZone = Global->SavedTimeZone;
Time->Daylight = Global->Daylight; Time->Daylight = Global->Daylight;
@ -733,13 +753,13 @@ PcRtcGetWakeupTime (
// Get the alarm info from variable // Get the alarm info from variable
// //
DataSize = sizeof (EFI_TIME); DataSize = sizeof (EFI_TIME);
Status = EfiGetVariable ( Status = EfiGetVariable (
L"RTCALARM", L"RTCALARM",
&gEfiCallerIdGuid, &gEfiCallerIdGuid,
NULL, NULL,
&DataSize, &DataSize,
&RtcTime &RtcTime
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
// //
// The alarm variable exists. In this case, we read variable to get info. // The alarm variable exists. In this case, we read variable to get info.
@ -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;
} }
@ -792,18 +813,18 @@ PcRtcSetWakeupTime (
IN PC_RTC_MODULE_GLOBALS *Global IN PC_RTC_MODULE_GLOBALS *Global
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_TIME RtcTime; EFI_TIME RtcTime;
RTC_REGISTER_B RegisterB; RTC_REGISTER_B RegisterB;
EFI_TIME_CAPABILITIES Capabilities; EFI_TIME_CAPABILITIES Capabilities;
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,31 +841,36 @@ 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
// //
Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout)); Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Read Register B // Read Register B
// //
@ -855,12 +882,12 @@ PcRtcSetWakeupTime (
// //
// if the alarm is disable, record the current setting. // if the alarm is disable, record the current setting.
// //
RtcTime.Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM); RtcTime.Second = RtcRead (RTC_ADDRESS_SECONDS_ALARM);
RtcTime.Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM); RtcTime.Minute = RtcRead (RTC_ADDRESS_MINUTES_ALARM);
RtcTime.Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM); RtcTime.Hour = RtcRead (RTC_ADDRESS_HOURS_ALARM);
RtcTime.Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH); RtcTime.Day = RtcRead (RTC_ADDRESS_DAY_OF_THE_MONTH);
RtcTime.Month = RtcRead (RTC_ADDRESS_MONTH); RtcTime.Month = RtcRead (RTC_ADDRESS_MONTH);
RtcTime.Year = RtcRead (RTC_ADDRESS_YEAR); RtcTime.Year = RtcRead (RTC_ADDRESS_YEAR);
RtcTime.TimeZone = Global->SavedTimeZone; RtcTime.TimeZone = Global->SavedTimeZone;
RtcTime.Daylight = Global->Daylight; RtcTime.Daylight = Global->Daylight;
} }
@ -879,13 +906,14 @@ PcRtcSetWakeupTime (
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock); EfiReleaseLock (&Global->RtcLock);
} }
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Inhibit updates of the RTC // Inhibit updates of the RTC
// //
RegisterB.Bits.Set = 1; RegisterB.Bits.Set = 1;
RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data); RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);
if (Enable) { if (Enable) {
@ -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.
@ -964,8 +992,8 @@ ConvertRtcTimeToEfiTime (
IN RTC_REGISTER_B RegisterB IN RTC_REGISTER_B RegisterB
) )
{ {
BOOLEAN IsPM; BOOLEAN IsPM;
UINT8 Century; UINT8 Century;
if ((Time->Hour & 0x80) != 0) { if ((Time->Hour & 0x80) != 0) {
IsPM = TRUE; IsPM = TRUE;
@ -973,19 +1001,20 @@ 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);
Time->Minute = CheckAndConvertBcd8ToDecimal8 (Time->Minute); Time->Minute = CheckAndConvertBcd8ToDecimal8 (Time->Minute);
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,26 +1023,27 @@ 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;
} }
} }
Time->Nanosecond = 0; Time->Nanosecond = 0;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1028,7 +1058,7 @@ ConvertRtcTimeToEfiTime (
**/ **/
EFI_STATUS EFI_STATUS
RtcWaitToUpdate ( RtcWaitToUpdate (
UINTN Timeout UINTN Timeout
) )
{ {
RTC_REGISTER_A RegisterA; RTC_REGISTER_A RegisterA;
@ -1042,11 +1072,12 @@ 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.
// //
Timeout = (Timeout / 10) + 1; Timeout = (Timeout / 10) + 1;
RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A); RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A);
while (RegisterA.Bits.Uip == 1 && Timeout > 0) { while (RegisterA.Bits.Uip == 1 && Timeout > 0) {
MicroSecondDelay (10); MicroSecondDelay (10);
RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A); RegisterA.Data = RtcRead (RTC_ADDRESS_REGISTER_A);
@ -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;
} }
@ -1072,20 +1103,21 @@ RtcWaitToUpdate (
**/ **/
EFI_STATUS EFI_STATUS
RtcTimeFieldsValid ( 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;
} }
@ -1130,7 +1163,7 @@ DayValid (
**/ **/
BOOLEAN BOOLEAN
IsLeapYear ( IsLeapYear (
IN EFI_TIME *Time IN EFI_TIME *Time
) )
{ {
if (Time->Year % 4 == 0) { if (Time->Year % 4 == 0) {
@ -1165,7 +1198,7 @@ ConvertEfiTimeToRtcTime (
IN RTC_REGISTER_B RegisterB IN RTC_REGISTER_B RegisterB
) )
{ {
BOOLEAN IsPM; BOOLEAN IsPM;
IsPM = TRUE; IsPM = TRUE;
// //
@ -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);
} }
} }
@ -1217,13 +1252,14 @@ ConvertEfiTimeToRtcTime (
**/ **/
INTN INTN
CompareHMS ( CompareHMS (
IN EFI_TIME *From, IN EFI_TIME *From,
IN EFI_TIME *To IN EFI_TIME *To
) )
{ {
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;
@ -1247,37 +1283,37 @@ IsWithinOneDay (
IN EFI_TIME *To IN EFI_TIME *To
) )
{ {
BOOLEAN Adjacent; BOOLEAN Adjacent;
Adjacent = FALSE; Adjacent = FALSE;
// //
// 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;
} }
} }
@ -1304,15 +1341,16 @@ GetCenturyRtcAddress (
VOID VOID
) )
{ {
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;
@ -1332,21 +1370,21 @@ GetCenturyRtcAddress (
VOID VOID
EFIAPI EFIAPI
PcRtcAcpiTableChangeCallback ( PcRtcAcpiTableChangeCallback (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_TIME Time; EFI_TIME Time;
UINT8 CenturyRtcAddress; UINT8 CenturyRtcAddress;
UINT8 Century; UINT8 Century;
CenturyRtcAddress = GetCenturyRtcAddress (); CenturyRtcAddress = GetCenturyRtcAddress ();
if ((CenturyRtcAddress != 0) && (mModuleGlobal.CenturyRtcAddress != CenturyRtcAddress)) { if ((CenturyRtcAddress != 0) && (mModuleGlobal.CenturyRtcAddress != CenturyRtcAddress)) {
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>
@ -33,10 +31,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/ReportStatusCodeLib.h> #include <Library/ReportStatusCodeLib.h>
typedef struct { typedef struct {
EFI_LOCK RtcLock; EFI_LOCK RtcLock;
INT16 SavedTimeZone; INT16 SavedTimeZone;
UINT8 Daylight; UINT8 Daylight;
UINT8 CenturyRtcAddress; UINT8 CenturyRtcAddress;
} PC_RTC_MODULE_GLOBALS; } PC_RTC_MODULE_GLOBALS;
extern PC_RTC_MODULE_GLOBALS mModuleGlobal; extern PC_RTC_MODULE_GLOBALS mModuleGlobal;
@ -62,73 +60,73 @@ extern PC_RTC_MODULE_GLOBALS mModuleGlobal;
// Date and time initial values. // Date and time initial values.
// They are used if the RTC values are invalid during driver initialization // They are used if the RTC values are invalid during driver initialization
// //
#define RTC_INIT_SECOND 0 #define RTC_INIT_SECOND 0
#define RTC_INIT_MINUTE 0 #define RTC_INIT_MINUTE 0
#define RTC_INIT_HOUR 0 #define RTC_INIT_HOUR 0
#define RTC_INIT_DAY 1 #define RTC_INIT_DAY 1
#define RTC_INIT_MONTH 1 #define RTC_INIT_MONTH 1
#pragma pack(1) #pragma pack(1)
// //
// Register A // Register A
// //
typedef struct { typedef struct {
UINT8 Rs : 4; // Rate Selection Bits UINT8 Rs : 4; // Rate Selection Bits
UINT8 Dv : 3; // Divisor UINT8 Dv : 3; // Divisor
UINT8 Uip : 1; // Update in progress UINT8 Uip : 1; // Update in progress
} RTC_REGISTER_A_BITS; } RTC_REGISTER_A_BITS;
typedef union { typedef union {
RTC_REGISTER_A_BITS Bits; RTC_REGISTER_A_BITS Bits;
UINT8 Data; UINT8 Data;
} RTC_REGISTER_A; } RTC_REGISTER_A;
// //
// Register B // Register B
// //
typedef struct { typedef struct {
UINT8 Dse : 1; // 0 - Daylight saving disabled 1 - Daylight savings enabled UINT8 Dse : 1; // 0 - Daylight saving disabled 1 - Daylight savings enabled
UINT8 Mil : 1; // 0 - 12 hour mode 1 - 24 hour mode UINT8 Mil : 1; // 0 - 12 hour mode 1 - 24 hour mode
UINT8 Dm : 1; // 0 - BCD Format 1 - Binary Format UINT8 Dm : 1; // 0 - BCD Format 1 - Binary Format
UINT8 Sqwe : 1; // 0 - Disable SQWE output 1 - Enable SQWE output UINT8 Sqwe : 1; // 0 - Disable SQWE output 1 - Enable SQWE output
UINT8 Uie : 1; // 0 - Update INT disabled 1 - Update INT enabled UINT8 Uie : 1; // 0 - Update INT disabled 1 - Update INT enabled
UINT8 Aie : 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled UINT8 Aie : 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled
UINT8 Pie : 1; // 0 - Periodic INT disabled 1 - Periodic INT Enabled UINT8 Pie : 1; // 0 - Periodic INT disabled 1 - Periodic INT Enabled
UINT8 Set : 1; // 0 - Normal operation. 1 - Updates inhibited UINT8 Set : 1; // 0 - Normal operation. 1 - Updates inhibited
} RTC_REGISTER_B_BITS; } RTC_REGISTER_B_BITS;
typedef union { typedef union {
RTC_REGISTER_B_BITS Bits; RTC_REGISTER_B_BITS Bits;
UINT8 Data; UINT8 Data;
} RTC_REGISTER_B; } RTC_REGISTER_B;
// //
// Register C // Register C
// //
typedef struct { typedef struct {
UINT8 Reserved : 4; // Read as zero. Can not be written. UINT8 Reserved : 4; // Read as zero. Can not be written.
UINT8 Uf : 1; // Update End Interrupt Flag UINT8 Uf : 1; // Update End Interrupt Flag
UINT8 Af : 1; // Alarm Interrupt Flag UINT8 Af : 1; // Alarm Interrupt Flag
UINT8 Pf : 1; // Periodic Interrupt Flag UINT8 Pf : 1; // Periodic Interrupt Flag
UINT8 Irqf : 1; // Interrupt Request Flag = PF & PIE | AF & AIE | UF & UIE UINT8 Irqf : 1; // Interrupt Request Flag = PF & PIE | AF & AIE | UF & UIE
} RTC_REGISTER_C_BITS; } RTC_REGISTER_C_BITS;
typedef union { typedef union {
RTC_REGISTER_C_BITS Bits; RTC_REGISTER_C_BITS Bits;
UINT8 Data; UINT8 Data;
} RTC_REGISTER_C; } RTC_REGISTER_C;
// //
// Register D // Register D
// //
typedef struct { typedef struct {
UINT8 Reserved : 7; // Read as zero. Can not be written. UINT8 Reserved : 7; // Read as zero. Can not be written.
UINT8 Vrt : 1; // Valid RAM and Time UINT8 Vrt : 1; // Valid RAM and Time
} RTC_REGISTER_D_BITS; } RTC_REGISTER_D_BITS;
typedef union { typedef union {
RTC_REGISTER_D_BITS Bits; RTC_REGISTER_D_BITS Bits;
UINT8 Data; UINT8 Data;
} RTC_REGISTER_D; } RTC_REGISTER_D;
#pragma pack() #pragma pack()
@ -180,9 +178,9 @@ PcRtcSetTime (
**/ **/
EFI_STATUS EFI_STATUS
PcRtcGetTime ( PcRtcGetTime (
OUT EFI_TIME *Time, OUT EFI_TIME *Time,
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL, OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL,
IN PC_RTC_MODULE_GLOBALS *Global IN PC_RTC_MODULE_GLOBALS *Global
); );
/** /**
@ -225,10 +223,10 @@ PcRtcSetWakeupTime (
**/ **/
EFI_STATUS EFI_STATUS
PcRtcGetWakeupTime ( PcRtcGetWakeupTime (
OUT BOOLEAN *Enabled, OUT BOOLEAN *Enabled,
OUT BOOLEAN *Pending, OUT BOOLEAN *Pending,
OUT EFI_TIME *Time, OUT EFI_TIME *Time,
IN PC_RTC_MODULE_GLOBALS *Global IN PC_RTC_MODULE_GLOBALS *Global
); );
/** /**
@ -247,8 +245,8 @@ PcRtcGetWakeupTime (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InitializePcRtc ( InitializePcRtc (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
); );
/** /**
@ -262,7 +260,7 @@ InitializePcRtc (
**/ **/
EFI_STATUS EFI_STATUS
RtcTimeFieldsValid ( RtcTimeFieldsValid (
IN EFI_TIME *Time IN EFI_TIME *Time
); );
/** /**
@ -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.
@ -316,7 +313,7 @@ ConvertRtcTimeToEfiTime (
**/ **/
EFI_STATUS EFI_STATUS
RtcWaitToUpdate ( RtcWaitToUpdate (
UINTN Timeout UINTN Timeout
); );
/** /**
@ -342,7 +339,7 @@ DayValid (
**/ **/
BOOLEAN BOOLEAN
IsLeapYear ( IsLeapYear (
IN EFI_TIME *Time IN EFI_TIME *Time
); );
/** /**
@ -368,7 +365,8 @@ GetCenturyRtcAddress (
VOID VOID
EFIAPI EFIAPI
PcRtcAcpiTableChangeCallback ( PcRtcAcpiTableChangeCallback (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
); );
#endif #endif

View File

@ -12,12 +12,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
PC_RTC_MODULE_GLOBALS mModuleGlobal; PC_RTC_MODULE_GLOBALS mModuleGlobal;
EFI_HANDLE mHandle = NULL; EFI_HANDLE mHandle = NULL;
STATIC EFI_EVENT mVirtualAddrChangeEvent; STATIC EFI_EVENT mVirtualAddrChangeEvent;
UINTN mRtcIndexRegister; UINTN mRtcIndexRegister;
UINTN mRtcTargetRegister; UINTN mRtcTargetRegister;
/** /**
Returns the current time and date information, and the time-keeping capabilities Returns the current time and date information, and the time-keeping capabilities
@ -35,8 +35,8 @@ UINTN mRtcTargetRegister;
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
PcRtcEfiGetTime ( PcRtcEfiGetTime (
OUT EFI_TIME *Time, OUT EFI_TIME *Time,
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
) )
{ {
return PcRtcGetTime (Time, Capabilities, &mModuleGlobal); return PcRtcGetTime (Time, Capabilities, &mModuleGlobal);
@ -55,7 +55,7 @@ PcRtcEfiGetTime (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
PcRtcEfiSetTime ( PcRtcEfiSetTime (
IN EFI_TIME *Time IN EFI_TIME *Time
) )
{ {
return PcRtcSetTime (Time, &mModuleGlobal); return PcRtcSetTime (Time, &mModuleGlobal);
@ -79,15 +79,14 @@ PcRtcEfiSetTime (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
PcRtcEfiGetWakeupTime ( PcRtcEfiGetWakeupTime (
OUT BOOLEAN *Enabled, OUT BOOLEAN *Enabled,
OUT BOOLEAN *Pending, OUT BOOLEAN *Pending,
OUT EFI_TIME *Time OUT EFI_TIME *Time
) )
{ {
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.
@ -105,8 +104,8 @@ PcRtcEfiGetWakeupTime (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
PcRtcEfiSetWakeupTime ( PcRtcEfiSetWakeupTime (
IN BOOLEAN Enabled, IN BOOLEAN Enabled,
IN EFI_TIME *Time OPTIONAL IN EFI_TIME *Time OPTIONAL
) )
{ {
return PcRtcSetWakeupTime (Enabled, Time, &mModuleGlobal); return PcRtcSetWakeupTime (Enabled, Time, &mModuleGlobal);
@ -123,8 +122,8 @@ PcRtcEfiSetWakeupTime (
VOID VOID
EFIAPI EFIAPI
LibRtcVirtualNotifyEvent ( LibRtcVirtualNotifyEvent (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
{ {
// Only needed if you are going to support the OS calling RTC functions in // Only needed if you are going to support the OS calling RTC functions in
@ -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);
} }
/** /**
@ -152,8 +151,8 @@ LibRtcVirtualNotifyEvent (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InitializePcRtc ( InitializePcRtc (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -163,7 +162,7 @@ InitializePcRtc (
mModuleGlobal.CenturyRtcAddress = GetCenturyRtcAddress (); mModuleGlobal.CenturyRtcAddress = GetCenturyRtcAddress ();
if (FeaturePcdGet (PcdRtcUseMmio)) { if (FeaturePcdGet (PcdRtcUseMmio)) {
mRtcIndexRegister = (UINTN)PcdGet64 (PcdRtcIndexRegister64); mRtcIndexRegister = (UINTN)PcdGet64 (PcdRtcIndexRegister64);
mRtcTargetRegister = (UINTN)PcdGet64 (PcdRtcTargetRegister64); mRtcTargetRegister = (UINTN)PcdGet64 (PcdRtcTargetRegister64);
} }