]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c
DuplicateDevicePath() function use wrong comment same as AppendDevicePath() function.
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / BootMaint / ConsoleOption.c
index 270948633b682fbcee47d11882677c5f793099db..da0a8389fa43ebbd9596d5d819fc738272f33d70 100644 (file)
@@ -15,24 +15,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "BootMaint.h"\r
 \r
 /**\r
-  EDES_TODO: Add function description.\r
-\r
-  @param DevPath         EDES_TODO: Add parameter description\r
-\r
-  @return EDES_TODO: Add description for return value\r
-\r
-**/\r
-EFI_DEVICE_PATH_PROTOCOL  *\r
-DevicePathInstanceDup (\r
-  IN EFI_DEVICE_PATH_PROTOCOL  *DevPath\r
-  );\r
-\r
-/**\r
-  EDES_TODO: Add function description.\r
+  Update Com Ports attributes from DevicePath\r
 \r
-  @param DevicePath      EDES_TODO: Add parameter description\r
+  @param DevicePath      DevicePath that contains Com ports\r
 \r
-  @return EDES_TODO: Add description for return value\r
+  @retval EFI_SUCCESS   The update is successful.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -41,18 +28,21 @@ UpdateComAttributeFromVariable (
   );\r
 \r
 /**\r
-  EDES_TODO: Add function description.\r
+  Update the multi-instance device path of Terminal Device based on\r
+  the global TerminalMenu. If ChangeTernimal is TRUE, the terminal \r
+  device path in the Terminal Device in TerminalMenu is also updated.\r
 \r
-  @param DevicePath      EDES_TODO: Add parameter description\r
-  @param ChangeTerminal  EDES_TODO: Add parameter description\r
+  @param DevicePath      The multi-instance device path.\r
+  @param ChangeTerminal  TRUE, then device path in the Terminal Device \r
+                         in TerminalMenu is also updated; FALSE, no update.\r
 \r
-  @return EDES_TODO: Add description for return value\r
+  @return EFI_SUCCESS    The function completes successfully.\r
 \r
 **/\r
 EFI_STATUS\r
 ChangeTerminalDevicePath (\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
-  BOOLEAN                   ChangeTerminal\r
+  IN OUT    EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN        BOOLEAN                   ChangeTerminal\r
   )\r
 {\r
   EFI_DEVICE_PATH_PROTOCOL  *Node;\r
@@ -78,9 +68,6 @@ ChangeTerminalDevicePath (
     }\r
 \r
     NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Com);\r
-    if (NULL == NewMenuEntry) {\r
-      return EFI_NOT_FOUND;\r
-    }\r
 \r
     NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;\r
     if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
@@ -162,16 +149,16 @@ ChangeTerminalDevicePath (
 }\r
 \r
 /**\r
-  EDES_TODO: Add function description.\r
+  Update the device path that describing a terminal device\r
+  based on the new BaudRate, Data Bits, parity and Stop Bits\r
+  set.\r
 \r
-  @param DevicePath      EDES_TODO: Add parameter description\r
-\r
-  @return EDES_TODO: Add description for return value\r
+  @param DevicePath terminal device's path\r
 \r
 **/\r
 VOID\r
 ChangeVariableDevicePath (\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
   )\r
 {\r
   EFI_DEVICE_PATH_PROTOCOL  *Node;\r
@@ -229,16 +216,13 @@ ChangeVariableDevicePath (
 \r
     Node = NextDevicePathNode (Node);\r
   }\r
-\r
-  return ;\r
 }\r
 \r
 /**\r
   Retrieve ACPI UID of UART from device path\r
 \r
-\r
-  @param Handle          EDES_TODO: Add parameter description\r
-  @param AcpiUid         EDES_TODO: Add parameter description\r
+  @param Handle          The handle for the UART device.\r
+  @param AcpiUid         The ACPI UID on output.\r
 \r
   @retval  TRUE   Find valid UID from device path\r
   @retval  FALSE  Can't find\r
@@ -281,14 +265,10 @@ RetrieveUartUid (
 }\r
 \r
 /**\r
-  Sort Uart handles array with Acpi->UID from low to high\r
-\r
+  Sort Uart handles array with Acpi->UID from low to high.\r
 \r
   @param Handles         EFI_SERIAL_IO_PROTOCOL handle buffer\r
   @param NoHandles       EFI_SERIAL_IO_PROTOCOL handle count\r
-\r
-           EDES_TODO: Incomplete Descriptions  None\r
-\r
 **/\r
 VOID\r
 SortedUartHandle (\r
@@ -328,13 +308,15 @@ SortedUartHandle (
 }\r
 \r
 /**\r
-  EDES_TODO: Add function description.\r
+  Test whether DevicePath is a valid Terminal\r
+\r
 \r
-  @param DevicePath      EDES_TODO: Add parameter description\r
-  @param Termi           EDES_TODO: Add parameter description\r
-  @param Com             EDES_TODO: Add parameter description\r
+  @param DevicePath      DevicePath to be checked\r
+  @param Termi           If DevicePath is valid Terminal, terminal type is returned.\r
+  @param Com             If DevicePath is valid Terminal, Com Port type is returned.\r
 \r
-  @return EDES_TODO: Add description for return value\r
+  @retval  TRUE         If DevicePath point to a Terminal.\r
+  @retval  FALSE        If DevicePath does not point to a Terminal.\r
 \r
 **/\r
 BOOLEAN\r
@@ -345,12 +327,11 @@ IsTerminalDevicePath (
   );\r
 \r
 /**\r
-  Build a list containing all serial devices\r
+  Build a list containing all serial devices.\r
 \r
 \r
-  @param VOID            EDES_TODO: Add parameter description\r
-\r
-  @return EDES_TODO: Add description for return value\r
+  @retval EFI_SUCCESS The function complete successfully.\r
+  @retval EFI_UNSUPPORTED No serial ports present.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -421,13 +402,13 @@ LocateSerialIo (
     if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {\r
       NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT);\r
       if (NewMenuEntry == NULL) {\r
-        SafeFreePool (Handles);\r
+        FreePool (Handles);\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
 \r
       NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;\r
       CopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32));\r
-      NewTerminalContext->DevicePath = DevicePathInstanceDup (DevicePath);\r
+      NewTerminalContext->DevicePath = DuplicateDevicePath (DevicePath);\r
       //\r
       // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system!\r
       // coz' the misc data for each platform is not correct, actually it's the device path stored in\r
@@ -474,7 +455,9 @@ LocateSerialIo (
       TerminalMenu.MenuNumber++;\r
     }\r
   }\r
-  SafeFreePool (Handles);\r
+  if (Handles != NULL) {\r
+    FreePool (Handles);\r
+  }\r
 \r
   //\r
   // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var\r
@@ -511,13 +494,15 @@ LocateSerialIo (
     Vendor.Header.SubType             = MSG_VENDOR_DP;\r
 \r
     for (Index2 = 0; Index2 < 4; Index2++) {\r
-      CopyMem (&Vendor.Guid, &Guid[Index2], sizeof (EFI_GUID));\r
+      CopyMem (&Vendor.Guid, &TerminalTypeGuid[Index2], sizeof (EFI_GUID));\r
       SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH));\r
       NewDevicePath = AppendDevicePathNode (\r
                         NewTerminalContext->DevicePath,\r
                         (EFI_DEVICE_PATH_PROTOCOL *) &Vendor\r
                         );\r
-      SafeFreePool (NewMenuEntry->HelpString);\r
+      if (NewMenuEntry->HelpString != NULL) {\r
+        FreePool (NewMenuEntry->HelpString);\r
+      }\r
       //\r
       // NewMenuEntry->HelpString = DevicePathToStr (NewDevicePath);\r
       // NewMenuEntry->DisplayString = NewMenuEntry->HelpString;\r
@@ -547,11 +532,10 @@ LocateSerialIo (
 /**\r
   Update Com Ports attributes from DevicePath\r
 \r
-\r
   @param DevicePath      DevicePath that contains Com ports\r
 \r
-  @return EDES_TODO: Add description for return value\r
-\r
+  @retval EFI_SUCCESS   The update is successful.\r
+  @retval EFI_NOT_FOUND Can not find specific menu entry\r
 **/\r
 EFI_STATUS\r
 UpdateComAttributeFromVariable (\r
@@ -666,59 +650,18 @@ UpdateComAttributeFromVariable (
 }\r
 \r
 /**\r
-  Function creates a device path data structure that identically matches the\r
-  device path passed in.\r
-\r
-\r
-  @param DevPath         A pointer to a device path data structure.\r
-\r
-           EDES_TODO: Incomplete Descriptions  The new copy of DevPath is created to identically match the input.\r
-           EDES_TODO: Incomplete Descriptions  Otherwise, NULL is returned.\r
-\r
-**/\r
-EFI_DEVICE_PATH_PROTOCOL *\r
-DevicePathInstanceDup (\r
-  IN EFI_DEVICE_PATH_PROTOCOL  *DevPath\r
-  )\r
-{\r
-  EFI_DEVICE_PATH_PROTOCOL  *NewDevPath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePathInst;\r
-  EFI_DEVICE_PATH_PROTOCOL  *Temp;\r
-  UINT8                     *Ptr;\r
-  UINTN                     Size;\r
-\r
-  //\r
-  // get the size of an instance from the input\r
-  //\r
-  Temp            = DevPath;\r
-  DevicePathInst  = GetNextDevicePathInstance (&Temp, &Size);\r
-\r
-  //\r
-  // Make a copy and set proper end type\r
-  //\r
-  NewDevPath = NULL;\r
-  if (Size != 0) {\r
-    NewDevPath = EfiAllocateZeroPool (Size);\r
-    ASSERT (NewDevPath != NULL);\r
-  }\r
-\r
-  if (NewDevPath != NULL) {\r
-    CopyMem (NewDevPath, DevicePathInst, Size);\r
-    Ptr = (UINT8 *) NewDevPath;\r
-    Ptr += Size - sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
-    Temp = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;\r
-    SetDevicePathEndNode (Temp);\r
-  }\r
-\r
-  return NewDevPath;\r
-}\r
-\r
-/**\r
-  EDES_TODO: Add function description.\r
+  Build up Console Menu based on types passed in. The type can\r
+  be BM_CONSOLE_IN_CONTEXT_SELECT, BM_CONSOLE_OUT_CONTEXT_SELECT\r
+  and BM_CONSOLE_ERR_CONTEXT_SELECT.\r
 \r
-  @param ConsoleMenuType EDES_TODO: Add parameter description\r
+  @param ConsoleMenuType Can be BM_CONSOLE_IN_CONTEXT_SELECT, BM_CONSOLE_OUT_CONTEXT_SELECT\r
+                         and BM_CONSOLE_ERR_CONTEXT_SELECT.\r
 \r
-  @return EDES_TODO: Add description for return value\r
+  @retval EFI_UNSUPPORTED The type passed in is not in the 3 types defined.\r
+  @retval EFI_NOT_FOUND   If the EFI Variable defined in UEFI spec with name "ConOutDev", \r
+                          "ConInDev" or "ConErrDev" doesn't exists.\r
+  @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operations.\r
+  @retval EFI_SUCCESS          Function completes successfully.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -796,7 +739,7 @@ GetConsoleMenu (
   AllCount                = EfiDevicePathInstanceCount (AllDevicePath);\r
   ConsoleMenu->MenuNumber = 0;\r
   //\r
-  // Following is menu building up for Console Out Devices\r
+  // Following is menu building up for Console Devices selected.\r
   //\r
   MultiDevicePath = AllDevicePath;\r
   Index2          = 0;\r
@@ -811,7 +754,7 @@ GetConsoleMenu (
     NewConsoleContext             = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;\r
     NewMenuEntry->OptionNumber    = Index2;\r
 \r
-    NewConsoleContext->DevicePath = DevicePathInstanceDup (DevicePathInst);\r
+    NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst);\r
     NewMenuEntry->DisplayString   = EfiLibStrFromDatahub (NewConsoleContext->DevicePath);\r
     if (NULL == NewMenuEntry->DisplayString) {\r
       NewMenuEntry->DisplayString = DevicePathToStr (NewConsoleContext->DevicePath);\r
@@ -843,11 +786,7 @@ GetConsoleMenu (
 /**\r
   Build up ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu\r
 \r
-\r
-  @param VOID            EDES_TODO: Add parameter description\r
-\r
-           EDES_TODO: Incomplete Descriptions  EFI_SUCCESS\r
-           EDES_TODO: Incomplete Descriptions  Others\r
+  @retval EFI_SUCCESS    The function always complete successfully.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -864,12 +803,7 @@ GetAllConsoles (
 /**\r
   Free ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu\r
 \r
-\r
-  @param VOID            EDES_TODO: Add parameter description\r
-\r
-           EDES_TODO: Incomplete Descriptions  EFI_SUCCESS\r
-           EDES_TODO: Incomplete Descriptions  Others\r
-\r
+  @retval EFI_SUCCESS    The function always complete successfully.\r
 **/\r
 EFI_STATUS\r
 FreeAllConsoles (\r
@@ -888,11 +822,11 @@ FreeAllConsoles (
 \r
 \r
   @param DevicePath      DevicePath to be checked\r
-  @param Termi           If is terminal, give its type\r
-  @param Com             If is Com Port, give its type\r
+  @param Termi           If DevicePath is valid Terminal, terminal type is returned.\r
+  @param Com             If DevicePath is valid Terminal, Com Port type is returned.\r
 \r
-  @retval  TRUE         If DevicePath point to a Terminal\r
-                        FALSE\r
+  @retval  TRUE         If DevicePath point to a Terminal.\r
+  @retval  FALSE        If DevicePath does not point to a Terminal.\r
 \r
 **/\r
 BOOLEAN\r
@@ -929,19 +863,19 @@ IsTerminalDevicePath (
   //\r
   CopyMem (&TempGuid, &Vendor->Guid, sizeof (EFI_GUID));\r
 \r
-  if (CompareGuid (&TempGuid, &Guid[0])) {\r
+  if (CompareGuid (&TempGuid, &TerminalTypeGuid[0])) {\r
     *Termi      = PC_ANSI;\r
     IsTerminal  = TRUE;\r
   } else {\r
-    if (CompareGuid (&TempGuid, &Guid[1])) {\r
+    if (CompareGuid (&TempGuid, &TerminalTypeGuid[1])) {\r
       *Termi      = VT_100;\r
       IsTerminal  = TRUE;\r
     } else {\r
-      if (CompareGuid (&TempGuid, &Guid[2])) {\r
+      if (CompareGuid (&TempGuid, &TerminalTypeGuid[2])) {\r
         *Termi      = VT_100_PLUS;\r
         IsTerminal  = TRUE;\r
       } else {\r
-        if (CompareGuid (&TempGuid, &Guid[3])) {\r
+        if (CompareGuid (&TempGuid, &TerminalTypeGuid[3])) {\r
           *Termi      = VT_UTF8;\r
           IsTerminal  = TRUE;\r
         } else {\r
@@ -970,11 +904,7 @@ IsTerminalDevicePath (
 /**\r
   Get mode number according to column and row\r
 \r
-\r
-  @param CallbackData    BMM_CALLBACK_DATA\r
-\r
-           EDES_TODO: Incomplete Descriptions  None.\r
-\r
+  @param CallbackData    The BMM context data.\r
 **/\r
 VOID\r
 GetConsoleOutMode (\r
@@ -993,7 +923,7 @@ GetConsoleOutMode (
 \r
   ConOut   = gST->ConOut;\r
   MaxMode  = (UINTN) (ConOut->Mode->MaxMode);\r
-  ModeInfo = EfiLibGetVariable (VarConOutMode, &gEfiGenericPlatformVariableGuid);\r
+  ModeInfo = EfiLibGetVariable (VAR_CON_OUT_MODE, &gEfiGenericPlatformVariableGuid);\r
 \r
   if (ModeInfo != NULL) {\r
     CurrentCol = ModeInfo->Column;\r
@@ -1007,6 +937,6 @@ GetConsoleOutMode (
         }\r
       }\r
     }\r
+    FreePool (ModeInfo);\r
   }\r
-  SafeFreePool (ModeInfo);\r
 }\r