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