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
= EfiLibInstallAllDriverProtocols (
107 &gWinNtConsoleDriverBinding
,
109 &gWinNtConsoleComponentName
,
113 ASSERT_EFI_ERROR (Status
);
122 WinNtConsoleDriverBindingSupported (
123 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
124 IN EFI_HANDLE Handle
,
125 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
138 // TODO: This - add argument and description to function comment
139 // TODO: Handle - add argument and description to function comment
140 // TODO: RemainingDevicePath - add argument and description to function comment
143 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
146 // Open the IO Abstraction(s) needed to perform the supported test
148 Status
= gBS
->OpenProtocol (
150 &gEfiWinNtIoProtocolGuid
,
152 This
->DriverBindingHandle
,
154 EFI_OPEN_PROTOCOL_BY_DRIVER
156 if (EFI_ERROR (Status
)) {
161 // Make sure that the WinNt Thunk Protocol is valid
163 Status
= EFI_UNSUPPORTED
;
164 if (WinNtIo
->WinNtThunk
->Signature
== EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE
) {
167 // Check the GUID to see if this is a handle type the driver supports
169 if (CompareGuid (WinNtIo
->TypeGuid
, &gEfiWinNtConsoleGuid
)) {
170 Status
= EFI_SUCCESS
;
175 // Close the I/O Abstraction(s) used to perform the supported test
179 &gEfiWinNtIoProtocolGuid
,
180 This
->DriverBindingHandle
,
189 WinNtConsoleDriverBindingStart (
190 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
191 IN EFI_HANDLE Handle
,
192 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
205 // TODO: This - add argument and description to function comment
206 // TODO: Handle - add argument and description to function comment
207 // TODO: RemainingDevicePath - add argument and description to function comment
210 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
211 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
214 // Grab the IO abstraction we need to get any work done
216 Status
= gBS
->OpenProtocol (
218 &gEfiWinNtIoProtocolGuid
,
220 This
->DriverBindingHandle
,
222 EFI_OPEN_PROTOCOL_BY_DRIVER
224 if (EFI_ERROR (Status
)) {
228 Private
= AllocatePool (sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
));
229 if (Private
== NULL
) {
233 ZeroMem (Private
, sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
));
235 Private
->Signature
= WIN_NT_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE
;
236 Private
->Handle
= Handle
;
237 Private
->WinNtIo
= WinNtIo
;
238 Private
->WinNtThunk
= WinNtIo
->WinNtThunk
;
240 WinNtSimpleTextOutOpenWindow (Private
);
241 WinNtSimpleTextInAttachToWindow (Private
);
243 Status
= gBS
->InstallMultipleProtocolInterfaces (
245 &gEfiSimpleTextOutProtocolGuid
,
246 &Private
->SimpleTextOut
,
247 &gEfiSimpleTextInProtocolGuid
,
248 &Private
->SimpleTextIn
,
251 if (!EFI_ERROR (Status
)) {
258 &gEfiWinNtIoProtocolGuid
,
259 This
->DriverBindingHandle
,
262 if (Private
!= NULL
) {
264 FreeUnicodeStringTable (Private
->ControllerNameTable
);
266 if (Private
->NtOutHandle
!= NULL
) {
267 Private
->WinNtThunk
->CloseHandle (Private
->NtOutHandle
);
270 if (Private
->SimpleTextIn
.WaitForKey
!= NULL
) {
271 gBS
->CloseEvent (Private
->SimpleTextIn
.WaitForKey
);
282 WinNtConsoleDriverBindingStop (
283 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
284 IN EFI_HANDLE Handle
,
285 IN UINTN NumberOfChildren
,
286 IN EFI_HANDLE
*ChildHandleBuffer
292 TODO: Add function description
296 This - TODO: add argument description
297 Handle - TODO: add argument description
298 NumberOfChildren - TODO: add argument description
299 ChildHandleBuffer - TODO: add argument description
303 EFI_UNSUPPORTED - TODO: Add description for return value
307 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
309 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
312 // Kick people off our interface???
314 Status
= gBS
->OpenProtocol (
316 &gEfiSimpleTextOutProtocolGuid
,
318 This
->DriverBindingHandle
,
320 EFI_OPEN_PROTOCOL_GET_PROTOCOL
322 if (EFI_ERROR (Status
)) {
323 return EFI_UNSUPPORTED
;
326 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut
);
328 ASSERT (Private
->Handle
== Handle
);
330 Status
= gBS
->UninstallMultipleProtocolInterfaces (
332 &gEfiSimpleTextOutProtocolGuid
,
333 &Private
->SimpleTextOut
,
334 &gEfiSimpleTextInProtocolGuid
,
335 &Private
->SimpleTextIn
,
338 if (!EFI_ERROR (Status
)) {
341 // Shut down our device
343 Status
= gBS
->CloseProtocol (
345 &gEfiWinNtIoProtocolGuid
,
346 This
->DriverBindingHandle
,
350 Status
= gBS
->CloseEvent (Private
->SimpleTextIn
.WaitForKey
);
351 ASSERT_EFI_ERROR (Status
);
353 Private
->WinNtThunk
->CloseHandle (Private
->NtOutHandle
);
355 // DO NOT close Private->NtInHandle. It points to StdIn and not
356 // the Private->NtOutHandle is StdIn and should not be closed!
358 FreeUnicodeStringTable (Private
->ControllerNameTable
);