From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi0-x242.google.com (mail-oi0-x242.google.com [IPv6:2607:f8b0:4003:c06::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B7C3621951C84 for ; Tue, 25 Apr 2017 09:36:25 -0700 (PDT) Received: by mail-oi0-x242.google.com with SMTP id w12so7959435oiw.0 for ; Tue, 25 Apr 2017 09:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n4MX3EkGVgiz5wa2Zno4rLVZWKOt5L9fcAF2PD7wb2Y=; b=dD9Kycm38cGyd2eSC6IR3hISdLq8ANL0nY5mnbV+sYMlX9/tZ68Xtx/inmQC9YW55y 6xBwwNhRnIupFir1tQZeZbn5JHiOV/kVh3LFpQxMUVIC0YGBgLcRkjcLaCg94QV1Xbrn eT4b+9X4GhJWN7nuzwhEEx2K4O8Hq6wzrCghuF2tsdH4fyPDjlp8YNWjgpeRkiIyChq6 jGcxtWwLPYKJH23sa736Psme8upqy6tLs05fb3TLokArkGqNd92w2pPRvp1v/chEzpL+ 2W6xIYmC+I/hVJjj4kbWyOfI9mbqmVIt+Mi5ZzSd0nr4ZWUjUra7e/6YYy6hthkXXQ0m i0tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n4MX3EkGVgiz5wa2Zno4rLVZWKOt5L9fcAF2PD7wb2Y=; b=bwpnQ34m1AyF6qTK45xX2a09H2yfIMk1EX9h+f80D3T9bE6PcuNpsAjmtgR4VA2Hzn PSJaDjrvG/hq7YHhnnbKhQ69dp4fnffbMcrDA9UBNMKj+GTjHC0h/1QyiFDVKg4hAg/H 9EiiDpRdrerSzTC3rK6mkxpR4OozTT7zp7e96biCCNEomTWfnMQKgKjCj4r63z0LJXS7 Y1EQotjX2znq6zrl3sKiYbp/vRWA23YjmeXeNDqMHRquwuVaEw8c2oFnx8bS+5sZcina HX0g1LF7EUQlvFn5WBaUqS9jn8oBUnh4HU9OiKQUnt8NjWBu7d7T3XV1rRVGv+aiHt+L P12g== X-Gm-Message-State: AN3rC/6aaKWs4sEuM9fcPg/LPz38nYzXjUOlJlbUWNApcwBbi5aj2osc LurTOyXNDqm5Zg== X-Received: by 10.157.15.210 with SMTP id m18mr2701570otd.210.1493138185099; Tue, 25 Apr 2017 09:36:25 -0700 (PDT) Received: from brijesh-build-machine.amd.com ([165.204.77.1]) by smtp.gmail.com with ESMTPSA id j17sm9666356ota.24.2017.04.25.09.36.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Apr 2017 09:36:24 -0700 (PDT) From: Brijesh Singh 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 Date: Tue, 25 Apr 2017 12:34:23 -0400 Message-Id: <1493138064-7816-15-git-send-email-brijesh.ksingh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493138064-7816-1-git-send-email-brijesh.ksingh@gmail.com> References: <1493138064-7816-1-git-send-email-brijesh.ksingh@gmail.com> Subject: [RFC v3 14/15] OvmfPkg/QemuFwCfgLib: Add SEV support X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Apr 2017 16:36:26 -0000 From: Brijesh Singh 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 --- 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