From nobody Tue Jan 14 15:27:23 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 1502107180579714.046968853511; Mon, 7 Aug 2017 04:59:40 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 19A9A21DF967D; Mon, 7 Aug 2017 04:57:12 -0700 (PDT) Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0046.outbound.protection.outlook.com [104.47.33.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 81EBF21DF966A for ; Mon, 7 Aug 2017 04:57:10 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by SN1PR12MB0159.namprd12.prod.outlook.com (10.162.3.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1320.16; Mon, 7 Aug 2017 11:59:24 +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=jys4ArBtFdkhMEDZUdTDoZ4oFtkNt/+YEahSe4AT42U=; b=UFaAw/+Rgz8cA1WNAXzcXDOEabxGeBVyFjTZ7zmmGQQidLewKTK857oBQ71kLI4FUpiBL5QN0GfwcKTUTLmmussQkwCn3D9Rt6HxnwKs3ssCI8pDxo0oTNjl8uJvMxOdZV54ZQHxj4/ALAZdwCL4lTr4Cj7XM83sA8TYrEoSWHA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 7 Aug 2017 07:58:49 -0400 Message-Id: <1502107139-412-5-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502107139-412-1-git-send-email-brijesh.singh@amd.com> References: <1502107139-412-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY4PR04CA0033.namprd04.prod.outlook.com (10.172.133.19) To SN1PR12MB0159.namprd12.prod.outlook.com (10.162.3.146) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cf643399-54bf-4aa6-1d2c-08d4dd8bbf48 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:SN1PR12MB0159; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0159; 3:p7xPo4k0Ua3eTqIkLCMzeGjdTmhlJrKq9VxUM1zdjsPR/mMR9EUbir7LN3pwk+zDAd0xITRZ7TPWXWGm8AuNVSDaFCjm3TNM69qZtVueVflZ4ISTHmbxyTuumx8T2qZz/TjTcgvgcTpApROreUm3suDrYWurJnD80N6AIrw+h0Lex8IuCurIEmCdylshBjP7msQheN8fQLgd+HbvsL1g2UC0qohOqMbl5F+bk06SZHh2D0DNuXCKwrBwcK+wUvIx; 25:Y0iytP0RDXe4eAPh7FGKmU81hgEto1RmiJkEWQEFXZBU//+gqyNoEKCgLM3zYjzV2xKCeQLXagNcosN7Bqs1snJ38uZL/W+m2mUN0ck4h3IWGvcZum3K1un+M4cY/iZbSoFnNPqEFYFIlUT9M70x4EYrH92uTADNk+F3g9NBdKCla+Qn4Nh2V1xKT9OLI6JM8ukVxRZoUHtZTx+O2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7Tel95IhGWi00iUGz5D+E63EStABM/Z2xffntPDWd4N4goD2pU/Whhg6Ou8ecFEIJLlRaKHaI+CNnLpRNXjGB/TCUzN6vDKpmbvKJ17YlwfKFM2bGevOMQLpM/IF8nNAZKgksRvA3Vtb1Q4ERiJlWMMAawZ/uz2iLrTE3vevtQ+CfSDPPrLe7ip4JwHfODyH40ExKjQhVzLhY2ZOjHD+o0h/6oQ== X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123558100)(20161123560025)(20161123555025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0159; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0159; X-Forefront-PRVS: 0392679D18 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(39400400002)(39850400002)(39450400003)(39410400002)(39840400002)(39860400002)(199003)(189002)(3846002)(6116002)(5660300001)(81156014)(81166006)(54906002)(8676002)(68736007)(50466002)(53936002)(53416004)(106356001)(2950100002)(105586002)(2351001)(42186005)(86362001)(6666003)(5003940100001)(36756003)(189998001)(33646002)(6916009)(97736004)(25786009)(2906002)(478600001)(110136004)(47776003)(38730400002)(76176999)(50986999)(66066001)(4326008)(2361001)(305945005)(50226002)(48376002)(7350300001)(101416001)(6486002)(7736002)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0159; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; 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; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0159; 23:Bjaulf4I1VJCw0C3ZiZfWe49ffTTvmpkZScq/fETC?= =?us-ascii?Q?4CTWVq4bpIyDIjm+AiP/VdxOH5iyd5QhKbL/uLhUnBvNV+5QeTNFo4uyvrkF?= =?us-ascii?Q?ND0/9zE5kKWDdUPia/pbK0ES8LXT0zMqBf1nw+LupuLtOnNWdiiwyTfmASbH?= =?us-ascii?Q?mT2ZgfkLq/OmXQ6lzpSLh/G3DVR8mte9EUgc7uDS9qnkYXpBXqAzoFSL/mXx?= =?us-ascii?Q?TmjOMeMP3UZMcKQmbuxyhS3a2Q9pPgU9zdrOMkq0DbiM7iJl8+ox+Kk1bqZb?= =?us-ascii?Q?NDgqyNE9nwgjxzCHs36VEzIghQYjwiFbs5EQ4CVj5Kv6SCGYZRlLkXXrVY4t?= =?us-ascii?Q?r72Vgs/0S+79GXL4060oGauwDWsmkQJ6WNIdY3VA6Y5ZKsCF/iPdAymkZ09N?= =?us-ascii?Q?p2XDkRyXGvkESWRDMujzRH3bQS/Xict3J5g1UEjqDInii0MoQFbF+/OIhKws?= =?us-ascii?Q?+2XP7dnWrUCOBGEd+CyRuZJNtScEynK3ximohbM93L+eobXgdKWPKM/5nEOk?= =?us-ascii?Q?daXysXy3dCcRDXXntsi53JPpz+13N3bZn4GS70w+CyIwNBXJX5wMoyUVDs2t?= =?us-ascii?Q?tn7yN0Akv9+GkbwFE2CSvhhEAVZQU0q9uGghjVteIOnYfyxyo2NUlLKdlYzL?= =?us-ascii?Q?Sq5lpDajHNQnP6j4/TVwZMt/m82Cu4O6DFNfqfkS8b7z9wpaSbqJcdLl+gxP?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wMdUyZlsMeBwnE8ESF7UzoPHWz4W44GgoF8xrOrjUqf7PI51pevhWz8HpwgoMOpp/QKjge+3XIhPqJEYlwCAOnstdoAGLyVZ1n7U56KVt/WD4xw==; 5:H5mZ3d0sCD+VWP/OqdrRfjiAsSq2Wz9bst7y0wFplLPf1WFUWAO6q5GBIz+qZf6tXWgGwcZfrEWlqZtU7ioT+pwpCNev+hln6A3zYwUVLDSII4E+FYPoFKtUEfKip90PlXPT1m+enBdfM7u5FPF/Mg==; 24:rwJbzUMTzVo5uagk7puYUt2P+/ccQPqkIo+pxy9fyu0PkQiVKtfhgT0mNvfrFrsMNcnI3sPwXoBuJunt5vhbXm/Av2jIUVZMUzadhNAikZA=; 7:Rd1oRVkg6DkfKaWMEcALTbrbV5p/Wd4XciHw2wbEjZy5DTjLxpr5eBFW2Ni1CQ70E30+DQ4fEXqiWoNme7Uk2jvM0xiMrZEb0k6luVxScpfC3vzj7OECvHYhMhHiii58MKqRV+DKETaTo/QCiydcsecWNgWyhgHvRYoiExVMFgyjMFfm2ScKjTz2mRhWX/KAIgIf/TH2qeKzoT8yt5BB91ekbeOXxB38bv4ZoBhIb7s= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0159; 20:HQZge7o2x+aeEeHgjyP26K30fd5vvgSix9wjWL4unb0Z/W6TnvZsE04ea9tyiCstS2TgPeu5adX1iUcZgz8ZYZe78U0G0V5HqzGe0OfR+hpm6kxss4Uh1k9u6vyCpY4/Rq5OdsCdpBDFFnBx1KhrWHGuwbdHHfuygEue/oGKtfzSb43VpBM3zr7UKy62YY2AF18jmnphSVGTV5yrPzU6aASzWnJuVtgLtssZNOYzvANX/Tv//lTz1oSsUoL2Fpw7 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2017 11:59:24.1232 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0159 Subject: [edk2] [PATCH v1 04/14] OvmfPkg/VirtioLib: Add SharedBuffer helper functions 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: Jordan Justen , Tom Lendacky , Laszlo Ersek , Ard Biesheuvel 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" Patch adds convenience helper functions to call VIRTIO_DEVICE_PROTOCOL AllocateSharedPages, FreeSharedPages, MapSharedBuffer and UnmapSharedBuffer member functions. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh --- OvmfPkg/Include/Library/VirtioLib.h | 143 +++++++++++++ OvmfPkg/Library/VirtioLib/VirtioLib.c | 220 ++++++++++++++++++++ 2 files changed, 363 insertions(+) diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/= VirtioLib.h index 5badfb32917f..fa82734f1852 100644 --- a/OvmfPkg/Include/Library/VirtioLib.h +++ b/OvmfPkg/Include/Library/VirtioLib.h @@ -3,6 +3,7 @@ Declarations of utility functions used by virtio device drivers. =20 Copyright (C) 2012-2016, Red Hat, Inc. + Copyright (C) 2017, AMD Inc, All rights reserved.
=20 This program and the accompanying materials are licensed and made availa= ble under the terms and conditions of the BSD License which accompanies this @@ -235,4 +236,146 @@ Virtio10WriteFeatures ( IN OUT UINT8 *DeviceStatus ); =20 +/** + Helper function to allocate pages that is suitable for sharing with + hypervisor. + + @param[in] VirtIo The target virtio device to use. It must be valid. + + @param[in] Pages The number of pages to allocate. + + @param[out] Buffer A pointer to store the base system memory address of + the allocated range. + + return Returns error code from VirtIo->AllocateSharedPages() +**/ +EFI_STATUS +EFIAPI +VirtioAllocateSharedPages ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN UINTN NumPages, + OUT VOID **Buffer + ); + +/** + Helper function to free pages allocated using VirtioAllocateSharedPages(= ). + + @param[in] VirtIo The target virtio device to use. It must be valid. + + @param[in] Pages The number of allocated pages. + + @param[in] Buffer System memory address allocated from + VirtioAllocateSharedPages (). +**/ +VOID +EFIAPI +VirtioFreeSharedPages ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN UINTN NumPages, + IN VOID *Buffer + ); + +/** + A helper function to map a system memory to a shared bus master memory f= or + read operation from DMA bus master. + + @param[in] VirtIo The target virtio device to use. It must be + valid. + + @param[in] HostAddress The system memory address to map to shared b= us + master address. + + @param[in] NumberOfBytes Number of bytes to be mapped. + + @param[out] DeviceAddress The resulting shared map address for the bus + master to access the hosts HostAddress. + + @param[out] Mapping A resulting value to pass to Unmap(). + + return Returns error code from + VirtIo->MapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioMapSharedBufferRead ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VOID *HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ); + +/** + A helper function to map a system memory to a shared bus master memory f= or + write operation from DMA bus master. + + @param[in] VirtIo The target virtio device to use. It must be + valid. + + @param[in] HostAddress The system memory address to map to shared b= us + master address. + + @param[in] NumberOfBytes Number of bytes to be mapped. + + @param[out] DeviceAddress The resulting shared map address for the bus + master to access the hosts HostAddress. + + @param[out] Mapping A resulting value to pass to Unmap(). + + return Returns error code from + VirtIo->MapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioMapSharedBufferWrite ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VOID *HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ); + +/** + A helper function to map a system memory to a shared bus master memory f= or + common operation from DMA bus master. + + @param[in] VirtIo The target virtio device to use. It must be + valid. + + @param[in] HostAddress The system memory address to map to shared b= us + master address. + + @param[in] NumberOfBytes Number of bytes to be mapped. + + @param[out] Mapping A resulting value to pass to Unmap(). + + return Returns error code from + VirtIo->MapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioMapSharedBufferCommon ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VOID *HostAddress, + IN UINTN NumberOfBytes, + OUT VOID **Mapping + ); + +/** + A helper function to unmap shared bus master memory mapped using Map(). + + @param[in] VirtIo The target virtio device to use. It must be + valid. + + @param[in] Mapping A mapping value return from Map(). + + return Returns error code from + VirtIo->UnmapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioUnmapSharedBuffer ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VOID *Mapping + ); #endif // _VIRTIO_LIB_H_ diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c b/OvmfPkg/Library/Virtio= Lib/VirtioLib.c index 845f206369a3..f6b464b6cdf8 100644 --- a/OvmfPkg/Library/VirtioLib/VirtioLib.c +++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c @@ -4,6 +4,7 @@ =20 Copyright (C) 2012-2016, Red Hat, Inc. Portion of Copyright (C) 2013, ARM Ltd. + Copyright (C) 2017, AMD Inc, All rights reserved.
=20 This program and the accompanying materials are licensed and made availa= ble under the terms and conditions of the BSD License which accompanies this @@ -414,3 +415,222 @@ Virtio10WriteFeatures ( =20 return Status; } + +/** + Helper function to allocate pages that is suitable for sharing with + hypervisor. + + @param[in] VirtIo The target virtio device to use. It must be valid. + + @param[in] Pages The number of pages to allocate. + + @param[out] Buffer A pointer to store the base system memory address of + the allocated range. + + return Returns error code from VirtIo->AllocateSharedPages() +**/ +EFI_STATUS +EFIAPI +VirtioAllocateSharedPages ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN UINTN NumPages, + OUT VOID **Buffer + ) +{ + return VirtIo->AllocateSharedPages (VirtIo, NumPages, Buffer); +} + +/** + Helper function to free pages allocated using VirtioAllocateSharedPages(= ). + + @param[in] VirtIo The target virtio device to use. It must be valid. + + @param[in] Pages The number of allocated pages. + + @param[in] Buffer System memory address allocated from + VirtioAllocateSharedPages (). +**/ +VOID +EFIAPI +VirtioFreeSharedPages ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN UINTN NumPages, + IN VOID *Buffer + ) +{ + VirtIo->FreeSharedPages (VirtIo, NumPages, Buffer); +} + +STATIC +EFI_STATUS +VirtioMapSharedBuffer ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VIRTIO_MAP_OPERATION Operation, + IN VOID *HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ) +{ + EFI_STATUS Status; + VOID *MapInfo; + UINTN Size; + EFI_PHYSICAL_ADDRESS PhysicalAddress; + + Size =3D NumberOfBytes; + Status =3D VirtIo->MapSharedBuffer ( + VirtIo, + Operation, + HostAddress, + &Size, + &PhysicalAddress, + &MapInfo + ); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Size < NumberOfBytes) { + goto Failed; + } + + *Mapping =3D MapInfo; + *DeviceAddress =3D PhysicalAddress; + + return EFI_SUCCESS; +Failed: + VirtIo->UnmapSharedBuffer (VirtIo, MapInfo); + return EFI_OUT_OF_RESOURCES; +} + +/** + A helper function to map a system memory to a shared bus master memory f= or + read operation from DMA bus master. + + @param[in] VirtIo The target virtio device to use. It must be + valid. + + @param[in] HostAddress The system memory address to map to shared b= us + master address. + + @param[in] NumberOfBytes Number of bytes to be mapped. + + @param[out] DeviceAddress The resulting shared map address for the bus + master to access the hosts HostAddress. + + @param[out] Mapping A resulting value to pass to Unmap(). + + return Returns error code from + VirtIo->MapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioMapSharedBufferRead ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VOID *HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ) +{ + return VirtioMapSharedBuffer (VirtIo, EfiVirtIoOperationBusMasterRead, + HostAddress, NumberOfBytes, DeviceAddress, Mapping); +} + +/** + A helper function to map a system memory to a shared bus master memory f= or + write operation from DMA bus master. + + @param[in] VirtIo The target virtio device to use. It must be + valid. + + @param[in] HostAddress The system memory address to map to shared b= us + master address. + + @param[in] NumberOfBytes Number of bytes to be mapped. + + @param[out] DeviceAddress The resulting shared map address for the bus + master to access the hosts HostAddress. + + @param[out] Mapping A resulting value to pass to Unmap(). + + return Returns error code from + VirtIo->MapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioMapSharedBufferWrite ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VOID *HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ) +{ + return VirtioMapSharedBuffer (VirtIo, EfiVirtIoOperationBusMasterWrite, + HostAddress, NumberOfBytes, DeviceAddress, Mapping); +} + +/** + A helper function to map a system memory to a shared bus master memory f= or + common operation from DMA bus master. + + @param[in] VirtIo The target virtio device to use. It must be + valid. + + @param[in] HostAddress The system memory address to map to shared b= us + master address. + + @param[in] NumberOfBytes Number of bytes to be mapped. + + @param[out] Mapping A resulting value to pass to Unmap(). + + return Returns error code from + VirtIo->MapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioMapSharedBufferCommon ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VOID *HostAddress, + IN UINTN NumberOfBytes, + OUT VOID **Mapping + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS DeviceAddress; + + Status =3D VirtioMapSharedBuffer (VirtIo, + EfiVirtIoOperationBusMasterCommonBuffer, HostAddress, + NumberOfBytes, &DeviceAddress, Mapping); + + // + // On Success, lets verify that DeviceAddress same as HostAddress + // + if (!EFI_ERROR (Status)) { + ASSERT (DeviceAddress =3D=3D (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddres= s); + } + + return Status; +} + +/** + A helper function to unmap shared bus master memory mapped using Map(). + + @param[in] VirtIo The target virtio device to use. It must be + valid. + + @param[in] Mapping A mapping value return from Map(). + + return Returns error code from + VirtIo->UnmapSharedBuffer() +**/ +EFI_STATUS +EFIAPI +VirtioUnmapSharedBuffer ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VOID *Mapping + ) +{ + return VirtIo->UnmapSharedBuffer (VirtIo, Mapping); +} --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel