From: qwang12 Date: Wed, 27 Jun 2007 08:38:05 +0000 (+0000) Subject: add RealTimeClockRuntimeDxe X-Git-Tag: edk2-stable201903~23159 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=49993bedb115f35031982ea48f36f85198e2409a add RealTimeClockRuntimeDxe git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2796 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/Nt32Pkg/RealTimeClockRuntimeDxe/CommonHeader.h b/Nt32Pkg/RealTimeClockRuntimeDxe/CommonHeader.h new file mode 100644 index 0000000000..282122e9db --- /dev/null +++ b/Nt32Pkg/RealTimeClockRuntimeDxe/CommonHeader.h @@ -0,0 +1,36 @@ +/**@file + Common header file shared by all source files. + + This file includes package header files, library classes and protocol, PPI & GUID definitions. + + Copyright (c) 2006 - 2007, Intel Corporation + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#ifndef __COMMON_HEADER_H_ +#define __COMMON_HEADER_H_ + + +// +// The package level header files this module uses +// +#include +#include +// +// The protocols, PPI and GUID defintions for this module +// +#include +// +// The Library classes this module consumes +// +#include +#include +#include +#include + +#endif diff --git a/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.c new file mode 100644 index 0000000000..59adc64952 --- /dev/null +++ b/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.c @@ -0,0 +1,396 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + RealTimeClock.c + +Abstract: + + NT Emulation Architectural Protocol Driver as defined in Tiano + +--*/ + + + +// +// Include common header file for this module. +// +#include "CommonHeader.h" + +BOOLEAN +DayValid ( + IN EFI_TIME *Time + ); + +BOOLEAN +IsLeapYear ( + IN EFI_TIME *Time + ); + +EFI_STATUS +RtcTimeFieldsValid ( + IN EFI_TIME *Time + ); + +EFI_STATUS +EFIAPI +InitializeRealTimeClock ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +STATIC +EFI_STATUS +EFIAPI +WinNtGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL + ) +/*++ + +Routine Description: + Service routine for RealTimeClockInstance->GetTime + +Arguments: + + Time - A pointer to storage that will receive a snapshot of the current time. + + Capabilities - A pointer to storage that will receive the capabilities of the real time clock + in the platform. This includes the real time clock's resolution and accuracy. + All reported device capabilities are rounded up. This is an OPTIONAL argument. + +Returns: + + EFI_SUCEESS - The underlying GetSystemTime call occurred and returned + Note that in the NT32 emulation, the GetSystemTime call has no return value + thus you will always receive a EFI_SUCCESS on this. + +--*/ +// TODO: EFI_INVALID_PARAMETER - add return value to function comment +{ + SYSTEMTIME SystemTime; + TIME_ZONE_INFORMATION TimeZone; + + // + // Check parameter for null pointer + // + if (Time == NULL) { + return EFI_INVALID_PARAMETER; + + } + + gWinNt->GetLocalTime (&SystemTime); + gWinNt->GetTimeZoneInformation (&TimeZone); + + Time->Year = (UINT16) SystemTime.wYear; + Time->Month = (UINT8) SystemTime.wMonth; + Time->Day = (UINT8) SystemTime.wDay; + Time->Hour = (UINT8) SystemTime.wHour; + Time->Minute = (UINT8) SystemTime.wMinute; + Time->Second = (UINT8) SystemTime.wSecond; + Time->Nanosecond = (UINT32) (SystemTime.wMilliseconds * 1000000); + Time->TimeZone = (INT16) TimeZone.Bias; + + if (Capabilities != NULL) { + Capabilities->Resolution = 1; + Capabilities->Accuracy = 50000000; + Capabilities->SetsToZero = FALSE; + } + + Time->Daylight = 0; + if (TimeZone.StandardDate.wMonth) { + Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT; + } + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +EFIAPI +WinNtSetTime ( + IN EFI_TIME *Time + ) +/*++ + +Routine Description: + Service routine for RealTimeClockInstance->SetTime + +Arguments: + + Time - A pointer to storage containing the time and date information to + program into the real time clock. + +Returns: + + EFI_SUCEESS - The operation completed successfully. + + EFI_INVALID_PARAMETER - One of the fields in Time is out of range. + + EFI_DEVICE_ERROR - The operation could not be complete due to a device error. + +--*/ +// TODO: EFI_SUCCESS - add return value to function comment +{ + TIME_ZONE_INFORMATION TimeZone; + EFI_STATUS Status; + SYSTEMTIME SystemTime; + BOOL Flag; + + if (Time == NULL) { + return EFI_INVALID_PARAMETER; + } + // + // Make sure that the time fields are valid + // + Status = RtcTimeFieldsValid (Time); + if (EFI_ERROR (Status)) { + return Status; + } + // + // Set Daylight savings time information and Time Zone + // + gWinNt->GetTimeZoneInformation (&TimeZone); + TimeZone.StandardDate.wMonth = Time->Daylight; + TimeZone.Bias = Time->TimeZone; + gWinNt->SetTimeZoneInformation (&TimeZone); + + SystemTime.wYear = Time->Year; + SystemTime.wMonth = Time->Month; + SystemTime.wDay = Time->Day; + SystemTime.wHour = Time->Hour; + SystemTime.wMinute = Time->Minute; + SystemTime.wSecond = Time->Second; + SystemTime.wMilliseconds = (INT16) (Time->Nanosecond / 1000000); + + Flag = gWinNt->SetLocalTime (&SystemTime); + + if (!Flag) { + return EFI_DEVICE_ERROR; + } else { + return EFI_SUCCESS; + } +} + +STATIC +EFI_STATUS +EFIAPI +WinNtGetWakeupTime ( + OUT BOOLEAN *Enabled, + OUT BOOLEAN *Pending, + OUT EFI_TIME *Time + ) +/*++ + +Routine Description: + Service routine for RealTimeClockInstance->GetWakeupTime + +Arguments: + This - Indicates the protocol instance structure. + + Enabled - Indicates if the alarm is currently enabled or disabled. + + Pending - Indicates if the alarm signal is pending and requires + acknowledgement. + + Time - The current alarm setting. + +Returns: + + EFI_SUCEESS - The operation completed successfully. + + EFI_DEVICE_ERROR - The operation could not be complete due to a device error. + + EFI_UNSUPPORTED - The operation is not supported on this platform. + +--*/ +{ + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +WinNtSetWakeupTime ( + IN BOOLEAN Enable, + OUT EFI_TIME *Time + ) +/*++ + +Routine Description: + Service routine for RealTimeClockInstance->SetWakeupTime + +Arguments: + + Enabled - Enable or disable the wakeup alarm. + + Time - If enable is TRUE, the time to set the wakup alarm for. + If enable is FALSE, then this parameter is optional, and + may be NULL. + +Returns: + + EFI_SUCEESS - The operation completed successfully. + + EFI_DEVICE_ERROR - The operation could not be complete due to a device error. + + EFI_INVALID_PARAMETER - A field in Time is out of range. + + EFI_UNSUPPORTED - The operation is not supported on this platform. + +--*/ +{ + return EFI_UNSUPPORTED; +} + +EFI_STATUS +EFIAPI +InitializeRealTimeClock ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +/*++ + +Routine Description: + Install Real Time Clock Protocol + +Arguments: + (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT) + +Returns: + + EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table + +--*/ +// TODO: ImageHandle - add argument and description to function comment +// TODO: SystemTable - add argument and description to function comment +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + + + SystemTable->RuntimeServices->GetTime = WinNtGetTime; + SystemTable->RuntimeServices->SetTime = WinNtSetTime; + SystemTable->RuntimeServices->GetWakeupTime = WinNtGetWakeupTime; + SystemTable->RuntimeServices->SetWakeupTime = WinNtSetWakeupTime; + + Handle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces ( + &Handle, + &gEfiRealTimeClockArchProtocolGuid, + NULL, + NULL + ); + return Status; +} + +EFI_STATUS +RtcTimeFieldsValid ( + IN EFI_TIME *Time + ) +/*++ + +Routine Description: + + Arguments: + + Returns: +--*/ +// TODO: Time - add argument and description to function comment +// TODO: EFI_INVALID_PARAMETER - add return value to function comment +// TODO: EFI_SUCCESS - add return value to function comment +{ + if (Time->Year < 1998 || + Time->Year > 2099 || + Time->Month < 1 || + Time->Month > 12 || + (!DayValid (Time)) || + Time->Hour > 23 || + Time->Minute > 59 || + Time->Second > 59 || + Time->Nanosecond > 999999999 || + (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) || + (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT))) + ) { + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +BOOLEAN +DayValid ( + IN EFI_TIME *Time + ) +/*++ + +Routine Description: + + TODO: Add function description + +Arguments: + + Time - TODO: add argument description + +Returns: + + TODO: add return values + +--*/ +{ + + INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + + if (Time->Day < 1 || + Time->Day > DayOfMonth[Time->Month - 1] || + (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28)) + ) { + return FALSE; + } + + return TRUE; +} + +BOOLEAN +IsLeapYear ( + IN EFI_TIME *Time + ) +/*++ + +Routine Description: + + TODO: Add function description + +Arguments: + + Time - TODO: add argument description + +Returns: + + TODO: add return values + +--*/ +{ + if (Time->Year % 4 == 0) { + if (Time->Year % 100 == 0) { + if (Time->Year % 400 == 0) { + return TRUE; + } else { + return FALSE; + } + } else { + return TRUE; + } + } else { + return FALSE; + } +} diff --git a/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.dxs b/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.dxs new file mode 100644 index 0000000000..314ea42c58 --- /dev/null +++ b/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.dxs @@ -0,0 +1,31 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + RealTimeClock.dxs + +Abstract: + + Dependency expression source file. + +--*/ + +// +// Include common header file for this module. +// +#include "CommonHeader.h" + +#include + +DEPENDENCY_START + TRUE +DEPENDENCY_END diff --git a/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.inf b/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.inf new file mode 100644 index 0000000000..e289548a82 --- /dev/null +++ b/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.inf @@ -0,0 +1,95 @@ +#/** @file +# NT Emulation Real time clock Architectural Protocol Driver as defined in TIANO +# +# This real time clock module simulates virtual device by time WinAPI. +# Copyright (c) 2006 - 2007, Intel Corporation +# +# All rights reserved. This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = RealTimeClock + FILE_GUID = 27F05AF5-1644-4EF4-8944-48C4F75675A0 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + ENTRY_POINT = InitializeRealTimeClock + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 +# + +################################################################################ +# +# Sources Section - list of files that are required for the build to succeed. +# +################################################################################ + +[Sources.common] + RealTimeClock.dxs + RealTimeClock.c + CommonHeader.h + + +################################################################################ +# +# Includes Section - list of Include locations that are required for +# this module. +# +################################################################################ + +[Includes] + $(WORKSPACE)/MdePkg/Include/Library + +################################################################################ +# +# Package Dependency Section - list of Package files that are required for +# this module. +# +################################################################################ + +[Packages] + MdePkg/MdePkg.dec + + +################################################################################ +# +# Library Class Section - list of Library Classes that are required for +# this module. +# +################################################################################ + +[LibraryClasses] + UefiBootServicesTableLib + WinNtLib + UefiDriverEntryPoint + DebugLib + + +################################################################################ +# +# Protocol C Name Section - list of Protocol and Protocol Notify C Names +# that this module uses or produces. +# +################################################################################ + +[Protocols] + gEfiRealTimeClockArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED + diff --git a/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.msa b/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.msa new file mode 100644 index 0000000000..0fe3cd09bf --- /dev/null +++ b/Nt32Pkg/RealTimeClockRuntimeDxe/RealTimeClock.msa @@ -0,0 +1,58 @@ + + + + RealTimeClock + DXE_DRIVER + 27F05AF5-1644-4EF4-8944-48C4F75675A0 + 1.0 + NT Emulation Real time clock Architectural Protocol Driver as defined in TIANO + This real time clock module simulates virtual device by time WinAPI. + Copyright (c) 2006 - 2007, Intel Corporation + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052 + + + IA32 + false + RealTimeClock + + + + DebugLib + + + UefiDriverEntryPoint + + + WinNtLib + + + UefiBootServicesTableLib + + + + RealTimeClock.c + RealTimeClock.dxs + + + + + + + + gEfiRealTimeClockArchProtocolGuid + + + + EFI_SPECIFICATION_VERSION 0x00020000 + EDK_RELEASE_VERSION 0x00020000 + + InitializeRealTimeClock + + + \ No newline at end of file