]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Universal/ConPlatform/Dxe/ConPlatform.c
MdePkg:
[mirror_edk2.git] / EdkModulePkg / Universal / ConPlatform / Dxe / ConPlatform.c
index 684c66485235d600a6e0584e12c7a9447cb7dcf1..1972e0c6aa90eec1ade1f90d63c6876d4161cd15 100644 (file)
@@ -1,18 +1,18 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \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
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+Copyright (c) 2006 - 2007, Intel Corporation\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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 Module Name:\r
 \r
     ConPlatform.c\r
-    \r
+\r
 Abstract:\r
 \r
 --*/\r
@@ -22,8 +22,8 @@ Abstract:
 EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding = {\r
   ConPlatformTextInDriverBindingSupported,\r
   ConPlatformTextInDriverBindingStart,\r
-  ConPlatformDriverBindingStop,\r
-  0x10,\r
+  ConPlatformTextInDriverBindingStop,\r
+  0xa,\r
   NULL,\r
   NULL\r
 };\r
@@ -31,8 +31,8 @@ EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding = {
 EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding = {\r
   ConPlatformTextOutDriverBindingSupported,\r
   ConPlatformTextOutDriverBindingStart,\r
-  ConPlatformDriverBindingStop,\r
-  0x10,\r
+  ConPlatformTextOutDriverBindingStop,\r
+  0xa,\r
   NULL,\r
   NULL\r
 };\r
@@ -47,7 +47,7 @@ ConPlatformTextInDriverBindingSupported (
 /*++\r
 \r
 Routine Description:\r
-  Supported \r
+  Supported\r
 \r
 Arguments:\r
   (Standard DriverBinding Protocol Supported() function)\r
@@ -76,7 +76,7 @@ ConPlatformTextOutDriverBindingSupported (
 /*++\r
 \r
 Routine Description:\r
-  Supported \r
+  Supported\r
 \r
 Arguments:\r
   (Standard DriverBinding Protocol Supported() function)\r
@@ -105,7 +105,7 @@ ConPlatformDriverBindingSupported (
 /*++\r
 \r
 Routine Description:\r
-  Supported \r
+  Supported\r
 \r
 Arguments:\r
   (Standard DriverBinding Protocol Supported() function)\r
@@ -287,7 +287,6 @@ Returns:
   EFI_STATUS                    Status;\r
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
   EFI_SIMPLE_TEXT_OUT_PROTOCOL  *TextOut;\r
-\r
   BOOLEAN                       NeedClose;\r
 \r
   NeedClose = TRUE;\r
@@ -360,6 +359,7 @@ Returns:
               DevicePath,\r
               CHECK\r
               );\r
+\r
     if (!EFI_ERROR (Status)) {\r
       NeedClose = FALSE;\r
       Status = gBS->InstallMultipleProtocolInterfaces (\r
@@ -403,7 +403,7 @@ Returns:
 \r
 EFI_STATUS\r
 EFIAPI\r
-ConPlatformDriverBindingStop (\r
+ConPlatformTextInDriverBindingStop (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   ControllerHandle,\r
   IN  UINTN                        NumberOfChildren,\r
@@ -443,13 +443,81 @@ Returns:
                     );\r
     if (!EFI_ERROR (Status)) {\r
       //\r
-      // Remove DevicePath from ConInDev, ConOutDev, and StdErrDev\r
+      // Remove DevicePath from ConInDev\r
       //\r
       ConPlatformUpdateDeviceVariable (\r
         VarConsoleInpDev,\r
         DevicePath,\r
         DELETE\r
         );\r
+    }\r
+  }\r
+  //\r
+  // Uninstall the Console Device GUIDs from Controller Handle\r
+  //\r
+  ConPlatformUnInstallProtocol (\r
+    This,\r
+    ControllerHandle,\r
+    &gEfiConsoleInDeviceGuid\r
+    );\r
+\r
+  //\r
+  // Close the Simple Input Protocol\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiSimpleTextInProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ConPlatformTextOutDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+  (Standard DriverBinding Protocol Stop() function)\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+\r
+  //\r
+  // hot plug device is not included into the console associated variables,\r
+  // so no need to check variable for those hot plug devices.\r
+  //\r
+  if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
+    //\r
+    // Get the Device Path Protocol so the environment variables can be updated\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    ControllerHandle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    (VOID **) &DevicePath,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Remove DevicePath from ConOutDev, and StdErrDev\r
+      //\r
       ConPlatformUpdateDeviceVariable (\r
         VarConsoleOutDev,\r
         DevicePath,\r
@@ -465,12 +533,6 @@ Returns:
   //\r
   // Uninstall the Console Device GUIDs from Controller Handle\r
   //\r
-  ConPlatformUnInstallProtocol (\r
-    This,\r
-    ControllerHandle,\r
-    &gEfiConsoleInDeviceGuid\r
-    );\r
-\r
   ConPlatformUnInstallProtocol (\r
     This,\r
     ControllerHandle,\r
@@ -484,15 +546,8 @@ Returns:
     );\r
 \r
   //\r
-  // Close the Simple Input and Simple Text Output Protocols\r
+  // Close the Simple Text Output Protocol\r
   //\r
-  gBS->CloseProtocol (\r
-        ControllerHandle,\r
-        &gEfiSimpleTextInProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        ControllerHandle\r
-        );\r
-\r
   gBS->CloseProtocol (\r
         ControllerHandle,\r
         &gEfiSimpleTextOutProtocolGuid,\r
@@ -503,6 +558,7 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
 VOID\r
 ConPlatformUnInstallProtocol (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
@@ -551,7 +607,7 @@ Returns:
   Caller is repsoncible freeing the buffer.\r
 \r
   NULL - Variable was not read\r
-  \r
+\r
 --*/\r
 {\r
   EFI_STATUS  Status;\r
@@ -576,8 +632,8 @@ Returns:
     //\r
     // Allocate the buffer to return\r
     //\r
-    Status = gBS->AllocatePool (EfiBootServicesData, BufferSize, &Buffer);\r
-    if (EFI_ERROR (Status)) {\r
+    Buffer = AllocatePool (BufferSize);\r
+    if (Buffer == NULL) {\r
       return NULL;\r
     }\r
     //\r
@@ -591,7 +647,7 @@ Returns:
                     Buffer\r
                     );\r
     if (EFI_ERROR (Status)) {\r
-      gBS->FreePool (Buffer);\r
+      FreePool (Buffer);\r
       Buffer = NULL;\r
     }\r
   }\r
@@ -616,18 +672,18 @@ Arguments:
   Multi        - A pointer to a multi-instance device path data structure.\r
 \r
   Single       - A pointer to a single-instance device path data structure.\r
-  \r
+\r
   NewDevicePath - If Delete is TRUE, this parameter must not be null, and it\r
-                  points to the remaining device path data structure. \r
+                  points to the remaining device path data structure.\r
                   (remaining device path = Multi - Single.)\r
-  \r
+\r
   Delete        - If TRUE, means removing Single from Multi.\r
-                  If FALSE, the routine just check whether Single matches \r
+                  If FALSE, the routine just check whether Single matches\r
                   with any instance in Multi.\r
 \r
 Returns:\r
 \r
-  The function returns EFI_SUCCESS if the Single is contained within Multi.  \r
+  The function returns EFI_SUCCESS if the Single is contained within Multi.\r
   Otherwise, EFI_NOT_FOUND is returned.\r
 \r
 --*/\r
@@ -658,7 +714,7 @@ Returns:
   while (DevicePathInst) {\r
     if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
       if (!Delete) {\r
-        gBS->FreePool (DevicePathInst);\r
+        FreePool (DevicePathInst);\r
         return EFI_SUCCESS;\r
       }\r
     } else {\r
@@ -667,12 +723,14 @@ Returns:
                             TempDevicePath1,\r
                             DevicePathInst\r
                             );\r
-        gBS->FreePool (TempDevicePath1);\r
+        if (TempDevicePath1 != NULL) {\r
+          FreePool (TempDevicePath1);\r
+        }\r
         TempDevicePath1 = TempDevicePath2;\r
       }\r
     }\r
 \r
-    gBS->FreePool (DevicePathInst);\r
+    FreePool (DevicePathInst);\r
     DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
   }\r
 \r
@@ -693,7 +751,7 @@ ConPlatformUpdateDeviceVariable (
 /*++\r
 \r
 Routine Description:\r
-  \r
+\r
 \r
 Arguments:\r
 \r
@@ -730,7 +788,9 @@ Returns:
       //\r
       // The device path is already in the variable\r
       //\r
-      gBS->FreePool (VariableDevicePath);\r
+      if (VariableDevicePath != NULL) {\r
+        FreePool (VariableDevicePath);\r
+      }\r
 \r
       return Status;\r
     }\r
@@ -760,7 +820,9 @@ Returns:
               );\r
   }\r
 \r
-  gBS->FreePool (VariableDevicePath);\r
+  if (VariableDevicePath != NULL) {\r
+    FreePool (VariableDevicePath);\r
+  }\r
 \r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -774,7 +836,7 @@ Returns:
                   NewVariableDevicePath\r
                   );\r
 \r
-  gBS->FreePool (NewVariableDevicePath);\r
+  FreePool (NewVariableDevicePath);\r
 \r
   return Status;\r
 }\r