From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by mx.groups.io with SMTP id smtpd.web11.15228.1585152488697715593 for ; Wed, 25 Mar 2020 09:08:08 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=azrN2yDj; spf=pass (domain: oracle.com, ip: 156.151.31.85, mailfrom: liran.alon@oracle.com) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02PG4JKu133152; Wed, 25 Mar 2020 16:08:08 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=CwkRNjiuZN34BBhiTiPt0kJlFyA4IIVd4hrtYOFgJyM=; b=azrN2yDjUvU0Xi8RjlQLPMdQfRNUQK506jsaTLE3uLKGn84UD1A41IgGGYrVJakhLhvz nmbetC0oLEa49+E+ur//iT5oO93RCeH65t+OPtiye02djLo8lUrV6cdGPIkjTmuIk6aG FbMg8OSQBFd055GVtcbvbNY+S1WJQ20X0YytUljtv4nZhFNJktDpMpfl3Okq98cZyWzY IcUb6zxUiMvJqb4UMq5YFNALe3OfidbGR4EB1tJA0lq81bvUFJgU5pzoohsNeA22YUMv 7Cf9dTM1dDlrOxRmhN1ulYi0gMrYAh90OjRfmMb2eAIHCY2BTuuWQueGB2oX6B2hdeke iA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 3005kv9pj7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Mar 2020 16:08:08 +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 02PG6bRk033946; Wed, 25 Mar 2020 16:08:07 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 30073ahtgc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Mar 2020 16:08:07 +0000 Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 02PG87al011925; Wed, 25 Mar 2020 16:08:07 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 25 Mar 2020 09:08:06 -0700 From: "Liran Alon" To: devel@edk2.groups.io, lersek@redhat.com Cc: nikita.leshchenko@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, ard.biesheuvel@linaro.org, Liran Alon Subject: [PATCH v2 14/17] OvmfPkg/PvScsiDxe: Introduce DMA communication buffer Date: Wed, 25 Mar 2020 18:10:02 +0200 Message-Id: <20200325161005.16743-15-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200325161005.16743-1-liran.alon@oracle.com> References: <20200325161005.16743-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9571 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003250129 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9571 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 impostorscore=0 spamscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003250128 Content-Transfer-Encoding: 8bit In case device is constrained by IOMMU or guest is running under AMD SEV, input/output buffers provided to device (DataBuffer and SenseData) needs to be explicitly mapped to device by PciIo->Map(). To avoid the overhead of mapping/unmapping the DataBuffer and SenseData to the device for every SCSI requst (And to simplify code), introduce a single DMA communication buffer that will be mapped to device on initialization. When a SCSI request needs to be sent to device, the DataBuffer and SenseData will be copied from/to the DMA communication buffer as required. This will be done by the following commits. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2567 Signed-off-by: Liran Alon --- OvmfPkg/PvScsiDxe/PvScsi.c | 27 +++++++++++++++++++++++++++ OvmfPkg/PvScsiDxe/PvScsi.h | 10 ++++++++++ 2 files changed, 37 insertions(+) diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c index 59863f83c60c..928984099520 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.c +++ b/OvmfPkg/PvScsiDxe/PvScsi.c @@ -710,6 +710,20 @@ PvScsiInit ( goto RestorePciAttributes; } + // + // Allocate DMA communication buffer + // + Status = PvScsiAllocateSharedPages ( + Dev, + EFI_SIZE_TO_PAGES (sizeof (*Dev->DmaBuf)), + EfiPciIoOperationBusMasterCommonBuffer, + (VOID **)&Dev->DmaBuf, + &Dev->DmaBufDmaDesc + ); + if (EFI_ERROR (Status)) { + goto FreeRings; + } + // // Populate the exported interface's attributes // @@ -741,6 +755,9 @@ PvScsiInit ( return EFI_SUCCESS; +FreeRings: + PvScsiFreeRings (Dev); + RestorePciAttributes: PvScsiRestorePciAttributes (Dev); @@ -753,6 +770,16 @@ PvScsiUninit ( IN OUT PVSCSI_DEV *Dev ) { + // + // Free DMA communication buffer + // + PvScsiFreeSharedPages ( + Dev, + EFI_SIZE_TO_PAGES (sizeof (*Dev->DmaBuf)), + (VOID **)&Dev->DmaBuf, + &Dev->DmaBufDmaDesc + ); + PvScsiFreeRings (Dev); PvScsiRestorePciAttributes (Dev); diff --git a/OvmfPkg/PvScsiDxe/PvScsi.h b/OvmfPkg/PvScsiDxe/PvScsi.h index 6d23b6e1eccf..7f91d70fec79 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.h +++ b/OvmfPkg/PvScsiDxe/PvScsi.h @@ -31,6 +31,11 @@ typedef struct { PVSCSI_DMA_DESC RingCmpsDmaDesc; } PVSCSI_RING_DESC; +typedef struct { + UINT8 SenseData[MAX_UINT8]; + UINT8 Data[0x2000]; +} PVSCSI_DMA_BUFFER; + #define PVSCSI_SIG SIGNATURE_32 ('P', 'S', 'C', 'S') typedef struct { @@ -38,6 +43,8 @@ typedef struct { EFI_PCI_IO_PROTOCOL *PciIo; UINT64 OriginalPciAttributes; PVSCSI_RING_DESC RingDesc; + PVSCSI_DMA_BUFFER *DmaBuf; + PVSCSI_DMA_DESC DmaBufDmaDesc; UINT8 MaxTarget; UINT8 MaxLun; EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; @@ -47,4 +54,7 @@ typedef struct { #define PVSCSI_FROM_PASS_THRU(PassThruPointer) \ CR (PassThruPointer, PVSCSI_DEV, PassThru, PVSCSI_SIG) +#define PVSCSI_DMA_BUF_DEV_ADDR(Dev, MemberName) \ + (Dev->DmaBufDmaDesc.DeviceAddress + OFFSET_OF(PVSCSI_DMA_BUFFER, MemberName)) + #endif // __PVSCSI_DXE_H_ -- 2.20.1