Home | History | Annotate | Download | only in MetronomeDxe
      1 /**@file
      2 
      3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
      4 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
      8 
      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.
     11 
     12 Module Name:
     13 
     14   Metronome.c
     15 
     16 Abstract:
     17 
     18   NT Emulation Metronome Architectural Protocol Driver as defined in DXE CIS
     19 
     20 **/
     21 
     22 #include "Metronome.h"
     23 
     24 //
     25 // Global Variables
     26 //
     27 EFI_METRONOME_ARCH_PROTOCOL mMetronome = {
     28   WinNtMetronomeDriverWaitForTick,
     29   TICK_PERIOD
     30 };
     31 
     32 //
     33 // Worker Functions
     34 //
     35 
     36 EFI_STATUS
     37 EFIAPI
     38 WinNtMetronomeDriverWaitForTick (
     39   IN EFI_METRONOME_ARCH_PROTOCOL  *This,
     40   IN UINT32                       TickNumber
     41   )
     42 /*++
     43 
     44 Routine Description:
     45 
     46   The WaitForTick() function waits for the number of ticks specified by
     47   TickNumber from a known time source in the platform.  If TickNumber of
     48   ticks are detected, then EFI_SUCCESS is returned.  The actual time passed
     49   between entry of this function and the first tick is between 0 and
     50   TickPeriod 100 nS units.  If you want to guarantee that at least TickPeriod
     51   time has elapsed, wait for two ticks.  This function waits for a hardware
     52   event to determine when a tick occurs.  It is possible for interrupt
     53   processing, or exception processing to interrupt the execution of the
     54   WaitForTick() function.  Depending on the hardware source for the ticks, it
     55   is possible for a tick to be missed.  This function cannot guarantee that
     56   ticks will not be missed.  If a timeout occurs waiting for the specified
     57   number of ticks, then EFI_TIMEOUT is returned.
     58 
     59 Arguments:
     60 
     61   This       - The EFI_METRONOME_ARCH_PROTOCOL instance.
     62   TickNumber - Number of ticks to wait.
     63 
     64 Returns:
     65 
     66   EFI_SUCCESS - The wait for the number of ticks specified by TickNumber
     67                 succeeded.
     68 
     69 --*/
     70 {
     71   UINT64  SleepTime;
     72 
     73   //
     74   // Calculate the time to sleep.  Win API smallest unit to sleep is 1 millisec
     75   // Tick Period is in 100ns units, divide by 10000 to convert to ms
     76   //
     77   SleepTime = DivU64x32 (MultU64x32 ((UINT64) TickNumber, TICK_PERIOD) + 9999, 10000);
     78   gWinNt->Sleep ((UINT32) SleepTime);
     79 
     80   return EFI_SUCCESS;
     81 }
     82 
     83 
     84 EFI_STATUS
     85 EFIAPI
     86 WinNtMetronomeDriverInitialize (
     87   IN EFI_HANDLE        ImageHandle,
     88   IN EFI_SYSTEM_TABLE  *SystemTable
     89   )
     90 /*++
     91 
     92 Routine Description:
     93 
     94   Initialize the Metronome Architectural Protocol driver
     95 
     96 Arguments:
     97 
     98   ImageHandle - ImageHandle of the loaded driver
     99 
    100 
    101   SystemTable - Pointer to the System Table
    102 
    103 Returns:
    104 
    105   EFI_SUCCESS           - Metronome Architectural Protocol created
    106 
    107   EFI_OUT_OF_RESOURCES  - Not enough resources available to initialize driver.
    108 
    109   EFI_DEVICE_ERROR      - A device error occured attempting to initialize the driver.
    110 
    111 --*/
    112 {
    113   EFI_STATUS  Status;
    114   EFI_HANDLE  Handle;
    115 
    116 
    117   //
    118   // Install the Metronome Architectural Protocol onto a new handle
    119   //
    120   Handle = NULL;
    121   Status = gBS->InstallProtocolInterface (
    122                   &Handle,
    123                   &gEfiMetronomeArchProtocolGuid,
    124                   EFI_NATIVE_INTERFACE,
    125                   &mMetronome
    126                   );
    127 
    128   return Status;
    129 }
    130