]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/WinNtThunk/Bus/Console/Console.c
remove unnecessary check for NULL pointer.
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / Console / 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 #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 Private = AllocatePool (sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA));
168 if (Private == NULL) {
169 goto Done;
170 }
171
172 ZeroMem (Private, sizeof (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA));
173
174 Private->Signature = WIN_NT_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE;
175 Private->Handle = Handle;
176 Private->WinNtIo = WinNtIo;
177 Private->WinNtThunk = WinNtIo->WinNtThunk;
178
179 WinNtSimpleTextOutOpenWindow (Private);
180 WinNtSimpleTextInAttachToWindow (Private);
181
182 Status = gBS->InstallMultipleProtocolInterfaces (
183 &Handle,
184 &gEfiSimpleTextOutProtocolGuid,
185 &Private->SimpleTextOut,
186 &gEfiSimpleTextInProtocolGuid,
187 &Private->SimpleTextIn,
188 NULL
189 );
190 if (!EFI_ERROR (Status)) {
191 return Status;
192 }
193
194 Done:
195 gBS->CloseProtocol (
196 Handle,
197 &gEfiWinNtIoProtocolGuid,
198 This->DriverBindingHandle,
199 Handle
200 );
201 if (Private != NULL) {
202
203 FreeUnicodeStringTable (Private->ControllerNameTable);
204
205 if (Private->NtOutHandle != NULL) {
206 Private->WinNtThunk->CloseHandle (Private->NtOutHandle);
207 }
208
209 if (Private->SimpleTextIn.WaitForKey != NULL) {
210 gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
211 }
212
213 FreePool (Private);
214 }
215
216 return Status;
217 }
218
219 EFI_STATUS
220 EFIAPI
221 WinNtConsoleDriverBindingStop (
222 IN EFI_DRIVER_BINDING_PROTOCOL *This,
223 IN EFI_HANDLE Handle,
224 IN UINTN NumberOfChildren,
225 IN EFI_HANDLE *ChildHandleBuffer
226 )
227 /*++
228
229 Routine Description:
230
231 TODO: Add function description
232
233 Arguments:
234
235 This - TODO: add argument description
236 Handle - TODO: add argument description
237 NumberOfChildren - TODO: add argument description
238 ChildHandleBuffer - TODO: add argument description
239
240 Returns:
241
242 EFI_UNSUPPORTED - TODO: Add description for return value
243
244 --*/
245 {
246 EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleTextOut;
247 EFI_STATUS Status;
248 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
249
250 //
251 // Kick people off our interface???
252 //
253 Status = gBS->OpenProtocol (
254 Handle,
255 &gEfiSimpleTextOutProtocolGuid,
256 &SimpleTextOut,
257 This->DriverBindingHandle,
258 Handle,
259 EFI_OPEN_PROTOCOL_GET_PROTOCOL
260 );
261 if (EFI_ERROR (Status)) {
262 return EFI_UNSUPPORTED;
263 }
264
265 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);
266
267 ASSERT (Private->Handle == Handle);
268
269 Status = gBS->UninstallMultipleProtocolInterfaces (
270 Handle,
271 &gEfiSimpleTextOutProtocolGuid,
272 &Private->SimpleTextOut,
273 &gEfiSimpleTextInProtocolGuid,
274 &Private->SimpleTextIn,
275 NULL
276 );
277 if (!EFI_ERROR (Status)) {
278
279 //
280 // Shut down our device
281 //
282 Status = gBS->CloseProtocol (
283 Handle,
284 &gEfiWinNtIoProtocolGuid,
285 This->DriverBindingHandle,
286 Handle
287 );
288
289 Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
290 ASSERT_EFI_ERROR (Status);
291
292 Private->WinNtThunk->CloseHandle (Private->NtOutHandle);
293 //
294 // DO NOT close Private->NtInHandle. It points to StdIn and not
295 // the Private->NtOutHandle is StdIn and should not be closed!
296 //
297 FreeUnicodeStringTable (Private->ControllerNameTable);
298
299 FreePool (Private);
300 }
301
302 return Status;
303 }