From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 86DBF21E47D54 for ; Wed, 23 Aug 2017 12:11:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D923C056791; Wed, 23 Aug 2017 19:13:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1D923C056791 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-43.phx2.redhat.com [10.3.116.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id A26BA5D98B; Wed, 23 Aug 2017 19:13:52 +0000 (UTC) To: Brijesh Singh , edk2-devel@lists.01.org Cc: Jordan Justen , Tom Lendacky , Ard Biesheuvel References: <1503490967-5559-1-git-send-email-brijesh.singh@amd.com> <1503490967-5559-3-git-send-email-brijesh.singh@amd.com> From: Laszlo Ersek Message-ID: <189f42c7-9fbd-f1f7-41d9-6e5cc09c6ff9@redhat.com> Date: Wed, 23 Aug 2017 21:13:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1503490967-5559-3-git-send-email-brijesh.singh@amd.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 23 Aug 2017 19:13:54 +0000 (UTC) Subject: Re: [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 19:11:20 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 08/23/17 14:22, Brijesh Singh wrote: > 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(-) Reviewed-by: Laszlo Ersek Thanks! Laszlo > 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); >