From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0076.outbound.protection.outlook.com [104.47.40.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9AB2821D0A251 for ; Mon, 14 Aug 2017 04:34:54 -0700 (PDT) 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=L2M1R/jaYsd5XNiYEJ2+gsYbuV395Nbq6Kx4lKuVTd8=; b=WsMSAuwB0H29vMx8Z5YKKcZjjXXqv14NVFaFbTU1+dBR67PunORCOW3sKhcZhCOTUFknfGOT29sWLe86cdljaMEOKK+AcfJn6f/9X5G2bkr6BB8xbINKCEs1fT7qTbYz1IR9fiV2o2hyeVdUx9w6HDncmOlV1fQbYerE6+2w+vo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from brijesh-build-machine.amd.com (165.204.77.1) by BY2PR12MB0145.namprd12.prod.outlook.com (10.162.82.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1341.21; Mon, 14 Aug 2017 11:37:15 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Mon, 14 Aug 2017 07:36:32 -0400 Message-Id: <1502710605-8058-11-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502710605-8058-1-git-send-email-brijesh.singh@amd.com> References: <1502710605-8058-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR15CA0043.namprd15.prod.outlook.com (10.173.226.157) To BY2PR12MB0145.namprd12.prod.outlook.com (10.162.82.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 690804ef-0ec6-4a74-524e-08d4e308d043 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:BY2PR12MB0145; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 3:kJXyLEgCtOkzPe6i5QRkH8P3axXMT1E5ixFgDeWJo+9hEvryw6AnCETWHjz9jd7XVHm/sbUG4PDBrJ1wwc0UOR10rZRccQqpvz1E5/MZovNi3YhgTEibIZvMTxDFuVIcQif5Lj5bKNCUqiqW65DgqW/vOq2rJVr7cRWMgUg1TVxJK9iLEVGqxt6C7czYTfjLbWO8QTUUPaTXn3C7nLmnVd+8IHq8ckeDFFDhB1m1ZAlmOIVwWMjoEUGCtgIwztF0; 25:0G7IOLy8jMw3ffg27tV6LN5E0h90eT05YUNoSo9zoRqTYV72sRZ2+znLI6Yn2YhZh+lzvU2W36qMp8/Qei0Bewgc9feVIQC6Qf16SfzB20IeeGSFdNjAdj0oowvOSP19mf3qa6M3jyf+6WsPRzzSSV9YK7GHz5or0cC2xtGvl8cfje/yT4m9WL4ye/zgYfJSEFZ44RZ/I07HD3i6QQgGRsTbwptGxci3AzjunAKXwetUMVUIfAtp0XlXT+axAs2um6ma3YkwDbCSsMHa+KjjdCTIm3LLBj26ugeMISECESqorD60bRL5bneNVeMucAf18EUusvXrzE/lNg8Wl0PMJg==; 31:jqTsnHg9cExAVi/HlqQyxkb3R9HGkQv5Ogr91OsGgj6ABQbWhOqHd1/Yi/pc1zQaB8cdY1eSU8lKoDCAO7F7YjkeeuQyOf6ipTvKk3rKH19l7n6ySNTqZK+L0ud6vq/4A+FnncyVUqglma77g350yzyTUh4wyMQx4gdW+ESXzjtCoaPK3xlWU/GrmrC2+k68SMAbg1MJhgHZmJCVEs7MStuelu2eFk45ZIfcFQujQBg= X-MS-TrafficTypeDiagnostic: BY2PR12MB0145: X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:tRWhPwfFZDg1L/4kimbs31x0b60gOc7OUukp2wvP31lr6fiQ97v3wDuyskYA4JLtwdTyrXqvnjkxNGrM7s7lIsrq3GYsQy1/r/9gvBY+jNWTHAJvmLJfl4jqzt/ex60XBStZWxxvvLFEo4STCqq22oOMt1uokcikfHMm1nEpbahan/pUFJSHoyCKqvk/HOfkii7qf56Sm+4SmwRVUTJsB6+DEBTVSng9lGBYZuvyty1lwmPj+T4exHDlxtGF2dooMUy4RPQA1M3hQKKqExcFcDlWpAztWiVBab9dEiB6BL3dzw7C8R0EgCpIKu/+r4ZjLJBoFoEM/ZIUcH1/KHZp5meKuCH0zNtUyY2INK0ynXhgZjfTzRW0NwFXgDCxHQFeyhnV0JGj+y3sXkJGvIKTbtoRcOWYqkd5IzT4W2PKEFVVnVgjEfXO95fi5tI1yXfAHyFIZCGYJi1Z7YeJhGaR27v/ZZZjY/rnIRMMzAAYG2KWT8VCWQ3QWJjKXnl109b8; 4:9fMeupoIbW47aFGrgTMbB5h9stzKMDqx6A4VMrYpO9Jji1mZtpo8GE96O8QSiR6TshFWIqAhjdO5mQ16fW9NlT3CkV1WFj3hC/2Hs3OWfbkFVmtcEMJrf4JIStth6Rp89O0YqltcAPMddpWRkNI2dEZ2m9KQ6QRHxnkOFJW5fU8Zo8pIyCNaX72YYdFWFvLuNejVA5Gq3HZqYphzzORKy9uCgb41fjS0BWApUSzdvJkAG8wXjmaiMQEvpCvXLxszGLfdax1MBCfFvY7Atv/73l/GDfOjICtuEcBT3EPkG0qqkpdiUU76pOqwUwFjozowwmShnMbQlcFb+HPA5ZfGfw== 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)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123558100)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BY2PR12MB0145; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BY2PR12MB0145; X-Forefront-PRVS: 039975700A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6029001)(6009001)(39860400002)(199003)(189002)(54906002)(5003940100001)(6116002)(3846002)(53936002)(97736004)(575784001)(86362001)(36756003)(81156014)(81166006)(110136004)(8676002)(189998001)(50986999)(76176999)(5660300001)(2361001)(25786009)(2351001)(50226002)(4326008)(7350300001)(33646002)(478600001)(53416004)(42186005)(2906002)(105586002)(7736002)(305945005)(106356001)(48376002)(50466002)(47776003)(66066001)(6486002)(6916009)(2950100002)(6666003)(68736007)(101416001)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0145; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR12MB0145; 23:dCXaXZVJcqFaW0xH9WpGfbpoOlKhjc/vD5nKlEZCx?= =?us-ascii?Q?r725p0Ks42UmWQayUHk8v71kxFh/KOERAeoZwWumgID9F2YkZkpDCnf5pbJS?= =?us-ascii?Q?NrQAoFVuzsWPhAi1SxnHmSZZjMtQspo9/evZlV/Ys/MX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m0Arpr8mM3cHlCoTwyRuEw6mExwjUw+1bJaTs5bUN3gcfWSFevhqqHgsfCFd8FB7Oi0cSq6OFXEJISVpUBkLRr5tC2cK3b0v+6AGkLSLCk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:V5i+7nP5ddbwbePIJCgdtYoo/1zintDCqPYkB1N0aUuPQV66XFom1LNKk08gRYBzILjbB20eCoEDLk7jb3WA7h6t1CJLeUYcebxpt0LOF0fk7/a4Oloa6OEoWF3AvR1rqUecvTZ85DcXuo7IxohIDW0UMk1VvdIrNVaDCaFqDZd0X3E7XkqIOvdMdn2CswSSUeQNlfsMEEhiUQ6e/Iw9uukjrXdwozOWRlaW++ypfmEy6ODldaSicg7GhnDHPNht X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2017 11:37:15.3305 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0145 Subject: [PATCH v2 10/23] OvmfPkg/VirtioLib: add VirtioMapAllBytesInSharedBuffer() helper function 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: Mon, 14 Aug 2017 11:34:54 -0000 Content-Type: text/plain The function can be used for mapping the system physical address to virtio device address using VIRTIO_DEVICE_PROTOCOL.MapSharedBuffer (). The function helps centralizing error handling, and it allows caller to pass in constant or other evaluated expression for NumberOfBytes. 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 | 44 +++++++++++ OvmfPkg/Library/VirtioLib/VirtioLib.c | 78 ++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/VirtioLib.h index 5badfb32917f..d8f24a5d68b1 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. Copyright (C) 2012-2016, Red Hat, Inc. + Copyright (C) 2017, AMD Inc, All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this @@ -235,4 +236,47 @@ Virtio10WriteFeatures ( IN OUT UINT8 *DeviceStatus ); +/** + Provides the virtio device address required to access system memory from a + DMA bus master. + + @param[in] This The protocol instance pointer. + + @param[in] Operation Indicates if the bus master is going to + read or write to system memory. + + @param[in] HostAddress The system memory address to map to shared + buffer address. + + @param[in,out] NumberOfBytes On input the number of bytes to map. + On output the number of bytes that were + mapped. + + @param[out] DeviceAddress The resulting shared map address for the + bus master to access the hosts HostAddress. + + @param[out] Mapping A resulting taken to pass to + VIRTIO_UNMAP_SHARED. + + + @retval EFI_SUCCESS The range was mapped for the returned + NumberOfBytes. + @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a + common buffer. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to + a lack of resources. + @retval EFI_DEVICE_ERROR The system hardware could not map the + requested address. +**/ +EFI_STATUS +EFIAPI +VirtioMapAllBytesInSharedBuffer ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN VIRTIO_MAP_OPERATION Operation, + IN VOID *HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ); #endif // _VIRTIO_LIB_H_ diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c b/OvmfPkg/Library/VirtioLib/VirtioLib.c index 845f206369a3..ac0ae97f3692 100644 --- a/OvmfPkg/Library/VirtioLib/VirtioLib.c +++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c @@ -4,6 +4,7 @@ Copyright (C) 2012-2016, Red Hat, Inc. Portion of Copyright (C) 2013, ARM Ltd. + Copyright (C) 2017, AMD Inc, All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this @@ -414,3 +415,80 @@ Virtio10WriteFeatures ( return Status; } + +/** + Provides the virtio device address required to access system memory from a + DMA bus master. + + @param[in] This The protocol instance pointer. + + @param[in] Operation Indicates if the bus master is going to + read or write to system memory. + + @param[in] HostAddress The system memory address to map to shared + buffer address. + + @param[in,out] NumberOfBytes On input the number of bytes to map. + On output the number of bytes that were + mapped. + + @param[out] DeviceAddress The resulting shared map address for the + bus master to access the hosts HostAddress. + + @param[out] Mapping A resulting taken to pass to + VIRTIO_UNMAP_SHARED. + + + @retval EFI_SUCCESS The range was mapped for the returned + NumberOfBytes. + @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a + common buffer. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to + a lack of resources. + @retval EFI_DEVICE_ERROR The system hardware could not map the + requested address. +**/ +EFI_STATUS +EFIAPI +VirtioMapAllBytesInSharedBuffer ( + 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 = NumberOfBytes; + Status = VirtIo->MapSharedBuffer ( + VirtIo, + Operation, + HostAddress, + &Size, + &PhysicalAddress, + &MapInfo + ); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Size < NumberOfBytes) { + goto Failed; + } + + *Mapping = MapInfo; + *DeviceAddress = PhysicalAddress; + + return EFI_SUCCESS; + +Failed: + VirtIo->UnmapSharedBuffer (VirtIo, MapInfo); + *Mapping = NULL; + return EFI_OUT_OF_RESOURCES; +} -- 2.7.4