]>
Commit | Line | Data |
---|---|---|
fb0b259e | 1 | /** @file\r |
11baadb6 | 2 | Produces Simple Text Input Protocol, Simple Text Input Extended Protocol and\r |
fb0b259e | 3 | Simple Text Output Protocol upon Serial IO Protocol.\r |
95276127 | 4 | \r |
8ce87fff | 5 | Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 6 | This program and the accompanying materials\r |
95276127 | 7 | are licensed and made available under the terms and conditions of the BSD License\r |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
fb0b259e | 14 | **/\r |
95276127 | 15 | \r |
16 | \r | |
95276127 | 17 | #include "Terminal.h"\r |
18 | \r | |
95276127 | 19 | //\r |
20 | // Globals\r | |
21 | //\r | |
22 | EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding = {\r | |
23 | TerminalDriverBindingSupported,\r | |
24 | TerminalDriverBindingStart,\r | |
25 | TerminalDriverBindingStop,\r | |
26 | 0xa,\r | |
27 | NULL,\r | |
28 | NULL\r | |
29 | };\r | |
30 | \r | |
31 | \r | |
f9163275 | 32 | EFI_GUID *mTerminalType[] = {\r |
6b88ceec A |
33 | &gEfiPcAnsiGuid,\r |
34 | &gEfiVT100Guid,\r | |
35 | &gEfiVT100PlusGuid,\r | |
6e3227c8 RF |
36 | &gEfiVTUTF8Guid,\r |
37 | &gEfiTtyTermGuid\r | |
6b88ceec A |
38 | };\r |
39 | \r | |
40 | \r | |
fa3f99e5 RN |
41 | CHAR16 *mSerialConsoleNames[] = {\r |
42 | L"PC-ANSI Serial Console",\r | |
43 | L"VT-100 Serial Console",\r | |
44 | L"VT-100+ Serial Console",\r | |
45 | L"VT-UTF8 Serial Console",\r | |
46 | L"Tty Terminal Serial Console"\r | |
47 | };\r | |
48 | \r | |
204ba917 | 49 | TERMINAL_DEV mTerminalDevTemplate = {\r |
6b88ceec A |
50 | TERMINAL_DEV_SIGNATURE,\r |
51 | NULL,\r | |
52 | 0,\r | |
53 | NULL,\r | |
54 | NULL,\r | |
55 | { // SimpleTextInput\r | |
56 | TerminalConInReset,\r | |
57 | TerminalConInReadKeyStroke,\r | |
58 | NULL\r | |
59 | },\r | |
60 | { // SimpleTextOutput\r | |
61 | TerminalConOutReset,\r | |
62 | TerminalConOutOutputString,\r | |
63 | TerminalConOutTestString,\r | |
64 | TerminalConOutQueryMode,\r | |
65 | TerminalConOutSetMode,\r | |
66 | TerminalConOutSetAttribute,\r | |
67 | TerminalConOutClearScreen,\r | |
68 | TerminalConOutSetCursorPosition,\r | |
69 | TerminalConOutEnableCursor,\r | |
70 | NULL\r | |
71 | },\r | |
72 | { // SimpleTextOutputMode\r | |
73 | 1, // MaxMode\r | |
11baadb6 | 74 | 0, // Mode\r |
6b88ceec A |
75 | EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK), // Attribute\r |
76 | 0, // CursorColumn\r | |
77 | 0, // CursorRow\r | |
78 | TRUE // CursorVisible\r | |
79 | },\r | |
79d07c66 | 80 | NULL, // TerminalConsoleModeData\r |
11baadb6 | 81 | 0, // SerialInTimeOut\r |
5c998646 | 82 | \r |
83 | NULL, // RawFifo\r | |
84 | NULL, // UnicodeFiFo\r | |
85 | NULL, // EfiKeyFiFo\r | |
47b612db | 86 | NULL, // EfiKeyFiFoForNotify\r |
5c998646 | 87 | \r |
6b88ceec | 88 | NULL, // ControllerNameTable\r |
f0368006 | 89 | NULL, // TimerEvent\r |
11baadb6 | 90 | NULL, // TwoSecondTimeOut\r |
6b88ceec A |
91 | INPUT_STATE_DEFAULT,\r |
92 | RESET_STATE_DEFAULT,\r | |
014f93ac RF |
93 | {\r |
94 | 0,\r | |
95 | 0,\r | |
96 | 0\r | |
97 | },\r | |
98 | 0,\r | |
66aa04e4 | 99 | FALSE,\r |
100 | { // SimpleTextInputEx\r | |
101 | TerminalConInResetEx,\r | |
102 | TerminalConInReadKeyStrokeEx,\r | |
103 | NULL,\r | |
104 | TerminalConInSetState,\r | |
105 | TerminalConInRegisterKeyNotify,\r | |
106 | TerminalConInUnregisterKeyNotify,\r | |
107 | },\r | |
11baadb6 | 108 | { // NotifyList\r |
66aa04e4 | 109 | NULL,\r |
110 | NULL,\r | |
47b612db SZ |
111 | },\r |
112 | NULL // KeyNotifyProcessEvent\r | |
6b88ceec A |
113 | };\r |
114 | \r | |
79d07c66 | 115 | TERMINAL_CONSOLE_MODE_DATA mTerminalConsoleModeData[] = {\r |
390b95a4 RN |
116 | {80, 25},\r |
117 | {80, 50},\r | |
79d07c66 | 118 | {100, 31},\r |
119 | //\r | |
120 | // New modes can be added here.\r | |
79d07c66 | 121 | //\r |
79d07c66 | 122 | };\r |
123 | \r | |
f9163275 RN |
124 | /**\r |
125 | Convert the GUID representation of terminal type to enum type.\r | |
126 | \r | |
127 | @param Guid The GUID representation of terminal type.\r | |
128 | \r | |
129 | @return The terminal type in enum type.\r | |
130 | **/\r | |
131 | TERMINAL_TYPE\r | |
132 | TerminalTypeFromGuid (\r | |
133 | IN EFI_GUID *Guid\r | |
134 | )\r | |
135 | {\r | |
136 | TERMINAL_TYPE Type;\r | |
137 | \r | |
138 | for (Type = 0; Type < ARRAY_SIZE (mTerminalType); Type++) {\r | |
139 | if (CompareGuid (Guid, mTerminalType[Type])) {\r | |
140 | break;\r | |
141 | }\r | |
142 | }\r | |
143 | return Type;\r | |
144 | }\r | |
145 | \r | |
8fd98315 | 146 | /**\r |
677fdb90 | 147 | Test to see if this driver supports Controller.\r |
8fd98315 | 148 | \r |
149 | @param This Protocol instance pointer.\r | |
ab76200c | 150 | @param Controller Handle of device to test\r |
8fd98315 | 151 | @param RemainingDevicePath Optional parameter use to pick a specific child\r |
152 | device to start.\r | |
153 | \r | |
ab76200c | 154 | @retval EFI_SUCCESS This driver supports this device.\r |
155 | @retval EFI_ALREADY_STARTED This driver is already running on this device.\r | |
156 | @retval other This driver does not support this device.\r | |
6b88ceec | 157 | \r |
8fd98315 | 158 | **/\r |
95276127 | 159 | EFI_STATUS\r |
160 | EFIAPI\r | |
161 | TerminalDriverBindingSupported (\r | |
162 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
163 | IN EFI_HANDLE Controller,\r | |
164 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
165 | )\r | |
166 | {\r | |
167 | EFI_STATUS Status;\r | |
168 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
169 | EFI_SERIAL_IO_PROTOCOL *SerialIo;\r | |
170 | VENDOR_DEVICE_PATH *Node;\r | |
171 | \r | |
172 | //\r | |
173 | // If remaining device path is not NULL, then make sure it is a\r | |
174 | // device path that describes a terminal communications protocol.\r | |
175 | //\r | |
176 | if (RemainingDevicePath != NULL) {\r | |
95276127 | 177 | //\r |
e3dcffcc | 178 | // Check if RemainingDevicePath is the End of Device Path Node,\r |
af4a6385 | 179 | // if yes, go on checking other conditions\r |
95276127 | 180 | //\r |
af4a6385 | 181 | if (!IsDevicePathEnd (RemainingDevicePath)) {\r |
182 | //\r | |
183 | // If RemainingDevicePath isn't the End of Device Path Node,\r | |
184 | // check its validation\r | |
185 | //\r | |
186 | Node = (VENDOR_DEVICE_PATH *) RemainingDevicePath;\r | |
e3dcffcc | 187 | \r |
af4a6385 | 188 | if (Node->Header.Type != MESSAGING_DEVICE_PATH ||\r |
189 | Node->Header.SubType != MSG_VENDOR_DP ||\r | |
190 | DevicePathNodeLength(&Node->Header) != sizeof(VENDOR_DEVICE_PATH)) {\r | |
e3dcffcc | 191 | \r |
af4a6385 | 192 | return EFI_UNSUPPORTED;\r |
e3dcffcc | 193 | \r |
af4a6385 | 194 | }\r |
195 | //\r | |
6e3227c8 | 196 | // only supports PC ANSI, VT100, VT100+, VT-UTF8, and TtyTerm terminal types\r |
af4a6385 | 197 | //\r |
f9163275 | 198 | if (TerminalTypeFromGuid (&Node->Guid) == ARRAY_SIZE (mTerminalType)) {\r |
af4a6385 | 199 | return EFI_UNSUPPORTED;\r |
200 | }\r | |
95276127 | 201 | }\r |
202 | }\r | |
203 | //\r | |
204 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
af4a6385 | 205 | // The Controller must support the Serial I/O Protocol.\r |
206 | // This driver is a bus driver with at most 1 child device, so it is\r | |
207 | // ok for it to be already started.\r | |
95276127 | 208 | //\r |
209 | Status = gBS->OpenProtocol (\r | |
210 | Controller,\r | |
af4a6385 | 211 | &gEfiSerialIoProtocolGuid,\r |
212 | (VOID **) &SerialIo,\r | |
95276127 | 213 | This->DriverBindingHandle,\r |
214 | Controller,\r | |
215 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
216 | );\r | |
217 | if (Status == EFI_ALREADY_STARTED) {\r | |
218 | return EFI_SUCCESS;\r | |
219 | }\r | |
220 | \r | |
221 | if (EFI_ERROR (Status)) {\r | |
222 | return Status;\r | |
223 | }\r | |
224 | \r | |
af4a6385 | 225 | //\r |
226 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
227 | //\r | |
95276127 | 228 | gBS->CloseProtocol (\r |
229 | Controller,\r | |
af4a6385 | 230 | &gEfiSerialIoProtocolGuid,\r |
95276127 | 231 | This->DriverBindingHandle,\r |
232 | Controller\r | |
233 | );\r | |
234 | \r | |
235 | //\r | |
af4a6385 | 236 | // Open the EFI Device Path protocol needed to perform the supported test\r |
95276127 | 237 | //\r |
238 | Status = gBS->OpenProtocol (\r | |
239 | Controller,\r | |
af4a6385 | 240 | &gEfiDevicePathProtocolGuid,\r |
241 | (VOID **) &ParentDevicePath,\r | |
95276127 | 242 | This->DriverBindingHandle,\r |
243 | Controller,\r | |
244 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
245 | );\r | |
246 | if (Status == EFI_ALREADY_STARTED) {\r | |
247 | return EFI_SUCCESS;\r | |
248 | }\r | |
249 | \r | |
250 | if (EFI_ERROR (Status)) {\r | |
251 | return Status;\r | |
252 | }\r | |
af4a6385 | 253 | \r |
95276127 | 254 | //\r |
af4a6385 | 255 | // Close protocol, don't use device path protocol in the Support() function\r |
95276127 | 256 | //\r |
257 | gBS->CloseProtocol (\r | |
258 | Controller,\r | |
af4a6385 | 259 | &gEfiDevicePathProtocolGuid,\r |
95276127 | 260 | This->DriverBindingHandle,\r |
261 | Controller\r | |
262 | );\r | |
263 | \r | |
264 | return Status;\r | |
265 | }\r | |
266 | \r | |
e3dcffcc | 267 | \r |
268 | /**\r | |
269 | Free notify functions list.\r | |
270 | \r | |
271 | @param ListHead The list head\r | |
272 | \r | |
273 | @retval EFI_SUCCESS Free the notify list successfully.\r | |
274 | @retval EFI_INVALID_PARAMETER ListHead is NULL.\r | |
275 | \r | |
276 | **/\r | |
277 | EFI_STATUS\r | |
278 | TerminalFreeNotifyList (\r | |
279 | IN OUT LIST_ENTRY *ListHead\r | |
280 | )\r | |
281 | {\r | |
282 | TERMINAL_CONSOLE_IN_EX_NOTIFY *NotifyNode;\r | |
283 | \r | |
284 | if (ListHead == NULL) {\r | |
285 | return EFI_INVALID_PARAMETER;\r | |
286 | }\r | |
287 | while (!IsListEmpty (ListHead)) {\r | |
288 | NotifyNode = CR (\r | |
289 | ListHead->ForwardLink,\r | |
290 | TERMINAL_CONSOLE_IN_EX_NOTIFY,\r | |
291 | NotifyEntry,\r | |
292 | TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE\r | |
293 | );\r | |
294 | RemoveEntryList (ListHead->ForwardLink);\r | |
295 | FreePool (NotifyNode);\r | |
296 | }\r | |
297 | \r | |
298 | return EFI_SUCCESS;\r | |
299 | }\r | |
300 | \r | |
79d07c66 | 301 | /**\r |
302 | Initialize all the text modes which the terminal console supports.\r | |
303 | \r | |
304 | It returns information for available text modes that the terminal can support.\r | |
305 | \r | |
306 | @param[out] TextModeCount The total number of text modes that terminal console supports.\r | |
79d07c66 | 307 | \r |
390b95a4 RN |
308 | @return The buffer to the text modes column and row information.\r |
309 | Caller is responsible to free it when it's non-NULL.\r | |
79d07c66 | 310 | \r |
311 | **/\r | |
390b95a4 | 312 | TERMINAL_CONSOLE_MODE_DATA *\r |
79d07c66 | 313 | InitializeTerminalConsoleTextMode (\r |
390b95a4 RN |
314 | OUT INT32 *TextModeCount\r |
315 | )\r | |
79d07c66 | 316 | {\r |
390b95a4 RN |
317 | TERMINAL_CONSOLE_MODE_DATA *TextModeData;\r |
318 | \r | |
319 | ASSERT (TextModeCount != NULL);\r | |
320 | \r | |
390b95a4 RN |
321 | TextModeData = AllocateCopyPool (sizeof (mTerminalConsoleModeData), mTerminalConsoleModeData);\r |
322 | if (TextModeData == NULL) {\r | |
323 | return NULL;\r | |
79d07c66 | 324 | }\r |
390b95a4 RN |
325 | *TextModeCount = ARRAY_SIZE (mTerminalConsoleModeData);\r |
326 | \r | |
79d07c66 | 327 | DEBUG_CODE (\r |
390b95a4 RN |
328 | INT32 Index;\r |
329 | for (Index = 0; Index < *TextModeCount; Index++) {\r | |
330 | DEBUG ((DEBUG_INFO, "Terminal - Mode %d, Column = %d, Row = %d\n",\r | |
331 | Index, TextModeData[Index].Columns, TextModeData[Index].Rows));\r | |
79d07c66 | 332 | }\r |
333 | );\r | |
390b95a4 | 334 | return TextModeData;\r |
79d07c66 | 335 | }\r |
e3dcffcc | 336 | \r |
b7cf1c07 RN |
337 | /**\r |
338 | Stop the terminal state machine.\r | |
339 | \r | |
340 | @param TerminalDevice The terminal device.\r | |
341 | **/\r | |
342 | VOID\r | |
343 | StopTerminalStateMachine (\r | |
344 | TERMINAL_DEV *TerminalDevice\r | |
345 | )\r | |
346 | {\r | |
347 | EFI_TPL OriginalTpl;\r | |
348 | \r | |
349 | OriginalTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
350 | \r | |
351 | gBS->CloseEvent (TerminalDevice->TimerEvent);\r | |
352 | gBS->CloseEvent (TerminalDevice->TwoSecondTimeOut);\r | |
353 | \r | |
354 | gBS->RestoreTPL (OriginalTpl);\r | |
355 | }\r | |
356 | \r | |
357 | /**\r | |
358 | Start the terminal state machine.\r | |
359 | \r | |
360 | @param TerminalDevice The terminal device.\r | |
361 | **/\r | |
362 | VOID\r | |
363 | StartTerminalStateMachine (\r | |
364 | TERMINAL_DEV *TerminalDevice\r | |
365 | )\r | |
366 | {\r | |
367 | EFI_STATUS Status;\r | |
368 | Status = gBS->CreateEvent (\r | |
369 | EVT_TIMER | EVT_NOTIFY_SIGNAL,\r | |
370 | TPL_NOTIFY,\r | |
371 | TerminalConInTimerHandler,\r | |
372 | TerminalDevice,\r | |
373 | &TerminalDevice->TimerEvent\r | |
374 | );\r | |
375 | ASSERT_EFI_ERROR (Status);\r | |
376 | \r | |
377 | Status = gBS->SetTimer (\r | |
378 | TerminalDevice->TimerEvent,\r | |
379 | TimerPeriodic,\r | |
380 | KEYBOARD_TIMER_INTERVAL\r | |
381 | );\r | |
382 | ASSERT_EFI_ERROR (Status);\r | |
383 | \r | |
384 | Status = gBS->CreateEvent (\r | |
385 | EVT_TIMER,\r | |
386 | TPL_CALLBACK,\r | |
387 | NULL,\r | |
388 | NULL,\r | |
389 | &TerminalDevice->TwoSecondTimeOut\r | |
390 | );\r | |
391 | ASSERT_EFI_ERROR (Status);\r | |
392 | }\r | |
393 | \r | |
fa3f99e5 RN |
394 | /**\r |
395 | Initialize the controller name table.\r | |
396 | \r | |
397 | @param TerminalType The terminal type.\r | |
398 | @param ControllerNameTable The controller name table.\r | |
399 | \r | |
400 | @retval EFI_SUCCESS The controller name table is initialized successfully.\r | |
401 | @retval others Return status of AddUnicodeString2 ().\r | |
402 | **/\r | |
403 | EFI_STATUS\r | |
404 | InitializeControllerNameTable (\r | |
405 | TERMINAL_TYPE TerminalType,\r | |
406 | EFI_UNICODE_STRING_TABLE **ControllerNameTable\r | |
407 | )\r | |
408 | {\r | |
409 | EFI_STATUS Status;\r | |
410 | EFI_UNICODE_STRING_TABLE *Table;\r | |
411 | \r | |
412 | ASSERT (TerminalType < ARRAY_SIZE (mTerminalType));\r | |
413 | Table = NULL;\r | |
414 | Status = AddUnicodeString2 (\r | |
415 | "eng",\r | |
416 | gTerminalComponentName.SupportedLanguages,\r | |
417 | &Table,\r | |
418 | mSerialConsoleNames[TerminalType],\r | |
419 | TRUE\r | |
420 | );\r | |
421 | if (!EFI_ERROR (Status)) {\r | |
422 | Status = AddUnicodeString2 (\r | |
423 | "en",\r | |
424 | gTerminalComponentName2.SupportedLanguages,\r | |
425 | &Table,\r | |
426 | mSerialConsoleNames[TerminalType],\r | |
427 | FALSE\r | |
428 | );\r | |
429 | if (EFI_ERROR (Status)) {\r | |
430 | FreeUnicodeStringTable (Table);\r | |
431 | }\r | |
432 | }\r | |
433 | if (!EFI_ERROR (Status)) {\r | |
434 | *ControllerNameTable = Table;\r | |
435 | }\r | |
436 | return Status;\r | |
437 | }\r | |
438 | \r | |
e49ef433 | 439 | /**\r |
ab76200c | 440 | Start this driver on Controller by opening a Serial IO protocol,\r |
8fd98315 | 441 | reading Device Path, and creating a child handle with a Simple Text In,\r |
442 | Simple Text In Ex and Simple Text Out protocol, and device path protocol.\r | |
443 | And store Console Device Environment Variables.\r | |
e49ef433 | 444 | \r |
8fd98315 | 445 | @param This Protocol instance pointer.\r |
ab76200c | 446 | @param Controller Handle of device to bind driver to\r |
8fd98315 | 447 | @param RemainingDevicePath Optional parameter use to pick a specific child\r |
448 | device to start.\r | |
e49ef433 | 449 | \r |
ab76200c | 450 | @retval EFI_SUCCESS This driver is added to Controller.\r |
451 | @retval EFI_ALREADY_STARTED This driver is already running on Controller.\r | |
452 | @retval other This driver does not support this device.\r | |
e49ef433 | 453 | \r |
454 | **/\r | |
95276127 | 455 | EFI_STATUS\r |
456 | EFIAPI\r | |
457 | TerminalDriverBindingStart (\r | |
458 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
459 | IN EFI_HANDLE Controller,\r | |
460 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
461 | )\r | |
95276127 | 462 | {\r |
463 | EFI_STATUS Status;\r | |
464 | EFI_SERIAL_IO_PROTOCOL *SerialIo;\r | |
465 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
f7c11d9b RN |
466 | EFI_DEVICE_PATH_PROTOCOL *Vendor;\r |
467 | EFI_HANDLE SerialIoHandle;\r | |
95276127 | 468 | EFI_SERIAL_IO_MODE *Mode;\r |
469 | UINTN SerialInTimeOut;\r | |
470 | TERMINAL_DEV *TerminalDevice;\r | |
f7c11d9b | 471 | UINT8 TerminalType;\r |
95276127 | 472 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r |
473 | UINTN EntryCount;\r | |
474 | UINTN Index;\r | |
c4f9201e | 475 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOutput;\r |
e3dcffcc | 476 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleTextInput;\r |
f7c11d9b RN |
477 | EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r |
478 | \r | |
95276127 | 479 | //\r |
480 | // Get the Device Path Protocol to build the device path of the child device\r | |
481 | //\r | |
482 | Status = gBS->OpenProtocol (\r | |
483 | Controller,\r | |
484 | &gEfiDevicePathProtocolGuid,\r | |
485 | (VOID **) &ParentDevicePath,\r | |
486 | This->DriverBindingHandle,\r | |
487 | Controller,\r | |
488 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
489 | );\r | |
f7c11d9b | 490 | ASSERT ((Status == EFI_SUCCESS) || (Status == EFI_ALREADY_STARTED));\r |
95276127 | 491 | \r |
492 | //\r | |
493 | // Open the Serial I/O Protocol BY_DRIVER. It might already be started.\r | |
494 | //\r | |
495 | Status = gBS->OpenProtocol (\r | |
496 | Controller,\r | |
497 | &gEfiSerialIoProtocolGuid,\r | |
498 | (VOID **) &SerialIo,\r | |
499 | This->DriverBindingHandle,\r | |
500 | Controller,\r | |
501 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
502 | );\r | |
f7c11d9b | 503 | ASSERT ((Status == EFI_SUCCESS) || (Status == EFI_ALREADY_STARTED));\r |
95276127 | 504 | \r |
f7c11d9b | 505 | if (!IsHotPlugDevice (ParentDevicePath)) {\r |
95276127 | 506 | //\r |
f7c11d9b RN |
507 | // if the serial device is a hot plug device, do not update the\r |
508 | // ConInDev, ConOutDev, and StdErrDev variables.\r | |
95276127 | 509 | //\r |
f7c11d9b RN |
510 | TerminalUpdateConsoleDevVariable (EFI_CON_IN_DEV_VARIABLE_NAME, ParentDevicePath);\r |
511 | TerminalUpdateConsoleDevVariable (EFI_CON_OUT_DEV_VARIABLE_NAME, ParentDevicePath);\r | |
512 | TerminalUpdateConsoleDevVariable (EFI_ERR_OUT_DEV_VARIABLE_NAME, ParentDevicePath);\r | |
95276127 | 513 | }\r |
e3dcffcc | 514 | \r |
95276127 | 515 | //\r |
f7c11d9b | 516 | // Do not create any child for END remaining device path.\r |
95276127 | 517 | //\r |
f7c11d9b RN |
518 | if ((RemainingDevicePath != NULL) && IsDevicePathEnd (RemainingDevicePath)) {\r |
519 | return EFI_SUCCESS;\r | |
520 | }\r | |
95276127 | 521 | \r |
f7c11d9b RN |
522 | if (Status == EFI_ALREADY_STARTED) {\r |
523 | \r | |
524 | if (RemainingDevicePath == NULL) {\r | |
e3dcffcc | 525 | //\r |
f7c11d9b | 526 | // If RemainingDevicePath is NULL or is the End of Device Path Node\r |
e3dcffcc | 527 | //\r |
f7c11d9b | 528 | return EFI_SUCCESS;\r |
95276127 | 529 | }\r |
e3dcffcc | 530 | \r |
e3dcffcc | 531 | //\r |
f7c11d9b RN |
532 | // This driver can only produce one child per serial port.\r |
533 | // Change its terminal type as remaining device path requests.\r | |
e3dcffcc | 534 | //\r |
535 | Status = gBS->OpenProtocolInformation (\r | |
536 | Controller,\r | |
537 | &gEfiSerialIoProtocolGuid,\r | |
538 | &OpenInfoBuffer,\r | |
539 | &EntryCount\r | |
540 | );\r | |
541 | if (!EFI_ERROR (Status)) {\r | |
f7c11d9b | 542 | Status = EFI_NOT_FOUND;\r |
e3dcffcc | 543 | for (Index = 0; Index < EntryCount; Index++) {\r |
544 | if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r | |
f7c11d9b RN |
545 | Status = gBS->OpenProtocol (\r |
546 | OpenInfoBuffer[Index].ControllerHandle,\r | |
547 | &gEfiSimpleTextInProtocolGuid,\r | |
548 | (VOID **) &SimpleTextInput,\r | |
549 | This->DriverBindingHandle,\r | |
550 | Controller,\r | |
551 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
552 | );\r | |
553 | if (!EFI_ERROR (Status)) {\r | |
554 | TerminalDevice = TERMINAL_CON_IN_DEV_FROM_THIS (SimpleTextInput);\r | |
555 | TerminalType = TerminalTypeFromGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid);\r | |
556 | ASSERT (TerminalType < ARRAY_SIZE (mTerminalType));\r | |
557 | if (TerminalDevice->TerminalType != TerminalType) {\r | |
558 | Status = InitializeControllerNameTable (TerminalType, &ControllerNameTable);\r | |
559 | if (!EFI_ERROR (Status)) {\r | |
560 | StopTerminalStateMachine (TerminalDevice);\r | |
561 | //\r | |
562 | // Update the device path\r | |
563 | //\r | |
564 | Vendor = TerminalDevice->DevicePath;\r | |
565 | Status = gBS->LocateDevicePath (&gEfiSerialIoProtocolGuid, &Vendor, &SerialIoHandle);\r | |
566 | ASSERT_EFI_ERROR (Status);\r | |
567 | CopyGuid (&((VENDOR_DEVICE_PATH *) Vendor)->Guid, mTerminalType[TerminalType]);\r | |
568 | Status = gBS->ReinstallProtocolInterface (\r | |
569 | TerminalDevice->Handle,\r | |
570 | &gEfiDevicePathProtocolGuid,\r | |
571 | TerminalDevice->DevicePath,\r | |
572 | TerminalDevice->DevicePath\r | |
573 | );\r | |
574 | if (!EFI_ERROR (Status)) {\r | |
575 | TerminalDevice->TerminalType = TerminalType;\r | |
576 | StartTerminalStateMachine (TerminalDevice);\r | |
577 | FreeUnicodeStringTable (TerminalDevice->ControllerNameTable);\r | |
578 | TerminalDevice->ControllerNameTable = ControllerNameTable;\r | |
579 | } else {\r | |
580 | //\r | |
581 | // Restore the device path on failure\r | |
582 | //\r | |
583 | CopyGuid (&((VENDOR_DEVICE_PATH *) Vendor)->Guid, mTerminalType[TerminalDevice->TerminalType]);\r | |
584 | FreeUnicodeStringTable (ControllerNameTable);\r | |
585 | }\r | |
586 | }\r | |
587 | }\r | |
588 | }\r | |
589 | break;\r | |
e3dcffcc | 590 | }\r |
591 | }\r | |
e3dcffcc | 592 | FreePool (OpenInfoBuffer);\r |
e3dcffcc | 593 | }\r |
f7c11d9b RN |
594 | return Status;\r |
595 | }\r | |
e3dcffcc | 596 | \r |
f7c11d9b RN |
597 | //\r |
598 | // Initialize the Terminal Dev\r | |
599 | //\r | |
600 | TerminalDevice = AllocateCopyPool (sizeof (TERMINAL_DEV), &mTerminalDevTemplate);\r | |
601 | if (TerminalDevice == NULL) {\r | |
602 | Status = EFI_OUT_OF_RESOURCES;\r | |
603 | goto CloseProtocols;\r | |
604 | }\r | |
390b95a4 | 605 | \r |
f7c11d9b | 606 | if (RemainingDevicePath == NULL) {\r |
e3dcffcc | 607 | //\r |
f7c11d9b | 608 | // If RemainingDevicePath is NULL, use default terminal type\r |
e3dcffcc | 609 | //\r |
f7c11d9b RN |
610 | TerminalDevice->TerminalType = PcdGet8 (PcdDefaultTerminalType);\r |
611 | } else {\r | |
e3dcffcc | 612 | //\r |
f7c11d9b | 613 | // End of Device Path Node is handled in above.\r |
e3dcffcc | 614 | //\r |
f7c11d9b | 615 | ASSERT (!IsDevicePathEnd (RemainingDevicePath));\r |
95276127 | 616 | //\r |
f7c11d9b RN |
617 | // If RemainingDevicePath isn't the End of Device Path Node,\r |
618 | // Use the RemainingDevicePath to determine the terminal type\r | |
95276127 | 619 | //\r |
f7c11d9b RN |
620 | TerminalDevice->TerminalType = TerminalTypeFromGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid);\r |
621 | }\r | |
622 | ASSERT (TerminalDevice->TerminalType < ARRAY_SIZE (mTerminalType));\r | |
623 | TerminalDevice->SerialIo = SerialIo;\r | |
abef1c7a | 624 | \r |
f7c11d9b RN |
625 | //\r |
626 | // Build the component name for the child device\r | |
627 | //\r | |
628 | Status = InitializeControllerNameTable (TerminalDevice->TerminalType, &TerminalDevice->ControllerNameTable);\r | |
629 | if (EFI_ERROR (Status)) {\r | |
630 | goto FreeResources;\r | |
631 | }\r | |
abef1c7a | 632 | \r |
f7c11d9b RN |
633 | //\r |
634 | // Build the device path for the child device\r | |
635 | //\r | |
636 | Status = SetTerminalDevicePath (TerminalDevice->TerminalType, ParentDevicePath, &TerminalDevice->DevicePath);\r | |
637 | if (EFI_ERROR (Status)) {\r | |
638 | goto FreeResources;\r | |
639 | }\r | |
abef1c7a | 640 | \r |
f7c11d9b RN |
641 | InitializeListHead (&TerminalDevice->NotifyList);\r |
642 | Status = gBS->CreateEvent (\r | |
643 | EVT_NOTIFY_WAIT,\r | |
644 | TPL_NOTIFY,\r | |
645 | TerminalConInWaitForKeyEx,\r | |
646 | TerminalDevice,\r | |
647 | &TerminalDevice->SimpleInputEx.WaitForKeyEx\r | |
648 | );\r | |
649 | ASSERT_EFI_ERROR (Status);\r | |
47b612db | 650 | \r |
f7c11d9b RN |
651 | Status = gBS->CreateEvent (\r |
652 | EVT_NOTIFY_WAIT,\r | |
653 | TPL_NOTIFY,\r | |
654 | TerminalConInWaitForKey,\r | |
655 | TerminalDevice,\r | |
656 | &TerminalDevice->SimpleInput.WaitForKey\r | |
657 | );\r | |
658 | ASSERT_EFI_ERROR (Status);\r | |
659 | Status = gBS->CreateEvent (\r | |
660 | EVT_NOTIFY_SIGNAL,\r | |
661 | TPL_CALLBACK,\r | |
662 | KeyNotifyProcessHandler,\r | |
663 | TerminalDevice,\r | |
664 | &TerminalDevice->KeyNotifyProcessEvent\r | |
665 | );\r | |
666 | ASSERT_EFI_ERROR (Status);\r | |
95276127 | 667 | \r |
f7c11d9b RN |
668 | //\r |
669 | // Allocates and initializes the FIFO buffer to be zero, used for accommodating\r | |
670 | // the pre-read pending characters.\r | |
671 | //\r | |
672 | TerminalDevice->RawFiFo = AllocateZeroPool (sizeof (RAW_DATA_FIFO));\r | |
673 | if (TerminalDevice->RawFiFo == NULL) {\r | |
674 | goto FreeResources;\r | |
675 | }\r | |
676 | TerminalDevice->UnicodeFiFo = AllocateZeroPool (sizeof (UNICODE_FIFO));\r | |
677 | if (TerminalDevice->UnicodeFiFo == NULL) {\r | |
678 | goto FreeResources;\r | |
679 | }\r | |
680 | TerminalDevice->EfiKeyFiFo = AllocateZeroPool (sizeof (EFI_KEY_FIFO));\r | |
681 | if (TerminalDevice->EfiKeyFiFo == NULL) {\r | |
682 | goto FreeResources;\r | |
683 | }\r | |
684 | TerminalDevice->EfiKeyFiFoForNotify = AllocateZeroPool (sizeof (EFI_KEY_FIFO));\r | |
685 | if (TerminalDevice->EfiKeyFiFoForNotify == NULL) {\r | |
686 | goto FreeResources;\r | |
95276127 | 687 | }\r |
95276127 | 688 | \r |
3012ce5c | 689 | //\r |
f7c11d9b | 690 | // Set the timeout value of serial buffer for keystroke response performance issue\r |
3012ce5c | 691 | //\r |
f7c11d9b | 692 | Mode = TerminalDevice->SerialIo->Mode;\r |
3012ce5c | 693 | \r |
f7c11d9b RN |
694 | SerialInTimeOut = 0;\r |
695 | if (Mode->BaudRate != 0) {\r | |
696 | SerialInTimeOut = (1 + Mode->DataBits + Mode->StopBits) * 2 * 1000000 / (UINTN) Mode->BaudRate;\r | |
697 | }\r | |
95276127 | 698 | \r |
f7c11d9b RN |
699 | Status = TerminalDevice->SerialIo->SetAttributes (\r |
700 | TerminalDevice->SerialIo,\r | |
701 | Mode->BaudRate,\r | |
702 | Mode->ReceiveFifoDepth,\r | |
703 | (UINT32) SerialInTimeOut,\r | |
704 | (EFI_PARITY_TYPE) (Mode->Parity),\r | |
705 | (UINT8) Mode->DataBits,\r | |
706 | (EFI_STOP_BITS_TYPE) (Mode->StopBits)\r | |
707 | );\r | |
708 | if (EFI_ERROR (Status)) {\r | |
709 | //\r | |
710 | // if set attributes operation fails, invalidate\r | |
711 | // the value of SerialInTimeOut,thus make it\r | |
712 | // inconsistent with the default timeout value\r | |
713 | // of serial buffer. This will invoke the recalculation\r | |
714 | // in the readkeystroke routine.\r | |
715 | //\r | |
716 | TerminalDevice->SerialInTimeOut = 0;\r | |
e3dcffcc | 717 | } else {\r |
f7c11d9b | 718 | TerminalDevice->SerialInTimeOut = SerialInTimeOut;\r |
95276127 | 719 | }\r |
720 | \r | |
f7c11d9b RN |
721 | SimpleTextOutput = &TerminalDevice->SimpleTextOutput;\r |
722 | SimpleTextInput = &TerminalDevice->SimpleInput;\r | |
723 | \r | |
e3dcffcc | 724 | //\r |
f7c11d9b | 725 | // Initialize SimpleTextOut instance\r |
e3dcffcc | 726 | //\r |
f7c11d9b RN |
727 | SimpleTextOutput->Mode = &TerminalDevice->SimpleTextOutputMode;\r |
728 | TerminalDevice->TerminalConsoleModeData = InitializeTerminalConsoleTextMode (\r | |
729 | &SimpleTextOutput->Mode->MaxMode\r | |
730 | );\r | |
731 | if (TerminalDevice->TerminalConsoleModeData == NULL) {\r | |
732 | goto FreeResources;\r | |
95276127 | 733 | }\r |
95276127 | 734 | //\r |
f7c11d9b | 735 | // For terminal devices, cursor is always visible\r |
95276127 | 736 | //\r |
f7c11d9b RN |
737 | SimpleTextOutput->Mode->CursorVisible = TRUE;\r |
738 | Status = SimpleTextOutput->SetAttribute (SimpleTextOutput, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r | |
739 | if (!EFI_ERROR (Status)) {\r | |
740 | Status = SimpleTextOutput->Reset (SimpleTextOutput, FALSE);\r | |
741 | }\r | |
742 | if (EFI_ERROR (Status)) {\r | |
743 | goto ReportError;\r | |
95276127 | 744 | }\r |
f1aec6cc | 745 | \r |
95276127 | 746 | //\r |
f7c11d9b | 747 | // Initialize SimpleTextInput instance\r |
95276127 | 748 | //\r |
f7c11d9b RN |
749 | Status = SimpleTextInput->Reset (SimpleTextInput, FALSE);\r |
750 | if (EFI_ERROR (Status)) {\r | |
751 | goto ReportError;\r | |
95276127 | 752 | }\r |
753 | \r | |
f7c11d9b RN |
754 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
755 | &TerminalDevice->Handle,\r | |
756 | &gEfiSimpleTextInProtocolGuid, &TerminalDevice->SimpleInput,\r | |
757 | &gEfiSimpleTextInputExProtocolGuid, &TerminalDevice->SimpleInputEx,\r | |
758 | &gEfiSimpleTextOutProtocolGuid, &TerminalDevice->SimpleTextOutput,\r | |
759 | &gEfiDevicePathProtocolGuid, TerminalDevice->DevicePath,\r | |
760 | NULL\r | |
761 | );\r | |
762 | if (!EFI_ERROR (Status)) {\r | |
763 | Status = gBS->OpenProtocol (\r | |
764 | Controller,\r | |
765 | &gEfiSerialIoProtocolGuid,\r | |
766 | (VOID **) &TerminalDevice->SerialIo,\r | |
767 | This->DriverBindingHandle,\r | |
768 | TerminalDevice->Handle,\r | |
769 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
e3dcffcc | 770 | );\r |
f7c11d9b RN |
771 | ASSERT_EFI_ERROR (Status);\r |
772 | StartTerminalStateMachine (TerminalDevice);\r | |
773 | return Status;\r | |
e3dcffcc | 774 | }\r |
95276127 | 775 | \r |
95276127 | 776 | ReportError:\r |
95276127 | 777 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r |
778 | EFI_ERROR_CODE | EFI_ERROR_MINOR,\r | |
f9876ecf | 779 | (EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_CONTROLLER_ERROR),\r |
f7c11d9b | 780 | ParentDevicePath\r |
95276127 | 781 | );\r |
782 | \r | |
f7c11d9b RN |
783 | FreeResources:\r |
784 | ASSERT (TerminalDevice != NULL);\r | |
95276127 | 785 | \r |
f7c11d9b RN |
786 | if (TerminalDevice->SimpleInput.WaitForKey != NULL) {\r |
787 | gBS->CloseEvent (TerminalDevice->SimpleInput.WaitForKey);\r | |
788 | }\r | |
789 | if (TerminalDevice->SimpleInputEx.WaitForKeyEx != NULL) {\r | |
790 | gBS->CloseEvent (TerminalDevice->SimpleInputEx.WaitForKeyEx);\r | |
791 | }\r | |
792 | if (TerminalDevice->KeyNotifyProcessEvent != NULL) {\r | |
793 | gBS->CloseEvent (TerminalDevice->KeyNotifyProcessEvent);\r | |
794 | }\r | |
f0368006 | 795 | \r |
f7c11d9b RN |
796 | if (TerminalDevice->RawFiFo != NULL) {\r |
797 | FreePool (TerminalDevice->RawFiFo);\r | |
798 | }\r | |
799 | if (TerminalDevice->UnicodeFiFo != NULL) {\r | |
800 | FreePool (TerminalDevice->UnicodeFiFo);\r | |
801 | }\r | |
802 | if (TerminalDevice->EfiKeyFiFo != NULL) {\r | |
803 | FreePool (TerminalDevice->EfiKeyFiFo);\r | |
804 | }\r | |
805 | if (TerminalDevice->EfiKeyFiFoForNotify != NULL) {\r | |
806 | FreePool (TerminalDevice->EfiKeyFiFoForNotify);\r | |
807 | }\r | |
95276127 | 808 | \r |
f7c11d9b RN |
809 | if (TerminalDevice->ControllerNameTable != NULL) {\r |
810 | FreeUnicodeStringTable (TerminalDevice->ControllerNameTable);\r | |
811 | }\r | |
66aa04e4 | 812 | \r |
f7c11d9b RN |
813 | if (TerminalDevice->DevicePath != NULL) {\r |
814 | FreePool (TerminalDevice->DevicePath);\r | |
815 | }\r | |
66aa04e4 | 816 | \r |
f7c11d9b RN |
817 | if (TerminalDevice->TerminalConsoleModeData != NULL) {\r |
818 | FreePool (TerminalDevice->TerminalConsoleModeData);\r | |
819 | }\r | |
95276127 | 820 | \r |
f7c11d9b | 821 | FreePool (TerminalDevice);\r |
95276127 | 822 | \r |
f7c11d9b | 823 | CloseProtocols:\r |
79d07c66 | 824 | \r |
f7c11d9b RN |
825 | //\r |
826 | // Remove Parent Device Path from\r | |
827 | // the Console Device Environment Variables\r | |
828 | //\r | |
829 | TerminalRemoveConsoleDevVariable (EFI_CON_IN_DEV_VARIABLE_NAME, ParentDevicePath);\r | |
830 | TerminalRemoveConsoleDevVariable (EFI_CON_OUT_DEV_VARIABLE_NAME, ParentDevicePath);\r | |
831 | TerminalRemoveConsoleDevVariable (EFI_ERR_OUT_DEV_VARIABLE_NAME, ParentDevicePath);\r | |
95276127 | 832 | \r |
f7c11d9b RN |
833 | Status = gBS->CloseProtocol (\r |
834 | Controller,\r | |
835 | &gEfiSerialIoProtocolGuid,\r | |
836 | This->DriverBindingHandle,\r | |
837 | Controller\r | |
838 | );\r | |
839 | ASSERT_EFI_ERROR (Status);\r | |
95276127 | 840 | \r |
f7c11d9b RN |
841 | Status = gBS->CloseProtocol (\r |
842 | Controller,\r | |
843 | &gEfiDevicePathProtocolGuid,\r | |
844 | This->DriverBindingHandle,\r | |
845 | Controller\r | |
846 | );\r | |
847 | ASSERT_EFI_ERROR (Status);\r | |
95276127 | 848 | return Status;\r |
849 | }\r | |
850 | \r | |
e49ef433 | 851 | /**\r |
ab76200c | 852 | Stop this driver on Controller by closing Simple Text In, Simple Text\r |
8fd98315 | 853 | In Ex, Simple Text Out protocol, and removing parent device path from\r |
677fdb90 | 854 | Console Device Environment Variables.\r |
e49ef433 | 855 | \r |
8fd98315 | 856 | @param This Protocol instance pointer.\r |
ab76200c | 857 | @param Controller Handle of device to stop driver on\r |
8fd98315 | 858 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r |
859 | children is zero stop the entire bus driver.\r | |
860 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
e49ef433 | 861 | \r |
ab76200c | 862 | @retval EFI_SUCCESS This driver is removed Controller.\r |
8fd98315 | 863 | @retval other This driver could not be removed from this device.\r |
e49ef433 | 864 | \r |
865 | **/\r | |
95276127 | 866 | EFI_STATUS\r |
867 | EFIAPI\r | |
868 | TerminalDriverBindingStop (\r | |
869 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
870 | IN EFI_HANDLE Controller,\r | |
871 | IN UINTN NumberOfChildren,\r | |
872 | IN EFI_HANDLE *ChildHandleBuffer\r | |
873 | )\r | |
95276127 | 874 | {\r |
875 | EFI_STATUS Status;\r | |
876 | UINTN Index;\r | |
877 | BOOLEAN AllChildrenStopped;\r | |
878 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOutput;\r | |
879 | TERMINAL_DEV *TerminalDevice;\r | |
880 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
881 | EFI_SERIAL_IO_PROTOCOL *SerialIo;\r | |
95276127 | 882 | \r |
883 | //\r | |
884 | // Complete all outstanding transactions to Controller.\r | |
885 | // Don't allow any new transaction to Controller to be started.\r | |
886 | //\r | |
887 | if (NumberOfChildren == 0) {\r | |
888 | //\r | |
889 | // Close the bus driver\r | |
890 | //\r | |
891 | Status = gBS->OpenProtocol (\r | |
892 | Controller,\r | |
f7c11d9b | 893 | &gEfiDevicePathProtocolGuid,\r |
95276127 | 894 | (VOID **) &ParentDevicePath,\r |
895 | This->DriverBindingHandle,\r | |
896 | Controller,\r | |
897 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
898 | );\r | |
f7c11d9b | 899 | ASSERT_EFI_ERROR (Status);\r |
95276127 | 900 | \r |
f7c11d9b RN |
901 | //\r |
902 | // Remove Parent Device Path from\r | |
903 | // the Console Device Environment Variables\r | |
904 | //\r | |
905 | TerminalRemoveConsoleDevVariable (EFI_CON_IN_DEV_VARIABLE_NAME, ParentDevicePath);\r | |
906 | TerminalRemoveConsoleDevVariable (EFI_CON_OUT_DEV_VARIABLE_NAME, ParentDevicePath);\r | |
907 | TerminalRemoveConsoleDevVariable (EFI_ERR_OUT_DEV_VARIABLE_NAME, ParentDevicePath);\r | |
95276127 | 908 | \r |
909 | gBS->CloseProtocol (\r | |
910 | Controller,\r | |
911 | &gEfiSerialIoProtocolGuid,\r | |
912 | This->DriverBindingHandle,\r | |
913 | Controller\r | |
914 | );\r | |
915 | \r | |
916 | gBS->CloseProtocol (\r | |
917 | Controller,\r | |
918 | &gEfiDevicePathProtocolGuid,\r | |
919 | This->DriverBindingHandle,\r | |
920 | Controller\r | |
921 | );\r | |
922 | \r | |
923 | return EFI_SUCCESS;\r | |
924 | }\r | |
925 | \r | |
926 | AllChildrenStopped = TRUE;\r | |
927 | \r | |
928 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
929 | \r | |
930 | Status = gBS->OpenProtocol (\r | |
931 | ChildHandleBuffer[Index],\r | |
932 | &gEfiSimpleTextOutProtocolGuid,\r | |
933 | (VOID **) &SimpleTextOutput,\r | |
934 | This->DriverBindingHandle,\r | |
935 | ChildHandleBuffer[Index],\r | |
936 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
937 | );\r | |
938 | if (!EFI_ERROR (Status)) {\r | |
939 | \r | |
940 | TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (SimpleTextOutput);\r | |
941 | \r | |
942 | gBS->CloseProtocol (\r | |
943 | Controller,\r | |
944 | &gEfiSerialIoProtocolGuid,\r | |
945 | This->DriverBindingHandle,\r | |
946 | ChildHandleBuffer[Index]\r | |
947 | );\r | |
948 | \r | |
949 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
950 | ChildHandleBuffer[Index],\r | |
951 | &gEfiSimpleTextInProtocolGuid,\r | |
952 | &TerminalDevice->SimpleInput,\r | |
66aa04e4 | 953 | &gEfiSimpleTextInputExProtocolGuid,\r |
954 | &TerminalDevice->SimpleInputEx,\r | |
95276127 | 955 | &gEfiSimpleTextOutProtocolGuid,\r |
956 | &TerminalDevice->SimpleTextOutput,\r | |
957 | &gEfiDevicePathProtocolGuid,\r | |
958 | TerminalDevice->DevicePath,\r | |
959 | NULL\r | |
960 | );\r | |
961 | if (EFI_ERROR (Status)) {\r | |
962 | gBS->OpenProtocol (\r | |
963 | Controller,\r | |
964 | &gEfiSerialIoProtocolGuid,\r | |
965 | (VOID **) &SerialIo,\r | |
966 | This->DriverBindingHandle,\r | |
967 | ChildHandleBuffer[Index],\r | |
968 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
969 | );\r | |
970 | } else {\r | |
971 | \r | |
0d8b3f81 | 972 | FreeUnicodeStringTable (TerminalDevice->ControllerNameTable);\r |
b7cf1c07 | 973 | StopTerminalStateMachine (TerminalDevice);\r |
95276127 | 974 | gBS->CloseEvent (TerminalDevice->SimpleInput.WaitForKey);\r |
66aa04e4 | 975 | gBS->CloseEvent (TerminalDevice->SimpleInputEx.WaitForKeyEx);\r |
47b612db | 976 | gBS->CloseEvent (TerminalDevice->KeyNotifyProcessEvent);\r |
66aa04e4 | 977 | TerminalFreeNotifyList (&TerminalDevice->NotifyList);\r |
95276127 | 978 | FreePool (TerminalDevice->DevicePath);\r |
0d8b3f81 | 979 | FreePool (TerminalDevice->TerminalConsoleModeData);\r |
95276127 | 980 | FreePool (TerminalDevice);\r |
981 | }\r | |
982 | }\r | |
983 | \r | |
984 | if (EFI_ERROR (Status)) {\r | |
985 | AllChildrenStopped = FALSE;\r | |
986 | }\r | |
987 | }\r | |
988 | \r | |
989 | if (!AllChildrenStopped) {\r | |
990 | return EFI_DEVICE_ERROR;\r | |
991 | }\r | |
992 | \r | |
993 | return EFI_SUCCESS;\r | |
994 | }\r | |
995 | \r | |
8fd98315 | 996 | /**\r |
997 | Update terminal device path in Console Device Environment Variables.\r | |
998 | \r | |
999 | @param VariableName The Console Device Environment Variable.\r | |
11baadb6 | 1000 | @param ParentDevicePath The terminal device path to be updated.\r |
8fd98315 | 1001 | \r |
8fd98315 | 1002 | **/\r |
95276127 | 1003 | VOID\r |
1004 | TerminalUpdateConsoleDevVariable (\r | |
1005 | IN CHAR16 *VariableName,\r | |
1006 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath\r | |
1007 | )\r | |
1008 | {\r | |
1009 | EFI_STATUS Status;\r | |
5070befc | 1010 | UINTN NameSize;\r |
95276127 | 1011 | UINTN VariableSize;\r |
8ce87fff | 1012 | TERMINAL_TYPE TerminalType;\r |
95276127 | 1013 | EFI_DEVICE_PATH_PROTOCOL *Variable;\r |
1014 | EFI_DEVICE_PATH_PROTOCOL *NewVariable;\r | |
1015 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r | |
5070befc | 1016 | EDKII_SET_VARIABLE_STATUS *SetVariableStatus;\r |
95276127 | 1017 | \r |
95276127 | 1018 | //\r |
1019 | // Get global variable and its size according to the name given.\r | |
1020 | //\r | |
f01b91ae | 1021 | GetEfiGlobalVariable2 (VariableName, (VOID**)&Variable, NULL);\r |
e3dcffcc | 1022 | if (Variable == NULL) {\r |
1023 | return;\r | |
1024 | }\r | |
1025 | \r | |
95276127 | 1026 | //\r |
1027 | // Append terminal device path onto the variable.\r | |
1028 | //\r | |
f9163275 | 1029 | for (TerminalType = 0; TerminalType < ARRAY_SIZE (mTerminalType); TerminalType++) {\r |
95276127 | 1030 | SetTerminalDevicePath (TerminalType, ParentDevicePath, &TempDevicePath);\r |
1031 | NewVariable = AppendDevicePathInstance (Variable, TempDevicePath);\r | |
4b0786b4 | 1032 | ASSERT (NewVariable != NULL);\r |
95276127 | 1033 | if (Variable != NULL) {\r |
1034 | FreePool (Variable);\r | |
1035 | }\r | |
1036 | \r | |
1037 | if (TempDevicePath != NULL) {\r | |
1038 | FreePool (TempDevicePath);\r | |
1039 | }\r | |
1040 | \r | |
1041 | Variable = NewVariable;\r | |
1042 | }\r | |
1043 | \r | |
1044 | VariableSize = GetDevicePathSize (Variable);\r | |
1045 | \r | |
1046 | Status = gRT->SetVariable (\r | |
1047 | VariableName,\r | |
1048 | &gEfiGlobalVariableGuid,\r | |
1049 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
1050 | VariableSize,\r | |
1051 | Variable\r | |
1052 | );\r | |
5070befc RN |
1053 | \r |
1054 | if (EFI_ERROR (Status)) {\r | |
1055 | NameSize = StrSize (VariableName);\r | |
1056 | SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + VariableSize);\r | |
1057 | if (SetVariableStatus != NULL) {\r | |
1058 | CopyGuid (&SetVariableStatus->Guid, &gEfiGlobalVariableGuid);\r | |
1059 | SetVariableStatus->NameSize = NameSize;\r | |
1060 | SetVariableStatus->DataSize = VariableSize;\r | |
1061 | SetVariableStatus->SetStatus = Status;\r | |
1062 | SetVariableStatus->Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;\r | |
1063 | CopyMem (SetVariableStatus + 1, VariableName, NameSize);\r | |
1064 | CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Variable, VariableSize);\r | |
1065 | \r | |
1066 | REPORT_STATUS_CODE_EX (\r | |
1067 | EFI_ERROR_CODE,\r | |
1068 | PcdGet32 (PcdErrorCodeSetVariable),\r | |
1069 | 0,\r | |
1070 | NULL,\r | |
1071 | &gEdkiiStatusCodeDataTypeVariableGuid,\r | |
1072 | SetVariableStatus,\r | |
1073 | sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + VariableSize\r | |
1074 | );\r | |
1075 | \r | |
1076 | FreePool (SetVariableStatus);\r | |
1077 | }\r | |
1078 | }\r | |
1079 | \r | |
95276127 | 1080 | FreePool (Variable);\r |
1081 | \r | |
1082 | return ;\r | |
1083 | }\r | |
1084 | \r | |
e49ef433 | 1085 | \r |
1086 | /**\r | |
8fd98315 | 1087 | Remove terminal device path from Console Device Environment Variables.\r |
e49ef433 | 1088 | \r |
8fd98315 | 1089 | @param VariableName Console Device Environment Variables.\r |
11baadb6 | 1090 | @param ParentDevicePath The terminal device path to be updated.\r |
e49ef433 | 1091 | \r |
e49ef433 | 1092 | **/\r |
95276127 | 1093 | VOID\r |
1094 | TerminalRemoveConsoleDevVariable (\r | |
1095 | IN CHAR16 *VariableName,\r | |
1096 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath\r | |
1097 | )\r | |
95276127 | 1098 | {\r |
1099 | EFI_STATUS Status;\r | |
1100 | BOOLEAN FoundOne;\r | |
1101 | BOOLEAN Match;\r | |
1102 | UINTN VariableSize;\r | |
1103 | UINTN InstanceSize;\r | |
8ce87fff | 1104 | TERMINAL_TYPE TerminalType;\r |
95276127 | 1105 | EFI_DEVICE_PATH_PROTOCOL *Instance;\r |
1106 | EFI_DEVICE_PATH_PROTOCOL *Variable;\r | |
1107 | EFI_DEVICE_PATH_PROTOCOL *OriginalVariable;\r | |
1108 | EFI_DEVICE_PATH_PROTOCOL *NewVariable;\r | |
1109 | EFI_DEVICE_PATH_PROTOCOL *SavedNewVariable;\r | |
1110 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r | |
1111 | \r | |
95276127 | 1112 | Instance = NULL;\r |
1113 | \r | |
1114 | //\r | |
1115 | // Get global variable and its size according to the name given.\r | |
1116 | //\r | |
f01b91ae | 1117 | GetEfiGlobalVariable2 (VariableName, (VOID**)&Variable, NULL);\r |
95276127 | 1118 | if (Variable == NULL) {\r |
1119 | return ;\r | |
1120 | }\r | |
1121 | \r | |
1122 | FoundOne = FALSE;\r | |
1123 | OriginalVariable = Variable;\r | |
1124 | NewVariable = NULL;\r | |
1125 | \r | |
1126 | //\r | |
1127 | // Get first device path instance from Variable\r | |
1128 | //\r | |
1129 | Instance = GetNextDevicePathInstance (&Variable, &InstanceSize);\r | |
1130 | if (Instance == NULL) {\r | |
1131 | FreePool (OriginalVariable);\r | |
1132 | return ;\r | |
1133 | }\r | |
1134 | //\r | |
1135 | // Loop through all the device path instances of Variable\r | |
1136 | //\r | |
1137 | do {\r | |
1138 | //\r | |
1139 | // Loop through all the terminal types that this driver supports\r | |
1140 | //\r | |
1141 | Match = FALSE;\r | |
f9163275 | 1142 | for (TerminalType = 0; TerminalType < ARRAY_SIZE (mTerminalType); TerminalType++) {\r |
95276127 | 1143 | \r |
1144 | SetTerminalDevicePath (TerminalType, ParentDevicePath, &TempDevicePath);\r | |
1145 | \r | |
1146 | //\r | |
11baadb6 | 1147 | // Compare the generated device path to the current device path instance\r |
95276127 | 1148 | //\r |
1149 | if (TempDevicePath != NULL) {\r | |
1150 | if (CompareMem (Instance, TempDevicePath, InstanceSize) == 0) {\r | |
1151 | Match = TRUE;\r | |
1152 | FoundOne = TRUE;\r | |
1153 | }\r | |
1154 | \r | |
1155 | FreePool (TempDevicePath);\r | |
1156 | }\r | |
1157 | }\r | |
1158 | //\r | |
1159 | // If a match was not found, then keep the current device path instance\r | |
1160 | //\r | |
1161 | if (!Match) {\r | |
1162 | SavedNewVariable = NewVariable;\r | |
1163 | NewVariable = AppendDevicePathInstance (NewVariable, Instance);\r | |
1164 | if (SavedNewVariable != NULL) {\r | |
1165 | FreePool (SavedNewVariable);\r | |
1166 | }\r | |
1167 | }\r | |
1168 | //\r | |
1169 | // Get next device path instance from Variable\r | |
1170 | //\r | |
1171 | FreePool (Instance);\r | |
1172 | Instance = GetNextDevicePathInstance (&Variable, &InstanceSize);\r | |
1173 | } while (Instance != NULL);\r | |
1174 | \r | |
1175 | FreePool (OriginalVariable);\r | |
1176 | \r | |
1177 | if (FoundOne) {\r | |
1178 | VariableSize = GetDevicePathSize (NewVariable);\r | |
1179 | \r | |
1180 | Status = gRT->SetVariable (\r | |
1181 | VariableName,\r | |
1182 | &gEfiGlobalVariableGuid,\r | |
1183 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
1184 | VariableSize,\r | |
1185 | NewVariable\r | |
1186 | );\r | |
5070befc RN |
1187 | //\r |
1188 | // Shrinking variable with existing variable driver implementation shouldn't fail.\r | |
1189 | //\r | |
1190 | ASSERT_EFI_ERROR (Status);\r | |
95276127 | 1191 | }\r |
1192 | \r | |
1193 | if (NewVariable != NULL) {\r | |
1194 | FreePool (NewVariable);\r | |
1195 | }\r | |
1196 | \r | |
1197 | return ;\r | |
1198 | }\r | |
1199 | \r | |
8fd98315 | 1200 | /**\r |
11baadb6 | 1201 | Build terminal device path according to terminal type.\r |
8fd98315 | 1202 | \r |
1203 | @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.\r | |
11baadb6 | 1204 | @param ParentDevicePath Parent device path.\r |
8fd98315 | 1205 | @param TerminalDevicePath Returned terminal device path, if building successfully.\r |
1206 | \r | |
1207 | @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.\r | |
1208 | @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.\r | |
1209 | @retval EFI_SUCCESS Build terminal device path successfully.\r | |
1210 | \r | |
1211 | **/\r | |
95276127 | 1212 | EFI_STATUS\r |
1213 | SetTerminalDevicePath (\r | |
8ce87fff | 1214 | IN TERMINAL_TYPE TerminalType,\r |
95276127 | 1215 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r |
1216 | OUT EFI_DEVICE_PATH_PROTOCOL **TerminalDevicePath\r | |
1217 | )\r | |
1218 | {\r | |
1219 | VENDOR_DEVICE_PATH Node;\r | |
1220 | \r | |
802c39b0 | 1221 | ASSERT (TerminalType < ARRAY_SIZE (mTerminalType));\r |
95276127 | 1222 | Node.Header.Type = MESSAGING_DEVICE_PATH;\r |
1223 | Node.Header.SubType = MSG_VENDOR_DP;\r | |
178b6b5d | 1224 | SetDevicePathNodeLength (&Node.Header, sizeof (VENDOR_DEVICE_PATH));\r |
802c39b0 | 1225 | CopyGuid (&Node.Guid, mTerminalType[TerminalType]);\r |
ab76200c | 1226 | \r |
95276127 | 1227 | //\r |
ab76200c | 1228 | // Append the terminal node onto parent device path\r |
95276127 | 1229 | // to generate a complete terminal device path.\r |
1230 | //\r | |
1231 | *TerminalDevicePath = AppendDevicePathNode (\r | |
1232 | ParentDevicePath,\r | |
1233 | (EFI_DEVICE_PATH_PROTOCOL *) &Node\r | |
1234 | );\r | |
1235 | if (*TerminalDevicePath == NULL) {\r | |
1236 | return EFI_OUT_OF_RESOURCES;\r | |
1237 | }\r | |
1238 | \r | |
1239 | return EFI_SUCCESS;\r | |
1240 | }\r | |
1241 | \r | |
97a079ed A |
1242 | /**\r |
1243 | The user Entry Point for module Terminal. The user code starts with this function.\r | |
1244 | \r | |
ab76200c | 1245 | @param ImageHandle The firmware allocated handle for the EFI image.\r |
1246 | @param SystemTable A pointer to the EFI System Table.\r | |
fb0b259e | 1247 | \r |
97a079ed A |
1248 | @retval EFI_SUCCESS The entry point is executed successfully.\r |
1249 | @retval other Some error occurs when executing this entry point.\r | |
1250 | \r | |
1251 | **/\r | |
1252 | EFI_STATUS\r | |
1253 | EFIAPI\r | |
1254 | InitializeTerminal(\r | |
1255 | IN EFI_HANDLE ImageHandle,\r | |
1256 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1257 | )\r | |
1258 | {\r | |
1259 | EFI_STATUS Status;\r | |
1260 | \r | |
1261 | //\r | |
1262 | // Install driver model protocol(s).\r | |
1263 | //\r | |
5bca971e | 1264 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
97a079ed A |
1265 | ImageHandle,\r |
1266 | SystemTable,\r | |
1267 | &gTerminalDriverBinding,\r | |
1268 | ImageHandle,\r | |
1269 | &gTerminalComponentName,\r | |
5bca971e | 1270 | &gTerminalComponentName2\r |
97a079ed A |
1271 | );\r |
1272 | ASSERT_EFI_ERROR (Status);\r | |
1273 | \r | |
97a079ed A |
1274 | return Status;\r |
1275 | }\r | |
f1aec6cc | 1276 | \r |
1277 | /**\r | |
1278 | Check if the device supports hot-plug through its device path.\r | |
1279 | \r | |
1280 | This function could be updated to check more types of Hot Plug devices.\r | |
1281 | Currently, it checks USB and PCCard device.\r | |
1282 | \r | |
1283 | @param DevicePath Pointer to device's device path.\r | |
1284 | \r | |
1285 | @retval TRUE The devcie is a hot-plug device\r | |
1286 | @retval FALSE The devcie is not a hot-plug device.\r | |
1287 | \r | |
1288 | **/\r | |
1289 | BOOLEAN\r | |
1290 | IsHotPlugDevice (\r | |
1291 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
1292 | )\r | |
1293 | {\r | |
1294 | EFI_DEVICE_PATH_PROTOCOL *CheckDevicePath;\r | |
1295 | \r | |
1296 | CheckDevicePath = DevicePath;\r | |
1297 | while (!IsDevicePathEnd (CheckDevicePath)) {\r | |
1298 | //\r | |
1299 | // Check device whether is hot plug device or not throught Device Path\r | |
e3dcffcc | 1300 | //\r |
f1aec6cc | 1301 | if ((DevicePathType (CheckDevicePath) == MESSAGING_DEVICE_PATH) &&\r |
1302 | (DevicePathSubType (CheckDevicePath) == MSG_USB_DP ||\r | |
1303 | DevicePathSubType (CheckDevicePath) == MSG_USB_CLASS_DP ||\r | |
1304 | DevicePathSubType (CheckDevicePath) == MSG_USB_WWID_DP)) {\r | |
1305 | //\r | |
1306 | // If Device is USB device\r | |
1307 | //\r | |
1308 | return TRUE;\r | |
1309 | }\r | |
1310 | if ((DevicePathType (CheckDevicePath) == HARDWARE_DEVICE_PATH) &&\r | |
1311 | (DevicePathSubType (CheckDevicePath) == HW_PCCARD_DP)) {\r | |
1312 | //\r | |
1313 | // If Device is PCCard\r | |
1314 | //\r | |
1315 | return TRUE;\r | |
1316 | }\r | |
e3dcffcc | 1317 | \r |
f1aec6cc | 1318 | CheckDevicePath = NextDevicePathNode (CheckDevicePath);\r |
1319 | }\r | |
1320 | \r | |
1321 | return FALSE;\r | |
1322 | }\r | |
1323 | \r |