InOsEmuPkg: Add TimerLib for PEI, DXE_CORE, and DXE/EFI drivers/applications.

Start using MdeModulePkg MetronomeDxe driver. Add PEI and DXE_CORE TimerLibs that just call back to the emulator. Add a DXE/UEFI TimerLib that also does a gBS->WaitForEvent() if the stall is for a long period of time. Change the Thunk API for Sleep to nanoseconds. 

Signed-off-by: andrewfish


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11872 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
andrewfish 2011-06-21 23:41:31 +00:00
parent 090f3fdbf9
commit 1ef41207dc
16 changed files with 672 additions and 256 deletions

View File

@ -1221,7 +1221,7 @@ CpuDriverApIdolLoop (
// Poll 5 times a seconds, 200ms
// Don't want to burn too many system resources doing nothing.
gEmuThunk->Sleep (200);
gEmuThunk->Sleep (200 * 1000);
}
return 0;

View File

@ -0,0 +1,128 @@
/** @file
A non-functional instance of the Timer Library.
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#include <PiPei.h>
#include <Library/TimerLib.h>
#include <Library/DebugLib.h>
#include <Library/EmuThunkLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/Timer.h>
/**
Stalls the CPU for at least the given number of microseconds.
Stalls the CPU for the number of microseconds specified by MicroSeconds.
@param MicroSeconds The minimum number of microseconds to delay.
@return The value of MicroSeconds inputted.
**/
UINTN
EFIAPI
MicroSecondDelay (
IN UINTN MicroSeconds
)
{
return NanoSecondDelay (MicroSeconds * 1000);
}
/**
Stalls the CPU for at least the given number of nanoseconds.
Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
@param NanoSeconds The minimum number of nanoseconds to delay.
@return The value of NanoSeconds inputted.
**/
UINTN
EFIAPI
NanoSecondDelay (
IN UINTN NanoSeconds
)
{
gEmuThunk->Sleep (NanoSeconds);
return NanoSeconds;
}
/**
Retrieves the current value of a 64-bit free running performance counter.
The counter can either count up by 1 or count down by 1. If the physical
performance counter counts by a larger increment, then the counter values
must be translated. The properties of the counter can be retrieved from
GetPerformanceCounterProperties().
@return The current value of the free running performance counter.
**/
UINT64
EFIAPI
GetPerformanceCounter (
VOID
)
{
return gEmuThunk->QueryPerformanceCounter ();
}
/**
Retrieves the 64-bit frequency in Hz and the range of performance counter
values.
If StartValue is not NULL, then the value that the performance counter starts
with immediately after is it rolls over is returned in StartValue. If
EndValue is not NULL, then the value that the performance counter end with
immediately before it rolls over is returned in EndValue. The 64-bit
frequency of the performance counter in Hz is always returned. If StartValue
is less than EndValue, then the performance counter counts up. If StartValue
is greater than EndValue, then the performance counter counts down. For
example, a 64-bit free running counter that counts up would have a StartValue
of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
@param StartValue The value the performance counter starts with when it
rolls over.
@param EndValue The value that the performance counter ends with before
it rolls over.
@return The frequency in Hz.
**/
UINT64
EFIAPI
GetPerformanceCounterProperties (
OUT UINT64 *StartValue, OPTIONAL
OUT UINT64 *EndValue OPTIONAL
)
{
if (StartValue != NULL) {
*StartValue = 0ULL;
}
if (EndValue != NULL) {
*EndValue = (UINT64)-1LL;
}
return gEmuThunk->QueryPerformanceFrequency ();
}

View File

@ -0,0 +1,44 @@
## @file
# NULL instance of Timer Library as a template.
#
# A non-functional instance of the Timer Library that can be used as a template
# for the implementation of a functional timer library instance. This library instance can
# also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules that require timer
# services as well as EBC modules that require timer services.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# 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]
INF_VERSION = 0x00010005
BASE_NAME = EmuDxeCodeTimerLib
FILE_GUID = FB184AF4-A2F2-EE4E-8885-E81E5D8B0135
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = TimerLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
DxeCoreTimerLib.c
[Packages]
MdePkg/MdePkg.dec
InOsEmuPkg/InOsEmuPkg.dec
[LibraryClasses]
DebugLib
EmuThunkLib

View File

@ -0,0 +1,206 @@
/** @file
A non-functional instance of the Timer Library.
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/TimerLib.h>
#include <Library/DebugLib.h>
#include <Library/EmuThunkLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/Timer.h>
STATIC UINT64 gTimerPeriod = 0;
STATIC EFI_TIMER_ARCH_PROTOCOL *gTimerAp = NULL;
STATIC EFI_EVENT gTimerEvent = NULL;
STATIC VOID *gRegistration = NULL;
VOID
EFIAPI
RegisterTimerArchProtocol (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **)&gTimerAp);
if (!EFI_ERROR (Status)) {
Status = gTimerAp->GetTimerPeriod (gTimerAp, &gTimerPeriod);
ASSERT_EFI_ERROR (Status);
// Convert to Nanoseconds.
gTimerPeriod = MultU64x32 (gTimerPeriod, 100);
if (gTimerEvent == NULL) {
Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, (VOID **)&gTimerEvent);
ASSERT_EFI_ERROR (Status);
}
}
}
/**
Stalls the CPU for at least the given number of microseconds.
Stalls the CPU for the number of microseconds specified by MicroSeconds.
@param MicroSeconds The minimum number of microseconds to delay.
@return The value of MicroSeconds inputted.
**/
UINTN
EFIAPI
MicroSecondDelay (
IN UINTN MicroSeconds
)
{
return NanoSecondDelay (MicroSeconds * 1000);
}
/**
Stalls the CPU for at least the given number of nanoseconds.
Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
@param NanoSeconds The minimum number of nanoseconds to delay.
@return The value of NanoSeconds inputted.
**/
UINTN
EFIAPI
NanoSecondDelay (
IN UINTN NanoSeconds
)
{
EFI_STATUS Status;
UINT64 HundredNanoseconds;
UINTN Index;
if ((gTimerPeriod != 0) &&
((UINT64)NanoSeconds > gTimerPeriod) &&
(EfiGetCurrentTpl () == TPL_APPLICATION)) {
//
// This stall is long, so use gBS->WaitForEvent () to yield CPU to DXE Core
//
HundredNanoseconds = DivU64x32 (NanoSeconds, 100);
Status = gBS->SetTimer (gTimerEvent, TimerRelative, HundredNanoseconds);
ASSERT_EFI_ERROR (Status);
Status = gBS->WaitForEvent (sizeof (gTimerEvent)/sizeof (EFI_EVENT), &gTimerEvent, &Index);
ASSERT_EFI_ERROR (Status);
} else {
gEmuThunk->Sleep (NanoSeconds);
}
return NanoSeconds;
}
/**
Retrieves the current value of a 64-bit free running performance counter.
The counter can either count up by 1 or count down by 1. If the physical
performance counter counts by a larger increment, then the counter values
must be translated. The properties of the counter can be retrieved from
GetPerformanceCounterProperties().
@return The current value of the free running performance counter.
**/
UINT64
EFIAPI
GetPerformanceCounter (
VOID
)
{
return gEmuThunk->QueryPerformanceCounter ();
}
/**
Retrieves the 64-bit frequency in Hz and the range of performance counter
values.
If StartValue is not NULL, then the value that the performance counter starts
with immediately after is it rolls over is returned in StartValue. If
EndValue is not NULL, then the value that the performance counter end with
immediately before it rolls over is returned in EndValue. The 64-bit
frequency of the performance counter in Hz is always returned. If StartValue
is less than EndValue, then the performance counter counts up. If StartValue
is greater than EndValue, then the performance counter counts down. For
example, a 64-bit free running counter that counts up would have a StartValue
of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
@param StartValue The value the performance counter starts with when it
rolls over.
@param EndValue The value that the performance counter ends with before
it rolls over.
@return The frequency in Hz.
**/
UINT64
EFIAPI
GetPerformanceCounterProperties (
OUT UINT64 *StartValue, OPTIONAL
OUT UINT64 *EndValue OPTIONAL
)
{
if (StartValue != NULL) {
*StartValue = 0ULL;
}
if (EndValue != NULL) {
*EndValue = (UINT64)-1LL;
}
return gEmuThunk->QueryPerformanceFrequency ();
}
/**
Register for the Timer AP protocol.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
DxeTimerLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EfiCreateProtocolNotifyEvent (
&gEfiTimerArchProtocolGuid,
TPL_CALLBACK,
RegisterTimerArchProtocol,
NULL,
&gRegistration
);
return EFI_SUCCESS;
}

View File

@ -0,0 +1,51 @@
## @file
# NULL instance of Timer Library as a template.
#
# A non-functional instance of the Timer Library that can be used as a template
# for the implementation of a functional timer library instance. This library instance can
# also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules that require timer
# services as well as EBC modules that require timer services.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# 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]
INF_VERSION = 0x00010005
BASE_NAME = EmuDxeTimerLib
FILE_GUID = 74B62391-AD0D-1B4D-8784-151404F9D538
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = TimerLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION
CONSTRUCTOR = DxeTimerLibConstructor
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
DxeTimerLib.c
[Packages]
MdePkg/MdePkg.dec
InOsEmuPkg/InOsEmuPkg.dec
[LibraryClasses]
BaseLib
DebugLib
EmuThunkLib
UefiLib
UefiBootServicesTableLib
[Protocols]
gEfiTimerArchProtocolGuid

View File

@ -0,0 +1,174 @@
/** @file
A non-functional instance of the Timer Library.
Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#include <PiPei.h>
#include <Library/TimerLib.h>
#include <Library/DebugLib.h>
#include <Library/PeiServicesLib.h>
#include <Ppi/EmuThunk.h>
#include <Protocol/EmuThunk.h>
/**
Stalls the CPU for at least the given number of microseconds.
Stalls the CPU for the number of microseconds specified by MicroSeconds.
@param MicroSeconds The minimum number of microseconds to delay.
@return The value of MicroSeconds inputted.
**/
UINTN
EFIAPI
MicroSecondDelay (
IN UINTN MicroSeconds
)
{
return NanoSecondDelay (MicroSeconds * 1000);
}
/**
Stalls the CPU for at least the given number of nanoseconds.
Stalls the CPU for the number of nanoseconds specified by NanoSeconds.
@param NanoSeconds The minimum number of nanoseconds to delay.
@return The value of NanoSeconds inputted.
**/
UINTN
EFIAPI
NanoSecondDelay (
IN UINTN NanoSeconds
)
{
EMU_THUNK_PPI *ThunkPpi;
EFI_STATUS Status;
EMU_THUNK_PROTOCOL *Thunk;
//
// Locate EmuThunkPpi for
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid,
0,
NULL,
(VOID **) &ThunkPpi
);
if (!EFI_ERROR (Status)) {
Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
Thunk->Sleep (NanoSeconds * 100);
return NanoSeconds;
}
return 0;
}
/**
Retrieves the current value of a 64-bit free running performance counter.
The counter can either count up by 1 or count down by 1. If the physical
performance counter counts by a larger increment, then the counter values
must be translated. The properties of the counter can be retrieved from
GetPerformanceCounterProperties().
@return The current value of the free running performance counter.
**/
UINT64
EFIAPI
GetPerformanceCounter (
VOID
)
{
EMU_THUNK_PPI *ThunkPpi;
EFI_STATUS Status;
EMU_THUNK_PROTOCOL *Thunk;
//
// Locate EmuThunkPpi for
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid,
0,
NULL,
(VOID **) &ThunkPpi
);
if (!EFI_ERROR (Status)) {
Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
return Thunk->QueryPerformanceCounter ();
}
return 0;
}
/**
Retrieves the 64-bit frequency in Hz and the range of performance counter
values.
If StartValue is not NULL, then the value that the performance counter starts
with immediately after is it rolls over is returned in StartValue. If
EndValue is not NULL, then the value that the performance counter end with
immediately before it rolls over is returned in EndValue. The 64-bit
frequency of the performance counter in Hz is always returned. If StartValue
is less than EndValue, then the performance counter counts up. If StartValue
is greater than EndValue, then the performance counter counts down. For
example, a 64-bit free running counter that counts up would have a StartValue
of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter
that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.
@param StartValue The value the performance counter starts with when it
rolls over.
@param EndValue The value that the performance counter ends with before
it rolls over.
@return The frequency in Hz.
**/
UINT64
EFIAPI
GetPerformanceCounterProperties (
OUT UINT64 *StartValue, OPTIONAL
OUT UINT64 *EndValue OPTIONAL
)
{
EMU_THUNK_PPI *ThunkPpi;
EFI_STATUS Status;
EMU_THUNK_PROTOCOL *Thunk;
//
// Locate EmuThunkPpi for
//
Status = PeiServicesLocatePpi (
&gEmuThunkPpiGuid,
0,
NULL,
(VOID **) &ThunkPpi
);
if (!EFI_ERROR (Status)) {
if (StartValue != NULL) {
*StartValue = 0ULL;
}
if (EndValue != NULL) {
*EndValue = (UINT64)-1LL;
}
Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();
return Thunk->QueryPerformanceFrequency ();
}
return 0;
}

View File

@ -0,0 +1,47 @@
## @file
# NULL instance of Timer Library as a template.
#
# A non-functional instance of the Timer Library that can be used as a template
# for the implementation of a functional timer library instance. This library instance can
# also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules that require timer
# services as well as EBC modules that require timer services.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
#
# 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]
INF_VERSION = 0x00010005
BASE_NAME = EmuPeiTimerLib
FILE_GUID = 6ABE5FDC-AE4B-474E-8E52-9546C96AE536
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = TimerLib|PEIM PEI_CORE SEC
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
PeiTimerLib.c
[Packages]
MdePkg/MdePkg.dec
InOsEmuPkg/InOsEmuPkg.dec
[LibraryClasses]
DebugLib
PeiServicesLib
[Ppis]
gEmuThunkPpiGuid

View File

@ -1,125 +0,0 @@
/*++ @file
Emu Emulation Metronome Architectural Protocol Driver as defined in DXE CIS
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2010 - 2011, Apple Inc. 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.
**/
#include "Metronome.h"
//
// Global Variables
//
EFI_METRONOME_ARCH_PROTOCOL mMetronome = {
EmuMetronomeDriverWaitForTick,
TICK_PERIOD
};
//
// Worker Functions
//
EFI_STATUS
EFIAPI
EmuMetronomeDriverWaitForTick (
IN EFI_METRONOME_ARCH_PROTOCOL *This,
IN UINT32 TickNumber
)
/*++
Routine Description:
The WaitForTick() function waits for the number of ticks specified by
TickNumber from a known time source in the platform. If TickNumber of
ticks are detected, then EFI_SUCCESS is returned. The actual time passed
between entry of this function and the first tick is between 0 and
TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod
time has elapsed, wait for two ticks. This function waits for a hardware
event to determine when a tick occurs. It is possible for interrupt
processing, or exception processing to interrupt the execution of the
WaitForTick() function. Depending on the hardware source for the ticks, it
is possible for a tick to be missed. This function cannot guarantee that
ticks will not be missed. If a timeout occurs waiting for the specified
number of ticks, then EFI_TIMEOUT is returned.
Arguments:
This - The EFI_METRONOME_ARCH_PROTOCOL instance.
TickNumber - Number of ticks to wait.
Returns:
EFI_SUCCESS - The wait for the number of ticks specified by TickNumber
succeeded.
**/
{
UINT64 SleepTime;
//
// Calculate the time to sleep. Emu smallest unit to sleep is 1 millisec
// Tick Period is in 100ns units, divide by 10000 to convert to ms
//
SleepTime = DivU64x32 (MultU64x32 ((UINT64) TickNumber, TICK_PERIOD) + 9999, 10000);
gEmuThunk->Sleep (SleepTime);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
EmuMetronomeDriverInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Initialize the Metronome Architectural Protocol driver
Arguments:
ImageHandle - ImageHandle of the loaded driver
SystemTable - Pointer to the System Table
Returns:
EFI_SUCCESS - Metronome Architectural Protocol created
EFI_OUT_OF_RESOURCES - Not enough resources available to initialize driver.
EFI_DEVICE_ERROR - A device error occured attempting to initialize the driver.
**/
{
EFI_STATUS Status;
EFI_HANDLE Handle;
//
// Install the Metronome Architectural Protocol onto a new handle
//
Handle = NULL;
Status = gBS->InstallProtocolInterface (
&Handle,
&gEfiMetronomeArchProtocolGuid,
EFI_NATIVE_INTERFACE,
&mMetronome
);
return Status;
}

View File

@ -1,56 +0,0 @@
/*++ @file
Emu Emulation Metronome Architectural Protocol Driver as defined in DXE CIS
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2010 - 2011, Apple Inc. 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 _EMU_THUNK_METRONOME_H_
#define _EMU_THUNK_METRONOME_H_
#include <PiDxe.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/EmuThunkLib.h>
#include <Protocol/Metronome.h>
//
// Period of on tick in 100 nanosecond units
//
#define TICK_PERIOD 2000
//
// Function Prototypes
//
EFI_STATUS
EFIAPI
EmuMetronomeDriverInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
EFI_STATUS
EFIAPI
EmuMetronomeDriverWaitForTick (
IN EFI_METRONOME_ARCH_PROTOCOL *This,
IN UINT32 TickNumber
);
#endif

View File

@ -1,59 +0,0 @@
## @file
# Emu Emulation Metronome Architectural Protocol Driver as defined in DXE CIS
#
# This metronome module simulates metronome by Sleep WinAPI.
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Portions copyright (c) 2011, Apple Inc. 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]
INF_VERSION = 0x00010005
BASE_NAME = Metronome
FILE_GUID = f348f6fe-8985-11db-b4c3-0040d02b1835
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = EmuMetronomeDriverInitialize
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
Metronome.h
Metronome.c
[Packages]
MdePkg/MdePkg.dec
InOsEmuPkg/InOsEmuPkg.dec
[LibraryClasses]
UefiBootServicesTableLib
MemoryAllocationLib
EmuThunkLib
UefiDriverEntryPoint
UefiLib
DebugLib
BaseLib
[Protocols]
gEfiMetronomeArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED
[Depex]
TRUE

View File

@ -325,6 +325,14 @@ Returns:
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (void *)&mCpu);
ASSERT_EFI_ERROR (Status);
//
// Start the timer thread at the default timer period
//
Status = mTimer.SetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATION);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Install the Timer Architectural Protocol onto a new handle
//
@ -339,13 +347,6 @@ Returns:
return Status;
}
//
// Start the timer thread at the default timer period
//
Status = mTimer.SetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATION);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}

View File

@ -250,15 +250,15 @@ QueryPerformanceCounter (
VOID
SecSleep (
IN UINT64 Milliseconds
IN UINT64 Nanoseconds
)
{
struct timespec rq, rm;
struct timeval start, end;
unsigned long MicroSec;
rq.tv_sec = Milliseconds / 1000;
rq.tv_nsec = (Milliseconds % 1000) * 1000000;
rq.tv_sec = Nanoseconds / 1000000000;
rq.tv_nsec = Nanoseconds % 1000000000;
//
// nanosleep gets interrupted by our timer tic.

View File

@ -109,7 +109,7 @@ GasketQueryPerformanceCounter (
VOID
EFIAPI
GasketSecSleep (
IN UINT64 Milliseconds
IN UINT64 Nanoseconds
);
VOID

View File

@ -336,7 +336,7 @@ MapFd0 (
VOID SecSleep (UINT64 Milliseconds);
VOID SecSleep (UINT64 Nanoseconds);
VOID SecEnableInterrupt (VOID);
VOID SecDisableInterrupt (VOID);
BOOLEAN SecInterruptEanbled (VOID);

View File

@ -124,6 +124,7 @@
SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf
PpiListLib|InOsEmuPkg/Library/SecPpiListLib/SecPpiListLib.inf
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
TimerLib|InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.inf
[LibraryClasses.common.USER_DEFINED, LibraryClasses.common.BASE]
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
@ -147,6 +148,7 @@
ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
SerialPortLib|InOsEmuPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf
ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
TimerLib|InOsEmuPkg/Library/PeiTimerLib/PeiTimerLib.inf
[LibraryClasses.common.PEI_CORE]
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
@ -161,6 +163,8 @@
PeCoffExtraActionLib|InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf
ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
TimerLib|InOsEmuPkg/Library/DxeCoreTimerLib/DxeCoreTimerLib.inf
EmuThunkLib|InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.inf
[LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.UEFI_APPLICATION]
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
@ -170,6 +174,7 @@
EmuThunkLib|InOsEmuPkg/Library/DxeEmuLib/DxeEmuLib.inf
PeCoffExtraActionLib|InOsEmuPkg/Library/DxeEmuPeCoffExtraActionLib/DxeEmuPeCoffExtraActionLib.inf
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
TimerLib|InOsEmuPkg/Library/DxeTimerLib/DxeTimerLib.inf
[LibraryClasses.common.UEFI_DRIVER]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
@ -340,7 +345,7 @@
SerialPortLib|InOsEmuPkg/Library/DxeEmuStdErrSerialPortLib/DxeEmuStdErrSerialPortLib.inf
}
InOsEmuPkg/MetronomeDxe/Metronome.inf
MdeModulePkg/Universal/Metronome/Metronome.inf
InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf
InOsEmuPkg/ResetRuntimeDxe/Reset.inf
MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

View File

@ -165,7 +165,7 @@ APRIORI PEI {
}
APRIORI DXE {
INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
INF InOsEmuPkg/MetronomeDxe/Metronome.inf
INF MdeModulePkg/Universal/Metronome/Metronome.inf
}
INF InOsEmuPkg/Sec/Sec.inf
INF MdeModulePkg/Core/Pei/PeiMain.inf
@ -187,7 +187,7 @@ INF MdeModulePkg/Core/Dxe/DxeMain.inf
INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf
INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf
INF InOsEmuPkg/MetronomeDxe/Metronome.inf
INF MdeModulePkg/Universal/Metronome/Metronome.inf
INF InOsEmuPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf
INF InOsEmuPkg/ResetRuntimeDxe/Reset.inf
INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf