From nobody Sun Dec 29 03:39:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; dkim=fail spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1494454222762365.6666830331445; Wed, 10 May 2017 15:10:22 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C1E5E21A16E48; Wed, 10 May 2017 15:09:57 -0700 (PDT) Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0608.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe4a::608]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B659A21A16E40 for ; Wed, 10 May 2017 15:09:54 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by CY1PR12MB0149.namprd12.prod.outlook.com (10.161.173.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1075.11; Wed, 10 May 2017 22:09:53 +0000 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=e/QD1Ha4VJF3nMAPhTrZWX6ZBFd3ZswQT1OEbCmYUc0=; b=Fdj00GtBSKcvbGgHSd6MIpg3fgYF1sURUHeETJdP7S/iOW7gbwoOz4CeIFfZ2UGzb5rWN5C9INmUWlrI8jSMbNjLYxz+1YP3Trt4MgnZBLUlm+NxcSBMFMC95ggrtt5NFBCYgcPqNRjEXnPwVNC2HOE5wWSKKI3rW/G3y/jfdKQ= Authentication-Results: lists.01.org; dkim=none (message not signed) header.d=none;lists.01.org; dmarc=none action=none header.from=amd.com; From: Brijesh Singh To: Date: Wed, 10 May 2017 18:09:22 -0400 Message-ID: <1494454162-9940-14-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494454162-9940-1-git-send-email-brijesh.singh@amd.com> References: <1494454162-9940-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR21CA0051.namprd21.prod.outlook.com (10.172.93.141) To CY1PR12MB0149.namprd12.prod.outlook.com (10.161.173.19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 814994a0-efad-45cd-f14a-08d497f14935 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:CY1PR12MB0149; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0149; 3:eW41r1kyVmb7aWP+8Pf8+0Qb6ssZIVwo2RjkDSpmnQqAZbs2H952MFc4T/M/1HBgY10K7/xORDv1Ji+i0BPf7ChUvSUjHW1zhBFRvQyydkVM1cMx0OluGwZqS63TOmTJZlLyHcvI3oDnO7BulG/GMPpuAcs8BNapLqaez/wDV77z/8+CYhOPMIfvpxi4Ml2g9ocFZv4YV1GtPite5p7DeaZ68BBAuzD3miytoHWpQ8aryDJeJT3bW0Zakvz9mVycKZBeZ07FPO2yA08UXbO+K8YHv6AVhfw+fPElLaBvZqCShwgI1xXsjx0TJzJm+zwqWKMllU2wgQ3MvvxXmHaGF9oQVaEkFmXd3vRSBerBAi8=; 25:2d3Y65Jjj2hnkf/KP7au52Y7Jqx8XhCHu0GzyI/2h1EgdRXRFEiXmCDjdxXeVg1oZYE00XjkG/uwzM65GKXDKHMc4FSvUI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S/D+ltzbKhET9VT7rzJlh55O+HWlyAC/0ijlQcRJM24MFCpNOIoOge4iMtDG0MlsIoegnkArb/0zbjqUw3/qaZssNSMLRCR7kOtTI1HR6GMOllbur X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123558100)(20161123560025)(20161123555025)(20161123564025)(6072148); SRVR:CY1PR12MB0149; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0149; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0149; 4:UeOGq8KIn55iDyAxYEqGZxKEWlDpra3lgWd1uyVDwDb84AaDfwrPGyb22glHYd/0cLwM1xs8IfFTrBr77yc8MAWKsVTmgDM48CkRNDsEBD3Zk9QHxNIu3wnzeULTG8wJJ0oi4t0FtiDro+b6Wj6IAuKJncxZbASVtUq1kwAp+eSCMhE1Rbdz+85usoMsHSCHNWf3BZkfEhROdbRDozwSwvzwUkNLc9FDG0fO/Jo/qOic4BnfsOCkv1TW6j9uSQAstGT/NUqE4UbdZAJgV9uOiOhlGTKGObL9sUMTFUw7Dq2BsuMrsnXnmuYKuUi950Ia8IiG5ff72hYf0HUxNxf4n0JxvHUehTuKOzH9nQs6UjH2477xzkx9R4JndlvQm2As4Y9St4rhovuoptSqB6Cnd/cza/l5N3CD7Xcvf6D3tusKI7Ih9rbSc0OBBVJB5F5l0T20dHkSbtSMJkkXQuww7b6E78WYnzOMenpGhhixnSDbKzeX3dUJrWyKpZRjeobdGHsIFfw2GKjw4Qdy7BmHprSVztz7tyMe8oHL2CMcyHD5ESwuf613Bf7sMXh2tEv922bEQOwHyXj8AGuVYuJvjX7SmC0diccMcqx+Twp36p0RDEAo9PDV0vhmSPuI5ep27jZeorFpjgCYIDSmGx1f6Ar3s1YaQP91reCy9nXek4T1qaUpbp1O43fshXbv+3D2EkAiC+xU9r+8POZfq28VcICfkWeCCUVxG+xEWaOWMustpXVtpM5539+D6l20UaEURAgaX02yFUhF5OlmJbzhT1Py62cPwpuYslXHmMNd914PJrGaAx/5fhlHzBBrzobHxlpxYW/5jNES0PBX/Fm3I6Mbljlzux/pMs7k8qMKJFKugYYZBw043YCKqG8kKjL7 X-Forefront-PRVS: 03030B9493 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6029001)(6009001)(39840400002)(39400400002)(39410400002)(39850400002)(50986999)(2950100002)(6666003)(6916009)(6486002)(76176999)(50466002)(33646002)(478600001)(86362001)(189998001)(48376002)(110136004)(8676002)(4326008)(2906002)(54906002)(38730400002)(53936002)(3846002)(6116002)(50226002)(25786009)(81166006)(5003940100001)(5660300001)(53416004)(36756003)(42186005)(66066001)(7736002)(305945005)(2351001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0149; H:brijesh-build-machine.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR12MB0149; 23:iH1kBEtKRR0Dikb52nygu8TSJlDKPgM+ffNSLH1eT?= =?us-ascii?Q?Bg+DPb+0S6C0yyiKfdDL2eLYqGX74FrvgXUdWpN2yv1lOmkqE5qogWeAt3NV?= =?us-ascii?Q?q0q87qJvSPdVXnVrlXuOg3F3TWSbNdKvKoaRAGvZHLFuEPSxIuZuEj/6CqEb?= =?us-ascii?Q?WJUpMmKS2BQzHqXqCYsRQbHIb/Mp7QAeVRtdMK1VdVLwqNZXeHEHPwdciIwu?= =?us-ascii?Q?QbSyyG3KFMj/5OHob19jahlKoBOwMMqpJJYhuZrkW58fzFOGID1YRmoA0WAw?= =?us-ascii?Q?gJNggoKtxekvaciP1yJTBkPZ7wfcun0B+IICQl21zp8BJ18mW17gVuaEmYXE?= =?us-ascii?Q?jKDpatQNIff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2ockmzaBsEDqcJd8xFjiCWuFRJ1A2IGuXTtbhXLFiXpVjsbP1HTV0SdGja4dTCNfpigU8Hs6/ywVt2AUdIunawa8HfwDJwMLzrkRwR2nklTbcuvaVbvqo043nfxPzOTb/ZhniEGfUg5PgrtN/bq5ve5Ck12QpC2rxYGIY1TIyniyYiEJTKVSapSUlUBbIhm7AEtA/pIcdiHvJ72+nXqpCB9 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2017 22:09:53.0522 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0149 Subject: [edk2] [RFC v4 13/13] 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: , Cc: Thomas.Lendacky@amd.com, leo.duran@amd.com, Laszlo Ersek , Jordan Justen Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When SEV is enabled, use a bounce buffer to perform the DMA operation. Cc: Jordan Justen Cc: Laszlo Ersek 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; =20 ASSERT (Control =3D=3D FW_CFG_DMA_CTL_WRITE || Control =3D=3D FW_CFG_DMA= _CTL_READ || Control =3D=3D FW_CFG_DMA_CTL_SKIP); @@ -80,11 +82,44 @@ InternalQemuFwCfgDmaBytes ( return; } =20 - Access =3D &LocalAccess; + // + // When SEV is enabled then allocate DMA bounce buffer + // + if (InternalQemuFwCfgSevIsEnabled ()) { + UINT32 TotalSize; + + TotalSize =3D sizeof (*Access); + // + // Control operation does not need buffer + // + if (Control !=3D FW_CFG_DMA_CTL_SKIP) { + TotalSize +=3D Size; + } + + // + // Allocate SEV DMA bounce buffer + // + NumPages =3D EFI_SIZE_TO_PAGES (TotalSize); + InternalQemuFwCfgSevDmaAllocateBuffer (NumPages, &BounceBuffer); + + Access =3D BounceBuffer; + DmaBuffer =3D BounceBuffer + sizeof (*Access); + + // + // Copy data from Host buffer into DMA buffer + // + if (Buffer && Control =3D=3D FW_CFG_DMA_CTL_WRITE) { + CopyMem (DmaBuffer, Buffer, Size); + } + } else { + Access =3D &LocalAccess; + DmaBuffer =3D Buffer; + BounceBuffer =3D NULL; + } =20 Access->Control =3D SwapBytes32 (Control); Access->Length =3D SwapBytes32 (Size); - Access->Address =3D SwapBytes64 ((UINTN)Buffer); + Access->Address =3D SwapBytes64 ((UINTN)DmaBuffer); =20 // // 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 =3D=3D FW_CFG_DMA_CTL_READ) { + CopyMem (Buffer, DmaBuffer, Size); + } + + InternalQemuFwCfgSevDmaFreeBuffer (BounceBuffer, NumPages); + } } =20 =20 --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel