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.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshche...@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.w...@oracle.com>
Reviewed-by: Aaron Young <aaron.yo...@oracle.com>
Reviewed-by: Liran Alon <liran.a...@oracle.com>
---
 OvmfPkg/MptScsiDxe/MptScsi.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 29816fb98c..92c190499e 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -43,6 +43,7 @@ typedef struct {
   EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru;
   EFI_EXT_SCSI_PASS_THRU_MODE     PassThruMode;
   EFI_PCI_IO_PROTOCOL             *PciIo;
+  UINT64                          OriginalPciAttributes;
 } MPT_SCSI_DEV;
 
 #define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \
@@ -269,6 +270,7 @@ MptScsiControllerStart (
   EFI_STATUS           Status;
   EFI_PHYSICAL_ADDRESS PhysicalAddress;
   MPT_SCSI_DEV         *Dev;
+  BOOLEAN              PciAttributesChanged = FALSE;
 
   DEBUG ((EFI_D_INFO, "Starting MptScsi\n"));
 
@@ -307,6 +309,25 @@ MptScsiControllerStart (
     goto Done;
   }
 
+  Status = Dev->PciIo->Attributes (
+                  Dev->PciIo,
+                  EfiPciIoAttributeOperationGet, 0,
+                  &Dev->OriginalPciAttributes);
+  if (EFI_ERROR (Status)) {
+    goto Done;
+  }
+
+  // Enable I/O Space & Bus-Mastering
+  Status = Dev->PciIo->Attributes (
+                  Dev->PciIo,
+                  EfiPciIoAttributeOperationEnable,
+                  EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER,
+                  NULL);
+  if (EFI_ERROR (Status)) {
+    goto Done;
+  }
+  PciAttributesChanged = TRUE;
+
   Dev->PassThruMode.AdapterId = MAX_UINT32; // Host adapter channel, doesn't 
exist
   Dev->PassThruMode.Attributes =
     EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL
@@ -332,6 +353,13 @@ MptScsiControllerStart (
   DEBUG ((EFI_D_INFO, "MptScsi Installed\n"));
 Done:
   if (EFI_ERROR (Status)) {
+    if (PciAttributesChanged) {
+      Dev->PciIo->Attributes (
+                      Dev->PciIo,
+                      EfiPciIoAttributeOperationEnable,
+                      Dev->OriginalPciAttributes,
+                      NULL);
+    }
     if (Dev->PciIo) {
       gBS->CloseProtocol (
                       ControllerHandle,
@@ -378,6 +406,13 @@ MptScsiControllerStop (
                   ControllerHandle,
                   &gEfiExtScsiPassThruProtocolGuid,
                   &Dev->PassThru);
+
+  Dev->PciIo->Attributes (
+                  Dev->PciIo,
+                  EfiPciIoAttributeOperationEnable,
+                  Dev->OriginalPciAttributes,
+                  NULL);
+
   gBS->CloseProtocol (
                   ControllerHandle,
                   &gEfiPciIoProtocolGuid,
-- 
2.20.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to