]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
IntelFrameworkModulePkg: Refine casting expression result to bigger size
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsConsole.c
index 02ad3a2bb78c2588cfa4f893e2d557d9d6d8e8b0..8f273ff1b1eaaf44ad95ee2dd2655a81405db33f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   BDS Lib functions which contain all the code to connect console device\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 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
@@ -65,9 +65,9 @@ IsNvNeed (
   @param  VarName            The name of the EFI console variable.\r
   @param  ConsoleGuid        Specified Console protocol GUID.\r
   @param  ConsoleHandle      On IN,  console handle in System Table to be checked. \r
-                             On OUT, new console hanlde in system table.\r
+                             On OUT, new console handle in system table.\r
   @param  ProtocolInterface  On IN,  console protocol on console handle in System Table to be checked. \r
-                             On OUT, new console protocol on new console hanlde in system table.\r
+                             On OUT, new console protocol on new console handle in system table.\r
 \r
   @retval TRUE               System Table has been updated.\r
   @retval FALSE              System Table hasn't been updated.\r
@@ -181,114 +181,6 @@ UpdateSystemTableConsole (
   return FALSE;\r
 }\r
 \r
-/**\r
-  Connect the console device base on the variable ConVarName, if\r
-  device path of the ConVarName is multi-instance device path and\r
-  anyone of the instances is connected success, this function will\r
-  return success. \r
-  Dispatch service is called basing on input when the handle associate\r
-  with one device path node can not be created successfully. Since in\r
-  some cases we assume driver dependency does not exist and do not \r
-  need to call this service.\r
-\r
-  @param  ConVarName               Console related variable name, ConIn, ConOut,\r
-                                   ErrOut.\r
-  @param  NeedDispatch              Whether requires dispatch service during connection \r
-\r
-  @retval EFI_NOT_FOUND            There is not any console devices connected\r
-                                   success\r
-  @retval EFI_SUCCESS              Success connect any one instance of the console\r
-                                   device path base on the variable ConVarName.\r
-\r
-**/\r
-EFI_STATUS\r
-ConnectConsoleVariableInternal (\r
-  IN  CHAR16                 *ConVarName,\r
-  IN  BOOLEAN                NeedDispatch\r
-  )\r
-{\r
-  EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *StartDevicePath;\r
-  UINTN                     VariableSize;\r
-  EFI_DEVICE_PATH_PROTOCOL  *Instance;\r
-  EFI_DEVICE_PATH_PROTOCOL  *Next;\r
-  EFI_DEVICE_PATH_PROTOCOL  *CopyOfDevicePath;\r
-  UINTN                     Size;\r
-  BOOLEAN                   DeviceExist;\r
-\r
-  Status      = EFI_SUCCESS;\r
-  DeviceExist = FALSE;\r
-\r
-  //\r
-  // Check if the console variable exist\r
-  //\r
-  StartDevicePath = BdsLibGetVariableAndSize (\r
-                      ConVarName,\r
-                      &gEfiGlobalVariableGuid,\r
-                      &VariableSize\r
-                      );\r
-  if (StartDevicePath == NULL) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  CopyOfDevicePath = StartDevicePath;\r
-  do {\r
-    //\r
-    // Check every instance of the console variable\r
-    //\r
-    Instance  = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);\r
-    if (Instance == NULL) {\r
-      FreePool (StartDevicePath);\r
-      return EFI_UNSUPPORTED;\r
-    }\r
-    \r
-    Next      = Instance;\r
-    while (!IsDevicePathEndType (Next)) {\r
-      Next = NextDevicePathNode (Next);\r
-    }\r
-\r
-    SetDevicePathEndNode (Next);\r
-    //\r
-    // Connect the USB console\r
-    // USB console device path is a short-form device path that \r
-    //  starts with the first element being a USB WWID\r
-    //  or a USB Class device path\r
-    //\r
-    if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&\r
-       ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)\r
-       || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)\r
-       )) {\r
-      Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance);\r
-      if (!EFI_ERROR (Status)) {\r
-        DeviceExist = TRUE;\r
-      }\r
-    } else {\r
-      //\r
-      // Connect the instance device path\r
-      //\r
-      Status = ConnectDevicePathInternal (Instance, NeedDispatch);\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        //\r
-        // Delete the instance from the console varialbe\r
-        //\r
-        BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);\r
-      } else {\r
-        DeviceExist = TRUE;\r
-      }\r
-    }\r
-    FreePool(Instance);\r
-  } while (CopyOfDevicePath != NULL);\r
-\r
-  FreePool (StartDevicePath);\r
-\r
-  if (!DeviceExist) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
 /**\r
   This function update console variable based on ConVarName, it can\r
   add or remove one specific console device path from the variable\r
@@ -393,17 +285,16 @@ BdsLibUpdateConsoleVariable (
   // Finally, Update the variable of the default console by NewDevicePath\r
   //\r
   DevicePathSize = GetDevicePathSize (NewDevicePath);\r
-  Status = gRT->SetVariable (\r
-                  ConVarName,\r
-                  &gEfiGlobalVariableGuid,\r
-                  Attributes,\r
-                  DevicePathSize,\r
-                  NewDevicePath\r
-                  );\r
+  Status = SetVariableAndReportStatusCodeOnError (\r
+             ConVarName,\r
+             &gEfiGlobalVariableGuid,\r
+             Attributes,\r
+             DevicePathSize,\r
+             NewDevicePath\r
+             );\r
   if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {\r
     Status = EFI_SUCCESS;\r
   }\r
-  ASSERT_EFI_ERROR (Status);\r
 \r
   if (VarConsole == NewDevicePath) {\r
     if (VarConsole != NULL) {\r
@@ -447,35 +338,86 @@ BdsLibConnectConsoleVariable (
   IN  CHAR16                 *ConVarName\r
   )\r
 {\r
-  return ConnectConsoleVariableInternal(ConVarName, TRUE);\r
-}\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *StartDevicePath;\r
+  UINTN                     VariableSize;\r
+  EFI_DEVICE_PATH_PROTOCOL  *Instance;\r
+  EFI_DEVICE_PATH_PROTOCOL  *Next;\r
+  EFI_DEVICE_PATH_PROTOCOL  *CopyOfDevicePath;\r
+  UINTN                     Size;\r
+  BOOLEAN                   DeviceExist;\r
 \r
-/**\r
-  Connect the console device base on the variable ConVarName, if\r
-  device path of the ConVarName is multi-instance device path and\r
-  anyone of the instances is connected success, then this function\r
-  will return success.\r
-  Dispatch service is not called when the handle associate with one \r
-  device path node can not be created successfully. Here no driver \r
-  dependency is assumed exist, so need not to call this service.\r
+  Status      = EFI_SUCCESS;\r
+  DeviceExist = FALSE;\r
 \r
+  //\r
+  // Check if the console variable exist\r
+  //\r
+  StartDevicePath = BdsLibGetVariableAndSize (\r
+                      ConVarName,\r
+                      &gEfiGlobalVariableGuid,\r
+                      &VariableSize\r
+                      );\r
+  if (StartDevicePath == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
-  @param  ConVarName               Console related variable name, ConIn, ConOut,\r
-                                   ErrOut.\r
+  CopyOfDevicePath = StartDevicePath;\r
+  do {\r
+    //\r
+    // Check every instance of the console variable\r
+    //\r
+    Instance  = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);\r
+    if (Instance == NULL) {\r
+      FreePool (StartDevicePath);\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    \r
+    Next      = Instance;\r
+    while (!IsDevicePathEndType (Next)) {\r
+      Next = NextDevicePathNode (Next);\r
+    }\r
 \r
-  @retval EFI_NOT_FOUND            There is not any console devices connected\r
-                                   success\r
-  @retval EFI_SUCCESS              Success connect any one instance of the console\r
-                                   device path base on the variable ConVarName.\r
+    SetDevicePathEndNode (Next);\r
+    //\r
+    // Connect the USB console\r
+    // USB console device path is a short-form device path that \r
+    //  starts with the first element being a USB WWID\r
+    //  or a USB Class device path\r
+    //\r
+    if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&\r
+       ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)\r
+       || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)\r
+       )) {\r
+      Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance);\r
+      if (!EFI_ERROR (Status)) {\r
+        DeviceExist = TRUE;\r
+      }\r
+    } else {\r
+      //\r
+      // Connect the instance device path\r
+      //\r
+      Status = BdsLibConnectDevicePath (Instance);\r
 \r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-BdsLibConnectConsoleVariableWithOutDispatch (\r
-  IN  CHAR16                 *ConVarName\r
-  )\r
-{\r
-  return ConnectConsoleVariableInternal(ConVarName, FALSE);\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // Delete the instance from the console varialbe\r
+        //\r
+        BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);\r
+      } else {\r
+        DeviceExist = TRUE;\r
+      }\r
+    }\r
+    FreePool(Instance);\r
+  } while (CopyOfDevicePath != NULL);\r
+\r
+  FreePool (StartDevicePath);\r
+\r
+  if (!DeviceExist) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -927,12 +869,11 @@ ConvertBmpToGopBlt (
           *GopBlt = NULL;\r
         }\r
         return EFI_UNSUPPORTED;\r
-        break;\r
       };\r
 \r
     }\r
 \r
-    ImageIndex = (UINTN) (Image - ImageHeader);\r
+    ImageIndex = (UINTN)Image - (UINTN)ImageHeader;\r
     if ((ImageIndex % 4) != 0) {\r
       //\r
       // Bmp Image starts each row on a 32-bit boundary!\r