From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: jiewen.yao@intel.com) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by groups.io with SMTP; Fri, 09 Aug 2019 05:34:40 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Aug 2019 05:34:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,364,1559545200"; d="scan'208";a="180128139" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga006.jf.intel.com with ESMTP; 09 Aug 2019 05:34:39 -0700 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 9 Aug 2019 05:34:38 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 9 Aug 2019 05:34:38 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.19]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.139]) with mapi id 14.03.0439.000; Fri, 9 Aug 2019 20:34:35 +0800 From: "Yao, Jiewen" To: "devel@edk2.groups.io" , "Wang, Iwen Evelyn" CC: "Huang, Jenny" , "Shih, More" , "Ni, Ray" , "Chaganty, Rangasai V" Subject: Re: [edk2-devel] [PATCH] IntelSiliconPkg-Vtd: A new PMR interface Thread-Topic: [edk2-devel] [PATCH] IntelSiliconPkg-Vtd: A new PMR interface Thread-Index: AQHVTjRBvUaeNk+7IkmbKkKu/ORbeqbyu2AQ Date: Fri, 9 Aug 2019 12:34:34 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503F74D717@shsmsx102.ccr.corp.intel.com> References: <20190808215158.8408-1-iwen.evelyn.wang@intel.com> In-Reply-To: <20190808215158.8408-1-iwen.evelyn.wang@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYTE1NDFhZTQtOTNjOC00ZTgyLTgwNzMtNDRlNjY1OWM4MjFmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiUDBuV3cxZ1h0NDJGclVHK1p6ZkVJK3BuMXRXSkFVd2ZwYkU2cDVRV0ttTTkreWZJblJtdmU5SGFYaUZYd2t0ViJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: jiewen.yao@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks Evelyn Comments below: 1) The EFIAPI is missing in library API. Please follow EDKII coding standa= rd. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D UINTN GetGlobalVtdPmrAlignment ( ); =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Should be: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D UINTN EFIAPI GetGlobalVtdPmrAlignment ( VOID ); =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 2) Because you added a new library dependency, please make sure you did no= t break any other platform. For example, the one in KabylakeOpenBoardPkg, w= hich will consume VTd drivers. 3) Please replace below BIT0 with meaningful MACRO, in MdePkg\Include\Indu= stryStandard\DmaRemappingReportingTable.h if ((DrhdHeader->Flags & BIT0) =3D=3D BIT0) { 4) GetVtdPmrAlignmentLib seems only work in PEI phase. Please rename it to= be PeiGetVtdPmrAlignmentLib. 5) In IntelVTdPmrPei.c the indent should be 2 spaces. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D if (SysMemHobPtr =3D=3D NULL) { // // Calcuate the PMR memory alignment // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Should be =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D if (SysMemHobPtr =3D=3D NULL) { // // Calcuate the PMR memory alignment // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 6) I think we should follow VTd spec to defined width of below register. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D typedef struct { UINTN ProtectedLowBase; UINTN ProtectedLowLimit; UINTN ProtectedHighBase; UINTN ProtectedHighLimit; } SYSTEM_MEM_INFO_HOB; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Should be: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D typedef struct { UINT32 ProtectedLowBase; UINT32 ProtectedLowLimit; UINT64 ProtectedHighBase; UINT64 ProtectedHighLimit; } SYSTEM_MEM_INFO_HOB; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Using UINTN in PEI means you cannot set above 4G memory for PHMR in 32bit = PEI. 7) I think we need use ProtectedHighBase instead of hardcode below: HighBottom =3D (UINT64) BASE_4GB; If you always hardcode BASE_4GB, the ProtectedHighBase in hob is useless. 8) Please use LShiftU64 for 64bit operation. HighTop =3D (UINT64) SysMemHob->ProtectedHighLimit << 20; Using direct shift might cause link failure in non-optimization mode. Thank you Yao Jiewen > -----Original Message----- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > Evelyn Wang > Sent: Friday, August 9, 2019 5:52 AM > To: devel@edk2.groups.io > Cc: Huang, Jenny ; Shih, More > ; Ni, Ray ; Chaganty, Rangasai V > > Subject: [edk2-devel] [PATCH] IntelSiliconPkg-Vtd: A new PMR interface >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1770 >=20 > 1) IOMMU PMR feature should be generic to support different hardware > architecture. Platforms may request no overlap between PMR regions > and system reserve memory. Create an interface to control PLMR/PHMR > regions. It allows silicon code to adjust PLMR/PHMR region base on > the project needs. >=20 > 2) DisableDMAr Function Code Optimization > Optimize the flow to follow the VT-d spec requirements. >=20 > 3) Renamed InitDmar() to InitGlobalVtd() > The oringal function name is misleading >=20 > 4) A new GetVtdPmrAlignmentLib for silicon code to get > PMR alignment values. >=20 > Signed-off-by: Evelyn Wang > Cc: Jenny Huang > Cc: More Shih > Cc: Ray Ni > Cc: Rangasai V Chaganty > --- > Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/VtdReg.c > | 30 +++++++++++++++++++++++++++--- > Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei= .c > | 73 > ++++++++++++++++++++++++++++++++++++++++++++++++++------------------ > ----- > Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/VtdReg.c > | 29 ++++++++++++++++++++++++++--- >=20 > Silicon/Intel/IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/Platf= or > mVTdInfoSamplePei.c | 9 +++++---- >=20 > Silicon/Intel/IntelSiliconPkg/Library/GetVtdPmrAlignmentLib/GetVtdPmrAli= g > nmentLib.c | 164 > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++ >=20 > Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.= inf > | 5 ++++- > Silicon/Intel/IntelSiliconPkg/Include/Library/GetVtdPmrAlignmentLib.h > | 25 +++++++++++++++++++++++++ > Silicon/Intel/IntelSiliconPkg/Include/SysMemInfoHob.h > | 21 +++++++++++++++++++++ > Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec > | 11 +++++++++-- > Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc > | 3 ++- >=20 > Silicon/Intel/IntelSiliconPkg/Library/GetVtdPmrAlignmentLib/GetVtdPmrAli= g > nmentLib.inf | 32 ++++++++++++++++++++++++++++++++ > 11 files changed, 365 insertions(+), 37 deletions(-) >=20 > diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/VtdRe= g.c > b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/VtdReg.c > index 22bf821d2b..699639ba88 100644 > --- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/VtdReg.c > +++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/VtdReg.c > @@ -1,6 +1,6 @@ > /** @file >=20 > - Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved. > + Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -309,6 +309,8 @@ DisableDmar ( > UINTN Index; > UINTN SubIndex; > UINT32 Reg32; > + UINT32 Status; > + UINT32 Command; >=20 > for (Index =3D 0; Index < mVtdUnitNumber; Index++) { > DEBUG((DEBUG_INFO, ">>>>>>DisableDmar() for engine [%d] \n", > Index)); > @@ -319,9 +321,31 @@ DisableDmar ( > FlushWriteBuffer (Index); >=20 > // > - // Disable VTd > + // Disable Dmar > // > - MmioWrite32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + > R_GCMD_REG, B_GMCD_REG_SRTP); > + // > + // Set TE (Translation Enable: BIT31) of Global command register to > zero > + // > + Reg32 =3D MmioRead32 > (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_GSTS_REG); > + Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits > + Command =3D (Status & ~B_GMCD_REG_TE); > + MmioWrite32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + > R_GCMD_REG, Command); > + > + // > + // Poll on TE Status bit of Global status register to become zero > + // > + do { > + Reg32 =3D MmioRead32 > (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_GSTS_REG); > + } while ((Reg32 & B_GSTS_REG_TE) =3D=3D B_GSTS_REG_TE); > + > + // > + // Set SRTP (Set Root Table Pointer: BIT30) of Global command > register in order to update the root table pointerDisable VTd > + // > + Reg32 =3D MmioRead32 > (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_GSTS_REG); > + Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits > + Command =3D (Status | B_GMCD_REG_SRTP); > + MmioWrite32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + > R_GCMD_REG, Command); > + > do { > Reg32 =3D MmioRead32 > (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_GSTS_REG); > } while((Reg32 & B_GSTS_REG_RTPS) =3D=3D 0); > diff --git > a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPe= i. > c > b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPe= i. > c > index ca099ed71d..14da18289e 100644 > --- > a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPe= i. > c > +++ > b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPe= i. > c > @@ -1,6 +1,6 @@ > /** @file >=20 > - Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved. > + Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. >=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -20,7 +20,7 @@ > #include > #include > #include > - > +#include > #include "IntelVTdPmrPei.h" >=20 > EFI_GUID mVTdInfoGuid =3D { > @@ -424,38 +424,69 @@ InitDmaProtection ( > UINTN MemoryAlignment; > UINTN LowBottom; > UINTN LowTop; > - UINTN HighBottom; > + UINT64 HighBottom; > UINT64 HighTop; > DMA_BUFFER_INFO *DmaBufferInfo; > VOID *Hob; > EFI_PEI_PPI_DESCRIPTOR *OldDescriptor; > EDKII_IOMMU_PPI *OldIoMmuPpi; > + SYSTEM_MEM_INFO_HOB *SysMemHob; > + VOID *SysMemHobPtr; > + > + SysMemHob =3D NULL; > + >=20 > Hob =3D GetFirstGuidHob (&mDmaBufferInfoGuid); > DmaBufferInfo =3D GET_GUID_HOB_DATA(Hob); >=20 > - DEBUG ((DEBUG_INFO, " DmaBufferSize : 0x%x\n", > DmaBufferInfo->DmaBufferSize)); > + SysMemHobPtr =3D GetFirstGuidHob (&gSysMemInfoDataHobGuid); > + > + if (SysMemHobPtr =3D=3D NULL) { > + // > + // Calcuate the PMR memory alignment > + // > + LowMemoryAlignment =3D GetLowMemoryAlignment (VTdInfo, > VTdInfo->EngineMask); > + HighMemoryAlignment =3D GetHighMemoryAlignment (VTdInfo, > VTdInfo->EngineMask); > + if (LowMemoryAlignment < HighMemoryAlignment) { > + MemoryAlignment =3D (UINTN)HighMemoryAlignment; > + } else { > + MemoryAlignment =3D LowMemoryAlignment; > + } > + ASSERT (DmaBufferInfo->DmaBufferSize =3D=3D > ALIGN_VALUE(DmaBufferInfo->DmaBufferSize, MemoryAlignment)); > + > + // > + // Allocate memory for DMA buffer > + // > + DmaBufferInfo->DmaBufferBase =3D (UINTN)AllocateAlignedPages > (EFI_SIZE_TO_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; > + } > + > + DmaBufferInfo->DmaBufferCurrentTop =3D > DmaBufferInfo->DmaBufferBase + DmaBufferInfo->DmaBufferSize; > + DmaBufferInfo->DmaBufferCurrentBottom =3D > DmaBufferInfo->DmaBufferBase; > + LowBottom =3D 0; > + LowTop =3D DmaBufferInfo->DmaBufferBase; > + HighBottom =3D DmaBufferInfo->DmaBufferBase + > DmaBufferInfo->DmaBufferSize; > + HighTop =3D LShiftU64 (1, VTdInfo->HostAddressWidth + 1); >=20 > - LowMemoryAlignment =3D GetLowMemoryAlignment (VTdInfo, > VTdInfo->EngineMask); > - HighMemoryAlignment =3D GetHighMemoryAlignment (VTdInfo, > VTdInfo->EngineMask); > - if (LowMemoryAlignment < HighMemoryAlignment) { > - MemoryAlignment =3D (UINTN)HighMemoryAlignment; > } else { > - MemoryAlignment =3D LowMemoryAlignment; > - } > - ASSERT (DmaBufferInfo->DmaBufferSize =3D=3D > ALIGN_VALUE(DmaBufferInfo->DmaBufferSize, MemoryAlignment)); > - DmaBufferInfo->DmaBufferBase =3D (UINTN)AllocateAlignedPages > (EFI_SIZE_TO_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; > + > + // > + // Get the PMR ranges information for the system hob > + // > + SysMemHob =3D GET_GUID_HOB_DATA (SysMemHobPtr); > + DmaBufferInfo->DmaBufferBase =3D SysMemHob->ProtectedLowLimit > << 20; > + LowBottom =3D SysMemHob->ProtectedLowBase; > + LowTop =3D SysMemHob->ProtectedLowLimit << 20; > + HighBottom =3D (UINT64) BASE_4GB; > + HighTop =3D (UINT64) SysMemHob->ProtectedHighLimit << 20; > } >=20 > + DEBUG ((DEBUG_INFO, " DmaBufferSize : 0x%x\n", > DmaBufferInfo->DmaBufferSize)); > DEBUG ((DEBUG_INFO, " DmaBufferBase : 0x%x\n", > DmaBufferInfo->DmaBufferBase)); >=20 > - DmaBufferInfo->DmaBufferCurrentTop =3D > DmaBufferInfo->DmaBufferBase + DmaBufferInfo->DmaBufferSize; > - DmaBufferInfo->DmaBufferCurrentBottom =3D > DmaBufferInfo->DmaBufferBase; > - > // > // (Re)Install PPI. > // > @@ -472,10 +503,6 @@ InitDmaProtection ( > } > ASSERT_EFI_ERROR (Status); >=20 > - LowBottom =3D 0; > - LowTop =3D DmaBufferInfo->DmaBufferBase; > - HighBottom =3D DmaBufferInfo->DmaBufferBase + > DmaBufferInfo->DmaBufferSize; > - HighTop =3D LShiftU64 (1, VTdInfo->HostAddressWidth + 1); >=20 > Status =3D SetDmaProtectedRange ( > VTdInfo, > diff --git > a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/VtdReg.c > b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/VtdReg.c > index 4774a2ae5b..c9669426aa 100644 > --- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/VtdReg.c > +++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/VtdReg.c > @@ -1,6 +1,6 @@ > /** @file >=20 > - Copyright (c) 2017, Intel Corporation. All rights reserved.
> + Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. >=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -197,6 +197,8 @@ DisableDmar ( > ) > { > UINT32 Reg32; > + UINT32 Status; > + UINT32 Command; >=20 > DEBUG((DEBUG_INFO, ">>>>>>DisableDmar() for engine [%x] \n", > VtdUnitBaseAddress)); >=20 > @@ -206,9 +208,30 @@ DisableDmar ( > FlushWriteBuffer (VtdUnitBaseAddress); >=20 > // > - // Disable VTd > + // Disable Dmar > // > - MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, > B_GMCD_REG_SRTP); > + // > + // Set TE (Translation Enable: BIT31) of Global command register to z= ero > + // > + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); > + Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits > + Command =3D (Status & ~B_GMCD_REG_TE); > + MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Command); > + > + // > + // Poll on TE Status bit of Global status register to become zero > + // > + do { > + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); > + } while ((Reg32 & B_GSTS_REG_TE) =3D=3D B_GSTS_REG_TE); > + > + // > + // Set SRTP (Set Root Table Pointer: BIT30) of Global command registe= r > in order to update the root table pointerDisable VTd > + // > + Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); > + Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits > + Command =3D (Status | B_GMCD_REG_SRTP); > + MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Command); > do { > Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG); > } while((Reg32 & B_GSTS_REG_RTPS) =3D=3D 0); > diff --git > a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/Pla= tf > ormVTdInfoSamplePei.c > b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/Pla= tf > ormVTdInfoSamplePei.c > index 3698c3d3f1..6f6c14f7a9 100644 > --- > a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/Pla= tf > ormVTdInfoSamplePei.c > +++ > b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/Pla= tf > ormVTdInfoSamplePei.c > @@ -1,7 +1,7 @@ > /** @file > Platform VTd Info Sample PEI driver. >=20 > - Copyright (c) 2017, Intel Corporation. All rights reserved.
> + Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -166,15 +166,16 @@ EFI_PEI_PPI_DESCRIPTOR > mPlatformVTdNoIgdInfoSampleDesc =3D { >=20 > /** > Initialize VTd register. > + Initialize the VTd hardware unit which has INCLUDE_PCI_ALL set > **/ > VOID > -InitDmar ( > +InitGlobalVtd ( > VOID > ) > { > UINT32 MchBar; >=20 > - DEBUG ((DEBUG_INFO, "InitDmar\n")); > + DEBUG ((DEBUG_INFO, "InitGlobalVtd\n")); >=20 > MchBar =3D PciRead32 (PCI_LIB_ADDRESS(0, 0, 0, R_SA_MCHBAR)) & > ~BIT0; > PciWrite32 (PCI_LIB_ADDRESS(0, 0, 0, R_SA_MCHBAR), 0xFED10000 | > BIT0); > @@ -346,7 +347,7 @@ PlatformVTdInfoSampleInitialize ( > DEBUG ((DEBUG_INFO, "SiliconInitialized - %x\n", SiliconInitialized))= ; > if (!SiliconInitialized) { > Status =3D PeiServicesNotifyPpi (&mSiliconInitializedNotifyList); > - InitDmar (); > + InitGlobalVtd (); >=20 > Status =3D PeiServicesInstallPpi (&mPlatformVTdNoIgdInfoSampleDesc)= ; > ASSERT_EFI_ERROR (Status); > diff --git > a/Silicon/Intel/IntelSiliconPkg/Library/GetVtdPmrAlignmentLib/GetVtdPmrA= li > gnmentLib.c > b/Silicon/Intel/IntelSiliconPkg/Library/GetVtdPmrAlignmentLib/GetVtdPmrA= li > gnmentLib.c > new file mode 100644 > index 0000000000..10fbd1d80a > --- /dev/null > +++ > b/Silicon/Intel/IntelSiliconPkg/Library/GetVtdPmrAlignmentLib/GetVtdPmrA= li > gnmentLib.c > @@ -0,0 +1,164 @@ > +/** @file > + Library to get Global VTd PMR alignment information. > + Copyright (c) 2019, Intel Corporation. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +typedef union { > + struct { > + UINT32 Low; > + UINT32 High; > + } Data32; > + UINT64 Data; > +} UINT64_STRUCT; > + > +/** > + Get protected low memory alignment. > + > + @param HostAddressWidth The host address width. > + @param VtdUnitBaseAddress The base address of the VTd engine. > + > + @return protected low memory alignment. > +**/ > +UINT32 > +GetGlobalVTdPlmrAlignment ( > + IN UINT8 HostAddressWidth, > + IN UINTN VtdUnitBaseAddress > + ) > +{ > + UINT32 Data32; > + > + MmioWrite32 (VtdUnitBaseAddress + R_PMEN_LOW_BASE_REG, > 0xFFFFFFFF); > + Data32 =3D MmioRead32 (VtdUnitBaseAddress + > R_PMEN_LOW_BASE_REG); > + Data32 =3D ~Data32 + 1; > + > + return Data32; > +} > + > +/** > + Get protected high memory alignment. > + > + @param HostAddressWidth The host address width. > + @param VtdUnitBaseAddress The base address of the VTd engine. > + > + @return protected high memory alignment. > +**/ > +UINT64_STRUCT > +GetGlobalVTdPhmrAlignment ( > + IN UINT8 HostAddressWidth, > + IN UINTN VtdUnitBaseAddress > + ) > +{ > + UINT64_STRUCT Data64; > + > + MmioWrite64 (VtdUnitBaseAddress + R_PMEN_HIGH_BASE_REG, > 0xFFFFFFFFFFFFFFFF); > + Data64.Data =3D MmioRead64 (VtdUnitBaseAddress + > R_PMEN_HIGH_BASE_REG); > + Data64.Data =3D ~Data64.Data + 1; > + Data64.Data =3D Data64.Data & (LShiftU64 (1, HostAddressWidth) - 1); > + > + return Data64; > +} > + > +/** > + Get Global VT-d Protected Memory Aignment. > + > + @return protected high memory alignment. > +**/ > +UINTN > +GetGlobalVtdPmrAlignment ( > +) > +{ > + UINT32 LowMemoryAlignment; > + UINT64_STRUCT HighMemoryAlignment; > + UINTN MemoryAlignment; > + UINT32 GlobalVTdBaseAddress; > + EFI_STATUS Status; > + UINTN VtdIndex; > + EFI_ACPI_DMAR_STRUCTURE_HEADER *DmarHeader; > + EFI_ACPI_DMAR_DRHD_HEADER *DrhdHeader; > + EFI_ACPI_DMAR_HEADER *AcpiDmarTable; > + > + // > + // Initialization > + // > + GlobalVTdBaseAddress =3D 0xFFFFFFFF; > + LowMemoryAlignment =3D 0; > + HighMemoryAlignment.Data =3D 0; > + MemoryAlignment =3D 0; > + Status =3D EFI_UNSUPPORTED; > + VtdIndex =3D 0; > + DmarHeader =3D NULL; > + DrhdHeader =3D NULL; > + AcpiDmarTable =3D NULL; > + > + // > + // Fatch the PEI DMAR ACPU Table that created and installed in > PlatformVTdInfoSamplePei.c > + // > + Status =3D PeiServicesLocatePpi ( > + &gEdkiiVTdInfoPpiGuid, > + 0, > + NULL, > + (VOID **)&AcpiDmarTable > + ); > + if (EFI_ERROR (Status)) { > + > + DEBUG ((DEBUG_ERROR, "PeiServicesLocatePpi gEdkiiVTdInfoPpiGuid > failed. Status: %r\n", Status)); > + MemoryAlignment =3D SIZE_1MB; > + return MemoryAlignment; > + > + } else { > + > + // > + // Seatch the DRHD structure with INCLUDE_PCI_ALL flag Set -> Globa= l > VT-d > + // > + DmarHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER > *)((UINTN)(AcpiDmarTable + 1)); > + while ((UINTN)DmarHeader < (UINTN)AcpiDmarTable + > AcpiDmarTable->Header.Length) { > + switch (DmarHeader->Type) { > + case EFI_ACPI_DMAR_TYPE_DRHD: > + DrhdHeader =3D (EFI_ACPI_DMAR_DRHD_HEADER *) DmarHeader; > + if ((DrhdHeader->Flags & BIT0) =3D=3D BIT0) { > + GlobalVTdBaseAddress =3D > (UINT32)DrhdHeader->RegisterBaseAddress; > + DEBUG ((DEBUG_INFO," GlobalVTdBaseAddress: %x\n", > GlobalVTdBaseAddress)); > + } > + VtdIndex++; > + > + break; > + > + default: > + break; > + } > + DmarHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER > *)((UINTN)DmarHeader + DmarHeader->Length); > + } > + > + if (GlobalVTdBaseAddress =3D=3D 0xFFFFFFFF) { > + > + DEBUG ((DEBUG_ERROR, "Error! Please set INCLUDE_PCI_ALL flag > to the Global VT-d\n")); > + MemoryAlignment =3D SIZE_1MB; > + > + } else { > + // > + // Get the alignment information from VT-d register > + // > + LowMemoryAlignment =3D GetGlobalVTdPlmrAlignment > (AcpiDmarTable->HostAddressWidth, GlobalVTdBaseAddress); > + HighMemoryAlignment =3D GetGlobalVTdPhmrAlignment > (AcpiDmarTable->HostAddressWidth, GlobalVTdBaseAddress); > + if (LowMemoryAlignment < HighMemoryAlignment.Data) { > + MemoryAlignment =3D (UINTN)HighMemoryAlignment.Data; > + } else { > + MemoryAlignment =3D LowMemoryAlignment; > + } > + } > + } > + > + return MemoryAlignment; > +} > diff --git > a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPe= i.i > nf > b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPe= i.i > nf > index 39b914cd00..2f6599d818 100644 > --- > a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPe= i.i > nf > +++ > b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPe= i.i > nf > @@ -4,7 +4,7 @@ > # This driver initializes VTd engine based upon EDKII_VTD_INFO_PPI > # and provide DMA protection in PEI. > # > -# Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved. > +# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > ## > @@ -40,6 +40,9 @@ > IoLib > CacheMaintenanceLib >=20 > +[Guids] > + gSysMemInfoDataHobGuid ## CONSUMES > + > [Ppis] > gEdkiiIoMmuPpiGuid ## PRODUCES > gEdkiiVTdInfoPpiGuid ## CONSUMES > diff --git > a/Silicon/Intel/IntelSiliconPkg/Include/Library/GetVtdPmrAlignmentLib.h > b/Silicon/Intel/IntelSiliconPkg/Include/Library/GetVtdPmrAlignmentLib.h > new file mode 100644 > index 0000000000..0b79887851 > --- /dev/null > +++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/GetVtdPmrAlignmentLi= b.h > @@ -0,0 +1,25 @@ > +/** @file > + Get Global VTd PMR alignment information library. > + > + Copyright (c) 2016, Intel Corporation. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > + > +#ifndef __GET_VTD_PMR_ALIGN_LIB_H__ > +#define __GET_VTD_PMR_ALIGN_LIB_H__ > +#include > + > +/** > + Get Global VT-d Protected Memory alignment. > + > + > + @return protected high memory alignment. > +**/ > + > +UINTN > +GetGlobalVtdPmrAlignment ( > +); > + > +#endif // __GET_VTD_PMR_ALIGN_LIB_H__ > diff --git a/Silicon/Intel/IntelSiliconPkg/Include/SysMemInfoHob.h > b/Silicon/Intel/IntelSiliconPkg/Include/SysMemInfoHob.h > new file mode 100644 > index 0000000000..ce40b570c7 > --- /dev/null > +++ b/Silicon/Intel/IntelSiliconPkg/Include/SysMemInfoHob.h > @@ -0,0 +1,21 @@ > +/** @file > + The definition for VTD System information Hob. > + > + Copyright (c) 2019, Intel Corporation. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > + > +#ifndef _SYS_MEM_INFO_HOB_H_ > +#define _SYS_MEM_INFO_HOB_H_ > + > +typedef struct { > + UINTN ProtectedLowBase; > + UINTN ProtectedLowLimit; > + UINTN ProtectedHighBase; > + UINTN ProtectedHighLimit; > +} SYSTEM_MEM_INFO_HOB; > + > +#endif // _SYS_MEM_INFO_HOB_H_ > + > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec > index fe5bfa0dc6..c082a59596 100644 > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec > @@ -3,7 +3,7 @@ > # > # This package provides common open source Intel silicon modules. > # > -# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved. > +# Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved. > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > ## > @@ -18,10 +18,14 @@ > Include >=20 > [LibraryClasses.IA32, LibraryClasses.X64] > - ## @libraryclass Provides services to access Microcode region on fla= sh > device. > + ## @libraryclass Provides services to access Microcode region on flas= h > device. > # > MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h >=20 > + ## @libraryclass Provides services to access VTd PMR information > + # > + GetVtdPmrAlignmentLib|Include/Library/GetVtdPmrAlignmentLib.h > + > [Guids] > ## GUID for Package token space > # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735} > @@ -35,6 +39,9 @@ > ## Include/Guid/MicrocodeFmp.h > gMicrocodeFmpImageTypeIdGuid =3D { 0x96d4fdcd, 0x1502, 0x424d, > { 0x9d, 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } } >=20 > + ## HOB GUID to get memory information after MRC is done. The hob > data will be used to set the PMR ranges > + gSysMemInfoDataHobGuid =3D {0x6fb61645, 0xf168, 0x46be, { 0x80, 0xec, > 0xb5, 0x02, 0x38, 0x5e, 0xe7, 0xe7 } } > + > [Ppis] > gEdkiiVTdInfoPpiGuid =3D { 0x8a59fcb3, 0xf191, 0x400c, { 0x97, 0x67, = 0x67, > 0xaf, 0x2b, 0x25, 0x68, 0x4a } } >=20 > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc > index 58b5b656ef..77fe760aa7 100644 > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc > @@ -1,7 +1,7 @@ > ## @file > # This package provides common open source Intel silicon modules. > # > -# Copyright (c) 2017, Intel Corporation. All rights reserved.
> +# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved. > # > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -34,6 +34,7 @@ >=20 > SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull= .in > f >=20 > CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCac > heMaintenanceLib.inf >=20 > MicrocodeFlashAccessLib|IntelSiliconPkg/Feature/Capsule/Library/Microcod > eFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf > + > GetVtdPmrAlignmentLib|IntelSiliconPkg/Library/GetVtdPmrAlignmentLib/Get > VtdPmrAlignmentLib.inf >=20 > [LibraryClasses.common.PEIM] > PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf > diff --git > a/Silicon/Intel/IntelSiliconPkg/Library/GetVtdPmrAlignmentLib/GetVtdPmrA= li > gnmentLib.inf > b/Silicon/Intel/IntelSiliconPkg/Library/GetVtdPmrAlignmentLib/GetVtdPmrA= li > gnmentLib.inf > new file mode 100644 > index 0000000000..6a980e00c8 > --- /dev/null > +++ > b/Silicon/Intel/IntelSiliconPkg/Library/GetVtdPmrAlignmentLib/GetVtdPmrA= li > gnmentLib.inf > @@ -0,0 +1,32 @@ > +## @file > +# Component INF file for the GetVtdPmrAlignment library. > +# > +# Copyright (c) 2019, Intel Corporation. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > +INF_VERSION =3D 0x00010017 > +BASE_NAME =3D GetVtdPmrAlignmentLib > +FILE_GUID =3D 0332BE93-0547-4D87-A7FA-0D9D76C53187 > +MODULE_TYPE =3D BASE > +LIBRARY_CLASS =3D GetVtdPmrAlignmentLib > + > +[Packages] > +MdePkg/MdePkg.dec > +IntelSiliconPkg/IntelSiliconPkg.dec > + > +[Sources] > +GetVtdPmrAlignmentLib.c > + > +[LibraryClasses] > +DebugLib > +BaseMemoryLib > +MemoryAllocationLib > +BaseLib > +PeiServicesLib > + > +[Ppis] > +gEdkiiVTdInfoPpiGuid ## CONSUMES > -- > 2.16.2.windows.1 >=20 >=20 >=20