]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/LsiScsiDxe/LsiScsi.c
OvmfPkg/LsiScsiDxe: Map DMA buffer
[mirror_edk2.git] / OvmfPkg / LsiScsiDxe / LsiScsi.c
index a9c107c04ef18d848a07284110b52567f54acd44..52c224aad9a5ac0380275000100034bd22816f9e 100644 (file)
@@ -356,6 +356,8 @@ LsiScsiControllerStart (
 {\r
   EFI_STATUS           Status;\r
   LSI_SCSI_DEV         *Dev;\r
+  UINTN                Pages;\r
+  UINTN                BytesMapped;\r
 \r
   Dev = AllocateZeroPool (sizeof (*Dev));\r
   if (Dev == NULL) {\r
@@ -411,11 +413,45 @@ LsiScsiControllerStart (
     goto CloseProtocol;\r
   }\r
 \r
-  Status = LsiScsiReset (Dev);\r
+  //\r
+  // Create buffers for data transfer\r
+  //\r
+  Pages = EFI_SIZE_TO_PAGES (sizeof (*Dev->Dma));\r
+  Status = Dev->PciIo->AllocateBuffer (\r
+                         Dev->PciIo,\r
+                         AllocateAnyPages,\r
+                         EfiBootServicesData,\r
+                         Pages,\r
+                         (VOID **)&Dev->Dma,\r
+                         EFI_PCI_ATTRIBUTE_MEMORY_CACHED\r
+                         );\r
   if (EFI_ERROR (Status)) {\r
     goto RestoreAttributes;\r
   }\r
 \r
+  BytesMapped = EFI_PAGES_TO_SIZE (Pages);\r
+  Status = Dev->PciIo->Map (\r
+                         Dev->PciIo,\r
+                         EfiPciIoOperationBusMasterCommonBuffer,\r
+                         Dev->Dma,\r
+                         &BytesMapped,\r
+                         &Dev->DmaPhysical,\r
+                         &Dev->DmaMapping\r
+                         );\r
+  if (EFI_ERROR (Status)) {\r
+    goto FreeBuffer;\r
+  }\r
+\r
+  if (BytesMapped != EFI_PAGES_TO_SIZE (Pages)) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Unmap;\r
+  }\r
+\r
+  Status = LsiScsiReset (Dev);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Unmap;\r
+  }\r
+\r
   Status = gBS->CreateEvent (\r
                   EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
                   TPL_CALLBACK,\r
@@ -462,6 +498,19 @@ CloseExitBoot:
 UninitDev:\r
   LsiScsiReset (Dev);\r
 \r
+Unmap:\r
+  Dev->PciIo->Unmap (\r
+                Dev->PciIo,\r
+                Dev->DmaMapping\r
+                );\r
+\r
+FreeBuffer:\r
+  Dev->PciIo->FreeBuffer (\r
+                Dev->PciIo,\r
+                Pages,\r
+                Dev->Dma\r
+                );\r
+\r
 RestoreAttributes:\r
   Dev->PciIo->Attributes (\r
                 Dev->PciIo,\r
@@ -524,6 +573,17 @@ LsiScsiControllerStop (
 \r
   LsiScsiReset (Dev);\r
 \r
+  Dev->PciIo->Unmap (\r
+                Dev->PciIo,\r
+                Dev->DmaMapping\r
+                );\r
+\r
+  Dev->PciIo->FreeBuffer (\r
+                Dev->PciIo,\r
+                EFI_SIZE_TO_PAGES (sizeof (*Dev->Dma)),\r
+                Dev->Dma\r
+                );\r
+\r
   Dev->PciIo->Attributes (\r
                 Dev->PciIo,\r
                 EfiPciIoAttributeOperationSet,\r