]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/MptScsiDxe: Set and restore PCI attributes
authorNikita Leshenko <nikita.leshchenko@oracle.com>
Mon, 4 May 2020 21:06:04 +0000 (00:06 +0300)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 5 May 2020 20:43:02 +0000 (20:43 +0000)
Enable the IO Space and Bus Mastering and restore the original values
when the device is stopped. This is a standard procedure in PCI
drivers.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20200504210607.144434-10-nikita.leshchenko@oracle.com>

OvmfPkg/MptScsiDxe/MptScsi.c

index 3dfc78cf2e1f3a98d59e5a7f6411f8e3317d11da..289bd9fc372bccb9b760805e4ac288bc722ec31e 100644 (file)
@@ -38,6 +38,7 @@ typedef struct {
   EFI_EXT_SCSI_PASS_THRU_MODE     PassThruMode;\r
   UINT8                           MaxTarget;\r
   EFI_PCI_IO_PROTOCOL             *PciIo;\r
+  UINT64                          OriginalPciAttributes;\r
 } MPT_SCSI_DEV;\r
 \r
 #define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \\r
@@ -335,6 +336,53 @@ MptScsiControllerStart (
     goto FreePool;\r
   }\r
 \r
+  Status = Dev->PciIo->Attributes (\r
+                         Dev->PciIo,\r
+                         EfiPciIoAttributeOperationGet,\r
+                         0,\r
+                         &Dev->OriginalPciAttributes\r
+                         );\r
+  if (EFI_ERROR (Status)) {\r
+    goto CloseProtocol;\r
+  }\r
+\r
+  //\r
+  // Enable I/O Space & Bus-Mastering\r
+  //\r
+  Status = Dev->PciIo->Attributes (\r
+                         Dev->PciIo,\r
+                         EfiPciIoAttributeOperationEnable,\r
+                         (EFI_PCI_IO_ATTRIBUTE_IO |\r
+                          EFI_PCI_IO_ATTRIBUTE_BUS_MASTER),\r
+                         NULL\r
+                         );\r
+  if (EFI_ERROR (Status)) {\r
+    goto CloseProtocol;\r
+  }\r
+\r
+  //\r
+  // Signal device supports 64-bit DMA addresses\r
+  //\r
+  Status = Dev->PciIo->Attributes (\r
+                         Dev->PciIo,\r
+                         EfiPciIoAttributeOperationEnable,\r
+                         EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE,\r
+                         NULL\r
+                         );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Warn user that device will only be using 32-bit DMA addresses.\r
+    //\r
+    // Note that this does not prevent the device/driver from working\r
+    // and therefore we only warn and continue as usual.\r
+    //\r
+    DEBUG ((\r
+      DEBUG_WARN,\r
+      "%a: failed to enable 64-bit DMA addresses\n",\r
+      __FUNCTION__\r
+      ));\r
+  }\r
+\r
   //\r
   // Host adapter channel, doesn't exist\r
   //\r
@@ -359,11 +407,19 @@ MptScsiControllerStart (
                   &Dev->PassThru\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto CloseProtocol;\r
+    goto RestoreAttributes;\r
   }\r
 \r
   return EFI_SUCCESS;\r
 \r
+RestoreAttributes:\r
+  Dev->PciIo->Attributes (\r
+                Dev->PciIo,\r
+                EfiPciIoAttributeOperationSet,\r
+                Dev->OriginalPciAttributes,\r
+                NULL\r
+                );\r
+\r
 CloseProtocol:\r
   gBS->CloseProtocol (\r
          ControllerHandle,\r
@@ -415,6 +471,13 @@ MptScsiControllerStop (
     return Status;\r
   }\r
 \r
+  Dev->PciIo->Attributes (\r
+                Dev->PciIo,\r
+                EfiPciIoAttributeOperationSet,\r
+                Dev->OriginalPciAttributes,\r
+                NULL\r
+                );\r
+\r
   gBS->CloseProtocol (\r
          ControllerHandle,\r
          &gEfiPciIoProtocolGuid,\r