From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-x231.google.com (mail-io0-x231.google.com [IPv6:2607:f8b0:4001:c06::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4573221951CB5 for ; Tue, 2 May 2017 03:04:10 -0700 (PDT) Received: by mail-io0-x231.google.com with SMTP id r16so153277915ioi.2 for ; Tue, 02 May 2017 03:04:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=vlfqLiolVcqhHN5SMYehHIGI0ZnX4LrxE8CjJALBJis=; b=QENYYfZk0g2yk4E1qtpkPZ/qI/IPnLPdvrjirt5ihswwcVhM3o1dBff6T2ivTWF+j7 KQ8mYtSxPxeSpSkhvcsakaYfn7eofELDE0AdemaQtC7w4ruWmY5wYe2rVWWqCwJ72xjQ 1gNaeVDOUDctIvC47QckbJqsE6/n5P9NAZRKI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vlfqLiolVcqhHN5SMYehHIGI0ZnX4LrxE8CjJALBJis=; b=ofaA0/i7cBCkA3kInjYTq96NrJ4EQQoRDQsBpADdTYJ+L9rrmZgiASxbSu7RhGKnpN NuIU+hE0HlxLddFXjhHQ3fW7Z0YJd3gkhS3b0xiTKtewu+QJNzaPGFMzk/Fi0JkHvqmU utr+PKm9pzJT9bMgmIq2heZjTg+CTUFl1KFGS5F/CgVPTnvIcySRvbLAw+PEnH0RU7Jv uhNu9Y9fdzcYt9EvezlHg/hT4YsSoJrp8gTdo8KpYc98U7oUxKUWjcdIFZXl2yW/+tCu +Xq0uqhXvrYITRR8KbxFtkZ0XDr1/Tm19wC0uIgZ+pIeE09CBaaKEyXNZDcrKrKP+vs2 lgqw== X-Gm-Message-State: AN3rC/4hf8JvzON1xNYu7A7A2j04NTcHyebsIPfXC9IERhxGefFuZvRJ FgVCfSJ3fyigl2d0lmTrGKfz83iKdtcF X-Received: by 10.107.26.1 with SMTP id a1mr25609711ioa.72.1493719448758; Tue, 02 May 2017 03:04:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.201.76 with HTTP; Tue, 2 May 2017 03:04:08 -0700 (PDT) In-Reply-To: <1493473694-5064-4-git-send-email-jiewen.yao@intel.com> References: <1493473694-5064-1-git-send-email-jiewen.yao@intel.com> <1493473694-5064-4-git-send-email-jiewen.yao@intel.com> From: Ard Biesheuvel Date: Tue, 2 May 2017 11:04:08 +0100 Message-ID: To: Jiewen Yao Cc: "edk2-devel@lists.01.org" , Ruiyu Ni , Leo Duran , Brijesh Singh Subject: Re: [PATCH 3/3] MdeModulePkg/PciBus: Add IOMMU support. 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: Tue, 02 May 2017 10:04:10 -0000 Content-Type: text/plain; charset=UTF-8 On 29 April 2017 at 14:48, Jiewen Yao wrote: > If IOMMU protocol is installed, PciBus need call IOMMU > to set access attribute for the PCI device in Map/Ummap. > > Only after the access attribute is set, the PCI device can > access the DMA memory. > > Cc: Ruiyu Ni > Cc: Leo Duran > Cc: Brijesh Singh > Cc: Ard Biesheuvel > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jiewen Yao > --- > MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c | 9 +++++ > MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h | 1 + > MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf | 1 + > MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c | 37 ++++++++++++++++++++ > 4 files changed, 48 insertions(+) > > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c > index f3be47a..950cacc 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.c > @@ -42,6 +42,7 @@ UINT64 gAllZero = 0; > > EFI_PCI_PLATFORM_PROTOCOL *gPciPlatformProtocol; > EFI_PCI_OVERRIDE_PROTOCOL *gPciOverrideProtocol; > +EDKII_IOMMU_PROTOCOL *mIoMmuProtocol; > > > GLOBAL_REMOVE_IF_UNREFERENCED EFI_PCI_HOTPLUG_REQUEST_PROTOCOL mPciHotPlugRequest = { > @@ -284,6 +285,14 @@ PciBusDriverBindingStart ( > ); > } > > + if (mIoMmuProtocol == NULL) { > + gBS->LocateProtocol ( > + &gEdkiiIoMmuProtocolGuid, > + NULL, > + (VOID **) &mIoMmuProtocol > + ); > + } > + > if (PcdGetBool (PcdPciDisableBusEnumeration)) { > gFullEnumeration = FALSE; > } else { > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > index 39ba8b9..3bcc134 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > @@ -32,6 +32,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > #include > #include > #include > +#include > > #include > #include > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf > index a3ab11f..5da094f 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf > @@ -95,6 +95,7 @@ > gEfiPciRootBridgeIoProtocolGuid ## TO_START > gEfiIncompatiblePciDeviceSupportProtocolGuid ## SOMETIMES_CONSUMES > gEfiLoadFile2ProtocolGuid ## SOMETIMES_PRODUCES > + gEdkiiIoMmuProtocolGuid ## SOMETIMES_CONSUMES > > [FeaturePcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdPciBusHotplugDeviceSupport ## CONSUMES > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c > index f72598d..c0251c0 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c > @@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > > #include "PciBus.h" > > +extern EDKII_IOMMU_PROTOCOL *mIoMmuProtocol; > + > // > // Pci Io Protocol Interface > // > @@ -967,6 +969,7 @@ PciIoMap ( > { > EFI_STATUS Status; > PCI_IO_DEVICE *PciIoDevice; > + UINT64 IoMmuAttribute; > > PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This); > > @@ -999,6 +1002,31 @@ PciIoMap ( > ); > } > > + if (mIoMmuProtocol != NULL) { > + if (!EFI_ERROR (Status)) { > + switch (Operation) { > + case EfiPciIoOperationBusMasterRead: > + IoMmuAttribute = EDKII_IOMMU_ACCESS_READ; > + break; > + case EfiPciIoOperationBusMasterWrite: > + IoMmuAttribute = EDKII_IOMMU_ACCESS_WRITE; > + break; > + case EfiPciIoOperationBusMasterCommonBuffer: > + IoMmuAttribute = EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE; > + break; > + default: > + ASSERT(FALSE); > + return EFI_INVALID_PARAMETER; I am hitting this assert(). The reason is that Operation is modified if the EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE attribute is set, and so it does not have any of these values anymore. > + } > + mIoMmuProtocol->SetMappingAttribute ( > + mIoMmuProtocol, > + PciIoDevice->Handle, > + *Mapping, > + IoMmuAttribute > + ); > + } > + } > + > return Status; > } > > @@ -1024,6 +1052,15 @@ PciIoUnmap ( > > PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This); > > + if (mIoMmuProtocol != NULL) { > + mIoMmuProtocol->SetMappingAttribute ( > + mIoMmuProtocol, > + PciIoDevice->Handle, > + Mapping, > + 0 > + ); > + } > + > Status = PciIoDevice->PciRootBridgeIo->Unmap ( > PciIoDevice->PciRootBridgeIo, > Mapping > -- > 2.7.4.windows.1 >