]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/I2c/I2cDxe/I2cBus.c
If the driver does not start before, we do not disconnect driver and we must still...
[mirror_edk2.git] / MdeModulePkg / Bus / I2c / I2cDxe / I2cBus.c
index 3da1474edc009c8957d65a96ba708ee4c4d7369e..c9913c07ca522e5416c5398013c33c185e1569aa 100644 (file)
@@ -2,7 +2,7 @@
   This file implements I2C IO Protocol which enables the user to manipulate a single \r
   I2C device independent of the host controller and I2C design.\r
 \r
-  Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2013 - 2014, 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
@@ -1408,6 +1408,8 @@ I2cBusUnload (
   EFI_HANDLE                        *DeviceHandleBuffer;\r
   UINTN                             DeviceHandleCount;\r
   UINTN                             Index;\r
+  EFI_COMPONENT_NAME_PROTOCOL       *ComponentName;\r
+  EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;\r
 \r
   //\r
   // Get the list of all I2C Controller handles in the handle database.\r
@@ -1422,22 +1424,20 @@ I2cBusUnload (
                   &DeviceHandleBuffer\r
                   );\r
 \r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Disconnect the driver specified by Driver BindingHandle from all\r
-  // the devices in the handle database.\r
-  //\r
-  for (Index = 0; Index < DeviceHandleCount; Index++) {\r
-    Status = gBS->DisconnectController (\r
-                    DeviceHandleBuffer[Index],\r
-                    gI2cBusDriverBinding.DriverBindingHandle,\r
-                    NULL\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      goto Done;\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Disconnect the driver specified by Driver BindingHandle from all\r
+    // the devices in the handle database.\r
+    //\r
+    for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+      Status = gBS->DisconnectController (\r
+                      DeviceHandleBuffer[Index],\r
+                      gI2cBusDriverBinding.DriverBindingHandle,\r
+                      NULL\r
+                      );\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
     }\r
   }\r
 \r
@@ -1448,14 +1448,47 @@ I2cBusUnload (
                   gI2cBusDriverBinding.DriverBindingHandle,\r
                   &gEfiDriverBindingProtocolGuid,\r
                   &gI2cBusDriverBinding,\r
-                  &gEfiComponentNameProtocolGuid,\r
-                  &gI2cBusComponentName,\r
-                  &gEfiComponentName2ProtocolGuid,\r
-                  &gI2cBusComponentName2,\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Note we have to one by one uninstall the following protocols.\r
+  // It's because some of them are optionally installed based on\r
+  // the following PCD settings.\r
+  //   gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable\r
+  //   gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable\r
+  //   gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable\r
+  //   gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+                  gI2cBusDriverBinding.DriverBindingHandle,\r
+                  &gEfiComponentNameProtocolGuid,\r
+                  (VOID **) &ComponentName\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->UninstallProtocolInterface (\r
+           gI2cBusDriverBinding.DriverBindingHandle,\r
+           &gEfiComponentNameProtocolGuid,\r
+           ComponentName\r
+           );\r
+  }\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  gI2cBusDriverBinding.DriverBindingHandle,\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  (VOID **) &ComponentName2\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->UninstallProtocolInterface (\r
+           gI2cBusDriverBinding.DriverBindingHandle,\r
+           &gEfiComponentName2ProtocolGuid,\r
+           ComponentName2\r
+           );\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
 Done:\r
   //\r
   // Free the buffer containing the list of handles from the handle database\r