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