]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/WinNtThunk/Bus/Console/Console.c
0027069b7aa433f15bfeaae4838f4b2847a204e5
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / Console / Console.c
1 /*++
2
3 Copyright (c) 2006, 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 #include "Console.h"
23
24 EFI_STATUS
25 EFIAPI
26 WinNtConsoleDriverBindingSupported (
27 IN EFI_DRIVER_BINDING_PROTOCOL *This,
28 IN EFI_HANDLE Handle,
29 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
30 );
31
32 EFI_STATUS
33 EFIAPI
34 WinNtConsoleDriverBindingStart (
35 IN EFI_DRIVER_BINDING_PROTOCOL *This,
36 IN EFI_HANDLE Handle,
37 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
38 );
39
40 EFI_STATUS
41 EFIAPI
42 WinNtConsoleDriverBindingStop (
43 IN EFI_DRIVER_BINDING_PROTOCOL *This,
44 IN EFI_HANDLE Handle,
45 IN UINTN NumberOfChildren,
46 IN EFI_HANDLE *ChildHandleBuffer
47 );
48
49 EFI_DRIVER_BINDING_PROTOCOL gWinNtConsoleDriverBinding = {
50 WinNtConsoleDriverBindingSupported,
51 WinNtConsoleDriverBindingStart,
52 WinNtConsoleDriverBindingStop,
53 0xa,
54 NULL,
55 NULL
56 };
57
58
59 EFI_STATUS
60 EFIAPI
61 WinNtConsoleDriverBindingSupported (
62 IN EFI_DRIVER_BINDING_PROTOCOL *This,
63 IN EFI_HANDLE Handle,
64 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
65 )
66 /*++
67
68 Routine Description:
69
70 Arguments:
71
72 Returns:
73
74 None
75
76 --*/
77 // TODO: This - add argument and description to function comment
78 // TODO: Handle - add argument and description to function comment
79 // TODO: RemainingDevicePath - add argument and description to function comment
80 {
81 EFI_STATUS Status;
82 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
83
84 //
85 // Open the IO Abstraction(s) needed to perform the supported test
86 //
87 Status = gBS->OpenProtocol (
88 Handle,
89 &gEfiWinNtIoProtocolGuid,
90 &WinNtIo,
91 This->DriverBindingHandle,
92 Handle,
93 EFI_OPEN_PROTOCOL_BY_DRIVER
94 );
95 if (EFI_ERROR (Status)) {
96 return Status;
97 }
98
99 //
100 // Make sure that the WinNt Thunk Protocol is valid
101 //
102 Status = EFI_UNSUPPORTED;
103 if (WinNtIo->WinNtThunk->Signature == EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) {
104
105 //
106 // Check the GUID to see if this is a handle type the driver supports
107 //
108 if (CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtConsoleGuid)) {
109 Status = EFI_SUCCESS;
110 }
111 }
112
113 //
114 // Close the I/O Abstraction(s) used to perform the supported test
115 //
116 gBS->CloseProtocol (
117 Handle,
118 &gEfiWinNtIoProtocolGuid,
119 This->DriverBindingHandle,
120 Handle
121 );
122
123 return Status;
124 }
125
126 EFI_STATUS
127 EFIAPI
128 WinNtConsoleDriverBindingStart (
129 IN EFI_DRIVER_BINDING_PROTOCOL *This,
130 IN EFI_HANDLE Handle,
131 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
132 )
133 /*++
134
135 Routine Description:
136
137 Arguments:
138
139 Returns:
140
141 None
142
143 --*/
144 // TODO: This - add argument and description to function comment
145 // TODO: Handle - add argument and description to function comment
146 // TODO: RemainingDevicePath - add argument and description to function comment
147 {
148 EFI_STATUS Status;
149 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
150 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
151
152 //
153 // Grab the IO abstraction we need to get any work done
154 //
155 Status = gBS->OpenProtocol (
156 Handle,
157 &gEfiWinNtIoProtocolGuid,
158 &WinNtIo,
159 This->DriverBindingHandle,
160 Handle,
161 EFI_OPEN_PROTOCOL_BY_DRIVER
162 );
163 if (EFI_ERROR (Status)) {
164 return Status;
165 }
166
167 Status = gBS->AllocatePool (
168 EfiBootServicesData,
169 sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA),
170 &Private
171 );
172 if (EFI_ERROR (Status)) {
173 goto Done;
174 }
175
176 ZeroMem (Private, sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA));
177
178 Private->Signature = WIN_NT_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE;
179 Private->Handle = Handle;
180 Private->WinNtIo = WinNtIo;
181 Private->WinNtThunk = WinNtIo->WinNtThunk;
182
183 WinNtSimpleTextOutOpenWindow (Private);
184 WinNtSimpleTextInAttachToWindow (Private);
185
186 Status = gBS->InstallMultipleProtocolInterfaces (
187 &Handle,
188 &gEfiSimpleTextOutProtocolGuid,
189 &Private->SimpleTextOut,
190 &gEfiSimpleTextInProtocolGuid,
191 &Private->SimpleTextIn,
192 NULL
193 );
194 if (!EFI_ERROR (Status)) {
195 return Status;
196 }
197
198 Done:
199 gBS->CloseProtocol (
200 Handle,
201 &gEfiWinNtIoProtocolGuid,
202 This->DriverBindingHandle,
203 Handle
204 );
205 if (Private != NULL) {
206
207 FreeUnicodeStringTable (Private->ControllerNameTable);
208
209 if (Private->NtOutHandle != NULL) {
210 Private->WinNtThunk->CloseHandle (Private->NtOutHandle);
211 }
212
213 if (Private->SimpleTextIn.WaitForKey != NULL) {
214 gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
215 }
216
217 gBS->FreePool (Private);
218 }
219
220 return Status;
221 }
222
223 EFI_STATUS
224 EFIAPI
225 WinNtConsoleDriverBindingStop (
226 IN EFI_DRIVER_BINDING_PROTOCOL *This,
227 IN EFI_HANDLE Handle,
228 IN UINTN NumberOfChildren,
229 IN EFI_HANDLE *ChildHandleBuffer
230 )
231 /*++
232
233 Routine Description:
234
235 TODO: Add function description
236
237 Arguments:
238
239 This - TODO: add argument description
240 Handle - TODO: add argument description
241 NumberOfChildren - TODO: add argument description
242 ChildHandleBuffer - TODO: add argument description
243
244 Returns:
245
246 EFI_UNSUPPORTED - TODO: Add description for return value
247
248 --*/
249 {
250 EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleTextOut;
251 EFI_STATUS Status;
252 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
253
254 //
255 // Kick people off our interface???
256 //
257 Status = gBS->OpenProtocol (
258 Handle,
259 &gEfiSimpleTextOutProtocolGuid,
260 &SimpleTextOut,
261 This->DriverBindingHandle,
262 Handle,
263 EFI_OPEN_PROTOCOL_GET_PROTOCOL
264 );
265 if (EFI_ERROR (Status)) {
266 return EFI_UNSUPPORTED;
267 }
268
269 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);
270
271 ASSERT (Private->Handle == Handle);
272
273 Status = gBS->UninstallMultipleProtocolInterfaces (
274 Handle,
275 &gEfiSimpleTextOutProtocolGuid,
276 &Private->SimpleTextOut,
277 &gEfiSimpleTextInProtocolGuid,
278 &Private->SimpleTextIn,
279 NULL
280 );
281 if (!EFI_ERROR (Status)) {
282
283 //
284 // Shut down our device
285 //
286 Status = gBS->CloseProtocol (
287 Handle,
288 &gEfiWinNtIoProtocolGuid,
289 This->DriverBindingHandle,
290 Handle
291 );
292
293 Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
294 ASSERT_EFI_ERROR (Status);
295
296 Private->WinNtThunk->CloseHandle (Private->NtOutHandle);
297 //
298 // DO NOT close Private->NtInHandle. It points to StdIn and not
299 // the Private->NtOutHandle is StdIn and should not be closed!
300 //
301 FreeUnicodeStringTable (Private->ControllerNameTable);
302
303 gBS->FreePool (Private);
304 }
305
306 return Status;
307 }