[edk2-devel] [PATCH v2 10/13] OvmfPkg/MptScsiDxe: Set and restore PCI attributes
Nikita Leshenko
nikita.leshchenko at oracle.com
Wed Feb 26 16:41:48 UTC 2020
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
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Nikita Leshenko <nikita.leshchenko at oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk at oracle.com>
Reviewed-by: Aaron Young <aaron.young at oracle.com>
Reviewed-by: Liran Alon <liran.alon at oracle.com>
---
OvmfPkg/MptScsiDxe/MptScsi.c | 44 ++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c
index 22001da763..f5f774e431 100644
--- a/OvmfPkg/MptScsiDxe/MptScsi.c
+++ b/OvmfPkg/MptScsiDxe/MptScsi.c
@@ -41,6 +41,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) \
@@ -263,6 +264,7 @@ MptScsiControllerStart (
{
EFI_STATUS Status;
MPT_SCSI_DEV *Dev;
+ BOOLEAN PciAttributesChanged;
Dev = AllocateZeroPool (sizeof (*Dev));
if (Dev == NULL) {
@@ -270,6 +272,7 @@ MptScsiControllerStart (
}
Dev->Signature = MPT_SCSI_DEV_SIGNATURE;
+ PciAttributesChanged = FALSE;
Status = gBS->OpenProtocol (
ControllerHandle,
@@ -283,6 +286,31 @@ 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;
+
//
// Host adapter channel, doesn't exist
//
@@ -312,6 +340,15 @@ MptScsiControllerStart (
Done:
if (EFI_ERROR (Status)) {
+ if (PciAttributesChanged) {
+ Dev->PciIo->Attributes (
+ Dev->PciIo,
+ EfiPciIoAttributeOperationEnable,
+ Dev->OriginalPciAttributes,
+ NULL
+ );
+ }
+
if (Dev->PciIo) {
gBS->CloseProtocol (
ControllerHandle,
@@ -361,6 +398,13 @@ MptScsiControllerStop (
&Dev->PassThru
);
+ Dev->PciIo->Attributes (
+ Dev->PciIo,
+ EfiPciIoAttributeOperationEnable,
+ Dev->OriginalPciAttributes,
+ NULL
+ );
+
gBS->CloseProtocol (
ControllerHandle,
&gEfiPciIoProtocolGuid,
--
2.20.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#54909): https://edk2.groups.io/g/devel/message/54909
Mute This Topic: https://groups.io/mt/71570010/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list