X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FConsole%2FTerminalDxe%2FTerminal.c;h=b8dcf0c472bd2670d1f5d8a4e51618833418558d;hp=7732db8b38627a8ad00b34db775ac8e917ae8f51;hb=b7cf1c07479bbe5a3d5fd3c944b2ab76f740c072;hpb=e5eed7d3641d71d7ea539e5379ea9c6a5cd97004 diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c index 7732db8b38..b8dcf0c472 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c @@ -2,7 +2,7 @@ Produces Simple Text Input Protocol, Simple Text Input Extended Protocol and Simple Text Output Protocol upon Serial IO Protocol. -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -29,14 +29,23 @@ EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding = { }; -EFI_GUID *gTerminalType[] = { +EFI_GUID *mTerminalType[] = { &gEfiPcAnsiGuid, &gEfiVT100Guid, &gEfiVT100PlusGuid, - &gEfiVTUTF8Guid + &gEfiVTUTF8Guid, + &gEfiTtyTermGuid }; +CHAR16 *mSerialConsoleNames[] = { + L"PC-ANSI Serial Console", + L"VT-100 Serial Console", + L"VT-100+ Serial Console", + L"VT-UTF8 Serial Console", + L"Tty Terminal Serial Console" +}; + TERMINAL_DEV mTerminalDevTemplate = { TERMINAL_DEV_SIGNATURE, NULL, @@ -68,16 +77,25 @@ TERMINAL_DEV mTerminalDevTemplate = { 0, // CursorRow TRUE // CursorVisible }, + NULL, // TerminalConsoleModeData 0, // SerialInTimeOut NULL, // RawFifo NULL, // UnicodeFiFo NULL, // EfiKeyFiFo + NULL, // EfiKeyFiFoForNotify NULL, // ControllerNameTable + NULL, // TimerEvent NULL, // TwoSecondTimeOut INPUT_STATE_DEFAULT, RESET_STATE_DEFAULT, + { + 0, + 0, + 0 + }, + 0, FALSE, { // SimpleTextInputEx TerminalConInResetEx, @@ -90,9 +108,41 @@ TERMINAL_DEV mTerminalDevTemplate = { { // NotifyList NULL, NULL, - } + }, + NULL // KeyNotifyProcessEvent +}; + +TERMINAL_CONSOLE_MODE_DATA mTerminalConsoleModeData[] = { + {80, 25}, + {80, 50}, + {100, 31}, + // + // New modes can be added here. + // }; +/** + Convert the GUID representation of terminal type to enum type. + + @param Guid The GUID representation of terminal type. + + @return The terminal type in enum type. +**/ +TERMINAL_TYPE +TerminalTypeFromGuid ( + IN EFI_GUID *Guid +) +{ + TERMINAL_TYPE Type; + + for (Type = 0; Type < ARRAY_SIZE (mTerminalType); Type++) { + if (CompareGuid (Guid, mTerminalType[Type])) { + break; + } + } + return Type; +} + /** Test to see if this driver supports Controller. @@ -143,13 +193,9 @@ TerminalDriverBindingSupported ( } // - // only supports PC ANSI, VT100, VT100+ and VT-UTF8 terminal types + // only supports PC ANSI, VT100, VT100+, VT-UTF8, and TtyTerm terminal types // - if (!CompareGuid (&Node->Guid, &gEfiPcAnsiGuid) && - !CompareGuid (&Node->Guid, &gEfiVT100Guid) && - !CompareGuid (&Node->Guid, &gEfiVT100PlusGuid) && - !CompareGuid (&Node->Guid, &gEfiVTUTF8Guid)) { - + if (TerminalTypeFromGuid (&Node->Guid) == ARRAY_SIZE (mTerminalType)) { return EFI_UNSUPPORTED; } } @@ -236,35 +282,38 @@ BuildTerminalDevpath ( ) { EFI_DEVICE_PATH_PROTOCOL *TerminalDevicePath; - UINT8 TerminalType; + TERMINAL_TYPE TerminalType; VENDOR_DEVICE_PATH *Node; EFI_STATUS Status; TerminalDevicePath = NULL; - TerminalType = PCANSITYPE; // // Use the RemainingDevicePath to determine the terminal type // Node = (VENDOR_DEVICE_PATH *) RemainingDevicePath; if (Node == NULL) { - TerminalType = PCANSITYPE; + TerminalType = PcdGet8 (PcdDefaultTerminalType); } else if (CompareGuid (&Node->Guid, &gEfiPcAnsiGuid)) { - TerminalType = PCANSITYPE; + TerminalType = TerminalTypePcAnsi; } else if (CompareGuid (&Node->Guid, &gEfiVT100Guid)) { - TerminalType = VT100TYPE; + TerminalType = TerminalTypeVt100; } else if (CompareGuid (&Node->Guid, &gEfiVT100PlusGuid)) { - TerminalType = VT100PLUSTYPE; + TerminalType = TerminalTypeVt100Plus; } else if (CompareGuid (&Node->Guid, &gEfiVTUTF8Guid)) { - TerminalType = VTUTF8TYPE; + TerminalType = TerminalTypeVtUtf8; + + } else if (CompareGuid (&Node->Guid, &gEfiTtyTermGuid)) { + + TerminalType = TerminalTypeTtyTerm; } else { return NULL; @@ -349,7 +398,7 @@ IsTerminalInConsoleVariable ( // // Get global variable and its size according to the name given. // - Variable = GetEfiGlobalVariable (VariableName); + GetEfiGlobalVariable2 (VariableName, (VOID**)&Variable, NULL); if (Variable == NULL) { return FALSE; } @@ -397,6 +446,148 @@ TerminalFreeNotifyList ( return EFI_SUCCESS; } +/** + Initialize all the text modes which the terminal console supports. + + It returns information for available text modes that the terminal can support. + + @param[out] TextModeCount The total number of text modes that terminal console supports. + + @return The buffer to the text modes column and row information. + Caller is responsible to free it when it's non-NULL. + +**/ +TERMINAL_CONSOLE_MODE_DATA * +InitializeTerminalConsoleTextMode ( + OUT INT32 *TextModeCount +) +{ + TERMINAL_CONSOLE_MODE_DATA *TextModeData; + + ASSERT (TextModeCount != NULL); + + // + // Here we make sure that the final mode exposed does not include the duplicated modes, + // and does not include the invalid modes which exceed the max column and row. + // Reserve 2 modes for 80x25, 80x50 of terminal console. + // + TextModeData = AllocateCopyPool (sizeof (mTerminalConsoleModeData), mTerminalConsoleModeData); + if (TextModeData == NULL) { + return NULL; + } + *TextModeCount = ARRAY_SIZE (mTerminalConsoleModeData); + + DEBUG_CODE ( + INT32 Index; + for (Index = 0; Index < *TextModeCount; Index++) { + DEBUG ((DEBUG_INFO, "Terminal - Mode %d, Column = %d, Row = %d\n", + Index, TextModeData[Index].Columns, TextModeData[Index].Rows)); + } + ); + return TextModeData; +} + +/** + Stop the terminal state machine. + + @param TerminalDevice The terminal device. +**/ +VOID +StopTerminalStateMachine ( + TERMINAL_DEV *TerminalDevice + ) +{ + EFI_TPL OriginalTpl; + + OriginalTpl = gBS->RaiseTPL (TPL_NOTIFY); + + gBS->CloseEvent (TerminalDevice->TimerEvent); + gBS->CloseEvent (TerminalDevice->TwoSecondTimeOut); + + gBS->RestoreTPL (OriginalTpl); +} + +/** + Start the terminal state machine. + + @param TerminalDevice The terminal device. +**/ +VOID +StartTerminalStateMachine ( + TERMINAL_DEV *TerminalDevice + ) +{ + EFI_STATUS Status; + Status = gBS->CreateEvent ( + EVT_TIMER | EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + TerminalConInTimerHandler, + TerminalDevice, + &TerminalDevice->TimerEvent + ); + ASSERT_EFI_ERROR (Status); + + Status = gBS->SetTimer ( + TerminalDevice->TimerEvent, + TimerPeriodic, + KEYBOARD_TIMER_INTERVAL + ); + ASSERT_EFI_ERROR (Status); + + Status = gBS->CreateEvent ( + EVT_TIMER, + TPL_CALLBACK, + NULL, + NULL, + &TerminalDevice->TwoSecondTimeOut + ); + ASSERT_EFI_ERROR (Status); +} + +/** + Initialize the controller name table. + + @param TerminalType The terminal type. + @param ControllerNameTable The controller name table. + + @retval EFI_SUCCESS The controller name table is initialized successfully. + @retval others Return status of AddUnicodeString2 (). +**/ +EFI_STATUS +InitializeControllerNameTable ( + TERMINAL_TYPE TerminalType, + EFI_UNICODE_STRING_TABLE **ControllerNameTable +) +{ + EFI_STATUS Status; + EFI_UNICODE_STRING_TABLE *Table; + + ASSERT (TerminalType < ARRAY_SIZE (mTerminalType)); + Table = NULL; + Status = AddUnicodeString2 ( + "eng", + gTerminalComponentName.SupportedLanguages, + &Table, + mSerialConsoleNames[TerminalType], + TRUE + ); + if (!EFI_ERROR (Status)) { + Status = AddUnicodeString2 ( + "en", + gTerminalComponentName2.SupportedLanguages, + &Table, + mSerialConsoleNames[TerminalType], + FALSE + ); + if (EFI_ERROR (Status)) { + FreeUnicodeStringTable (Table); + } + } + if (!EFI_ERROR (Status)) { + *ControllerNameTable = Table; + } + return Status; +} /** Start this driver on Controller by opening a Serial IO protocol, @@ -426,11 +617,10 @@ TerminalDriverBindingStart ( EFI_SERIAL_IO_PROTOCOL *SerialIo; EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; VENDOR_DEVICE_PATH *Node; - VENDOR_DEVICE_PATH *DefaultNode; EFI_SERIAL_IO_MODE *Mode; UINTN SerialInTimeOut; TERMINAL_DEV *TerminalDevice; - UINT8 TerminalType; + TERMINAL_TYPE TerminalType; EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer; UINTN EntryCount; UINTN Index; @@ -445,10 +635,9 @@ TerminalDriverBindingStart ( BOOLEAN FirstEnter; TerminalDevice = NULL; - DefaultNode = NULL; - ConInSelected = FALSE; - ConOutSelected = FALSE; - NullRemaining = TRUE; + ConInSelected = FALSE; + ConOutSelected = FALSE; + NullRemaining = FALSE; SimTxtInInstalled = FALSE; SimTxtOutInstalled = FALSE; FirstEnter = FALSE; @@ -561,7 +750,7 @@ TerminalDriverBindingStart ( // if (FirstEnter) { // - // First enther the start funciton + // First enther the start function // FirstEnter = FALSE; // @@ -589,40 +778,17 @@ TerminalDriverBindingStart ( } // - // If RemainingDevicePath is NULL, then create default device path node + // If RemainingDevicePath is NULL, use default terminal type // if (RemainingDevicePath == NULL) { - DefaultNode = AllocateZeroPool (sizeof (VENDOR_DEVICE_PATH)); - if (DefaultNode == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Error; - } - TerminalType = PcdGet8 (PcdDefaultTerminalType); - // - // Must be between PCANSITYPE (0) and VTUTF8TYPE (3) - // - ASSERT (TerminalType <= VTUTF8TYPE); - - CopyMem (&DefaultNode->Guid, gTerminalType[TerminalType], sizeof (EFI_GUID)); - RemainingDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) DefaultNode; } else if (!IsDevicePathEnd (RemainingDevicePath)) { // // If RemainingDevicePath isn't the End of Device Path Node, // Use the RemainingDevicePath to determine the terminal type // Node = (VENDOR_DEVICE_PATH *)RemainingDevicePath; - if (CompareGuid (&Node->Guid, &gEfiPcAnsiGuid)) { - TerminalType = PCANSITYPE; - } else if (CompareGuid (&Node->Guid, &gEfiVT100Guid)) { - TerminalType = VT100TYPE; - } else if (CompareGuid (&Node->Guid, &gEfiVT100PlusGuid)) { - TerminalType = VT100PLUSTYPE; - } else if (CompareGuid (&Node->Guid, &gEfiVTUTF8Guid)) { - TerminalType = VTUTF8TYPE; - } else { - goto Error; - } + TerminalType = TerminalTypeFromGuid (&Node->Guid); } else { // // If RemainingDevicePath is the End of Device Path Node, @@ -631,6 +797,8 @@ TerminalDriverBindingStart ( return EFI_SUCCESS; } + ASSERT (TerminalType < ARRAY_SIZE (mTerminalType)); + // // Initialize the Terminal Dev // @@ -648,7 +816,7 @@ TerminalDriverBindingStart ( EVT_NOTIFY_WAIT, TPL_NOTIFY, TerminalConInWaitForKeyEx, - &TerminalDevice->SimpleInputEx, + TerminalDevice, &TerminalDevice->SimpleInputEx.WaitForKeyEx ); if (EFI_ERROR (Status)) { @@ -659,7 +827,7 @@ TerminalDriverBindingStart ( EVT_NOTIFY_WAIT, TPL_NOTIFY, TerminalConInWaitForKey, - &TerminalDevice->SimpleInput, + TerminalDevice, &TerminalDevice->SimpleInput.WaitForKey ); if (EFI_ERROR (Status)) { @@ -681,6 +849,10 @@ TerminalDriverBindingStart ( if (TerminalDevice->EfiKeyFiFo == NULL) { goto Error; } + TerminalDevice->EfiKeyFiFoForNotify = AllocateZeroPool (sizeof (EFI_KEY_FIFO)); + if (TerminalDevice->EfiKeyFiFoForNotify == NULL) { + goto Error; + } // // Set the timeout value of serial buffer for @@ -723,8 +895,14 @@ TerminalDriverBindingStart ( sizeof (mTerminalDevTemplate.SimpleTextOutput) ); SimpleTextOutput->Mode = &TerminalDevice->SimpleTextOutputMode; + + TerminalDevice->TerminalConsoleModeData = InitializeTerminalConsoleTextMode ( + &SimpleTextOutput->Mode->MaxMode + ); + if (TerminalDevice->TerminalConsoleModeData == NULL) { + goto ReportError; + } - TerminalDevice->SimpleTextOutputMode.MaxMode = 3; // // For terminal devices, cursor is always visible // @@ -737,6 +915,26 @@ TerminalDriverBindingStart ( goto ReportError; } + // + // Build the component name for the child device + // + Status = InitializeControllerNameTable (TerminalDevice->TerminalType, &TerminalDevice->ControllerNameTable); + if (EFI_ERROR (Status)) { + goto Error; + } + + // + // Build the device path for the child device + // + Status = SetTerminalDevicePath ( + TerminalDevice->TerminalType, + ParentDevicePath, + &TerminalDevice->DevicePath + ); + if (EFI_ERROR (Status)) { + goto Error; + } + Status = TerminalConOutReset (SimpleTextOutput, FALSE); if (EFI_ERROR (Status)) { goto ReportError; @@ -752,103 +950,16 @@ TerminalDriverBindingStart ( goto ReportError; } + StartTerminalStateMachine (TerminalDevice); + Status = gBS->CreateEvent ( - EVT_TIMER, + EVT_NOTIFY_SIGNAL, TPL_CALLBACK, - NULL, - NULL, - &TerminalDevice->TwoSecondTimeOut + KeyNotifyProcessHandler, + TerminalDevice, + &TerminalDevice->KeyNotifyProcessEvent ); - - // - // Build the component name for the child device - // - TerminalDevice->ControllerNameTable = NULL; - switch (TerminalDevice->TerminalType) { - case PCANSITYPE: - AddUnicodeString2 ( - "eng", - gTerminalComponentName.SupportedLanguages, - &TerminalDevice->ControllerNameTable, - (CHAR16 *)L"PC-ANSI Serial Console", - TRUE - ); - AddUnicodeString2 ( - "en", - gTerminalComponentName2.SupportedLanguages, - &TerminalDevice->ControllerNameTable, - (CHAR16 *)L"PC-ANSI Serial Console", - FALSE - ); - - break; - - case VT100TYPE: - AddUnicodeString2 ( - "eng", - gTerminalComponentName.SupportedLanguages, - &TerminalDevice->ControllerNameTable, - (CHAR16 *)L"VT-100 Serial Console", - TRUE - ); - AddUnicodeString2 ( - "en", - gTerminalComponentName2.SupportedLanguages, - &TerminalDevice->ControllerNameTable, - (CHAR16 *)L"VT-100 Serial Console", - FALSE - ); - - break; - - case VT100PLUSTYPE: - AddUnicodeString2 ( - "eng", - gTerminalComponentName.SupportedLanguages, - &TerminalDevice->ControllerNameTable, - (CHAR16 *)L"VT-100+ Serial Console", - TRUE - ); - AddUnicodeString2 ( - "en", - gTerminalComponentName2.SupportedLanguages, - &TerminalDevice->ControllerNameTable, - (CHAR16 *)L"VT-100+ Serial Console", - FALSE - ); - - break; - - case VTUTF8TYPE: - AddUnicodeString2 ( - "eng", - gTerminalComponentName.SupportedLanguages, - &TerminalDevice->ControllerNameTable, - (CHAR16 *)L"VT-UTF8 Serial Console", - TRUE - ); - AddUnicodeString2 ( - "en", - gTerminalComponentName2.SupportedLanguages, - &TerminalDevice->ControllerNameTable, - (CHAR16 *)L"VT-UTF8 Serial Console", - FALSE - ); - - break; - } - - // - // Build the device path for the child device - // - Status = SetTerminalDevicePath ( - TerminalDevice->TerminalType, - ParentDevicePath, - &TerminalDevice->DevicePath - ); - if (EFI_ERROR (Status)) { - goto Error; - } + ASSERT_EFI_ERROR (Status); Status = gBS->InstallProtocolInterface ( &TerminalDevice->Handle, @@ -1021,9 +1132,6 @@ TerminalDriverBindingStart ( goto Error; } } - if (DefaultNode != NULL) { - FreePool (DefaultNode); - } return EFI_SUCCESS; @@ -1052,6 +1160,10 @@ Error: gBS->CloseEvent (TerminalDevice->TwoSecondTimeOut); } + if (TerminalDevice->TimerEvent != NULL) { + gBS->CloseEvent (TerminalDevice->TimerEvent); + } + if (TerminalDevice->SimpleInput.WaitForKey != NULL) { gBS->CloseEvent (TerminalDevice->SimpleInput.WaitForKey); } @@ -1071,7 +1183,10 @@ Error: if (TerminalDevice->EfiKeyFiFo != NULL) { FreePool (TerminalDevice->EfiKeyFiFo); } - + if (TerminalDevice->EfiKeyFiFoForNotify != NULL) { + FreePool (TerminalDevice->EfiKeyFiFoForNotify); + } + if (TerminalDevice->ControllerNameTable != NULL) { FreeUnicodeStringTable (TerminalDevice->ControllerNameTable); } @@ -1080,14 +1195,14 @@ Error: FreePool (TerminalDevice->DevicePath); } + if (TerminalDevice->TerminalConsoleModeData != NULL) { + FreePool (TerminalDevice->TerminalConsoleModeData); + } + FreePool (TerminalDevice); } } - if (DefaultNode != NULL) { - FreePool (DefaultNode); - } - This->Stop (This, Controller, 0, NULL); return Status; @@ -1245,11 +1360,15 @@ TerminalDriverBindingStop ( FreeUnicodeStringTable (TerminalDevice->ControllerNameTable); } - gBS->CloseEvent (TerminalDevice->TwoSecondTimeOut); + StopTerminalStateMachine (TerminalDevice); gBS->CloseEvent (TerminalDevice->SimpleInput.WaitForKey); gBS->CloseEvent (TerminalDevice->SimpleInputEx.WaitForKeyEx); + gBS->CloseEvent (TerminalDevice->KeyNotifyProcessEvent); TerminalFreeNotifyList (&TerminalDevice->NotifyList); FreePool (TerminalDevice->DevicePath); + if (TerminalDevice->TerminalConsoleModeData != NULL) { + FreePool (TerminalDevice->TerminalConsoleModeData); + } FreePool (TerminalDevice); } } @@ -1280,16 +1399,18 @@ TerminalUpdateConsoleDevVariable ( ) { EFI_STATUS Status; + UINTN NameSize; UINTN VariableSize; - UINT8 TerminalType; + TERMINAL_TYPE TerminalType; EFI_DEVICE_PATH_PROTOCOL *Variable; EFI_DEVICE_PATH_PROTOCOL *NewVariable; EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EDKII_SET_VARIABLE_STATUS *SetVariableStatus; // // Get global variable and its size according to the name given. // - Variable = GetEfiGlobalVariable (VariableName); + GetEfiGlobalVariable2 (VariableName, (VOID**)&Variable, NULL); if (Variable == NULL) { return; } @@ -1297,9 +1418,10 @@ TerminalUpdateConsoleDevVariable ( // // Append terminal device path onto the variable. // - for (TerminalType = PCANSITYPE; TerminalType <= VTUTF8TYPE; TerminalType++) { + for (TerminalType = 0; TerminalType < ARRAY_SIZE (mTerminalType); TerminalType++) { SetTerminalDevicePath (TerminalType, ParentDevicePath, &TempDevicePath); NewVariable = AppendDevicePathInstance (Variable, TempDevicePath); + ASSERT (NewVariable != NULL); if (Variable != NULL) { FreePool (Variable); } @@ -1320,7 +1442,33 @@ TerminalUpdateConsoleDevVariable ( VariableSize, Variable ); - ASSERT_EFI_ERROR (Status); + + if (EFI_ERROR (Status)) { + NameSize = StrSize (VariableName); + SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + VariableSize); + if (SetVariableStatus != NULL) { + CopyGuid (&SetVariableStatus->Guid, &gEfiGlobalVariableGuid); + SetVariableStatus->NameSize = NameSize; + SetVariableStatus->DataSize = VariableSize; + SetVariableStatus->SetStatus = Status; + SetVariableStatus->Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; + CopyMem (SetVariableStatus + 1, VariableName, NameSize); + CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Variable, VariableSize); + + REPORT_STATUS_CODE_EX ( + EFI_ERROR_CODE, + PcdGet32 (PcdErrorCodeSetVariable), + 0, + NULL, + &gEdkiiStatusCodeDataTypeVariableGuid, + SetVariableStatus, + sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + VariableSize + ); + + FreePool (SetVariableStatus); + } + } + FreePool (Variable); return ; @@ -1345,7 +1493,7 @@ TerminalRemoveConsoleDevVariable ( BOOLEAN Match; UINTN VariableSize; UINTN InstanceSize; - UINT8 TerminalType; + TERMINAL_TYPE TerminalType; EFI_DEVICE_PATH_PROTOCOL *Instance; EFI_DEVICE_PATH_PROTOCOL *Variable; EFI_DEVICE_PATH_PROTOCOL *OriginalVariable; @@ -1358,7 +1506,7 @@ TerminalRemoveConsoleDevVariable ( // // Get global variable and its size according to the name given. // - Variable = GetEfiGlobalVariable (VariableName); + GetEfiGlobalVariable2 (VariableName, (VOID**)&Variable, NULL); if (Variable == NULL) { return ; } @@ -1383,7 +1531,7 @@ TerminalRemoveConsoleDevVariable ( // Loop through all the terminal types that this driver supports // Match = FALSE; - for (TerminalType = PCANSITYPE; TerminalType <= VTUTF8TYPE; TerminalType++) { + for (TerminalType = 0; TerminalType < ARRAY_SIZE (mTerminalType); TerminalType++) { SetTerminalDevicePath (TerminalType, ParentDevicePath, &TempDevicePath); @@ -1428,6 +1576,9 @@ TerminalRemoveConsoleDevVariable ( VariableSize, NewVariable ); + // + // Shrinking variable with existing variable driver implementation shouldn't fail. + // ASSERT_EFI_ERROR (Status); } @@ -1452,49 +1603,18 @@ TerminalRemoveConsoleDevVariable ( **/ EFI_STATUS SetTerminalDevicePath ( - IN UINT8 TerminalType, + IN TERMINAL_TYPE TerminalType, IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath, OUT EFI_DEVICE_PATH_PROTOCOL **TerminalDevicePath ) { VENDOR_DEVICE_PATH Node; - *TerminalDevicePath = NULL; + ASSERT (TerminalType < ARRAY_SIZE (mTerminalType)); Node.Header.Type = MESSAGING_DEVICE_PATH; Node.Header.SubType = MSG_VENDOR_DP; - - // - // Generate terminal device path node according to terminal type. - // - switch (TerminalType) { - - case PCANSITYPE: - CopyGuid (&Node.Guid, &gEfiPcAnsiGuid); - break; - - case VT100TYPE: - CopyGuid (&Node.Guid, &gEfiVT100Guid); - break; - - case VT100PLUSTYPE: - CopyGuid (&Node.Guid, &gEfiVT100PlusGuid); - break; - - case VTUTF8TYPE: - CopyGuid (&Node.Guid, &gEfiVTUTF8Guid); - break; - - default: - return EFI_UNSUPPORTED; - } - - // - // Get VENDOR_DEVCIE_PATH size and put into Node.Header - // - SetDevicePathNodeLength ( - &Node.Header, - sizeof (VENDOR_DEVICE_PATH) - ); + SetDevicePathNodeLength (&Node, sizeof (VENDOR_DEVICE_PATH)); + CopyGuid (&Node.Guid, mTerminalType[TerminalType]); // // Append the terminal node onto parent device path