]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/EnhancedFatDxe/Fat.c
PcAtChipsetPkg/PcRtc: Handle NULL table entry in RSDT/XSDT
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Fat.c
index 38b70882c5c5ca796af0216c9437e1ca9512030e..2080005adc95321806ee03708a3883b4bce5d628 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
 distribution. The full text of the license may be found at\r
@@ -140,6 +140,8 @@ Returns:
   EFI_HANDLE  *DeviceHandleBuffer;\r
   UINTN       DeviceHandleCount;\r
   UINTN       Index;\r
+  VOID        *ComponentName;\r
+  VOID        *ComponentName2;\r
 \r
   Status = gBS->LocateHandleBuffer (\r
                   AllHandles,\r
@@ -148,20 +150,77 @@ Returns:
                   &DeviceHandleCount,\r
                   &DeviceHandleBuffer\r
                   );\r
-  if (!EFI_ERROR (Status)) {\r
-    for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+    Status = EfiTestManagedDevice (DeviceHandleBuffer[Index], ImageHandle, &gEfiDiskIoProtocolGuid);\r
+    if (!EFI_ERROR (Status)) {\r
       Status = gBS->DisconnectController (\r
                       DeviceHandleBuffer[Index],\r
                       ImageHandle,\r
                       NULL\r
                       );\r
+      if (EFI_ERROR (Status)) {\r
+        break;\r
+      }\r
     }\r
+  }\r
 \r
-    if (DeviceHandleBuffer != NULL) {\r
-      FreePool (DeviceHandleBuffer);\r
+  if (Index == DeviceHandleCount) {\r
+    //\r
+    // Driver is stopped successfully.\r
+    //\r
+    Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, &ComponentName);\r
+    if (EFI_ERROR (Status)) {\r
+      ComponentName = NULL;\r
+    }\r
+\r
+    Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentName2ProtocolGuid, &ComponentName2);\r
+    if (EFI_ERROR (Status)) {\r
+      ComponentName2 = NULL;\r
+    }\r
+\r
+    if (ComponentName == NULL) {\r
+      if (ComponentName2 == NULL) {\r
+        Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                        ImageHandle,\r
+                        &gEfiDriverBindingProtocolGuid,  &gFatDriverBinding,\r
+                        NULL\r
+                        );\r
+      } else {\r
+        Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                        ImageHandle,\r
+                        &gEfiDriverBindingProtocolGuid,  &gFatDriverBinding,\r
+                        &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+                        NULL\r
+                        );\r
+      }\r
+    } else {\r
+      if (ComponentName2 == NULL) {\r
+        Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                        ImageHandle,\r
+                        &gEfiDriverBindingProtocolGuid,  &gFatDriverBinding,\r
+                        &gEfiComponentNameProtocolGuid,  ComponentName,\r
+                        NULL\r
+                        );\r
+      } else {\r
+        Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                        ImageHandle,\r
+                        &gEfiDriverBindingProtocolGuid,  &gFatDriverBinding,\r
+                        &gEfiComponentNameProtocolGuid,  ComponentName,\r
+                        &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+                        NULL\r
+                        );\r
+      }\r
     }\r
   }\r
 \r
+  if (DeviceHandleBuffer != NULL) {\r
+    FreePool (DeviceHandleBuffer);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -269,6 +328,7 @@ Returns:
   EFI_STATUS            Status;\r
   EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
   EFI_DISK_IO_PROTOCOL  *DiskIo;\r
+  EFI_DISK_IO2_PROTOCOL *DiskIo2;\r
   BOOLEAN               LockedByMe;\r
 \r
   LockedByMe = FALSE;\r
@@ -311,11 +371,24 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     goto Exit;\r
   }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDiskIo2ProtocolGuid,\r
+                  (VOID **) &DiskIo2,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DiskIo2 = NULL;\r
+  }\r
+\r
   //\r
   // Allocate Volume structure. In FatAllocateVolume(), Resources\r
   // are allocated with protocol installed and cached initialized\r
   //\r
-  Status = FatAllocateVolume (ControllerHandle, DiskIo, BlockIo);\r
+  Status = FatAllocateVolume (ControllerHandle, DiskIo, DiskIo2, BlockIo);\r
 \r
   //\r
   // When the media changes on a device it will Reinstall the BlockIo interaface.\r
@@ -338,6 +411,12 @@ Returns:
              This->DriverBindingHandle,\r
              ControllerHandle\r
              );\r
+      gBS->CloseProtocol (\r
+             ControllerHandle,\r
+             &gEfiDiskIo2ProtocolGuid,\r
+             This->DriverBindingHandle,\r
+             ControllerHandle\r
+             );\r
     }\r
   }\r
 \r
@@ -379,7 +458,9 @@ Returns:
   EFI_STATUS                      Status;\r
   EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;\r
   FAT_VOLUME                      *Volume;\r
+  EFI_DISK_IO2_PROTOCOL           *DiskIo2;\r
 \r
+  DiskIo2 = NULL;\r
   //\r
   // Get our context back\r
   //\r
@@ -393,19 +474,29 @@ Returns:
                   );\r
 \r
   if (!EFI_ERROR (Status)) {\r
-    Volume = VOLUME_FROM_VOL_INTERFACE (FileSystem);\r
-    Status = FatAbandonVolume (Volume);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
+    Volume  = VOLUME_FROM_VOL_INTERFACE (FileSystem);\r
+    DiskIo2 = Volume->DiskIo2;\r
+    Status  = FatAbandonVolume (Volume);\r
   }\r
 \r
-  Status = gBS->CloseProtocol (\r
-                  ControllerHandle,\r
-                  &gEfiDiskIoProtocolGuid,\r
-                  This->DriverBindingHandle,\r
-                  ControllerHandle\r
-                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    if (DiskIo2 != NULL) {\r
+      Status = gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiDiskIo2ProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+    Status = gBS->CloseProtocol (\r
+      ControllerHandle,\r
+      &gEfiDiskIoProtocolGuid,\r
+      This->DriverBindingHandle,\r
+      ControllerHandle\r
+      );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 \r
   return Status;\r
 }\r