From 8dffd33247d6dac1c4a5732d320c4ff4bc22beaf Mon Sep 17 00:00:00 2001 From: Jiewen Yao Date: Mon, 6 Nov 2017 15:07:51 +0800 Subject: Add DMA protection check test point. Cc: Michael A Kubacki Cc: Amy Chan Cc: Chasel Chiu Cc: Brett Wang Cc: Daocheng Bu Cc: Isaac W Oram Cc: Rangasai V Chaganty Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiewen Yao Reviewed-by: Amy Chan --- .../Test/Library/TestPointCheckLib/DxeCheckAcpi.c | 21 ++++ .../TestPointCheckLib/DxeCheckDmaProtection.c | 101 ++++++++++++++++++ .../TestPointCheckLib/DxeTestPointCheckLib.c | 39 +++++++ .../TestPointCheckLib/DxeTestPointCheckLib.inf | 2 + .../TestPointCheckLib/PeiCheckDmaProtection.c | 113 +++++++++++++++++++++ .../TestPointCheckLib/PeiTestPointCheckLib.c | 42 ++++++++ .../TestPointCheckLib/PeiTestPointCheckLib.inf | 5 +- .../TestPointCheckLibNull/TestPointCheckLibNull.c | 18 ++++ 8 files changed, 340 insertions(+), 1 deletion(-) create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c (limited to 'Platform/Intel/MinPlatformPkg/Test/Library') diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpi.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpi.c index 491d2fd162..fce46bd083 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpi.c +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpi.c @@ -356,3 +356,24 @@ TestPointCheckAcpi ( return Status; } + +VOID * +TestPointGetAcpi ( + IN UINT32 Signature + ) +{ + EFI_STATUS Status; + VOID *Table; + + Status = DumpAcpiWithGuid (&gEfiAcpi20TableGuid, &Signature, &Table); + if (Status == EFI_NOT_FOUND) { + Status = DumpAcpiWithGuid (&gEfiAcpi10TableGuid, &Signature, &Table); + } + + if (EFI_ERROR(Status)) { + return NULL; + } + + return Table; +} + diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c new file mode 100644 index 0000000000..e24ca90463 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDmaProtection.c @@ -0,0 +1,101 @@ +/** @file + +Copyright (c) 2017, 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 that accompanies this distribution. +The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php. + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +EFI_STATUS +CheckDrhd ( + IN EFI_ACPI_DMAR_HEADER *Dmar + ) +{ + EFI_ACPI_DMAR_STRUCTURE_HEADER *DmarStructHeader; + INTN DmarLen; + EFI_ACPI_DMAR_DRHD_HEADER *Drhd; + UINT32 Reg32; + + // + // Sub table + // + DmarLen = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER); + DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1); + while (DmarLen > 0) { + switch (DmarStructHeader->Type) { + case EFI_ACPI_DMAR_TYPE_DRHD: + Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; + + Reg32 = MmioRead32 ((UINTN)Drhd->RegisterBaseAddress + R_GSTS_REG); + if ((Reg32 & B_GSTS_REG_TE) == 0) { + return EFI_INVALID_PARAMETER; + } + + break; + case EFI_ACPI_DMAR_TYPE_RMRR: + case EFI_ACPI_DMAR_TYPE_ATSR: + case EFI_ACPI_DMAR_TYPE_RHSA: + case EFI_ACPI_DMAR_TYPE_ANDD: + default: + break; + } + DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length); + DmarLen -= DmarStructHeader->Length; + } + + return EFI_SUCCESS; +} + +VOID * +TestPointGetAcpi ( + IN UINT32 Signature + ); + +EFI_STATUS +TestPointVtdEngine ( + VOID + ) +{ + EFI_ACPI_DMAR_HEADER *Dmar; + EFI_STATUS Status; + + Status = EFI_SUCCESS; + + Dmar = TestPointGetAcpi (EFI_ACPI_4_0_DMA_REMAPPING_TABLE_SIGNATURE); + if (Dmar == NULL) { + DEBUG ((DEBUG_ERROR, "No DMAR table\n")); + Status = EFI_INVALID_PARAMETER; + } else { + Status = CheckDrhd (Dmar); + } + + if (EFI_ERROR(Status)) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE3_END_OF_DXE_DMA_PROTECTION_ENABLED_ERROR_CODE \ + TEST_POINT_READY_TO_BOOT \ + TEST_POINT_BYTE3_END_OF_DXE_DXE_DMA_PROTECTION_ENABLED_ERROR_STRING + ); + } + + return Status; +} \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.c index dc42722e3d..cc3a2a9377 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.c +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.c @@ -140,6 +140,11 @@ TestPointCheckTcgMor ( VOID ); +EFI_STATUS +TestPointVtdEngine ( + VOID + ); + GLOBAL_REMOVE_IF_UNREFERENCED ADAPTER_INFO_PLATFORM_TEST_POINT_STRUCT mTestPointStruct = { PLATFORM_TEST_POINT_VERSION, PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, @@ -256,6 +261,40 @@ TestPointEndOfDxeDmaAcpiTableFuntional ( return EFI_SUCCESS; } +EFI_STATUS +EFIAPI +TestPointEndOfDxeDmaProtectionEnabled ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + if ((mFeatureImplemented[3] & TEST_POINT_BYTE3_END_OF_DXE_DMA_PROTECTION_ENABLED) == 0) { + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_INFO, "======== TestPointEndOfDxeDmaProtectionEnabled - Enter\n")); + + Result = TRUE; + Status = TestPointVtdEngine (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 3, + TEST_POINT_BYTE3_END_OF_DXE_DMA_PROTECTION_ENABLED + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointEndOfDxeDmaProtectionEnabled - Exit\n")); + return EFI_SUCCESS; +} + EFI_STATUS EFIAPI TestPointEndOfDxeNoThirdPartyPciOptionRom ( diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf index 7ca562a023..6930e48d42 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf @@ -43,6 +43,7 @@ MinPlatformPkg/MinPlatformPkg.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + IntelSiliconPkg/IntelSiliconPkg.dec [Sources] DxeTestPointCheckLib.c @@ -70,6 +71,7 @@ DxeCheckPiSignedFvBoot.c DxeCheckTcgTrustedBoot.c DxeCheckTcgMor.c + DxeCheckDmaProtection.c TestPointHelp.c [Guids] diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c new file mode 100644 index 0000000000..4639e9ffaa --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDmaProtection.c @@ -0,0 +1,113 @@ +/** @file + +Copyright (c) 2017, 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 that accompanies this distribution. +The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php. + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +EFI_STATUS +CheckDrhd ( + IN EFI_ACPI_DMAR_HEADER *Dmar + ) +{ + EFI_ACPI_DMAR_STRUCTURE_HEADER *DmarStructHeader; + INTN DmarLen; + EFI_ACPI_DMAR_DRHD_HEADER *Drhd; + UINT32 Reg32; + VTD_CAP_REG CapReg; + + // + // Sub table + // + DmarLen = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER); + DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1); + while (DmarLen > 0) { + switch (DmarStructHeader->Type) { + case EFI_ACPI_DMAR_TYPE_DRHD: + Drhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; + + Reg32 = MmioRead32 ((UINTN)Drhd->RegisterBaseAddress + R_GSTS_REG); + + CapReg.Uint64 = MmioRead64 ((UINTN)Drhd->RegisterBaseAddress + R_CAP_REG); + if (CapReg.Bits.PLMR == 0 || CapReg.Bits.PHMR == 0) { + return EFI_INVALID_PARAMETER; + } + + Reg32 = MmioRead32 ((UINTN)Drhd->RegisterBaseAddress + R_PMEN_ENABLE_REG); + if ((Reg32 & BIT0) == 0) { + return EFI_INVALID_PARAMETER; + } + + break; + case EFI_ACPI_DMAR_TYPE_RMRR: + case EFI_ACPI_DMAR_TYPE_ATSR: + case EFI_ACPI_DMAR_TYPE_RHSA: + case EFI_ACPI_DMAR_TYPE_ANDD: + default: + break; + } + DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length); + DmarLen -= DmarStructHeader->Length; + } + + return EFI_SUCCESS; +} + +VOID * +TestPointGetAcpi ( + IN UINT32 Signature + ); + +EFI_STATUS +TestPointVtdEngine ( + VOID + ) +{ + EFI_ACPI_DMAR_HEADER *Dmar; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi ( + &gEdkiiVTdInfoPpiGuid, + 0, + NULL, + (VOID **) &Dmar + ); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "No DMAR table\n")); + } else { + Status = CheckDrhd (Dmar); + } + + if (EFI_ERROR(Status)) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE1_MEMORY_DISCOVERED_DMA_PROTECTION_ENABLED_ERROR_CODE \ + TEST_POINT_MEMORY_DISCOVERED \ + TEST_POINT_BYTE1_MEMORY_DISCOVERED_DMA_PROTECTION_ENABLED_ERROR_STRING + ); + } + + return Status; +} \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.c index 07ec3d1972..f9df81e836 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.c +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.c @@ -53,6 +53,11 @@ TestPointCheckPciBusMaster ( VOID ); +EFI_STATUS +TestPointVtdEngine ( + VOID + ); + GLOBAL_REMOVE_IF_UNREFERENCED ADAPTER_INFO_PLATFORM_TEST_POINT_STRUCT mTestPointStruct = { PLATFORM_TEST_POINT_VERSION, PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, @@ -232,6 +237,43 @@ TestPointMemoryDiscoveredFvInfoFunctional ( return EFI_SUCCESS; } +EFI_STATUS +EFIAPI +TestPointMemoryDiscoveredDmaProtectionEnabled ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + UINT8 *FeatureImplemented; + + FeatureImplemented = GetFeatureImplemented (); + + if ((FeatureImplemented[1] & TEST_POINT_BYTE1_MEMORY_DISCOVERED_DMA_PROTECTION_ENABLED) == 0) { + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_INFO, "======== TestPointMemoryDiscoveredDmaProtectionEnabled - Enter\n")); + + Result = TRUE; + Status = TestPointVtdEngine (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 1, + TEST_POINT_BYTE1_MEMORY_DISCOVERED_DMA_PROTECTION_ENABLED + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointMemoryDiscoveredDmaProtectionEnabled - Exit\n")); + return EFI_SUCCESS; +} + EFI_STATUS EFIAPI TestPointEndOfPeiSystemResourceFunctional ( diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf index 9ef9471a2e..ad5461e451 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf @@ -40,6 +40,7 @@ MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec + IntelSiliconPkg/IntelSiliconPkg.dec [Sources] PeiTestPointCheckLib.c @@ -48,6 +49,7 @@ PeiCheckFvInfo.c PeiCheckSmmInfo.c PeiCheckPci.c + PeiCheckDmaProtection.c [Pcd] gMinPlatformModuleTokenSpaceGuid.PcdTestPointIbvPlatformFeature @@ -60,4 +62,5 @@ [Ppis] gEfiPeiFirmwareVolumeInfoPpiGuid gEfiPeiFirmwareVolumeInfo2PpiGuid - gPeiSmmAccessPpiGuid \ No newline at end of file + gPeiSmmAccessPpiGuid + gEdkiiVTdInfoPpiGuid \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.c index 9e83c76b11..0ddceac5ff 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.c +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.c @@ -60,6 +60,15 @@ TestPointMemoryDiscoveredFvInfoFunctional ( return EFI_SUCCESS; } +EFI_STATUS +EFIAPI +TestPointMemoryDiscoveredDmaProtectionEnabled ( + VOID + ) +{ + return EFI_SUCCESS; +} + EFI_STATUS EFIAPI TestPointEndOfPeiSystemResourceFunctional ( @@ -123,6 +132,15 @@ TestPointEndOfDxeDmaAcpiTableFuntional ( return EFI_SUCCESS; } +EFI_STATUS +EFIAPI +TestPointEndOfDxeDmaProtectionEnabled ( + VOID + ) +{ + return EFI_SUCCESS; +} + EFI_STATUS EFIAPI TestPointDxeSmmReadyToLockSmramAligned ( -- cgit v1.2.3