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