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
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.
18 Console based on Win32 APIs.
23 // The package level header files this module uses
28 // The protocols, PPI and GUID defintions for this module
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>
36 // The Library classes this module consumes
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>
50 WinNtConsoleDriverBindingSupported (
51 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
53 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
58 WinNtConsoleDriverBindingStart (
59 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
61 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
66 WinNtConsoleDriverBindingStop (
67 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
69 IN UINTN NumberOfChildren
,
70 IN EFI_HANDLE
*ChildHandleBuffer
73 EFI_DRIVER_BINDING_PROTOCOL gWinNtConsoleDriverBinding
= {
74 WinNtConsoleDriverBindingSupported
,
75 WinNtConsoleDriverBindingStart
,
76 WinNtConsoleDriverBindingStop
,
83 The user Entry Point for module WinNtConsole. The user code starts with this function.
85 @param[in] ImageHandle The firmware allocated handle for the EFI image.
86 @param[in] SystemTable A pointer to the EFI System Table.
88 @retval EFI_SUCCESS The entry point is executed successfully.
89 @retval other Some error occurs when executing this entry point.
94 InitializeWinNtConsole(
95 IN EFI_HANDLE ImageHandle
,
96 IN EFI_SYSTEM_TABLE
*SystemTable
102 // Install driver model protocol(s).
104 Status
= EfiLibInstallDriverBindingComponentName2 (
107 &gWinNtConsoleDriverBinding
,
109 &gWinNtConsoleComponentName
,
110 &gWinNtConsoleComponentName2
112 ASSERT_EFI_ERROR (Status
);
121 WinNtConsoleDriverBindingSupported (
122 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
123 IN EFI_HANDLE Handle
,
124 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
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
142 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
145 // Open the IO Abstraction(s) needed to perform the supported test
147 Status
= gBS
->OpenProtocol (
149 &gEfiWinNtIoProtocolGuid
,
151 This
->DriverBindingHandle
,
153 EFI_OPEN_PROTOCOL_BY_DRIVER
155 if (EFI_ERROR (Status
)) {
160 // Make sure that the WinNt Thunk Protocol is valid
162 Status
= EFI_UNSUPPORTED
;
163 if (WinNtIo
->WinNtThunk
->Signature
== EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE
) {
166 // Check the GUID to see if this is a handle type the driver supports
168 if (CompareGuid (WinNtIo
->TypeGuid
, &gEfiWinNtConsoleGuid
)) {
169 Status
= EFI_SUCCESS
;
174 // Close the I/O Abstraction(s) used to perform the supported test
178 &gEfiWinNtIoProtocolGuid
,
179 This
->DriverBindingHandle
,
188 WinNtConsoleDriverBindingStart (
189 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
190 IN EFI_HANDLE Handle
,
191 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
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
209 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
210 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
213 // Grab the IO abstraction we need to get any work done
215 Status
= gBS
->OpenProtocol (
217 &gEfiWinNtIoProtocolGuid
,
219 This
->DriverBindingHandle
,
221 EFI_OPEN_PROTOCOL_BY_DRIVER
223 if (EFI_ERROR (Status
)) {
227 Private
= AllocatePool (sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
));
228 if (Private
== NULL
) {
232 ZeroMem (Private
, sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
));
234 Private
->Signature
= WIN_NT_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE
;
235 Private
->Handle
= Handle
;
236 Private
->WinNtIo
= WinNtIo
;
237 Private
->WinNtThunk
= WinNtIo
->WinNtThunk
;
239 WinNtSimpleTextOutOpenWindow (Private
);
240 WinNtSimpleTextInAttachToWindow (Private
);
242 Status
= gBS
->InstallMultipleProtocolInterfaces (
244 &gEfiSimpleTextOutProtocolGuid
,
245 &Private
->SimpleTextOut
,
246 &gEfiSimpleTextInProtocolGuid
,
247 &Private
->SimpleTextIn
,
250 if (!EFI_ERROR (Status
)) {
257 &gEfiWinNtIoProtocolGuid
,
258 This
->DriverBindingHandle
,
261 if (Private
!= NULL
) {
263 FreeUnicodeStringTable (Private
->ControllerNameTable
);
265 if (Private
->NtOutHandle
!= NULL
) {
266 Private
->WinNtThunk
->CloseHandle (Private
->NtOutHandle
);
269 if (Private
->SimpleTextIn
.WaitForKey
!= NULL
) {
270 gBS
->CloseEvent (Private
->SimpleTextIn
.WaitForKey
);
281 WinNtConsoleDriverBindingStop (
282 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
283 IN EFI_HANDLE Handle
,
284 IN UINTN NumberOfChildren
,
285 IN EFI_HANDLE
*ChildHandleBuffer
291 TODO: Add function description
295 This - TODO: add argument description
296 Handle - TODO: add argument description
297 NumberOfChildren - TODO: add argument description
298 ChildHandleBuffer - TODO: add argument description
302 EFI_UNSUPPORTED - TODO: Add description for return value
306 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
308 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
311 // Kick people off our interface???
313 Status
= gBS
->OpenProtocol (
315 &gEfiSimpleTextOutProtocolGuid
,
317 This
->DriverBindingHandle
,
319 EFI_OPEN_PROTOCOL_GET_PROTOCOL
321 if (EFI_ERROR (Status
)) {
322 return EFI_UNSUPPORTED
;
325 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut
);
327 ASSERT (Private
->Handle
== Handle
);
329 Status
= gBS
->UninstallMultipleProtocolInterfaces (
331 &gEfiSimpleTextOutProtocolGuid
,
332 &Private
->SimpleTextOut
,
333 &gEfiSimpleTextInProtocolGuid
,
334 &Private
->SimpleTextIn
,
337 if (!EFI_ERROR (Status
)) {
340 // Shut down our device
342 Status
= gBS
->CloseProtocol (
344 &gEfiWinNtIoProtocolGuid
,
345 This
->DriverBindingHandle
,
349 Status
= gBS
->CloseEvent (Private
->SimpleTextIn
.WaitForKey
);
350 ASSERT_EFI_ERROR (Status
);
352 Private
->WinNtThunk
->CloseHandle (Private
->NtOutHandle
);
354 // DO NOT close Private->NtInHandle. It points to StdIn and not
355 // the Private->NtOutHandle is StdIn and should not be closed!
357 FreeUnicodeStringTable (Private
->ControllerNameTable
);