From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0071.outbound.protection.outlook.com [104.47.40.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 14C4021D2E633 for ; Wed, 23 Aug 2017 05:20:28 -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=CvA43yYOr0PgDKMJ7uYbn386lOh1+JVZEX/McJOaGTk=; b=mojRUYst95x8A+4T2L81DAVInVlpJola1NTvlZ0FToR5E5aXqneOG1Hf3HOo4LVrX+a8jvYWvolTwsz1PBvRcJvuJw4g90JSHUQuOEOpFgjDhAYushtyKAjrF56GtXBOiE65Tt5BO2w2jJzfM34BUYcxbor/89x5he8HPY2C2Yw= 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 DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1362.18; Wed, 23 Aug 2017 12:22:59 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Wed, 23 Aug 2017 08:22:29 -0400 Message-Id: <1503490967-5559-6-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> References: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR12CA0069.namprd12.prod.outlook.com (2603:10b6:3:103::31) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 16a60458-2883-4312-dba7-08d4ea21b195 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:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:wwpTuem/qwtyj1ZuXFF4U+A04SVmK3PC8KVJrWAzNhxwSCeGs/sc+w01roHYqcVgI3NzE/2tF0ziNVG8n2i2eQnuY+9kX2DT2Rtc9mJSXDtE7tTHW/+ASjUKqvS1vv3FVHZwpUSBnCWc/tmALHJksFutkEl7WnOVj6r9ZjP7SN+eQggxQsRjH/iZYyC3o5l1s+bsP5qNo/il0bxVifnJ2JsiutIrlr60VK5hhjHVsS3GlvbLNz5ZuykjwOlRCLGb; 25:yi9Uo4v0KqUsS5rUPOqx1WOorFZKhCH5bPn9ISK+ppcR+y6gSHwEcbJ2zB8IyJjMDeX2V9kmCL2hbgXWzgfhP3WBpQ9LTyR7t2CeM9WwOoy7d9BEzW00BJMrds+VHzEgQOvYpIXi/gFHhxEceXf3f8A9B6gwSlRTX0UUwPaVSV6xNKLlP7+tpNpQX03JNyJwBqHCyrWsqKfw/l89ZC+MMjO+3cJXC07t8DeaRg7nwuWkvY9o2NYYaJZsJcg0CzSva4btNnbAgNYNYCyVG/MJdVnTLa+x2p2Xoaig6WvHZG73sP47mjNO37ZEb9Og/8XYgDU3AwiOlqTq8Ves1xJOeA==; 31:uxHitBF38bKidKtAonzDIPZqm9Mgoc/w3cVhmbL1YMKRwUha+8UaqaduZeCOEU+ByVz+NaHgq65hYZk2elbBcc4lJhH54VLC4h0rTexkDwN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-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)(5005006)(8121501046)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0155; X-Forefront-PRVS: 040866B734 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(6029001)(39860400002)(189002)(199003)(305945005)(47776003)(97736004)(101416001)(110136004)(6666003)(189998001)(478600001)(7736002)(3846002)(66066001)(5003940100001)(6116002)(6486002)(48376002)(86362001)(105586002)(2950100002)(4326008)(106356001)(36756003)(6916009)(50466002)(2906002)(50226002)(42186005)(2351001)(33646002)(53416004)(25786009)(7350300001)(81156014)(76176999)(5660300001)(68736007)(54906002)(8676002)(53936002)(50986999)(81166006)(2361001)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; DM2PR12MB0155; 23:84l4bnszt6gRIUX/rtwfAtFKjK65lIu//3HbSx39x?= =?us-ascii?Q?sP//4vyu0GgOZy0QZat7hhMJkN7ewpGb3IUBTriOhss9unfn43AOxJmkcO2w?= =?us-ascii?Q?Bt8532ymZprSAtpgUyxr8GaBceTn6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ddqYgnAGOgIXfTxtTmqLA2mK7uwaOap2OEF8qZ076Vk0gGFxvGPL3e0SsJYL5AVAM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:ewway70kjKUXJDWvvxk679pX5K7X9OdCw0CdNizK3nP1+nrTgyhOm4AXA87cBCPFxrHtSXceT8Q/gIxFNCYwdqZxDFyfhfZN5IjuPOHoLB+KLTK7/maW2FnGgB4k0S51U57uydvABHiho+jRgvitf+3S32jBNbxehoZEH3PgW+1WnndXJCUoM7L+i/HB6eVcvF+gXO+r+MBeYMcBVSfHVZbC0D2YnX9sFCHBSOSvJHgUtEq9QZsERzr4JV52zjIH X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 12:22:59.8572 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [PATCH v3 05/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: Wed, 23 Aug 2017 12:20:28 -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 with centralizing error handling, and it allows the caller to pass in constant or other evaluated expressions 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 | 52 ++++++++++++ OvmfPkg/Library/VirtioLib/VirtioLib.c | 85 ++++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/VirtioLib.h index 5badfb32917f..9ec9b91b59bb 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,55 @@ Virtio10WriteFeatures ( IN OUT UINT8 *DeviceStatus ); +/** + Provides the virtio device address required to access system memory from a + DMA bus master. + + The interface follows the same usage pattern as defined in UEFI spec 2.6 + (Section 13.2 PCI Root Bridge I/O Protocol) + + The VirtioMapAllBytesInSharedBuffer() is similar to VIRTIO_MAP_SHARED + with exception that NumberOfBytes is IN-only parameter. The function + maps all the bytes specified in NumberOfBytes param in one consecutive + range. + + @param[in] This The virtio device for which the mapping is + requested. + + @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] NumberOfBytes Number of bytes to map. + + @param[out] DeviceAddress The resulting shared map address for the + bus master to access the hosts HostAddress. + + @param[out] Mapping A resulting token to pass to + VIRTIO_UNMAP_SHARED. + + + @retval EFI_SUCCESS The NumberOfBytes is succesfully mapped. + @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. This includes the case + when NumberOfBytes bytes cannot be mapped + in one consecutive range. + @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..c85cd8dba569 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,87 @@ Virtio10WriteFeatures ( return Status; } + +/** + Provides the virtio device address required to access system memory from a + DMA bus master. + + The interface follows the same usage pattern as defined in UEFI spec 2.6 + (Section 13.2 PCI Root Bridge I/O Protocol) + + The VirtioMapAllBytesInSharedBuffer() is similar to VIRTIO_MAP_SHARED + with exception that NumberOfBytes is IN-only parameter. The function + maps all the bytes specified in NumberOfBytes param in one consecutive + range. + + @param[in] This The virtio device for which the mapping is + requested. + + @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] NumberOfBytes Number of bytes to map. + + @param[out] DeviceAddress The resulting shared map address for the + bus master to access the hosts HostAddress. + + @param[out] Mapping A resulting token to pass to + VIRTIO_UNMAP_SHARED. + + + @retval EFI_SUCCESS The NumberOfBytes is succesfully mapped. + @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. This includes the case + when NumberOfBytes bytes cannot be mapped + in one consecutive range. + @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); + return EFI_OUT_OF_RESOURCES; +} -- 2.7.4