From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0085.outbound.protection.outlook.com [104.47.40.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7952921D0A242 for ; Mon, 14 Aug 2017 04:34:50 -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=OxthZJKK85zslsvijNEY9TAblgLjeHRmIKxU3uyg4cA=; b=VTERjGB5jFKdtr4/28gbdbmEBozc/tEaj5ALADZ2fBNp0jwglyQo07XyM+aCsu5aqwQ0etzYjNueFcxGglfyJJeZf+mj8k3anlre3UYYWDtPR8qdprVMZL/TXN7BvQ8gQNgjOv7jOVelO7Jv5sEmTK+I5qvL0LfKrAXG65oM+CY= 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:10 +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:28 -0400 Message-Id: <1502710605-8058-7-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: e219579d-46c2-4e02-5c81-08d4e308cda5 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:AOyrnLWRFMNwF5om8/qxVI2qVlHbXX/bLLupmCmvOIbmy95lSOl6c0Vq9Hc3KhTkUWP+ZHRrozanpEGE0xbNTu2UoENlIc6c0onlolYyDopTKrQeA8Djy1sQ6aZ3jOzqHrGTwJozNO/DnBIWTJsIW9vJPFdvsZ3E/uQj8UQzCpmwiH/42fpgcqoUn42C+4w18HcZtFsqP6P16/Z/fiGSJIu2ClgP9OKyAzfRzah1jjR1PU8NWy6ixWLKeBOTj9zJ; 25:NfgT1JdHelwcV8VwBIcRBkWo5v2/q4s/V0CP68fv6aDlt0iCPA/M3IGQ9PalcbmSq1rPz2zT0izu6wyLigm7qPl6guHbT7RWyADCLHdT7BKbeWUJMrcuadaMjBgVOYqaImxhipd/071iYhSDWy/4EY2+31T3exVjtatnCeK3GGBD7boyLqT13QQOk+IhROJUbltwKOjURCKf3MNn89QH+NoBKJorHsl7tiFJ7qhD60/9zaeE9/swpYCy1/wwfqf7Nsd37pTc7nQWH9S+NTEsPy8pr2VPhRC5BIGf5DUvvr5C4OyweYHDygiDaeJHAqhKrsQEqaTjREMpJlLq1inRvw==; 31:XA851+Hot5Qi7/5S4QZz5vTlx3ZgupEkwBWYY4HmatzzGfyc2vdeiCia7QzHtl+S6WViZcKTKvgIAGt1wcidh+gsdKmRX4xJdfVEQulbAlBzrjrDUTmfysforkKrFlWmI0Ac8lZNrqUusiSElttBdTqM1y7BLDB5uS8Wfhe87JZdu1hAJZaQENrtSEJiWsAYnaD8Q0SaunrkrOZMsKgLEirQE0zMhOgb3f/rOvVxSoY= X-MS-TrafficTypeDiagnostic: BY2PR12MB0145: X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:8IW/jfZ+8XOJP98RhwrY+4Ls7Hn2/MgCpKl7xEyCpaLnwrfFiIK9jQeXpMSFver/B3fzkg3GALZoFgazUORkpnjolErYW2c+hfE4HtHOzzopt3lCeOPOYIYEJzoAfTxhd6YRiZYGhmfcPkjO5PfetrZo6AAGPpj/GanZmxlycGII21m6Z4PlzomrjIvhcGlmrFeOrem3wbbdZgd8dQTrfWYsOeg1YfbCLVrhYs/Xsal1FqLrJVRcarjd8lAAr8bb56Lf4mhYysrzX2UZ1oNqpNBAMQ7BXb6pNfXxl4ZS2FUnApZ9fZOKR9YCOtfKvViok8wDOWMqO1AKa+rQ5O4B8FfZyhJEoWm51KNQdTklp5My3f+j6PbzXdLaMqXQHMqSvEP3DAH1qwUK4bHw/I2jxNrVMMEMzV9GtfE700WInO+mDpyRVdWUMfM1hsVY6Gm/kzWkwS8p5dg+UHFSTLhX89NKTBOV0nVWg6XlGnx3BS/8xVL7kCP/EJNEtKr4wYAu; 4:XXj+ThP9MCqdPJVYZXvXgOwgWZZIqyQWIvTredv20Kp+oGicuuUwpOgnlLJ001Je8ZfrycLQgRKXwxnFzg5UDS0SgURV9us87AoLTeKOriBDqiJUpKdf7Em3VcbCqHewnsUSx+9lE4Ao16BDaFlBg05npDOMahJdEIEMewY9o2PMN9Qit1Z4S2G0syj+fOUznauwe8ks/cVxW8uy6UKR72u6M1CZGCFVoCiGkhmNUGFhRnOO7A500y5R6xtXVFkWOptaL654A9jtq7yfS00Joq4mGIfdI2zmomlAH1GQj3mPHtSHi6zIacZqFMC9Zl+VBuUQhGliGluglyxwClmv5A== 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)(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); 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:u7zlM7WMWb1/ORqfVZdukOuwwSHXCHmcH8cfvvAXb?= =?us-ascii?Q?3S3OWV9JbJqELMowIXyxGOI7aBk+vzm6f26Tf1dxyDWUUggEFfYFitD6v21C?= =?us-ascii?Q?Bv+mw0lToxTEI4kxSm9Wye4DXJ6bDMnMed1hZDQdxPeQbMq1gxU1/yS5WBt9?= =?us-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I0MjJaCupMw8ttJYM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:fH31yVHUVUEBGLEStjIy16Ob3/2F2kc1V3hEYcziKZb9ODvEKBaZWtgEt1bfqjSCmLppSeAl3IOes6HECI4U0Q2S0hpqyT6pFw4VW+bVOLFE5yKZllyoQXJGNNzumhqQPmi7KO72mYVq8WM5ozwqsfh9/rzWz/8apXkqivQT+3ELDF9zHwgn3egz9+QpjN/6Nve7ol0MlPIgqNmnEF7EPVjBHBzztSR5JXTQWySJL3RppjDj5noOV9F3wipbn5l8 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2017 11:37:10.9554 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0145 Subject: [PATCH v2 06/23] OvmfPkg/Virtio: introduce IOMMU-like member functions to VIRTIO_DEVICE_PROTOCOL 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:50 -0000 Content-Type: text/plain The patch extends VIRTIO_DEVICE_PROTOCOL to provide the following new member functions: - AllocateSharedPages : allocate a memory region suitable for sharing between guest and hypervisor (e.g ring buffer). - FreeSharedPages: free the memory allocated using AllocateSharedPages (). - MapSharedBuffer: map a host address to device address suitable to share with device for bus master operations. - UnmapSharedBuffer: unmap the device address obtained through the MapSharedBuffer(). Suggested-by: Laszlo Ersek 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/Protocol/VirtioDevice.h | 143 ++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/OvmfPkg/Include/Protocol/VirtioDevice.h b/OvmfPkg/Include/Protocol/VirtioDevice.h index edb20c18822c..14f980d7bf0a 100644 --- a/OvmfPkg/Include/Protocol/VirtioDevice.h +++ b/OvmfPkg/Include/Protocol/VirtioDevice.h @@ -5,6 +5,7 @@ and should not be used outside of the EDK II tree. Copyright (c) 2013, ARM Ltd. All rights reserved.
+ 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 @@ -31,6 +32,25 @@ typedef struct _VIRTIO_DEVICE_PROTOCOL VIRTIO_DEVICE_PROTOCOL; +// +// VIRTIO Operation for VIRTIO_MAP_SHARED +// +typedef enum { + // + // A read operation from system memory by a bus master + // + VirtioOperationBusMasterRead, + // + // A write operation to system memory by a bus master + // + VirtioOperationBusMasterWrite, + // + // Provides both read and write access to system memory by both the + // processor and a bus master + // + VirtioOperationBusMasterCommonBuffer, +} VIRTIO_MAP_OPERATION; + /** Read a word from the device-specific I/O region of the Virtio Header. @@ -319,6 +339,121 @@ EFI_STATUS IN UINT8 DeviceStatus ); +/** + + Allocates pages that are suitable for an VirtioOperationBusMasterCommonBuffer + mapping. This means that the buffer allocated by this function supports + simultaneous access by both the processor and the bus master. The device + address that the bus master uses to access the buffer must be retrieved with + a call to VIRTIO_MAP_SHARED. + + @param[in] This The protocol instance pointer. + + @param[in] Pages The number of pages to allocate. + + @param[in,out] HostAddress A pointer to store the system memory base + address of the allocated range. + + @retval EFI_SUCCESS The requested memory pages were allocated. + @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + +**/ +typedef +EFI_STATUS +(EFIAPI *VIRTIO_ALLOCATE_SHARED)( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN UINTN Pages, + IN OUT VOID **HostAddress + ); + +/** + Frees memory that was allocated with VIRTIO_ALLOCATE_SHARED. + + @param[in] This The protocol instance pointer. + + @param[in] Pages The number of pages to free. + + @param[in] HostAddress The system memory base address of the allocated + range. + +**/ +typedef +VOID +(EFIAPI *VIRTIO_FREE_SHARED)( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN UINTN Pages, + IN VOID *HostAddress + ); + +/** + 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) + + @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. +**/ + +typedef +EFI_STATUS +(EFIAPI *VIRTIO_MAP_SHARED) ( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN VIRTIO_MAP_OPERATION Operation, + IN VOID *HostAddress, + IN OUT UINTN *NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ); + +/** + Completes the VIRTIO_MAP_SHARED operation and releases any corresponding + resources. + + @param[in] This The protocol instance pointer. + + @param[in] Mapping The mapping token returned from + VIRTIO_MAP_SHARED. + + @retval EFI_SUCCESS The range was unmapped. + @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by + VIRTIO_MAP_SHARED. Passing an invalid Mapping + token can cause undefined behavior. + @retval EFI_DEVICE_ERROR The data was not committed to the target + system memory. +**/ +typedef +EFI_STATUS +(EFIAPI *VIRTIO_UNMAP_SHARED)( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN VOID *Mapping + ); /** @@ -359,6 +494,14 @@ struct _VIRTIO_DEVICE_PROTOCOL { // Functions to read/write Device Specific headers VIRTIO_DEVICE_WRITE WriteDevice; VIRTIO_DEVICE_READ ReadDevice; + + // + // Functions to allocate, free, map and unmap shared buffer + // + VIRTIO_ALLOCATE_SHARED AllocateSharedPages; + VIRTIO_FREE_SHARED FreeSharedPages; + VIRTIO_MAP_SHARED MapSharedBuffer; + VIRTIO_UNMAP_SHARED UnmapSharedBuffer; }; extern EFI_GUID gVirtioDeviceProtocolGuid; -- 2.7.4