public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>, Feng Tian <feng.tian@intel.com>
Subject: [PATCH 2/8] MdeModulePkg/TerminalDxe: Add TerminalTypeFromGuid internal function
Date: Tue, 10 Jan 2017 16:38:58 +0800	[thread overview]
Message-ID: <20170110083904.34104-3-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20170110083904.34104-1-ruiyu.ni@intel.com>

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
---
 .../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



  parent reply	other threads:[~2017-01-10  8:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10  8:38 [PATCH 0/8] Fix TerminalDxe driver model bug Ruiyu Ni
2017-01-10  8:38 ` [PATCH 1/8] MdeModulePkg/TerminalDxe: Replace macro with enum for terminal types Ruiyu Ni
2017-01-11  7:32   ` Tian, Feng
2017-01-10  8:38 ` Ruiyu Ni [this message]
2017-01-10  8:38 ` [PATCH 3/8] MdeModulePkg/TerminalDxe: Separate controller name init logic Ruiyu Ni
2017-01-10  8:39 ` [PATCH 4/8] MdeModulePkg/TerminalDxe: Refine InitializeTerminalConsoleTextMode Ruiyu Ni
2017-01-12 10:41   ` Laszlo Ersek
2017-01-12 15:39     ` Ni, Ruiyu
2017-01-10  8:39 ` [PATCH 5/8] MdeModulePkg/TerminalDxe: Refine SetTerminalDevicePath Ruiyu Ni
2017-01-10  8:39 ` [PATCH 6/8] MdeModulePkg/TerminalDxe: Separate state machine start/stop logic Ruiyu Ni
2017-01-10  8:39 ` [PATCH 7/8] MdeModulePkg/TerminalDxe: Remove unnecessary NULL pointer check Ruiyu Ni
2017-01-10  8:39 ` [PATCH 8/8] MdeModulePkg/TerminalDxe: Fix driver model bug Ruiyu Ni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170110083904.34104-3-ruiyu.ni@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox