blob: 37672dfce6b52f6c1bc042e83716663cbb534833 [file] [log] [blame]
klu2af4d71f2007-06-27 06:23:37 +00001/*++
2
3Copyright (c) 2006 - 2007, Intel Corporation
4All rights reserved. This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution. The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12Module Name:
13
14 Console.c
15
16Abstract:
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
48EFI_STATUS
49EFIAPI
50WinNtConsoleDriverBindingSupported (
51 IN EFI_DRIVER_BINDING_PROTOCOL *This,
52 IN EFI_HANDLE Handle,
53 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
54 );
55
56EFI_STATUS
57EFIAPI
58WinNtConsoleDriverBindingStart (
59 IN EFI_DRIVER_BINDING_PROTOCOL *This,
60 IN EFI_HANDLE Handle,
61 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
62 );
63
64EFI_STATUS
65EFIAPI
66WinNtConsoleDriverBindingStop (
67 IN EFI_DRIVER_BINDING_PROTOCOL *This,
68 IN EFI_HANDLE Handle,
69 IN UINTN NumberOfChildren,
70 IN EFI_HANDLE *ChildHandleBuffer
71 );
72
73EFI_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**/
92EFI_STATUS
93EFIAPI
94InitializeWinNtConsole(
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 = EfiLibInstallAllDriverProtocols (
105 ImageHandle,
106 SystemTable,
107 &gWinNtConsoleDriverBinding,
108 ImageHandle,
109 &gWinNtConsoleComponentName,
110 NULL,
111 NULL
112 );
113 ASSERT_EFI_ERROR (Status);
114
115
116 return Status;
117}
118
119
120EFI_STATUS
121EFIAPI
122WinNtConsoleDriverBindingSupported (
123 IN EFI_DRIVER_BINDING_PROTOCOL *This,
124 IN EFI_HANDLE Handle,
125 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
126 )
127/*++
128
129Routine Description:
130
131Arguments:
132
133Returns:
134
135 None
136
137--*/
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
141{
142 EFI_STATUS Status;
143 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
144
145 //
146 // Open the IO Abstraction(s) needed to perform the supported test
147 //
148 Status = gBS->OpenProtocol (
149 Handle,
150 &gEfiWinNtIoProtocolGuid,
151 &WinNtIo,
152 This->DriverBindingHandle,
153 Handle,
154 EFI_OPEN_PROTOCOL_BY_DRIVER
155 );
156 if (EFI_ERROR (Status)) {
157 return Status;
158 }
159
160 //
161 // Make sure that the WinNt Thunk Protocol is valid
162 //
163 Status = EFI_UNSUPPORTED;
164 if (WinNtIo->WinNtThunk->Signature == EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) {
165
166 //
167 // Check the GUID to see if this is a handle type the driver supports
168 //
169 if (CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtConsoleGuid)) {
170 Status = EFI_SUCCESS;
171 }
172 }
173
174 //
175 // Close the I/O Abstraction(s) used to perform the supported test
176 //
177 gBS->CloseProtocol (
178 Handle,
179 &gEfiWinNtIoProtocolGuid,
180 This->DriverBindingHandle,
181 Handle
182 );
183
184 return Status;
185}
186
187EFI_STATUS
188EFIAPI
189WinNtConsoleDriverBindingStart (
190 IN EFI_DRIVER_BINDING_PROTOCOL *This,
191 IN EFI_HANDLE Handle,
192 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
193 )
194/*++
195
196Routine Description:
197
198Arguments:
199
200Returns:
201
202 None
203
204--*/
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
208{
209 EFI_STATUS Status;
210 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
211 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
212
213 //
214 // Grab the IO abstraction we need to get any work done
215 //
216 Status = gBS->OpenProtocol (
217 Handle,
218 &gEfiWinNtIoProtocolGuid,
219 &WinNtIo,
220 This->DriverBindingHandle,
221 Handle,
222 EFI_OPEN_PROTOCOL_BY_DRIVER
223 );
224 if (EFI_ERROR (Status)) {
225 return Status;
226 }
227
228 Private = AllocatePool (sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA));
229 if (Private == NULL) {
230 goto Done;
231 }
232
233 ZeroMem (Private, sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA));
234
235 Private->Signature = WIN_NT_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE;
236 Private->Handle = Handle;
237 Private->WinNtIo = WinNtIo;
238 Private->WinNtThunk = WinNtIo->WinNtThunk;
239
240 WinNtSimpleTextOutOpenWindow (Private);
241 WinNtSimpleTextInAttachToWindow (Private);
242
243 Status = gBS->InstallMultipleProtocolInterfaces (
244 &Handle,
245 &gEfiSimpleTextOutProtocolGuid,
246 &Private->SimpleTextOut,
247 &gEfiSimpleTextInProtocolGuid,
248 &Private->SimpleTextIn,
249 NULL
250 );
251 if (!EFI_ERROR (Status)) {
252 return Status;
253 }
254
255Done:
256 gBS->CloseProtocol (
257 Handle,
258 &gEfiWinNtIoProtocolGuid,
259 This->DriverBindingHandle,
260 Handle
261 );
262 if (Private != NULL) {
263
264 FreeUnicodeStringTable (Private->ControllerNameTable);
265
266 if (Private->NtOutHandle != NULL) {
267 Private->WinNtThunk->CloseHandle (Private->NtOutHandle);
268 }
269
270 if (Private->SimpleTextIn.WaitForKey != NULL) {
271 gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
272 }
273
274 FreePool (Private);
275 }
276
277 return Status;
278}
279
280EFI_STATUS
281EFIAPI
282WinNtConsoleDriverBindingStop (
283 IN EFI_DRIVER_BINDING_PROTOCOL *This,
284 IN EFI_HANDLE Handle,
285 IN UINTN NumberOfChildren,
286 IN EFI_HANDLE *ChildHandleBuffer
287 )
288/*++
289
290Routine Description:
291
292 TODO: Add function description
293
294Arguments:
295
296 This - TODO: add argument description
297 Handle - TODO: add argument description
298 NumberOfChildren - TODO: add argument description
299 ChildHandleBuffer - TODO: add argument description
300
301Returns:
302
303 EFI_UNSUPPORTED - TODO: Add description for return value
304
305--*/
306{
307 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
308 EFI_STATUS Status;
309 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
310
311 //
312 // Kick people off our interface???
313 //
314 Status = gBS->OpenProtocol (
315 Handle,
316 &gEfiSimpleTextOutProtocolGuid,
317 &SimpleTextOut,
318 This->DriverBindingHandle,
319 Handle,
320 EFI_OPEN_PROTOCOL_GET_PROTOCOL
321 );
322 if (EFI_ERROR (Status)) {
323 return EFI_UNSUPPORTED;
324 }
325
326 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);
327
328 ASSERT (Private->Handle == Handle);
329
330 Status = gBS->UninstallMultipleProtocolInterfaces (
331 Handle,
332 &gEfiSimpleTextOutProtocolGuid,
333 &Private->SimpleTextOut,
334 &gEfiSimpleTextInProtocolGuid,
335 &Private->SimpleTextIn,
336 NULL
337 );
338 if (!EFI_ERROR (Status)) {
339
340 //
341 // Shut down our device
342 //
343 Status = gBS->CloseProtocol (
344 Handle,
345 &gEfiWinNtIoProtocolGuid,
346 This->DriverBindingHandle,
347 Handle
348 );
349
350 Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
351 ASSERT_EFI_ERROR (Status);
352
353 Private->WinNtThunk->CloseHandle (Private->NtOutHandle);
354 //
355 // DO NOT close Private->NtInHandle. It points to StdIn and not
356 // the Private->NtOutHandle is StdIn and should not be closed!
357 //
358 FreeUnicodeStringTable (Private->ControllerNameTable);
359
360 FreePool (Private);
361 }
362
363 return Status;
364}