From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web12.10856.1582735243652730726 for ; Wed, 26 Feb 2020 08:40:43 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=BOiuWdZI; spf=pass (domain: oracle.com, ip: 141.146.126.78, mailfrom: nikita.leshchenko@oracle.com) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01QGNlCx060221; Wed, 26 Feb 2020 16:40:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=J59setnadx2WhEVQBhOxsw+rsPqKpHvLrik/DRDeisI=; b=BOiuWdZIJUWDlGkh9F5DiO+loX50GqBS9FJGglis14UaJBSAcAVvdg+THO+A1+b6adhg tt/d/X5WFZrMFSHYk0JNUFpftDaPnQXsYVZqQvvc6R3c1ZD8MwplE3VQ9cPR9z3EpUBK A5IhSKId1XI1HGonL3KPYcx2k1FgotwxURwmIZKbgSQ0foiqOa+x9CWpmIuD+ymVyLSk ztyu9BW1MhNyzrYSYdNDbhbGY6Y7SvSD4R3YwR9tWJftvPrGqI8l+B96XR05OYZ/UkF6 diIIAS3KW45/zOMBbvtoy4l/tHKER6F2muvrnrZhjlE2V2rpq1yJJixzblz+qGAw8tK7 uQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2ydcsrmwab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Feb 2020 16:40:43 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01QGMHd6015528; Wed, 26 Feb 2020 16:40:42 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2ydcs5ffyd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Feb 2020 16:40:42 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01QGefNP013199; Wed, 26 Feb 2020 16:40:41 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 26 Feb 2020 08:40:41 -0800 From: "Nikita Leshenko" To: devel@edk2.groups.io Cc: liran.alon@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, lersek@redhat.com, ard.biesheuvel@linaro.org, Nikita Leshenko Subject: [PATCH v2 10/13] OvmfPkg/MptScsiDxe: Set and restore PCI attributes Date: Wed, 26 Feb 2020 18:41:48 +0200 Message-Id: <20200226164151.125182-11-nikita.leshchenko@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200226164151.125182-1-nikita.leshchenko@oracle.com> References: <20200226164151.125182-1-nikita.leshchenko@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9543 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002260112 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9543 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 suspectscore=0 bulkscore=0 malwarescore=0 spamscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002260112 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Aaron Young Reviewed-by: Liran Alon --- 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