]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/WinNtConsoleDxe/Console.c
Correct ExtractGuidedSectionLib library instance for PEIM and DXE
[mirror_edk2.git] / Nt32Pkg / WinNtConsoleDxe / Console.c
1 /*++
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 Console.c
15
16 Abstract:
17
18 Console based on Win32 APIs.
19
20 --*/
21
22 //
23 // The package level header files this module uses
24 //
25 #include <Uefi.h>
26 #include <WinNtDxe.h>
27 //
28 // The protocols, PPI and GUID defintions for this module
29 //
30 #include <Protocol/SimpleTextIn.h>
31 #include <Protocol/WinNtIo.h>
32 #include <Protocol/SimpleTextOut.h>
33 #include <Protocol/ComponentName.h>
34 #include <Protocol/DriverBinding.h>
35 //
36 // The Library classes this module consumes
37 //
38 #include <Library/DebugLib.h>
39 #include <Library/BaseLib.h>
40 #include <Library/UefiDriverEntryPoint.h>
41 #include <Library/UefiLib.h>
42 #include <Library/BaseMemoryLib.h>
43 #include <Library/UefiBootServicesTableLib.h>
44 #include <Library/MemoryAllocationLib.h>
45
46 #include "Console.h"
47
48 EFI_STATUS
49 EFIAPI
50 WinNtConsoleDriverBindingSupported (
51 IN EFI_DRIVER_BINDING_PROTOCOL *This,
52 IN EFI_HANDLE Handle,
53 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
54 );
55
56 EFI_STATUS
57 EFIAPI
58 WinNtConsoleDriverBindingStart (
59 IN EFI_DRIVER_BINDING_PROTOCOL *This,
60 IN EFI_HANDLE Handle,
61 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
62 );
63
64 EFI_STATUS
65 EFIAPI
66 WinNtConsoleDriverBindingStop (
67 IN EFI_DRIVER_BINDING_PROTOCOL *This,
68 IN EFI_HANDLE Handle,
69 IN UINTN NumberOfChildren,
70 IN EFI_HANDLE *ChildHandleBuffer
71 );
72
73 EFI_DRIVER_BINDING_PROTOCOL gWinNtConsoleDriverBinding = {
74 WinNtConsoleDriverBindingSupported,
75 WinNtConsoleDriverBindingStart,
76 WinNtConsoleDriverBindingStop,
77 0xa,
78 NULL,
79 NULL
80 };
81
82 /**
83 The user Entry Point for module WinNtConsole. The user code starts with this function.
84
85 @param[in] ImageHandle The firmware allocated handle for the EFI image.
86 @param[in] SystemTable A pointer to the EFI System Table.
87
88 @retval EFI_SUCCESS The entry point is executed successfully.
89 @retval other Some error occurs when executing this entry point.
90
91 **/
92 EFI_STATUS
93 EFIAPI
94 InitializeWinNtConsole(
95 IN EFI_HANDLE ImageHandle,
96 IN EFI_SYSTEM_TABLE *SystemTable
97 )
98 {
99 EFI_STATUS Status;
100
101 //
102 // Install driver model protocol(s).
103 //
104 Status = EfiLibInstallDriverBindingComponentName2 (
105 ImageHandle,
106 SystemTable,
107 &gWinNtConsoleDriverBinding,
108 ImageHandle,
109 &gWinNtConsoleComponentName,
110 &gWinNtConsoleComponentName2
111 );
112 ASSERT_EFI_ERROR (Status);
113
114
115 return Status;
116 }
117
118
119 EFI_STATUS
120 EFIAPI
121 WinNtConsoleDriverBindingSupported (
122 IN EFI_DRIVER_BINDING_PROTOCOL *This,
123 IN EFI_HANDLE Handle,
124 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
125 )
126 /*++
127
128 Routine Description:
129
130 Arguments:
131
132 Returns:
133
134 None
135
136 --*/
137 // TODO: This - add argument and description to function comment
138 // TODO: Handle - add argument and description to function comment
139 // TODO: RemainingDevicePath - add argument and description to function comment
140 {
141 EFI_STATUS Status;
142 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
143
144 //
145 // Open the IO Abstraction(s) needed to perform the supported test
146 //
147 Status = gBS->OpenProtocol (
148 Handle,
149 &gEfiWinNtIoProtocolGuid,
150 &WinNtIo,
151 This->DriverBindingHandle,
152 Handle,
153 EFI_OPEN_PROTOCOL_BY_DRIVER
154 );
155 if (EFI_ERROR (Status)) {
156 return Status;
157 }
158
159 //
160 // Make sure that the WinNt Thunk Protocol is valid
161 //
162 Status = EFI_UNSUPPORTED;
163 if (WinNtIo->WinNtThunk->Signature == EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) {
164
165 //
166 // Check the GUID to see if this is a handle type the driver supports
167 //
168 if (CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtConsoleGuid)) {
169 Status = EFI_SUCCESS;
170 }
171 }
172
173 //
174 // Close the I/O Abstraction(s) used to perform the supported test
175 //
176 gBS->CloseProtocol (
177 Handle,
178 &gEfiWinNtIoProtocolGuid,
179 This->DriverBindingHandle,
180 Handle
181 );
182
183 return Status;
184 }
185
186 EFI_STATUS
187 EFIAPI
188 WinNtConsoleDriverBindingStart (
189 IN EFI_DRIVER_BINDING_PROTOCOL *This,
190 IN EFI_HANDLE Handle,
191 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
192 )
193 /*++
194
195 Routine Description:
196
197 Arguments:
198
199 Returns:
200
201 None
202
203 --*/
204 // TODO: This - add argument and description to function comment
205 // TODO: Handle - add argument and description to function comment
206 // TODO: RemainingDevicePath - add argument and description to function comment
207 {
208 EFI_STATUS Status;
209 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
210 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
211
212 //
213 // Grab the IO abstraction we need to get any work done
214 //
215 Status = gBS->OpenProtocol (
216 Handle,
217 &gEfiWinNtIoProtocolGuid,
218 &WinNtIo,
219 This->DriverBindingHandle,
220 Handle,
221 EFI_OPEN_PROTOCOL_BY_DRIVER
222 );
223 if (EFI_ERROR (Status)) {
224 return Status;
225 }
226
227 Private = AllocatePool (sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA));
228 if (Private == NULL) {
229 goto Done;
230 }
231
232 ZeroMem (Private, sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA));
233
234 Private->Signature = WIN_NT_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE;
235 Private->Handle = Handle;
236 Private->WinNtIo = WinNtIo;
237 Private->WinNtThunk = WinNtIo->WinNtThunk;
238
239 WinNtSimpleTextOutOpenWindow (Private);
240 WinNtSimpleTextInAttachToWindow (Private);
241
242 Status = gBS->InstallMultipleProtocolInterfaces (
243 &Handle,
244 &gEfiSimpleTextOutProtocolGuid,
245 &Private->SimpleTextOut,
246 &gEfiSimpleTextInProtocolGuid,
247 &Private->SimpleTextIn,
248 NULL
249 );
250 if (!EFI_ERROR (Status)) {
251 return Status;
252 }
253
254 Done:
255 gBS->CloseProtocol (
256 Handle,
257 &gEfiWinNtIoProtocolGuid,
258 This->DriverBindingHandle,
259 Handle
260 );
261 if (Private != NULL) {
262
263 FreeUnicodeStringTable (Private->ControllerNameTable);
264
265 if (Private->NtOutHandle != NULL) {
266 Private->WinNtThunk->CloseHandle (Private->NtOutHandle);
267 }
268
269 if (Private->SimpleTextIn.WaitForKey != NULL) {
270 gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
271 }
272
273 FreePool (Private);
274 }
275
276 return Status;
277 }
278
279 EFI_STATUS
280 EFIAPI
281 WinNtConsoleDriverBindingStop (
282 IN EFI_DRIVER_BINDING_PROTOCOL *This,
283 IN EFI_HANDLE Handle,
284 IN UINTN NumberOfChildren,
285 IN EFI_HANDLE *ChildHandleBuffer
286 )
287 /*++
288
289 Routine Description:
290
291 TODO: Add function description
292
293 Arguments:
294
295 This - TODO: add argument description
296 Handle - TODO: add argument description
297 NumberOfChildren - TODO: add argument description
298 ChildHandleBuffer - TODO: add argument description
299
300 Returns:
301
302 EFI_UNSUPPORTED - TODO: Add description for return value
303
304 --*/
305 {
306 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
307 EFI_STATUS Status;
308 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
309
310 //
311 // Kick people off our interface???
312 //
313 Status = gBS->OpenProtocol (
314 Handle,
315 &gEfiSimpleTextOutProtocolGuid,
316 &SimpleTextOut,
317 This->DriverBindingHandle,
318 Handle,
319 EFI_OPEN_PROTOCOL_GET_PROTOCOL
320 );
321 if (EFI_ERROR (Status)) {
322 return EFI_UNSUPPORTED;
323 }
324
325 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);
326
327 ASSERT (Private->Handle == Handle);
328
329 Status = gBS->UninstallMultipleProtocolInterfaces (
330 Handle,
331 &gEfiSimpleTextOutProtocolGuid,
332 &Private->SimpleTextOut,
333 &gEfiSimpleTextInProtocolGuid,
334 &Private->SimpleTextIn,
335 NULL
336 );
337 if (!EFI_ERROR (Status)) {
338
339 //
340 // Shut down our device
341 //
342 Status = gBS->CloseProtocol (
343 Handle,
344 &gEfiWinNtIoProtocolGuid,
345 This->DriverBindingHandle,
346 Handle
347 );
348
349 Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
350 ASSERT_EFI_ERROR (Status);
351
352 Private->WinNtThunk->CloseHandle (Private->NtOutHandle);
353 //
354 // DO NOT close Private->NtInHandle. It points to StdIn and not
355 // the Private->NtOutHandle is StdIn and should not be closed!
356 //
357 FreeUnicodeStringTable (Private->ControllerNameTable);
358
359 FreePool (Private);
360 }
361
362 return Status;
363 }