blob: 1fd3ecff500c400bf42202fe6db31e739f78e860 [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/*++
2
3Copyright (c) 2005, Intel Corporation. All rights reserved.<BR>
4This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution. The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12Module Name:
13 LegacyMetronome.c
14
15Abstract:
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//
26EFI_HANDLE mMetronomeHandle = NULL;
27
28//
29// The Metronome Architectural Protocol instance produced by this driver
30//
31EFI_METRONOME_ARCH_PROTOCOL mMetronome = {
32 WaitForTick,
33 TICK_PERIOD
34};
35
36//
37// Worker Functions
38//
39EFI_STATUS
40EFIAPI
41WaitForTick (
42 IN EFI_METRONOME_ARCH_PROTOCOL *This,
43 IN UINT32 TickNumber
44 )
45/*++
46
47Routine Description:
48
49 Waits for the TickNumber of ticks from a known platform time source.
50
51Arguments:
52
53 This Pointer to the protocol instance.
54
55Returns:
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
74EFI_STATUS
75EFIAPI
76InstallMetronome (
77 IN EFI_HANDLE ImageHandle,
78 IN EFI_SYSTEM_TABLE *SystemTable
79 )
80/*++
81
82Routine Description:
83
84 Install the LegacyMetronome driver. Loads a Metronome Arch Protocol based
85 on the Port 61 timer.
86
87Arguments:
88
89 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
90
91Returns:
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}