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.69806.1584370960020988001 for ; Mon, 16 Mar 2020 08:02:40 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=Og1LMWGT; 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 02GErYVV156629; Mon, 16 Mar 2020 15:02:39 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=OH1HvBk7CngZgVbldHS8J6WJ2+AGQTfeia9gvlYwpl4=; b=Og1LMWGTtG6Fy8NfURjaQ6VHWNdbGUp1ww//PUFhFEroWxel5J5e7eGcFwsCQYA/IuRP aT3AB1yWUgbSUhilmW4A3kugJAsrmKyHck9y6rgWetqVhRKSjSn6BxtBEFvjGmNqbv7e EoCeJHVQVxW7DRzoRSHuUXH56tGwsqYnFkBPILmt7LbLxEJiyseKlhxhuHiUnHed/JOU Ah/Hz84pdtgW9EaMbOjtSyglQol9Iw9J3JnUIHLL2ayy9slx+OLb2n+xe2oqjiOkSgP+ 0b5w1bUX38zfGAh4G+7D2AQUDNZk0oif16sc3ssZ2NTmfRfamrA9Jf/nUOitZl56kWtm pA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2yrqwmyb01-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2020 15:02:39 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02GEqLBa172490; Mon, 16 Mar 2020 15:00:39 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2ys8yvyjnn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2020 15:00:39 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 02GF0cGF009389; Mon, 16 Mar 2020 15:00:38 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 16 Mar 2020 08:00:37 -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 14/17] OvmfPkg/PvScsiDxe: Introduce DMA communication buffer Date: Mon, 16 Mar 2020 17:01:10 +0200 Message-Id: <20200316150113.104630-15-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200316150113.104630-1-liran.alon@oracle.com> References: <20200316150113.104630-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9561 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 bulkscore=0 malwarescore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003160072 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9561 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003160072 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 Reviewed-by: Nikita Leshenko Signed-off-by: Liran Alon --- OvmfPkg/PvScsiDxe/PvScsi.c | 24 ++++++++++++++++++++++++ OvmfPkg/PvScsiDxe/PvScsi.h | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c index c3f5d38f3d30..e48929bf044c 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.c +++ b/OvmfPkg/PvScsiDxe/PvScsi.c @@ -638,6 +638,20 @@ PvScsiInit ( return Status; } + // + // Allocate DMA communication buffer + // + Status = PvScsiAllocateSharedPages ( + Dev, + EFI_SIZE_TO_PAGES (sizeof (*Dev->DmaBuf)), + EfiPciIoOperationBusMasterCommonBuffer, + (VOID **)&Dev->DmaBuf, + &Dev->DmaBufDmaDesc + ); + if (EFI_ERROR (Status)) { + return Status; + } + // // Populate the exported interface's attributes // @@ -676,6 +690,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 + ); + // // Free PVSCSI rings // 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