From nobody Sun Apr 28 04:36:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1517914067199565.7557875801502; Tue, 6 Feb 2018 02:47:47 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 59471223AF831; Tue, 6 Feb 2018 02:42:02 -0800 (PST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 5A42A222A3345 for ; Tue, 6 Feb 2018 02:42:00 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2018 02:47:43 -0800 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga002.fm.intel.com with ESMTP; 06 Feb 2018 02:47:42 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,468,1511856000"; d="scan'208";a="17455442" From: Star Zeng To: edk2-devel@lists.01.org Date: Tue, 6 Feb 2018 18:47:37 +0800 Message-Id: <1517914059-10980-2-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1517914059-10980-1-git-send-email-star.zeng@intel.com> References: <1517914059-10980-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH 1/3] IntelSiliconPkg IntelVTdPmrPei: Install IoMmu PPI before enabling PMR X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiewen Yao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Then the consumer of IoMmu PPI has opportunity to get granted DMA buffer (by callback) to replace old buffer before it is forbidden by enabling PMR. Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Jiewen.yao@intel.com --- .../Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c | 63 ++++++++++--------= ---- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c b/= IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c index 63ba94d62b7e..87708cfcddda 100644 --- a/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c +++ b/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c @@ -381,17 +381,13 @@ CONST EFI_PEI_PPI_DESCRIPTOR mIoMmuPpiList =3D { Initialize DMA protection. =20 @param VTdInfo The VTd engine context information. - @param DmaBufferSize the DMA buffer size - @param DmaBufferBase the DMA buffer base =20 @retval EFI_SUCCESS the DMA protection is initialized. @retval EFI_OUT_OF_RESOURCES no enough resource to initialize DMA prote= ction. **/ EFI_STATUS InitDmaProtection ( - IN VTD_INFO *VTdInfo, - IN UINTN DmaBufferSize, - OUT UINTN *DmaBufferBase + IN VTD_INFO *VTdInfo ) { EFI_STATUS Status; @@ -402,6 +398,13 @@ InitDmaProtection ( UINTN LowTop; UINTN HighBottom; UINT64 HighTop; + DMA_BUFFER_INFO *DmaBufferInfo; + VOID *Hob; + + Hob =3D GetFirstGuidHob (&mDmaBufferInfoGuid); + DmaBufferInfo =3D GET_GUID_HOB_DATA(Hob); + + DEBUG ((DEBUG_INFO, " DmaBufferSize : 0x%x\n", DmaBufferInfo->DmaBufferS= ize)); =20 LowMemoryAlignment =3D GetLowMemoryAlignment (VTdInfo, VTdInfo->EngineMa= sk); HighMemoryAlignment =3D GetHighMemoryAlignment (VTdInfo, VTdInfo->Engine= Mask); @@ -410,17 +413,28 @@ InitDmaProtection ( } else { MemoryAlignment =3D LowMemoryAlignment; } - ASSERT (DmaBufferSize =3D=3D ALIGN_VALUE(DmaBufferSize, MemoryAlignment)= ); - *DmaBufferBase =3D (UINTN)AllocateAlignedPages (EFI_SIZE_TO_PAGES(DmaBuf= ferSize), MemoryAlignment); - ASSERT (*DmaBufferBase !=3D 0); - if (*DmaBufferBase =3D=3D 0) { + ASSERT (DmaBufferInfo->DmaBufferSize =3D=3D ALIGN_VALUE(DmaBufferInfo->D= maBufferSize, MemoryAlignment)); + DmaBufferInfo->DmaBufferBase =3D (UINTN)AllocateAlignedPages (EFI_SIZE_T= O_PAGES(DmaBufferInfo->DmaBufferSize), MemoryAlignment); + ASSERT (DmaBufferInfo->DmaBufferBase !=3D 0); + if (DmaBufferInfo->DmaBufferBase =3D=3D 0) { DEBUG ((DEBUG_INFO, " InitDmaProtection : OutOfResource\n")); return EFI_OUT_OF_RESOURCES; } =20 + DEBUG ((DEBUG_INFO, " DmaBufferBase : 0x%x\n", DmaBufferInfo->DmaBufferB= ase)); + + DmaBufferInfo->DmaBufferCurrentTop =3D DmaBufferInfo->DmaBufferBase + Dm= aBufferInfo->DmaBufferSize; + DmaBufferInfo->DmaBufferCurrentBottom =3D DmaBufferInfo->DmaBufferBase; + + // + // Install PPI. + // + Status =3D PeiServicesInstallPpi (&mIoMmuPpiList); + ASSERT_EFI_ERROR(Status); + LowBottom =3D 0; - LowTop =3D *DmaBufferBase; - HighBottom =3D *DmaBufferBase + DmaBufferSize; + LowTop =3D DmaBufferInfo->DmaBufferBase; + HighBottom =3D DmaBufferInfo->DmaBufferBase + DmaBufferInfo->DmaBufferSi= ze; HighTop =3D LShiftU64 (1, VTdInfo->HostAddressWidth + 1); =20 Status =3D SetDmaProtectedRange ( @@ -433,7 +447,7 @@ InitDmaProtection ( ); =20 if (EFI_ERROR(Status)) { - FreePages ((VOID *)*DmaBufferBase, EFI_SIZE_TO_PAGES(DmaBufferSize)); + FreePages ((VOID *)DmaBufferInfo->DmaBufferBase, EFI_SIZE_TO_PAGES(Dma= BufferInfo->DmaBufferSize)); } =20 return Status; @@ -543,7 +557,6 @@ InitVTdPmrForDma ( EFI_STATUS Status; VOID *Hob; VTD_INFO *VTdInfo; - DMA_BUFFER_INFO *DmaBufferInfo; =20 Hob =3D GetFirstGuidHob (&mVTdInfoGuid); VTdInfo =3D GET_GUID_HOB_DATA(Hob); @@ -553,29 +566,11 @@ InitVTdPmrForDma ( // ParseDmarAcpiTableRmrr (VTdInfo); =20 - Hob =3D GetFirstGuidHob (&mDmaBufferInfoGuid); - DmaBufferInfo =3D GET_GUID_HOB_DATA(Hob); - - DEBUG ((DEBUG_INFO, " DmaBufferSize : 0x%x\n", DmaBufferInfo->DmaBufferS= ize)); - // - // Find a pre-memory in resource hob as DMA buffer - // Mark PEI memory to be DMA protected. - // - Status =3D InitDmaProtection (VTdInfo, DmaBufferInfo->DmaBufferSize, &Dm= aBufferInfo->DmaBufferBase); - if (EFI_ERROR(Status)) { - return Status; - } - - DEBUG ((DEBUG_INFO, " DmaBufferBase : 0x%x\n", DmaBufferInfo->DmaBufferB= ase)); - - DmaBufferInfo->DmaBufferCurrentTop =3D DmaBufferInfo->DmaBufferBase + Dm= aBufferInfo->DmaBufferSize; - DmaBufferInfo->DmaBufferCurrentBottom =3D DmaBufferInfo->DmaBufferBase; - // - // Install PPI. + // Allocate a range in PEI memory as DMA buffer + // Mark others to be DMA protected. // - Status =3D PeiServicesInstallPpi (&mIoMmuPpiList); - ASSERT_EFI_ERROR(Status); + Status =3D InitDmaProtection (VTdInfo); =20 return Status; } --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun Apr 28 04:36:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1517914069638243.30750588353703; Tue, 6 Feb 2018 02:47:49 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C383E223AF839; Tue, 6 Feb 2018 02:42:03 -0800 (PST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 24BD0223AF826 for ; Tue, 6 Feb 2018 02:42:01 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2018 02:47:43 -0800 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga002.fm.intel.com with ESMTP; 06 Feb 2018 02:47:43 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,468,1511856000"; d="scan'208";a="17455446" From: Star Zeng To: edk2-devel@lists.01.org Date: Tue, 6 Feb 2018 18:47:38 +0800 Message-Id: <1517914059-10980-3-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1517914059-10980-1-git-send-email-star.zeng@intel.com> References: <1517914059-10980-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH 2/3] MdeModulePkg Ppi/IoMmu.h: Add EFI_NOT_AVAILABLE_YET return status code X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiewen Yao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Install IOMMU PPI for pre-memory phase and return EFI_NOT_AVAILABLE_YET to indicate that DMA protection has been enabled, but DMA buffer are not available to be allocated yet. Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Jiewen.yao@intel.com --- MdeModulePkg/Include/Ppi/IoMmu.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Include/Ppi/IoMmu.h b/MdeModulePkg/Include/Ppi/Io= Mmu.h index ed8cd540a21f..0dfe6f4d4b44 100644 --- a/MdeModulePkg/Include/Ppi/IoMmu.h +++ b/MdeModulePkg/Include/Ppi/IoMmu.h @@ -1,7 +1,7 @@ /** @file PEI IOMMU PPI. =20 -Copyright (c) 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availabl= e under the terms and conditions of the BSD License that accompanies this distribu= tion. The full text of the license may be found at @@ -69,6 +69,8 @@ typedef struct _EDKII_IOMMU_PPI EDKII_IOMMU_PPI; @retval EFI_UNSUPPORTED The IOMMU does not support the memory ran= ge specified by Mapping. @retval EFI_OUT_OF_RESOURCES There are not enough resources available = to modify the IOMMU access. @retval EFI_DEVICE_ERROR The IOMMU device reported an error while = attempting the operation. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA = buffer are + not available to be allocated yet. =20 **/ typedef @@ -97,6 +99,8 @@ EFI_STATUS @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 requ= ested address. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are + not available to be allocated yet. =20 **/ typedef @@ -119,6 +123,9 @@ EFI_STATUS @retval EFI_SUCCESS The range was unmapped. @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned b= y Map(). @retval EFI_DEVICE_ERROR The data was not committed to the target s= ystem memory. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are + not available to be allocated yet. + **/ typedef EFI_STATUS @@ -144,6 +151,8 @@ EFI_STATUS MEMORY_WRITE_COMBINE, MEMORY_CACHED and DU= AL_ADDRESS_CYCLE. @retval EFI_INVALID_PARAMETER One or more parameters are invalid. @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are + not available to be allocated yet. =20 **/ typedef @@ -159,13 +168,15 @@ EFI_STATUS /** Frees memory that was allocated with AllocateBuffer(). =20 - @param This The protocol instance pointer. + @param This The PPI instance pointer. @param Pages The number of pages to free. @param HostAddress The base system memory address of the allo= cated range. =20 @retval EFI_SUCCESS The requested memory pages were freed. @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress = and Pages was not allocated with AllocateBuffer(). + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are + not available to be allocated yet. =20 **/ typedef --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun Apr 28 04:36:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 151791407241785.61000755907287; Tue, 6 Feb 2018 02:47:52 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3C594223AF83E; Tue, 6 Feb 2018 02:42:04 -0800 (PST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 EA11E223AF82B for ; Tue, 6 Feb 2018 02:42:01 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2018 02:47:44 -0800 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga002.fm.intel.com with ESMTP; 06 Feb 2018 02:47:43 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,468,1511856000"; d="scan'208";a="17455453" From: Star Zeng To: edk2-devel@lists.01.org Date: Tue, 6 Feb 2018 18:47:39 +0800 Message-Id: <1517914059-10980-4-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1517914059-10980-1-git-send-email-star.zeng@intel.com> References: <1517914059-10980-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH 3/3] IntelSiliconPkg IntelVTdPmrPei: Install IOMMU PPI for pre-memory phase X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiewen Yao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Install IOMMU PPI for pre-memory phase and return EFI_NOT_AVAILABLE_YET to indicate that DMA protection has been enabled, but DMA buffer are not available to be allocated yet. Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Jiewen.yao@intel.com --- .../Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c | 77 ++++++++++++++++++= ---- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c b/= IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c index 87708cfcddda..c6a1ccdb1b35 100644 --- a/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c +++ b/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c @@ -112,6 +112,8 @@ typedef struct { @retval EFI_UNSUPPORTED The IOMMU does not support the memory ran= ge specified by Mapping. @retval EFI_OUT_OF_RESOURCES There are not enough resources available = to modify the IOMMU access. @retval EFI_DEVICE_ERROR The IOMMU device reported an error while = attempting the operation. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA = buffer are + not available to be allocated yet. =20 **/ EFI_STATUS @@ -122,6 +124,16 @@ PeiIoMmuSetAttribute ( IN UINT64 IoMmuAccess ) { + VOID *Hob; + DMA_BUFFER_INFO *DmaBufferInfo; + + Hob =3D GetFirstGuidHob (&mDmaBufferInfoGuid); + DmaBufferInfo =3D GET_GUID_HOB_DATA(Hob); + + if (DmaBufferInfo->DmaBufferCurrentTop =3D=3D 0) { + return EFI_NOT_AVAILABLE_YET; + } + return EFI_SUCCESS; } =20 @@ -143,6 +155,8 @@ PeiIoMmuSetAttribute ( @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 requ= ested address. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are + not available to be allocated yet. =20 **/ EFI_STATUS @@ -164,6 +178,14 @@ PeiIoMmuMap ( Hob =3D GetFirstGuidHob (&mDmaBufferInfoGuid); DmaBufferInfo =3D GET_GUID_HOB_DATA(Hob); =20 + DEBUG ((DEBUG_VERBOSE, "PeiIoMmuMap - HostAddress - 0x%x, NumberOfBytes = - %x\n", HostAddress, *NumberOfBytes)); + DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentTop - %x\n", DmaBufferInfo->Dm= aBufferCurrentTop)); + DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentBottom - %x\n", DmaBufferInfo-= >DmaBufferCurrentBottom)); + + if (DmaBufferInfo->DmaBufferCurrentTop =3D=3D 0) { + return EFI_NOT_AVAILABLE_YET; + } + if (Operation =3D=3D EdkiiIoMmuOperationBusMasterCommonBuffer || Operation =3D=3D EdkiiIoMmuOperationBusMasterCommonBuffer64) { *DeviceAddress =3D (UINTN)HostAddress; @@ -171,10 +193,6 @@ PeiIoMmuMap ( return EFI_SUCCESS; } =20 - DEBUG ((DEBUG_VERBOSE, "PeiIoMmuMap - HostAddress - 0x%x, NumberOfBytes = - %x\n", HostAddress, *NumberOfBytes)); - DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentTop - %x\n", DmaBufferInfo->Dm= aBufferCurrentTop)); - DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentBottom - %x\n", DmaBufferInfo-= >DmaBufferCurrentBottom)); - Length =3D *NumberOfBytes + sizeof(MAP_INFO); if (Length > DmaBufferInfo->DmaBufferCurrentTop - DmaBufferInfo->DmaBuff= erCurrentBottom) { DEBUG ((DEBUG_ERROR, "PeiIoMmuMap - OUT_OF_RESOURCE\n")); @@ -220,6 +238,9 @@ PeiIoMmuMap ( @retval EFI_SUCCESS The range was unmapped. @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned b= y Map(). @retval EFI_DEVICE_ERROR The data was not committed to the target s= ystem memory. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are + not available to be allocated yet. + **/ EFI_STATUS EFIAPI @@ -236,14 +257,18 @@ PeiIoMmuUnmap ( Hob =3D GetFirstGuidHob (&mDmaBufferInfoGuid); DmaBufferInfo =3D GET_GUID_HOB_DATA(Hob); =20 - if (Mapping =3D=3D NULL) { - return EFI_SUCCESS; - } - DEBUG ((DEBUG_VERBOSE, "PeiIoMmuUnmap - Mapping - %x\n", Mapping)); DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentTop - %x\n", DmaBufferInfo->Dm= aBufferCurrentTop)); DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentBottom - %x\n", DmaBufferInfo-= >DmaBufferCurrentBottom)); =20 + if (DmaBufferInfo->DmaBufferCurrentTop =3D=3D 0) { + return EFI_NOT_AVAILABLE_YET; + } + + if (Mapping =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + MapInfo =3D Mapping; ASSERT (MapInfo->Signature =3D=3D MAP_INFO_SIGNATURE); DEBUG ((DEBUG_VERBOSE, " Op(%x):DeviceAddress - %x, NumberOfBytes - %x\= n", MapInfo->Operation, (UINTN)MapInfo->DeviceAddress, MapInfo->NumberOfByt= es)); @@ -287,6 +312,8 @@ PeiIoMmuUnmap ( MEMORY_WRITE_COMBINE, MEMORY_CACHED and DU= AL_ADDRESS_CYCLE. @retval EFI_INVALID_PARAMETER One or more parameters are invalid. @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are + not available to be allocated yet. =20 **/ EFI_STATUS @@ -310,6 +337,10 @@ PeiIoMmuAllocateBuffer ( DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentTop - %x\n", DmaBufferInfo->Dm= aBufferCurrentTop)); DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentBottom - %x\n", DmaBufferInfo-= >DmaBufferCurrentBottom)); =20 + if (DmaBufferInfo->DmaBufferCurrentTop =3D=3D 0) { + return EFI_NOT_AVAILABLE_YET; + } + Length =3D EFI_PAGES_TO_SIZE(Pages); if (Length > DmaBufferInfo->DmaBufferCurrentTop - DmaBufferInfo->DmaBuff= erCurrentBottom) { DEBUG ((DEBUG_ERROR, "PeiIoMmuAllocateBuffer - OUT_OF_RESOURCE\n")); @@ -333,6 +364,8 @@ PeiIoMmuAllocateBuffer ( @retval EFI_SUCCESS The requested memory pages were freed. @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress = and Pages was not allocated with AllocateBuffer(). + @retval EFI_NOT_AVAILABLE_YET DMA protection has been enabled, but DMA b= uffer are + not available to be allocated yet. =20 **/ EFI_STATUS @@ -354,6 +387,10 @@ PeiIoMmuFreeBuffer ( DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentTop - %x\n", DmaBufferInfo->Dm= aBufferCurrentTop)); DEBUG ((DEBUG_VERBOSE, " DmaBufferCurrentBottom - %x\n", DmaBufferInfo-= >DmaBufferCurrentBottom)); =20 + if (DmaBufferInfo->DmaBufferCurrentTop =3D=3D 0) { + return EFI_NOT_AVAILABLE_YET; + } + Length =3D EFI_PAGES_TO_SIZE(Pages); if ((UINTN)HostAddress =3D=3D DmaBufferInfo->DmaBufferCurrentTop) { DmaBufferInfo->DmaBufferCurrentTop +=3D Length; @@ -400,6 +437,8 @@ InitDmaProtection ( UINT64 HighTop; DMA_BUFFER_INFO *DmaBufferInfo; VOID *Hob; + EFI_PEI_PPI_DESCRIPTOR *OldDescriptor; + EDKII_IOMMU_PPI *OldIoMmuPpi; =20 Hob =3D GetFirstGuidHob (&mDmaBufferInfoGuid); DmaBufferInfo =3D GET_GUID_HOB_DATA(Hob); @@ -427,10 +466,20 @@ InitDmaProtection ( DmaBufferInfo->DmaBufferCurrentBottom =3D DmaBufferInfo->DmaBufferBase; =20 // - // Install PPI. + // (Re)Install PPI. // - Status =3D PeiServicesInstallPpi (&mIoMmuPpiList); - ASSERT_EFI_ERROR(Status); + Status =3D PeiServicesLocatePpi ( + &gEdkiiIoMmuPpiGuid, + 0, + &OldDescriptor, + (VOID **) &OldIoMmuPpi + ); + if (!EFI_ERROR (Status)) { + Status =3D PeiServicesReInstallPpi (OldDescriptor, &mIoMmuPpiList); + } else { + Status =3D PeiServicesInstallPpi (&mIoMmuPpiList); + } + ASSERT_EFI_ERROR (Status); =20 LowBottom =3D 0; LowTop =3D DmaBufferInfo->DmaBufferBase; @@ -668,6 +717,12 @@ VTdInfoNotify ( // InitVTdInfo (); InitVTdPmrForAll (); + + // + // Install PPI. + // + Status =3D PeiServicesInstallPpi (&mIoMmuPpiList); + ASSERT_EFI_ERROR(Status); } else { // // If the memory is initialized, --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel