From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0072.outbound.protection.outlook.com [104.47.40.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 34B322095B9F4 for ; Wed, 23 Aug 2017 05:20:26 -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=hNGJ6k8AuDBdQUdf5kCf3O0bpuUDliXnHJD8XN0HcXk=; b=AxIAlpFmwkPUrt+HnIRQGkfqfn+7v4ih0kM1R5MDLzqrtNb0CxhFykO2dZJMu5YmmoLgrzH2rpk7yz36mR/SZJ3Q+xbFSZE5TXbQSGtnEpWswyHYLuM2un8DWdlkgzjMgKDgIF/d92NnL07ELKKdRNivzyKxPhH+Q5yWSyJD7Sc= 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:57 +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:25 -0400 Message-Id: <1503490967-5559-2-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: 8ae28d85-381e-4f66-9adf-08d4ea21b070 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:Gw/TMh9gUIwn5wIdEP7b9O3pzCpEqEGQf5+cCjMd93AEyzHbXi2xxuVOMfIFlGDt6VNEcvR/HARa4AhOcdmDRrdIxJ1Vm7dcI0uCCwTi8z+Ay6R8PZYvOdEuv3zSgupuLjcgd3oVpfqybORu4SqmzOBe9/gPD5tn9m7lYn5ycT7ZrcU6z/gC/GFAK/X64VDlzmOsPFx3RP17os9xy9jyWfk1idbYpmN++irFQhA0UHPm9PObHnppi2IdYIHc4Jvf; 25:QQK4PcCJNSD49adiFsmigZrb6AbjRdpAcWZEvbM2nihpH2H+ZOIkALIFLfXxUHhNRrvn+SOj4LwE4GvH5qv26Aq0ol1JusEbVZwdAv+H6CcRO5nYV+/j9IHEZ5nkaJE3eV2Wl3tN1WL3ptEIYgIKQRLQNR0PoUKziuyqhTjy11W2PxQ4aJ9/4U7+E3Ns/S8X5H9v5tP8S/dIqxOwKa8yV1JxTGZ1TkxoZQxxvbREslqIu2gvDb82O/iffQWrrHprwDM1lzIDIdzYurvLaLt8L35UCH/gSg5gKzc/zqqldp5yLRz+2OQL0Gks5JCu+dBuRffQIv25b2d0kajgygC0Qw==; 31:Nu3Iv57Q+6mehpYGAoXc18Y5fpiTd941K9Bd4trIZPBKMzFTWdXNMZ0LdQ7Nx+DPdhIWhxwmb57gER7oT+SlMAntus8nKfIhsUpxOnJNydmVWgi7bQMLyvQwdWVZ1SaAO5agvgV0FtAyWHGa1kYjAhMy2GOyEe6GSBb4Al/sj4Y1u9NCuwB46wSpJP4PWLEmo4FY/swpB3x0fM6qDTSr/02KKlHFvoFAJMs39rC8NNE= X-MS-TrafficTypeDiagnostic: DM2PR12MB0155: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:27gZ2gY5KEgmCkTASUfkfJjECqtg3KUm5aDmvPEhh+MunI2/j6g+rPim9znkalaoOR68BH2fYZRvniS3dvWZN0MxJN13t/UZ+rfZctlwyDadAucnK0D/P14O+nJDPhclg4GJhKZ3coIygg26ibClUgcRNBIqC+shQI6xYV2HseDzVViR+zKquw5dVUXVnk2GJq7op6siJrzuXGnMPNkoPO4nok5uflJj6BPS28FC190DL2luokkTAx4RBeNdyxJtU4TUIKtFryD5oxemJ53JQHF1Yy7ryTFIHro4ojPI8N0X4c347oveS0+Z8hfx6jRTHsS4owKhUahR9aEyIFBvTZ423P2K7u7mnFi0phzg6PYCmnIowM/sMnGCKaKMbOibKiN+t58nIT/Ca0h4ex8iP2qtVhFJb47E16KLtfmthBvZljD+SdynBlUYw0fwjUmw1/CvetzBBTaJZOOUwm0gmfKxDHuhWwKO+S/lnmg8A2omnD+Dxx0oztP0+4LH33Sl; 4:hz1yp/MbCxJ1zjlm7RfC5Hm0Q6+g4UbdyRfgarFYDSQXdh15d+P/nrQWvrpIOdwGoL75ZIuC6bD/8AK7bTPxhCL7wOn21tdM/4m9fffOix0rckDMupm5dnmw8A6kyE3zJ5WXi5Ny2KZqumel3grz1OK+29avJKhEwxg/mmz9Or2kk1gUaFhXQGhSWvAj8kpz8bUUCGW5LzxSquf9aLLbohSiOY3jwz07pnA/bmzrbsPT473AUI+zfVhtgCj7c2jre6kfeKynV4/sqhPhDMRbTC6g8tj141lB7JKeXyyXqRF+y2Lz/D5U6JfufTqlstd/pwoQ/29ZNWZLsxpcYFyYeg== 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)(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)(39860400002)(189002)(199003)(305945005)(47776003)(97736004)(101416001)(110136004)(6666003)(189998001)(478600001)(7736002)(3846002)(66066001)(5003940100001)(6116002)(6486002)(966005)(48376002)(86362001)(105586002)(2950100002)(4326008)(106356001)(36756003)(6916009)(50466002)(2906002)(50226002)(42186005)(2351001)(33646002)(53416004)(25786009)(7350300001)(81156014)(76176999)(5660300001)(68736007)(6306002)(54906002)(8676002)(53936002)(50986999)(81166006)(2361001); 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:QGp2y/cPARf8u0QoiKrXcaOyyNPxjA0JsJ1CA7a5q?= =?us-ascii?Q?+HjuKUOClV4i01rClL3Urd63wsCLe6bfg2w1LZhZJMJ+j1EhjI2J6Q5ePdeZ?= =?us-ascii?Q?7y24Mq29K/Gc4EZaEcv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gtb9NZUNSPKLnQ0zKwvmtpy+sGpaMzWA+2XTTR/bdiWrxjl63nRZNNep5Bf8LrqIsOOVsPvok= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:KRE0xWvJiMNsakoxWuoFY3mpAAHQ5T4Cjv7s5XEbHEkXwVWXr6nxK308CWcURG7XDV0KByg5Pv3FO9Ld8vg5LhZizcxfZsInIDzjsXYMSjVicLkten4U2ClzEVGwIbue/pEYVgSskuRb4BpPc35gYJw2fEBk7LEt98pjUsLPdiD1CjciFtoHpCJtol9f44FWXlqbU2MEg1op6+BEwmSwCebpoIa0cBAe3fwidHpMkaYmZsZMNCNy7lW+6h2QG25v X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 12:22:57.9041 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [PATCH v3 01/23] OvmfPkg: 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: Wed, 23 Aug 2017 12:20:26 -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(). We're free to extend the protocol structure without changing the protocol GUID, or bumping any protocol version fields (of which we currently have none), because VIRTIO_DEVICE_PROTOCOL is internal to edk2 by design -- see the disclaimers in "VirtioDevice.h". The patch implements Laszlo's recommendation [1]. [1] http://mid.mail-archive.com/841bec5f-6f6e-8b1f-25ba-0fd37a915b72@redhat.com 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 fc166bd1a2b4..9a01932958a2 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 @@ -33,6 +34,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. @@ -321,6 +341,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 token 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 + ); /// /// This protocol provides an abstraction over the VirtIo transport layer @@ -361,6 +496,14 @@ struct _VIRTIO_DEVICE_PROTOCOL { // 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