From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=david.wei@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 5A635203B99C8 for ; Tue, 17 Jul 2018 02:22:16 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 02:22:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="57114146" Received: from zwei4-mobl1.ccr.corp.intel.com ([10.239.193.155]) by orsmga007.jf.intel.com with ESMTP; 17 Jul 2018 02:22:12 -0700 From: zwei4 To: edk2-devel@lists.01.org Cc: David Wei , Mang Guo Date: Tue, 17 Jul 2018 17:22:08 +0800 Message-Id: <20180717092208.18764-1-david.wei@intel.com> X-Mailer: git-send-email 2.14.1.windows.1 Subject: [Patch][edk2-platforms/devel-IntelAtomProcessorE3900] Enable VT-d DMA remapping for DMA protection. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jul 2018 09:22:16 -0000 (1) Add VT-d modules into FDF file. (2) Add Setup option and configuration policy for pre-boot VT-d enabling. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: David Wei CC: Mang Guo --- .../Common/Include/Guid/SetupVariable.h | 4 ++- .../Library/PeiPolicyUpdateLib/PeiScPolicyUpdate.c | 2 ++ .../Common/PlatformSettings/PlatformDxe/Platform.c | 31 +++++++++++++++++++- .../PlatformSettings/PlatformDxe/PlatformDxe.inf | 5 +++- .../PlatformSettings/PlatformSetupDxe/Cpu.vfi | 9 ++++++ .../PlatformSetupDxe/PlatformSetupDxe.c | 5 ++++ .../PlatformSettings/PlatformSetupDxe/UqiList.uni | Bin 126916 -> 127232 bytes .../PlatformSetupDxe/VfrStrings.uni | Bin 306044 -> 306466 bytes .../PlatformVTdInfoPei/PlatformVTdInfoPei.c | 32 +++++++++++++++++++-- .../PlatformVTdInfoPei/PlatformVTdInfoPei.inf | 6 ++++ Platform/BroxtonPlatformPkg/PlatformPkg.fdf | 8 ++++++ .../SouthCluster/Include/ConfigBlock/VtdConfig.h | 3 +- .../SouthCluster/Library/DxeVtdLib/DxeVtdLib.c | 21 +++++++++++++- .../Library/PeiScPolicyLib/ScPrintPolicy.c | 2 +- 14 files changed, 120 insertions(+), 8 deletions(-) diff --git a/Platform/BroxtonPlatformPkg/Common/Include/Guid/SetupVariable.h b/Platform/BroxtonPlatformPkg/Common/Include/Guid/SetupVariable.h index 60ffb1beb5..4f5eeb1c0f 100644 --- a/Platform/BroxtonPlatformPkg/Common/Include/Guid/SetupVariable.h +++ b/Platform/BroxtonPlatformPkg/Common/Include/Guid/SetupVariable.h @@ -1,7 +1,7 @@ /** @file Header file for Setup Variable. - Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -1130,6 +1130,8 @@ typedef struct { UINT8 HotThermalTripPointSen2; UINT8 SueCreekBypass; + + UINT8 PrebootVTdEnable; } SYSTEM_CONFIGURATION; #pragma pack(pop) diff --git a/Platform/BroxtonPlatformPkg/Common/Library/PeiPolicyUpdateLib/PeiScPolicyUpdate.c b/Platform/BroxtonPlatformPkg/Common/Library/PeiPolicyUpdateLib/PeiScPolicyUpdate.c index e7714d189a..faf478ace8 100644 --- a/Platform/BroxtonPlatformPkg/Common/Library/PeiPolicyUpdateLib/PeiScPolicyUpdate.c +++ b/Platform/BroxtonPlatformPkg/Common/Library/PeiPolicyUpdateLib/PeiScPolicyUpdate.c @@ -640,6 +640,8 @@ UpdatePeiScPolicy ( } VtdConfig->VtdEnable = SystemConfiguration.VTdEnable; + VtdConfig->PrebootVTdEnable = SystemConfiguration.PrebootVTdEnable; + // // Power management Configuration // diff --git a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c index 712d5cd14f..31f8bedc31 100644 --- a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c +++ b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c @@ -1,7 +1,7 @@ /** @file Platform Initialization Driver. - Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -38,6 +38,9 @@ #include #include #include +#include +#include +#include #if (ENBDT_PF_ENABLE == 1) //BXTP #include @@ -496,6 +499,31 @@ InitPlatformBootMode ( } +VOID +InitPlatformVtdDxePolicy ( + VOID + ) +{ + SC_POLICY_HOB *ScPolicy; + EFI_PEI_HOB_POINTERS HobPtr; + SC_VTD_CONFIG *VtdConfig; + EFI_STATUS Status; + + // + // Get SC VT-d config block + // + HobPtr.Guid = GetFirstGuidHob (&gScPolicyHobGuid); + ASSERT (HobPtr.Guid != NULL); + ScPolicy = (SC_POLICY_HOB*) GET_GUID_HOB_DATA (HobPtr.Guid); + Status = GetConfigBlock ((VOID *) ScPolicy, &gVtdConfigGuid, (VOID *) &VtdConfig); + ASSERT_EFI_ERROR (Status); + DEBUG ((DEBUG_INFO, "Set ScPolicy VtdConfig PrebootVTdEnable.\n")); + + VtdConfig->PrebootVTdEnable = 0; + if ((BOOLEAN)(mSystemConfiguration.PrebootVTdEnable) == TRUE) { + VtdConfig->PrebootVTdEnable = 1; + } +} VOID InitPlatformUsbPolicy ( @@ -839,6 +867,7 @@ InitializePlatform ( IoWrite8 (PCAT_RTC_ADDRESS_REGISTER, RTC_ADDRESS_REGISTER_B); IoWrite8 (PCAT_RTC_DATA_REGISTER, IoRead8 (PCAT_RTC_DATA_REGISTER) & ~B_RTC_ALARM_INT_ENABLE); + InitPlatformVtdDxePolicy(); InitPlatformIdePolicy (); InitPlatformUsbPolicy (); InitSioPlatformPolicy (); diff --git a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.inf b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.inf index 440071fd41..8eb6a7aa82 100644 --- a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.inf +++ b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.inf @@ -1,7 +1,7 @@ ## @file # Component description file for platform DXE driver # -# Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -43,6 +43,7 @@ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec BroxtonPlatformPkg/PlatformPkg.dec BroxtonSiPkg/BroxtonSiPkg.dec + BroxtonSiPkg/BroxtonSiPrivate.dec SecurityPkg/SecurityPkg.dec [LibraryClasses] @@ -89,6 +90,8 @@ gEfiImageSecurityDatabaseGuid gEfiPlatformInfoGuid gFdoModeEnabledHobGuid ## CONSUMES + gScPolicyHobGuid + gVtdConfigGuid [Protocols] gDxeSiPolicyProtocolGuid # PRODUCES diff --git a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/Cpu.vfi b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/Cpu.vfi index b2bafa979c..23859e6a3a 100644 --- a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/Cpu.vfi +++ b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/Cpu.vfi @@ -45,6 +45,15 @@ form formid = CPU_CONFIGURATION_FORM_ID, option text = STRING_TOKEN(STR_DISABLE), value = 0, flags = MANUFACTURING | DEFAULT | RESET_REQUIRED; option text = STRING_TOKEN(STR_ENABLE), value = 1, flags = RESET_REQUIRED; endoneof; + + grayoutif ideqval Setup.VTdEnable == 0; + oneof varid = Setup.PrebootVTdEnable, + prompt = STRING_TOKEN(STR_PREBOOT_VTD_PROMPT), + help = STRING_TOKEN(STR_PREBOOT_VTD_HELP), + option text = STRING_TOKEN(STR_DISABLE), value = 0, flags = MANUFACTURING | DEFAULT | RESET_REQUIRED; + option text = STRING_TOKEN(STR_ENABLE), value = 1, flags = RESET_REQUIRED; + endoneof; + endif; endif; oneof varid = Setup.EnableTm, diff --git a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/PlatformSetupDxe.c b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/PlatformSetupDxe.c index 7e3beb6116..21fd328fd4 100644 --- a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/PlatformSetupDxe.c +++ b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/PlatformSetupDxe.c @@ -477,6 +477,11 @@ SystemConfigCallback ( if (Private->FakeNvData.IpuEn == 1) { Private->FakeNvData.VTdEnable = 0; } + + if (Private->FakeNvData.VTdEnable == 0) { + Private->FakeNvData.PrebootVTdEnable = 0; + } + // // Pass changed uncommitted data back to Form Browser // diff --git a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/UqiList.uni b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/UqiList.uni index 4666b9a6a5b2b365750f5afdbc1ce1810c62b1e4..c7aa4873575c9f3b933314bdd4717378b8c698a2 100644 GIT binary patch delta 92 zcmX?dpS|G`d&3sSBk!lDJ!X`eu29Fw!tcu9#NZEvAq?>hVGJRY7dj+P517cv#hk)m fIoZ%a5naLbjn5cur*EiYQ~@hvOJPW4P+|Z8O6eLR delta 11 ScmZp8#D3&Hd&3sSBkuts%LV)Z diff --git a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/VfrStrings.uni b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformSetupDxe/VfrStrings.uni index df868581ebdda14ee03287bbb2d73bd40e03dbe8..bb53da281824b22ebff1c370df87c7e0409b1fb9 100644 GIT binary patch delta 156 zcmex!O=!_Ap$&2KIb9i?82o`SWOCzN&*=s|%xZ$E3`q?6Kv=?{z!1g|!k|0ZFtIG4u9I^I2AL0|00eE)f6# delta 47 zcmZ2^EoJ!3V3)?FeG6FFZ5HoMDSje)98vqjM B6vzMo diff --git a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformVTdInfoPei/PlatformVTdInfoPei.c b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformVTdInfoPei/PlatformVTdInfoPei.c index b342e99f22..89b0133fd8 100644 --- a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformVTdInfoPei/PlatformVTdInfoPei.c +++ b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformVTdInfoPei/PlatformVTdInfoPei.c @@ -15,12 +15,14 @@ #include #include - +#include #include #include #include #include +#include #include +#include #define R_SA_MCHBAR (0x48) @@ -320,7 +322,33 @@ PlatformVTdInfoInitialize ( { EFI_STATUS Status; EFI_PEI_PPI_DESCRIPTOR *PpiDesc; - + UINTN VariableSize; + EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariableServices; + SYSTEM_CONFIGURATION SystemConfiguration; + + VariableSize = sizeof (SYSTEM_CONFIGURATION); + ZeroMem (&SystemConfiguration, sizeof (SYSTEM_CONFIGURATION)); + + Status = (*PeiServices)->LocatePpi ( + (CONST EFI_PEI_SERVICES **)PeiServices, + &gEfiPeiReadOnlyVariable2PpiGuid, + 0, + NULL, + (VOID **) &VariableServices + ); + + Status = VariableServices->GetVariable ( + VariableServices, + PLATFORM_SETUP_VARIABLE_NAME, + &gEfiSetupVariableGuid, + NULL, + &VariableSize, + &SystemConfiguration + ); + + if ((SystemConfiguration.VTdEnable == FALSE) || (SystemConfiguration.PrebootVTdEnable == FALSE) ) { + return EFI_SUCCESS; + } // // This driver assumes VT-d has been enabled by FSP. // diff --git a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformVTdInfoPei/PlatformVTdInfoPei.inf b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformVTdInfoPei/PlatformVTdInfoPei.inf index d6a865109c..506cf3d8ea 100644 --- a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformVTdInfoPei/PlatformVTdInfoPei.inf +++ b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformVTdInfoPei/PlatformVTdInfoPei.inf @@ -36,6 +36,7 @@ MdeModulePkg/MdeModulePkg.dec IntelSiliconPkg/IntelSiliconPkg.dec BroxtonSiPkg/BroxtonSiPkg.dec + BroxtonPlatformPkg/PlatformPkg.dec [LibraryClasses] PeimEntryPoint @@ -43,9 +44,14 @@ DebugLib PciLib IoLib + BaseMemoryLib [Ppis] gEdkiiVTdInfoPpiGuid ## PRODUCES + gEfiPeiReadOnlyVariable2PpiGuid + +[Guids] + gEfiSetupVariableGuid [Depex] gEfiPeiMasterBootModePpiGuid diff --git a/Platform/BroxtonPlatformPkg/PlatformPkg.fdf b/Platform/BroxtonPlatformPkg/PlatformPkg.fdf index ca22f75965..4ad90dc3c8 100644 --- a/Platform/BroxtonPlatformPkg/PlatformPkg.fdf +++ b/Platform/BroxtonPlatformPkg/PlatformPkg.fdf @@ -306,6 +306,12 @@ INF MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf !endif + # + # VT-d for DMA Protection + # + INF $(PLATFORM_PACKAGE_COMMON)/PlatformSettings/PlatformVTdInfoPei/PlatformVTdInfoPei.inf + INF IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.inf + [FV.FVIBBM] BlockSize = $(FLASH_BLOCK_SIZE) FvBaseAddress = 0xFEF45000 @@ -768,6 +774,8 @@ APRIORI DXE { # VT-d for MDA Protection # INF RuleOverride = ACPITABLE $(PLATFORM_SI_PACKAGE)/SouthCluster/AcpiTableDmar/AcpiTableDmar.inf + INF $(PLATFORM_PACKAGE_COMMON)/PlatformSettings/PlatformVTdDxe/PlatformVTdDxe.inf + INF IntelSiliconPkg/Feature/VTd/IntelVTdDxe/IntelVTdDxe.inf [FV.FVOBB] BlockSize = $(FLASH_BLOCK_SIZE) diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Include/ConfigBlock/VtdConfig.h b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Include/ConfigBlock/VtdConfig.h index e6fb1a24ec..b38d34a4a1 100644 --- a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Include/ConfigBlock/VtdConfig.h +++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Include/ConfigBlock/VtdConfig.h @@ -28,8 +28,9 @@ extern EFI_GUID gVtdConfigGuid; typedef struct { CONFIG_BLOCK_HEADER Header; ///< Config Block Header UINT32 VtdEnable : 1; ///< 1: Enable, 0: Disable VT-d + UINT32 PrebootVTdEnable : 1; UINT8 x2ApicEnabled : 1; - UINT32 RsvdBits : 30; ///< Reserved bits + UINT32 RsvdBits : 29; ///< Reserved bits UINT64 RmrrUsbBaseAddr; UINT64 RmrrUsbLimit; } SC_VTD_CONFIG; diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/DxeVtdLib/DxeVtdLib.c b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/DxeVtdLib/DxeVtdLib.c index 80f37a664b..abcfee2998 100644 --- a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/DxeVtdLib/DxeVtdLib.c +++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/DxeVtdLib/DxeVtdLib.c @@ -542,11 +542,24 @@ UpdateDmarOnReadyToBoot ( UINTN AcpiTableHandle; EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol; EFI_ACPI_DESCRIPTION_HEADER *DmarAcpiTable; + SC_POLICY_HOB *ScPolicy; + EFI_PEI_HOB_POINTERS HobPtr; + SC_VTD_CONFIG *VtdConfig; AcpiTableProtocol = NULL; DmarAcpiTable = NULL; Index = 0; + // + // Get SC VT-d config block + // + HobPtr.Guid = GetFirstGuidHob (&gScPolicyHobGuid); + ASSERT (HobPtr.Guid != NULL); + ScPolicy = (SC_POLICY_HOB*) GET_GUID_HOB_DATA (HobPtr.Guid); + Status = GetConfigBlock ((VOID *) ScPolicy, &gVtdConfigGuid, (VOID *) &VtdConfig); + ASSERT_EFI_ERROR (Status); + DEBUG ((DEBUG_INFO, "ScPolicy PrebootVTdEnable = %x\n", VtdConfig->PrebootVTdEnable)); + // // Locate ACPI support protocol // @@ -684,7 +697,13 @@ UpdateDmarOnReadyToBoot ( DEBUG ((DEBUG_ERROR, "Error updating the DMAR ACPI table\n")); } - EfiEventGroupSignal (&gEfiAcpi10TableGuid); + // + // Only notify IntelVtdDxe driver to setup pre-boot VT-d if pre-boot VT-d has been enabled by BIOS Setup option. + // + if ((BOOLEAN)(VtdConfig->PrebootVTdEnable) == TRUE) { + DEBUG ((DEBUG_INFO, "VT-d signal gEfiAcpi10TableGuid.\n")); + EfiEventGroupSignal (&gEfiAcpi10TableGuid); + } } diff --git a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/PeiScPolicyLib/ScPrintPolicy.c b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/PeiScPolicyLib/ScPrintPolicy.c index 7ccf1d2495..7ccaac8f7e 100644 --- a/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/PeiScPolicyLib/ScPrintPolicy.c +++ b/Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/PeiScPolicyLib/ScPrintPolicy.c @@ -500,7 +500,7 @@ PrintVtdConfig ( { DEBUG ((DEBUG_INFO, "------------------ Vtd Config ------------------\n")); DEBUG ((DEBUG_INFO, " VtdEnable = %x\n", VtdConfig->VtdEnable)); - + DEBUG ((DEBUG_INFO, " PrebootVTdEnable = %x\n", VtdConfig->PrebootVTdEnable)); return; } -- 2.14.1.windows.1