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