]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/LegacyMetronome/Metronome.c
Porting Duet module from EDKI to EDKII
[mirror_edk2.git] / DuetPkg / LegacyMetronome / Metronome.c
CommitLineData
c69dd9df 1/*++\r
2\r
3Copyright (c) 2005, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13 LegacyMetronome.c\r
14\r
15Abstract:\r
16\r
17 This contains the installation function for the driver.\r
18\r
19--*/\r
20\r
21#include "Metronome.h"\r
22\r
23//\r
24// Handle for the Metronome Architectural Protocol instance produced by this driver\r
25//\r
26EFI_HANDLE mMetronomeHandle = NULL;\r
27\r
28//\r
29// The Metronome Architectural Protocol instance produced by this driver\r
30//\r
31EFI_METRONOME_ARCH_PROTOCOL mMetronome = {\r
32 WaitForTick,\r
33 TICK_PERIOD\r
34};\r
35\r
36//\r
37// The CPU I/O Protocol used to access system hardware\r
38//\r
39EFI_CPU_IO_PROTOCOL *mCpuIo = NULL;\r
40\r
41//\r
42// Worker Functions\r
43//\r
44VOID\r
45IoWrite8 (\r
46 UINT16 Port,\r
47 UINT8 Data\r
48 )\r
49/*++\r
50\r
51Routine Description:\r
52\r
53 Write an 8 bit value to an I/O port and save it to the S3 script\r
54\r
55Arguments:\r
56\r
57Returns: \r
58\r
59 None.\r
60\r
61--*/\r
62// TODO: Port - add argument and description to function comment\r
63// TODO: Data - add argument and description to function comment\r
64{\r
65 mCpuIo->Io.Write (\r
66 mCpuIo,\r
67 EfiCpuIoWidthUint8,\r
68 Port,\r
69 1,\r
70 &Data\r
71 );\r
72\r
73}\r
74\r
75UINT8\r
76ReadRefresh (\r
77 VOID\r
78 )\r
79/*++\r
80\r
81Routine Description:\r
82\r
83 Read the refresh bit from the REFRESH_PORT\r
84\r
85Arguments:\r
86\r
87Returns: \r
88\r
89 None.\r
90\r
91--*/\r
92{\r
93 UINT8 Data;\r
94\r
95 mCpuIo->Io.Read (\r
96 mCpuIo,\r
97 EfiCpuIoWidthUint8,\r
98 REFRESH_PORT,\r
99 1,\r
100 &Data\r
101 );\r
102 return (UINT8) (Data & REFRESH_ON);\r
103}\r
104\r
105EFI_STATUS\r
106EFIAPI\r
107WaitForTick (\r
108 IN EFI_METRONOME_ARCH_PROTOCOL *This,\r
109 IN UINT32 TickNumber\r
110 )\r
111/*++\r
112\r
113Routine Description:\r
114\r
115 Waits for the TickNumber of ticks from a known platform time source.\r
116\r
117Arguments:\r
118\r
119 This Pointer to the protocol instance.\r
120\r
121Returns: \r
122\r
123 EFI_SUCCESS If number of ticks occurred.\r
124 EFI_NOT_FOUND Could not locate CPU IO protocol\r
125\r
126--*/\r
127// TODO: TickNumber - add argument and description to function comment\r
128{\r
129 //\r
130 // Wait for TickNumber toggles of the Refresh bit\r
131 //\r
132 for (; TickNumber != 0x00; TickNumber--) {\r
133 while (ReadRefresh () == REFRESH_ON)\r
134 ;\r
135 while (ReadRefresh () == REFRESH_OFF)\r
136 ;\r
137 }\r
138\r
139 return EFI_SUCCESS;\r
140}\r
141\r
142EFI_STATUS\r
143EFIAPI\r
144InstallMetronome (\r
145 IN EFI_HANDLE ImageHandle,\r
146 IN EFI_SYSTEM_TABLE *SystemTable\r
147 )\r
148/*++\r
149\r
150Routine Description:\r
151 \r
152 Install the LegacyMetronome driver. Loads a Metronome Arch Protocol based\r
153 on the Port 61 timer.\r
154\r
155Arguments:\r
156\r
157 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
158\r
159Returns:\r
160\r
161 EFI_SUCCESS - Metronome Architectural Protocol Installed\r
162\r
163--*/\r
164// TODO: ImageHandle - add argument and description to function comment\r
165// TODO: SystemTable - add argument and description to function comment\r
166{\r
167 EFI_STATUS Status;\r
168\r
169 //\r
170 // Make sure the Metronome Architectural Protocol is not already installed in the system\r
171 //\r
172 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiMetronomeArchProtocolGuid);\r
173\r
174 //\r
175 // Get the CPU I/O Protocol that this driver requires\r
176 // If the CPU I/O Protocol is not found, then ASSERT because the dependency expression\r
177 // should guarantee that it is present in the handle database.\r
178 //\r
179 Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &mCpuIo);\r
180 ASSERT_EFI_ERROR (Status);\r
181\r
182 //\r
183 // Program port 61 timer 1 as refresh timer. We could use ACPI timer in the\r
184 // future.\r
185 //\r
186 IoWrite8 (TIMER1_CONTROL_PORT, LOAD_COUNTER1_LSB);\r
187 IoWrite8 (TIMER1_COUNT_PORT, COUNTER1_COUNT);\r
188\r
189 //\r
190 // Install on a new handle\r
191 //\r
192 Status = gBS->InstallMultipleProtocolInterfaces (\r
193 &mMetronomeHandle,\r
194 &gEfiMetronomeArchProtocolGuid,\r
195 &mMetronome,\r
196 NULL\r
197 );\r
198 ASSERT_EFI_ERROR (Status);\r
199\r
200 return Status;\r
201}\r