3 Copyright (c) 2006 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 UNIX Emulation Metronome Architectural Protocol Driver as defined in DXE CIS
23 #include <Protocol/Metronome.h>
24 #include "Metronome.h"
26 #include <Library/BaseLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/UefiLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UnixLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
37 EFI_METRONOME_ARCH_PROTOCOL mMetronome
= {
38 UnixMetronomeDriverWaitForTick
,
48 UnixMetronomeDriverWaitForTick (
49 IN EFI_METRONOME_ARCH_PROTOCOL
*This
,
56 The WaitForTick() function waits for the number of ticks specified by
57 TickNumber from a known time source in the platform. If TickNumber of
58 ticks are detected, then EFI_SUCCESS is returned. The actual time passed
59 between entry of this function and the first tick is between 0 and
60 TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod
61 time has elapsed, wait for two ticks. This function waits for a hardware
62 event to determine when a tick occurs. It is possible for interrupt
63 processing, or exception processing to interrupt the execution of the
64 WaitForTick() function. Depending on the hardware source for the ticks, it
65 is possible for a tick to be missed. This function cannot guarantee that
66 ticks will not be missed. If a timeout occurs waiting for the specified
67 number of ticks, then EFI_TIMEOUT is returned.
71 This - The EFI_METRONOME_ARCH_PROTOCOL instance.
72 TickNumber - Number of ticks to wait.
76 EFI_SUCCESS - The wait for the number of ticks specified by TickNumber
84 // Calculate the time to sleep. Win API smallest unit to sleep is 1 millisec
85 // Tick Period is in 100ns units, divide by 10000 to convert to ms
87 SleepTime
= DivU64x32 (MultU64x32 ((UINT64
) TickNumber
, TICK_PERIOD
) + 9999, 10000);
88 gUnix
->Sleep ((UINT32
) SleepTime
);
96 UnixMetronomeDriverInitialize (
97 IN EFI_HANDLE ImageHandle
,
98 IN EFI_SYSTEM_TABLE
*SystemTable
104 Initialize the Metronome Architectural Protocol driver
108 ImageHandle - ImageHandle of the loaded driver
111 SystemTable - Pointer to the System Table
115 EFI_SUCCESS - Metronome Architectural Protocol created
117 EFI_OUT_OF_RESOURCES - Not enough resources available to initialize driver.
119 EFI_DEVICE_ERROR - A device error occured attempting to initialize the driver.
128 // Install the Metronome Architectural Protocol onto a new handle
131 DEBUG ((EFI_D_ERROR
, "*******************file %d line %d\n", __FUNCTION__
, __LINE__
));
132 Status
= gBS
->InstallProtocolInterface (
134 &gEfiMetronomeArchProtocolGuid
,
135 EFI_NATIVE_INTERFACE
,