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