Home | History | Annotate | Download | only in LegacyMetronome
      1 /*++
      2 
      3 Copyright (c) 2005, 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   LegacyMetronome.c
     14 
     15 Abstract:
     16 
     17   This contains the installation function for the driver.
     18 
     19 --*/
     20 
     21 #include "Metronome.h"
     22 
     23 //
     24 // Handle for the Metronome Architectural Protocol instance produced by this driver
     25 //
     26 EFI_HANDLE                  mMetronomeHandle = NULL;
     27 
     28 //
     29 // The Metronome Architectural Protocol instance produced by this driver
     30 //
     31 EFI_METRONOME_ARCH_PROTOCOL mMetronome = {
     32   WaitForTick,
     33   TICK_PERIOD
     34 };
     35 
     36 //
     37 // Worker Functions
     38 //
     39 EFI_STATUS
     40 EFIAPI
     41 WaitForTick (
     42   IN EFI_METRONOME_ARCH_PROTOCOL  *This,
     43   IN UINT32                       TickNumber
     44   )
     45 /*++
     46 
     47 Routine Description:
     48 
     49   Waits for the TickNumber of ticks from a known platform time source.
     50 
     51 Arguments:
     52 
     53   This                Pointer to the protocol instance.
     54 
     55 Returns:
     56 
     57   EFI_SUCCESS         If number of ticks occurred.
     58   EFI_NOT_FOUND       Could not locate CPU IO protocol
     59 
     60 --*/
     61 // TODO:    TickNumber - add argument and description to function comment
     62 {
     63   //
     64   // Wait for TickNumber toggles of the Refresh bit
     65   //
     66   for (; TickNumber != 0x00; TickNumber--) {
     67     while ((IoRead8(REFRESH_PORT) & REFRESH_ON) == REFRESH_ON);
     68     while ((IoRead8(REFRESH_PORT) & REFRESH_ON) == REFRESH_OFF);
     69   }
     70 
     71   return EFI_SUCCESS;
     72 }
     73 
     74 EFI_STATUS
     75 EFIAPI
     76 InstallMetronome (
     77   IN EFI_HANDLE        ImageHandle,
     78   IN EFI_SYSTEM_TABLE  *SystemTable
     79   )
     80 /*++
     81 
     82 Routine Description:
     83 
     84   Install the LegacyMetronome driver.  Loads a Metronome Arch Protocol based
     85   on the Port 61 timer.
     86 
     87 Arguments:
     88 
     89   (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
     90 
     91 Returns:
     92 
     93   EFI_SUCCESS - Metronome Architectural Protocol Installed
     94 
     95 --*/
     96 // TODO:    ImageHandle - add argument and description to function comment
     97 // TODO:    SystemTable - add argument and description to function comment
     98 {
     99   EFI_STATUS  Status;
    100 
    101   //
    102   // Make sure the Metronome Architectural Protocol is not already installed in the system
    103   //
    104   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiMetronomeArchProtocolGuid);
    105 
    106   //
    107   // Program port 61 timer 1 as refresh timer. We could use ACPI timer in the
    108   // future.
    109   //
    110   IoWrite8 (TIMER1_CONTROL_PORT, LOAD_COUNTER1_LSB);
    111   IoWrite8 (TIMER1_COUNT_PORT, COUNTER1_COUNT);
    112 
    113   //
    114   // Install on a new handle
    115   //
    116   Status = gBS->InstallMultipleProtocolInterfaces (
    117                   &mMetronomeHandle,
    118                   &gEfiMetronomeArchProtocolGuid,
    119                   &mMetronome,
    120                   NULL
    121                   );
    122   ASSERT_EFI_ERROR (Status);
    123 
    124   return Status;
    125 }
    126