OvmfPkg/PvScsiDxe: Introduce DMA communication buffer

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 <liran.alon@oracle.com>
Message-Id: <20200328200100.60786-15-liran.alon@oracle.com>
Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Liran Alon
2020-03-28 23:00:57 +03:00
committed by mergify[bot]
parent b654edec03
commit 6510e19794
2 changed files with 58 additions and 2 deletions

View File

@@ -677,6 +677,19 @@ PvScsiInit (
goto RestorePciAttributes;
}
//
// Allocate DMA communication buffer
//
Status = PvScsiAllocateSharedPages (
Dev,
EFI_SIZE_TO_PAGES (sizeof (*Dev->DmaBuf)),
(VOID **)&Dev->DmaBuf,
&Dev->DmaBufDmaDesc
);
if (EFI_ERROR (Status)) {
goto FreeRings;
}
//
// Populate the exported interface's attributes
//
@@ -708,6 +721,15 @@ PvScsiInit (
return EFI_SUCCESS;
FreeRings:
//
// Reset device to stop device usage of the rings.
// This is required to safely free the rings.
//
PvScsiResetAdapter (Dev);
PvScsiFreeRings (Dev);
RestorePciAttributes:
PvScsiRestorePciAttributes (Dev);
@@ -721,11 +743,25 @@ PvScsiUninit (
)
{
//
// Reset device to stop device usage of the rings.
// This is required to safely free the rings.
// Reset device to:
// - Make device stop processing all requests.
// - Stop device usage of the rings.
//
// This is required to safely free the DMA communication buffer
// and the rings.
//
PvScsiResetAdapter (Dev);
//
// Free DMA communication buffer
//
PvScsiFreeSharedPages (
Dev,
EFI_SIZE_TO_PAGES (sizeof (*Dev->DmaBuf)),
Dev->DmaBuf,
&Dev->DmaBufDmaDesc
);
PvScsiFreeRings (Dev);
PvScsiRestorePciAttributes (Dev);