]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/WinNtGopDxe/WinNtGopDriver.c
Clean up: update "EFI" to "UEFI" if applicable.
[mirror_edk2.git] / Nt32Pkg / WinNtGopDxe / WinNtGopDriver.c
1 /** @file
2
3 Copyright (c) 2006 - 2007, 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
14 WinNtGopDriver.c
15
16 Abstract:
17
18 This file implements the UEFI Device Driver model requirements for GOP
19
20 GOP is short hand for Graphics Output Protocol.
21
22
23 **/
24 #include "WinNtGop.h"
25
26 STATIC
27 EFI_STATUS
28 FreeNotifyList (
29 IN OUT LIST_ENTRY *ListHead
30 )
31 /*++
32
33 Routine Description:
34
35 Arguments:
36
37 ListHead - The list head
38
39 Returns:
40
41 EFI_SUCCESS - Free the notify list successfully
42 EFI_INVALID_PARAMETER - ListHead is invalid.
43
44 --*/
45 {
46 WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NotifyNode;
47
48 if (ListHead == NULL) {
49 return EFI_INVALID_PARAMETER;
50 }
51 while (!IsListEmpty (ListHead)) {
52 NotifyNode = CR (
53 ListHead->ForwardLink,
54 WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
55 NotifyEntry,
56 WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
57 );
58 RemoveEntryList (ListHead->ForwardLink);
59 gBS->FreePool (NotifyNode);
60 }
61
62 return EFI_SUCCESS;
63 }
64
65 EFI_DRIVER_BINDING_PROTOCOL gWinNtGopDriverBinding = {
66 WinNtGopDriverBindingSupported,
67 WinNtGopDriverBindingStart,
68 WinNtGopDriverBindingStop,
69 0xa,
70 NULL,
71 NULL
72 };
73
74 /**
75 The user Entry Point for module WinNtGop. The user code starts with this function.
76
77 @param[in] ImageHandle The firmware allocated handle for the EFI image.
78 @param[in] SystemTable A pointer to the EFI System Table.
79
80 @retval EFI_SUCCESS The entry point is executed successfully.
81 @retval other Some error occurs when executing this entry point.
82
83 **/
84 EFI_STATUS
85 EFIAPI
86 InitializeWinNtGop(
87 IN EFI_HANDLE ImageHandle,
88 IN EFI_SYSTEM_TABLE *SystemTable
89 )
90 {
91 EFI_STATUS Status;
92
93 //
94 // Install driver model protocol(s).
95 //
96 Status = EfiLibInstallDriverBindingComponentName2 (
97 ImageHandle,
98 SystemTable,
99 &gWinNtGopDriverBinding,
100 ImageHandle,
101 &gWinNtGopComponentName,
102 &gWinNtGopComponentName2
103 );
104 ASSERT_EFI_ERROR (Status);
105
106
107 return Status;
108 }
109
110 /**
111
112
113 @return None
114
115 **/
116 // TODO: This - add argument and description to function comment
117 // TODO: Handle - add argument and description to function comment
118 // TODO: RemainingDevicePath - add argument and description to function comment
119 EFI_STATUS
120 EFIAPI
121 WinNtGopDriverBindingSupported (
122 IN EFI_DRIVER_BINDING_PROTOCOL *This,
123 IN EFI_HANDLE Handle,
124 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
125 )
126 {
127 EFI_STATUS Status;
128 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
129
130 //
131 // Open the IO Abstraction(s) needed to perform the supported test
132 //
133 Status = gBS->OpenProtocol (
134 Handle,
135 &gEfiWinNtIoProtocolGuid,
136 &WinNtIo,
137 This->DriverBindingHandle,
138 Handle,
139 EFI_OPEN_PROTOCOL_BY_DRIVER
140 );
141 if (EFI_ERROR (Status)) {
142 return Status;
143 }
144
145 Status = WinNtGopSupported (WinNtIo);
146
147 //
148 // Close the I/O Abstraction(s) used to perform the supported test
149 //
150 gBS->CloseProtocol (
151 Handle,
152 &gEfiWinNtIoProtocolGuid,
153 This->DriverBindingHandle,
154 Handle
155 );
156
157 return Status;
158 }
159
160
161 /**
162
163
164 @return None
165
166 **/
167 // TODO: This - add argument and description to function comment
168 // TODO: Handle - add argument and description to function comment
169 // TODO: RemainingDevicePath - add argument and description to function comment
170 // TODO: EFI_UNSUPPORTED - add return value to function comment
171 EFI_STATUS
172 EFIAPI
173 WinNtGopDriverBindingStart (
174 IN EFI_DRIVER_BINDING_PROTOCOL *This,
175 IN EFI_HANDLE Handle,
176 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
177 )
178 {
179 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
180 EFI_STATUS Status;
181 GOP_PRIVATE_DATA *Private;
182
183 //
184 // Grab the protocols we need
185 //
186 Status = gBS->OpenProtocol (
187 Handle,
188 &gEfiWinNtIoProtocolGuid,
189 &WinNtIo,
190 This->DriverBindingHandle,
191 Handle,
192 EFI_OPEN_PROTOCOL_BY_DRIVER
193 );
194 if (EFI_ERROR (Status)) {
195 return EFI_UNSUPPORTED;
196 }
197
198 //
199 // Allocate Private context data for SGO inteface.
200 //
201 Private = NULL;
202 Private = AllocatePool (sizeof (GOP_PRIVATE_DATA));
203 if (Private == NULL) {
204 Status = EFI_OUT_OF_RESOURCES;
205 goto Done;
206 }
207 //
208 // Set up context record
209 //
210 Private->Signature = GOP_PRIVATE_DATA_SIGNATURE;
211 Private->Handle = Handle;
212 Private->WinNtThunk = WinNtIo->WinNtThunk;
213
214 Private->ControllerNameTable = NULL;
215
216 AddUnicodeString2 (
217 "eng",
218 gWinNtGopComponentName.SupportedLanguages,
219 &Private->ControllerNameTable,
220 WinNtIo->EnvString,
221 TRUE
222 );
223 AddUnicodeString2 (
224 "en",
225 gWinNtGopComponentName2.SupportedLanguages,
226 &Private->ControllerNameTable,
227 WinNtIo->EnvString,
228 FALSE
229 );
230
231
232 Private->WindowName = WinNtIo->EnvString;
233
234 Status = WinNtGopConstructor (Private);
235 if (EFI_ERROR (Status)) {
236 goto Done;
237 }
238 //
239 // Publish the Gop interface to the world
240 //
241 Status = gBS->InstallMultipleProtocolInterfaces (
242 &Private->Handle,
243 &gEfiGraphicsOutputProtocolGuid,
244 &Private->GraphicsOutput,
245 &gEfiSimpleTextInProtocolGuid,
246 &Private->SimpleTextIn,
247 &gEfiSimpleTextInputExProtocolGuid,
248 &Private->SimpleTextInEx,
249 NULL
250 );
251
252 Done:
253 if (EFI_ERROR (Status)) {
254
255 gBS->CloseProtocol (
256 Handle,
257 &gEfiWinNtIoProtocolGuid,
258 This->DriverBindingHandle,
259 Handle
260 );
261
262 if (Private != NULL) {
263 //
264 // On Error Free back private data
265 //
266 if (Private->ControllerNameTable != NULL) {
267 FreeUnicodeStringTable (Private->ControllerNameTable);
268 }
269
270 if (Private->SimpleTextIn.WaitForKey != NULL) {
271 gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
272 }
273 if (Private->SimpleTextInEx.WaitForKeyEx != NULL) {
274 gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);
275 }
276 FreeNotifyList (&Private->NotifyList);
277 FreePool (Private);
278 }
279 }
280
281 return Status;
282 }
283
284
285 /**
286
287
288 @return None
289
290 **/
291 // TODO: This - add argument and description to function comment
292 // TODO: Handle - add argument and description to function comment
293 // TODO: NumberOfChildren - add argument and description to function comment
294 // TODO: ChildHandleBuffer - add argument and description to function comment
295 // TODO: EFI_NOT_STARTED - add return value to function comment
296 // TODO: EFI_DEVICE_ERROR - add return value to function comment
297 EFI_STATUS
298 EFIAPI
299 WinNtGopDriverBindingStop (
300 IN EFI_DRIVER_BINDING_PROTOCOL *This,
301 IN EFI_HANDLE Handle,
302 IN UINTN NumberOfChildren,
303 IN EFI_HANDLE *ChildHandleBuffer
304 )
305 {
306 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
307 EFI_STATUS Status;
308 GOP_PRIVATE_DATA *Private;
309
310 Status = gBS->OpenProtocol (
311 Handle,
312 &gEfiGraphicsOutputProtocolGuid,
313 &GraphicsOutput,
314 This->DriverBindingHandle,
315 Handle,
316 EFI_OPEN_PROTOCOL_GET_PROTOCOL
317 );
318 if (EFI_ERROR (Status)) {
319 //
320 // If the GOP interface does not exist the driver is not started
321 //
322 return EFI_NOT_STARTED;
323 }
324
325 //
326 // Get our private context information
327 //
328 Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);
329
330 //
331 // Remove the SGO interface from the system
332 //
333 Status = gBS->UninstallMultipleProtocolInterfaces (
334 Private->Handle,
335 &gEfiGraphicsOutputProtocolGuid,
336 &Private->GraphicsOutput,
337 &gEfiSimpleTextInProtocolGuid,
338 &Private->SimpleTextIn,
339 &gEfiSimpleTextInputExProtocolGuid,
340 &Private->SimpleTextInEx,
341 NULL
342 );
343 if (!EFI_ERROR (Status)) {
344 //
345 // Shutdown the hardware
346 //
347 Status = WinNtGopDestructor (Private);
348 if (EFI_ERROR (Status)) {
349 return EFI_DEVICE_ERROR;
350 }
351
352 gBS->CloseProtocol (
353 Handle,
354 &gEfiWinNtIoProtocolGuid,
355 This->DriverBindingHandle,
356 Handle
357 );
358
359 //
360 // Free our instance data
361 //
362 FreeUnicodeStringTable (Private->ControllerNameTable);
363 Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
364 ASSERT_EFI_ERROR (Status);
365 Status = gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);
366 ASSERT_EFI_ERROR (Status);
367 FreeNotifyList (&Private->NotifyList);
368
369 gBS->FreePool (Private);
370
371 }
372
373 return Status;
374 }
375