From: Brijesh Singh <brijesh.ksingh@gmail.com>
To: edk2-devel@lists.01.org, lersek@redhat.com, jordan.l.justen@intel.com
Cc: jiewen.yao@intel.com, leo.duran@amd.com, star.zeng@intel.com,
liming.gao@intel.com, ard.biesheuvel@linaro.org,
brijesh.singh@amd.com, William.Tambe@amd.com,
thomas.lendacky@amd.com
Subject: [RFC v3 14/15] OvmfPkg/QemuFwCfgLib: Add SEV support
Date: Tue, 25 Apr 2017 12:34:23 -0400 [thread overview]
Message-ID: <1493138064-7816-15-git-send-email-brijesh.ksingh@gmail.com> (raw)
In-Reply-To: <1493138064-7816-1-git-send-email-brijesh.ksingh@gmail.com>
From: Brijesh Singh <brijesh.singh@amd.com>
When SEV is enabled, use a bounce buffer to perform the DMA operation.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 54 +++++++++++++++++++-
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
index 73a19772bee1..86d8bf880e71 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c
@@ -72,6 +72,8 @@ InternalQemuFwCfgDmaBytes (
volatile FW_CFG_DMA_ACCESS *Access;
UINT32 AccessHigh, AccessLow;
UINT32 Status;
+ UINT32 NumPages;
+ VOID *DmaBuffer, *BounceBuffer;
ASSERT (Control == FW_CFG_DMA_CTL_WRITE || Control == FW_CFG_DMA_CTL_READ ||
Control == FW_CFG_DMA_CTL_SKIP);
@@ -80,11 +82,44 @@ InternalQemuFwCfgDmaBytes (
return;
}
- Access = &LocalAccess;
+ //
+ // When SEV is enabled then allocate DMA bounce buffer
+ //
+ if (InternalQemuFwCfgSevIsEnabled ()) {
+ UINT32 TotalSize;
+
+ TotalSize = sizeof (*Access);
+ //
+ // Control operation does not need buffer
+ //
+ if (Control != FW_CFG_DMA_CTL_SKIP) {
+ TotalSize += Size;
+ }
+
+ //
+ // Allocate SEV DMA bounce buffer
+ //
+ NumPages = EFI_SIZE_TO_PAGES (TotalSize);
+ InternalQemuFwCfgSevDmaAllocateBuffer (NumPages, &BounceBuffer);
+
+ Access = BounceBuffer;
+ DmaBuffer = BounceBuffer + sizeof (*Access);
+
+ //
+ // Copy data from Host buffer into DMA buffer
+ //
+ if (Buffer && Control == FW_CFG_DMA_CTL_WRITE) {
+ CopyMem (DmaBuffer, Buffer, Size);
+ }
+ } else {
+ Access = &LocalAccess;
+ DmaBuffer = Buffer;
+ BounceBuffer = NULL;
+ }
Access->Control = SwapBytes32 (Control);
Access->Length = SwapBytes32 (Size);
- Access->Address = SwapBytes64 ((UINTN)Buffer);
+ Access->Address = SwapBytes64 ((UINTN)DmaBuffer);
//
// Delimit the transfer from (a) modifications to Access, (b) in case of a
@@ -117,6 +152,21 @@ InternalQemuFwCfgDmaBytes (
// After a read, the caller will want to use Buffer.
//
MemoryFence ();
+
+ //
+ // If Bounce buffer was allocated then copy the data into host buffer and
+ // free the bounce buffer
+ //
+ if (BounceBuffer) {
+ //
+ // Copy data from DMA buffer into host buffer
+ //
+ if (Buffer && Control == FW_CFG_DMA_CTL_READ) {
+ CopyMem (Buffer, DmaBuffer, Size);
+ }
+
+ InternalQemuFwCfgSevDmaFreeBuffer (BounceBuffer, NumPages);
+ }
}
--
2.7.4
next prev parent reply other threads:[~2017-04-25 16:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-25 16:34 [RFC v3 00/15] x86: Secure Encrypted Virtualization (AMD) Brijesh Singh
2017-04-25 16:34 ` [RFC v3 01/15] UefiCpuPkg: Define AMD Memory Encryption specific CPUID and MSR Brijesh Singh
2017-04-25 16:34 ` [RFC v3 02/15] OvmfPkg/ResetVector: Set C-bit when building initial page table Brijesh Singh
2017-04-25 16:34 ` [RFC v3 03/15] OvmfPkg: Update dsc to use IoLib from BaseIoLibIntrinsicSev.inf Brijesh Singh
2017-04-25 16:34 ` [RFC v3 04/15] OvmfPkg/BaseMemcryptSevLib: Add SEV helper library Brijesh Singh
2017-04-25 16:34 ` [RFC v3 05/15] OvmfPkg/PlatformPei: Set memory encryption PCD when SEV is enabled Brijesh Singh
2017-04-25 16:34 ` [RFC v3 06/15] OvmfPkg/DxeBmDmaLib: Import DxeBmDmaLib package Brijesh Singh
2017-04-25 16:34 ` [RFC v3 07/15] OvmfPkg/BmDmaLib: Add SEV support Brijesh Singh
2017-04-25 16:34 ` [RFC v3 08/15] OvmfPkg/QemuFwCfgLib: Provide Pei and Dxe specific library Brijesh Singh
2017-04-25 16:34 ` [RFC v3 09/15] OvmfPkg/QemuFwCfgLib: Prepare for SEV support Brijesh Singh
2017-04-25 16:34 ` [RFC v3 10/15] OvmfPkg/QemuFwCfgLib: Implement SEV internal function for SEC phase Brijesh Singh
2017-04-25 16:34 ` [RFC v3 11/15] OvmfPkg/QemuFwCfgLib: Implement SEV internal functions for PEI phase Brijesh Singh
2017-04-25 16:34 ` [RFC v3 12/15] OvmfPkg/QemuFwCfgLib: Implement SEV internal function for Dxe phase Brijesh Singh
2017-04-25 16:34 ` [RFC v3 13/15] OvmfPkg/QemuFwCfgLib: Add option to dynamic alloc FW_CFG_DMA Access Brijesh Singh
2017-04-25 16:34 ` Brijesh Singh [this message]
2017-04-25 16:34 ` [RFC v3 15/15] OvmfPkg/AmdSevDxe: Add AmdSevDxe driver Brijesh Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1493138064-7816-15-git-send-email-brijesh.ksingh@gmail.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox