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