From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 3236E821CB for ; Tue, 28 Feb 2017 18:53:56 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Feb 2017 18:53:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,223,1484035200"; d="scan'208";a="1116865961" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2017 18:53:52 -0800 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 28 Feb 2017 18:53:48 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX153.amr.corp.intel.com (10.18.125.6) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 28 Feb 2017 18:53:47 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.59]) by shsmsx102.ccr.corp.intel.com ([169.254.2.88]) with mapi id 14.03.0248.002; Wed, 1 Mar 2017 10:53:43 +0800 From: "Ni, Ruiyu" To: Leo Duran , "edk2-devel@ml01.01.org" CC: "Tian, Feng" , "Zeng, Star" Thread-Topic: [edk2] [PATCH v3 6/6] MdeModulePkg: Modify PciHostBridgeDxe to use new BmDmaLib class library Thread-Index: AQHSgvNSZfujvokLlEiPwM1EKZgdC6F/Z/IQ Date: Wed, 1 Mar 2017 02:53:43 +0000 Deferred-Delivery: Wed, 1 Mar 2017 02:53:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B8BB1D8@SHSMSX104.ccr.corp.intel.com> References: <1486658427-6551-1-git-send-email-leo.duran@amd.com> <1486658427-6551-7-git-send-email-leo.duran@amd.com> In-Reply-To: <1486658427-6551-7-git-send-email-leo.duran@amd.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3 6/6] MdeModulePkg: Modify PciHostBridgeDxe to use new BmDmaLib class library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Mar 2017 02:53:56 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ruiyu Ni Thanks/Ray > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Leo Duran > Sent: Friday, February 10, 2017 12:40 AM > To: edk2-devel@ml01.01.org > Cc: Tian, Feng ; Leo Duran ; > Zeng, Star > Subject: [edk2] [PATCH v3 6/6] MdeModulePkg: Modify PciHostBridgeDxe to > use new BmDmaLib class library >=20 > The BmDmaLib class library provides an abstraction layer for Bus-master D= MA > operations as currently implemented by the PciHostBridgeDxe driver. The > intent is to allow override of the library as required by specific hardwa= re > implementations, such as AMD's Secure Encrypted Virtualization (SEV). >=20 > Cc: Feng Tian > Cc: Star Zeng > Contributed-under: TianoCore Contribution Agreement 1.0 > signed-off-by: Leo Duran > --- > .../Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf | 1 + > .../Bus/Pci/PciHostBridgeDxe/PciRootBridge.h | 13 +- > .../Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c | 272 +++++----------= ------ > MdeModulePkg/MdeModulePkg.dsc | 1 + > 4 files changed, 67 insertions(+), 220 deletions(-) >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf > b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf > index d8b0439..35bb5c4 100644 > --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf > +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf > @@ -42,6 +42,7 @@ [LibraryClasses] > BaseLib > PciSegmentLib > PciHostBridgeLib > + BmDmaLib >=20 > [Protocols] > gEfiMetronomeArchProtocolGuid ## CONSUMES > diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h > b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h > index 13185b4..c125fcd 100644 > --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h > +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h > @@ -34,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. > #include > #include > #include > +#include > #include "PciHostResource.h" >=20 >=20 > @@ -43,17 +44,6 @@ typedef enum { > PciOperation > } OPERATION_TYPE; >=20 > -#define MAP_INFO_SIGNATURE SIGNATURE_32 ('_', 'm', 'a', 'p') -typedef > struct { > - UINT32 Signature; > - LIST_ENTRY Link; > - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation; > - UINTN NumberOfBytes; > - UINTN NumberOfPages; > - EFI_PHYSICAL_ADDRESS HostAddress; > - EFI_PHYSICAL_ADDRESS MappedHostAddress; > -} MAP_INFO; > -#define MAP_INFO_FROM_LINK(a) CR (a, MAP_INFO, Link, > MAP_INFO_SIGNATURE) >=20 > #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('_', 'p', 'r', 'b') >=20 > @@ -79,7 +69,6 @@ typedef struct { > EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL RootBridgeIo; >=20 > BOOLEAN ResourceSubmitted; > - LIST_ENTRY Maps; > } PCI_ROOT_BRIDGE_INSTANCE; >=20 > #define ROOT_BRIDGE_FROM_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, > RootBridgeIo, PCI_ROOT_BRIDGE_SIGNATURE) diff --git > a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c > b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c > index 8af131b..8a74bf6 100644 > --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c > +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c > @@ -17,7 +17,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. > #include "PciRootBridge.h" > #include "PciHostResource.h" >=20 > -#define NO_MAPPING (VOID *) (UINTN) -1 >=20 > // > // Lookup table for increment values based on transfer widths @@ -55,6 > +54,39 @@ UINT8 mOutStride[] =3D { > 0 // EfiPciWidthFillUint64 > }; >=20 > + > +BM_DMA_OPERATION > +ConvertDmaOperation ( > + IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION RbOperation > + ) > +{ > + BM_DMA_OPERATION BmOperation; > + > + switch (RbOperation) { > + case EfiPciOperationBusMasterRead: > + case EfiPciOperationBusMasterRead64: > + BmOperation =3D DmaOperationBusMasterRead; > + break; > + > + case EfiPciOperationBusMasterWrite: > + case EfiPciOperationBusMasterWrite64: > + BmOperation =3D DmaOperationBusMasterWrite; > + break; > + > + case EfiPciOperationBusMasterCommonBuffer: > + case EfiPciOperationBusMasterCommonBuffer64: > + BmOperation =3D DmaOperationBusMasterCommonBuffer; > + break; > + > + default: > + BmOperation =3D DmaOperationBusMasterMaximum; > + break; > + } > + > + return BmOperation; > +} > + > + > /** > Construct the Pci Root Bridge instance. >=20 > @@ -168,7 +200,6 @@ CreateRootBridge ( > TypeMax * sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof > (EFI_ACPI_END_TAG_DESCRIPTOR) > ); > ASSERT (RootBridge->ConfigBuffer !=3D NULL); > - InitializeListHead (&RootBridge->Maps); >=20 > CopyMem (&RootBridge->Bus, &Bridge->Bus, sizeof > (PCI_ROOT_BRIDGE_APERTURE)); > CopyMem (&RootBridge->Io, &Bridge->Io, sizeof > (PCI_ROOT_BRIDGE_APERTURE)); @@ -1053,118 +1084,27 @@ > RootBridgeIoMap ( > OUT VOID **Mapping > ) > { > - EFI_STATUS Status; > - PCI_ROOT_BRIDGE_INSTANCE *RootBridge; > - EFI_PHYSICAL_ADDRESS PhysicalAddress; > - MAP_INFO *MapInfo; > - > - if (HostAddress =3D=3D NULL || NumberOfBytes =3D=3D NULL || DeviceAddr= ess =3D=3D > NULL || > - Mapping =3D=3D NULL) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // Make sure that Operation is valid > - // > - if ((UINT32) Operation >=3D EfiPciOperationMaximum) { > - return EFI_INVALID_PARAMETER; > - } > + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; > + BOOLEAN DmaAbove4GB; > + BM_DMA_OPERATION BmOperation; >=20 > RootBridge =3D ROOT_BRIDGE_FROM_THIS (This); > - > - PhysicalAddress =3D (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress; > - if ((!RootBridge->DmaAbove4G || > - (Operation !=3D EfiPciOperationBusMasterRead64 && > - Operation !=3D EfiPciOperationBusMasterWrite64 && > - Operation !=3D EfiPciOperationBusMasterCommonBuffer64)) && > - ((PhysicalAddress + *NumberOfBytes) > SIZE_4GB)) { > - > - // > - // If the root bridge or the device cannot handle performing DMA abo= ve > - // 4GB but any part of the DMA transfer being mapped is above 4GB, t= hen > - // map the DMA transfer to a buffer below 4GB. > - // > - > - if (Operation =3D=3D EfiPciOperationBusMasterCommonBuffer || > - Operation =3D=3D EfiPciOperationBusMasterCommonBuffer64) { > - // > - // Common Buffer operations can not be remapped. If the common > buffer > - // if above 4GB, then it is not possible to generate a mapping, so= return > - // an error. > - // > - return EFI_UNSUPPORTED; > - } > - > - // > - // Allocate a MAP_INFO structure to remember the mapping when > Unmap() is > - // called later. > - // > - MapInfo =3D AllocatePool (sizeof (MAP_INFO)); > - if (MapInfo =3D=3D NULL) { > - *NumberOfBytes =3D 0; > - return EFI_OUT_OF_RESOURCES; > - } > - > - // > - // Initialize the MAP_INFO structure > - // > - MapInfo->Signature =3D MAP_INFO_SIGNATURE; > - MapInfo->Operation =3D Operation; > - MapInfo->NumberOfBytes =3D *NumberOfBytes; > - MapInfo->NumberOfPages =3D EFI_SIZE_TO_PAGES (MapInfo- > >NumberOfBytes); > - MapInfo->HostAddress =3D PhysicalAddress; > - MapInfo->MappedHostAddress =3D SIZE_4GB - 1; > - > - // > - // Allocate a buffer below 4GB to map the transfer to. > - // > - Status =3D gBS->AllocatePages ( > - AllocateMaxAddress, > - EfiBootServicesData, > - MapInfo->NumberOfPages, > - &MapInfo->MappedHostAddress > - ); > - if (EFI_ERROR (Status)) { > - FreePool (MapInfo); > - *NumberOfBytes =3D 0; > - return Status; > - } > - > - // > - // If this is a read operation from the Bus Master's point of view, > - // then copy the contents of the real buffer into the mapped buffer > - // so the Bus Master can read the contents of the real buffer. > - // > - if (Operation =3D=3D EfiPciOperationBusMasterRead || > - Operation =3D=3D EfiPciOperationBusMasterRead64) { > - CopyMem ( > - (VOID *) (UINTN) MapInfo->MappedHostAddress, > - (VOID *) (UINTN) MapInfo->HostAddress, > - MapInfo->NumberOfBytes > - ); > - } > - > - InsertTailList (&RootBridge->Maps, &MapInfo->Link); > - > - // > - // The DeviceAddress is the address of the maped buffer below 4GB > - // > - *DeviceAddress =3D MapInfo->MappedHostAddress; > - // > - // Return a pointer to the MAP_INFO structure in Mapping > - // > - *Mapping =3D MapInfo; > - } else { > - // > - // If the root bridge CAN handle performing DMA above 4GB or > - // the transfer is below 4GB, so the DeviceAddress is simply the > - // HostAddress > - // > - *DeviceAddress =3D PhysicalAddress; > - *Mapping =3D NO_MAPPING; > - } > - > - return EFI_SUCCESS; > + DmaAbove4GB =3D RootBridge->DmaAbove4G && ( > + Operation =3D=3D EfiPciOperationBusMasterRead64 || > + Operation =3D=3D EfiPciOperationBusMasterWrite64 || > + Operation =3D=3D EfiPciOperationBusMasterCommonBuffer6= 4 > + ); > + > + BmOperation =3D ConvertDmaOperation (Operation); > + > + return BmDmaMap ( > + DmaAbove4GB, > + BmOperation, > + HostAddress, > + NumberOfBytes, > + DeviceAddress, > + Mapping > + ); > } >=20 > /** > @@ -1191,58 +1131,7 @@ RootBridgeIoUnmap ( > IN VOID *Mapping > ) > { > - MAP_INFO *MapInfo; > - LIST_ENTRY *Link; > - PCI_ROOT_BRIDGE_INSTANCE *RootBridge; > - > - RootBridge =3D ROOT_BRIDGE_FROM_THIS (This); > - // > - // See if the Map() operation associated with this Unmap() required a > mapping > - // buffer. If a mapping buffer was not required, then this function si= mply > - // returns EFI_SUCCESS. > - // > - if (Mapping =3D=3D NO_MAPPING) { > - return EFI_SUCCESS; > - } > - > - MapInfo =3D NO_MAPPING; > - for (Link =3D GetFirstNode (&RootBridge->Maps) > - ; !IsNull (&RootBridge->Maps, Link) > - ; Link =3D GetNextNode (&RootBridge->Maps, Link) > - ) { > - MapInfo =3D MAP_INFO_FROM_LINK (Link); > - if (MapInfo =3D=3D Mapping) { > - break; > - } > - } > - // > - // Mapping is not a valid value returned by Map() > - // > - if (MapInfo !=3D Mapping) { > - return EFI_INVALID_PARAMETER; > - } > - RemoveEntryList (&MapInfo->Link); > - > - // > - // If this is a write operation from the Bus Master's point of view, > - // then copy the contents of the mapped buffer into the real buffer > - // so the processor can read the contents of the real buffer. > - // > - if (MapInfo->Operation =3D=3D EfiPciOperationBusMasterWrite || > - MapInfo->Operation =3D=3D EfiPciOperationBusMasterWrite64) { > - CopyMem ( > - (VOID *) (UINTN) MapInfo->HostAddress, > - (VOID *) (UINTN) MapInfo->MappedHostAddress, > - MapInfo->NumberOfBytes > - ); > - } > - > - // > - // Free the mapped buffer and the MAP_INFO structure. > - // > - gBS->FreePages (MapInfo->MappedHostAddress, MapInfo- > >NumberOfPages); > - FreePool (Mapping); > - return EFI_SUCCESS; > + return BmDmaUnmap (Mapping); > } >=20 > /** > @@ -1282,56 +1171,23 @@ RootBridgeIoAllocateBuffer ( > IN UINT64 Attributes > ) > { > - EFI_STATUS Status; > - EFI_PHYSICAL_ADDRESS PhysicalAddress; > - PCI_ROOT_BRIDGE_INSTANCE *RootBridge; > - EFI_ALLOCATE_TYPE AllocateType; > + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; > + BOOLEAN DmaAbove4GB; >=20 > - // > - // Validate Attributes > - // > if ((Attributes & EFI_PCI_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER) !=3D > 0) { > return EFI_UNSUPPORTED; > } >=20 > - // > - // Check for invalid inputs > - // > - if (HostAddress =3D=3D NULL) { > - return EFI_INVALID_PARAMETER; > - } > - > - // > - // The only valid memory types are EfiBootServicesData and > - // EfiRuntimeServicesData > - // > - if (MemoryType !=3D EfiBootServicesData && > - MemoryType !=3D EfiRuntimeServicesData) { > - return EFI_INVALID_PARAMETER; > - } > - > RootBridge =3D ROOT_BRIDGE_FROM_THIS (This); > + DmaAbove4GB =3D RootBridge->DmaAbove4G && > + (Attributes & EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE) > + !=3D 0; >=20 > - AllocateType =3D AllocateAnyPages; > - if (!RootBridge->DmaAbove4G || > - (Attributes & EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE) =3D=3D 0) { > - // > - // Limit allocations to memory below 4GB > - // > - AllocateType =3D AllocateMaxAddress; > - PhysicalAddress =3D (EFI_PHYSICAL_ADDRESS) (SIZE_4GB - 1); > - } > - Status =3D gBS->AllocatePages ( > - AllocateType, > - MemoryType, > - Pages, > - &PhysicalAddress > - ); > - if (!EFI_ERROR (Status)) { > - *HostAddress =3D (VOID *) (UINTN) PhysicalAddress; > - } > - > - return Status; > + return BmDmaAllocateBuffer ( > + DmaAbove4GB, > + MemoryType, > + Pages, > + HostAddress > + ); > } >=20 > /** > @@ -1356,7 +1212,7 @@ RootBridgeIoFreeBuffer ( > OUT VOID *HostAddress > ) > { > - return gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress, > Pages); > + return BmDmaFreeBuffer (Pages, HostAddress); > } >=20 > /** > diff --git a/MdeModulePkg/MdeModulePkg.dsc > b/MdeModulePkg/MdeModulePkg.dsc index b343c19..47aa9b9 100644 > --- a/MdeModulePkg/MdeModulePkg.dsc > +++ b/MdeModulePkg/MdeModulePkg.dsc > @@ -83,6 +83,7 @@ [LibraryClasses] > PalLib|MdePkg/Library/BasePalLibNull/BasePalLibNull.inf >=20 > CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Custo > mizedDisplayLib.inf >=20 > FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBuffer > BltLib.inf > + BmDmaLib|MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.inf > # > # Misc > # > -- > 1.9.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel