From 27a9dec7e5d613e1be7419a362676609a8a92cc6 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Mon, 23 May 2016 23:54:43 +0800 Subject: EFI: Add AcpiOsGetTimer() support This patch adds AcpiOsGetTimer() support for EFI environment. Note that currently we don't support timezone. Lv Zheng. Signed-off-by: Lv Zheng --- source/include/platform/acefi.h | 2 + source/include/platform/acefiex.h | 73 +++++++++++++++++++++++++-- source/os_specific/service_layers/oseficlib.c | 1 + source/os_specific/service_layers/osefixf.c | 61 ++++++++++++++++++++++ 4 files changed, 133 insertions(+), 4 deletions(-) diff --git a/source/include/platform/acefi.h b/source/include/platform/acefi.h index 4e1bca132..c24b3058c 100644 --- a/source/include/platform/acefi.h +++ b/source/include/platform/acefi.h @@ -325,10 +325,12 @@ struct _SIMPLE_INPUT_INTERFACE; struct _EFI_FILE_IO_INTERFACE; struct _EFI_FILE_HANDLE; struct _EFI_BOOT_SERVICES; +struct _EFI_RUNTIME_SERVICES; struct _EFI_SYSTEM_TABLE; extern struct _EFI_SYSTEM_TABLE *ST; extern struct _EFI_BOOT_SERVICES *BS; +extern struct _EFI_RUNTIME_SERVICES *RT; typedef union acpi_efi_file ACPI_EFI_FILE; diff --git a/source/include/platform/acefiex.h b/source/include/platform/acefiex.h index f78f034ad..fc1438738 100644 --- a/source/include/platform/acefiex.h +++ b/source/include/platform/acefiex.h @@ -615,6 +615,27 @@ EFI_STATUS VOID *Buffer); +/* + * EFI Time + */ +typedef struct { + UINT32 Resolution; + UINT32 Accuracy; + BOOLEAN SetsToZero; +} EFI_TIME_CAPABILITIES; + +typedef +EFI_STATUS +(EFIAPI *EFI_GET_TIME) ( + EFI_TIME *Time, + EFI_TIME_CAPABILITIES *Capabilities); + +typedef +EFI_STATUS +(EFIAPI *EFI_SET_TIME) ( + EFI_TIME *Time); + + /* * Protocol handler functions */ @@ -879,6 +900,54 @@ typedef struct _EFI_BOOT_SERVICES { } EFI_BOOT_SERVICES; +/* + * EFI Runtime Services Table + */ +#define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552 +#define EFI_RUNTIME_SERVICES_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION) + +typedef struct _EFI_RUNTIME_SERVICES { + EFI_TABLE_HEADER Hdr; + + EFI_GET_TIME GetTime; + EFI_SET_TIME SetTime; +#if 0 + EFI_GET_WAKEUP_TIME GetWakeupTime; + EFI_SET_WAKEUP_TIME SetWakeupTime; +#else + EFI_UNKNOWN_INTERFACE GetWakeupTime; + EFI_UNKNOWN_INTERFACE SetWakeupTime; +#endif + +#if 0 + EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap; + EFI_CONVERT_POINTER ConvertPointer; +#else + EFI_UNKNOWN_INTERFACE SetVirtualAddressMap; + EFI_UNKNOWN_INTERFACE ConvertPointer; +#endif + +#if 0 + EFI_GET_VARIABLE GetVariable; + EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName; + EFI_SET_VARIABLE SetVariable; +#else + EFI_UNKNOWN_INTERFACE GetVariable; + EFI_UNKNOWN_INTERFACE GetNextVariableName; + EFI_UNKNOWN_INTERFACE SetVariable; +#endif + +#if 0 + EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount; + EFI_RESET_SYSTEM ResetSystem; +#else + EFI_UNKNOWN_INTERFACE GetNextHighMonotonicCount; + EFI_UNKNOWN_INTERFACE ResetSystem; +#endif + +} EFI_RUNTIME_SERVICES; + + /* * EFI System Table */ @@ -915,11 +984,7 @@ typedef struct _EFI_SYSTEM_TABLE { EFI_HANDLE StandardErrorHandle; SIMPLE_TEXT_OUTPUT_INTERFACE *StdErr; -#if 0 EFI_RUNTIME_SERVICES *RuntimeServices; -#else - EFI_HANDLE *RuntimeServices; -#endif EFI_BOOT_SERVICES *BootServices; UINTN NumberOfTableEntries; diff --git a/source/os_specific/service_layers/oseficlib.c b/source/os_specific/service_layers/oseficlib.c index 062d1912d..69f92b6d1 100644 --- a/source/os_specific/service_layers/oseficlib.c +++ b/source/os_specific/service_layers/oseficlib.c @@ -1190,6 +1190,7 @@ efi_main ( ST = SystemTab; BS = SystemTab->BootServices; + RT = SystemTab->RuntimeServices; /* Disable the platform watchdog timer if we go interactive */ diff --git a/source/os_specific/service_layers/osefixf.c b/source/os_specific/service_layers/osefixf.c index 2ab8683db..439494cbc 100644 --- a/source/os_specific/service_layers/osefixf.c +++ b/source/os_specific/service_layers/osefixf.c @@ -644,6 +644,67 @@ AcpiOsWriteMemory ( } +/****************************************************************************** + * + * FUNCTION: AcpiOsGetTimer + * + * PARAMETERS: None + * + * RETURN: Current time in 100 nanosecond units + * + * DESCRIPTION: Get the current system time + * + *****************************************************************************/ + +UINT64 +AcpiOsGetTimer ( + void) +{ + EFI_STATUS EfiStatus; + EFI_TIME EfiTime; + int Year, Month, Day; + int Hour, Minute, Second; + UINT64 Timer; + + + EfiStatus = uefi_call_wrapper (RT->GetTime, 2, &EfiTime, NULL); + if (EFI_ERROR (EfiStatus)) + { + return (-1); + } + + Year = EfiTime.Year; + Month = EfiTime.Month; + Day = EfiTime.Day; + Hour = EfiTime.Hour; + Minute = EfiTime.Minute; + Second = EfiTime.Second; + + /* 1..12 -> 11,12,1..10 */ + + if (0 >= (int) (Month -= 2)) + { + /* Feb has leap days */ + + Month += 12; + Year -= 1; + } + + /* Calculate days */ + + Timer = ((UINT64) (Year/4 - Year/100 + Year/400 + 367*Month/12 + Day) + + Year*365 - 719499); + + /* Calculate seconds */ + + Timer = ((Timer*24 + Hour) * 60 + Minute) * 60 + Second; + + /* Calculate 100 nanoseconds */ + + return ((Timer * ACPI_100NSEC_PER_SEC) + (EfiTime.Nanosecond / 100)); +} + + /****************************************************************************** * * FUNCTION: AcpiOsAllocate -- cgit v1.2.1