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 <lv.zheng@intel.com>
This commit is contained in:
Lv Zheng 2016-05-23 23:54:43 +08:00
parent 370047064c
commit 27a9dec7e5
4 changed files with 133 additions and 4 deletions

View File

@ -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;

View File

@ -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;

View File

@ -1190,6 +1190,7 @@ efi_main (
ST = SystemTab;
BS = SystemTab->BootServices;
RT = SystemTab->RuntimeServices;
/* Disable the platform watchdog timer if we go interactive */

View File

@ -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