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 7D37F2095B9F4 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=jXyNXcTomLuFaOFpl2SIr8bcH3JRcPUc5li8DCu6M0Y=; b=KoSPpdVs6rx4ayHs4mzGznU54d9G0kiV55Obkl/zaitIBZYLvK8Gabmf6f3bijz6er5HjmFkC1GbdRWBAR17po7XEkLvhVDuy7TjTRBgExM90ciEcYwmO0hE3D9fjHTz2OwSBHBIGYtcdYydOLt1qgEKmzZAN0MwlgednnkrgA8= 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:58 +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:26 -0400 Message-Id: <1503490967-5559-3-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: 1d56a2b0-3774-418e-bef7-08d4ea21b0b5 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:CXJwAGj31fiN1+FTYQmOgUB+ZSnEbELB6qDmCshnZlAcKWXwDcAR5GnFE75x41IanVBldc9w4lyDNIvSTpcRRuswg1jLBWxKnzEmdYS29kZbvpAMuu42edZpxrpYRn484WJq9ibMc5hm/q2sZ33hXjEqxqvDrA0luWjEdJz3/OzCWI8GR1Dy/yfiQ05qzp2jB0HQTJXW1YGdo7HKgtR9WZUb1oK6HGADsqA/EDrN37JcgWfeYUVKJp/k3DPiwnMd; 25:Okv0wFjtNSYx8VrQRno9cknbBsF462pcoDQBN9h5hZhgWJN2lQLM4J5ksm9d1pnihbAX0D5KtLbYNGDnw5+ouAgkdonCxy0dHUqExZT6wJw6Vzle27o6PV3BDZNPQuVvs4semoK0rtYW6SKyjbIVsyTE8JkFye1VeTyb6DoihyMhHvl6NmkoKDmLC+sHgxGYVowPjM7NJ7ssvBg9yQGM/UpLqtYtBg2cps+B8Ma+nPZLa/rDu5zh61KYwI6M1dhLik4g0sGqwYXksCeQj+ANlHgcY6j6TIjUfQKQ57I6na59irEdgS/5mvlsFgs25MG0TpqPbqkrHp7Ux3XXJjpmPw==; 31:VTSr5blViy8x0vYq2I8ETsAEu6SAFRJR+/H7OtqlT7iNNPsJAkWjhDqrBhwYI4MXOBypgdFQtEIwd6e99saYrvlA1x1VuaGqpFkTiWyUblquB/C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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)(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:axrQ57j4sdhuDTn1vC+VTgDACY+ilJiyNbQ5jHPez?= =?us-ascii?Q?GWlLjxVyTM57DoAfe/435JF/npw9HAk7lj1CBZnV+f9ZvmOpfMAL+1FHOjFy?= =?us-ascii?Q?O+jTQ/sD834ZzpAxsIbCxhVIsgR/eL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Tsu6EK/faeFwMz+J6QV7kLnnjj0x+BLwgF8sO+a4A= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:NdgXPlt5YSWemN/K/iCN/IudPVVakhekBYLZl9aMv7lTPYwaPM9MbQnnS1FWBqGA9/JCVlTi0lDIx4l1nJuUV2neXOXnJ/3ioo5+7zq82cIhHEnrGZByoJVrkozeSC41pzehD5u/38yBqboHgC2eu3nXMRVsE7DsTx2O7KlUPe53zUIDZoaiP6MbVJ13PtdTPbmDxteHiT7fihWPFu3lWd2qL/DEXf+VwVM1VaUphNUe7J5e9r8aJAP4DSwe0fMc X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 12:22:58.3885 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [PATCH v3 02/23] OvmfPkg/Virtio10Dxe: implement IOMMU-like member 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: , X-List-Received-Date: Wed, 23 Aug 2017 12:20:26 -0000 Content-Type: text/plain The patch implements the newly added IOMMU-like member functions by respectively delegating the job to: - VIRTIO_DEVICE_PROTOCOL.AllocateSharedPages() -> EFI_PCI_IO_PROTOCOL.AllocateBuffer() - VIRTIO_DEVICE_PROTOCOL.FreeSharedPages() -> EFI_PCI_IO_PROTOCOL.FreeBuffer() - VIRTIO_DEVICE_PROTOCOL.MapSharedBuffer() -> EFI_PCI_IO_PROTOCOL.Map() - VIRTIO_DEVICE_PROTOCOL.UnmapSharedBuffer() -> EFI_PCI_IO_PROTOCOL.Unmap() 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/Virtio10Dxe/Virtio10.c | 122 +++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Virtio10Dxe/Virtio10.c b/OvmfPkg/Virtio10Dxe/Virtio10.c index d7ea4432bcb6..89ccac8c1c04 100644 --- a/OvmfPkg/Virtio10Dxe/Virtio10.c +++ b/OvmfPkg/Virtio10Dxe/Virtio10.c @@ -2,6 +2,7 @@ A non-transitional driver for VirtIo 1.0 PCI devices. Copyright (C) 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 @@ -15,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -772,6 +774,117 @@ Virtio10ReadDevice ( return Status; } +STATIC +EFI_STATUS +EFIAPI +Virtio10AllocateSharedPages ( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN UINTN Pages, + IN OUT VOID **HostAddress + ) +{ + VIRTIO_1_0_DEV *Dev; + EFI_STATUS Status; + + Dev = VIRTIO_1_0_FROM_VIRTIO_DEVICE (This); + + Status = Dev->PciIo->AllocateBuffer ( + Dev->PciIo, + AllocateAnyPages, + EfiBootServicesData, + Pages, + HostAddress, + EFI_PCI_ATTRIBUTE_MEMORY_CACHED + ); + return Status; +} + +STATIC +VOID +EFIAPI +Virtio10FreeSharedPages ( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN UINTN Pages, + IN VOID *HostAddress + ) +{ + VIRTIO_1_0_DEV *Dev; + + Dev = VIRTIO_1_0_FROM_VIRTIO_DEVICE (This); + + Dev->PciIo->FreeBuffer ( + Dev->PciIo, + Pages, + HostAddress + ); +} + +STATIC +EFI_STATUS +EFIAPI +Virtio10MapSharedBuffer ( + 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 + ) +{ + EFI_STATUS Status; + VIRTIO_1_0_DEV *Dev; + EFI_PCI_IO_PROTOCOL_OPERATION PciIoOperation; + + Dev = VIRTIO_1_0_FROM_VIRTIO_DEVICE (This); + + // + // Map VIRTIO_MAP_OPERATION to EFI_PCI_IO_PROTOCOL_OPERATION + // + switch (Operation) { + case VirtioOperationBusMasterRead: + PciIoOperation = EfiPciIoOperationBusMasterRead; + break; + case VirtioOperationBusMasterWrite: + PciIoOperation = EfiPciIoOperationBusMasterWrite; + break; + case VirtioOperationBusMasterCommonBuffer: + PciIoOperation = EfiPciIoOperationBusMasterCommonBuffer; + break; + default: + return EFI_INVALID_PARAMETER; + } + + Status = Dev->PciIo->Map ( + Dev->PciIo, + PciIoOperation, + HostAddress, + NumberOfBytes, + DeviceAddress, + Mapping + ); + return Status; +} + +STATIC +EFI_STATUS +EFIAPI +Virtio10UnmapSharedBuffer ( + IN VIRTIO_DEVICE_PROTOCOL *This, + IN VOID *Mapping + ) +{ + EFI_STATUS Status; + VIRTIO_1_0_DEV *Dev; + + Dev = VIRTIO_1_0_FROM_VIRTIO_DEVICE (This); + + Status = Dev->PciIo->Unmap ( + Dev->PciIo, + Mapping + ); + + return Status; +} STATIC CONST VIRTIO_DEVICE_PROTOCOL mVirtIoTemplate = { VIRTIO_SPEC_REVISION (1, 0, 0), @@ -788,7 +901,11 @@ STATIC CONST VIRTIO_DEVICE_PROTOCOL mVirtIoTemplate = { Virtio10GetDeviceStatus, Virtio10SetDeviceStatus, Virtio10WriteDevice, - Virtio10ReadDevice + Virtio10ReadDevice, + Virtio10AllocateSharedPages, + Virtio10FreeSharedPages, + Virtio10MapSharedBuffer, + Virtio10UnmapSharedBuffer }; @@ -906,7 +1023,8 @@ Virtio10BindingStart ( goto ClosePciIo; } - SetAttributes = EFI_PCI_IO_ATTRIBUTE_BUS_MASTER; + SetAttributes = (EFI_PCI_IO_ATTRIBUTE_BUS_MASTER | + EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE); UpdateAttributes (&Device->CommonConfig, &SetAttributes); UpdateAttributes (&Device->NotifyConfig, &SetAttributes); UpdateAttributes (&Device->SpecificConfig, &SetAttributes); -- 2.7.4