]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c
1. IsaSerialIo driver was changed to produce the flow control device path node when...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BootMaint / ConsoleOption.c
index 06fd0e0af775c3eb33aa62abe5ff6ef31d315bd7..e79b3f6a3013cee3c68181d0d93782344fd1f708 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   handles console redirection from boot manager\r
 \r
-Copyright (c) 2004 - 2009, Intel Corporation. <BR>\r
+Copyright (c) 2004 - 2010, Intel Corporation. <BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -14,6 +14,27 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "BootMaint.h"\r
 \r
+/**\r
+  Check whether the device path node is ISA Serial Node.\r
+\r
+  @param Acpi           Device path node to be checked\r
+\r
+  @retval TRUE          It's ISA Serial Node.\r
+  @retval FALSE         It's NOT ISA Serial Node.\r
+\r
+**/\r
+BOOLEAN\r
+IsIsaSerialNode (\r
+  IN ACPI_HID_DEVICE_PATH *Acpi\r
+  )\r
+{\r
+  return (BOOLEAN) (\r
+      (DevicePathType (Acpi) == ACPI_DEVICE_PATH) &&\r
+      (DevicePathSubType (Acpi) == ACPI_DP) &&\r
+      (ReadUnaligned32 (&Acpi->HID) == EISA_PNP_ID (0x0501))\r
+      );\r
+}\r
+\r
 /**\r
   Update Com Ports attributes from DevicePath\r
 \r
@@ -51,20 +72,16 @@ ChangeTerminalDevicePath (
   UART_DEVICE_PATH          *Uart;\r
   UART_DEVICE_PATH          *Uart1;\r
   UINTN                     Com;\r
-  UINT32                    Match;\r
   BM_TERMINAL_CONTEXT       *NewTerminalContext;\r
   BM_MENU_ENTRY             *NewMenuEntry;\r
 \r
-  Match = EISA_PNP_ID (0x0501);\r
   Node  = DevicePath;\r
   Node  = NextDevicePathNode (Node);\r
   Com   = 0;\r
   while (!IsDevicePathEnd (Node)) {\r
-    if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) {\r
-      Acpi = (ACPI_HID_DEVICE_PATH *) Node;\r
-      if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {\r
-        CopyMem (&Com, &Acpi->UID, sizeof (UINT32));\r
-      }\r
+    Acpi = (ACPI_HID_DEVICE_PATH *) Node;\r
+    if (IsIsaSerialNode (Acpi)) {\r
+      CopyMem (&Com, &Acpi->UID, sizeof (UINT32));\r
     }\r
 \r
     NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Com);\r
@@ -165,20 +182,16 @@ ChangeVariableDevicePath (
   ACPI_HID_DEVICE_PATH      *Acpi;\r
   UART_DEVICE_PATH          *Uart;\r
   UINTN                     Com;\r
-  UINT32                    Match;\r
   BM_TERMINAL_CONTEXT       *NewTerminalContext;\r
   BM_MENU_ENTRY             *NewMenuEntry;\r
 \r
-  Match = EISA_PNP_ID (0x0501);\r
   Node  = DevicePath;\r
   Node  = NextDevicePathNode (Node);\r
   Com   = 0;\r
   while (!IsDevicePathEnd (Node)) {\r
-    if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) {\r
-      Acpi = (ACPI_HID_DEVICE_PATH *) Node;\r
-      if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {\r
-        CopyMem (&Com, &Acpi->UID, sizeof (UINT32));\r
-      }\r
+    Acpi = (ACPI_HID_DEVICE_PATH *) Node;\r
+    if (IsIsaSerialNode (Acpi)) {\r
+      CopyMem (&Com, &Acpi->UID, sizeof (UINT32));\r
     }\r
 \r
     if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
@@ -234,29 +247,33 @@ RetrieveUartUid (
   IN OUT UINT32   *AcpiUid\r
   )\r
 {\r
-  UINT32                    Match;\r
-  UINT8                     *Ptr;\r
+  EFI_STATUS                Status;\r
   ACPI_HID_DEVICE_PATH      *Acpi;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
 \r
-  gBS->HandleProtocol (\r
-        Handle,\r
-        &gEfiDevicePathProtocolGuid,\r
-        (VOID **) &DevicePath\r
-        );\r
-  Ptr = (UINT8 *) DevicePath;\r
-\r
-  while (*Ptr != END_DEVICE_PATH_TYPE) {\r
-    Ptr++;\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &DevicePath\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
   }\r
 \r
-  Ptr   = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH);\r
-  Acpi  = (ACPI_HID_DEVICE_PATH *) Ptr;\r
-  Match = EISA_PNP_ID (0x0501);\r
+  Acpi = NULL;\r
+  for (; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r
+    if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (DevicePath) == MSG_UART_DP)) {\r
+      break;\r
+    }\r
+    //\r
+    // Acpi points to the node before the Uart node\r
+    //\r
+    Acpi = (ACPI_HID_DEVICE_PATH *) DevicePath;\r
+  }\r
 \r
-  if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {\r
+  if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {\r
     if (AcpiUid != NULL) {\r
-      *AcpiUid = Acpi->UID;\r
+      CopyMem (AcpiUid, &Acpi->UID, sizeof (UINT32));\r
     }\r
     return TRUE;\r
   } else {\r
@@ -339,7 +356,6 @@ LocateSerialIo (
   VOID\r
   )\r
 {\r
-  UINT8                     *Ptr;\r
   UINTN                     Index;\r
   UINTN                     Index2;\r
   UINTN                     NoHandles;\r
@@ -347,8 +363,8 @@ LocateSerialIo (
   EFI_STATUS                Status;\r
   ACPI_HID_DEVICE_PATH      *Acpi;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  UINT32                    Match;\r
   EFI_SERIAL_IO_PROTOCOL    *SerialIo;\r
+  EFI_DEVICE_PATH_PROTOCOL  *Node;\r
   EFI_DEVICE_PATH_PROTOCOL  *OutDevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL  *InpDevicePath;\r
   EFI_DEVICE_PATH_PROTOCOL  *ErrDevicePath;\r
@@ -390,16 +406,19 @@ LocateSerialIo (
           &gEfiDevicePathProtocolGuid,\r
           (VOID **) &DevicePath\r
           );\r
-    Ptr = (UINT8 *) DevicePath;\r
-    while (*Ptr != END_DEVICE_PATH_TYPE) {\r
-      Ptr++;\r
-    }\r
 \r
-    Ptr   = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH);\r
-    Acpi  = (ACPI_HID_DEVICE_PATH *) Ptr;\r
-    Match = EISA_PNP_ID (0x0501);\r
+    Acpi = NULL;\r
+    for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {\r
+      if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
+        break;\r
+      }\r
+      //\r
+      // Acpi points to the node before Uart node\r
+      //\r
+      Acpi = (ACPI_HID_DEVICE_PATH *) Node;\r
+    }\r
 \r
-    if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {\r
+    if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {\r
       NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT);\r
       if (NewMenuEntry == NULL) {\r
         FreePool (Handles);\r
@@ -547,23 +566,19 @@ UpdateComAttributeFromVariable (
   ACPI_HID_DEVICE_PATH      *Acpi;\r
   UART_DEVICE_PATH          *Uart;\r
   UART_DEVICE_PATH          *Uart1;\r
-  UINT32                    Match;\r
   UINTN                     TerminalNumber;\r
   BM_MENU_ENTRY             *NewMenuEntry;\r
   BM_TERMINAL_CONTEXT       *NewTerminalContext;\r
   UINTN                     Index;\r
 \r
-  Match           = EISA_PNP_ID (0x0501);\r
   Node            = DevicePath;\r
   Node            = NextDevicePathNode (Node);\r
   TerminalNumber  = 0;\r
   for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
     while (!IsDevicePathEnd (Node)) {\r
-      if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) {\r
-        Acpi = (ACPI_HID_DEVICE_PATH *) Node;\r
-        if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {\r
-          CopyMem (&TerminalNumber, &Acpi->UID, sizeof (UINT32));\r
-        }\r
+      Acpi = (ACPI_HID_DEVICE_PATH *) Node;\r
+      if (IsIsaSerialNode (Acpi)) {\r
+        CopyMem (&TerminalNumber, &Acpi->UID, sizeof (UINT32));\r
       }\r
 \r
       if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
@@ -755,6 +770,7 @@ GetConsoleMenu (
     NewMenuEntry->OptionNumber    = Index2;\r
 \r
     NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst);\r
+    ASSERT (NewConsoleContext->DevicePath != NULL);\r
     NewMenuEntry->DisplayString   = EfiLibStrFromDatahub (NewConsoleContext->DevicePath);\r
     if (NULL == NewMenuEntry->DisplayString) {\r
       NewMenuEntry->DisplayString = DevicePathToStr (NewConsoleContext->DevicePath);\r
@@ -836,46 +852,60 @@ IsTerminalDevicePath (
   OUT UINTN                    *Com\r
   )\r
 {\r
-  UINT8                 *Ptr;\r
-  BOOLEAN               IsTerminal;\r
-  VENDOR_DEVICE_PATH    *Vendor;\r
-  ACPI_HID_DEVICE_PATH  *Acpi;\r
-  UINT32                Match;\r
-  EFI_GUID              TempGuid;\r
+  BOOLEAN                   IsTerminal;\r
+  EFI_DEVICE_PATH_PROTOCOL  *Node;\r
+  VENDOR_DEVICE_PATH        *Vendor;\r
+  UART_DEVICE_PATH          *Uart;\r
+  ACPI_HID_DEVICE_PATH      *Acpi;\r
 \r
   IsTerminal = FALSE;\r
 \r
-  //\r
-  // Parse the Device Path, should be change later!!!\r
-  //\r
-  Ptr = (UINT8 *) DevicePath;\r
-  while (*Ptr != END_DEVICE_PATH_TYPE) {\r
-    Ptr++;\r
+  Uart   = NULL;\r
+  Vendor = NULL;\r
+  Acpi   = NULL;\r
+  for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {\r
+    //\r
+    // Vendor points to the node before the End node\r
+    //\r
+    Vendor = (VENDOR_DEVICE_PATH *) Node;\r
+\r
+    if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
+      Uart = (UART_DEVICE_PATH *) Node;\r
+    }\r
+\r
+    if (Uart == NULL) {\r
+      //\r
+      // Acpi points to the node before the UART node\r
+      //\r
+      Acpi = (ACPI_HID_DEVICE_PATH *) Node;\r
+    }\r
   }\r
 \r
-  Ptr     = Ptr - sizeof (VENDOR_DEVICE_PATH);\r
-  Vendor  = (VENDOR_DEVICE_PATH *) Ptr;\r
+  if (Vendor == NULL ||\r
+      DevicePathType (Vendor) != MESSAGING_DEVICE_PATH ||\r
+      DevicePathSubType (Vendor) != MSG_VENDOR_DP ||\r
+      Uart == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
   // There are four kinds of Terminal types\r
   // check to see whether this devicepath\r
   // is one of that type\r
   //\r
-  CopyMem (&TempGuid, &Vendor->Guid, sizeof (EFI_GUID));\r
-\r
-  if (CompareGuid (&TempGuid, &TerminalTypeGuid[0])) {\r
+  if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[0])) {\r
     *Termi      = TerminalTypePcAnsi;\r
     IsTerminal  = TRUE;\r
   } else {\r
-    if (CompareGuid (&TempGuid, &TerminalTypeGuid[1])) {\r
+    if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[1])) {\r
       *Termi      = TerminalTypeVt100;\r
       IsTerminal  = TRUE;\r
     } else {\r
-      if (CompareGuid (&TempGuid, &TerminalTypeGuid[2])) {\r
+      if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[2])) {\r
         *Termi      = TerminalTypeVt100Plus;\r
         IsTerminal  = TRUE;\r
       } else {\r
-        if (CompareGuid (&TempGuid, &TerminalTypeGuid[3])) {\r
+        if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[3])) {\r
           *Termi      = TerminalTypeVtUtf8;\r
           IsTerminal  = TRUE;\r
         } else {\r
@@ -889,10 +919,7 @@ IsTerminalDevicePath (
     return FALSE;\r
   }\r
 \r
-  Ptr   = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH);\r
-  Acpi  = (ACPI_HID_DEVICE_PATH *) Ptr;\r
-  Match = EISA_PNP_ID (0x0501);\r
-  if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {\r
+  if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {\r
     CopyMem (Com, &Acpi->UID, sizeof (UINT32));\r
   } else {\r
     return FALSE;\r