TianoCore EDK2 master
Loading...
Searching...
No Matches
PcRtc.c File Reference
#include "PcRtc.h"

Go to the source code of this file.

Functions

INTN CompareHMS (IN EFI_TIME *From, IN EFI_TIME *To)
 
BOOLEAN IsWithinOneDay (IN EFI_TIME *From, IN EFI_TIME *To)
 
STATIC UINT8 IoRtcRead (IN UINTN Address)
 
STATIC VOID IoRtcWrite (IN UINTN Address, IN UINT8 Data)
 
STATIC UINT8 MmioRtcRead (IN UINTN Address)
 
STATIC VOID MmioRtcWrite (IN UINTN Address, IN UINT8 Data)
 
STATIC UINT8 RtcRead (IN UINTN Address)
 
STATIC VOID RtcWrite (IN UINTN Address, IN UINT8 Data)
 
EFI_STATUS PcRtcSetTimeZone (IN INT16 TimeZone, IN UINT8 Daylight, IN PC_RTC_MODULE_GLOBALS *Global)
 
EFI_STATUS PcRtcInit (IN PC_RTC_MODULE_GLOBALS *Global)
 
EFI_STATUS PcRtcGetTime (OUT EFI_TIME *Time, OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL, IN PC_RTC_MODULE_GLOBALS *Global)
 
EFI_STATUS PcRtcSetTime (IN EFI_TIME *Time, IN PC_RTC_MODULE_GLOBALS *Global)
 
EFI_STATUS PcRtcGetWakeupTime (OUT BOOLEAN *Enabled, OUT BOOLEAN *Pending, OUT EFI_TIME *Time, IN PC_RTC_MODULE_GLOBALS *Global)
 
EFI_STATUS PcRtcSetWakeupTime (IN BOOLEAN Enable, IN EFI_TIME *Time OPTIONAL, IN PC_RTC_MODULE_GLOBALS *Global)
 
UINT8 CheckAndConvertBcd8ToDecimal8 (IN UINT8 Value)
 
EFI_STATUS ConvertRtcTimeToEfiTime (IN OUT EFI_TIME *Time, IN RTC_REGISTER_B RegisterB)
 
EFI_STATUS RtcWaitToUpdate (UINTN Timeout)
 
EFI_STATUS RtcTimeFieldsValid (IN EFI_TIME *Time)
 
BOOLEAN DayValid (IN EFI_TIME *Time)
 
BOOLEAN IsLeapYear (IN EFI_TIME *Time)
 
VOID ConvertEfiTimeToRtcTime (IN OUT EFI_TIME *Time, IN RTC_REGISTER_B RegisterB)
 
UINT8 GetCenturyRtcAddress (VOID)
 
VOID EFIAPI PcRtcAcpiTableChangeCallback (IN EFI_EVENT Event, IN VOID *Context)
 

Variables

UINTN mRtcIndexRegister
 
UINTN mRtcTargetRegister
 
UINT16 mRtcDefaultYear
 
UINT16 mMinimalValidYear
 
UINT16 mMaximalValidYear
 
UINTN mDayOfMonth [] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
 
CHAR16 mTimeZoneVariableName [] = L"RTC"
 

Detailed Description

RTC Architectural Protocol GUID as defined in DxeCis 0.96.

Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
Copyright (c) 2017, AMD Inc. All rights reserved.
Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file PcRtc.c.

Function Documentation

◆ CheckAndConvertBcd8ToDecimal8()

UINT8 CheckAndConvertBcd8ToDecimal8 ( IN UINT8  Value)

Checks an 8-bit BCD value, and converts to an 8-bit value if valid.

This function checks the 8-bit BCD value specified by Value. If valid, the function converts it to an 8-bit value and returns it. Otherwise, return 0xff.

Parameters
ValueThe 8-bit BCD value to check and convert
Returns
The 8-bit value converted. Or 0xff if Value is invalid.

Definition at line 1022 of file PcRtc.c.

◆ CompareHMS()

INTN CompareHMS ( IN EFI_TIME From,
IN EFI_TIME To 
)

Compare the Hour, Minute and Second of the From time and the To time.

Only compare H/M/S in EFI_TIME and ignore other fields here.

Parameters
Fromthe first time
Tothe second time
Returns
>0 The H/M/S of the From time is later than those of To time
==0 The H/M/S of the From time is same as those of To time
<0 The H/M/S of the From time is earlier than those of To time

Definition at line 1318 of file PcRtc.c.

◆ ConvertEfiTimeToRtcTime()

VOID ConvertEfiTimeToRtcTime ( IN OUT EFI_TIME Time,
IN RTC_REGISTER_B  RegisterB 
)

Converts time from EFI_TIME format defined by UEFI spec to RTC format.

This function converts time from EFI_TIME format defined by UEFI spec to RTC format. If data mode of RTC is BCD, then converts EFI_TIME to it. If RTC is in 12-hour format, then converts EFI_TIME to it.

Parameters
TimeOn input, the time data read from UEFI to convert On output, the time converted to RTC format
RegisterBValue of Register B of RTC, indicating data mode

Definition at line 1260 of file PcRtc.c.

◆ ConvertRtcTimeToEfiTime()

EFI_STATUS ConvertRtcTimeToEfiTime ( IN OUT EFI_TIME Time,
IN RTC_REGISTER_B  RegisterB 
)

Converts time read from RTC to EFI_TIME format defined by UEFI spec.

This function converts raw time data read from RTC to the EFI_TIME format defined by UEFI spec. If data mode of RTC is BCD, then converts it to decimal, If RTC is in 12-hour format, then converts it to 24-hour format.

Parameters
TimeOn input, the time data read from RTC to convert On output, the time converted to UEFI format
RegisterBValue of Register B of RTC, indicating data mode and hour format.
Return values
EFI_INVALID_PARAMETERParameters passed in are invalid.
EFI_SUCCESSConvert RTC time to EFI time successfully.

Definition at line 1051 of file PcRtc.c.

◆ DayValid()

BOOLEAN DayValid ( IN EFI_TIME Time)

See if field Day of an EFI_TIME is correct.

Parameters
TimeIts Day field is to be checked.
Return values
TRUEDay field of Time is correct.
FALSEDay field of Time is NOT correct.

Definition at line 1200 of file PcRtc.c.

◆ GetCenturyRtcAddress()

UINT8 GetCenturyRtcAddress ( VOID  )

Get the century RTC address from the ACPI FADT table.

Returns
The century RTC address or 0 if not found.

Definition at line 1404 of file PcRtc.c.

◆ IoRtcRead()

STATIC UINT8 IoRtcRead ( IN UINTN  Address)

Read RTC content through its registers using IO access.

Parameters
AddressAddress offset of RTC. It is recommended to use macros such as RTC_ADDRESS_SECONDS.
Returns
The data of UINT8 type read from RTC.

Definition at line 72 of file PcRtc.c.

◆ IoRtcWrite()

STATIC VOID IoRtcWrite ( IN UINTN  Address,
IN UINT8  Data 
)

Write RTC through its registers using IO access.

Parameters
AddressAddress offset of RTC. It is recommended to use macros such as RTC_ADDRESS_SECONDS.
DataThe content you want to write into RTC.

Definition at line 93 of file PcRtc.c.

◆ IsLeapYear()

BOOLEAN IsLeapYear ( IN EFI_TIME Time)

Check if it is a leap year.

Parameters
TimeThe time to be checked.
Return values
TRUEIt is a leap year.
FALSEIt is NOT a leap year.

Definition at line 1229 of file PcRtc.c.

◆ IsWithinOneDay()

BOOLEAN IsWithinOneDay ( IN EFI_TIME From,
IN EFI_TIME To 
)

To check if second date is later than first date within 24 hours.

Parameters
Fromthe first date
Tothe second date
Return values
TRUEFrom is previous to To within 24 hours.
FALSEFrom is later, or it is previous to To more than 24 hours.

Definition at line 1345 of file PcRtc.c.

◆ MmioRtcRead()

STATIC UINT8 MmioRtcRead ( IN UINTN  Address)

Read RTC content through its registers using MMIO access.

Parameters
AddressAddress offset of RTC. It is recommended to use macros such as RTC_ADDRESS_SECONDS.
Returns
The data of UINT8 type read from RTC.

Definition at line 115 of file PcRtc.c.

◆ MmioRtcWrite()

STATIC VOID MmioRtcWrite ( IN UINTN  Address,
IN UINT8  Data 
)

Write RTC through its registers using MMIO access.

Parameters
AddressAddress offset of RTC. It is recommended to use macros such as RTC_ADDRESS_SECONDS.
DataThe content you want to write into RTC.

Definition at line 136 of file PcRtc.c.

◆ PcRtcAcpiTableChangeCallback()

VOID EFIAPI PcRtcAcpiTableChangeCallback ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Notification function of ACPI Table change.

This is a notification function registered on ACPI Table change event. It saves the Century address stored in ACPI FADT table.

Parameters
EventEvent whose notification function is being invoked.
ContextPointer to the notification function's context.

Definition at line 1436 of file PcRtc.c.

◆ PcRtcGetTime()

EFI_STATUS PcRtcGetTime ( OUT EFI_TIME Time,
OUT EFI_TIME_CAPABILITIES *Capabilities  OPTIONAL,
IN PC_RTC_MODULE_GLOBALS Global 
)

Returns the current time and date information, and the time-keeping capabilities of the hardware platform.

Parameters
TimeA pointer to storage to receive a snapshot of the current time.
CapabilitiesAn optional pointer to a buffer to receive the real time clock device's capabilities.
GlobalFor global use inside this module.
Return values
EFI_SUCCESSThe operation completed successfully.
EFI_INVALID_PARAMETERTime is NULL.
EFI_DEVICE_ERRORThe time could not be retrieved due to hardware error.

Definition at line 527 of file PcRtc.c.

◆ PcRtcGetWakeupTime()

EFI_STATUS PcRtcGetWakeupTime ( OUT BOOLEAN *  Enabled,
OUT BOOLEAN *  Pending,
OUT EFI_TIME Time,
IN PC_RTC_MODULE_GLOBALS Global 
)

Returns the current wakeup alarm clock setting.

Parameters
EnabledIndicates if the alarm is currently enabled or disabled.
PendingIndicates if the alarm signal is pending and requires acknowledgment.
TimeThe current alarm setting.
GlobalFor global use inside this module.
Return values
EFI_SUCCESSThe alarm settings were returned.
EFI_INVALID_PARAMETEREnabled is NULL.
EFI_INVALID_PARAMETERPending is NULL.
EFI_INVALID_PARAMETERTime is NULL.
EFI_DEVICE_ERRORThe wakeup time could not be retrieved due to a hardware error.
EFI_UNSUPPORTEDA wakeup timer is not supported on this platform.

Definition at line 750 of file PcRtc.c.

◆ PcRtcInit()

EFI_STATUS PcRtcInit ( IN PC_RTC_MODULE_GLOBALS Global)

Initialize RTC.

Parameters
GlobalFor global use inside this module.
Return values
EFI_DEVICE_ERRORInitialization failed due to device error.
EFI_SUCCESSInitialization successful.

Definition at line 262 of file PcRtc.c.

◆ PcRtcSetTime()

EFI_STATUS PcRtcSetTime ( IN EFI_TIME Time,
IN PC_RTC_MODULE_GLOBALS Global 
)

Sets the current local time and date information.

Parameters
TimeA pointer to the current time.
GlobalFor global use inside this module.
Return values
EFI_SUCCESSThe operation completed successfully.
EFI_INVALID_PARAMETERA time field is out of range.
EFI_DEVICE_ERRORThe time could not be set due due to hardware error.

Definition at line 632 of file PcRtc.c.

◆ PcRtcSetTimeZone()

EFI_STATUS PcRtcSetTimeZone ( IN INT16  TimeZone,
IN UINT8  Daylight,
IN PC_RTC_MODULE_GLOBALS Global 
)

Sets the current local timezone & daylight information.

Parameters
TimeZoneTimezone info.
DaylightDaylight info.
GlobalFor global use inside this module.
Return values
EFI_SUCCESSThe operation completed successfully.
EFI_DEVICE_ERRORThe variable could not be set due due to hardware error.

Definition at line 203 of file PcRtc.c.

◆ PcRtcSetWakeupTime()

EFI_STATUS PcRtcSetWakeupTime ( IN BOOLEAN  Enable,
IN EFI_TIME *Time  OPTIONAL,
IN PC_RTC_MODULE_GLOBALS Global 
)

Sets the system wakeup alarm clock time.

Parameters
EnabledEnable or disable the wakeup alarm.
TimeIf Enable is TRUE, the time to set the wakeup alarm for. If Enable is FALSE, then this parameter is optional, and may be NULL.
GlobalFor global use inside this module.
Return values
EFI_SUCCESSIf Enable is TRUE, then the wakeup alarm was enabled. If Enable is FALSE, then the wakeup alarm was disabled.
EFI_INVALID_PARAMETERA time field is out of range.
EFI_DEVICE_ERRORThe wakeup time could not be set due to a hardware error.
EFI_UNSUPPORTEDA wakeup timer is not supported on this platform.

Definition at line 868 of file PcRtc.c.

◆ RtcRead()

STATIC UINT8 RtcRead ( IN UINTN  Address)

Read RTC content through its registers.

Parameters
AddressAddress offset of RTC. It is recommended to use macros such as RTC_ADDRESS_SECONDS.
Returns
The data of UINT8 type read from RTC.

Definition at line 158 of file PcRtc.c.

◆ RtcTimeFieldsValid()

EFI_STATUS RtcTimeFieldsValid ( IN EFI_TIME Time)

See if all fields of a variable of EFI_TIME type is correct.

Parameters
TimeThe time to be checked.
Return values
EFI_INVALID_PARAMETERSome fields of Time are not correct.
EFI_SUCCESSTime is a valid EFI_TIME variable.

Definition at line 1169 of file PcRtc.c.

◆ RtcWaitToUpdate()

EFI_STATUS RtcWaitToUpdate ( UINTN  Timeout)

Wait for a period for the RTC to be ready.

Parameters
TimeoutTell how long it should take to wait.
Return values
EFI_DEVICE_ERRORRTC device error.
EFI_SUCCESSRTC is updated and ready.

Definition at line 1124 of file PcRtc.c.

◆ RtcWrite()

STATIC VOID RtcWrite ( IN UINTN  Address,
IN UINT8  Data 
)

Write RTC through its registers.

Parameters
AddressAddress offset of RTC. It is recommended to use macros such as RTC_ADDRESS_SECONDS.
DataThe content you want to write into RTC.

Definition at line 179 of file PcRtc.c.

Variable Documentation

◆ mDayOfMonth

UINTN mDayOfMonth[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }

Definition at line 22 of file PcRtc.c.

◆ mMaximalValidYear

UINT16 mMaximalValidYear
extern

Definition at line 23 of file PcRtcEntry.c.

◆ mMinimalValidYear

UINT16 mMinimalValidYear
extern

Definition at line 22 of file PcRtcEntry.c.

◆ mRtcDefaultYear

UINT16 mRtcDefaultYear
extern

Definition at line 21 of file PcRtcEntry.c.

◆ mRtcIndexRegister

UINTN mRtcIndexRegister
extern

Definition at line 19 of file PcRtcEntry.c.

◆ mRtcTargetRegister

UINTN mRtcTargetRegister
extern

Definition at line 20 of file PcRtcEntry.c.

◆ mTimeZoneVariableName

CHAR16 mTimeZoneVariableName[] = L"RTC"

Definition at line 27 of file PcRtc.c.