From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4CF7781B44 for ; Tue, 10 Jan 2017 00:39:09 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 10 Jan 2017 00:39:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,343,1477983600"; d="scan'208";a="211598994" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by fmsmga004.fm.intel.com with ESMTP; 10 Jan 2017 00:39:08 -0800 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Star Zeng , Feng Tian Date: Tue, 10 Jan 2017 16:38:58 +0800 Message-Id: <20170110083904.34104-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170110083904.34104-1-ruiyu.ni@intel.com> References: <20170110083904.34104-1-ruiyu.ni@intel.com> Subject: [PATCH 2/8] MdeModulePkg/TerminalDxe: Add TerminalTypeFromGuid internal function X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jan 2017 08:39:09 -0000 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Star Zeng Cc: Feng Tian --- .../Universal/Console/TerminalDxe/Terminal.c | 55 ++++++++++++---------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c index 1c1f5e1..992d58e 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c @@ -29,7 +29,7 @@ EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding = { }; -EFI_GUID *gTerminalType[] = { +EFI_GUID *mTerminalType[] = { &gEfiPcAnsiGuid, &gEfiVT100Guid, &gEfiVT100PlusGuid, @@ -112,6 +112,28 @@ TERMINAL_CONSOLE_MODE_DATA mTerminalConsoleModeData[] = { }; /** + 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. @param This Protocol instance pointer. @@ -163,12 +185,7 @@ TerminalDriverBindingSupported ( // // 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) && - !CompareGuid (&Node->Guid, &gEfiTtyTermGuid)) { - + if (TerminalTypeFromGuid (&Node->Guid) == ARRAY_SIZE (mTerminalType)) { return EFI_UNSUPPORTED; } } @@ -712,29 +729,13 @@ TerminalDriverBindingStart ( // if (RemainingDevicePath == NULL) { TerminalType = PcdGet8 (PcdDefaultTerminalType); - // - // Must be between TerminalTypePcAnsi (0) and TerminalTypeTtyTerm (4) - // - ASSERT (TerminalType <= TerminalTypeTtyTerm); } 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 = TerminalTypePcAnsi; - } else if (CompareGuid (&Node->Guid, &gEfiVT100Guid)) { - TerminalType = TerminalTypeVt100; - } else if (CompareGuid (&Node->Guid, &gEfiVT100PlusGuid)) { - TerminalType = TerminalTypeVt100Plus; - } else if (CompareGuid (&Node->Guid, &gEfiVTUTF8Guid)) { - TerminalType = TerminalTypeVtUtf8; - } else if (CompareGuid (&Node->Guid, &gEfiTtyTermGuid)) { - TerminalType = TerminalTypeTtyTerm; - } else { - goto Error; - } + TerminalType = TerminalTypeFromGuid (&Node->Guid); } else { // // If RemainingDevicePath is the End of Device Path Node, @@ -743,6 +744,8 @@ TerminalDriverBindingStart ( return EFI_SUCCESS; } + ASSERT (TerminalType < ARRAY_SIZE (mTerminalType)); + // // Initialize the Terminal Dev // @@ -1473,7 +1476,7 @@ TerminalUpdateConsoleDevVariable ( // // Append terminal device path onto the variable. // - for (TerminalType = TerminalTypePcAnsi; TerminalType <= TerminalTypeTtyTerm; TerminalType++) { + for (TerminalType = 0; TerminalType < ARRAY_SIZE (mTerminalType); TerminalType++) { SetTerminalDevicePath (TerminalType, ParentDevicePath, &TempDevicePath); NewVariable = AppendDevicePathInstance (Variable, TempDevicePath); ASSERT (NewVariable != NULL); @@ -1586,7 +1589,7 @@ TerminalRemoveConsoleDevVariable ( // Loop through all the terminal types that this driver supports // Match = FALSE; - for (TerminalType = TerminalTypePcAnsi; TerminalType <= TerminalTypeTtyTerm; TerminalType++) { + for (TerminalType = 0; TerminalType < ARRAY_SIZE (mTerminalType); TerminalType++) { SetTerminalDevicePath (TerminalType, ParentDevicePath, &TempDevicePath); -- 2.9.0.windows.1