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