]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/LegacyMetronome/Metronome.c
Porting Duet module from EDKI to EDKII
[mirror_edk2.git] / DuetPkg / LegacyMetronome / Metronome.c
1 /*++
2
3 Copyright (c) 2005, 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
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 // The CPU I/O Protocol used to access system hardware
38 //
39 EFI_CPU_IO_PROTOCOL *mCpuIo = NULL;
40
41 //
42 // Worker Functions
43 //
44 VOID
45 IoWrite8 (
46 UINT16 Port,
47 UINT8 Data
48 )
49 /*++
50
51 Routine Description:
52
53 Write an 8 bit value to an I/O port and save it to the S3 script
54
55 Arguments:
56
57 Returns:
58
59 None.
60
61 --*/
62 // TODO: Port - add argument and description to function comment
63 // TODO: Data - add argument and description to function comment
64 {
65 mCpuIo->Io.Write (
66 mCpuIo,
67 EfiCpuIoWidthUint8,
68 Port,
69 1,
70 &Data
71 );
72
73 }
74
75 UINT8
76 ReadRefresh (
77 VOID
78 )
79 /*++
80
81 Routine Description:
82
83 Read the refresh bit from the REFRESH_PORT
84
85 Arguments:
86
87 Returns:
88
89 None.
90
91 --*/
92 {
93 UINT8 Data;
94
95 mCpuIo->Io.Read (
96 mCpuIo,
97 EfiCpuIoWidthUint8,
98 REFRESH_PORT,
99 1,
100 &Data
101 );
102 return (UINT8) (Data & REFRESH_ON);
103 }
104
105 EFI_STATUS
106 EFIAPI
107 WaitForTick (
108 IN EFI_METRONOME_ARCH_PROTOCOL *This,
109 IN UINT32 TickNumber
110 )
111 /*++
112
113 Routine Description:
114
115 Waits for the TickNumber of ticks from a known platform time source.
116
117 Arguments:
118
119 This Pointer to the protocol instance.
120
121 Returns:
122
123 EFI_SUCCESS If number of ticks occurred.
124 EFI_NOT_FOUND Could not locate CPU IO protocol
125
126 --*/
127 // TODO: TickNumber - add argument and description to function comment
128 {
129 //
130 // Wait for TickNumber toggles of the Refresh bit
131 //
132 for (; TickNumber != 0x00; TickNumber--) {
133 while (ReadRefresh () == REFRESH_ON)
134 ;
135 while (ReadRefresh () == REFRESH_OFF)
136 ;
137 }
138
139 return EFI_SUCCESS;
140 }
141
142 EFI_STATUS
143 EFIAPI
144 InstallMetronome (
145 IN EFI_HANDLE ImageHandle,
146 IN EFI_SYSTEM_TABLE *SystemTable
147 )
148 /*++
149
150 Routine Description:
151
152 Install the LegacyMetronome driver. Loads a Metronome Arch Protocol based
153 on the Port 61 timer.
154
155 Arguments:
156
157 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
158
159 Returns:
160
161 EFI_SUCCESS - Metronome Architectural Protocol Installed
162
163 --*/
164 // TODO: ImageHandle - add argument and description to function comment
165 // TODO: SystemTable - add argument and description to function comment
166 {
167 EFI_STATUS Status;
168
169 //
170 // Make sure the Metronome Architectural Protocol is not already installed in the system
171 //
172 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiMetronomeArchProtocolGuid);
173
174 //
175 // Get the CPU I/O Protocol that this driver requires
176 // If the CPU I/O Protocol is not found, then ASSERT because the dependency expression
177 // should guarantee that it is present in the handle database.
178 //
179 Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &mCpuIo);
180 ASSERT_EFI_ERROR (Status);
181
182 //
183 // Program port 61 timer 1 as refresh timer. We could use ACPI timer in the
184 // future.
185 //
186 IoWrite8 (TIMER1_CONTROL_PORT, LOAD_COUNTER1_LSB);
187 IoWrite8 (TIMER1_COUNT_PORT, COUNTER1_COUNT);
188
189 //
190 // Install on a new handle
191 //
192 Status = gBS->InstallMultipleProtocolInterfaces (
193 &mMetronomeHandle,
194 &gEfiMetronomeArchProtocolGuid,
195 &mMetronome,
196 NULL
197 );
198 ASSERT_EFI_ERROR (Status);
199
200 return Status;
201 }