OvmfPkg/MptScsiDxe: Reset device on ExitBootServices()
[mirror_edk2.git] / OvmfPkg / MptScsiDxe / MptScsi.c
index 8be38f6..9ed1831 100644 (file)
@@ -59,6 +59,7 @@ typedef struct {
   UINT32                          StallPerPollUsec;\r
   EFI_PCI_IO_PROTOCOL             *PciIo;\r
   UINT64                          OriginalPciAttributes;\r
+  EFI_EVENT                       ExitBoot;\r
   MPT_SCSI_DMA_BUFFER             *Dma;\r
   EFI_PHYSICAL_ADDRESS            DmaPhysical;\r
   VOID                            *DmaMapping;\r
@@ -762,6 +763,20 @@ MptScsiResetChannel (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+STATIC\r
+VOID\r
+EFIAPI\r
+MptScsiExitBoot (\r
+  IN  EFI_EVENT Event,\r
+  IN  VOID      *Context\r
+  )\r
+{\r
+  MPT_SCSI_DEV *Dev;\r
+\r
+  Dev = Context;\r
+  DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context));\r
+  MptScsiReset (Dev);\r
+}\r
 STATIC\r
 EFI_STATUS\r
 EFIAPI\r
@@ -955,6 +970,17 @@ MptScsiControllerStart (
     goto Unmap;\r
   }\r
 \r
+  Status = gBS->CreateEvent (\r
+                  EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
+                  TPL_CALLBACK,\r
+                  &MptScsiExitBoot,\r
+                  Dev,\r
+                  &Dev->ExitBoot\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto UninitDev;\r
+  }\r
+\r
   //\r
   // Host adapter channel, doesn't exist\r
   //\r
@@ -979,11 +1005,14 @@ MptScsiControllerStart (
                   &Dev->PassThru\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto UninitDev;\r
+    goto CloseExitBoot;\r
   }\r
 \r
   return EFI_SUCCESS;\r
 \r
+CloseExitBoot:\r
+  gBS->CloseEvent (Dev->ExitBoot);\r
+\r
 UninitDev:\r
   MptScsiReset (Dev);\r
 \r
@@ -1059,6 +1088,8 @@ MptScsiControllerStop (
     return Status;\r
   }\r
 \r
+  gBS->CloseEvent (Dev->ExitBoot);\r
+\r
   MptScsiReset (Dev);\r
 \r
   Dev->PciIo->Unmap (\r