From 1f003fafade69043b4fd587dd30fc63997df0d3e Mon Sep 17 00:00:00 2001 From: Jiewen Yao Date: Sat, 20 May 2017 15:42:12 +0800 Subject: Add MinPlatform. reviewed-by: Jiewen Yao reviewed-by: Michael A Kubacki reviewed-by: Amy Chan reviewed-by: Rangasai V Chaganty reviewed-by: Chasel Chiu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiewen Yao --- .../Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.c | 114 ++ .../Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.h | 30 + .../Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.inf | 54 + .../MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 746 +++++++++++++ .../MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h | 128 +++ .../Acpi/AcpiTables/AcpiPlatform.inf | 101 ++ .../MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.c | 74 ++ .../MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.h | 42 + .../MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.c | 222 ++++ .../MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.h | 189 ++++ .../MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.c | 61 ++ .../MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.h | 51 + .../MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.c | 389 +++++++ .../MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.h | 144 +++ .../MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.c | 78 ++ .../MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.h | 62 ++ .../MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.c | 44 + .../MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.h | 30 + .../Library/BoardAcpiLibNull/BoardAcpiEnableLib.c | 35 + .../BoardAcpiLibNull/BoardAcpiEnableLibNull.inf | 34 + .../Library/BoardAcpiLibNull/BoardAcpiTableLib.c | 28 + .../BoardAcpiLibNull/BoardAcpiTableLibNull.inf | 34 + .../Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.c | 314 ++++++ .../Library/DxeAslUpdateLib/DxeAslUpdateLib.inf | 47 + .../DxeBoardAcpiTableLib.c | 41 + .../DxeMultiBoardAcpiSupportLib.c | 39 + .../DxeMultiBoardAcpiSupportLib.inf | 42 + .../SmmBoardAcpiEnableLib.c | 63 ++ .../SmmMultiBoardAcpiSupportLib.c | 39 + .../SmmMultiBoardAcpiSupportLib.inf | 42 + .../DxePlatformBootManagerLib/BdsPlatform.c | 1112 ++++++++++++++++++++ .../DxePlatformBootManagerLib/BdsPlatform.h | 193 ++++ .../DxePlatformBootManagerLib.inf | 95 ++ .../DxePlatformBootManagerLib/PlatformBootOption.c | 563 ++++++++++ .../DxePlatformBootManagerLib/PlatformData.c | 96 ++ Platform/Intel/MinPlatformPkg/Contributions.txt | 218 ++++ .../SpiFlashCommonLibNull/SpiFlashCommonLibNull.c | 107 ++ .../SpiFlashCommonLibNull.inf | 35 + .../Flash/SpiFvbService/Common/FvbInfo.c | 100 ++ .../SpiFvbService/Common/SpiFvbServiceCommon.c | 911 ++++++++++++++++ .../SpiFvbService/Common/SpiFvbServiceCommon.h | 168 +++ .../Flash/SpiFvbService/Smm/SpiFvbServiceSmm.c | 281 +++++ .../Flash/SpiFvbService/SpiFvbServiceSmm.inf | 72 ++ .../DxeFspWrapperPlatformResetLib.c | 49 + .../DxeFspWrapperPlatformResetLib.inf | 68 ++ .../FspWrapperHobProcessLib.c | 662 ++++++++++++ .../PeiFspWrapperHobProcessLib.inf | 84 ++ .../PeiFspWrapperPlatformLib.c | 74 ++ .../PeiFspWrapperPlatformLib.inf | 61 ++ .../PeiFspWrapperPlatformResetLib.c | 48 + .../PeiFspWrapperPlatformResetLib.inf | 67 ++ .../FspWrapperPlatformSecLib.c | 162 +++ .../SecFspWrapperPlatformSecLib/FsptCoreUpd.h | 46 + .../Library/SecFspWrapperPlatformSecLib/Ia32/Fsp.h | 48 + .../Ia32/PeiCoreEntry.S | 123 +++ .../Ia32/PeiCoreEntry.asm | 134 +++ .../SecFspWrapperPlatformSecLib/Ia32/SecEntry.S | 348 ++++++ .../SecFspWrapperPlatformSecLib/Ia32/SecEntry.asm | 375 +++++++ .../SecFspWrapperPlatformSecLib/Ia32/Stack.S | 73 ++ .../SecFspWrapperPlatformSecLib/Ia32/Stack.asm | 79 ++ .../SecFspWrapperPlatformSecLib/PlatformInit.c | 51 + .../SecFspWrapperPlatformSecLib.inf | 103 ++ .../SecGetPerformance.c | 95 ++ .../SecPlatformInformation.c | 84 ++ .../SecFspWrapperPlatformSecLib/SecRamInitData.c | 42 + .../SecFspWrapperPlatformSecLib/SecTempRamDone.c | 53 + .../FspWrapper/SaveMemoryConfig/SaveMemoryConfig.c | 139 +++ .../SaveMemoryConfig/SaveMemoryConfig.inf | 52 + .../ExternalDeviceDmaProtection.c | 53 + .../FirmwareTrustConfigurationCryptoStrength.c | 52 + .../FirmwareVersionRollbackProtection.c | 53 + .../Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.c | 259 +++++ .../Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.h | 121 +++ .../Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.inf | 53 + .../Hsti/HstiIbvPlatformDxe/MorSupport.c | 54 + .../HstiIbvPlatformDxe/NoTestKeyVerification.c | 55 + .../Hsti/HstiIbvPlatformDxe/SecureBootBypass.c | 51 + .../MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc | 142 +++ .../MinPlatformPkg/Include/Dsc/CoreDxeInclude.dsc | 142 +++ .../MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc | 96 ++ .../MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc | 58 + .../MinPlatformPkg/Include/Dsc/CorePeiLib.dsc | 56 + .../MinPlatformPkg/Include/Fdf/CoreDxeInclude.fdf | 111 ++ .../Include/Fdf/CorePeiBfvInclude.fdf | 18 + .../Include/Fdf/CorePeiPostMemInclude.fdf | 14 + .../Include/Fdf/CorePeiPreMemInclude.fdf | 32 + .../MinPlatformPkg/Include/Fdf/RuleInclude.fdf | 303 ++++++ .../Include/Guid/SmramMemoryReserve.h | 60 ++ .../MinPlatformPkg/Include/HstiIbvFeatureBit.h | 60 ++ .../MinPlatformPkg/Include/Library/AslUpdateLib.h | 146 +++ .../Include/Library/BoardAcpiEnableLib.h | 33 + .../Include/Library/BoardAcpiTableLib.h | 28 + .../MinPlatformPkg/Include/Library/BoardInitLib.h | 92 ++ .../Include/Library/FspPolicyInitLib.h | 30 + .../Include/Library/FspPolicyUpdateLib.h | 30 + .../Include/Library/HobVariableLib.h | 111 ++ .../Include/Library/MultiBoardAcpiSupportLib.h | 60 ++ .../Include/Library/MultiBoardInitSupportLib.h | 85 ++ .../Intel/MinPlatformPkg/Include/Library/PeiLib.h | 85 ++ .../Include/Library/SecBoardInitLib.h | 38 + .../Include/Library/SpiFlashCommonLib.h | 104 ++ .../Include/Library/TestPointCheckLib.h | 219 ++++ .../MinPlatformPkg/Include/Library/TestPointLib.h | 225 ++++ .../Library/PeiHobVariableLibFce/Fce.h | 48 + .../PeiHobVariableLibFce/InternalCommonLib.c | 634 +++++++++++ .../PeiHobVariableLibFce/PeiHobVariableLibFce.c | 467 ++++++++ .../PeiHobVariableLibFce/PeiHobVariableLibFce.inf | 54 + .../PeiHobVariableLibFceOptSize.c | 206 ++++ .../PeiHobVariableLibFceOptSize.inf | 53 + .../Library/PeiHobVariableLibFce/Variable.h | 178 ++++ .../Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c | 293 ++++++ .../Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf | 37 + Platform/Intel/MinPlatformPkg/License.txt | 25 + Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec | 224 ++++ Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc | 180 ++++ .../PciHostBridgeLibSimple.c | 166 +++ .../PciHostBridgeLibSimple.inf | 59 ++ .../Library/BoardInitLibNull/BoardInitLib.c | 124 +++ .../Library/BoardInitLibNull/BoardInitLibNull.inf | 36 + .../MultiBoardInitSupportLib/DxeBoardInitLib.c | 84 ++ .../DxeMultiBoardInitSupportLib.c | 39 + .../DxeMultiBoardInitSupportLib.inf | 42 + .../MultiBoardInitSupportLib/PeiBoardInitLib.c | 229 ++++ .../PeiMultiBoardInitSupportLib.c | 82 ++ .../PeiMultiBoardInitSupportLib.inf | 44 + .../SecBoardInitLibNull/Ia32/SecBoardInit.nasm | 32 + .../Library/SecBoardInitLibNull/SecBoardInitLib.c | 25 + .../SecBoardInitLibNull/SecBoardInitLibNull.inf | 40 + .../PlatformInit/PlatformInitDxe/PlatformInitDxe.c | 400 +++++++ .../PlatformInitDxe/PlatformInitDxe.inf | 60 ++ .../PlatformInitPei/PlatformInitPostMem.c | 228 ++++ .../PlatformInitPei/PlatformInitPostMem.inf | 59 ++ .../PlatformInitPei/PlatformInitPreMem.c | 507 +++++++++ .../PlatformInitPei/PlatformInitPreMem.inf | 71 ++ .../PlatformInit/PlatformInitSmm/PlatformInitSmm.c | 168 +++ .../PlatformInitSmm/PlatformInitSmm.inf | 52 + .../Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.c | 218 ++++ .../Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf | 56 + .../Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c | 233 ++++ .../Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf | 56 + .../Test/Library/TestPointCheckLib/DxeDumpAcpi.c | 340 ++++++ .../Library/TestPointCheckLib/DxeDumpAcpiDmar.c | 210 ++++ .../Library/TestPointCheckLib/DxeDumpAcpiHpet.c | 52 + .../Library/TestPointCheckLib/DxeDumpAcpiMadt.c | 241 +++++ .../Library/TestPointCheckLib/DxeDumpAcpiMcfg.c | 63 ++ .../Library/TestPointCheckLib/DxeDumpAcpiWsmt.c | 45 + .../TestPointCheckLib/DxeDumpBootVariable.c | 195 ++++ .../TestPointCheckLib/DxeDumpConsoleVariable.c | 69 ++ .../Library/TestPointCheckLib/DxeDumpDevicePath.c | 78 ++ .../Test/Library/TestPointCheckLib/DxeDumpEsrt.c | 120 +++ .../Test/Library/TestPointCheckLib/DxeDumpGcd.c | 230 ++++ .../Test/Library/TestPointCheckLib/DxeDumpHsti.c | 123 +++ .../Library/TestPointCheckLib/DxeDumpLoadedImage.c | 203 ++++ .../TestPointCheckLib/DxeDumpMemAttribute.c | 89 ++ .../Test/Library/TestPointCheckLib/DxeDumpMemMap.c | 219 ++++ .../DxeDumpMemoryTypeInformation.c | 158 +++ .../Test/Library/TestPointCheckLib/DxeDumpPci.c | 384 +++++++ .../Library/TestPointCheckLib/DxeDumpSmmInfo.c | 80 ++ .../Library/TestPointCheckLib/DxeDumpVariable.c | 173 +++ .../TestPointCheckLib/DxeTestPointCheckLib.c | 335 ++++++ .../TestPointCheckLib/DxeTestPointCheckLib.inf | 86 ++ .../Test/Library/TestPointCheckLib/PeiDumpFvInfo.c | 118 +++ .../Test/Library/TestPointCheckLib/PeiDumpHob.c | 377 +++++++ .../Test/Library/TestPointCheckLib/PeiDumpMtrr.c | 77 ++ .../Library/TestPointCheckLib/PeiDumpSmramHob.c | 95 ++ .../TestPointCheckLib/PeiTestPointCheckLib.c | 204 ++++ .../TestPointCheckLib/PeiTestPointCheckLib.inf | 58 + .../Library/TestPointCheckLib/SecDumpCpuInfo.c | 39 + .../TestPointCheckLib/SecTestPointCheckLib.c | 40 + .../TestPointCheckLib/SecTestPointCheckLib.inf | 37 + .../Library/TestPointCheckLib/SmmDumpLoadedImage.c | 111 ++ .../TestPointCheckLib/SmmDumpMemAttribute.c | 86 ++ .../Test/Library/TestPointCheckLib/SmmDumpSmrr.c | 125 +++ .../TestPointCheckLib/SmmTestPointCheckLib.c | 172 +++ .../TestPointCheckLib/SmmTestPointCheckLib.inf | 59 ++ .../TestPointCheckLibNull/TestPointCheckLibNull.c | 133 +++ .../TestPointCheckLibNull.inf | 32 + .../Test/Library/TestPointLib/DxeTestPoint.c | 611 +++++++++++ .../Test/Library/TestPointLib/DxeTestPoint.h | 61 ++ .../Test/Library/TestPointLib/DxeTestPointAip.c | 175 +++ .../Test/Library/TestPointLib/DxeTestPointLib.inf | 48 + .../Test/Library/TestPointLib/PeiTestPoint.c | 541 ++++++++++ .../Test/Library/TestPointLib/PeiTestPoint.h | 44 + .../Test/Library/TestPointLib/PeiTestPointLib.inf | 44 + .../Test/Library/TestPointLib/SmmTestPoint.c | 634 +++++++++++ .../Test/Library/TestPointLib/SmmTestPoint.h | 71 ++ .../Test/Library/TestPointLib/SmmTestPointAip.c | 175 +++ .../TestPointLib/SmmTestPointCommunication.c | 379 +++++++ .../Test/Library/TestPointLib/SmmTestPointLib.inf | 50 + .../Test/TestPointDumpApp/TestPointDump.c | 412 ++++++++ .../Test/TestPointDumpApp/TestPointDumpApp.inf | 49 + .../Tools/Fsp/PatchFspBinFvsBaseAddress.py | 116 ++ .../Tools/Fsp/RebaseAndPatchFspBinBaseAddress.py | 121 +++ Platform/Intel/MinPlatformPkg/Tools/Fsp/pad.bin | 1 + .../MinPlatformPkg/Tools/Help/CheckCodeBase.py | 795 ++++++++++++++ 195 files changed, 28609 insertions(+) create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.h create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.inf create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.h create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.h create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.h create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.h create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.h create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.h create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLibNull.inf create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLibNull.inf create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeBoardAcpiTableLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeMultiBoardAcpiSupportLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeMultiBoardAcpiSupportLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmBoardAcpiEnableLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmMultiBoardAcpiSupportLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmMultiBoardAcpiSupportLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.c create mode 100644 Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.h create mode 100644 Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/PlatformBootOption.c create mode 100644 Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/PlatformData.c create mode 100644 Platform/Intel/MinPlatformPkg/Contributions.txt create mode 100644 Platform/Intel/MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.c create mode 100644 Platform/Intel/MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.inf create mode 100644 Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/FvbInfo.c create mode 100644 Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/SpiFvbServiceCommon.c create mode 100644 Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/SpiFvbServiceCommon.h create mode 100644 Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Smm/SpiFvbServiceSmm.c create mode 100644 Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/SpiFvbServiceSmm.inf create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/FspWrapperHobProcessLib.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/FspWrapperPlatformSecLib.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/FsptCoreUpd.h create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Fsp.h create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/PeiCoreEntry.S create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/PeiCoreEntry.asm create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/SecEntry.S create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/SecEntry.asm create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Stack.S create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Stack.asm create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/PlatformInit.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecGetPerformance.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecPlatformInformation.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecRamInitData.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecTempRamDone.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf create mode 100644 Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/ExternalDeviceDmaProtection.c create mode 100644 Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/FirmwareTrustConfigurationCryptoStrength.c create mode 100644 Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/FirmwareVersionRollbackProtection.c create mode 100644 Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.c create mode 100644 Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.h create mode 100644 Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.inf create mode 100644 Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/MorSupport.c create mode 100644 Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/NoTestKeyVerification.c create mode 100644 Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/SecureBootBypass.c create mode 100644 Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc create mode 100644 Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeInclude.dsc create mode 100644 Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc create mode 100644 Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc create mode 100644 Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc create mode 100644 Platform/Intel/MinPlatformPkg/Include/Fdf/CoreDxeInclude.fdf create mode 100644 Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiBfvInclude.fdf create mode 100644 Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiPostMemInclude.fdf create mode 100644 Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiPreMemInclude.fdf create mode 100644 Platform/Intel/MinPlatformPkg/Include/Fdf/RuleInclude.fdf create mode 100644 Platform/Intel/MinPlatformPkg/Include/Guid/SmramMemoryReserve.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/HstiIbvFeatureBit.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/AslUpdateLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/BoardAcpiEnableLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/BoardAcpiTableLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/BoardInitLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/FspPolicyInitLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/FspPolicyUpdateLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/HobVariableLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardAcpiSupportLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/PeiLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/SecBoardInitLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/SpiFlashCommonLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/TestPointCheckLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/TestPointLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/Fce.h create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/InternalCommonLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFce.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFce.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFceOptSize.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFceOptSize.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/Variable.h create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/License.txt create mode 100644 Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec create mode 100644 Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc create mode 100644 Platform/Intel/MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.c create mode 100644 Platform/Intel/MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.inf create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLib.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLibNull.inf create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeBoardInitLib.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiBoardInitLib.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/Ia32/SecBoardInit.nasm create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/SecBoardInitLib.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/SecBoardInitLibNull.inf create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitDxe/PlatformInitDxe.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitDxe/PlatformInitDxe.inf create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPostMem.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPostMem.inf create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPreMem.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPreMem.inf create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitSmm/PlatformInitSmm.c create mode 100644 Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitSmm/PlatformInitSmm.inf create mode 100644 Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.c create mode 100644 Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf create mode 100644 Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c create mode 100644 Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpi.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiDmar.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiHpet.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiMadt.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiMcfg.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiWsmt.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpBootVariable.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpConsoleVariable.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpDevicePath.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpEsrt.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpGcd.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpHsti.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpLoadedImage.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemAttribute.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemMap.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemoryTypeInformation.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpPci.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpSmmInfo.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpVariable.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpFvInfo.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpHob.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpMtrr.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpSmramHob.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecDumpCpuInfo.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpLoadedImage.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpMemAttribute.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpSmrr.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.inf create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPoint.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPoint.h create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointAip.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPoint.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPoint.h create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPointLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPoint.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPoint.h create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointAip.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointCommunication.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Test/TestPointDumpApp/TestPointDump.c create mode 100644 Platform/Intel/MinPlatformPkg/Test/TestPointDumpApp/TestPointDumpApp.inf create mode 100644 Platform/Intel/MinPlatformPkg/Tools/Fsp/PatchFspBinFvsBaseAddress.py create mode 100644 Platform/Intel/MinPlatformPkg/Tools/Fsp/RebaseAndPatchFspBinBaseAddress.py create mode 100644 Platform/Intel/MinPlatformPkg/Tools/Fsp/pad.bin create mode 100644 Platform/Intel/MinPlatformPkg/Tools/Help/CheckCodeBase.py (limited to 'Platform/Intel/MinPlatformPkg') diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.c new file mode 100644 index 0000000000..74c1678bc8 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.c @@ -0,0 +1,114 @@ +/** @file + Acpi Smm driver. + +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 "AcpiSmm.h" + +/** + Enable SCI + + @param[in] DispatchHandle - The handle of this callback, obtained when registering + @param[in] DispatchContext - Pointer to the EFI_SMM_SW_DISPATCH_CONTEXT + @param[in] CommBuffer - A pointer to a collection of data in memory that will + be conveyed from a non-SMM environment into an SMM environment. + @param[in] CommBufferSize - The size of the CommBuffer. +**/ +EFI_STATUS +EFIAPI +EnableAcpiCallback ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL + ) +{ + BoardEnableAcpi (TRUE); + return EFI_SUCCESS; +} + +/** + Disable SCI + + @param[in] DispatchHandle - The handle of this callback, obtained when registering + @param[in] DispatchContext - Pointer to the EFI_SMM_SW_DISPATCH_CONTEXT + @param[in] CommBuffer - A pointer to a collection of data in memory that will + be conveyed from a non-SMM environment into an SMM environment. + @param[in] CommBufferSize - The size of the CommBuffer. +**/ +EFI_STATUS +EFIAPI +DisableAcpiCallback ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *DispatchContext, + IN OUT VOID *CommBuffer OPTIONAL, + IN UINTN *CommBufferSize OPTIONAL + ) +{ + BoardDisableAcpi (TRUE); + return EFI_SUCCESS; +} + +/** + Initializes the Acpi Smm Driver + + @param[in] ImageHandle - Pointer to the loaded image protocol for this driver + @param[in] SystemTable - Pointer to the EFI System Table + + @retval Status - EFI_SUCCESS + @retval Assert, otherwise. + +**/ +EFI_STATUS +EFIAPI +InitializeAcpiSmm ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE SwHandle; + EFI_SMM_SW_DISPATCH2_PROTOCOL *SwDispatch; + EFI_SMM_SW_REGISTER_CONTEXT SwContext; + + // + // Locate the ICH SMM SW dispatch protocol + // + Status = gSmst->SmmLocateProtocol (&gEfiSmmSwDispatch2ProtocolGuid, NULL, (VOID**)&SwDispatch); + ASSERT_EFI_ERROR (Status); + + // + // Register ACPI enable SMI handler + // + SwContext.SwSmiInputValue = (UINTN) PcdGet8 (PcdAcpiEnableSwSmi); + Status = SwDispatch->Register ( + SwDispatch, + EnableAcpiCallback, + &SwContext, + &SwHandle + ); + ASSERT_EFI_ERROR (Status); + + // + // Register ACPI disable SMI handler + // + SwContext.SwSmiInputValue = (UINTN) PcdGet8 (PcdAcpiDisableSwSmi); + Status = SwDispatch->Register ( + SwDispatch, + DisableAcpiCallback, + &SwContext, + &SwHandle + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.h b/Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.h new file mode 100644 index 0000000000..a34d87250f --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.h @@ -0,0 +1,30 @@ +/** @file + Header file for the Smm platform driver. + +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. + +**/ + +#ifndef _ACPI_SMM_H_ +#define _ACPI_SMM_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif + diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.inf b/Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.inf new file mode 100644 index 0000000000..e7f5d57494 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.inf @@ -0,0 +1,54 @@ +### @file +# Component information file for ACPI SMM module. +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = AcpiSmm + FILE_GUID = DF9A9FFC-A075-4867-A0B2-5E7540BB023E + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_SMM_DRIVER + PI_SPECIFICATION_VERSION = 1.20 + ENTRY_POINT = InitializeAcpiSmm + +[LibraryClasses] + UefiDriverEntryPoint + UefiBootServicesTableLib + DebugLib + HobLib + IoLib + PcdLib + UefiLib + SmmServicesTableLib + BoardAcpiEnableLib + +[Packages] + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[Pcd] + gPlatformModuleTokenSpaceGuid.PcdAcpiEnableSwSmi ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdAcpiDisableSwSmi ## CONSUMES + +[Sources] + AcpiSmm.h + AcpiSmm.c + +[Protocols] + gEfiSmmSwDispatch2ProtocolGuid ## CONSUMES + +[Guids] + +[Depex] + gEfiSmmSwDispatch2ProtocolGuid diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c new file mode 100644 index 0000000000..91b37f5a8a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c @@ -0,0 +1,746 @@ +/** @file + ACPI Platform Driver + +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 "AcpiPlatform.h" + +// +// Global variables +// + +VOID *mLocalTable[] = { + &Facs, + &Fadt, + &Hpet, + &Madt, + &Mcfg, + &Wsmt +}; + +GLOBAL_REMOVE_IF_UNREFERENCED EFI_CPU_ID_ORDER_MAP mCpuApicIdOrderTable[MAX_CPU_NUM]; +GLOBAL_REMOVE_IF_UNREFERENCED EFI_CPU_APIC_ID_REORDER_MAP mCpuApicIdReorderTable[MAX_CPU_NUM]; + +GLOBAL_REMOVE_IF_UNREFERENCED EFI_CPU_PACKAGE_INFO mSbspPackageInfo; + +// +// Function implementations +// + +/* + This function will determine whether Native ASPM is supported on the platform. + + @return TRUE if Native ASPM is supported, FALSE otherwise +*/ +BOOLEAN +IsNativeAspmSupported ( + VOID + ) +{ + if (PcdGet8 (PcdPciExpNative) == 0) { + return FALSE; + } + switch (PcdGet8 (PcdNativeAspmEnable)) { + case 0: + return FALSE; + case 1: + return TRUE; + default: + ASSERT (0); + } + return TRUE; +} + +/** + This function will update any runtime platform specific information. + This currently includes: + Setting OEM table values, ID, table ID, creator ID and creator revision. + Enabling the proper processor entries in the APIC tables + It also indicates with which ACPI table version the table belongs. + + @param[in] Table The table to update + @param[in] Version Where to install this table + + @retval EFI_SUCCESS Updated tables commplete. +**/ +EFI_STATUS +PlatformUpdateTables ( + IN OUT EFI_ACPI_COMMON_HEADER *Table, + IN OUT EFI_ACPI_TABLE_VERSION *Version + ) +{ + EFI_ACPI_DESCRIPTION_HEADER *TableHeader; + UINT8 *CurrPtr; + UINT8 *EndPtr; + UINT8 *TempPtr; + EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *ApicPtr; + UINT8 CurrProcessor; + EFI_STATUS Status; + EFI_MP_SERVICES_PROTOCOL *MpService; + UINTN NumberOfCPUs; + UINTN NumberOfEnabledCPUs; + UINT32 HpetBaseAdress; + UINT8 LocalApicCounter; + + CurrPtr = NULL; + EndPtr = NULL; + ApicPtr = NULL; + TempPtr = NULL; + CurrProcessor = 0; + NumberOfCPUs = 1; + LocalApicCounter = 0; + + // + // This will be accurate except for FACS structure + // + TableHeader = (EFI_ACPI_DESCRIPTION_HEADER *) Table; + + // + // Update the OEM and creator information for every table except FACS. + // + if (Table->Signature != EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) { + *(UINT32 *) (TableHeader->OemId) = 'I' + ('N' << 8) + ('T' << 16) + ('E' << 24); + *(UINT16 *) (TableHeader->OemId + 4) = 'L' + (' ' << 8); + + // + // Skip OEM table ID and creator information for DSDT, SSDT and PSDT tables, since these are + // created by an ASL compiler and the creator information is useful. + // + if (Table->Signature != EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE && + Table->Signature != EFI_ACPI_1_0_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE && + Table->Signature != EFI_ACPI_1_0_PERSISTENT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE + ) { + + // + // Update OEM table ID + // + // Check if the silicon is KBL + TableHeader->OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId); + // + // Update creator information + // + TableHeader->CreatorId = EFI_ACPI_CREATOR_ID; + TableHeader->CreatorRevision = EFI_ACPI_CREATOR_REVISION; + } + } + + // + // Locate the MP services protocol + // Find the MP Protocol. This is an MP platform, so MP protocol must be there. + // + Status = gBS->LocateProtocol ( + &gEfiMpServiceProtocolGuid, + NULL, + (VOID **) &MpService + ); + ASSERT_EFI_ERROR (Status); + + // + // Determine the number of processors + // + MpService->GetNumberOfProcessors ( + MpService, + &NumberOfCPUs, + &NumberOfEnabledCPUs + ); + + // + // By default, a table belongs in all ACPI table versions published. + // Some tables will override this because they have different versions of the table. + // + *Version = EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0 | EFI_ACPI_TABLE_VERSION_3_0; + + // + // Update the various table types with the necessary updates + // + switch (Table->Signature) { + + case EFI_ACPI_1_0_APIC_SIGNATURE: + // + // if not MP and not APIC then don't publish the APIC tables. + // + + // + // Call for Local APIC ID Reorder + // + SortCpuLocalApicInTable ( + MpService, + NumberOfCPUs, + NumberOfEnabledCPUs + ); + + CurrPtr = (UINT8 *) &((EFI_ACPI_DESCRIPTION_HEADER *) Table)[1]; + CurrPtr = CurrPtr + 8; + // + // Size of Local APIC Address & Flag + // + EndPtr = (UINT8 *) Table; + EndPtr = EndPtr + Table->Length; + + while (CurrPtr < EndPtr) { + ApicPtr = (EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *) CurrPtr; + + // + // Check table entry type + // + if (ApicPtr->Type == EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC) { + AppendCpuMapTableEntry ( + ApicPtr, + NumberOfCPUs, + NumberOfEnabledCPUs, + LocalApicCounter + ); + LocalApicCounter++; + } + + // + // Go to the next structure in the APIC table + // + CurrPtr = CurrPtr + ApicPtr->Length; + } + break; + + case EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE: + // + // Fix up all FACP Table values if configuration requires it. + // This code fixes up the following Table values: + // (1) C2/C3/CST Enable FACP values + // (2) RTC S4 Flag + // + { + EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *FadtPointer; + + FadtPointer = (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *) Table; + + // + // Check the version of the table + // + *Version = EFI_ACPI_TABLE_VERSION_NONE; + if (FadtPointer->Header.Revision == EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) { + *Version = EFI_ACPI_TABLE_VERSION_NONE; + } else if (FadtPointer->Header.Revision == EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) { + *Version = EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0; + } else if (FadtPointer->Header.Revision == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) { + *Version = EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_3_0; + } else if (FadtPointer->Header.Revision == EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) { + *Version = EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_5_0; + } + + // + // Modify Preferred_PM_Profile field based on Board SKU's. Default is set to Mobile + // + FadtPointer->PreferredPmProfile = PcdGet8 (PcdPreferredPmProfile); + + // + // if Native ASPM is disabled, set FACP table to skip Native ASPM + // + if (!IsNativeAspmSupported ()) { + FadtPointer->IaPcBootArch |= 0x10; + } + + // + //PME WAKE supported, set PCI_EXP_WAK, BIT14 of Fixed feature flags. + // + FadtPointer->Flags |= (EFI_ACPI_6_0_PCI_EXP_WAK); + + if (PcdGet8 (PcdLowPowerS0Idle)) { + // The Flags field within the FADT (offset 112) + // 1) will have a new Low Power S0 Idle Capable ACPI flag (bit offset 21). + FadtPointer->Flags = (BIT21 | FadtPointer->Flags); + //Only passive docking available in Conected Standby mode. Clear Docking capability Bit + FadtPointer->Flags &= ~BIT9; + } + // + // Modify FADT Fixed Feature Flag to support 10 sec Power button. + // If 10sec Power button is enabled: Set PWR_BUTTON(bit4) in Fixed Feature Flag(FACP offset 112) + // + if ((PcdGet8 (PcdLowPowerS0Idle) == 1) || (PcdGet8 (PcdTenSecondPowerButtonEnable) == 1)) { + FadtPointer->Flags |= EFI_ACPI_2_0_PWR_BUTTON; // Set Fixed Power Button flag (Disabling Fixed Power button and enabling Control Method PB) + } else { + FadtPointer->Flags &= ~(EFI_ACPI_2_0_PWR_BUTTON); // Clear fixed Power Button flag, means enable Power Button as Fixed PB + } + + // + // 1. set header revision. + // + FadtPointer->Header.Revision = EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION; + + // + // 2. set all GAR register AccessSize to valid value. + // + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->ResetReg.AccessSize = EFI_ACPI_5_0_BYTE; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->XPm1aEvtBlk.AccessSize = EFI_ACPI_5_0_WORD; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->XPm1bEvtBlk.AccessSize = EFI_ACPI_5_0_WORD; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->XPm1aCntBlk.AccessSize = EFI_ACPI_5_0_WORD; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->XPm1bCntBlk.AccessSize = EFI_ACPI_5_0_WORD; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->XPm2CntBlk.AccessSize = EFI_ACPI_5_0_BYTE; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->XPmTmrBlk.AccessSize = EFI_ACPI_5_0_DWORD; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->XGpe0Blk.AccessSize = EFI_ACPI_5_0_BYTE; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->XGpe1Blk.AccessSize = EFI_ACPI_5_0_BYTE; + + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepControlReg.AddressSpaceId = 0x1; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepControlReg.RegisterBitWidth = 0x8; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepControlReg.RegisterBitOffset = 0; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepControlReg.AccessSize = EFI_ACPI_5_0_DWORD; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepControlReg.Address = EFI_ACPI_PM1A_EVT_BLK_ADDRESS + 4; + + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepStatusReg.AddressSpaceId = 0x1; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepStatusReg.RegisterBitWidth = 0x8; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepStatusReg.RegisterBitOffset = 0; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepStatusReg.AccessSize = EFI_ACPI_5_0_DWORD; + ((EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)FadtPointer)->SleepStatusReg.Address = EFI_ACPI_PM1A_EVT_BLK_ADDRESS; + + } + break; + + case EFI_ACPI_3_0_HIGH_PRECISION_EVENT_TIMER_TABLE_SIGNATURE: + // + // If HPET is disabled in setup, don't publish the table. + // + // + // Get HPET base address + // + HpetBaseAdress = PcdGet32 (PcdHpetBaseAddress); + // + // Adjust HPET Table to correct the Base Address + // + ((EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_HEADER*) Table)->BaseAddressLower32Bit.Address = HpetBaseAdress; + break; + + default: + break; + } + return EFI_SUCCESS; +} + +/** + This function calculates RCR based on PCI Device ID and Vendor ID from the devices + available on the platform. + It also includes other instances of BIOS change to calculate CRC and provides as + HWSignature filed in FADT table. +**/ +VOID +IsHardwareChange ( + VOID + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + EFI_PCI_IO_PROTOCOL *PciIo; + UINT32 CRC; + UINT32 *HWChange; + UINTN HWChangeSize; + UINT32 PciId; + UINTN Handle; + EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsPtr; + EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *pFADT; + + HandleCount = 0; + HandleBuffer = NULL; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciIoProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return; // PciIO protocol not installed yet! + } + + // + // Allocate memory for HWChange and add additional entrie for + // pFADT->XDsdt + // + HWChangeSize = HandleCount + 1; + HWChange = AllocateZeroPool( sizeof(UINT32) * HWChangeSize ); + ASSERT( HWChange != NULL ); + + if (HWChange == NULL) return; + + // + // add HWChange inputs: PCI devices + // + for (Index = 0; HandleCount > 0; HandleCount--) { + PciId = 0; + Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtocolGuid, (VOID **) &PciIo); + if (!EFI_ERROR (Status)) { + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, 1, &PciId); + if (EFI_ERROR (Status)) { + continue; + } + HWChange[Index++] = PciId; + } + } + + // + // Locate FACP Table + // + Handle = 0; + Status = LocateAcpiTableBySignature ( + EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, + (EFI_ACPI_DESCRIPTION_HEADER **) &pFADT, + &Handle + ); + if (EFI_ERROR (Status) || (pFADT == NULL)) { + return; //Table not found or out of memory resource for pFADT table + } + + // + // add HWChange inputs: others + // + HWChange[Index++] = (UINT32)pFADT->XDsdt; + + // + // Calculate CRC value with HWChange data. + // + Status = gBS->CalculateCrc32(HWChange, HWChangeSize, &CRC); + DEBUG((DEBUG_INFO, "CRC = %x and Status = %r\n", CRC, Status)); + + // + // Set HardwareSignature value based on CRC value. + // + FacsPtr = (EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)pFADT->FirmwareCtrl; + FacsPtr->HardwareSignature = CRC; + FreePool( HWChange ); +} + +VOID +UpdateLocalTable ( + VOID + ) +{ + EFI_STATUS Status; + EFI_ACPI_COMMON_HEADER *CurrentTable; + EFI_ACPI_TABLE_VERSION Version; + UINTN TableHandle; + EFI_ACPI_TABLE_PROTOCOL *AcpiTable; + UINTN Index; + + Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, &AcpiTable); + + for (Index = 0; Index < sizeof(mLocalTable)/sizeof(mLocalTable[0]); Index++) { + CurrentTable = mLocalTable[Index]; + + PlatformUpdateTables (CurrentTable, &Version); + + // + // Add the table + // + TableHandle = 0; + + if (Version != EFI_ACPI_TABLE_VERSION_NONE) { + Status = AcpiTable->InstallAcpiTable ( + AcpiTable, + CurrentTable, + CurrentTable->Length, + &TableHandle + ); + } + + ASSERT_EFI_ERROR (Status); + } +} + + +VOID +EFIAPI +AcpiEndOfDxeEvent ( + EFI_EVENT Event, + VOID *ParentImageHandle + ) +{ + + if (Event != NULL) { + gBS->CloseEvent(Event); + } + + + // + // Calculate Hardware Signature value based on current platform configurations + // + IsHardwareChange(); +} + +/** + ACPI Platform driver installation function. + + @param[in] ImageHandle Handle for this drivers loaded image protocol. + @param[in] SystemTable EFI system table. + + @retval EFI_SUCCESS The driver installed without error. + @retval EFI_ABORTED The driver encountered an error and could not complete installation of + the ACPI tables. + +**/ +EFI_STATUS +EFIAPI +InstallAcpiPlatform ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + INTN Instance; + EFI_ACPI_COMMON_HEADER *CurrentTable; + UINTN TableHandle; + EFI_HANDLE Handle; + EFI_EVENT EndOfDxeEvent; + + Instance = 0; + CurrentTable = NULL; + TableHandle = 0; + Handle = NULL; + + // + // Create an End of DXE event. + // + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + AcpiEndOfDxeEvent, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &EndOfDxeEvent + ); + ASSERT_EFI_ERROR (Status); + + // + // Update local table + // + UpdateLocalTable (); + + // + // Finished + // + return EFI_SUCCESS; +} + +/** + Sort ordering of CPUs according to the priorities of cores and threads. + ** ASSUMPTION: 1) single CPU package systsem wide; 2) two threads per core + + @param[in] MpService The MP servicde protocol (used to retrievel MP info) + @param[in] NumberOfCPUs Number of CPUs + @param[in] NumberOfEnabledCPUs Number of Enabled CPUs. + + @retval EFI_SUCCESS The driver installed without error. + +**/ +EFI_STATUS +SortCpuLocalApicInTable ( + IN EFI_MP_SERVICES_PROTOCOL *MpService, + IN UINTN NumberOfCPUs, + IN UINTN NumberOfEnabledCPUs + ) +{ + EFI_PROCESSOR_INFORMATION *MpContext; + UINTN BufferSize; + INTN Index2; + UINTN Index1; + UINTN Index; + UINT8 CpuThreadIndex; + UINTN BspIndex; + UINT8 CurrProcessor; + EFI_STATUS Status; + UINT8 MaxCpuPackage; + UINT8 MaxCpuCore; + UINT8 MaxCpuThread; + + BufferSize = 0; + MpContext = NULL; + MaxCpuPackage = 0; + MaxCpuCore = 0; + MaxCpuThread = 0; + + Status = MpService->WhoAmI ( + MpService, + &BspIndex + ); + + // + // Fill mCpuApicIdOrderTable + // + for (CurrProcessor = 0; CurrProcessor < NumberOfCPUs; CurrProcessor++) { + + MpContext = AllocatePool (sizeof(EFI_PROCESSOR_INFORMATION)); + ASSERT (MpContext != NULL); + Status = MpService->GetProcessorInfo ( + MpService, + CurrProcessor, + MpContext + ); + ASSERT_EFI_ERROR (Status); + + if (MpContext == NULL) { + return Status; + } + mCpuApicIdOrderTable[CurrProcessor].ApicId = (UINT8) MpContext->ProcessorId; + DEBUG((DEBUG_INFO, "The CurrProcessor 0x%x ApicId is 0x%x\n", CurrProcessor, mCpuApicIdOrderTable[CurrProcessor].ApicId)); + mCpuApicIdOrderTable[CurrProcessor].Flags = (MpContext->StatusFlag | PROCESSOR_ENABLED_BIT)? 1: 0; + mCpuApicIdOrderTable[CurrProcessor].Package = (UINT8) MpContext->Location.Package; + mCpuApicIdOrderTable[CurrProcessor].Die = (UINT8) 0; + mCpuApicIdOrderTable[CurrProcessor].Core = (UINT8) MpContext->Location.Core; + mCpuApicIdOrderTable[CurrProcessor].Thread = (UINT8) MpContext->Location.Thread; + + if (MaxCpuThread < (UINT8) MpContext->Location.Thread) { + MaxCpuThread = (UINT8) MpContext->Location.Thread; + } + + if (MaxCpuCore < (UINT8) MpContext->Location.Core) { + MaxCpuCore = (UINT8) MpContext->Location.Core; + } + + if (MaxCpuPackage < (UINT8) MpContext->Location.Package) { + MaxCpuPackage = (UINT8) MpContext->Location.Package; + } + } + + // + // Do some statistics about the SBSP package + // + for (CurrProcessor = 0; CurrProcessor < NumberOfCPUs; CurrProcessor++) { + if (CurrProcessor == BspIndex) { + mSbspPackageInfo.BspApicId = mCpuApicIdOrderTable[CurrProcessor].ApicId; + mSbspPackageInfo.PackageNo = mCpuApicIdOrderTable[CurrProcessor].Package; + mSbspPackageInfo.TotalThreads = 0; + mSbspPackageInfo.CoreNo = 0; + mSbspPackageInfo.LogicalThreadNo = 0; + } + } + + for (CurrProcessor = 0; CurrProcessor < NumberOfCPUs; CurrProcessor++) { + if (mCpuApicIdOrderTable[CurrProcessor].Package == mSbspPackageInfo.PackageNo) { + mSbspPackageInfo.TotalThreads++; + if (mCpuApicIdOrderTable[CurrProcessor].Thread == 0) { + mSbspPackageInfo.CoreNo++; + } else { + mSbspPackageInfo.LogicalThreadNo++; + } + } + } + + // + // Output debug info + // + for (Index = 0; Index < NumberOfCPUs; Index++) { + DEBUG((DEBUG_INFO, "Package = %x, Die = %x, Core = %x, Thread = %x, ApicId = %x\n", \ + mCpuApicIdOrderTable[Index].Package, \ + mCpuApicIdOrderTable[Index].Die, \ + mCpuApicIdOrderTable[Index].Core, \ + mCpuApicIdOrderTable[Index].Thread, \ + mCpuApicIdOrderTable[Index].ApicId)); + } + + DEBUG((DEBUG_INFO, "MaxCpuPackage = %x\n", MaxCpuPackage)); + DEBUG((DEBUG_INFO, "MaxCpuCore = %x\n", MaxCpuCore)); + DEBUG((DEBUG_INFO, "MaxCpuThread = %x\n\n", MaxCpuThread)); + DEBUG((DEBUG_INFO, "mSbspPackageInfo.BspApicId = %x\n", mSbspPackageInfo.BspApicId)); + DEBUG((DEBUG_INFO, "mSbspPackageInfo.TotalThreads = %x\n", mSbspPackageInfo.TotalThreads)); + DEBUG((DEBUG_INFO, "mSbspPackageInfo.PackageNo = %x\n", mSbspPackageInfo.PackageNo)); + DEBUG((DEBUG_INFO, "mSbspPackageInfo.CoreNo = %x\n", mSbspPackageInfo.CoreNo)); + DEBUG((DEBUG_INFO, "mSbspPackageInfo.LogicalThreadNo = %x\n", mSbspPackageInfo.LogicalThreadNo)); + + // + // First entry is always SBSP + // + CurrProcessor = 0; + mCpuApicIdReorderTable[CurrProcessor].ApicId = mSbspPackageInfo.BspApicId; + mCpuApicIdReorderTable[CurrProcessor].Package = mSbspPackageInfo.PackageNo; + mCpuApicIdReorderTable[CurrProcessor].Flags = 1; + CurrProcessor++; + + // + // Reorder Core and threads + // + for (Index2 = -1; Index2 <= MaxCpuPackage; Index2 ++) { + INTN PackageIndex; + + PackageIndex = Index2; + if (Index2 == -1) { + // add Sbsp as first + PackageIndex = mSbspPackageInfo.PackageNo; + } else if (Index2 == mSbspPackageInfo.PackageNo) { + // Skip Sbsp + continue; + } + for (Index1 = 0; Index1 <= MaxCpuThread; Index1 ++) { + for (Index = 0; Index <= MaxCpuCore; Index++) { + for (CpuThreadIndex = 0; CpuThreadIndex < NumberOfCPUs; CpuThreadIndex++) { + if ((mCpuApicIdOrderTable[CpuThreadIndex].Package == PackageIndex) && + (mCpuApicIdOrderTable[CpuThreadIndex].Thread == Index1) && + (mCpuApicIdOrderTable[CpuThreadIndex].Core == Index) && + (mCpuApicIdOrderTable[CpuThreadIndex].ApicId != mCpuApicIdReorderTable[0].ApicId)) { + mCpuApicIdReorderTable[CurrProcessor].ApicId = mCpuApicIdOrderTable[CpuThreadIndex].ApicId; + mCpuApicIdReorderTable[CurrProcessor].Package = (UINT8)PackageIndex; + mCpuApicIdReorderTable[CurrProcessor].Flags = mCpuApicIdOrderTable[CpuThreadIndex].Flags; + CurrProcessor++; + break; + } + } + } + } + } + + // + // Output debug info + // + for (Index = 0; Index < NumberOfCPUs; Index++) { + DEBUG((DEBUG_INFO, "Index = %x, ApicId = %x, Package = %x\n", \ + Index, \ + mCpuApicIdReorderTable[Index].ApicId, \ + mCpuApicIdReorderTable[Index].Package)); + } + + FreePool (MpContext); + + return EFI_SUCCESS; +} + + +EFI_STATUS +AppendCpuMapTableEntry ( + IN EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *AcpiLocalApic, + IN UINTN NumberOfCPUs, + IN UINTN NumberOfEnabledCPUs, + IN UINT8 LocalApicCounter + ) +{ + if (LocalApicCounter < NumberOfCPUs) { + AcpiLocalApic->Flags = mCpuApicIdReorderTable[LocalApicCounter].Flags; + AcpiLocalApic->ApicId = mCpuApicIdReorderTable[LocalApicCounter].ApicId; + // + // Make AcpiProcessorIds 1-based, matching the ones in Processor() definitions + // + AcpiLocalApic->AcpiProcessorId = LocalApicCounter + 1; + } else { + AcpiLocalApic->Flags = 0; + AcpiLocalApic->ApicId = 0xFF; + // + // Make AcpiProcessorIds 1-based, matching the ones in Processor() definitions + // + AcpiLocalApic->AcpiProcessorId = LocalApicCounter + 1; + } + + // + // Display the results + // + DEBUG((DEBUG_INFO, "AcpiLocalApic: AcpiProcessorId=%x, ApicId=%x, Flags=%x\n", \ + AcpiLocalApic->AcpiProcessorId, \ + AcpiLocalApic->ApicId, \ + AcpiLocalApic->Flags)); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h new file mode 100644 index 0000000000..3ba9b02340 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h @@ -0,0 +1,128 @@ +/** @file + This is an implementation of the ACPI platform driver. + +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. + +**/ + +#ifndef _ACPI_PLATFORM_H_ +#define _ACPI_PLATFORM_H_ + +// +// Statements that include other header files +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "Fadt/Fadt.h" +#include "Facs/Facs.h" +#include "Madt/Madt.h" +#include "Mcfg/Mcfg.h" +#include "Hpet/Hpet.h" +#include "Wsmt/Wsmt.h" + +// +// ACPI table information used to initialize tables. +// +#define EFI_ACPI_OEM_ID "INTEL " +#define ACPI_OEM_TABLE_ID_SKL 0x4C4B53 // SKL +#define ACPI_OEM_TABLE_ID_SKL_ULT 0x544C552D4C4B53 // SKL-ULT +#define ACPI_OEM_TABLE_ID_SKL_SDS 0x5344532D4C4B53 // SKL-SDS +#define ACPI_OEM_TABLE_ID_KBL 0x4C424B // KBL +#define ACPI_OEM_TABLE_ID_KBL_ULT 0x544C552D4C424B // KBL-ULT +#define ACPI_OEM_TABLE_ID_KBL_SDS 0x5344532D4C424B // KBL-SDS +#define ACPI_OEM_TABLE_ID_UNKNOWN 0x304E574F4E4B4E55 // "UNKNOWN0" +#define EFI_ACPI_OEM_REVISION 0x00000001 +#define EFI_ACPI_CREATOR_ID 0x5446534D // "MSFT" +#define EFI_ACPI_CREATOR_REVISION 0x00000005F + +#define MAX_CPU_NUM 16 + +typedef struct { + UINT8 ApicId; + UINT32 Flags; + UINT8 Package; + UINT8 Die; + UINT8 Core; + UINT8 Thread; +} EFI_CPU_ID_ORDER_MAP; + +typedef struct { + UINT8 Package; + UINT8 ApicId; + UINT32 Flags; +} EFI_CPU_APIC_ID_REORDER_MAP; + +typedef struct { + UINT8 BspApicId; + UINT8 TotalThreads; + UINT8 PackageNo; + UINT8 CoreNo; + UINT8 LogicalThreadNo; +} EFI_CPU_PACKAGE_INFO; + +// +// Function definitions +// + +/** + Entry point of the ACPI platform driver. + + @param[in] ImageHandle A handle for the image that is initializing this driver + @param[in] SystemTable A pointer to the EFI system table + + @retval EFI_SUCCESS The driver installed without error. + @retval EFI_ABORTED The driver encountered an error and could not complete + installation of the ACPI tables. +**/ +EFI_STATUS +EFIAPI +InstallAcpiPlatform ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +EFI_STATUS +SortCpuLocalApicInTable ( + IN EFI_MP_SERVICES_PROTOCOL *MpService, + IN UINTN NumberOfCPUs, + IN UINTN NumberOfEnabledCPUs + ); + +EFI_STATUS +AppendCpuMapTableEntry ( + IN EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *AcpiLocalApic, + IN UINTN NumberOfCPUs, + IN UINTN NumberOfEnabledCPUs, + IN UINT8 LocalApicCounter + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf new file mode 100644 index 0000000000..8a2007bbe2 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf @@ -0,0 +1,101 @@ +### @file +# Component information file for AcpiPlatform module +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = AcpiPlatform + FILE_GUID = FC90EB7A-3E0A-483C-A26C-484D36593FF4 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = InstallAcpiPlatform + +[Sources.common] + AcpiPlatform.h + AcpiPlatform.c + Fadt/Fadt.c + Facs/Facs.c + Hpet/Hpet.c + Madt/Madt.c + Mcfg/Mcfg.c + Wsmt/Wsmt.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + PcAtChipsetPkg/PcAtChipsetPkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + BaseLib + DebugLib + IoLib + PcdLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + BaseMemoryLib + HobLib + AslUpdateLib + BoardAcpiTableLib + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId ## CONSUMES + gPcAtChipsetPkgTokenSpaceGuid.PcdHpetBaseAddress + + gPlatformModuleTokenSpaceGuid.PcdPreferredPmProfile + gPlatformModuleTokenSpaceGuid.PcdLowPowerS0Idle + gPlatformModuleTokenSpaceGuid.PcdTenSecondPowerButtonEnable + gPlatformModuleTokenSpaceGuid.PcdPciExpNative + gPlatformModuleTokenSpaceGuid.PcdNativeAspmEnable + +[FixedPcd] + gPlatformModuleTokenSpaceGuid.PcdAcpiPm1AEventBlockAddress + gPlatformModuleTokenSpaceGuid.PcdAcpiPm1BEventBlockAddress + gPlatformModuleTokenSpaceGuid.PcdAcpiPm1AControlBlockAddress + gPlatformModuleTokenSpaceGuid.PcdAcpiPm1BControlBlockAddress + gPlatformModuleTokenSpaceGuid.PcdAcpiPm2ControlBlockAddress + gPlatformModuleTokenSpaceGuid.PcdAcpiPmTimerBlockAddress + gPlatformModuleTokenSpaceGuid.PcdAcpiGpe0BlockAddress + gPlatformModuleTokenSpaceGuid.PcdAcpiGpe1BlockAddress + gPlatformModuleTokenSpaceGuid.PcdPciExpressRegionLength + + gPlatformModuleTokenSpaceGuid.PcdApicLocalAddress ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdApicIoAddress ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdAcpiEnableSwSmi ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdAcpiDisableSwSmi ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdApicIoIdPch ## CONSUMES + + gPlatformModuleTokenSpaceGuid.PcdWsmtProtectionFlags + +[Protocols] + gEfiAcpiTableProtocolGuid ## CONSUMES + gEfiMpServiceProtocolGuid ## CONSUMES + gEfiPciIoProtocolGuid ## CONSUMES + +[Guids] + gEfiGlobalVariableGuid ## CONSUMES + gEfiHobListGuid ## CONSUMES + gEfiEndOfDxeEventGroupGuid ## CONSUMES + +[Depex] + gEfiAcpiTableProtocolGuid AND + gEfiMpServiceProtocolGuid AND + gEfiPciRootBridgeIoProtocolGuid AND + gEfiVariableArchProtocolGuid AND + gEfiVariableWriteArchProtocolGuid + + diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.c new file mode 100644 index 0000000000..5cc44182af --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.c @@ -0,0 +1,74 @@ +/** @file + This file contains a structure definition for the ACPI 5.0 Firmware ACPI + Control Structure (FACS). The contents of this file should only be modified + for bug fixes, no porting is required. + +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. + +**/ + +// +// Statements that include other files +// + +#include "Facs.h" + +// +// Firmware ACPI Control Structure +// Please modify all values in Facs.h only. +// + +EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE Facs = { + EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE, + sizeof (EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE), + + // + // Hardware Signature will be updated at runtime + // + 0x00000000, + + EFI_ACPI_FIRMWARE_WAKING_VECTOR, + EFI_ACPI_GLOBAL_LOCK, + EFI_ACPI_FIRMWARE_CONTROL_STRUCTURE_FLAGS, + EFI_ACPI_X_FIRMWARE_WAKING_VECTOR, + EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION, + { + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE + }, + EFI_ACPI_RESERVED_DWORD, //EFI_ACPI_5_0_OSPM_64BIT_WAKE_F + { + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE + } +}; diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.h b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.h new file mode 100644 index 0000000000..4254d9c4b2 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Facs/Facs.h @@ -0,0 +1,42 @@ +/** @file + This file describes the contents of the ACPI Firmware ACPI Control + Structure (FACS). All changes to the FACS contents should be done + in this 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. + +**/ + +#ifndef _FACS_H_ +#define _FACS_H_ + +// +// Statements that include other files +// + +#include + +// +// FACS Definitions +// + +#define EFI_ACPI_FIRMWARE_WAKING_VECTOR 0x00000000 +#define EFI_ACPI_GLOBAL_LOCK 0x00000000 + +// +// Firmware Control Structure Feature Flags are defined in AcpiX.0.h +// +#define EFI_ACPI_FIRMWARE_CONTROL_STRUCTURE_FLAGS 0x00000000 + +#define EFI_ACPI_X_FIRMWARE_WAKING_VECTOR 0x0000000000000000 + +extern EFI_ACPI_5_0_FIRMWARE_ACPI_CONTROL_STRUCTURE Facs; + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.c new file mode 100644 index 0000000000..0eb1328332 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.c @@ -0,0 +1,222 @@ +/** @file + This file contains a structure definition for the ACPI 5.0 Fixed ACPI + Description Table (FADT). The contents of this file should only be modified + for bug fixes, no porting is required. + +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. + +**/ + +// +// Statements that include other files +// + +#include "Fadt.h" + +// +// Fixed ACPI Description Table +// Please modify all values in Fadt.h only. +// + +EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE Fadt = { + { + EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, + sizeof (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE), + EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION, + + // + // Checksum will be updated at runtime + // + 0x00, + + // + // It is expected that these values will be updated at runtime + // + { ' ', ' ', ' ', ' ', ' ', ' ' }, + + 0, + EFI_ACPI_OEM_FADT_REVISION, + 0, + 0 + }, + + // + // These addresses will be updated at runtime + // + 0x00000000, + 0x00000000, + + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_PREFERRED_PM_PROFILE, + EFI_ACPI_SCI_INT, + EFI_ACPI_SMI_CMD, + FixedPcdGet8 (PcdAcpiEnableSwSmi), + FixedPcdGet8 (PcdAcpiDisableSwSmi), + EFI_ACPI_S4_BIOS_REQ, + EFI_ACPI_PSTATE_CNT, + + EFI_ACPI_PM1A_EVT_BLK_ADDRESS, + EFI_ACPI_PM1B_EVT_BLK_ADDRESS, + EFI_ACPI_PM1A_CNT_BLK_ADDRESS, + EFI_ACPI_PM1B_CNT_BLK_ADDRESS, + EFI_ACPI_PM2_CNT_BLK_ADDRESS, + EFI_ACPI_PM_TMR_BLK_ADDRESS, + EFI_ACPI_GPE0_BLK_ADDRESS, + EFI_ACPI_GPE1_BLK_ADDRESS, + EFI_ACPI_PM1_EVT_LEN, + EFI_ACPI_PM1_CNT_LEN, + EFI_ACPI_PM2_CNT_LEN, + EFI_ACPI_PM_TMR_LEN, + EFI_ACPI_GPE0_BLK_LEN, + EFI_ACPI_GPE1_BLK_LEN, + EFI_ACPI_GPE1_BASE, + + // + // Latest OS have C-State capability and CST_CNT SMI doesn't need to be defined. + // CST_CNT SMI is not handled in BIOS and it can be removed safely. + // + EFI_ACPI_CST_CNT, + EFI_ACPI_P_LVL2_LAT, + EFI_ACPI_P_LVL3_LAT, + EFI_ACPI_FLUSH_SIZE, + EFI_ACPI_FLUSH_STRIDE, + EFI_ACPI_DUTY_OFFSET, + EFI_ACPI_DUTY_WIDTH, + EFI_ACPI_DAY_ALRM, + EFI_ACPI_MON_ALRM, + EFI_ACPI_CENTURY, + EFI_ACPI_IAPC_BOOT_ARCH, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_FIXED_FEATURE_FLAGS, + + // + // Reset Register Block + // + { + EFI_ACPI_RESET_REG_ADDRESS_SPACE_ID, + EFI_ACPI_RESET_REG_BIT_WIDTH, + EFI_ACPI_RESET_REG_BIT_OFFSET, + EFI_ACPI_5_0_BYTE, + EFI_ACPI_RESET_REG_ADDRESS + }, + EFI_ACPI_RESET_VALUE, + { + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE, + EFI_ACPI_RESERVED_BYTE + }, + + // + // These addresses will be updated at runtime + // + 0x0000000000000000, // X_FIRMWARE_CTRL + 0x0000000000000000, // X_DSDT + + { + // + // X_PM1a Event Register Block + // + EFI_ACPI_PM1A_EVT_BLK_ADDRESS_SPACE_ID, + EFI_ACPI_PM1A_EVT_BLK_BIT_WIDTH, + EFI_ACPI_PM1A_EVT_BLK_BIT_OFFSET, + EFI_ACPI_5_0_WORD, + EFI_ACPI_PM1A_EVT_BLK_ADDRESS + }, + { + // + // X_PM1b Event Register Block + // + EFI_ACPI_PM1B_EVT_BLK_ADDRESS_SPACE_ID, + EFI_ACPI_PM1B_EVT_BLK_BIT_WIDTH, + EFI_ACPI_PM1B_EVT_BLK_BIT_OFFSET, + EFI_ACPI_5_0_WORD, + EFI_ACPI_PM1B_EVT_BLK_ADDRESS + }, + { + // + // X_PM1a Control Register Block + // + EFI_ACPI_PM1A_CNT_BLK_ADDRESS_SPACE_ID, + EFI_ACPI_PM1A_CNT_BLK_BIT_WIDTH, + EFI_ACPI_PM1A_CNT_BLK_BIT_OFFSET, + EFI_ACPI_5_0_WORD, + EFI_ACPI_PM1A_CNT_BLK_ADDRESS + }, + { + // + // X_PM1b Control Register Block + // + EFI_ACPI_PM1B_CNT_BLK_ADDRESS_SPACE_ID, + EFI_ACPI_PM1B_CNT_BLK_BIT_WIDTH, + EFI_ACPI_PM1B_CNT_BLK_BIT_OFFSET, + EFI_ACPI_5_0_WORD, + EFI_ACPI_PM1B_CNT_BLK_ADDRESS + }, + { + // + // X_PM2 Control Register Block + // + EFI_ACPI_PM2_CNT_BLK_ADDRESS_SPACE_ID, + EFI_ACPI_PM2_CNT_BLK_BIT_WIDTH, + EFI_ACPI_PM2_CNT_BLK_BIT_OFFSET, + EFI_ACPI_5_0_BYTE, + EFI_ACPI_PM2_CNT_BLK_ADDRESS + }, + { + // + // X_PM Timer Control Register Block + // + EFI_ACPI_PM_TMR_BLK_ADDRESS_SPACE_ID, + EFI_ACPI_PM_TMR_BLK_BIT_WIDTH, + EFI_ACPI_PM_TMR_BLK_BIT_OFFSET, + EFI_ACPI_5_0_DWORD, + EFI_ACPI_PM_TMR_BLK_ADDRESS + }, + { + // + // X_General Purpose Event 0 Register Block + // + EFI_ACPI_GPE0_BLK_ADDRESS_SPACE_ID, + 0x0, + EFI_ACPI_GPE0_BLK_BIT_OFFSET, + EFI_ACPI_5_0_BYTE, + EFI_ACPI_GPE0_BLK_ADDRESS + }, + { + // + // X_General Purpose Event 1 Register Block + // + EFI_ACPI_GPE1_BLK_ADDRESS_SPACE_ID, + EFI_ACPI_GPE1_BLK_BIT_WIDTH, + EFI_ACPI_GPE1_BLK_BIT_OFFSET, + EFI_ACPI_5_0_BYTE, + EFI_ACPI_GPE1_BLK_ADDRESS + }, + { + // + // Sleep Control Reg - update in DXE driver + // + 0, + 0, + 0, + 0, + 0 + }, + { + // + // Sleep Status Reg - update in DXE driver + // + 0, + 0, + 0, + 0, + 0 + } +}; diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.h b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.h new file mode 100644 index 0000000000..fb4c191b59 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Fadt/Fadt.h @@ -0,0 +1,189 @@ +/** @file + This file describes the contents of the ACPI Fixed ACPI Description Table + (FADT). All changes to the FADT contents should be done in this 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. + +**/ + +#ifndef _FADT_H_ +#define _FADT_H_ + +// +// Statements that include other files +// + +#include + +// +// FADT Definitions +// +#ifndef EFI_ACPI_OEM_FADT_REVISION +#define EFI_ACPI_OEM_FADT_REVISION 0x00000000 +#endif + +// +// For ACPI 1.0 support +// +#define EFI_ACPI_INT_MODEL 0x00 +/* +1 Desktop +2 Mobile +3 Workstation +4 Enterprise Server +5 SOHO Server +6 Appliance PC +7 Performance Server +*/ +#define EFI_ACPI_PREFERRED_PM_PROFILE 0x02 +#define EFI_ACPI_SCI_INT 0x0009 +#define EFI_ACPI_SMI_CMD 0x000000B2 +#define EFI_ACPI_S4_BIOS_REQ 0xF2 +#define EFI_ACPI_PSTATE_CNT 0x00 +#define EFI_ACPI_GPE1_BASE 0x10 +#define EFI_ACPI_CST_CNT 0x0 +#define EFI_ACPI_P_LVL2_LAT 101 +#define EFI_ACPI_P_LVL3_LAT 1001 +#define EFI_ACPI_FLUSH_SIZE 0x0000 +#define EFI_ACPI_FLUSH_STRIDE 0x0000 +#define EFI_ACPI_DUTY_OFFSET 0x01 +#define EFI_ACPI_DUTY_WIDTH 0x03 +#define EFI_ACPI_DAY_ALRM 0x0D +#define EFI_ACPI_MON_ALRM 0x00 +#define EFI_ACPI_CENTURY 0x32 + +// +// IA-PC Boot Architecture Flags, see ACPI 5.0 table specification and Acpi50.h +// We should not use EFI_ACPI_5_0_8042 for legacy free platform, or XP reset fail. No impact to mobile. +// +#define EFI_ACPI_IAPC_BOOT_ARCH (EFI_ACPI_5_0_LEGACY_DEVICES) + +// +// Fixed Feature Flags, see ACPI 2.0 table specification and Acpi2_0.h +// +#define EFI_ACPI_FIXED_FEATURE_FLAGS (\ + EFI_ACPI_5_0_USE_PLATFORM_CLOCK | \ + EFI_ACPI_5_0_WBINVD | \ + EFI_ACPI_5_0_DCK_CAP | \ + EFI_ACPI_5_0_RTC_S4 | \ + EFI_ACPI_5_0_SLP_BUTTON | \ + EFI_ACPI_5_0_PROC_C1 | \ + EFI_ACPI_5_0_RESET_REG_SUP \ + ) + +// +// PM1A Event Register Block Generic Address Information +// +#define EFI_ACPI_PM1A_EVT_BLK_ADDRESS_SPACE_ID EFI_ACPI_5_0_SYSTEM_IO +#define EFI_ACPI_PM1A_EVT_BLK_BIT_WIDTH 0x20 +#define EFI_ACPI_PM1A_EVT_BLK_BIT_OFFSET 0x00 +#define EFI_ACPI_PM1A_EVT_BLK_ADDRESS FixedPcdGet16 (PcdAcpiPm1AEventBlockAddress) + +// +// PM1B Event Register Block Generic Address Information +// +#define EFI_ACPI_PM1B_EVT_BLK_ADDRESS_SPACE_ID EFI_ACPI_5_0_SYSTEM_IO +#define EFI_ACPI_PM1B_EVT_BLK_BIT_WIDTH 0x00 +#define EFI_ACPI_PM1B_EVT_BLK_BIT_OFFSET 0x00 +#define EFI_ACPI_PM1B_EVT_BLK_ADDRESS FixedPcdGet16 (PcdAcpiPm1BEventBlockAddress) + +// +// PM1A Control Register Block Generic Address Information +// +#define EFI_ACPI_PM1A_CNT_BLK_ADDRESS_SPACE_ID EFI_ACPI_5_0_SYSTEM_IO +#define EFI_ACPI_PM1A_CNT_BLK_BIT_WIDTH 0x10 +#define EFI_ACPI_PM1A_CNT_BLK_BIT_OFFSET 0x00 +#define EFI_ACPI_PM1A_CNT_BLK_ADDRESS FixedPcdGet16 (PcdAcpiPm1AControlBlockAddress) + +// +// PM1B Control Register Block Generic Address Information +// +#define EFI_ACPI_PM1B_CNT_BLK_ADDRESS_SPACE_ID EFI_ACPI_5_0_SYSTEM_IO +#define EFI_ACPI_PM1B_CNT_BLK_BIT_WIDTH 0x00 +#define EFI_ACPI_PM1B_CNT_BLK_BIT_OFFSET 0x00 +#define EFI_ACPI_PM1B_CNT_BLK_ADDRESS FixedPcdGet16 (PcdAcpiPm1BControlBlockAddress) + +// +// PM2 Control Register Block Generic Address Information +// +#define EFI_ACPI_PM2_CNT_BLK_ADDRESS_SPACE_ID EFI_ACPI_5_0_SYSTEM_IO +#define EFI_ACPI_PM2_CNT_BLK_BIT_WIDTH 0x08 +#define EFI_ACPI_PM2_CNT_BLK_BIT_OFFSET 0x00 +#define EFI_ACPI_PM2_CNT_BLK_ADDRESS FixedPcdGet16 (PcdAcpiPm2ControlBlockAddress) + +// +// Power Management Timer Control Register Block Generic Address +// Information +// +#define EFI_ACPI_PM_TMR_BLK_ADDRESS_SPACE_ID EFI_ACPI_5_0_SYSTEM_IO +#define EFI_ACPI_PM_TMR_BLK_BIT_WIDTH 0x20 +#define EFI_ACPI_PM_TMR_BLK_BIT_OFFSET 0x00 +#define EFI_ACPI_PM_TMR_BLK_ADDRESS FixedPcdGet16 (PcdAcpiPmTimerBlockAddress) + +// +// General Purpose Event 0 Register Block Generic Address +// Information +// +#define EFI_ACPI_GPE0_BLK_ADDRESS_SPACE_ID EFI_ACPI_5_0_SYSTEM_IO +#define EFI_ACPI_GPE0_BLK_BIT_WIDTH 0x100 +#define EFI_ACPI_GPE0_BLK_BIT_OFFSET 0x00 +#define EFI_ACPI_GPE0_BLK_ADDRESS FixedPcdGet16 (PcdAcpiGpe0BlockAddress) + +// +// General Purpose Event 1 Register Block Generic Address +// Information +// +#define EFI_ACPI_GPE1_BLK_ADDRESS_SPACE_ID EFI_ACPI_5_0_SYSTEM_IO +#define EFI_ACPI_GPE1_BLK_BIT_WIDTH 0x00 +#define EFI_ACPI_GPE1_BLK_BIT_OFFSET 0x00 +#define EFI_ACPI_GPE1_BLK_ADDRESS FixedPcdGet16 (PcdAcpiGpe1BlockAddress) + +// +// Reset Register Generic Address Information +// +#define EFI_ACPI_RESET_REG_ADDRESS_SPACE_ID EFI_ACPI_5_0_SYSTEM_IO +#define EFI_ACPI_RESET_REG_BIT_WIDTH 0x08 +#define EFI_ACPI_RESET_REG_BIT_OFFSET 0x00 +#define EFI_ACPI_RESET_REG_ADDRESS 0x0000000000000CF9 +#define EFI_ACPI_RESET_VALUE 0x06 + +// +// Number of bytes decoded by PM1 event blocks (a and b) +// +#define EFI_ACPI_PM1_EVT_LEN ((EFI_ACPI_PM1A_EVT_BLK_BIT_WIDTH + EFI_ACPI_PM1B_EVT_BLK_BIT_WIDTH) / 8) + +// +// Number of bytes decoded by PM1 control blocks (a and b) +// +#define EFI_ACPI_PM1_CNT_LEN ((EFI_ACPI_PM1A_CNT_BLK_BIT_WIDTH + EFI_ACPI_PM1B_CNT_BLK_BIT_WIDTH) / 8) + +// +// Number of bytes decoded by PM2 control block +// +#define EFI_ACPI_PM2_CNT_LEN (EFI_ACPI_PM2_CNT_BLK_BIT_WIDTH / 8) + +// +// Number of bytes decoded by PM timer block +// +#define EFI_ACPI_PM_TMR_LEN (EFI_ACPI_PM_TMR_BLK_BIT_WIDTH / 8) + +// +// Number of bytes decoded by GPE0 block +// +#define EFI_ACPI_GPE0_BLK_LEN (EFI_ACPI_GPE0_BLK_BIT_WIDTH / 8) + +// +// Number of bytes decoded by GPE1 block +// +#define EFI_ACPI_GPE1_BLK_LEN (EFI_ACPI_GPE1_BLK_BIT_WIDTH / 8) + +extern EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE Fadt; + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.c new file mode 100644 index 0000000000..ea8fcba5ad --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.c @@ -0,0 +1,61 @@ +/** @file + This file contains a structure definition for the ACPI 1.0 High Precision Event Timer + Description Table (HPET). The contents of this file should only be modified + for bug fixes, no porting is required. + +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. + +**/ + +// +// Statements that include other files +// + +#include "Hpet.h" + +// +// High Precision Event Timer Table +// Please modify all values in Hpet.h only. +// + +EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_HEADER Hpet = { + { + EFI_ACPI_3_0_HIGH_PRECISION_EVENT_TIMER_TABLE_SIGNATURE, + sizeof (EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_HEADER), + EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_REVISION, + + // + // Checksum will be updated at runtime + // + 0x00, + + // + // It is expected that these values will be updated at runtime + // + { ' ', ' ', ' ', ' ', ' ', ' ' }, + + 0, + EFI_ACPI_OEM_HPET_REVISION, + 0, + 0 + }, + + EFI_ACPI_EVENT_TIMER_BLOCK_ID, + { + EFI_ACPI_EVENT_TIMER_BLOCK_ADDRESS_SPACE_ID, + EFI_ACPI_EVENT_TIMER_BLOCK_BIT_WIDTH, + EFI_ACPI_EVENT_TIMER_BLOCK_BIT_OFFSET, + EFI_ACPI_EVENT_TIMER_ACCESS_SIZE, + EFI_ACPI_EVENT_TIMER_BLOCK_ADDRESS + }, + EFI_ACPI_HPET_NUMBER, + EFI_ACPI_MIN_CLOCK_TICK, + EFI_ACPI_HPET_ATTRIBUTES +}; diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.h b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.h new file mode 100644 index 0000000000..b12954f330 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Hpet/Hpet.h @@ -0,0 +1,51 @@ +/** @file + This file describes the contents of the ACPI High Precision Event Timer Description Table + (HPET). All changes to the HPET contents should be done in this 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. + +**/ + +#ifndef _HPET_H_ +#define _HPET_H_ + +// +// Statements that include other files +// + +#include +#include + +// +// HPET Definitions +// + +#define EFI_ACPI_OEM_HPET_REVISION 0x00000001 + +#define EFI_ACPI_EVENT_TIMER_BLOCK_ID 0x8086A201 + +// +// Event Timer Block Base Address Information +// +#define EFI_ACPI_EVENT_TIMER_BLOCK_ADDRESS_SPACE_ID EFI_ACPI_3_0_SYSTEM_MEMORY +#define EFI_ACPI_EVENT_TIMER_BLOCK_BIT_WIDTH 0x40 +#define EFI_ACPI_EVENT_TIMER_BLOCK_BIT_OFFSET 0x00 +#define EFI_ACPI_EVENT_TIMER_ACCESS_SIZE 0x00 +#define EFI_ACPI_EVENT_TIMER_BLOCK_ADDRESS 0x00000000FED00000 + +#define EFI_ACPI_HPET_NUMBER 0x00 + +#define EFI_ACPI_MIN_CLOCK_TICK 0x0080 + +#define EFI_ACPI_HPET_ATTRIBUTES 0x00 + +extern EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_HEADER Hpet; + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.c new file mode 100644 index 0000000000..70ce150d73 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.c @@ -0,0 +1,389 @@ +/** @file + This file contains a structure definition for the ACPI 2.0 Multiple APIC + Description Table (MADT). Any changes to the MADT table require updating the + respective structure count in Madt.h and then adding the structure to the + MADT defined in this 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. + +**/ + +// +// Statements that include other files +// + +#include "Madt.h" + +// +// Multiple APIC Description Table +// + +EFI_ACPI_2_0_MULTIPLE_APIC_DESCRIPTION_TABLE Madt = { + { + { + EFI_ACPI_2_0_MULTIPLE_SAPIC_DESCRIPTION_TABLE_SIGNATURE, + sizeof (EFI_ACPI_2_0_MULTIPLE_APIC_DESCRIPTION_TABLE), + EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION, + + // + // Checksum will be updated at runtime + // + 0x00, + + // + // It is expected that these values will be programmed at runtime + // + { ' ', ' ', ' ', ' ', ' ', ' ' }, + + 0, + EFI_ACPI_OEM_MADT_REVISION, + 0, + 0 + }, + + // + // MADT specific fields + // + FixedPcdGet64 (PcdApicLocalAddress), + EFI_ACPI_2_0_MULTIPLE_APIC_FLAGS + }, + + // + // Sample Processor Local APIC Structure + // + //EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + //sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + //0x00 // Processor ID + //0x00 // Local APIC ID + //0x00000000, // Flags - Disabled (until initialized by platform driver) + { + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x01, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x02, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x03, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x04, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x05, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x06, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x07, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x08, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x09, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x0A, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x0B, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x0C, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x0D, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x0E, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x0F, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + }, + { + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC, // Type + sizeof (EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE), // Length + 0x10, // Processor ID + 0xFF, // Local APIC ID + 0x00000000 // Flags - Disabled (until initialized by platform driver) + } + }, + + // + // Sample IO APIC Structure + // + //EFI_ACPI_2_0_IO_APIC, // Type + //sizeof (EFI_ACPI_2_0_IO_APIC_STRUCTURE), // Length + //0x00, // IO APIC ID + //EFI_ACPI_RESERVED_BYTE, // Reserved + //0x00000000, // IO APIC Address (physical) + //0x00000000, // Global System Interrupt Base + { + { + // + // I/O SAPIC (ICH) + // + EFI_ACPI_2_0_IO_APIC, // Type + sizeof (EFI_ACPI_2_0_IO_APIC_STRUCTURE), // Length + FixedPcdGet8 (PcdApicIoIdPch), // IO APIC ID + EFI_ACPI_RESERVED_BYTE, // Reserved + FixedPcdGet64 (PcdApicIoAddress), // IO APIC Address (physical) + 0x18 * 0 // Global System Interrupt Base + } + }, + // + // Sample Interrupt Source Override Structure + // + //EFI_ACPI_2_0_INTERRUPT_SOURCE_OVERRIDE, // Type + //sizeof (EFI_ACPI_2_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE), // Length + //0x00, // Bus + //0x00, // Source + //0x00000000, // Global System Interrupt + //0x0000, // Flags + { + { + // + // IRQ0=>IRQ2 Interrupt Source Override Structure + // + EFI_ACPI_2_0_INTERRUPT_SOURCE_OVERRIDE, // Type + sizeof (EFI_ACPI_2_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE),// Length + 0x00, // Bus - ISA + 0x00, // Source - IRQ0 + 0x00000002, // Global System Interrupt - IRQ2 + 0x0000 // Flags - Conforms to specifications of the bus + }, + { + // + // ISO (SCI Active High) Interrupt Source Override Structure + // + EFI_ACPI_2_0_INTERRUPT_SOURCE_OVERRIDE, // Type + sizeof (EFI_ACPI_2_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE),// Length + 0x00, // Bus - ISA + 0x09, // Source - IRQ9 + 0x00000009, // Global System Interrupt - IRQ9 + 0x000D // Flags - Level-tiggered, Active High + } + }, + // + // Sample Non-Maskable Interrupt Source Structure + // + //EFI_ACPI_2_0_NON_MASKABLE_INTERRUPT_SOURCE, // Type + //sizeof (EFI_ACPI_2_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE), // Length + //0x0000, // Flags + //0x00000000, // Global System Interrupt + + // + // Sample Local APIC NMI Structure + // + //EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + //sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + //0x00, // ACPI Processor ID + //0x0000, // Flags + //0x00, // Local APIC LINT# + + { + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x01, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x02, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x03, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x04, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x05, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x06, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x07, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x08, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x09, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x0A, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x0B, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x0C, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x0D, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x0E, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x0F, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + }, + { + EFI_ACPI_2_0_LOCAL_APIC_NMI, // Type + sizeof (EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE), // Length + 0x10, // ACPI Processor ID + 0x0005, // Flags - Edge-tiggered, Active High + 0x01 // Local APIC LINT# + } + } + + // + // Sample Local APIC Address Override Structure + // + //EFI_ACPI_2_0_LOCAL_APIC_ADDRESS_OVERRIDE, // Type + //sizeof (EFI_ACPI_2_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE), // Length + //EFI_ACPI_RESERVED_WORD, // Reserved + //0x0000000000000000, // Local APIC Address + + // + // Sample Platform Interrupt Sources Structure + // + //EFI_ACPI_2_0_PLATFORM_INTERRUPT_SOURCES, // Type + //sizeof (EFI_ACPI_2_0_PLATFORM_INTERRUPT_SOURCES_STRUCTURE), // Length + //0x0000, // Flags + //0x00, // Interrupt Type + //0x00, // Processor ID + //0x00, // Processor EID + //0x00, // IO SAPIC Vector + //0x00000000, // Global System Interrupt + //EFI_ACPI_RESERVED_DWORD, // Reserved + +}; diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.h b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.h new file mode 100644 index 0000000000..d45db43b6d --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Madt/Madt.h @@ -0,0 +1,144 @@ +/** @file + This file describes the contents of the ACPI Multiple APIC Description + Table (MADT). + To make changes to the MADT, it is necessary to update the count for the + APIC structure being updated, and to modify table found in Madt.c. + +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. + +**/ + +#ifndef _MADT_H_ +#define _MADT_H_ + +// +// Statements that include other files +// + +#include + +// +// MADT Definitions +// + +#define EFI_ACPI_OEM_MADT_REVISION 0x00000001 + + +// +// Multiple APIC Flags are defined in AcpiX.0.h +// +#define EFI_ACPI_1_0_MULTIPLE_APIC_FLAGS (EFI_ACPI_1_0_PCAT_COMPAT) +#define EFI_ACPI_2_0_MULTIPLE_APIC_FLAGS (EFI_ACPI_2_0_PCAT_COMPAT) + +// +// Define the number of each table type. +// This is where the table layout is modified. +// + +#define EFI_ACPI_PROCESSOR_LOCAL_APIC_COUNT 16 +#define EFI_ACPI_IO_APIC_COUNT 1 +#define EFI_ACPI_INTERRUPT_SOURCE_OVERRIDE_COUNT 2 +#define EFI_ACPI_NON_MASKABLE_INTERRUPT_SOURCE_COUNT 0 +#define EFI_ACPI_LOCAL_APIC_NMI_COUNT 16 +#define EFI_ACPI_LOCAL_APIC_ADDRESS_OVERRIDE_COUNT 0 +#define EFI_ACPI_IO_SAPIC_COUNT 0 +#define EFI_ACPI_PROCESSOR_LOCAL_SAPIC_COUNT 0 +#define EFI_ACPI_PLATFORM_INTERRUPT_SOURCES_COUNT 0 + +// +// MADT structure +// + +// +// Ensure proper structure formats +// +#pragma pack (1) + +// +// ACPI 1.0 Table structure +// +typedef struct { + EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER Header; + +#if EFI_ACPI_PROCESSOR_LOCAL_APIC_COUNT > 0 + EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE LocalApic[EFI_ACPI_PROCESSOR_LOCAL_APIC_COUNT]; +#endif + +#if EFI_ACPI_IO_APIC_COUNT > 0 + EFI_ACPI_1_0_IO_APIC_STRUCTURE IoApic[EFI_ACPI_IO_APIC_COUNT]; +#endif + +#if EFI_ACPI_INTERRUPT_SOURCE_OVERRIDE_COUNT > 0 + EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE Iso[EFI_ACPI_INTERRUPT_SOURCE_OVERRIDE_COUNT]; +#endif + +#if EFI_ACPI_NON_MASKABLE_INTERRUPT_SOURCE_COUNT > 0 + EFI_ACPI_1_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE NmiSource[EFI_ACPI_NON_MASKABLE_INTERRUPT_SOURCE_COUNT]; +#endif + +#if EFI_ACPI_LOCAL_APIC_NMI_COUNT > 0 + EFI_ACPI_1_0_LOCAL_APIC_NMI_STRUCTURE LocalApicNmi[EFI_ACPI_LOCAL_APIC_NMI_COUNT]; +#endif + +#if EFI_ACPI_LOCAL_APIC_ADDRESS_OVERRIDE_COUNT > 0 + EFI_ACPI_1_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE LocalApicOverride[EFI_ACPI_LOCAL_APIC_OVERRIDE_COUNT]; +#endif + +} EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE; + +// +// ACPI 2.0 Table structure +// +typedef struct { + EFI_ACPI_2_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER Header; + +#if EFI_ACPI_PROCESSOR_LOCAL_APIC_COUNT > 0 + EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE LocalApic[EFI_ACPI_PROCESSOR_LOCAL_APIC_COUNT]; +#endif + +#if EFI_ACPI_IO_APIC_COUNT > 0 + EFI_ACPI_2_0_IO_APIC_STRUCTURE IoApic[EFI_ACPI_IO_APIC_COUNT]; +#endif + +#if EFI_ACPI_INTERRUPT_SOURCE_OVERRIDE_COUNT > 0 + EFI_ACPI_2_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE Iso[EFI_ACPI_INTERRUPT_SOURCE_OVERRIDE_COUNT]; +#endif + +#if EFI_ACPI_NON_MASKABLE_INTERRUPT_SOURCE_COUNT > 0 + EFI_ACPI_2_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE NmiSource[EFI_ACPI_NON_MASKABLE_INTERRUPT_SOURCE_COUNT]; +#endif + +#if EFI_ACPI_LOCAL_APIC_NMI_COUNT > 0 + EFI_ACPI_2_0_LOCAL_APIC_NMI_STRUCTURE LocalApicNmi[EFI_ACPI_LOCAL_APIC_NMI_COUNT]; +#endif + +#if EFI_ACPI_LOCAL_APIC_ADDRESS_OVERRIDE_COUNT > 0 + EFI_ACPI_2_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE LocalApicOverride[EFI_ACPI_LOCAL_APIC_OVERRIDE_COUNT]; +#endif + +#if EFI_ACPI_IO_SAPIC_COUNT > 0 + EFI_ACPI_2_0_IO_SAPIC_STRUCTURE IoSapic[EFI_ACPI_IO_SAPIC_COUNT]; +#endif + +#if EFI_ACPI_PROCESSOR_LOCAL_SAPIC_COUNT > 0 + EFI_ACPI_2_0_PROCESSOR_LOCAL_SAPIC_STRUCTURE LocalSapic[EFI_ACPI_PROCESSOR_LOCAL_SAPIC_COUNT]; +#endif + +#if EFI_ACPI_PLATFORM_INTERRUPT_SOURCES_COUNT > 0 + EFI_ACPI_2_0_PLATFORM_INTERRUPT_SOURCES_STRUCTURE PlatformInterruptSources[EFI_ACPI_PLATFORM_INTERRUPT_SOURCES_COUNT]; +#endif + +} EFI_ACPI_2_0_MULTIPLE_APIC_DESCRIPTION_TABLE; + +#pragma pack () + +extern EFI_ACPI_2_0_MULTIPLE_APIC_DESCRIPTION_TABLE Madt; + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.c new file mode 100644 index 0000000000..86f491a0bb --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.c @@ -0,0 +1,78 @@ +/** @file + This file contains a structure definition for the ACPI Memory Mapped Configuration + Address Space table (MCFG). Any changes to the number of entries in the table require + updating the structure count in Mcfg.h and then adding the structure to the + MCFG defined in this file. The table layout is defined in Mcfg.h and the + table contents are defined in the MemoryMappedConfigurationSpaceAccessTable.h. + +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. + +**/ + +// +// Statements that include other files +// + +#include "Mcfg.h" + +// +// Multiple APIC Description Table +// + +EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE Mcfg = { + { + EFI_ACPI_3_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE, + sizeof (EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE), + EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION, + + // + // Checksum will be updated at runtime + // + 0x00, + + // + // It is expected that these values will be programmed at runtime + // + { ' ', ' ', ' ', ' ', ' ', ' ' }, + + 0, + EFI_ACPI_OEM_MCFG_REVISION, + 0, + 0 + }, + + // + // Reserved + // + 0x0000000000000000, + + // + // MCFG specific fields + // + { + { + // + // Sample Base Address Structure + // + //0x0000000000000000, // BaseAddress + //0x0000, // PciSegmentGroupNumber + //0x00, // StartBusNumber + //0x00, // EndBusNumber + //0x00000000, // Reserved + + FixedPcdGet64 (PcdPciExpressBaseAddress), // BaseAddress + 0x0000, // PciSegmentGroupNumber + 0x00, // StartBusNumber + ((FixedPcdGet32 (PcdPciExpressRegionLength) / 0x100000) - 1), // EndBusNumber + 0x00000000 // Reserved + } + } +}; + diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.h b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.h new file mode 100644 index 0000000000..e41c223ef5 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Mcfg/Mcfg.h @@ -0,0 +1,62 @@ +/** @file + This file describes the contents of the ACPI Memory Mapped Configuration + Space Access Table (MCFG). + +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. + +**/ + +#ifndef _MCFG_H_ +#define _MCFG_H_ + +// +// Statements that include other files +// + +#include +#include + +// +// MCFG Definitions +// + +#define EFI_ACPI_OEM_MCFG_REVISION 0x00000001 + +// +// Define the number of allocation structures so that we can build the table structure. +// + +#define EFI_ACPI_ALLOCATION_STRUCTURE_COUNT 1 + +// +// MCFG structure +// + +// +// Ensure proper structure formats +// +#pragma pack (1) + +// +// MCFG Table structure +// +typedef struct { + EFI_ACPI_DESCRIPTION_HEADER Header; + UINT64 Reserved; +#if EFI_ACPI_ALLOCATION_STRUCTURE_COUNT > 0 + EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE AllocationStructure[EFI_ACPI_ALLOCATION_STRUCTURE_COUNT]; +#endif +} EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE; + +#pragma pack () + +extern EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE Mcfg; + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.c new file mode 100644 index 0000000000..ca6657d878 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.c @@ -0,0 +1,44 @@ +/** @file + ACPI WSMT table + +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. + +**/ + +// +// Statements that include other files +// + +#include "Wsmt.h" + +EFI_ACPI_WSMT_TABLE Wsmt = { + { + EFI_ACPI_WINDOWS_SMM_SECURITY_MITIGATION_TABLE_SIGNATURE, + sizeof (EFI_ACPI_WSMT_TABLE), + EFI_WSMT_TABLE_REVISION, + + // + // Checksum will be updated at runtime + // + 0x00, + + // + // It is expected that these values will be updated at runtime + // + { ' ', ' ', ' ', ' ', ' ', ' ' }, + + 0, + EFI_ACPI_OEM_WSMT_REVISION, + 0, + 0 + }, + + FixedPcdGet32(PcdWsmtProtectionFlags) +}; diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.h b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.h new file mode 100644 index 0000000000..dba8e23685 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/Wsmt/Wsmt.h @@ -0,0 +1,30 @@ +/** @file + ACPI WSMT table + +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. + +**/ + +#ifndef _WSMT_H_ +#define _WSMT_H_ + +#include +#include +#include + +// +// WSMT Definitions +// + +#define EFI_ACPI_OEM_WSMT_REVISION 0x00000001 + +extern EFI_ACPI_WSMT_TABLE Wsmt; + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLib.c b/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLib.c new file mode 100644 index 0000000000..ff284fc404 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLib.c @@ -0,0 +1,35 @@ +/** @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 + +EFI_STATUS +EFIAPI +BoardEnableAcpi ( + IN BOOLEAN EnableSci + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardDisableAcpi ( + IN BOOLEAN DisableSci + ) +{ + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLibNull.inf b/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLibNull.inf new file mode 100644 index 0000000000..10cc8fffff --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLibNull.inf @@ -0,0 +1,34 @@ +## @file +# Component information file for Board Acpi Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BoardAcpiEnableLib + FILE_GUID = EAF8AA6D-549A-40CC-8FB2-3A1FFEC41601 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = BoardAcpiEnableLib + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + +[Sources] + BoardAcpiEnableLib.c diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLib.c b/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLib.c new file mode 100644 index 0000000000..59a27c29a9 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLib.c @@ -0,0 +1,28 @@ +/** @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 + +EFI_STATUS +EFIAPI +BoardUpdateAcpiTable ( + IN OUT EFI_ACPI_COMMON_HEADER *Table, + IN OUT EFI_ACPI_TABLE_VERSION *Version + ) +{ + return EFI_SUCCESS; +} + diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLibNull.inf b/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLibNull.inf new file mode 100644 index 0000000000..1564c8546f --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLibNull.inf @@ -0,0 +1,34 @@ +## @file +# Component information file for Board Acpi Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BoardAcpiTableLib + FILE_GUID = F220FAB7-F8E4-4E7A-A599-D47E2D547956 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = BoardAcpiTableLib + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + +[Sources] + BoardAcpiTableLib.c diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.c b/Platform/Intel/MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.c new file mode 100644 index 0000000000..ea85be4a11 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.c @@ -0,0 +1,314 @@ +/** @file + Boot service DXE ASL update library implementation. + + These functions in this file can be called during DXE and cannot be called during runtime + or in SMM which should use a RT or SMM library. + + This library uses the ACPI Support protocol. + +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 + +// +// Function implemenations +// +static EFI_ACPI_SDT_PROTOCOL *mAcpiSdt = NULL; +static EFI_ACPI_TABLE_PROTOCOL *mAcpiTable = NULL; + +/** + Initialize the ASL update library state. + This must be called prior to invoking other library functions. + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +InitializeAslUpdateLib ( + VOID + ) +{ + EFI_STATUS Status; + + /// + /// Locate ACPI tables + /// + Status = gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID **) &mAcpiSdt); + ASSERT_EFI_ERROR (Status); + Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &mAcpiTable); + ASSERT_EFI_ERROR (Status); + return Status; +} + + +/** + This procedure will update immediate value assigned to a Name + + @param[in] AslSignature - The signature of Operation Region that we want to update. + @param[in] Buffer - source of data to be written over original aml + @param[in] Length - length of data to be overwritten + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +UpdateNameAslCode ( + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ) +{ + EFI_STATUS Status; + EFI_ACPI_DESCRIPTION_HEADER *Table; + UINT8 *CurrPtr; + UINT32 *Signature; + UINT8 *DsdtPointer; + UINTN Handle; + UINT8 DataSize; + + if (mAcpiTable == NULL) { + InitializeAslUpdateLib (); + if (mAcpiTable == NULL) { + return EFI_NOT_READY; + } + } + + /// + /// Locate table with matching ID + /// + Handle = 0; + Status = LocateAcpiTableBySignature ( + EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, + (EFI_ACPI_DESCRIPTION_HEADER **) &Table, + &Handle + ); + if (EFI_ERROR (Status)) { + return Status; + } + + /// + /// Point to the beginning of the DSDT table + /// + CurrPtr = (UINT8 *) Table; + + /// + /// Loop through the ASL looking for values that we must fix up. + /// + for (DsdtPointer = CurrPtr; DsdtPointer <= (CurrPtr + ((EFI_ACPI_COMMON_HEADER *) CurrPtr)->Length); DsdtPointer++) { + /// + /// Get a pointer to compare for signature + /// + Signature = (UINT32 *) DsdtPointer; + /// + /// Check if this is the Device Object signature we are looking for + /// + if ((*Signature) == AslSignature) { + /// + /// Look for Name Encoding + /// + if (*(DsdtPointer-1) == AML_NAME_OP) { + /// + /// Check if size of new and old data is the same + /// + DataSize = *(DsdtPointer+4); + if ((Length == 1 && DataSize == 0xA) || + (Length == 2 && DataSize == 0xB) || + (Length == 4 && DataSize == 0xC)) { + CopyMem (DsdtPointer+5, Buffer, Length); + } else if (Length == 1 && ((*(UINT8*) Buffer) == 0 || (*(UINT8*) Buffer) == 1) && (DataSize == 0 || DataSize == 1)) { + CopyMem (DsdtPointer+4, Buffer, Length); + } else { + FreePool (Table); + return EFI_BAD_BUFFER_SIZE; + } + Status = mAcpiTable->UninstallAcpiTable ( + mAcpiTable, + Handle + ); + Handle = 0; + Status = mAcpiTable->InstallAcpiTable ( + mAcpiTable, + Table, + Table->Length, + &Handle + ); + FreePool (Table); + return Status; + } + } + } + return EFI_NOT_FOUND; +} + + +/** + This function uses the ACPI SDT protocol to locate an ACPI table. + It is really only useful for finding tables that only have a single instance, + e.g. FADT, FACS, MADT, etc. It is not good for locating SSDT, etc. + + @param[in] Signature - Pointer to an ASCII string containing the OEM Table ID from the ACPI table header + @param[in, out] Table - Updated with a pointer to the table + @param[in, out] Handle - AcpiSupport protocol table handle for the table found + @param[in, out] Version - The version of the table desired + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +LocateAcpiTableBySignature ( + IN UINT32 Signature, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle + ) +{ + EFI_STATUS Status; + INTN Index; + EFI_ACPI_TABLE_VERSION Version; + EFI_ACPI_DESCRIPTION_HEADER *OrgTable; + + if (mAcpiSdt == NULL) { + InitializeAslUpdateLib (); + if (mAcpiSdt == NULL) { + return EFI_NOT_READY; + } + } + + /// + /// Locate table with matching ID + /// + Version = 0; + Index = 0; + do { + Status = mAcpiSdt->GetAcpiTable (Index, (EFI_ACPI_SDT_HEADER **)&OrgTable, &Version, Handle); + if (Status == EFI_NOT_FOUND) { + break; + } + ASSERT_EFI_ERROR (Status); + Index++; + } while (OrgTable->Signature != Signature); + + if (Status != EFI_NOT_FOUND) { + *Table = AllocateCopyPool (OrgTable->Length, OrgTable); + ASSERT (*Table); + } + + /// + /// If we found the table, there will be no error. + /// + return Status; +} + +/** + This function uses the ACPI SDT protocol to locate an ACPI SSDT table. + + @param[in] TableId - Pointer to an ASCII string containing the OEM Table ID from the ACPI table header + @param[in] TableIdSize - Length of the TableId to match. Table ID are 8 bytes long, this function + will consider it a match if the first TableIdSize bytes match + @param[in, out] Table - Updated with a pointer to the table + @param[in, out] Handle - AcpiSupport protocol table handle for the table found + @param[in, out] Version - See AcpiSupport protocol, GetAcpiTable function for use + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +LocateAcpiTableByOemTableId ( + IN UINT8 *TableId, + IN UINT8 TableIdSize, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle + ) +{ + EFI_STATUS Status; + INTN Index; + EFI_ACPI_TABLE_VERSION Version; + EFI_ACPI_DESCRIPTION_HEADER *OrgTable; + + if (mAcpiSdt == NULL) { + InitializeAslUpdateLib (); + if (mAcpiSdt == NULL) { + return EFI_NOT_READY; + } + } + /// + /// Locate table with matching ID + /// + Version = 0; + Index = 0; + do { + Status = mAcpiSdt->GetAcpiTable (Index, (EFI_ACPI_SDT_HEADER **)&OrgTable, &Version, Handle); + if (Status == EFI_NOT_FOUND) { + break; + } + ASSERT_EFI_ERROR (Status); + Index++; + } while (CompareMem (&(OrgTable->OemTableId), TableId, TableIdSize)); + + if (Status != EFI_NOT_FOUND) { + *Table = AllocateCopyPool (OrgTable->Length, OrgTable); + ASSERT (*Table); + } + + /// + /// If we found the table, there will be no error. + /// + return Status; +} + +/** + This function calculates and updates an UINT8 checksum. + + @param[in] Buffer Pointer to buffer to checksum + @param[in] Size Number of bytes to checksum + @param[in] ChecksumOffset Offset to place the checksum result in + + @retval EFI_SUCCESS The function completed successfully. +**/ +EFI_STATUS +AcpiChecksum ( + IN VOID *Buffer, + IN UINTN Size, + IN UINTN ChecksumOffset + ) +{ + UINT8 Sum; + UINT8 *Ptr; + + Sum = 0; + /// + /// Initialize pointer + /// + Ptr = Buffer; + + /// + /// set checksum to 0 first + /// + Ptr[ChecksumOffset] = 0; + + /// + /// add all content of buffer + /// + while (Size--) { + Sum = (UINT8) (Sum + (*Ptr++)); + } + /// + /// set checksum + /// + Ptr = Buffer; + Ptr[ChecksumOffset] = (UINT8) (0xff - Sum + 1); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.inf b/Platform/Intel/MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.inf new file mode 100644 index 0000000000..20fcc4e63c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.inf @@ -0,0 +1,47 @@ +## @file +# Provides services to update ASL tables. +# +# 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 which 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. +# +## + + +[Defines] +INF_VERSION = 0x00010017 +BASE_NAME = DxeAslUpdateLib +FILE_GUID = 8621697D-4E3A-4bf2-ADB0-3E2FF06559CA +VERSION_STRING = 1.0 +MODULE_TYPE = BASE +LIBRARY_CLASS = AslUpdateLib + + +[LibraryClasses] +BaseLib +IoLib +DebugLib +PcdLib +BaseMemoryLib +UefiLib +MemoryAllocationLib + + +[Packages] +MdePkg/MdePkg.dec +MinPlatformPkg/MinPlatformPkg.dec + + +[Sources] +DxeAslUpdateLib.c + + +[Protocols] +gEfiAcpiTableProtocolGuid ## CONSUMES +gEfiAcpiSdtProtocolGuid ## CONSUMES diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeBoardAcpiTableLib.c b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeBoardAcpiTableLib.c new file mode 100644 index 0000000000..700d5e0773 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeBoardAcpiTableLib.c @@ -0,0 +1,41 @@ +/** @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 + +EFI_STATUS +EFIAPI +BoardUpdateAcpiTable ( + IN OUT EFI_ACPI_COMMON_HEADER *Table, + IN OUT EFI_ACPI_TABLE_VERSION *Version + ) +{ + BOARD_ACPI_TABLE_FUNC *BoardAcpiTableFunc; + EFI_STATUS Status; + + Status = gBS->LocateProtocol ( + &gBoardAcpiTableGuid, + NULL, + (VOID **)&BoardAcpiTableFunc + ); + if (!EFI_ERROR(Status)) { + if (BoardAcpiTableFunc->BoardUpdateAcpiTable != NULL) { + return BoardAcpiTableFunc->BoardUpdateAcpiTable (Table, Version); + } + } + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeMultiBoardAcpiSupportLib.c b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeMultiBoardAcpiSupportLib.c new file mode 100644 index 0000000000..d054d724d6 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeMultiBoardAcpiSupportLib.c @@ -0,0 +1,39 @@ +/** @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 + +EFI_STATUS +EFIAPI +RegisterBoardAcpiTableFunc ( + IN BOARD_ACPI_TABLE_FUNC *BoardAcpiTableFunc + ) +{ + EFI_HANDLE Handle; + EFI_STATUS Status; + + Handle = NULL; + Status = gBS->InstallProtocolInterface ( + &Handle, + &gBoardAcpiTableGuid, + EFI_NATIVE_INTERFACE, + BoardAcpiTableFunc + ); + ASSERT_EFI_ERROR(Status); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeMultiBoardAcpiSupportLib.inf b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeMultiBoardAcpiSupportLib.inf new file mode 100644 index 0000000000..8422faf62a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeMultiBoardAcpiSupportLib.inf @@ -0,0 +1,42 @@ +## @file +# Component information file for Board Init Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeMultiBoardAcpiSupportLib + FILE_GUID = 80C96C2A-327A-447B-932D-610DDD449E03 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = MultiBoardAcpiSupportLib + LIBRARY_CLASS = BoardAcpiTableLib + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + UefiBootServicesTableLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + +[Sources] + DxeMultiBoardAcpiSupportLib.c + DxeBoardAcpiTableLib.c + +[Guids] + gBoardAcpiTableGuid + +[Pcd] diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmBoardAcpiEnableLib.c b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmBoardAcpiEnableLib.c new file mode 100644 index 0000000000..a0c6b20e13 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmBoardAcpiEnableLib.c @@ -0,0 +1,63 @@ +/** @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 + +EFI_STATUS +EFIAPI +BoardEnableAcpi ( + IN BOOLEAN EnableSci + ) +{ + BOARD_ACPI_ENABLE_FUNC *BoardAcpiEnableFunc; + EFI_STATUS Status; + + Status = gSmst->SmmLocateProtocol ( + &gBoardAcpiEnableGuid, + NULL, + (VOID **)&BoardAcpiEnableFunc + ); + if (!EFI_ERROR(Status)) { + if (BoardAcpiEnableFunc->BoardEnableAcpi != NULL) { + return BoardAcpiEnableFunc->BoardEnableAcpi (EnableSci); + } + } + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardDisableAcpi ( + IN BOOLEAN DisableSci + ) +{ + BOARD_ACPI_ENABLE_FUNC *BoardAcpiEnableFunc; + EFI_STATUS Status; + + Status = gSmst->SmmLocateProtocol ( + &gBoardAcpiEnableGuid, + NULL, + (VOID **)&BoardAcpiEnableFunc + ); + if (!EFI_ERROR(Status)) { + if (BoardAcpiEnableFunc->BoardDisableAcpi != NULL) { + return BoardAcpiEnableFunc->BoardDisableAcpi (DisableSci); + } + } + return EFI_SUCCESS; +} + diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmMultiBoardAcpiSupportLib.c b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmMultiBoardAcpiSupportLib.c new file mode 100644 index 0000000000..d858e8ae27 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmMultiBoardAcpiSupportLib.c @@ -0,0 +1,39 @@ +/** @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 + +EFI_STATUS +EFIAPI +RegisterBoardAcpiEnableFunc ( + IN BOARD_ACPI_ENABLE_FUNC *BoardAcpiEnableFunc + ) +{ + EFI_HANDLE Handle; + EFI_STATUS Status; + + Handle = NULL; + Status = gSmst->SmmInstallProtocolInterface ( + &Handle, + &gBoardAcpiEnableGuid, + EFI_NATIVE_INTERFACE, + BoardAcpiEnableFunc + ); + ASSERT_EFI_ERROR(Status); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmMultiBoardAcpiSupportLib.inf b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmMultiBoardAcpiSupportLib.inf new file mode 100644 index 0000000000..0ce45b25cb --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmMultiBoardAcpiSupportLib.inf @@ -0,0 +1,42 @@ +## @file +# Component information file for Board Init Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SmmMultiBoardAcpiSupportLib + FILE_GUID = E0238683-D3FD-4D97-8874-37C6157E2906 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = MultiBoardAcpiSupportLib + LIBRARY_CLASS = BoardAcpiEnableLib + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + SmmServicesTableLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + +[Sources] + SmmMultiBoardAcpiSupportLib.c + SmmBoardAcpiEnableLib.c + +[Guids] + gBoardAcpiEnableGuid + +[Pcd] diff --git a/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.c b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.c new file mode 100644 index 0000000000..f7767c07c7 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.c @@ -0,0 +1,1112 @@ +/** @file + This file include all platform action which can be customized by IBV/OEM. + +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 "BdsPlatform.h" +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#ifdef _MSC_VER +#pragma optimize("g", off) +#endif + +#include +#include + + +extern EFI_STATUS EfiBootManagerDispatchDeferredImages(VOID); + +GLOBAL_REMOVE_IF_UNREFERENCED EFI_BOOT_MODE gBootMode; + +BOOLEAN gPPRequireUIConfirm; + +// +// Internal shell mode +// +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mShellModeColumn; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mShellModeRow; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mShellHorizontalResolution; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mShellVerticalResolution; +// +// BDS Platform Functions +// + + +/** + The handle on the path we get might be not the display device. + We must check it. + + @todo fix the parameters + + @retval TRUE PCI class type is VGA. + @retval FALSE PCI class type isn't VGA. +**/ +BOOLEAN +IsVgaHandle ( + IN EFI_HANDLE Handle + ) +{ + EFI_PCI_IO_PROTOCOL *PciIo; + PCI_TYPE00 Pci; + EFI_STATUS Status; + + Status = gBS->HandleProtocol ( + Handle, + &gEfiPciIoProtocolGuid, + (VOID **)&PciIo + ); + + if (!EFI_ERROR (Status)) { + Status = PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint32, + 0, + sizeof (Pci) / sizeof (UINT32), + &Pci + ); + + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, " PCI CLASS CODE = 0x%x\n", Pci.Hdr.ClassCode [2])); + DEBUG ((DEBUG_INFO, " PCI SUBCLASS CODE = 0x%x\n", Pci.Hdr.ClassCode [1])); + + if (IS_PCI_VGA (&Pci) || IS_PCI_OLD_VGA (&Pci)) { + DEBUG ((DEBUG_INFO, " \nPCI VGA Device Found\n")); + return TRUE; + } + } + } + return FALSE; +} + +/** + An empty function to pass error checking of CreateEventEx (). + + This empty function ensures that EVT_NOTIFY_SIGNAL_ALL is error + checked correctly since it is now mapped into CreateEventEx() in UEFI 2.0. + + @param Event Event whose notification function is being invoked. + @param Context The pointer to the notification function's context, + which is implementation-dependent. +**/ +VOID +EFIAPI +InternalBdsEmptyCallbackFuntion ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + return; +} + +VOID +ExitPmAuth ( + VOID + ) +{ + EFI_HANDLE Handle; + EFI_STATUS Status; + EFI_EVENT EndOfDxeEvent; + + DEBUG((DEBUG_INFO,"ExitPmAuth ()- Start\n")); + // + // Prepare S3 information, this MUST be done before ExitPmAuth/EndOfDxe + // + // + // Since PI1.2.1, we need signal EndOfDxe as ExitPmAuth + // + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + InternalBdsEmptyCallbackFuntion, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &EndOfDxeEvent + ); + ASSERT_EFI_ERROR (Status); + gBS->SignalEvent (EndOfDxeEvent); + gBS->CloseEvent (EndOfDxeEvent); + DEBUG((DEBUG_INFO,"All EndOfDxe callbacks have returned successfully\n")); + + // + // NOTE: We need install DxeSmmReadyToLock directly here because many boot script is added via ExitPmAuth/EndOfDxe callback. + // If we install them at same callback, these boot script will be rejected because BootScript Driver runs first to lock them done. + // So we seperate them to be 2 different events, ExitPmAuth is last chance to let platform add boot script. DxeSmmReadyToLock will + // make boot script save driver lock down the interface. + // + Handle = NULL; + Status = gBS->InstallProtocolInterface ( + &Handle, + &gEfiDxeSmmReadyToLockProtocolGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + ASSERT_EFI_ERROR (Status); + DEBUG((DEBUG_INFO,"ExitPmAuth ()- End\n")); +} + +VOID +ConnectRootBridge ( + BOOLEAN Recursive + ) +{ + UINTN RootBridgeHandleCount; + EFI_HANDLE *RootBridgeHandleBuffer; + UINTN RootBridgeIndex; + + RootBridgeHandleCount = 0; + gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciRootBridgeIoProtocolGuid, + NULL, + &RootBridgeHandleCount, + &RootBridgeHandleBuffer + ); + for (RootBridgeIndex = 0; RootBridgeIndex < RootBridgeHandleCount; RootBridgeIndex++) { + gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL, NULL, Recursive); + } +} + + +BOOLEAN +IsGopDevicePath ( + EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + while (!IsDevicePathEndType (DevicePath)) { + if (DevicePathType (DevicePath) == ACPI_DEVICE_PATH && + DevicePathSubType (DevicePath) == ACPI_ADR_DP) { + return TRUE; + } + DevicePath = NextDevicePathNode (DevicePath); + } + return FALSE; +} + +/** + Connect the USB short form device path. + + @param DevicePath USB short form device path + + @retval EFI_SUCCESS Successfully connected the USB device + @retval EFI_NOT_FOUND Cannot connect the USB device + @retval EFI_INVALID_PARAMETER The device path is invalid. +**/ +EFI_STATUS +ConnectUsbShortFormDevicePath ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_STATUS Status; + EFI_HANDLE *Handles; + UINTN HandleCount; + UINTN Index; + EFI_PCI_IO_PROTOCOL *PciIo; + UINT8 Class[3]; + BOOLEAN AtLeastOneConnected; + + // + // Check the passed in parameters + // + if (DevicePath == NULL) { + return EFI_INVALID_PARAMETER; + } + + if ((DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH) || + ((DevicePathSubType (DevicePath) != MSG_USB_CLASS_DP) && (DevicePathSubType (DevicePath) != MSG_USB_WWID_DP)) + ) { + return EFI_INVALID_PARAMETER; + } + + // + // Find the usb host controller firstly, then connect with the remaining device path + // + AtLeastOneConnected = FALSE; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciIoProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol ( + Handles[Index], + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo + ); + if (!EFI_ERROR (Status)) { + // + // Check whether the Pci device is the wanted usb host controller + // + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class); + if (!EFI_ERROR (Status) && + ((PCI_CLASS_SERIAL == Class[2]) && (PCI_CLASS_SERIAL_USB == Class[1])) + ) { + Status = gBS->ConnectController ( + Handles[Index], + NULL, + DevicePath, + FALSE + ); + if (!EFI_ERROR(Status)) { + AtLeastOneConnected = TRUE; + } + } + } + } + + return AtLeastOneConnected ? EFI_SUCCESS : EFI_NOT_FOUND; +} + + +/** + Update the ConIn variable with USB Keyboard device path,if its not already exists in ConIn +**/ +VOID +EnumUsbKeyboard ( + VOID + ) +{ + UINTN DevicePathSize; + EFI_DEVICE_PATH_PROTOCOL *VarConIn; + EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance; + EFI_DEVICE_PATH_PROTOCOL *Next; + BOOLEAN UsbKeyboard; + + UsbKeyboard = FALSE; + GetEfiGlobalVariable2 (L"ConIn", (VOID **) &VarConIn, NULL); + + // + // If ConIn variable is empty, need to enumerate USB keyboard device path + // + do { + DevicePathInstance = GetNextDevicePathInstance ( + &VarConIn, + &DevicePathSize + ); + + if (DevicePathInstance == NULL) { + // + // The instance is NULL, it means the VarConIn is null, escape the DO loop, + // and need to add USB keyboard dev path. + // + break; + } + + Next = DevicePathInstance; + while (!IsDevicePathEndType(Next)) { + // + // Checking the device path to see the USB keyboard existance. + // + if ((Next->Type == MESSAGING_DEVICE_PATH) && + (Next->SubType == MSG_USB_CLASS_DP) && + (((USB_CLASS_DEVICE_PATH *) Next)->DeviceClass == CLASS_HID) && + (((USB_CLASS_DEVICE_PATH *) Next)->DeviceSubClass == SUBCLASS_BOOT) && + (((USB_CLASS_DEVICE_PATH *) Next)->DeviceProtocol == PROTOCOL_KEYBOARD)) { + DEBUG ((DEBUG_INFO, "[EnumUsbKeyboard] USB keyboard path exists\n")); + UsbKeyboard = TRUE; + + break; + } + Next = NextDevicePathNode (Next); + } // while (!IsDevicePathEndType(Next)); + + if (DevicePathInstance != NULL) { + FreePool (DevicePathInstance); + } + } while (VarConIn != NULL); + + // + // USB keyboard device path does not exist, So add it to the ConIn + // + if (!UsbKeyboard) { + DEBUG ((DEBUG_INFO, "[EnumUsbKeyboard] Adding USB keyboard device path to ConIn.\n")); + EfiBootManagerUpdateConsoleVariable (ConIn, (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath, NULL); + } + + if (VarConIn != NULL) { + FreePool (VarConIn); + } +} + +/** + Return whether the device is trusted console. + + @param Device The device to be tested. + + @retval TRUE The device can be trusted. + @retval FALSE The device cannot be trusted. +**/ +BOOLEAN +IsTrustedConsole ( + EFI_DEVICE_PATH_PROTOCOL *Device + ) +{ + + if(Device == NULL) { + return FALSE; + } + + if (CompareMem (Device, &gPlatformIGDDevice, GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &gPlatformIGDDevice) - END_DEVICE_PATH_LENGTH) == 0) { + return TRUE; + } + + if (CompareMem (Device, &gUsbClassKeyboardDevicePath, GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath) - END_DEVICE_PATH_LENGTH) == 0) { + return TRUE; + } + return FALSE; +} + +/** + The function connects the trusted consoles. +**/ +VOID +ConnectTrustedConsole ( + VOID + ) +{ + EFI_DEVICE_PATH_PROTOCOL *Consoles; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_DEVICE_PATH_PROTOCOL *Instance; + EFI_DEVICE_PATH_PROTOCOL *Next; + UINTN Size; + UINTN Index; + EFI_HANDLE Handle; + EFI_STATUS Status; + CHAR16 *ConsoleVar[] = {L"ConIn", L"ConOut"}; + + for (Index = 0; Index < sizeof (ConsoleVar) / sizeof (ConsoleVar[0]); Index++) { + GetEfiGlobalVariable2 (ConsoleVar[Index], &Consoles, NULL); + + TempDevicePath = Consoles; + do { + Instance = GetNextDevicePathInstance (&TempDevicePath, &Size); + if (Instance == NULL) { + break; + } + if (IsTrustedConsole (Instance)) { + if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) && + ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP) || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)) + ) { + ConnectUsbShortFormDevicePath (Instance); + } else { + for (Next = Instance; !IsDevicePathEnd (Next); Next = NextDevicePathNode (Next)) { + if (DevicePathType (Next) == ACPI_DEVICE_PATH && DevicePathSubType (Next) == ACPI_ADR_DP) { + break; + } else if (DevicePathType (Next) == HARDWARE_DEVICE_PATH && + DevicePathSubType (Next) == HW_CONTROLLER_DP && + DevicePathType (NextDevicePathNode (Next)) == ACPI_DEVICE_PATH && + DevicePathSubType (NextDevicePathNode (Next)) == ACPI_ADR_DP + ) { + break; + } + } + if (!IsDevicePathEnd (Next)) { + SetDevicePathEndNode (Next); + Status = EfiBootManagerConnectDevicePath (Instance, &Handle); + if (!EFI_ERROR (Status)) { + gBS->ConnectController (Handle, NULL, NULL, TRUE); + } + } else { + EfiBootManagerConnectDevicePath (Instance, NULL); + } + } + } + FreePool (Instance); + } while (TempDevicePath != NULL); + + if (Consoles != NULL) { + FreePool (Consoles); + } + } +} + +/** + The function connects the trusted consoles and then call the PP processing library interface. +**/ +VOID +ProcessTcgPp ( + VOID + ) +{ + gPPRequireUIConfirm |= Tcg2PhysicalPresenceLibNeedUserConfirm(); + + if (gPPRequireUIConfirm) { + ConnectTrustedConsole (); + } + + Tcg2PhysicalPresenceLibProcessRequest (NULL); +} + +/** + Remove all GOP device path instance from DevicePath and add the Gop to the DevicePath. +**/ +EFI_DEVICE_PATH_PROTOCOL * +UpdateDevicePath ( + EFI_DEVICE_PATH_PROTOCOL *DevicePath, + EFI_DEVICE_PATH_PROTOCOL *Gop + ) +{ + UINTN Size; + UINTN GopSize; + EFI_DEVICE_PATH_PROTOCOL *Temp; + EFI_DEVICE_PATH_PROTOCOL *Return; + EFI_DEVICE_PATH_PROTOCOL *Instance; + BOOLEAN Exist; + + Exist = FALSE; + Return = NULL; + GopSize = GetDevicePathSize (Gop); + do { + Instance = GetNextDevicePathInstance (&DevicePath, &Size); + if (Instance == NULL) { + break; + } + if (!IsGopDevicePath (Instance) || + (Size == GopSize && CompareMem (Instance, Gop, GopSize) == 0) + ) { + if (Size == GopSize && CompareMem (Instance, Gop, GopSize) == 0) { + Exist = TRUE; + } + Temp = Return; + Return = AppendDevicePathInstance (Return, Instance); + if (Temp != NULL) { + FreePool (Temp); + } + } + FreePool (Instance); + } while (DevicePath != NULL); + + if (!Exist) { + Temp = Return; + Return = AppendDevicePathInstance (Return, Gop); + if (Temp != NULL) { + FreePool (Temp); + } + } + return Return; +} + +#ifdef _MSC_VER +#pragma optimize("g", off) +#endif + +/** + Check if current BootCurrent variable is internal shell boot option. + + @retval TRUE BootCurrent is internal shell. + @retval FALSE BootCurrent is not internal shell. +**/ +BOOLEAN +BootCurrentIsInternalShell ( + VOID + ) +{ + UINTN VarSize; + UINT16 BootCurrent; + CHAR16 BootOptionName[16]; + UINT8 *BootOption; + UINT8 *Ptr; + EFI_DEVICE_PATH_PROTOCOL *BootDevicePath; + BOOLEAN Result; + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode; + EFI_GUID *GuidPoint; + + BootOption = NULL; + BootDevicePath = NULL; + Result = FALSE; + + // + // Get BootCurrent variable + // + VarSize = sizeof (UINT16); + Status = gRT->GetVariable ( + L"BootCurrent", + &gEfiGlobalVariableGuid, + NULL, + &VarSize, + &BootCurrent + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + // + // Create boot option Bootxxxx from BootCurrent + // + UnicodeSPrint (BootOptionName, sizeof(BootOptionName), L"Boot%04X", BootCurrent); + + GetEfiGlobalVariable2 (BootOptionName, (VOID **) &BootOption, &VarSize); + if (BootOption == NULL || VarSize == 0) { + return FALSE; + } + + Ptr = BootOption; + Ptr += sizeof (UINT32); + Ptr += sizeof (UINT16); + Ptr += StrSize ((CHAR16 *) Ptr); + TempDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr; + LastDeviceNode = TempDevicePath; + while (!IsDevicePathEnd (TempDevicePath)) { + LastDeviceNode = TempDevicePath; + TempDevicePath = NextDevicePathNode (TempDevicePath); + } + GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode ( + (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode + ); + if ((GuidPoint != NULL) && + ((CompareGuid (GuidPoint, &gUefiShellFileGuid))) + ) { + // + // if this option is internal shell, return TRUE + // + Result = TRUE; + } + + if (BootOption != NULL) { + FreePool (BootOption); + BootOption = NULL; + } + + return Result; +} + +/** + This function will change video resolution and text mode + for internl shell when internal shell is launched. + + @param None. + + @retval EFI_SUCCESS Mode is changed successfully. + @retval Others Mode failed to changed. +**/ +EFI_STATUS +EFIAPI +ChangeModeForInternalShell ( + VOID + ) +{ + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut; + UINTN SizeOfInfo; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; + UINT32 MaxGopMode; + UINT32 MaxTextMode; + UINT32 ModeNumber; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + EFI_STATUS Status; + UINTN Index; + UINTN CurrentColumn; + UINTN CurrentRow; + + Status = gBS->HandleProtocol ( + gST->ConsoleOutHandle, + &gEfiGraphicsOutputProtocolGuid, + (VOID**)&GraphicsOutput + ); + if (EFI_ERROR (Status)) { + GraphicsOutput = NULL; + } + + Status = gBS->HandleProtocol ( + gST->ConsoleOutHandle, + &gEfiSimpleTextOutProtocolGuid, + (VOID**)&SimpleTextOut + ); + if (EFI_ERROR (Status)) { + SimpleTextOut = NULL; + } + + if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) { + return EFI_UNSUPPORTED; + } + + MaxGopMode = GraphicsOutput->Mode->MaxMode; + MaxTextMode = SimpleTextOut->Mode->MaxMode; + + // + // 1. If current video resolution is same with new video resolution, + // video resolution need not be changed. + // 1.1. If current text mode is same with new text mode, text mode need not be change. + // 1.2. If current text mode is different with new text mode, text mode need be change to new text mode. + // 2. If current video resolution is different with new video resolution, we need restart whole console drivers. + // + for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) { + Status = GraphicsOutput->QueryMode ( + GraphicsOutput, + ModeNumber, + &SizeOfInfo, + &Info + ); + if (!EFI_ERROR (Status)) { + if ((Info->HorizontalResolution == mShellHorizontalResolution) && + (Info->VerticalResolution == mShellVerticalResolution)) { + if ((GraphicsOutput->Mode->Info->HorizontalResolution == mShellHorizontalResolution) && + (GraphicsOutput->Mode->Info->VerticalResolution == mShellVerticalResolution)) { + // + // If current video resolution is same with new resolution, + // then check if current text mode is same with new text mode. + // + Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow); + ASSERT_EFI_ERROR (Status); + if (CurrentColumn == mShellModeColumn && CurrentRow == mShellModeRow) { + // + // Current text mode is same with new text mode, text mode need not be change. + // + FreePool (Info); + return EFI_SUCCESS; + } else { + // + // Current text mode is different with new text mode, text mode need be change to new text mode. + // + for (Index = 0; Index < MaxTextMode; Index++) { + Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow); + if (!EFI_ERROR(Status)) { + if ((CurrentColumn == mShellModeColumn) && (CurrentRow == mShellModeRow)) { + // + // New text mode is supported, set it. + // + Status = SimpleTextOut->SetMode (SimpleTextOut, Index); + ASSERT_EFI_ERROR (Status); + // + // Update text mode PCD. + // + PcdSet32S (PcdConOutColumn, mShellModeColumn); + PcdSet32S (PcdConOutRow, mShellModeRow); + FreePool (Info); + return EFI_SUCCESS; + } + } + } + if (Index == MaxTextMode) { + // + // If new text mode is not supported, return error. + // + FreePool (Info); + return EFI_UNSUPPORTED; + } + } + } else { + FreePool (Info); + // + // If current video resolution is not same with the new one, set new video resolution. + // In this case, the driver which produces simple text out need be restarted. + // + Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber); + if (!EFI_ERROR (Status)) { + // + // Set PCD to restart GraphicsConsole and Consplitter to change video resolution + // and produce new text mode based on new resolution. + // + PcdSet32S (PcdVideoHorizontalResolution, mShellHorizontalResolution); + PcdSet32S (PcdVideoVerticalResolution, mShellVerticalResolution); + PcdSet32S (PcdConOutColumn, mShellModeColumn); + PcdSet32S (PcdConOutRow, mShellModeRow); + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiSimpleTextOutProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (Index = 0; Index < HandleCount; Index++) { + gBS->DisconnectController (HandleBuffer[Index], NULL, NULL); + } + for (Index = 0; Index < HandleCount; Index++) { + gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE); + } + if (HandleBuffer != NULL) { + FreePool (HandleBuffer); + } + break; + } + } + } + } + FreePool (Info); + } + } + + if (ModeNumber == MaxGopMode) { + // + // If the new resolution is not supported, return error. + // + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} + +/** + ReadyToBoot callback to set video and text mode for internal shell boot. + That will not connect USB controller while CSM and FastBoot are disabled, we need to connect them + before booting to Shell for showing USB devices in Shell. + + When FastBoot is enabled and Windows Console is the chosen Console behavior, input devices will not be connected + by default. Hence, when booting to EFI shell, connecting input consoles are required. + + @param Event Pointer to this event + @param Context Event hanlder private data + + @retval None. +**/ +VOID +EFIAPI +OnReadyToBootCallBack ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + DEBUG ((EFI_D_INFO, "OnReadyToBootCallBack\n")); + + if (BootCurrentIsInternalShell ()) { + + ChangeModeForInternalShell (); + EfiBootManagerConnectAllDefaultConsoles(); + gDS->Dispatch (); + } +} + +/** + Platform Bds init. Incude the platform firmware vendor, revision + and so crc check. +**/ +VOID +EFIAPI +PlatformBootManagerBeforeConsole ( + VOID + ) +{ + EFI_STATUS Status; + UINTN Index; + EFI_DEVICE_PATH_PROTOCOL *VarConOut; + EFI_DEVICE_PATH_PROTOCOL *VarConIn; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_DEVICE_PATH_PROTOCOL *ConsoleOut; + EFI_DEVICE_PATH_PROTOCOL *Temp; + EFI_DEVICE_PATH_PROTOCOL *Instance; + EFI_DEVICE_PATH_PROTOCOL *Next; + EFI_HANDLE VideoHandle; + BOOLEAN IsIgd; + EFI_EVENT Event; + UINTN InstanceSize; + + DEBUG ((EFI_D_INFO, "PlatformBootManagerBeforeConsole\n")); + + Status = EFI_SUCCESS; + // + // Append Usb Keyboard short form DevicePath into "ConInDev" + // + EfiBootManagerUpdateConsoleVariable ( + ConInDev, + (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath, + NULL + ); + + // + // Get user defined text mode for internal shell only once. + // + mShellHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution); + mShellVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution); + mShellModeColumn = PcdGet32 (PcdSetupConOutColumn); + mShellModeRow = PcdGet32 (PcdSetupConOutRow); + + // + // Create event to set proper video resolution and text mode for internal shell. + // + Status = EfiCreateEventReadyToBootEx ( + TPL_CALLBACK, + OnReadyToBootCallBack, + NULL, + &Event + ); + ASSERT_EFI_ERROR (Status); + + // + // Connect Root Bridge to make PCI BAR resource allocated and all PciIo created + // + ConnectRootBridge (FALSE); + + // + // Update ConOut variable according to the PrimaryDisplay setting + // + GetEfiGlobalVariable2 (L"ConOut", &ConsoleOut, NULL); + // + // Add IGD to ConOut + // + IsIgd = TRUE; + TempDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) &gPlatformIGDDevice; + Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &TempDevicePath, &VideoHandle); + + if ((VideoHandle != NULL) && (IsIgd == TRUE)) { + // + // Connect the GOP driver + // + gBS->ConnectController (VideoHandle, NULL, NULL, TRUE); + + // + // Get the GOP device path + // NOTE: We may get a device path that contains Controller node in it. + // + TempDevicePath = EfiBootManagerGetGopDevicePath (VideoHandle); + if (TempDevicePath != NULL) { + Temp = ConsoleOut; + ConsoleOut = UpdateDevicePath (ConsoleOut, TempDevicePath); + if (Temp != NULL) { + FreePool (Temp); + } + FreePool (TempDevicePath); + Status = gRT->SetVariable ( + L"ConOut", + &gEfiGlobalVariableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, + GetDevicePathSize (ConsoleOut), + ConsoleOut + ); + } + } + // + // Fill ConIn/ConOut in Full Configuration boot mode + // + DEBUG ((DEBUG_INFO, "PlatformBootManagerInit - %x\n", gBootMode)); + + if (gBootMode == BOOT_WITH_FULL_CONFIGURATION || + gBootMode == BOOT_WITH_DEFAULT_SETTINGS || + gBootMode == BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS || + gBootMode == BOOT_IN_RECOVERY_MODE) { + + GetEfiGlobalVariable2 (L"ConOut", &VarConOut, NULL); if (VarConOut != NULL) { FreePool (VarConOut); } + GetEfiGlobalVariable2 (L"ConIn", &VarConIn, NULL); if (VarConIn != NULL) { FreePool (VarConIn); } + + if (VarConOut == NULL || VarConIn == NULL) { + // + // Only fill ConIn/ConOut when ConIn/ConOut is empty because we may drop to Full Configuration boot mode in non-first boot + // + // + // Update ConOutDevicePath (just in case it is wrong at build phase) + // To be enabled later. + // +// PlatformPatchConOutDevicePath (); + + for (Index = 0; gPlatformConsole[Index].DevicePath != NULL; Index++) { + // + // Update the console variable with the connect type + // + if ((gPlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) { + EfiBootManagerUpdateConsoleVariable (ConIn, gPlatformConsole[Index].DevicePath, NULL); + } + if ((gPlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) { + EfiBootManagerUpdateConsoleVariable (ConOut, gPlatformConsole[Index].DevicePath, NULL); + } + if ((gPlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) { + EfiBootManagerUpdateConsoleVariable (ErrOut, gPlatformConsole[Index].DevicePath, NULL); + } + } + } + else { + if (gBootMode == BOOT_WITH_DEFAULT_SETTINGS) { + + GetEfiGlobalVariable2 (L"ConIn", &VarConIn, NULL); + Instance = GetNextDevicePathInstance (&VarConIn, &InstanceSize); + InstanceSize -= END_DEVICE_PATH_LENGTH; + + while (Instance != NULL) { + Next = Instance; + while (!IsDevicePathEndType (Next)) { + Next = NextDevicePathNode (Next); + if (DevicePathType (Next) == MESSAGING_DEVICE_PATH && DevicePathSubType (Next) == MSG_VENDOR_DP) { + // + // Restoring default serial device path + // + EfiBootManagerUpdateConsoleVariable (ConIn, NULL, Instance); + EfiBootManagerUpdateConsoleVariable (ConOut, NULL, Instance); + } + } + FreePool(Instance); + Instance = GetNextDevicePathInstance (&VarConIn, &InstanceSize); + InstanceSize -= END_DEVICE_PATH_LENGTH; + } + } + } + } + + EnumUsbKeyboard (); + + // + // Dynamically register hot key: F2/F7/Enter + // + RegisterDefaultBootOption (); + RegisterStaticHotkey (); + + // + // Connect Root Bridge to make PCI BAR resource allocated. + // Then exit PM auth before Legacy OPROM run. + // + PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7010); + ConnectRootBridge (FALSE); + if (PcdGetBool (PcdTpm2Enable)) { + ProcessTcgPp (); + } + PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7011); + + + PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7020); + ExitPmAuth (); + PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7021); + + // + // Dispatch the deferred 3rd party images. + // + EfiBootManagerDispatchDeferredImages (); + +} + + +/** + Connect with predeined platform connect sequence, + the OEM/IBV can customize with their own connect sequence. + + @param[in] BootMode Boot mode of this boot. +**/ +VOID +ConnectSequence ( + IN EFI_BOOT_MODE BootMode + ) +{ + EfiBootManagerConnectAll (); +} + +/** + The function is to consider the boot order which is not in our expectation. + In the case that we need to re-sort the boot option. + + @retval TRUE Need to sort Boot Option. + @retval FALSE Don't need to sort Boot Option. +**/ +BOOLEAN +IsNeedSortBootOption ( + VOID + ) +{ + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; + UINTN BootOptionCount; + + BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + + // + // If setup is the first priority in boot option, we need to sort boot option. + // + if ((BootOptionCount > 1) && + (((StrnCmp (BootOptions->Description, L"Enter Setup", StrLen (L"Enter Setup"))) == 0) || + ((StrnCmp (BootOptions->Description, L"BootManagerMenuApp", StrLen (L"BootManagerMenuApp"))) == 0))) { + return TRUE; + } + + return FALSE; +} + +/** + The function will excute with as the platform policy, current policy + is driven by boot mode. IBV/OEM can customize this code for their specific + policy action. + + @param DriverOptionList - The header of the driver option link list + @param BootOptionList - The header of the boot option link list + @param ProcessCapsules - A pointer to ProcessCapsules() + @param BaseMemoryTest - A pointer to BaseMemoryTest() +**/ +VOID +EFIAPI +PlatformBootManagerAfterConsole ( + VOID + ) +{ + EFI_BOOT_MODE LocalBootMode; + + DEBUG ((EFI_D_INFO, "PlatformBootManagerAfterConsole\n")); + + // + // Get current Boot Mode + // + LocalBootMode = gBootMode; + DEBUG ((DEBUG_INFO, "Current local bootmode - %x\n", LocalBootMode)); + + // + // Go the different platform policy with different boot mode + // Notes: this part code can be change with the table policy + // + switch (LocalBootMode) { + + case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES: + case BOOT_WITH_MINIMAL_CONFIGURATION: + case BOOT_ON_S4_RESUME: + // + // Perform some platform specific connect sequence + // + PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7050); + ConnectSequence (LocalBootMode); + PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7051); + + break; + + case BOOT_WITH_FULL_CONFIGURATION: + case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS: + case BOOT_WITH_DEFAULT_SETTINGS: + default: + // + // Perform some platform specific connect sequence + // + ConnectSequence (LocalBootMode); + + // + // Only in Full Configuration boot mode we do the enumeration of boot device + // + // + // Dispatch all but Storage Oprom explicitly, because we assume Int13Thunk driver is there. + // + EfiBootManagerRefreshAllBootOption (); + + if (IsNeedSortBootOption()) { + EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption); + } + // + // PXE boot option may appear after boot option enumeration + // + + break; + } + + Print (L"Press F7 for BootMenu!\n"); + + EfiBootManagerRefreshAllBootOption (); + EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption); + + + + +} + diff --git a/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.h b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.h new file mode 100644 index 0000000000..128e828cba --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.h @@ -0,0 +1,193 @@ +/** @file + Header file for BDS Platform specific code + +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. + +**/ + +#ifndef _BDS_PLATFORM_H +#define _BDS_PLATFORM_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/// +/// ConnectType +/// +#define CONSOLE_OUT 0x00000001 +#define STD_ERROR 0x00000002 +#define CONSOLE_IN 0x00000004 +#define CONSOLE_ALL (CONSOLE_OUT | CONSOLE_IN | STD_ERROR) + +extern EFI_GUID gUefiShellFileGuid; +extern EFI_BOOT_MODE gBootMode; + +#define gPciRootBridge \ + { \ + { \ + ACPI_DEVICE_PATH, \ + ACPI_DP, \ + { \ + (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \ + (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \ + }, \ + }, \ + EISA_PNP_ID (0x0A03), \ + 0 \ + } + +#define gEndEntire \ + { \ + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { END_DEVICE_PATH_LENGTH, 0 } \ + } + +typedef struct { + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + UINTN ConnectType; +} BDS_CONSOLE_CONNECT_ENTRY; + +// +// Platform Root Bridge +// +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_ROOT_BRIDGE_DEVICE_PATH; + +// +// Below is the platform console device path +// +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH IsaBridge; + ACPI_HID_DEVICE_PATH Keyboard; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_KEYBOARD_DEVICE_PATH; + +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH PciDevice; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_ONBOARD_CONTROLLER_DEVICE_PATH; + +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH Pci0Device; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_PEG_ROOT_CONTROLLER_DEVICE_PATH; + +typedef struct { + ACPI_HID_DEVICE_PATH PciRootBridge; + PCI_DEVICE_PATH PciBridge; + PCI_DEVICE_PATH PciDevice; + EFI_DEVICE_PATH_PROTOCOL End; +} PLATFORM_PCI_CONTROLLER_DEVICE_PATH; + +// +// Below is the boot option device path +// + +#define CLASS_HID 3 +#define SUBCLASS_BOOT 1 +#define PROTOCOL_KEYBOARD 1 + +typedef struct { + USB_CLASS_DEVICE_PATH UsbClass; + EFI_DEVICE_PATH_PROTOCOL End; +} USB_CLASS_FORMAT_DEVICE_PATH; + +extern BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[]; +extern PLATFORM_ONBOARD_CONTROLLER_DEVICE_PATH gPlatformIGDDevice; +extern USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath; +extern USB_CLASS_FORMAT_DEVICE_PATH gUsbClassMassStorageDevice; + +// +// Platform BDS Functions +// + + +/** + Perform the memory test base on the memory test intensive level, + and update the memory resource. + + @param Level The memory test intensive level. + + @retval EFI_STATUS Success test all the system memory and update + the memory resource + +**/ +EFI_STATUS +MemoryTest ( + IN EXTENDMEM_COVERAGE_LEVEL Level + ); + +VOID +ConnectSequence ( + IN EFI_BOOT_MODE BootMode + ); + + +INTN +EFIAPI +CompareBootOption ( + CONST VOID *Left, + CONST VOID *Right + ); + + +VOID +RegisterStaticHotkey ( + VOID + ); +VOID +RegisterDefaultBootOption ( + VOID + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf new file mode 100644 index 0000000000..4d32fd24a2 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf @@ -0,0 +1,95 @@ +### @file +# Component name for module DxePlatformBootManagerLib +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = DxePlatformBootManagerLib + FILE_GUID = A6BC385D-59E5-4B77-87D7-200ABAA83C15 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + UEFI_SPECIFICATION_VERSION = 2.10 + LIBRARY_CLASS = PlatformBootManagerLib|DXE_DRIVER +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 EBC +# + +[LibraryClasses] + BaseLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + BaseMemoryLib + DebugLib + PcdLib + PrintLib + DevicePathLib + UefiLib + HobLib + DxeServicesLib + DxeServicesTableLib + HiiLib + UefiBootManagerLib + PerformanceLib + TimerLib + Tcg2PhysicalPresenceLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[Pcd] + gPlatformModuleTokenSpaceGuid.PcdTpm2Enable ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut ## PRODUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution ## PRODUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution ## PRODUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow ## PRODUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn ## PRODUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutColumn ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupConOutRow ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand ## PRODUCES + gPlatformModuleTokenSpaceGuid.PcdBootToShellOnly + +[Sources] + BdsPlatform.c + PlatformData.c + BdsPlatform.h + PlatformBootOption.c + + +[Protocols] + gEfiPciRootBridgeIoProtocolGuid ## CONSUMES + gEfiPciIoProtocolGuid ## CONSUMES + gEfiCpuIo2ProtocolGuid ## CONSUMES + gEfiDxeSmmReadyToLockProtocolGuid ## PRODUCES + gEfiGenericMemTestProtocolGuid ## CONSUMES + gEfiDiskInfoProtocolGuid ## CONSUMES + gEfiDevicePathToTextProtocolGuid ## CONSUMES + gEfiSimpleTextInputExProtocolGuid ## CONSUMES + gEfiFirmwareVolume2ProtocolGuid ## CONSUMES + gEfiFormBrowser2ProtocolGuid ## CONSUMES + +[Guids] + gEfiGlobalVariableGuid ## PRODUCES + gEfiMemoryOverwriteControlDataGuid ## PRODUCES + gEfiEndOfDxeEventGroupGuid ## CONSUMES + +[Depex.common.DXE_DRIVER] + gEfiVariableArchProtocolGuid diff --git a/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/PlatformBootOption.c b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/PlatformBootOption.c new file mode 100644 index 0000000000..c909aca365 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/PlatformBootOption.c @@ -0,0 +1,563 @@ +/** @file + Driver for Platform Boot Options support. + +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 "BdsPlatform.h" + +#include + +BOOLEAN mContinueBoot = FALSE; +BOOLEAN mBootMenuBoot = FALSE; +BOOLEAN mPxeBoot = FALSE; +BOOLEAN mHotKeypressed = FALSE; +EFI_EVENT HotKeyEvent = NULL; + +UINTN mBootMenuOptionNumber; + +EFI_DEVICE_PATH_PROTOCOL * +BdsCreateShellDevicePath ( + VOID + ) +/*++ + +Routine Description: + + This function will create a SHELL BootOption to boot. + +Arguments: + + None. + +Returns: + + Shell Device path for booting. + +--*/ +{ + UINTN FvHandleCount; + EFI_HANDLE *FvHandleBuffer; + UINTN Index; + EFI_STATUS Status; + EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; + UINTN Size; + UINT32 AuthenticationStatus; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + VOID *Buffer; + + DevicePath = NULL; + Status = EFI_SUCCESS; + + DEBUG ((DEBUG_INFO, "[FVMAIN2] BdsCreateShellDevicePath\n")); + gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiFirmwareVolume2ProtocolGuid, + NULL, + &FvHandleCount, + &FvHandleBuffer + ); + + for (Index = 0; Index < FvHandleCount; Index++) { + gBS->HandleProtocol ( + FvHandleBuffer[Index], + &gEfiFirmwareVolume2ProtocolGuid, + (VOID **) &Fv + ); + + Buffer = NULL; + Size = 0; + Status = Fv->ReadSection ( + Fv, + &gUefiShellFileGuid, + EFI_SECTION_PE32, + 0, + &Buffer, + &Size, + &AuthenticationStatus + ); + if (EFI_ERROR (Status)) { + // + // Skip if no shell file in the FV + // + continue; + } else { + // + // Found the shell + // + break; + } + } + + if (EFI_ERROR (Status)) { + // + // No shell present + // + if (FvHandleCount) { + FreePool (FvHandleBuffer); + } + return NULL; + } + // + // Build the shell boot option + // + DevicePath = DevicePathFromHandle (FvHandleBuffer[Index]); + + if (FvHandleCount) { + FreePool (FvHandleBuffer); + } + + return DevicePath; +} + + +EFI_STATUS +CreateFvBootOption ( + EFI_GUID *FileGuid, + CHAR16 *Description, + EFI_BOOT_MANAGER_LOAD_OPTION *BootOption, + UINT32 Attributes, + UINT8 *OptionalData, OPTIONAL + UINT32 OptionalDataSize + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode; + EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; + UINT32 AuthenticationStatus; + VOID *Buffer; + UINTN Size; + + if ((BootOption == NULL) || (FileGuid == NULL) || (Description == NULL)) { + return EFI_INVALID_PARAMETER; + } + + EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid); + + if (!CompareGuid (&gUefiShellFileGuid, FileGuid)) { + Status = gBS->HandleProtocol ( + gImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **) &LoadedImage + ); + if (!EFI_ERROR (Status)) { + Status = gBS->HandleProtocol ( + LoadedImage->DeviceHandle, + &gEfiFirmwareVolume2ProtocolGuid, + (VOID **) &Fv + ); + if (!EFI_ERROR (Status)) { + Buffer = NULL; + Size = 0; + Status = Fv->ReadSection ( + Fv, + FileGuid, + EFI_SECTION_PE32, + 0, + &Buffer, + &Size, + &AuthenticationStatus + ); + if (Buffer != NULL) { + FreePool (Buffer); + } + } + } + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + DevicePath = AppendDevicePathNode ( + DevicePathFromHandle (LoadedImage->DeviceHandle), + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode + ); + } else { + DevicePath = AppendDevicePathNode ( + BdsCreateShellDevicePath (), + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode + ); + } + + Status = EfiBootManagerInitializeLoadOption ( + BootOption, + LoadOptionNumberUnassigned, + LoadOptionTypeBoot, + Attributes, + Description, + DevicePath, + OptionalData, + OptionalDataSize + ); + FreePool (DevicePath); + return Status; +} + +EFI_GUID mUiFile = { + 0x462CAA21, 0x7614, 0x4503, { 0x83, 0x6E, 0x8A, 0xB6, 0xF4, 0x66, 0x23, 0x31 } +}; +EFI_GUID mBootMenuFile = { + 0xEEC25BDC, 0x67F2, 0x4D95, { 0xB1, 0xD5, 0xF8, 0x1B, 0x20, 0x39, 0xD1, 0x1D } +}; + + +/** + Return the index of the load option in the load option array. + + The function consider two load options are equal when the + OptionType, Attributes, Description, FilePath and OptionalData are equal. + + @param Key Pointer to the load option to be found. + @param Array Pointer to the array of load options to be found. + @param Count Number of entries in the Array. + + @retval -1 Key wasn't found in the Array. + @retval 0 ~ Count-1 The index of the Key in the Array. +**/ +INTN +PlatformFindLoadOption ( + IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key, + IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array, + IN UINTN Count + ) +{ + UINTN Index; + + for (Index = 0; Index < Count; Index++) { + if ((Key->OptionType == Array[Index].OptionType) && + (Key->Attributes == Array[Index].Attributes) && + (StrCmp (Key->Description, Array[Index].Description) == 0) && + (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) && + (Key->OptionalDataSize == Array[Index].OptionalDataSize) && + (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0)) { + return (INTN) Index; + } + } + + return -1; +} + +UINTN +RegisterFvBootOption ( + EFI_GUID *FileGuid, + CHAR16 *Description, + UINTN Position, + UINT32 Attributes, + UINT8 *OptionalData, OPTIONAL + UINT32 OptionalDataSize + ) +{ + EFI_STATUS Status; + UINTN OptionIndex; + EFI_BOOT_MANAGER_LOAD_OPTION NewOption; + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; + UINTN BootOptionCount; + + NewOption.OptionNumber = LoadOptionNumberUnassigned; + Status = CreateFvBootOption (FileGuid, Description, &NewOption, Attributes, OptionalData, OptionalDataSize); + if (!EFI_ERROR (Status)) { + BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + + OptionIndex = PlatformFindLoadOption (&NewOption, BootOptions, BootOptionCount); + + if (OptionIndex == -1) { + Status = EfiBootManagerAddLoadOptionVariable (&NewOption, Position); + ASSERT_EFI_ERROR (Status); + } else { + NewOption.OptionNumber = BootOptions[OptionIndex].OptionNumber; + } + EfiBootManagerFreeLoadOption (&NewOption); + EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); + } + + return NewOption.OptionNumber; +} + + + +VOID +EFIAPI +PlatformBootManagerWaitCallback ( + UINT16 TimeoutRemain + ) +{ + UINT16 Timeout; + EFI_STATUS Status; + EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx; + EFI_KEY_DATA KeyData; + BOOLEAN PausePressed; + + Timeout = PcdGet16 (PcdPlatformBootTimeOut); + + // + // Pause on PAUSE key + // + Status = gBS->HandleProtocol (gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx); + ASSERT_EFI_ERROR (Status); + + PausePressed = FALSE; + + while (TRUE) { + Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData); + if (EFI_ERROR (Status)) { + break; + } + + if (KeyData.Key.ScanCode == SCAN_PAUSE) { + PausePressed = TRUE; + break; + } + } + + // + // Loop until non-PAUSE key pressed + // + while (PausePressed) { + Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData); + if (!EFI_ERROR (Status)) { + DEBUG (( + DEBUG_INFO, "[PauseCallback] %x/%x %x/%x\n", + KeyData.Key.ScanCode, KeyData.Key.UnicodeChar, + KeyData.KeyState.KeyShiftState, KeyData.KeyState.KeyToggleState + )); + PausePressed = (BOOLEAN) (KeyData.Key.ScanCode == SCAN_PAUSE); + } + } +} + + +EFI_GUID gUefiShellFileGuid = { 0x7C04A583, 0x9E3E, 0x4f1c, { 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } }; + +#define INTERNAL_UEFI_SHELL_NAME L"Internal UEFI Shell 2.0" +#define UEFI_HARD_DRIVE_NAME L"UEFI Hard Drive" + +VOID +RegisterDefaultBootOption ( + VOID + ) +{ + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode; + UINT16 *ShellData; + UINT32 ShellDataSize; + + ShellData = NULL; + ShellDataSize = 0; + RegisterFvBootOption (&gUefiShellFileGuid, INTERNAL_UEFI_SHELL_NAME, (UINTN) -1, LOAD_OPTION_ACTIVE, (UINT8 *)ShellData, ShellDataSize); + + // + // Boot Menu + // + mBootMenuOptionNumber = RegisterFvBootOption (&mBootMenuFile, L"Boot Device List", (UINTN) -1, LOAD_OPTION_CATEGORY_APP | LOAD_OPTION_ACTIVE | LOAD_OPTION_HIDDEN, NULL, 0); + + if (mBootMenuOptionNumber == LoadOptionNumberUnassigned) { + DEBUG ((DEBUG_INFO, "BootMenuOptionNumber (%d) should not be same to LoadOptionNumberUnassigned(%d).\n", mBootMenuOptionNumber, LoadOptionNumberUnassigned)); + } + + // + // Boot Manager Menu + // + EfiInitializeFwVolDevicepathNode (&FileNode, &mUiFile); + + gBS->HandleProtocol ( + gImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **) &LoadedImage + ); + DevicePath = AppendDevicePathNode (DevicePathFromHandle (LoadedImage->DeviceHandle), (EFI_DEVICE_PATH_PROTOCOL *) &FileNode); + +} + +VOID +RegisterBootOptionHotkey ( + UINT16 OptionNumber, + EFI_INPUT_KEY *Key, + BOOLEAN Add + ) +{ + EFI_STATUS Status; + + if (!Add) { + // + // No enter hotkey when force to setup or there is no boot option + // + Status = EfiBootManagerDeleteKeyOptionVariable (NULL, 0, Key, NULL); + ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND); + } else { + // + // Register enter hotkey for the first boot option + // + Status = EfiBootManagerAddKeyOptionVariable (NULL, OptionNumber, 0, Key,NULL); + ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED); + } +} + +EFI_STATUS +EFIAPI +DetectKeypressCallback ( + IN EFI_KEY_DATA *KeyData +) +{ + mHotKeypressed = TRUE; + + if (HotKeyEvent != NULL) { + gBS->SignalEvent(HotKeyEvent); + } + + return EFI_SUCCESS; +} + +/** + This function is called after all the boot options are enumerated and ordered properly. +**/ +VOID +RegisterStaticHotkey ( + VOID + ) +{ + + EFI_INPUT_KEY Enter; + EFI_KEY_DATA F2; + EFI_KEY_DATA F7; + BOOLEAN EnterSetup; + EFI_STATUS Status; + EFI_BOOT_MANAGER_LOAD_OPTION BootOption; + + EnterSetup = FALSE; + + // + // [Enter] + // + mContinueBoot = !EnterSetup; + if (mContinueBoot) { + Enter.ScanCode = SCAN_NULL; + Enter.UnicodeChar = CHAR_CARRIAGE_RETURN; + EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL); + } + + + // + // [F2]/[F7] + // + F2.Key.ScanCode = SCAN_F2; + F2.Key.UnicodeChar = CHAR_NULL; + F2.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID; + F2.KeyState.KeyToggleState = 0; + Status = EfiBootManagerGetBootManagerMenu (&BootOption); + ASSERT_EFI_ERROR (Status); + RegisterBootOptionHotkey ((UINT16) BootOption.OptionNumber, &F2.Key, TRUE); + EfiBootManagerFreeLoadOption (&BootOption); + + F7.Key.ScanCode = SCAN_F7; + F7.Key.UnicodeChar = CHAR_NULL; + F7.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID; + F7.KeyState.KeyToggleState = 0; + mBootMenuBoot = !EnterSetup; + RegisterBootOptionHotkey ((UINT16) mBootMenuOptionNumber, &F7.Key, mBootMenuBoot); + +} + +UINT8 +BootOptionType ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_DEVICE_PATH_PROTOCOL *Node; + EFI_DEVICE_PATH_PROTOCOL *NextNode; + + for (Node = DevicePath; !IsDevicePathEndType (Node); Node = NextDevicePathNode (Node)) { + if (DevicePathType (Node) == MESSAGING_DEVICE_PATH) { + // + // Make sure the device path points to the driver device. + // + NextNode = NextDevicePathNode (Node); + if (DevicePathSubType(NextNode) == MSG_DEVICE_LOGICAL_UNIT_DP) { + // + // if the next node type is Device Logical Unit, which specify the Logical Unit Number (LUN), + // skip it + // + NextNode = NextDevicePathNode (NextNode); + } + if (IsDevicePathEndType (NextNode)) { + if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH)) { + return DevicePathSubType (Node); + } else { + return MSG_SATA_DP; + } + } + } + } + + return (UINT8) -1; +} + +/** + Returns the priority number. + OptionType EFI + ------------------------------------ + PXE 2 + DVD 4 + USB 6 + NVME 7 + HDD 8 + EFI Shell 9 + Others 100 + + @param BootOption +**/ +UINTN +BootOptionPriority ( + CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption + ) +{ + // + // EFI boot options + // + switch (BootOptionType (BootOption->FilePath)) { + case MSG_MAC_ADDR_DP: + case MSG_VLAN_DP: + case MSG_IPv4_DP: + case MSG_IPv6_DP: + return 2; + + case MSG_SATA_DP: + case MSG_ATAPI_DP: + return 4; + + case MSG_USB_DP: + return 6; + + } + if (StrCmp (BootOption->Description, INTERNAL_UEFI_SHELL_NAME) == 0) { + if (PcdGetBool (PcdBootToShellOnly)) { + return 0; + } + return 9; + } + if (StrCmp (BootOption->Description, UEFI_HARD_DRIVE_NAME) == 0) { + return 8; + } + return 100; +} + +INTN +EFIAPI +CompareBootOption ( + CONST VOID *Left, + CONST VOID *Right + ) +{ + return BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION *) Left) - + BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION *) Right); +} + diff --git a/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/PlatformData.c b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/PlatformData.c new file mode 100644 index 0000000000..47499a0a21 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/PlatformData.c @@ -0,0 +1,96 @@ +/** @file + Defined the platform specific device path which will be used by + platform Bbd to perform the platform policy connect. + +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 "BdsPlatform.h" + +// +// Predefined platform root bridge +// +GLOBAL_REMOVE_IF_UNREFERENCED PLATFORM_ROOT_BRIDGE_DEVICE_PATH gPlatformRootBridge0 = { + gPciRootBridge, + gEndEntire +}; + +GLOBAL_REMOVE_IF_UNREFERENCED USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath = { + { + { + MESSAGING_DEVICE_PATH, + MSG_USB_CLASS_DP, + { + (UINT8) (sizeof (USB_CLASS_DEVICE_PATH)), + (UINT8) ((sizeof (USB_CLASS_DEVICE_PATH)) >> 8) + } + }, + 0xffff, // VendorId + 0xffff, // ProductId + CLASS_HID, // DeviceClass + SUBCLASS_BOOT, // DeviceSubClass + PROTOCOL_KEYBOARD // DeviceProtocol + }, + gEndEntire +}; + +// +// Onboard VGA controller device path +// +GLOBAL_REMOVE_IF_UNREFERENCED PLATFORM_ONBOARD_CONTROLLER_DEVICE_PATH gPlatformIGDDevice = { + gPciRootBridge, + { + { + HARDWARE_DEVICE_PATH, + HW_PCI_DP, + { + (UINT8) (sizeof (PCI_DEVICE_PATH)), + (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) + } + }, + 0x0, + 0x2 + }, + gEndEntire +}; + +// +// Predefined platform default console device path +// +GLOBAL_REMOVE_IF_UNREFERENCED BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[] = { + { + (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath, + CONSOLE_IN + }, + { + NULL, + 0 + } +}; + +GLOBAL_REMOVE_IF_UNREFERENCED USB_CLASS_FORMAT_DEVICE_PATH gUsbClassMassStorageDevice = { + { + { + MESSAGING_DEVICE_PATH, + MSG_USB_CLASS_DP, + { + (UINT8) (sizeof (USB_CLASS_DEVICE_PATH)), + (UINT8) ((sizeof (USB_CLASS_DEVICE_PATH)) >> 8) + } + }, + 0xffff, // VendorId + 0xffff, // ProductId + 0x08, // DeviceClass - USB Mass Storage Class + 0x06, // DeviceSubClass - SCSI Transparent Command Set + 0xff // DeviceProtocol - Match any Device Protocol + }, + gEndEntire +}; diff --git a/Platform/Intel/MinPlatformPkg/Contributions.txt b/Platform/Intel/MinPlatformPkg/Contributions.txt new file mode 100644 index 0000000000..f87cbd73c6 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Contributions.txt @@ -0,0 +1,218 @@ + +====================== += Code Contributions = +====================== + +To make a contribution to a TianoCore project, follow these steps. +1. Create a change description in the format specified below to + use in the source control commit log. +2. Your commit message must include your "Signed-off-by" signature, + and "Contributed-under" message. +3. Your "Contributed-under" message explicitly states that the + contribution is made under the terms of the specified + contribution agreement. Your "Contributed-under" message + must include the name of contribution agreement and version. + For example: Contributed-under: TianoCore Contribution Agreement 1.0 + The "TianoCore Contribution Agreement" is included below in + this document. +4. Submit your code to the TianoCore project using the process + that the project documents on its web page. If the process is + not documented, then submit the code on development email list + for the project. +5. It is preferred that contributions are submitted using the same + copyright license as the base project. When that is not possible, + then contributions using the following licenses can be accepted: + * BSD (2-clause): http://opensource.org/licenses/BSD-2-Clause + * BSD (3-clause): http://opensource.org/licenses/BSD-3-Clause + * MIT: http://opensource.org/licenses/MIT + * Python-2.0: http://opensource.org/licenses/Python-2.0 + * Zlib: http://opensource.org/licenses/Zlib + + Contributions of code put into the public domain can also be + accepted. + + Contributions using other licenses might be accepted, but further + review will be required. + +===================================================== += Change Description / Commit Message / Patch Email = +===================================================== + +Your change description should use the standard format for a +commit message, and must include your "Signed-off-by" signature +and the "Contributed-under" message. + +== Sample Change Description / Commit Message = + +=== Start of sample patch email message === + +From: Contributor Name +Subject: [PATCH] CodeModule: Brief-single-line-summary + +Full-commit-message + +Contributed-under: TianoCore Contribution Agreement 1.0 +Signed-off-by: Contributor Name +--- + +An extra message for the patch email which will not be considered part +of the commit message can be added here. + +Patch content inline or attached + +=== End of sample patch email message === + +=== Notes for sample patch email === + +* The first line of commit message is taken from the email's subject + line following [PATCH]. The remaining portion of the commit message + is the email's content until the '---' line. +* git format-patch is one way to create this format + +=== Definitions for sample patch email === + +* "CodeModule" is a short idenfier for the affected code. For + example MdePkg, or MdeModulePkg UsbBusDxe. +* "Brief-single-line-summary" is a short summary of the change. +* The entire first line should be less than ~70 characters. +* "Full-commit-message" a verbose multiple line comment describing + the change. Each line should be less than ~70 characters. +* "Contributed-under" explicitely states that the contribution is + made under the terms of the contribtion agreement. This + agreement is included below in this document. +* "Signed-off-by" is the contributor's signature identifying them + by their real/legal name and their email address. + +======================================== += TianoCore Contribution Agreement 1.0 = +======================================== + +INTEL CORPORATION ("INTEL") MAKES AVAILABLE SOFTWARE, DOCUMENTATION, +INFORMATION AND/OR OTHER MATERIALS FOR USE IN THE TIANOCORE OPEN SOURCE +PROJECT (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE +TERMS AND CONDITIONS OF THIS AGREEMENT BETWEEN YOU AND INTEL AND/OR THE +TERMS AND CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR +REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE OF THE +CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS +OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED +BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS +AGREEMENT AND THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE +AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT +USE THE CONTENT. + +Unless otherwise indicated, all Content made available on the TianoCore +site is provided to you under the terms and conditions of the BSD +License ("BSD"). A copy of the BSD License is available at +http://opensource.org/licenses/bsd-license.php +or when applicable, in the associated License.txt file. + +Certain other content may be made available under other licenses as +indicated in or with such Content. (For example, in a License.txt file.) + +You accept and agree to the following terms and conditions for Your +present and future Contributions submitted to TianoCore site. Except +for the license granted to Intel hereunder, You reserve all right, +title, and interest in and to Your Contributions. + +== SECTION 1: Definitions == +* "You" or "Contributor" shall mean the copyright owner or legal + entity authorized by the copyright owner that is making a + Contribution hereunder. All other entities that control, are + controlled by, or are under common control with that entity are + considered to be a single Contributor. For the purposes of this + definition, "control" means (i) the power, direct or indirect, to + cause the direction or management of such entity, whether by + contract or otherwise, or (ii) ownership of fifty percent (50%) + or more of the outstanding shares, or (iii) beneficial ownership + of such entity. +* "Contribution" shall mean any original work of authorship, + including any modifications or additions to an existing work, + that is intentionally submitted by You to the TinaoCore site for + inclusion in, or documentation of, any of the Content. For the + purposes of this definition, "submitted" means any form of + electronic, verbal, or written communication sent to the + TianoCore site or its representatives, including but not limited + to communication on electronic mailing lists, source code + control systems, and issue tracking systems that are managed by, + or on behalf of, the TianoCore site for the purpose of + discussing and improving the Content, but excluding + communication that is conspicuously marked or otherwise + designated in writing by You as "Not a Contribution." + +== SECTION 2: License for Contributions == +* Contributor hereby agrees that redistribution and use of the + Contribution in source and binary forms, with or without + modification, are permitted provided that the following + conditions are met: +** Redistributions of source code must retain the Contributor's + copyright notice, this list of conditions and the following + disclaimer. +** Redistributions in binary form must reproduce the Contributor's + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. +* Disclaimer. None of the names of Contributor, Intel, or the names + of their respective contributors may be used to endorse or + promote products derived from this software without specific + prior written permission. +* Contributor grants a license (with the right to sublicense) under + claims of Contributor's patents that Contributor can license that + are infringed by the Contribution (as delivered by Contributor) to + make, use, distribute, sell, offer for sale, and import the + Contribution and derivative works thereof solely to the minimum + extent necessary for licensee to exercise the granted copyright + license; this patent license applies solely to those portions of + the Contribution that are unmodified. No hardware per se is + licensed. +* EXCEPT AS EXPRESSLY SET FORTH IN SECTION 3 BELOW, THE + CONTRIBUTION IS PROVIDED BY THE CONTRIBUTOR "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE + CONTRIBUTION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + DAMAGE. + +== SECTION 3: Representations == +* You represent that You are legally entitled to grant the above + license. If your employer(s) has rights to intellectual property + that You create that includes Your Contributions, You represent + that You have received permission to make Contributions on behalf + of that employer, that Your employer has waived such rights for + Your Contributions. +* You represent that each of Your Contributions is Your original + creation (see Section 4 for submissions on behalf of others). + You represent that Your Contribution submissions include complete + details of any third-party license or other restriction + (including, but not limited to, related patents and trademarks) + of which You are personally aware and which are associated with + any part of Your Contributions. + +== SECTION 4: Third Party Contributions == +* Should You wish to submit work that is not Your original creation, + You may submit it to TianoCore site separately from any + Contribution, identifying the complete details of its source + and of any license or other restriction (including, but not + limited to, related patents, trademarks, and license agreements) + of which You are personally aware, and conspicuously marking the + work as "Submitted on behalf of a third-party: [named here]". + +== SECTION 5: Miscellaneous == +* Applicable Laws. Any claims arising under or relating to this + Agreement shall be governed by the internal substantive laws of + the State of Delaware or federal courts located in Delaware, + without regard to principles of conflict of laws. +* Language. This Agreement is in the English language only, which + language shall be controlling in all respects, and all versions + of this Agreement in any other language shall be for accommodation + only and shall not be binding. All communications and notices made + or given pursuant to this Agreement, and all documentation and + support to be provided, unless otherwise noted, shall be in the + English language. + diff --git a/Platform/Intel/MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.c b/Platform/Intel/MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.c new file mode 100644 index 0000000000..bacc440630 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.c @@ -0,0 +1,107 @@ +/** @file + Null Library instance of SPI Flash Common Library Class + +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 + +/** + Enable block protection on the Serial Flash device. + + @retval EFI_SUCCESS Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +SpiFlashLock ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + Read NumBytes bytes of data from the address specified by + PAddress into Buffer. + + @param[in] Address The starting physical address of the read. + @param[in,out] NumBytes On input, the number of bytes to read. On output, the number + of bytes actually read. + @param[out] Buffer The destination data buffer for the read. + + @retval EFI_SUCCESS Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +SpiFlashRead ( + IN UINTN Address, + IN OUT UINT32 *NumBytes, + OUT UINT8 *Buffer + ) +{ + ASSERT(FALSE); + return EFI_SUCCESS; +} + +/** + Write NumBytes bytes of data from Buffer to the address specified by + PAddresss. + + @param[in] Address The starting physical address of the write. + @param[in,out] NumBytes On input, the number of bytes to write. On output, + the actual number of bytes written. + @param[in] Buffer The source data buffer for the write. + + @retval EFI_SUCCESS Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +SpiFlashWrite ( + IN UINTN Address, + IN OUT UINT32 *NumBytes, + IN UINT8 *Buffer + ) +{ + ASSERT(FALSE); + return EFI_SUCCESS; +} + +/** + Erase the block starting at Address. + + @param[in] Address The starting physical address of the block to be erased. + This library assume that caller garantee that the PAddress + is at the starting address of this block. + @param[in] NumBytes On input, the number of bytes of the logical block to be erased. + On output, the actual number of bytes erased. + + @retval EFI_SUCCESS. Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +SpiFlashBlockErase ( + IN UINTN Address, + IN UINTN *NumBytes + ) +{ + ASSERT(FALSE); + return EFI_SUCCESS; +} + diff --git a/Platform/Intel/MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.inf b/Platform/Intel/MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.inf new file mode 100644 index 0000000000..73853c0d1c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.inf @@ -0,0 +1,35 @@ +### @file +# NULL instance of Spi Flash Common Library Class +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = SpiFlashCommonLibNull + FILE_GUID = F35BBEE7-A681-443E-BB15-07AF9FABBDED + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_SMM_DRIVER + LIBRARY_CLASS = SpiFlashCommonLib|DXE_SMM_DRIVER +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[LibraryClasses] + +[Packages] + MdePkg/MdePkg.dec + +[Sources] + SpiFlashCommonLibNull.c diff --git a/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/FvbInfo.c b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/FvbInfo.c new file mode 100644 index 0000000000..bd4366ea7c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/FvbInfo.c @@ -0,0 +1,100 @@ +/**@file + Defines data structure that is the volume header found. + These data is intent to decouple FVB driver with FV header. + +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 "SpiFvbServiceCommon.h" + +#define FIRMWARE_BLOCK_SIZE 0x10000 +#define FVB_MEDIA_BLOCK_SIZE FIRMWARE_BLOCK_SIZE + +#define NV_STORAGE_BASE_ADDRESS FixedPcdGet32(PcdFlashNvStorageVariableBase) +#define SYSTEM_NV_BLOCK_NUM ((FixedPcdGet32(PcdFlashNvStorageVariableSize)+ FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + FixedPcdGet32(PcdFlashNvStorageFtwSpareSize))/ FVB_MEDIA_BLOCK_SIZE) + +typedef struct { + EFI_PHYSICAL_ADDRESS BaseAddress; + EFI_FIRMWARE_VOLUME_HEADER FvbInfo; + EFI_FV_BLOCK_MAP_ENTRY End[1]; +} EFI_FVB2_MEDIA_INFO; + +// +// This data structure contains a template of all correct FV headers, which is used to restore +// Fv header if it's corrupted. +// +EFI_FVB2_MEDIA_INFO mPlatformFvbMediaInfo[] = { + // + // Systen NvStorage FVB + // + { + NV_STORAGE_BASE_ADDRESS, + { + {0,}, //ZeroVector[16] + EFI_SYSTEM_NV_DATA_FV_GUID, + FVB_MEDIA_BLOCK_SIZE * SYSTEM_NV_BLOCK_NUM, + EFI_FVH_SIGNATURE, + 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2 + sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY), + 0, //CheckSum which will be calucated dynamically. + 0, //ExtHeaderOffset + {0,}, //Reserved[1] + 2, //Revision + { + { + SYSTEM_NV_BLOCK_NUM, + FVB_MEDIA_BLOCK_SIZE, + } + } + }, + { + { + 0, + 0 + } + } + } +}; + +EFI_STATUS +GetFvbInfo ( + IN EFI_PHYSICAL_ADDRESS FvBaseAddress, + OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo + ) +{ + UINTN Index; + EFI_FIRMWARE_VOLUME_HEADER *FvHeader; + + for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB2_MEDIA_INFO); Index++) { + if (mPlatformFvbMediaInfo[Index].BaseAddress == FvBaseAddress) { + FvHeader = &mPlatformFvbMediaInfo[Index].FvbInfo; + + // + // Update the checksum value of FV header. + // + FvHeader->Checksum = CalculateCheckSum16 ( (UINT16 *) FvHeader, FvHeader->HeaderLength); + + *FvbInfo = FvHeader; + + DEBUG ((DEBUG_INFO, "BaseAddr: 0x%lx \n", FvBaseAddress)); + DEBUG ((DEBUG_INFO, "FvLength: 0x%lx \n", (*FvbInfo)->FvLength)); + DEBUG ((DEBUG_INFO, "HeaderLength: 0x%x \n", (*FvbInfo)->HeaderLength)); + DEBUG ((DEBUG_INFO, "Header Checksum: 0x%X\n", (*FvbInfo)->Checksum)); + DEBUG ((DEBUG_INFO, "FvBlockMap[0].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[0].NumBlocks)); + DEBUG ((DEBUG_INFO, "FvBlockMap[0].BlockLength: 0x%x \n", (*FvbInfo)->BlockMap[0].Length)); + DEBUG ((DEBUG_INFO, "FvBlockMap[1].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[1].NumBlocks)); + DEBUG ((DEBUG_INFO, "FvBlockMap[1].BlockLength: 0x%x \n\n", (*FvbInfo)->BlockMap[1].Length)); + + return EFI_SUCCESS; + } + } + return EFI_NOT_FOUND; +} diff --git a/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/SpiFvbServiceCommon.c b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/SpiFvbServiceCommon.c new file mode 100644 index 0000000000..f4f1746291 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/SpiFvbServiceCommon.c @@ -0,0 +1,911 @@ +/** @file + Common driver source for several Serial Flash devices + which are compliant with the Intel(R) Serial Flash Interface Compatibility Specification. + +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 "SpiFvbServiceCommon.h" + +// +// Global variable for this FVB driver which contains +// the private data of all firmware volume block instances +// +FVB_GLOBAL mFvbModuleGlobal; + +// +// This platform driver knows there are 5 FVs on +// FD, which are Test Menu, FvRecovery, FvMain and FvNvStorage. +// Now we only provide FVs on Variable region and MicorCode region for performance issue. +// +FV_INFO mPlatformFvBaseAddress[] = { + {FixedPcdGet32(PcdFlashNvStorageVariableBase), FixedPcdGet32(PcdFlashNvStorageVariableSize)}, + {FixedPcdGet32(PcdFlashMicrocodeFvBase), FixedPcdGet32(PcdFlashMicrocodeFvSize)}, + {0, 0} +}; + +FV_INFO mPlatformDefaultBaseAddress[] = { + {FixedPcdGet32(PcdFlashNvStorageVariableBase), FixedPcdGet32(PcdFlashNvStorageVariableSize)}, + {FixedPcdGet32(PcdFlashMicrocodeFvBase), FixedPcdGet32(PcdFlashMicrocodeFvSize)}, + {FixedPcdGet32(PcdFlashFvMain2Base), FixedPcdGet32(PcdFlashFvMain2Size)}, + {0, 0} +}; + +FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = { + { + { + HARDWARE_DEVICE_PATH, + HW_MEMMAP_DP, + { + (UINT8)(sizeof (MEMMAP_DEVICE_PATH)), + (UINT8)(sizeof (MEMMAP_DEVICE_PATH) >> 8) + } + }, + EfiMemoryMappedIO, + (EFI_PHYSICAL_ADDRESS) 0, + (EFI_PHYSICAL_ADDRESS) 0, + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } +}; + +FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate = { + { + { + MEDIA_DEVICE_PATH, + MEDIA_PIWG_FW_VOL_DP, + { + (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH)), + (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH) >> 8) + } + }, + { 0 } + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } +}; + +// +// Template structure used when installing FVB protocol +// +EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL mFvbProtocolTemplate = { + FvbProtocolGetAttributes, + FvbProtocolSetAttributes, + FvbProtocolGetPhysicalAddress, + FvbProtocolGetBlockSize, + FvbProtocolRead, + FvbProtocolWrite, + FvbProtocolEraseBlocks, + NULL +}; + +/** + Get the EFI_FVB_ATTRIBUTES_2 of a FV. + + @param[in] FvbInstance The pointer to the EFI_FVB_INSTANCE. + + @return Attributes of the FV identified by FvbInstance. + +**/ +EFI_FVB_ATTRIBUTES_2 +FvbGetVolumeAttributes ( + IN EFI_FVB_INSTANCE *FvbInstance + ) +{ + return FvbInstance->FvHeader.Attributes; +} + +/** + Retrieves the starting address of an LBA in an FV. It also + return a few other attribut of the FV. + + @param[in] FvbInstance The pointer to the EFI_FVB_INSTANCE. + @param[in] Lba The logical block address + @param[out] LbaAddress On output, contains the physical starting address + of the Lba + @param[out] LbaLength On output, contains the length of the block + @param[out] NumOfBlocks A pointer to a caller allocated UINTN in which the + number of consecutive blocks starting with Lba is + returned. All blocks in this range have a size of + BlockSize + + @retval EFI_SUCCESS Successfully returns + @retval EFI_INVALID_PARAMETER Instance not found + +**/ +EFI_STATUS +FvbGetLbaAddress ( + IN EFI_FVB_INSTANCE *FvbInstance, + IN EFI_LBA Lba, + OUT UINTN *LbaAddress, + OUT UINTN *LbaLength, + OUT UINTN *NumOfBlocks + ) +{ + UINT32 NumBlocks; + UINT32 BlockLength; + UINTN Offset; + EFI_LBA StartLba; + EFI_LBA NextLba; + EFI_FV_BLOCK_MAP_ENTRY *BlockMap; + + StartLba = 0; + Offset = 0; + BlockMap = &(FvbInstance->FvHeader.BlockMap[0]); + + // + // Parse the blockmap of the FV to find which map entry the Lba belongs to + // + while (TRUE) { + NumBlocks = BlockMap->NumBlocks; + BlockLength = BlockMap->Length; + + if ( NumBlocks == 0 || BlockLength == 0) { + return EFI_INVALID_PARAMETER; + } + + NextLba = StartLba + NumBlocks; + + // + // The map entry found + // + if (Lba >= StartLba && Lba < NextLba) { + Offset = Offset + (UINTN)MultU64x32((Lba - StartLba), BlockLength); + if (LbaAddress ) { + *LbaAddress = FvbInstance->FvBase + Offset; + } + + if (LbaLength ) { + *LbaLength = BlockLength; + } + + if (NumOfBlocks ) { + *NumOfBlocks = (UINTN)(NextLba - Lba); + } + return EFI_SUCCESS; + } + + StartLba = NextLba; + Offset = Offset + NumBlocks * BlockLength; + BlockMap++; + } +} + +/** + Reads specified number of bytes into a buffer from the specified block. + + @param[in] FvbInstance The pointer to the EFI_FVB_INSTANCE + @param[in] Lba The logical block address to be read from + @param[in] BlockOffset Offset into the block at which to begin reading + @param[in] NumBytes Pointer that on input contains the total size of + the buffer. On output, it contains the total number + of bytes read + @param[in] Buffer Pointer to a caller allocated buffer that will be + used to hold the data read + + + @retval EFI_SUCCESS The firmware volume was read successfully and + contents are in Buffer + @retval EFI_BAD_BUFFER_SIZE Read attempted across a LBA boundary. On output, + NumBytes contains the total number of bytes returned + in Buffer + @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state + @retval EFI_DEVICE_ERROR The block device is not functioning correctly and + could not be read + @retval EFI_INVALID_PARAMETER Instance not found, or NumBytes, Buffer are NULL + +**/ +EFI_STATUS +FvbReadBlock ( + IN EFI_FVB_INSTANCE *FvbInstance, + IN EFI_LBA Lba, + IN UINTN BlockOffset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ) +{ + EFI_FVB_ATTRIBUTES_2 Attributes; + UINTN LbaAddress; + UINTN LbaLength; + EFI_STATUS Status; + BOOLEAN BadBufferSize = FALSE; + + if ((NumBytes == NULL) || (Buffer == NULL)) { + return EFI_INVALID_PARAMETER; + } + if (*NumBytes == 0) { + return EFI_INVALID_PARAMETER; + } + + Status = FvbGetLbaAddress (FvbInstance, Lba, &LbaAddress, &LbaLength, NULL); + if (EFI_ERROR(Status)) { + return Status; + } + + Attributes = FvbGetVolumeAttributes (FvbInstance); + + if ((Attributes & EFI_FVB2_READ_STATUS) == 0) { + return EFI_ACCESS_DENIED; + } + + if (BlockOffset > LbaLength) { + return EFI_INVALID_PARAMETER; + } + + if (LbaLength < (*NumBytes + BlockOffset)) { + DEBUG ((DEBUG_INFO, + "FvReadBlock: Reducing Numbytes from 0x%x to 0x%x\n", + *NumBytes, + (UINT32)(LbaLength - BlockOffset)) + ); + *NumBytes = (UINT32) (LbaLength - BlockOffset); + BadBufferSize = TRUE; + } + + Status = SpiFlashRead (LbaAddress + BlockOffset, (UINT32 *)NumBytes, Buffer); + + if (!EFI_ERROR (Status) && BadBufferSize) { + return EFI_BAD_BUFFER_SIZE; + } else { + return Status; + } +} + +/** + Writes specified number of bytes from the input buffer to the block. + + @param[in] FvbInstance The pointer to the EFI_FVB_INSTANCE + @param[in] Lba The starting logical block index to write to + @param[in] BlockOffset Offset into the block at which to begin writing + @param[in] NumBytes Pointer that on input contains the total size of + the buffer. On output, it contains the total number + of bytes actually written + @param[in] Buffer Pointer to a caller allocated buffer that contains + the source for the write + @retval EFI_SUCCESS The firmware volume was written successfully + @retval EFI_BAD_BUFFER_SIZE Write attempted across a LBA boundary. On output, + NumBytes contains the total number of bytes + actually written + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state + @retval EFI_DEVICE_ERROR The block device is not functioning correctly and + could not be written + @retval EFI_INVALID_PARAMETER Instance not found, or NumBytes, Buffer are NULL + +**/ +EFI_STATUS +FvbWriteBlock ( + IN EFI_FVB_INSTANCE *FvbInstance, + IN EFI_LBA Lba, + IN UINTN BlockOffset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ) +{ + EFI_FVB_ATTRIBUTES_2 Attributes; + UINTN LbaAddress; + UINTN LbaLength; + EFI_STATUS Status; + BOOLEAN BadBufferSize = FALSE; + + if ((NumBytes == NULL) || (Buffer == NULL)) { + return EFI_INVALID_PARAMETER; + } + if (*NumBytes == 0) { + return EFI_INVALID_PARAMETER; + } + + Status = FvbGetLbaAddress (FvbInstance, Lba, &LbaAddress, &LbaLength, NULL); + if (EFI_ERROR(Status)) { + return Status; + } + + // + // Check if the FV is write enabled + // + Attributes = FvbGetVolumeAttributes (FvbInstance); + if ((Attributes & EFI_FVB2_WRITE_STATUS) == 0) { + return EFI_ACCESS_DENIED; + } + + // + // Perform boundary checks and adjust NumBytes + // + if (BlockOffset > LbaLength) { + return EFI_INVALID_PARAMETER; + } + + if (LbaLength < (*NumBytes + BlockOffset)) { + DEBUG ((DEBUG_INFO, + "FvWriteBlock: Reducing Numbytes from 0x%x to 0x%x\n", + *NumBytes, + (UINT32)(LbaLength - BlockOffset)) + ); + *NumBytes = (UINT32) (LbaLength - BlockOffset); + BadBufferSize = TRUE; + } + + Status = SpiFlashWrite (LbaAddress + BlockOffset, (UINT32 *)NumBytes, Buffer); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = SpiFlashLock (); + if (EFI_ERROR (Status)) { + return Status; + } + + WriteBackInvalidateDataCacheRange ((VOID *) (LbaAddress + BlockOffset), *NumBytes); + + if (!EFI_ERROR (Status) && BadBufferSize) { + return EFI_BAD_BUFFER_SIZE; + } else { + return Status; + } +} + + + +/** + Erases and initializes a firmware volume block. + + @param[in] FvbInstance The pointer to the EFI_FVB_INSTANCE + @param[in] Lba The logical block index to be erased + + @retval EFI_SUCCESS The erase request was successfully completed + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state + @retval EFI_DEVICE_ERROR The block device is not functioning correctly and + could not be written. Firmware device may have been + partially erased + @retval EFI_INVALID_PARAMETER Instance not found + +**/ +EFI_STATUS +FvbEraseBlock ( + IN EFI_FVB_INSTANCE *FvbInstance, + IN EFI_LBA Lba + ) +{ + + EFI_FVB_ATTRIBUTES_2 Attributes; + UINTN LbaAddress; + UINTN LbaLength; + EFI_STATUS Status; + + // + // Check if the FV is write enabled + // + Attributes = FvbGetVolumeAttributes (FvbInstance); + + if( (Attributes & EFI_FVB2_WRITE_STATUS) == 0) { + return EFI_ACCESS_DENIED; + } + + // + // Get the starting address of the block for erase. + // + Status = FvbGetLbaAddress (FvbInstance, Lba, &LbaAddress, &LbaLength, NULL); + if (EFI_ERROR(Status)) { + return Status; + } + + Status = SpiFlashBlockErase (LbaAddress, &LbaLength); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = SpiFlashLock (); + if (EFI_ERROR (Status)) { + return Status; + } + + WriteBackInvalidateDataCacheRange ((VOID *) LbaAddress, LbaLength); + + return Status; +} + +/** + Modifies the current settings of the firmware volume according to the + input parameter, and returns the new setting of the volume + + @param[in] FvbInstance The pointer to the EFI_FVB_INSTANCE. + @param[in] Attributes On input, it is a pointer to EFI_FVB_ATTRIBUTES_2 + containing the desired firmware volume settings. + On successful return, it contains the new settings + of the firmware volume + + @retval EFI_SUCCESS Successfully returns + @retval EFI_ACCESS_DENIED The volume setting is locked and cannot be modified + @retval EFI_INVALID_PARAMETER Instance not found, or The attributes requested are + in conflict with the capabilities as declared in the + firmware volume header + +**/ +EFI_STATUS +FvbSetVolumeAttributes ( + IN EFI_FVB_INSTANCE *FvbInstance, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ) +{ + EFI_FVB_ATTRIBUTES_2 OldAttributes; + EFI_FVB_ATTRIBUTES_2 *AttribPtr; + EFI_FVB_ATTRIBUTES_2 UnchangedAttributes; + UINT32 Capabilities; + UINT32 OldStatus, NewStatus; + + AttribPtr = (EFI_FVB_ATTRIBUTES_2 *) &(FvbInstance->FvHeader.Attributes); + OldAttributes = *AttribPtr; + Capabilities = OldAttributes & EFI_FVB2_CAPABILITIES; + OldStatus = OldAttributes & EFI_FVB2_STATUS; + NewStatus = *Attributes & EFI_FVB2_STATUS; + + UnchangedAttributes = EFI_FVB2_READ_DISABLED_CAP | \ + EFI_FVB2_READ_ENABLED_CAP | \ + EFI_FVB2_WRITE_DISABLED_CAP | \ + EFI_FVB2_WRITE_ENABLED_CAP | \ + EFI_FVB2_LOCK_CAP | \ + EFI_FVB2_STICKY_WRITE | \ + EFI_FVB2_MEMORY_MAPPED | \ + EFI_FVB2_ERASE_POLARITY | \ + EFI_FVB2_READ_LOCK_CAP | \ + EFI_FVB2_WRITE_LOCK_CAP | \ + EFI_FVB2_ALIGNMENT; + + // + // Some attributes of FV is read only can *not* be set + // + if ((OldAttributes & UnchangedAttributes) ^ (*Attributes & UnchangedAttributes)) { + return EFI_INVALID_PARAMETER; + } + + // + // If firmware volume is locked, no status bit can be updated + // + if ( OldAttributes & EFI_FVB2_LOCK_STATUS ) { + if ( OldStatus ^ NewStatus ) { + return EFI_ACCESS_DENIED; + } + } + + // + // Test read disable + // + if ((Capabilities & EFI_FVB2_READ_DISABLED_CAP) == 0) { + if ((NewStatus & EFI_FVB2_READ_STATUS) == 0) { + return EFI_INVALID_PARAMETER; + } + } + + // + // Test read enable + // + if ((Capabilities & EFI_FVB2_READ_ENABLED_CAP) == 0) { + if (NewStatus & EFI_FVB2_READ_STATUS) { + return EFI_INVALID_PARAMETER; + } + } + + // + // Test write disable + // + if ((Capabilities & EFI_FVB2_WRITE_DISABLED_CAP) == 0) { + if ((NewStatus & EFI_FVB2_WRITE_STATUS) == 0) { + return EFI_INVALID_PARAMETER; + } + } + + // + // Test write enable + // + if ((Capabilities & EFI_FVB2_WRITE_ENABLED_CAP) == 0) { + if (NewStatus & EFI_FVB2_WRITE_STATUS) { + return EFI_INVALID_PARAMETER; + } + } + + // + // Test lock + // + if ((Capabilities & EFI_FVB2_LOCK_CAP) == 0) { + if (NewStatus & EFI_FVB2_LOCK_STATUS) { + return EFI_INVALID_PARAMETER; + } + } + + *AttribPtr = (*AttribPtr) & (0xFFFFFFFF & (~EFI_FVB2_STATUS)); + *AttribPtr = (*AttribPtr) | NewStatus; + *Attributes = *AttribPtr; + + return EFI_SUCCESS; +} + +/** + Check the integrity of firmware volume header + + @param[in] FvHeader A pointer to a firmware volume header + + @retval TRUE The firmware volume is consistent + @retval FALSE The firmware volume has corrupted. + +**/ +BOOLEAN +IsFvHeaderValid ( + IN EFI_PHYSICAL_ADDRESS FvBase, + IN CONST EFI_FIRMWARE_VOLUME_HEADER *FvHeader + ) +{ + if (FvBase == PcdGet32(PcdFlashNvStorageVariableBase)) { + if (CompareMem (&FvHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid, sizeof(EFI_GUID)) != 0 ) { + return FALSE; + } + } else { + if (CompareMem (&FvHeader->FileSystemGuid, &gEfiFirmwareFileSystem2Guid, sizeof(EFI_GUID)) != 0 ) { + return FALSE; + } + } + if ( (FvHeader->Revision != EFI_FVH_REVISION) || + (FvHeader->Signature != EFI_FVH_SIGNATURE) || + (FvHeader->FvLength == ((UINTN) -1)) || + ((FvHeader->HeaderLength & 0x01 ) !=0) ) { + return FALSE; + } + + if (CalculateCheckSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength) != 0) { + return FALSE; + } + + return TRUE; +} + +// +// FVB protocol APIs +// + +/** + Retrieves the physical address of the device. + + @param[in] This A pointer to EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL. + @param[out] Address Output buffer containing the address. + + retval EFI_SUCCESS The function always return successfully. + +**/ +EFI_STATUS +EFIAPI +FvbProtocolGetPhysicalAddress ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + OUT EFI_PHYSICAL_ADDRESS *Address + ) +{ + EFI_FVB_INSTANCE *FvbInstance; + + FvbInstance = FVB_INSTANCE_FROM_THIS (This); + + *Address = FvbInstance->FvBase; + + return EFI_SUCCESS; +} + +/** + Retrieve the size of a logical block + + @param[in] This Calling context + @param[in] Lba Indicates which block to return the size for. + @param[out] BlockSize A pointer to a caller allocated UINTN in which + the size of the block is returned + @param[out] NumOfBlocks A pointer to a caller allocated UINTN in which the + number of consecutive blocks starting with Lba is + returned. All blocks in this range have a size of + BlockSize + + @retval EFI_SUCCESS The function always return successfully. + +**/ +EFI_STATUS +EFIAPI +FvbProtocolGetBlockSize ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN EFI_LBA Lba, + OUT UINTN *BlockSize, + OUT UINTN *NumOfBlocks + ) +{ + EFI_FVB_INSTANCE *FvbInstance; + + FvbInstance = FVB_INSTANCE_FROM_THIS (This); + + DEBUG((DEBUG_INFO, + "FvbProtocolGetBlockSize: Lba: 0x%lx BlockSize: 0x%x NumOfBlocks: 0x%x\n", + Lba, + BlockSize, + NumOfBlocks) + ); + + return FvbGetLbaAddress ( + FvbInstance, + Lba, + NULL, + BlockSize, + NumOfBlocks + ); +} + +/** + Retrieves Volume attributes. No polarity translations are done. + + @param[in] This Calling context + @param[out] Attributes Output buffer which contains attributes + + @retval EFI_SUCCESS The function always return successfully. + +**/ +EFI_STATUS +EFIAPI +FvbProtocolGetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ) +{ + EFI_FVB_INSTANCE *FvbInstance; + + FvbInstance = FVB_INSTANCE_FROM_THIS (This); + + *Attributes = FvbGetVolumeAttributes (FvbInstance); + + DEBUG ((DEBUG_INFO, + "FvbProtocolGetAttributes: This: 0x%x Attributes: 0x%x\n", + This, + *Attributes) + ); + + return EFI_SUCCESS; +} + +/** + Sets Volume attributes. No polarity translations are done. + + @param[in] This Calling context + @param[out] Attributes Output buffer which contains attributes + + @retval EFI_SUCCESS The function always return successfully. + +**/ +EFI_STATUS +EFIAPI +FvbProtocolSetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ) +{ + EFI_STATUS Status; + EFI_FVB_INSTANCE *FvbInstance; + + DEBUG((DEBUG_INFO, + "FvbProtocolSetAttributes: Before SET - This: 0x%x Attributes: 0x%x\n", + This, + *Attributes) + ); + + FvbInstance = FVB_INSTANCE_FROM_THIS (This); + + Status = FvbSetVolumeAttributes (FvbInstance, Attributes); + + DEBUG((DEBUG_INFO, + "FvbProtocolSetAttributes: After SET - This: 0x%x Attributes: 0x%x\n", + This, + *Attributes) + ); + + return Status; +} + +/** + The EraseBlock() function erases one or more blocks as denoted by the + variable argument list. The entire parameter list of blocks must be verified + prior to erasing any blocks. If a block is requested that does not exist + within the associated firmware volume (it has a larger index than the last + block of the firmware volume), the EraseBlock() function must return + EFI_INVALID_PARAMETER without modifying the contents of the firmware volume. + + @param[in] This Calling context + @param[in] ... Starting LBA followed by Number of Lba to erase. + a -1 to terminate the list. + + @retval EFI_SUCCESS The erase request was successfully completed + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state + @retval EFI_DEVICE_ERROR The block device is not functioning correctly and + could not be written. Firmware device may have been + partially erased + +**/ +EFI_STATUS +EFIAPI +FvbProtocolEraseBlocks ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + ... + ) +{ + EFI_FVB_INSTANCE *FvbInstance; + UINTN NumOfBlocks; + VA_LIST Args; + EFI_LBA StartingLba; + UINTN NumOfLba; + EFI_STATUS Status; + + DEBUG((DEBUG_INFO, "FvbProtocolEraseBlocks: \n")); + + FvbInstance = FVB_INSTANCE_FROM_THIS (This); + + NumOfBlocks = FvbInstance->NumOfBlocks; + + VA_START (Args, This); + + do { + StartingLba = VA_ARG (Args, EFI_LBA); + if ( StartingLba == EFI_LBA_LIST_TERMINATOR ) { + break; + } + + NumOfLba = VA_ARG (Args, UINT32); + + // + // Check input parameters + // + if (NumOfLba == 0) { + VA_END (Args); + return EFI_INVALID_PARAMETER; + } + + if ( ( StartingLba + NumOfLba ) > NumOfBlocks ) { + return EFI_INVALID_PARAMETER; + } + } while ( 1 ); + + VA_END (Args); + + VA_START (Args, This); + do { + StartingLba = VA_ARG (Args, EFI_LBA); + if (StartingLba == EFI_LBA_LIST_TERMINATOR) { + break; + } + + NumOfLba = VA_ARG (Args, UINT32); + + while ( NumOfLba > 0 ) { + Status = FvbEraseBlock (FvbInstance, StartingLba); + if ( EFI_ERROR(Status)) { + VA_END (Args); + return Status; + } + StartingLba ++; + NumOfLba --; + } + + } while ( 1 ); + + VA_END (Args); + + return EFI_SUCCESS; +} + +/** + Writes data beginning at Lba:Offset from FV. The write terminates either + when *NumBytes of data have been written, or when a block boundary is + reached. *NumBytes is updated to reflect the actual number of bytes + written. The write opertion does not include erase. This routine will + attempt to write only the specified bytes. If the writes do not stick, + it will return an error. + + @param[in] This Calling context + @param[in] Lba Block in which to begin write + @param[in] Offset Offset in the block at which to begin write + @param[in,out] NumBytes On input, indicates the requested write size. On + output, indicates the actual number of bytes written + @param[in] Buffer Buffer containing source data for the write. + + @retval EFI_SUCCESS The firmware volume was written successfully + @retval EFI_BAD_BUFFER_SIZE Write attempted across a LBA boundary. On output, + NumBytes contains the total number of bytes + actually written + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state + @retval EFI_DEVICE_ERROR The block device is not functioning correctly and + could not be written + @retval EFI_INVALID_PARAMETER NumBytes or Buffer are NULL + +**/ +EFI_STATUS +EFIAPI +FvbProtocolWrite ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ) +{ + EFI_FVB_INSTANCE *FvbInstance; + + FvbInstance = FVB_INSTANCE_FROM_THIS (This); + + DEBUG((DEBUG_INFO, + "FvbProtocolWrite: Lba: 0x%lx Offset: 0x%x NumBytes: 0x%x, Buffer: 0x%x\n", + Lba, + Offset, + *NumBytes, + Buffer) + ); + + return FvbWriteBlock (FvbInstance, Lba, Offset, NumBytes, Buffer); +} + +/** + Reads data beginning at Lba:Offset from FV. The Read terminates either + when *NumBytes of data have been read, or when a block boundary is + reached. *NumBytes is updated to reflect the actual number of bytes + written. The write opertion does not include erase. This routine will + attempt to write only the specified bytes. If the writes do not stick, + it will return an error. + + @param[in] This Calling context + @param[in] Lba Block in which to begin write + @param[in] Offset Offset in the block at which to begin write + @param[in,out] NumBytes On input, indicates the requested write size. On + output, indicates the actual number of bytes written + @param[in] Buffer Buffer containing source data for the write. + + @retval EFI_SUCCESS The firmware volume was read successfully and + contents are in Buffer + @retval EFI_BAD_BUFFER_SIZE Read attempted across a LBA boundary. On output, + NumBytes contains the total number of bytes returned + in Buffer + @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state + @retval EFI_DEVICE_ERROR The block device is not functioning correctly and + could not be read + @retval EFI_INVALID_PARAMETER NumBytes or Buffer are NULL + +**/ +EFI_STATUS +EFIAPI +FvbProtocolRead ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + OUT UINT8 *Buffer + ) +{ + EFI_FVB_INSTANCE *FvbInstance; + EFI_STATUS Status; + + FvbInstance = FVB_INSTANCE_FROM_THIS (This); + Status = FvbReadBlock (FvbInstance, Lba, Offset, NumBytes, Buffer); + DEBUG((DEBUG_INFO, + "FvbProtocolRead: Lba: 0x%lx Offset: 0x%x NumBytes: 0x%x, Buffer: 0x%x\n", + Lba, + Offset, + *NumBytes, + Buffer) + ); + + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/SpiFvbServiceCommon.h b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/SpiFvbServiceCommon.h new file mode 100644 index 0000000000..876f14dc8c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Common/SpiFvbServiceCommon.h @@ -0,0 +1,168 @@ +/** @file + Common source definitions used in serial flash drivers + +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. + +**/ + +#ifndef _SPI_FVB_SERVICE_COMMON_H +#define _SPI_FVB_SERVICE_COMMON_H + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +// +// Define two helper macro to extract the Capability field or Status field in FVB +// bit fields +// +#define EFI_FVB2_CAPABILITIES (EFI_FVB2_READ_DISABLED_CAP | \ + EFI_FVB2_READ_ENABLED_CAP | \ + EFI_FVB2_WRITE_DISABLED_CAP | \ + EFI_FVB2_WRITE_ENABLED_CAP | \ + EFI_FVB2_LOCK_CAP \ + ) + +#define EFI_FVB2_STATUS (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS) + +#define FVB_INSTANCE_SIGNATURE SIGNATURE_32('F','V','B','I') + +typedef struct { + UINT32 Signature; + UINTN FvBase; + UINTN NumOfBlocks; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL FvbProtocol; + EFI_FIRMWARE_VOLUME_HEADER FvHeader; +} EFI_FVB_INSTANCE; + +typedef struct { + EFI_FVB_INSTANCE *FvbInstance; + UINT32 NumFv; +} FVB_GLOBAL; + +// +// Fvb Protocol instance data +// +#define FVB_INSTANCE_FROM_THIS(a) CR(a, EFI_FVB_INSTANCE, FvbProtocol, FVB_INSTANCE_SIGNATURE) + +typedef struct { + MEDIA_FW_VOL_DEVICE_PATH FvDevPath; + EFI_DEVICE_PATH_PROTOCOL EndDevPath; +} FV_PIWG_DEVICE_PATH; + +typedef struct { + MEMMAP_DEVICE_PATH MemMapDevPath; + EFI_DEVICE_PATH_PROTOCOL EndDevPath; +} FV_MEMMAP_DEVICE_PATH; + +typedef struct { + UINT32 FvBase; + UINT32 FvSize; +} FV_INFO; + +// +// Protocol APIs +// +EFI_STATUS +EFIAPI +FvbProtocolGetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ); + +EFI_STATUS +EFIAPI +FvbProtocolSetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ); + +EFI_STATUS +EFIAPI +FvbProtocolGetPhysicalAddress ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + OUT EFI_PHYSICAL_ADDRESS *Address + ); + +EFI_STATUS +EFIAPI +FvbProtocolGetBlockSize ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN EFI_LBA Lba, + OUT UINTN *BlockSize, + OUT UINTN *NumOfBlocks + ); + +EFI_STATUS +EFIAPI +FvbProtocolRead ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + OUT UINT8 *Buffer + ); + +EFI_STATUS +EFIAPI +FvbProtocolWrite ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ); + +EFI_STATUS +EFIAPI +FvbProtocolEraseBlocks ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + ... + ); + +BOOLEAN +IsFvHeaderValid ( + IN EFI_PHYSICAL_ADDRESS FvBase, + IN CONST EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader + ); + +EFI_STATUS +GetFvbInfo ( + IN EFI_PHYSICAL_ADDRESS FvBaseAddress, + OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo + ); + +extern FVB_GLOBAL mFvbModuleGlobal; +extern FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate; +extern FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate; +extern EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL mFvbProtocolTemplate; +extern FV_INFO mPlatformFvBaseAddress[]; +extern FV_INFO mPlatformDefaultBaseAddress[]; + +#endif + diff --git a/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Smm/SpiFvbServiceSmm.c b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Smm/SpiFvbServiceSmm.c new file mode 100644 index 0000000000..04fbde2ca8 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/Smm/SpiFvbServiceSmm.c @@ -0,0 +1,281 @@ +/** @file + Common driver source for several Serial Flash devices + which are compliant with the Intel(R) Serial Flash Interface Compatibility Specification. + +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 "SpiFvbServiceCommon.h" +#include +#include + +/** + The function installs EFI_FIRMWARE_VOLUME_BLOCK protocol + for each FV in the system. + + @param[in] FvbInstance The pointer to a FW volume instance structure, + which contains the information about one FV. + + @retval VOID + +**/ +VOID +InstallFvbProtocol ( + IN EFI_FVB_INSTANCE *FvbInstance + ) +{ + EFI_FIRMWARE_VOLUME_HEADER *FvHeader; + EFI_STATUS Status; + EFI_HANDLE FvbHandle; + + ASSERT (FvbInstance != NULL); + if (FvbInstance == NULL) { + return; + } + + CopyMem (&FvbInstance->FvbProtocol, &mFvbProtocolTemplate, sizeof (EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL)); + + FvHeader = &FvbInstance->FvHeader; + if (FvHeader == NULL) { + return; + } + + // + // Set up the devicepath + // + DEBUG ((DEBUG_INFO, "FwBlockService.c: Setting up DevicePath for 0x%lx:\n", FvbInstance->FvBase)); + if (FvHeader->ExtHeaderOffset == 0) { + // + // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH + // + FvbInstance->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate); + if (FvbInstance->DevicePath == NULL) { + DEBUG ((DEBUG_INFO, "SpiFvbServiceSmm.c: Memory allocation for MEMMAP_DEVICE_PATH failed\n")); + return; + } + ((FV_MEMMAP_DEVICE_PATH *) FvbInstance->DevicePath)->MemMapDevPath.StartingAddress = FvbInstance->FvBase; + ((FV_MEMMAP_DEVICE_PATH *) FvbInstance->DevicePath)->MemMapDevPath.EndingAddress = FvbInstance->FvBase + FvHeader->FvLength - 1; + } else { + FvbInstance->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate); + if (FvbInstance->DevicePath == NULL) { + DEBUG ((DEBUG_INFO, "SpiFvbServiceSmm.c: Memory allocation for FV_PIWG_DEVICE_PATH failed\n")); + return; + } + CopyGuid ( + &((FV_PIWG_DEVICE_PATH *)FvbInstance->DevicePath)->FvDevPath.FvName, + (GUID *)(UINTN)(FvbInstance->FvBase + FvHeader->ExtHeaderOffset) + ); + } + + // + // LocateDevicePath fails so install a new interface and device path + // + FvbHandle = NULL; + + Status = gSmst->SmmInstallProtocolInterface ( + &FvbHandle, + &gEfiSmmFirmwareVolumeBlockProtocolGuid, + EFI_NATIVE_INTERFACE, + &(FvbInstance->FvbProtocol) + ); + ASSERT_EFI_ERROR (Status); + + Status = gSmst->SmmInstallProtocolInterface ( + &FvbHandle, + &gEfiDevicePathProtocolGuid, + EFI_NATIVE_INTERFACE, + &(FvbInstance->DevicePath) + ); + ASSERT_EFI_ERROR (Status); +} + +/** + + The function does the necessary initialization work for + Firmware Volume Block Driver. + + @param[in] ImageHandle The firmware allocated handle for the UEFI image. + @param[in] SystemTable A pointer to the EFI system table. + + @retval EFI_SUCCESS This funtion always return EFI_SUCCESS. + It will ASSERT on errors. + +**/ +EFI_STATUS +EFIAPI +FvbInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_FVB_INSTANCE *FvbInstance; + EFI_FIRMWARE_VOLUME_HEADER *FvHeader; + EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry; + EFI_PHYSICAL_ADDRESS BaseAddress; + EFI_STATUS Status; + UINTN BufferSize; + UINTN Idx; + UINT32 MaxLbaSize; + UINT32 BytesWritten; + UINTN BytesErased; + + // + // We will only continue with FVB installation if the + // SPI is the active BIOS state + // + { + // + // Make sure all FVB are valid and/or fix if possible + // + for (Idx = 0;; Idx++) { + if (mPlatformFvBaseAddress[Idx].FvSize == 0 && mPlatformFvBaseAddress[Idx].FvBase == 0) { + break; + } + + BaseAddress = mPlatformFvBaseAddress[Idx].FvBase; + FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress; + + if (!IsFvHeaderValid (BaseAddress, FvHeader)) { + BytesWritten = 0; + BytesErased = 0; + DEBUG ((DEBUG_ERROR, "ERROR - The FV in 0x%x is invalid!\n", FvHeader)); + Status = GetFvbInfo (BaseAddress, &FvHeader); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "ERROR - Can't recovery FV header at 0x%x. GetFvbInfo Status %r\n", BaseAddress, Status)); + continue; + } + DEBUG ((DEBUG_INFO, "Rewriting FV header at 0x%X with static data\n", BaseAddress)); + // + // Spi erase + // + BytesErased = (UINTN) FvHeader->BlockMap->Length; + Status = SpiFlashBlockErase( (UINTN) BaseAddress, &BytesErased); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "ERROR - SpiFlashBlockErase Error %r\n", Status)); + continue; + } + if (BytesErased != FvHeader->BlockMap->Length) { + DEBUG ((DEBUG_WARN, "ERROR - BytesErased != FvHeader->BlockMap->Length\n")); + DEBUG ((DEBUG_INFO, " BytesErased = 0x%X\n Length = 0x%X\n", BytesErased, FvHeader->BlockMap->Length)); + continue; + } + BytesWritten = FvHeader->HeaderLength; + Status = SpiFlashWrite ((UINTN)BaseAddress, &BytesWritten, (UINT8*)FvHeader); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "ERROR - SpiFlashWrite Error %r\n", Status)); + continue; + } + if (BytesWritten != FvHeader->HeaderLength) { + DEBUG ((DEBUG_WARN, "ERROR - BytesWritten != HeaderLength\n")); + DEBUG ((DEBUG_INFO, " BytesWritten = 0x%X\n HeaderLength = 0x%X\n", BytesWritten, FvHeader->HeaderLength)); + continue; + } + Status = SpiFlashLock (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "ERROR - SpiFlashLock Error %r\n", Status)); + continue; + } + DEBUG ((DEBUG_INFO, "FV Header @ 0x%X restored with static data\n", BaseAddress)); + // + // Clear cache for this range. + // + WriteBackInvalidateDataCacheRange ( (VOID *) (UINTN) BaseAddress, FvHeader->BlockMap->Length); + } + } + + // + // Calculate the total size for all firmware volume block instances + // + BufferSize = 0; + for (Idx = 0; ; Idx++) { + if (mPlatformFvBaseAddress[Idx].FvSize == 0 && mPlatformFvBaseAddress[Idx].FvBase == 0) { + break; + } + BaseAddress = mPlatformFvBaseAddress[Idx].FvBase; + FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress; + + if (!IsFvHeaderValid (BaseAddress, FvHeader)) { + DEBUG ((DEBUG_WARN, "ERROR - The FV in 0x%x is invalid!\n", FvHeader)); + continue; + } + + BufferSize += (FvHeader->HeaderLength + + sizeof (EFI_FVB_INSTANCE) - + sizeof (EFI_FIRMWARE_VOLUME_HEADER) + ); + } + + mFvbModuleGlobal.FvbInstance = (EFI_FVB_INSTANCE *) AllocateRuntimeZeroPool (BufferSize); + if (mFvbModuleGlobal.FvbInstance == NULL) { + ASSERT (FALSE); + Status = EFI_OUT_OF_RESOURCES; + goto ERROR; + } + + MaxLbaSize = 0; + FvbInstance = mFvbModuleGlobal.FvbInstance; + mFvbModuleGlobal.NumFv = 0; + + for (Idx = 0; ; Idx++) { + if (mPlatformFvBaseAddress[Idx].FvSize == 0 && mPlatformFvBaseAddress[Idx].FvBase == 0) { + break; + } + BaseAddress = mPlatformFvBaseAddress[Idx].FvBase; + FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress; + + if (!IsFvHeaderValid (BaseAddress, FvHeader)) { + DEBUG ((DEBUG_WARN, "ERROR - The FV in 0x%x is invalid!\n", FvHeader)); + continue; + } + + FvbInstance->Signature = FVB_INSTANCE_SIGNATURE; + CopyMem (&(FvbInstance->FvHeader), FvHeader, FvHeader->HeaderLength); + + FvHeader = &(FvbInstance->FvHeader); + FvbInstance->FvBase = (UINTN)BaseAddress; + + // + // Process the block map for each FV + // + FvbInstance->NumOfBlocks = 0; + for (PtrBlockMapEntry = FvHeader->BlockMap; + PtrBlockMapEntry->NumBlocks != 0; + PtrBlockMapEntry++) { + // + // Get the maximum size of a block. + // + if (MaxLbaSize < PtrBlockMapEntry->Length) { + MaxLbaSize = PtrBlockMapEntry->Length; + } + FvbInstance->NumOfBlocks += PtrBlockMapEntry->NumBlocks; + } + + // + // Add a FVB Protocol Instance + // + InstallFvbProtocol (FvbInstance); + mFvbModuleGlobal.NumFv++; + + // + // Move on to the next FvbInstance + // + FvbInstance = (EFI_FVB_INSTANCE *) ((UINTN)((UINT8 *)FvbInstance) + + FvHeader->HeaderLength + + (sizeof (EFI_FVB_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))); + + } + } + + return EFI_SUCCESS; + +ERROR: + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/SpiFvbServiceSmm.inf b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/SpiFvbServiceSmm.inf new file mode 100644 index 0000000000..98f21933c4 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Flash/SpiFvbService/SpiFvbServiceSmm.inf @@ -0,0 +1,72 @@ +### @file +# Component description file for the Serial Flash device Runtime driver. +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = SpiFvbServiceSmm + FILE_GUID = 68A10D85-6858-4402-B070-028B3EA21747 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_SMM_DRIVER + PI_SPECIFICATION_VERSION = 1.10 + ENTRY_POINT = FvbInitialize +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[LibraryClasses] + PcdLib + MemoryAllocationLib + CacheMaintenanceLib + BaseMemoryLib + DebugLib + BaseLib + UefiLib + UefiBootServicesTableLib + UefiDriverEntryPoint + SpiFlashCommonLib + SmmServicesTableLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[FixedPcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdFlashMicrocodeFvBase ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdFlashMicrocodeFvSize ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdFlashFvMain2Base ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdFlashFvMain2Size ## CONSUMES + +[Sources] + Common/SpiFvbServiceCommon.c + Common/FvbInfo.c + Smm/SpiFvbServiceSmm.c + +[Protocols] + gEfiDevicePathProtocolGuid ## PRODUCES + gEfiSmmFirmwareVolumeBlockProtocolGuid ## PRODUCES + +[Guids] + gEfiFirmwareFileSystem2Guid ## CONSUMES + gEfiSystemNvDataFvGuid ## CONSUMES + +[Depex] + TRUE diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.c new file mode 100644 index 0000000000..395f189ee9 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.c @@ -0,0 +1,49 @@ +/** @file + Dxe library function to reset the system from FSP wrapper. + +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 + +/** + Perform platform related reset in FSP wrapper. + + @param[in] ResetType The type of reset the platform has to perform. + + @return Will reset the system based on Reset status provided. +**/ +VOID +EFIAPI +CallFspWrapperResetSystem ( + UINT32 ResetType + ) +{ + EFI_RESET_TYPE EfiResetType; + + switch (ResetType) { + case FSP_STATUS_RESET_REQUIRED_COLD: + EfiResetType = EfiResetCold; + break; + case FSP_STATUS_RESET_REQUIRED_WARM: + EfiResetType = EfiResetWarm; + break; + default: + DEBUG ((DEBUG_ERROR, "UnSupported reset type requested. Initiating cold reset\n")); + EfiResetType = EfiResetCold; + } + gRT->ResetSystem (EfiResetType, EFI_SUCCESS, 0, NULL); + CpuDeadLoop (); +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.inf new file mode 100644 index 0000000000..4ccc2fbd68 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.inf @@ -0,0 +1,68 @@ +## @file +# Provide Dxe FSP wrapper platform reset related function. +# +# 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 which 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. +# +## + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeFspWrapperPlatformResetLib + FILE_GUID = C176048B-EF9C-4BE2-A464-26F00C551EAA + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = FspWrapperPlatformResetLib + LIBRARY_CLASS = FspWrapperPlatformLib + + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +################################################################################ +# +# Sources Section - list of files that are required for the build to succeed. +# +################################################################################ + +[Sources] + DxeFspWrapperPlatformResetLib.c + + +################################################################################ +# +# Package Dependency Section - list of Package files that are required for +# this module. +# +################################################################################ + +[Packages] + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + IntelFsp2Pkg/IntelFsp2Pkg.dec + +[LibraryClasses] + BaseMemoryLib + UefiRuntimeServicesTableLib + +[Ppis] + +[Guids] + +[Pcd] + diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/FspWrapperHobProcessLib.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/FspWrapperHobProcessLib.c new file mode 100644 index 0000000000..8fe1572065 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/FspWrapperHobProcessLib.c @@ -0,0 +1,662 @@ +/** @file + Provide FSP wrapper hob process related function. + +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 +#include + +#include + +// +// Additional pages are used by DXE memory manager. +// It should be consistent between RetrieveRequiredMemorySize() and GetPeiMemSize() +// +#define PEI_ADDITIONAL_MEMORY_SIZE (16 * EFI_PAGE_SIZE) + +/** + Get the mem size in memory type infromation table. + + @param[in] PeiServices PEI Services table. + + @return the mem size in memory type infromation table. +**/ +UINT64 +GetMemorySizeInMemoryTypeInformation ( + IN EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + EFI_PEI_HOB_POINTERS Hob; + EFI_MEMORY_TYPE_INFORMATION *MemoryData; + UINT8 Index; + UINTN TempPageNum; + + MemoryData = NULL; + Status = (*PeiServices)->GetHobList ((CONST EFI_PEI_SERVICES**)PeiServices, (VOID **) &Hob.Raw); + while (!END_OF_HOB_LIST (Hob)) { + if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION && + CompareGuid (&Hob.Guid->Name, &gEfiMemoryTypeInformationGuid)) { + MemoryData = (EFI_MEMORY_TYPE_INFORMATION *) (Hob.Raw + sizeof (EFI_HOB_GENERIC_HEADER) + sizeof (EFI_GUID)); + break; + } + + Hob.Raw = GET_NEXT_HOB (Hob); + } + + if (MemoryData == NULL) { + return 0; + } + + TempPageNum = 0; + for (Index = 0; MemoryData[Index].Type != EfiMaxMemoryType; Index++) { + // + // Accumulate default memory size requirements + // + TempPageNum += MemoryData[Index].NumberOfPages; + } + + return TempPageNum * EFI_PAGE_SIZE; +} + +/** + Get the mem size need to be reserved in PEI phase. + + @param[in] PeiServices PEI Services table. + + @return the mem size need to be reserved in PEI phase. +**/ +UINT64 +RetrieveRequiredMemorySize ( + IN EFI_PEI_SERVICES **PeiServices + ) +{ + UINT64 Size; + + Size = GetMemorySizeInMemoryTypeInformation (PeiServices); + return Size + PEI_ADDITIONAL_MEMORY_SIZE; +} + +/** + Get the mem size need to be consumed and reserved in PEI phase. + + @param[in] PeiServices PEI Services table. + @param[in] BootMode Current boot mode. + + @return the mem size need to be consumed and reserved in PEI phase. +**/ +UINT64 +GetPeiMemSize ( + IN EFI_PEI_SERVICES **PeiServices, + IN UINT32 BootMode + ) +{ + UINT64 Size; + UINT64 MinSize; + + if (BootMode == BOOT_IN_RECOVERY_MODE) { + return PcdGet32 (PcdPeiRecoveryMinMemSize); + } + + Size = GetMemorySizeInMemoryTypeInformation (PeiServices); + + if (BootMode == BOOT_ON_FLASH_UPDATE) { + // + // Maybe more size when in CapsuleUpdate phase ? + // + MinSize = PcdGet32 (PcdPeiMinMemSize); + } else { + MinSize = PcdGet32 (PcdPeiMinMemSize); + } + + return MinSize + Size + PEI_ADDITIONAL_MEMORY_SIZE; +} + +/** + Post FSP-M HOB process for Memory Resource Descriptor. + + @param[in] FspHobList Pointer to the HOB data structure produced by FSP. + + @return If platform process the FSP hob list successfully. +**/ +EFI_STATUS +EFIAPI +PostFspmHobProcess ( + IN VOID *FspHobList + ) +{ + EFI_PEI_HOB_POINTERS Hob; + UINT64 PeiMemSize; + EFI_PHYSICAL_ADDRESS PeiMemBase; + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + EFI_PEI_CAPSULE_PPI *Capsule; + VOID *CapsuleBuffer; + UINTN CapsuleBufferLength; + UINT64 RequiredMemSize; + UINT64 ResourceLength; + EFI_PEI_SERVICES **PeiServices; + + PeiServices = (EFI_PEI_SERVICES **)GetPeiServicesTablePointer (); + + PeiServicesGetBootMode (&BootMode); + + PeiMemBase = 0; + ResourceLength = 0; + // + // Parse the hob list from fsp + // Report all the resource hob except MMIO and IO resource Hob's + // + if (BootMode != BOOT_ON_S3_RESUME) { + PeiMemSize = GetPeiMemSize (PeiServices, BootMode); + RequiredMemSize = RetrieveRequiredMemorySize (PeiServices); + Hob.Raw = (UINT8 *)(UINTN)FspHobList; + DEBUG((DEBUG_INFO, "FspHobList - 0x%x\n", FspHobList)); + // + // Find the largest available system Memory and use it for PeiMemory + // + while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw)) != NULL) { + if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) + && (Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength <= BASE_4GB) + && (Hob.ResourceDescriptor->PhysicalStart >= PeiMemBase) + && (Hob.ResourceDescriptor->ResourceLength >= PeiMemSize)) { + PeiMemBase = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength - PeiMemSize; + } + Hob.Raw = GET_NEXT_HOB (Hob); + } + } + + Hob.Raw = (UINT8 *)(UINTN)FspHobList; + + // + // Skip the MMIO and IO reource map from the FSP Hob list + // + while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw)) != NULL) { + if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_IO) || (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_MAPPED_IO)) { + Hob.Raw = GET_NEXT_HOB (Hob); + continue; + } + ResourceLength = Hob.ResourceDescriptor->ResourceLength; + DEBUG((DEBUG_INFO, "Resource start %lx resource length %lx resource type %d\n",Hob.ResourceDescriptor->PhysicalStart,Hob.ResourceDescriptor->ResourceLength,Hob.ResourceDescriptor->ResourceType)); + if (BootMode != BOOT_ON_S3_RESUME) { + // + // If the system memory found in FSP Hob is determined for PeiMemory. Split the Resource descriptor Hob + // + if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) + && (Hob.ResourceDescriptor->PhysicalStart <= PeiMemBase) + && (Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength >= PeiMemBase + PeiMemSize) + && (Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength <= BASE_4GB)) { + if ((CompareGuid (&Hob.ResourceDescriptor->Owner, &gZeroGuid))) { + BuildResourceDescriptorHob ( + Hob.ResourceDescriptor->ResourceType, + Hob.ResourceDescriptor->ResourceAttribute, + PeiMemBase, + PeiMemSize + ); + } else { + BuildResourceDescriptorWithOwnerHob ( + Hob.ResourceDescriptor->ResourceType, + Hob.ResourceDescriptor->ResourceAttribute, + PeiMemBase, + PeiMemSize, + &Hob.ResourceDescriptor->Owner + ); + } + ResourceLength = (Hob.ResourceDescriptor->ResourceLength) -(PeiMemSize); + } + } + + // + // Report the resource hob + // + if ((CompareGuid (&Hob.ResourceDescriptor->Owner, &gZeroGuid))) { + BuildResourceDescriptorHob ( + Hob.ResourceDescriptor->ResourceType, + Hob.ResourceDescriptor->ResourceAttribute, + Hob.ResourceDescriptor->PhysicalStart, + ResourceLength + ); + } else { + BuildResourceDescriptorWithOwnerHob ( + Hob.ResourceDescriptor->ResourceType, + Hob.ResourceDescriptor->ResourceAttribute, + Hob.ResourceDescriptor->PhysicalStart, + ResourceLength, + &Hob.ResourceDescriptor->Owner + ); + } + + Hob.Raw = GET_NEXT_HOB (Hob); + } + + // + // @todo: It is a W/A for SetMemorySpaceAttribute issue in PchSpi and PchReset drivers in FVMAIN of SSPT. + // We need to modify it instead of hard code here. Due to InstallEfiMemory is using hard code to + // describe memory resource, we have to hard code in here. Once InstallEfiMemory is merged, we should + // be able to remove this. + // + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE, + 0xFFA00000, + 0x80000 + ); + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE, + 0xFE000000, + 0x10000 + ); + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE, + PcdGet64 (PcdPciExpressBaseAddress), + PcdGet32 (PcdPciExpressRegionLength) + ); + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE, + 0xFE010000, + 0x1000 + ); + + + // + // Capsule mode + // + Capsule = NULL; + CapsuleBuffer = NULL; + CapsuleBufferLength = 0; + if (BootMode == BOOT_ON_FLASH_UPDATE) { + Status = PeiServicesLocatePpi ( + &gEfiPeiCapsulePpiGuid, + 0, + NULL, + (VOID **) &Capsule + ); + ASSERT_EFI_ERROR (Status); + + if (Status == EFI_SUCCESS) { + Status = PeiServicesGetHobList ((void**)&Hob.Raw); + while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw)) != NULL) { + if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) + && (Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength <= BASE_4GB) + && (Hob.ResourceDescriptor->PhysicalStart >= BASE_1MB) + && (Hob.ResourceDescriptor->PhysicalStart != PeiMemBase) + && (Hob.ResourceDescriptor->ResourceLength >= CapsuleBufferLength)) { + CapsuleBufferLength = (UINTN)Hob.ResourceDescriptor->ResourceLength; + CapsuleBuffer = (VOID*)(UINTN)Hob.ResourceDescriptor->PhysicalStart; + + } + Hob.Raw = GET_NEXT_HOB (Hob); + } + + // + // Call the Capsule PPI Coalesce function to coalesce the capsule data. + // + Status = Capsule->Coalesce (PeiServices, &CapsuleBuffer, &CapsuleBufferLength); + } + } + + + DEBUG((DEBUG_INFO, "FSP wrapper PeiMemBase : 0x%08x\n", PeiMemBase)); + DEBUG((DEBUG_INFO, "FSP wrapper PeiMemSize : 0x%08x\n", PeiMemSize)); + DEBUG((DEBUG_INFO, "FSP wrapper RequiredMemSize : 0x%08x\n", RequiredMemSize)); + + + // + // Install efi memory + // + Status = PeiServicesInstallPeiMemory ( + PeiMemBase, + PeiMemSize - RequiredMemSize + ); + ASSERT_EFI_ERROR (Status); + + if (Capsule != NULL) { + Status = Capsule->CreateState ((EFI_PEI_SERVICES **)PeiServices, CapsuleBuffer, CapsuleBufferLength); + } + + + // + // Create a memory allocation HOB at fixed location for MP Services PPI AP wait loop. + // Report memory region used by FSP. + // + BuildMemoryAllocationHob ( + PcdGet32 (PcdFspCpuPeiApWakeupBufferAddr), + EFI_PAGE_SIZE, + EfiBootServicesData + ); + + return EFI_SUCCESS; +} + +/** + Process FSP HOB list + + @param[in] FspHobList Pointer to the HOB data structure produced by FSP. + +**/ +VOID +ProcessFspHobList ( + IN VOID *FspHobList + ) +{ + UINT8 PhysicalAddressBits; + UINT32 RegEax; + EFI_PEI_HOB_POINTERS FspHob; + + FspHob.Raw = FspHobList; + + AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL); + if (RegEax >= 0x80000008) { + AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL); + PhysicalAddressBits = (UINT8) RegEax; + } else { + PhysicalAddressBits = 36; + } + + /// + /// Create a CPU hand-off information + /// + BuildCpuHob (PhysicalAddressBits, 16); + + // + // Add all the HOBs from FSP binary to FSP wrapper + // + while (!END_OF_HOB_LIST (FspHob)) { + if (FspHob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) { + // + // Skip FSP binary creates PcdDataBaseHobGuid + // + if (!CompareGuid(&FspHob.Guid->Name, &gPcdDataBaseHobGuid)) { + BuildGuidDataHob ( + &FspHob.Guid->Name, + GET_GUID_HOB_DATA(FspHob), + GET_GUID_HOB_DATA_SIZE(FspHob) + ); + } + } + FspHob.Raw = GET_NEXT_HOB (FspHob); + } +} + +VOID +CheckFspGraphicsDeviceInfoHob ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_STATUS Status; + EFI_PEI_GRAPHICS_INFO_HOB *FspGraphicsInfo = NULL; + EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *FspGraphicsDeviceInfo = NULL; + EFI_PEI_GRAPHICS_DEVICE_INFO_HOB GraphicsDeviceInfo; + + Status = PeiServicesGetHobList (&Hob.Raw); + if (!EFI_ERROR (Status)) { + if (Hob.Raw != NULL) { + if ((Hob.Raw = GetNextGuidHob (&gEfiGraphicsInfoHobGuid, Hob.Raw)) != NULL) { + FspGraphicsInfo = GET_GUID_HOB_DATA (Hob.Guid); + } + } + } + if (FspGraphicsInfo == NULL) { + return ; + } + + Status = PeiServicesGetHobList (&Hob.Raw); + if (!EFI_ERROR (Status)) { + if (Hob.Raw != NULL) { + if ((Hob.Raw = GetNextGuidHob (&gEfiGraphicsDeviceInfoHobGuid, Hob.Raw)) != NULL) { + FspGraphicsDeviceInfo = GET_GUID_HOB_DATA (Hob.Guid); + } + } + } + if (FspGraphicsDeviceInfo != NULL) { + return ; + } + + // + // FSP only publish FspGraphicsInfo, but no FspGraphicsDeviceInfo. + // + // Workaround: Need publish FspGraphicsDeviceInfo, because Intel Graphics BarIndex is 1. + // + GraphicsDeviceInfo.VendorId = MAX_UINT16; + GraphicsDeviceInfo.DeviceId = MAX_UINT16; + GraphicsDeviceInfo.SubsystemVendorId = MAX_UINT16; + GraphicsDeviceInfo.SubsystemId = MAX_UINT16; + GraphicsDeviceInfo.RevisionId = MAX_UINT8; + GraphicsDeviceInfo.BarIndex = 1; + BuildGuidDataHob ( + &gEfiGraphicsDeviceInfoHobGuid, + &GraphicsDeviceInfo, + sizeof(GraphicsDeviceInfo) + ); + + return ; +} + +/** + Dump FSP SMBIOS memory info HOB + +**/ +VOID +DumpFspSmbiosMemoryInfoHob ( + VOID + ) +{ +} + + +/** + Dump FSP SMBIOS Processor Info HOB + +**/ +VOID +DumpFspSmbiosProcessorInfoHob ( + VOID + ) +{ +} + +/** + Dump FSP SMBIOS Cache Info Hob + +**/ +VOID +DumpFspSmbiosCacheInfoHob ( + VOID + ) +{ +} + +/** + Dump FSP HOB list + +**/ +VOID +DumpFspHobList ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_STATUS Status; + + Status = PeiServicesGetHobList (&Hob.Raw); + while (!END_OF_HOB_LIST (Hob)) { + if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) { + DEBUG ((DEBUG_INFO, "FSP Extended GUID HOB: {%g}\n", &(Hob.Guid->Name))); + } + if ((Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) && + (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_RESERVED)) { + DEBUG ((DEBUG_INFO, "FSP Reserved Resource HOB: %016lX ~ %016lX\n", \ + Hob.ResourceDescriptor->PhysicalStart, Hob.ResourceDescriptor->PhysicalStart \ + + Hob.ResourceDescriptor->ResourceLength)); + } + Hob.Raw = GET_NEXT_HOB (Hob); + } +} + +/** + Dump FSP memory resource + +**/ +VOID +DumpFspMemoryResource ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_STATUS Status; + + Status = PeiServicesGetHobList (&Hob.Raw); + DEBUG ((DEBUG_INFO, "\nFSP Memory Resource\n")); + DEBUG ((DEBUG_INFO, " Resource Range Type Attribute Owner\n")); + DEBUG ((DEBUG_INFO, "================================= ==== ================ ====================================\n")); + while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw)) != NULL) { + if (!CompareGuid (&(Hob.ResourceDescriptor->Owner), &gZeroGuid)) { + DEBUG ((DEBUG_INFO, "%016lx-%016lx %4x %016x %g\n", + Hob.ResourceDescriptor->PhysicalStart, + Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength, + Hob.ResourceDescriptor->ResourceType, + Hob.ResourceDescriptor->ResourceAttribute, + &(Hob.ResourceDescriptor->Owner) + )); + } else { + DEBUG ((DEBUG_INFO, "%016lx-%016lx %4x %016x \n", + Hob.ResourceDescriptor->PhysicalStart, + Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength, + Hob.ResourceDescriptor->ResourceType, + Hob.ResourceDescriptor->ResourceAttribute + )); + } + Hob.Raw = GET_NEXT_HOB (Hob); + } + DEBUG ((DEBUG_INFO, "\n")); +} + +/** + Dump FSP memory resource + +**/ +VOID +DumpFspGraphicsInfoHob ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_STATUS Status; + EFI_PEI_GRAPHICS_INFO_HOB *FspGraphicsInfo = NULL; + + Status = PeiServicesGetHobList (&Hob.Raw); + if (!EFI_ERROR (Status)) { + if (Hob.Raw != NULL) { + if ((Hob.Raw = GetNextGuidHob (&gEfiGraphicsInfoHobGuid, Hob.Raw)) != NULL) { + FspGraphicsInfo = GET_GUID_HOB_DATA (Hob.Guid); + } + } + if (FspGraphicsInfo != NULL) { + DEBUG((DEBUG_INFO, "\nGraphicsInfo\n")); + DEBUG((DEBUG_INFO, " |-> FrameBufferBase : 0x%016lx\n", FspGraphicsInfo->FrameBufferBase)); + DEBUG((DEBUG_INFO, " |-> FrameBufferSize : 0x%016lx\n", FspGraphicsInfo->FrameBufferSize)); + DEBUG((DEBUG_INFO, " |-> GraphicsMode\n")); + DEBUG((DEBUG_INFO, " |-> Version : 0x%08x\n", FspGraphicsInfo->GraphicsMode.Version)); + DEBUG((DEBUG_INFO, " |-> HorizontalResolution : %d\n", FspGraphicsInfo->GraphicsMode.HorizontalResolution)); + DEBUG((DEBUG_INFO, " |-> VerticalResolution : %d\n", FspGraphicsInfo->GraphicsMode.VerticalResolution)); + DEBUG((DEBUG_INFO, " |-> PixelFormat : %d\n", FspGraphicsInfo->GraphicsMode.PixelFormat)); + DEBUG((DEBUG_INFO, " |-> PixelInformation : %d|%d|%d|%d\n", + FspGraphicsInfo->GraphicsMode.PixelInformation.RedMask, + FspGraphicsInfo->GraphicsMode.PixelInformation.GreenMask, + FspGraphicsInfo->GraphicsMode.PixelInformation.BlueMask, + FspGraphicsInfo->GraphicsMode.PixelInformation.ReservedMask + )); + DEBUG((DEBUG_INFO, " |-> PixelsPerScanLine : %d\n", FspGraphicsInfo->GraphicsMode.PixelsPerScanLine)); + DEBUG((DEBUG_INFO, "\n")); + } else { + DEBUG((DEBUG_INFO, "\nNo GraphicsInfo\n")); + } + } +} + +VOID +DumpFspGraphicsDeviceInfoHob ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_STATUS Status; + EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *FspGraphicsDeviceInfo = NULL; + + Status = PeiServicesGetHobList (&Hob.Raw); + if (!EFI_ERROR (Status)) { + if (Hob.Raw != NULL) { + if ((Hob.Raw = GetNextGuidHob (&gEfiGraphicsDeviceInfoHobGuid, Hob.Raw)) != NULL) { + FspGraphicsDeviceInfo = GET_GUID_HOB_DATA (Hob.Guid); + } + } + if (FspGraphicsDeviceInfo != NULL) { + DEBUG((DEBUG_INFO, "\nGraphicsDeviceInfo\n")); + DEBUG((DEBUG_INFO, " |-> VendorId : 0x%04x\n", FspGraphicsDeviceInfo->VendorId)); + DEBUG((DEBUG_INFO, " |-> DeviceId : 0x%04x\n", FspGraphicsDeviceInfo->DeviceId)); + DEBUG((DEBUG_INFO, " |-> SubsystemVendorId : 0x%04x\n", FspGraphicsDeviceInfo->SubsystemVendorId)); + DEBUG((DEBUG_INFO, " |-> SubsystemId : 0x%04x\n", FspGraphicsDeviceInfo->SubsystemId)); + DEBUG((DEBUG_INFO, " |-> RevisionId : 0x%02x\n", FspGraphicsDeviceInfo->RevisionId)); + DEBUG((DEBUG_INFO, " |-> BarIndex : 0x%02x\n", FspGraphicsDeviceInfo->BarIndex)); + DEBUG((DEBUG_INFO, "\n")); + } else { + DEBUG((DEBUG_INFO, "\nNo GraphicsDeviceInfo\n")); + } + } +} + +/** + Post FSP-S HOB process (not Memory Resource Descriptor). + + @param[in] FspHobList Pointer to the HOB data structure produced by FSP. + + @return If platform process the FSP hob list successfully. +**/ +EFI_STATUS +EFIAPI +PostFspsHobProcess ( + IN VOID *FspHobList + ) +{ + ProcessFspHobList (FspHobList); + + CheckFspGraphicsDeviceInfoHob (); + DEBUG_CODE_BEGIN (); + DumpFspSmbiosMemoryInfoHob (); + DumpFspSmbiosProcessorInfoHob(); + DumpFspSmbiosCacheInfoHob(); + DumpFspGraphicsInfoHob (); + DumpFspGraphicsDeviceInfoHob (); + DumpFspHobList (); + DumpFspMemoryResource (); + DEBUG_CODE_END (); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.inf new file mode 100644 index 0000000000..e36674e009 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.inf @@ -0,0 +1,84 @@ +## @file +# Provide FSP wrapper hob process related function. +# +# 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 which 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. +# +## + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiFspWrapperHobProcessLib + FILE_GUID = C7B7070B-E5A8-4b86-9110-BDCA1095F496 + MODULE_TYPE = SEC + VERSION_STRING = 1.0 + LIBRARY_CLASS = FspWrapperHobProcessLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +################################################################################ +# +# Sources Section - list of files that are required for the build to succeed. +# +################################################################################ + +[Sources] + FspWrapperHobProcessLib.c + + +################################################################################ +# +# Package Dependency Section - list of Package files that are required for +# this module. +# +################################################################################ + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + IntelFsp2Pkg/IntelFsp2Pkg.dec + IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + HobLib + DebugLib + FspWrapperPlatformLib + PeiServicesLib + PeiServicesTablePointerLib + +[Pcd] + gIntelFsp2WrapperTokenSpaceGuid.PcdPeiMinMemSize ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdPeiRecoveryMinMemSize ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress + gPlatformModuleTokenSpaceGuid.PcdPciExpressRegionLength + gPlatformModuleTokenSpaceGuid.PcdFspCpuPeiApWakeupBufferAddr + +[Guids] + gFspReservedMemoryResourceHobGuid ## CONSUMES ## HOB + gEfiMemoryTypeInformationGuid ## CONSUMES ## GUID + gPcdDataBaseHobGuid + gZeroGuid + gEfiGraphicsInfoHobGuid + gEfiGraphicsDeviceInfoHobGuid + +[Ppis] + gEfiPeiCapsulePpiGuid ## CONSUMES diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.c new file mode 100644 index 0000000000..3682a1e2e2 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.c @@ -0,0 +1,74 @@ +/** @file + Provide FSP wrapper platform related function. + +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 + + +/** + This function overrides the default configurations in the FSP-M UPD data region. + + @note At this point, memory is NOT ready, PeiServices are available to use. + + @param[in,out] FspUpdRgnPtr A pointer to the UPD data region data strcture. + +**/ +VOID +EFIAPI +UpdateFspmUpdData ( + IN OUT VOID *FspUpdRgnPtr + ) +{ + FspmPolicyInit (FspUpdRgnPtr); + FspmPolicyUpdate (FspUpdRgnPtr); +} + +/** + This function overrides the default configurations in the FSP-S UPD data region. + + @param[in,out] FspUpdRgnPtr A pointer to the UPD data region data strcture. + +**/ +VOID +EFIAPI +UpdateFspsUpdData ( + IN OUT VOID *FspUpdRgnPtr + ) +{ + FspsPolicyInit (FspUpdRgnPtr); + FspsPolicyUpdate (FspUpdRgnPtr); +} + +/** + Update TempRamExit parameter. + + @note At this point, memory is ready, PeiServices are available to use. + + @return TempRamExit parameter. +**/ +VOID * +EFIAPI +UpdateTempRamExitParam ( + VOID + ) +{ + return NULL; +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.inf new file mode 100644 index 0000000000..17f42582c1 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.inf @@ -0,0 +1,61 @@ +## @file +# Provide FSP wrapper platform related function. +# +# 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 which 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. +# +## + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiFspWrapperPlatformLib + FILE_GUID = 415F065F-CEC1-43A3-B9D8-39E5D0DDD9A0 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = FspWrapperPlatformLib + + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +################################################################################ +# +# Sources Section - list of files that are required for the build to succeed. +# +################################################################################ + +[Sources] + PeiFspWrapperPlatformLib.c + +################################################################################ +# +# Package Dependency Section - list of Package files that are required for +# this module. +# +################################################################################ + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + IntelFsp2Pkg/IntelFsp2Pkg.dec + IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[LibraryClasses.IA32] + FspPolicyInitLib + FspPolicyUpdateLib diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.c new file mode 100644 index 0000000000..501197c709 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.c @@ -0,0 +1,48 @@ +/** @file + Pei library function to reset the system from FSP wrapper. + +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 +/** + Perform platform related reset in FSP wrapper. + + @param[in] ResetType The type of reset the platform has to perform. + + @return Will reset the system based on Reset status provided. +**/ +VOID +EFIAPI +CallFspWrapperResetSystem ( + UINT32 ResetType + ) +{ + EFI_RESET_TYPE EfiResetType; + + switch (ResetType) { + case FSP_STATUS_RESET_REQUIRED_COLD: + EfiResetType = EfiResetCold; + break; + case FSP_STATUS_RESET_REQUIRED_WARM: + EfiResetType = EfiResetWarm; + break; + default: + DEBUG ((DEBUG_ERROR, "UnSupported reset type requested. Initiating cold reset\n")); + EfiResetType = EfiResetCold; + } + (*GetPeiServicesTablePointer ())->ResetSystem2 (EfiResetType, EFI_SUCCESS, 0, NULL); + CpuDeadLoop (); +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.inf new file mode 100644 index 0000000000..80df3427ff --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.inf @@ -0,0 +1,67 @@ +## @file +# Provide FSP wrapper platform reset related function. +# +# 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 which 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. +# +## + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiFspWrapperPlatformResetLib + FILE_GUID = B1EB436F-9188-4A54-A28C-F019A64ED9EA + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = FspWrapperPlatformResetLib + + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +################################################################################ +# +# Sources Section - list of files that are required for the build to succeed. +# +################################################################################ + +[Sources] + PeiFspWrapperPlatformResetLib.c + + +################################################################################ +# +# Package Dependency Section - list of Package files that are required for +# this module. +# +################################################################################ + +[Packages] + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + IntelFsp2Pkg/IntelFsp2Pkg.dec + +[LibraryClasses] + PeiServicesTablePointerLib + BaseMemoryLib + +[Ppis] + + +[Guids] + +[Pcd] diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/FspWrapperPlatformSecLib.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/FspWrapperPlatformSecLib.c new file mode 100644 index 0000000000..cc7e043c96 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/FspWrapperPlatformSecLib.c @@ -0,0 +1,162 @@ +/** @file + Provide FSP wrapper platform sec related function. + +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 + +/** + This interface conveys state information out of the Security (SEC) phase into PEI. + + @param[in] PeiServices Pointer to the PEI Services Table. + @param[in,out] StructureSize Pointer to the variable describing size of the input buffer. + @param[out] PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD. + + @retval EFI_SUCCESS The data was successfully returned. + @retval EFI_BUFFER_TOO_SMALL The buffer was too small. + +**/ +EFI_STATUS +EFIAPI +SecPlatformInformation ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN OUT UINT64 *StructureSize, + OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord + ); + +/** + This interface conveys performance information out of the Security (SEC) phase into PEI. + + This service is published by the SEC phase. The SEC phase handoff has an optional + EFI_PEI_PPI_DESCRIPTOR list as its final argument when control is passed from SEC into the + PEI Foundation. As such, if the platform supports collecting performance data in SEC, + this information is encapsulated into the data structure abstracted by this service. + This information is collected for the boot-strap processor (BSP) on IA-32. + + @param[in] PeiServices The pointer to the PEI Services Table. + @param[in] This The pointer to this instance of the PEI_SEC_PERFORMANCE_PPI. + @param[out] Performance The pointer to performance data collected in SEC phase. + + @retval EFI_SUCCESS The data was successfully returned. + +**/ +EFI_STATUS +EFIAPI +SecGetPerformance ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN PEI_SEC_PERFORMANCE_PPI *This, + OUT FIRMWARE_SEC_PERFORMANCE *Performance + ); + +PEI_SEC_PERFORMANCE_PPI mSecPerformancePpi = { + SecGetPerformance +}; + +EFI_PEI_FIRMWARE_VOLUME_INFO_PPI mRecovery2FirmwareVolumeInfoPpi = { + EFI_FIRMWARE_FILE_SYSTEM2_GUID, + (VOID *)(UINTN) FixedPcdGet32 (PcdFlashFvRecovery2Base), + FixedPcdGet32 (PcdFlashFvRecovery2Size), + NULL, + NULL +}; + +EFI_PEI_FIRMWARE_VOLUME_INFO_PPI mRecovery3FirmwareVolumeInfoPpi = { + EFI_FIRMWARE_FILE_SYSTEM2_GUID, + (VOID *)(UINTN) FixedPcdGet32 (PcdFlashFvRecovery3Base), + FixedPcdGet32 (PcdFlashFvRecovery3Size), + NULL, + NULL, +}; + +EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformPpi[] = { + { + EFI_PEI_PPI_DESCRIPTOR_PPI, + &gTopOfTemporaryRamPpiGuid, + NULL // To be patched later. + }, + { + EFI_PEI_PPI_DESCRIPTOR_PPI, + &gEfiPeiFirmwareVolumeInfoPpiGuid, + &mRecovery2FirmwareVolumeInfoPpi + }, + { + EFI_PEI_PPI_DESCRIPTOR_PPI, + &gEfiPeiFirmwareVolumeInfoPpiGuid, + &mRecovery3FirmwareVolumeInfoPpi + }, + { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gPeiSecPerformancePpiGuid, + &mSecPerformancePpi + }, +}; + +/** + A developer supplied function to perform platform specific operations. + + It's a developer supplied function to perform any operations appropriate to a + given platform. It's invoked just before passing control to PEI core by SEC + core. Platform developer may modify the SecCoreData passed to PEI Core. + It returns a platform specific PPI list that platform wishes to pass to PEI core. + The Generic SEC core module will merge this list to join the final list passed to + PEI core. + + @param[in,out] SecCoreData The same parameter as passing to PEI core. It + could be overridden by this function. + + @return The platform specific PPI list to be passed to PEI core or + NULL if there is no need of such platform specific PPI list. + +**/ +EFI_PEI_PPI_DESCRIPTOR * +EFIAPI +SecPlatformMain ( + IN OUT EFI_SEC_PEI_HAND_OFF *SecCoreData + ) +{ + EFI_PEI_PPI_DESCRIPTOR *PpiList; + + DEBUG ((DEBUG_INFO, "FSP Wrapper BootFirmwareVolumeBase - 0x%x\n", SecCoreData->BootFirmwareVolumeBase)); + DEBUG ((DEBUG_INFO, "FSP Wrapper BootFirmwareVolumeSize - 0x%x\n", SecCoreData->BootFirmwareVolumeSize)); + DEBUG ((DEBUG_INFO, "FSP Wrapper TemporaryRamBase - 0x%x\n", SecCoreData->TemporaryRamBase)); + DEBUG ((DEBUG_INFO, "FSP Wrapper TemporaryRamSize - 0x%x\n", SecCoreData->TemporaryRamSize)); + DEBUG ((DEBUG_INFO, "FSP Wrapper PeiTemporaryRamBase - 0x%x\n", SecCoreData->PeiTemporaryRamBase)); + DEBUG ((DEBUG_INFO, "FSP Wrapper PeiTemporaryRamSize - 0x%x\n", SecCoreData->PeiTemporaryRamSize)); + DEBUG ((DEBUG_INFO, "FSP Wrapper StackBase - 0x%x\n", SecCoreData->StackBase)); + DEBUG ((DEBUG_INFO, "FSP Wrapper StackSize - 0x%x\n", SecCoreData->StackSize)); + + InitializeApicTimer (0, (UINT32) -1, TRUE, 5); + + // + // Use middle of Heap as temp buffer, it will be copied by caller. + // Do not use Stack, because it will cause wrong calculation on stack by PeiCore + // + PpiList = (VOID *)((UINTN)SecCoreData->PeiTemporaryRamBase + (UINTN)SecCoreData->PeiTemporaryRamSize/2); + CopyMem (PpiList, mPeiSecPlatformPpi, sizeof(mPeiSecPlatformPpi)); + + // + // Patch TopOfTemporaryRamPpi + // + PpiList[0].Ppi = (VOID *)((UINTN)SecCoreData->TemporaryRamBase + SecCoreData->TemporaryRamSize); + + return PpiList; +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/FsptCoreUpd.h b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/FsptCoreUpd.h new file mode 100644 index 0000000000..bfdc279c4a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/FsptCoreUpd.h @@ -0,0 +1,46 @@ +/** @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. + +**/ + +#ifndef __FSPT_CORE_UPD_H__ +#define __FSPT_CORE_UPD_H__ + +#pragma pack(1) + +/** Fsp T Core UPD +**/ +typedef struct { + +/** Offset 0x0020 +**/ + UINT32 MicrocodeRegionBase; + +/** Offset 0x0024 +**/ + UINT32 MicrocodeRegionSize; + +/** Offset 0x0028 +**/ + UINT32 CodeRegionBase; + +/** Offset 0x002C +**/ + UINT32 CodeRegionSize; + +/** Offset 0x0030 +**/ + UINT8 Reserved[16]; +} FSPT_CORE_UPD; + +#pragma pack() + +#endif diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Fsp.h b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Fsp.h new file mode 100644 index 0000000000..ba5219198c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Fsp.h @@ -0,0 +1,48 @@ +/** @file + Fsp related definitions + +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. + +**/ + +#ifndef __FSP_H__ +#define __FSP_H__ + +// +// Fv Header +// +#define FVH_SIGINATURE_OFFSET 0x28 +#define FVH_SIGINATURE_VALID_VALUE 0x4856465F // valid signature:_FVH +#define FVH_HEADER_LENGTH_OFFSET 0x30 +#define FVH_EXTHEADER_OFFSET_OFFSET 0x34 +#define FVH_EXTHEADER_SIZE_OFFSET 0x10 + +// +// Ffs Header +// +#define FSP_HEADER_GUID_DWORD1 0x912740BE +#define FSP_HEADER_GUID_DWORD2 0x47342284 +#define FSP_HEADER_GUID_DWORD3 0xB08471B9 +#define FSP_HEADER_GUID_DWORD4 0x0C3F3527 +#define FFS_HEADER_SIZE_VALUE 0x18 + +// +// Section Header +// +#define SECTION_HEADER_TYPE_OFFSET 0x03 +#define RAW_SECTION_HEADER_SIZE_VALUE 0x04 + +// +// Fsp Header +// +#define FSP_HEADER_IMAGEBASE_OFFSET 0x1C +#define FSP_HEADER_TEMPRAMINIT_OFFSET 0x30 + +#endif diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/PeiCoreEntry.S b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/PeiCoreEntry.S new file mode 100644 index 0000000000..8923577263 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/PeiCoreEntry.S @@ -0,0 +1,123 @@ +## @file +# Find and call SecStartup +# +# 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. +# +## + +ASM_GLOBAL ASM_PFX(CallPeiCoreEntryPoint) +ASM_PFX(CallPeiCoreEntryPoint): + # + # Obtain the hob list pointer + # + movl 0x4(%esp), %eax + # + # Obtain the stack information + # ECX: start of range + # EDX: end of range + # + movl 0x8(%esp), %ecx + movl 0xC(%esp), %edx + + # + # Platform init + # + pushal + pushl %edx + pushl %ecx + pushl %eax + call ASM_PFX(PlatformInit) + popl %eax + popl %eax + popl %eax + popal + + # + # Set stack top pointer + # + movl %edx, %esp + + # + # Push the hob list pointer + # + pushl %eax + + # + # Save the value + # ECX: start of range + # EDX: end of range + # + movl %esp, %ebp + pushl %ecx + pushl %edx + + # + # Push processor count to stack first, then BIST status (AP then BSP) + # + movl $1, %eax + cpuid + shr $16, %ebx + andl $0x000000FF, %ebx + cmp $1, %bl + jae PushProcessorCount + + # + # Some processors report 0 logical processors. Effectively 0 = 1. + # So we fix up the processor count + # + inc %ebx + +PushProcessorCount: + pushl %ebx + + # + # We need to implement a long-term solution for BIST capture. For now, we just copy BSP BIST + # for all processor threads + # + xorl %ecx, %ecx + movb %bl, %cl +PushBist: + movd %mm0, %eax + pushl %eax + loop PushBist + + # Save Time-Stamp Counter + movd %mm5, %eax + pushl %eax + + movd %mm6, %eax + pushl %eax + + # + # Pass entry point of the PEI core + # + movl $0xFFFFFFE0, %edi + pushl %ds:(%edi) + + # + # Pass BFV into the PEI Core + # + movl $0xFFFFFFFC, %edi + pushl %ds:(%edi) + + # + # Pass stack size into the PEI Core + # + movl -4(%ebp), %ecx + movl -8(%ebp), %edx + pushl %ecx # RamBase + + subl %ecx, %edx + pushl %edx # RamSize + + # + # Pass Control into the PEI Core + # + call ASM_PFX(SecStartup) diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/PeiCoreEntry.asm b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/PeiCoreEntry.asm new file mode 100644 index 0000000000..d4703dc8ba --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/PeiCoreEntry.asm @@ -0,0 +1,134 @@ +;; @file +; Find and call SecStartup +; +; 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. +; +;; + + +.686p +.xmm +.model flat, c +.code + +EXTRN SecStartup:NEAR +EXTRN PlatformInit:NEAR + +CallPeiCoreEntryPoint PROC PUBLIC + ; + ; Obtain the hob list pointer + ; + mov eax, [esp+4] + ; + ; Obtain the stack information + ; ECX: start of range + ; EDX: end of range + ; + mov ecx, [esp+8] + mov edx, [esp+0Ch] + + ; + ; Platform init + ; + pushad + push edx + push ecx + push eax + call PlatformInit + pop eax + pop eax + pop eax + popad + + ; + ; Set stack top pointer + ; + mov esp, edx + + ; + ; Push the hob list pointer + ; + push eax + + ; + ; Save the value + ; ECX: start of range + ; EDX: end of range + ; + mov ebp, esp + push ecx + push edx + + ; + ; Push processor count to stack first, then BIST status (AP then BSP) + ; + mov eax, 1 + cpuid + shr ebx, 16 + and ebx, 0000000FFh + cmp bl, 1 + jae PushProcessorCount + + ; + ; Some processors report 0 logical processors. Effectively 0 = 1. + ; So we fix up the processor count + ; + inc ebx + +PushProcessorCount: + push ebx + + ; + ; We need to implement a long-term solution for BIST capture. For now, we just copy BSP BIST + ; for all processor threads + ; + xor ecx, ecx + mov cl, bl +PushBist: + movd eax, mm0 + push eax + loop PushBist + + ; Save Time-Stamp Counter + movd eax, mm5 + push eax + + movd eax, mm6 + push eax + + ; + ; Pass entry point of the PEI core + ; + mov edi, 0FFFFFFE0h + push DWORD PTR ds:[edi] + + ; + ; Pass BFV into the PEI Core + ; + mov edi, 0FFFFFFFCh + push DWORD PTR ds:[edi] + + ; + ; Pass stack size into the PEI Core + ; + mov ecx, [ebp - 4] + mov edx, [ebp - 8] + push ecx ; RamBase + + sub edx, ecx + push edx ; RamSize + + ; + ; Pass Control into the PEI Core + ; + call SecStartup +CallPeiCoreEntryPoint ENDP + +END diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/SecEntry.S b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/SecEntry.S new file mode 100644 index 0000000000..5610a16908 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/SecEntry.S @@ -0,0 +1,348 @@ +## @file +# This is the code that goes from real-mode to protected mode. +# It consumes the reset vector, calls TempRamInit API from FSP binary. +# +# 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 "Fsp.h" + +ASM_GLOBAL ASM_PFX(_gPcd_FixedAtBuild_PcdFsptBaseAddress) +ASM_GLOBAL ASM_PFX(_gPcd_FixedAtBuild_PcdFspTemporaryRamSize) + +ASM_GLOBAL ASM_PFX(_TEXT_REALMODE) +ASM_PFX(_TEXT_REALMODE): +#---------------------------------------------------------------------------- +# +# Procedure: _ModuleEntryPoint +# +# Input: None +# +# Output: None +# +# Destroys: Assume all registers +# +# Description: +# +# Transition to non-paged flat-model protected mode from a +# hard-coded GDT that provides exactly two descriptors. +# This is a bare bones transition to protected mode only +# used for a while in PEI and possibly DXE. +# +# After enabling protected mode, a far jump is executed to +# transfer to PEI using the newly loaded GDT. +# +# Return: None +# +# MMX Usage: +# MM0 = BIST State +# MM5 = Save time-stamp counter value high32bit +# MM6 = Save time-stamp counter value low32bit. +# +#---------------------------------------------------------------------------- + +ASM_GLOBAL ASM_PFX(_ModuleEntryPoint) +ASM_PFX(_ModuleEntryPoint): + fninit # clear any pending Floating point exceptions + # + # Store the BIST value in mm0 + # + movd %eax, %mm0 + cli + + # + # Check INIT# is asserted by port 0xCF9 + # + mov $0x0CF9, %dx + in %dx, %al + cmp $0x04, %al + jnz NotWarmStart + + # + # @note Issue warm reset, since if CPU only reset is issued not all MSRs are restored to their defaults + # + movw $0x0CF9, %dx + movb $0x06, %al + out %al, %dx + + # + # Save time-stamp counter value + # rdtsc load 64bit time-stamp counter to EDX:EAX + # + rdtsc + movd %edx, %mm5 + movd %ecx, %mm6 + + # + # Load the GDT table in GdtDesc + # + movl $GdtDesc, %esi + .byte 0x66 + lgdt %cs:(%si) + + # + # Transition to 16 bit protected mode + # + movl %cr0, %eax # Get control register 0 + orl $0x00000003, %eax # Set PE bit (bit #0) & MP bit (bit #1) + movl %eax, %cr0 # Activate protected mode + + movl %cr4, %eax # Get control register 4 + orl $0x00000600, %eax # Set OSFXSR bit (bit #9) & OSXMMEXCPT bit (bit #10) + movl %eax, %cr4 + + # + # Now we're in 16 bit protected mode + # Set up the selectors for 32 bit protected mode entry + # + mov $SYS_DATA_SEL, %ax + mov %ax, %ds + mov %ax, %es + mov %ax, %fs + mov %ax, %gs + mov %ax, %ss + + # + # Transition to Flat 32 bit protected mode + # The jump to a far pointer causes the transition to 32 bit mode + # + movl $ProtectedModeEntryLinearAddress, %esi + jmp *%cs:(%si) + +ASM_GLOBAL ASM_PFX(_TEXT_PROTECTED_MODE) +ASM_PFX(_TEXT_PROTECTED_MODE): + +#---------------------------------------------------------------------------- +# +# Procedure: ProtectedModeEntryPoint +# +# Input: None +# +# Output: None +# +# Destroys: Assume all registers +# +# Description: +# +# This function handles: +# Call two basic APIs from FSP binary +# Initializes stack with some early data (BIST, PEI entry, etc) +# +# Return: None +# +#---------------------------------------------------------------------------- + +ASM_GLOBAL ASM_PFX(ProtectedModeEntryPoint) +ASM_PFX(ProtectedModeEntryPoint): + + # Find the fsp info header + movl PcdGet32(PcdFsptBaseAddress), %edi + + movl $FVH_SIGINATURE_OFFSET(%edi), %eax + cmp $FVH_SIGINATURE_VALID_VALUE, %eax + jnz FspHeaderNotFound + + xorl %eax, %eax + movw $FVH_EXTHEADER_OFFSET_OFFSET(%edi), %ax + cmp $0x00, %ax + jnz FspFvExtHeaderExist + + xorl %eax, %eax + movw $FVH_HEADER_LENGTH_OFFSET(%edi), %ax # Bypass Fv Header + addl %eax, %edi + jmp FspCheckFfsHeader + +FspFvExtHeaderExist: + addl %eax, %edi + movl $FVH_EXTHEADER_SIZE_OFFSET(%edi), %eax # Bypass Ext Fv Header + addl %eax, %edi + + # Round up to 8 byte alignment + movl %edi, %eax + andb $0x07, %al + jz FspCheckFfsHeader + + and $0xFFFFFFF8, %edi + add $0x08, %edi + +FspCheckFfsHeader: + # Check the ffs guid + movl (%edi), %eax + cmp $FSP_HEADER_GUID_DWORD1, %eax + jnz FspHeaderNotFound + + movl 0x4(%edi), %eax + cmp $FSP_HEADER_GUID_DWORD2, %eax + jnz FspHeaderNotFound + + movl 0x08(%edi), %eax + cmp $FSP_HEADER_GUID_DWORD3, %eax + jnz FspHeaderNotFound + + movl 0x0c(%edi), %eax + cmp $FSP_HEADER_GUID_DWORD4, %eax + jnz FspHeaderNotFound + + add $FFS_HEADER_SIZE_VALUE, %edi # Bypass the ffs header + + # Check the section type as raw section + movb $SECTION_HEADER_TYPE_OFFSET(%edi), %al + cmp $0x19, %al + jnz FspHeaderNotFound + + addl $RAW_SECTION_HEADER_SIZE_VALUE, %edi # Bypass the section header + jmp FspHeaderFound + +FspHeaderNotFound: + jmp . + +FspHeaderFound: + # Get the fsp TempRamInit Api address + movl $FSP_HEADER_IMAGEBASE_OFFSET(%edi), %eax + addl $FSP_HEADER_TEMPRAMINIT_OFFSET(%edi), %eax + + # Setup the hardcode stack + movl $TempRamInitStack, %esp + + # Call the fsp TempRamInit Api + jmp *%eax + +TempRamInitDone: + cmp $0x8000000E, %eax #Check if EFI_NOT_FOUND returned. Error code for Microcode Update not found. + je CallSecFspInit #If microcode not found, don't hang, but continue. + + cmp $0x0, %eax + jnz FspApiFailed + + # ECX: start of range + # EDX: end of range +CallSecFspInit: + subl PcdGet32 (PcdFspTemporaryRamSize), %edx # TemporaryRam for FSP + xorl %eax, %eax + movl %edx, %esp + + # Align the stack at DWORD + addl $3, %esp + andl $0xFFFFFFFC, %esp + + pushl %edx + pushl %ecx + pushl %eax # zero - no hob list yet + call ASM_PFX(CallPeiCoreEntryPoint) + +FspApiFailed: + jmp . + +.align 0x10 +TempRamInitStack: + .long TempRamInitDone + .long FsptUpdDataPtr + +# +# ROM-based Global-Descriptor Table for the Tiano PEI Phase +# +.align 0x10 + +# +# GDT[0]: 0x00: Null entry, never used. +# +.equ NULL_SEL, . - GdtBase # Selector [0] +GdtBase: +BootGdtTable: + .long 0 + .long 0 + +# +# Linear data segment descriptor +# +.equ LINEAR_SEL, . - GdtBase # Selector [0x8] + .word 0xFFFF # limit 0xFFFFF + .word 0 # base 0 + .byte 0 + .byte 0x92 # present, ring 0, data, expand-up, writable + .byte 0xCF # page-granular, 32-bit + .byte 0 + +# +# Linear code segment descriptor +# +.equ LINEAR_CODE_SEL, . - GdtBase # Selector [0x10] + .word 0xFFFF # limit 0xFFFFF + .word 0 # base 0 + .byte 0 + .byte 0x9B # present, ring 0, data, expand-up, not-writable + .byte 0xCF # page-granular, 32-bit + .byte 0 +# +# System data segment descriptor +# +.equ SYS_DATA_SEL, . - GdtBase # Selector [0x18] + .word 0xFFFF # limit 0xFFFFF + .word 0 # base 0 + .byte 0 + .byte 0x93 # present, ring 0, data, expand-up, not-writable + .byte 0xCF # page-granular, 32-bit + .byte 0 + +# +# System code segment descriptor +# +.equ SYS_CODE_SEL, . - GdtBase # Selector [0x20] + .word 0xFFFF # limit 0xFFFFF + .word 0 # base 0 + .byte 0 + .byte 0x9A # present, ring 0, data, expand-up, writable + .byte 0xCF # page-granular, 32-bit + .byte 0 +# +# Spare segment descriptor +# +.equ SYS16_CODE_SEL, . - GdtBase # Selector [0x28] + .word 0xFFFF # limit 0xFFFFF + .word 0 # base 0 + .byte 0x0E # Changed from F000 to E000. + .byte 0x9B # present, ring 0, code, expand-up, writable + .byte 0x00 # byte-granular, 16-bit + .byte 0 +# +# Spare segment descriptor +# +.equ SYS16_DATA_SEL, . - GdtBase # Selector [0x30] + .word 0xFFFF # limit 0xFFFF + .word 0 # base 0 + .byte 0 + .byte 0x93 # present, ring 0, data, expand-up, not-writable + .byte 0x00 # byte-granular, 16-bit + .byte 0 + +# +# Spare segment descriptor +# +.equ SPARE5_SEL, . - GdtBase # Selector [0x38] + .word 0 # limit 0 + .word 0 # base 0 + .byte 0 + .byte 0 # present, ring 0, data, expand-up, writable + .byte 0 # page-granular, 32-bit + .byte 0 +.equ GDT_SIZE, . - BootGdtTable # Size, in bytes + +# +# GDT Descriptor +# +GdtDesc: # GDT descriptor + .word GDT_SIZE - 1 # GDT limit + .long BootGdtTable # GDT base address + +ASM_PFX(ProtectedModeEntryLinearAddress): +ProtectedModeEntryLinearOffset: + .long ProtectedModeEntryPoint # Offset of our 32 bit code + .word LINEAR_CODE_SEL diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/SecEntry.asm b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/SecEntry.asm new file mode 100644 index 0000000000..7b82cbaa0e --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/SecEntry.asm @@ -0,0 +1,375 @@ +;; @file +; This is the code that goes from real-mode to protected mode. +; It consumes the reset vector, calls TempRamInit API from FSP binary. +; +; 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 "Fsp.h" + +.686p +.xmm +.model small, c + +EXTRN CallPeiCoreEntryPoint:NEAR +EXTRN BoardBeforeTempRamInit:NEAR +EXTRN FsptUpdDataPtr:FAR + +; Pcds +EXTRN PcdGet32 (PcdFsptBaseAddress):DWORD +EXTRN PcdGet32(PcdFspTemporaryRamSize):DWORD + +_TEXT_REALMODE SEGMENT PARA PUBLIC USE16 'CODE' + ASSUME CS:_TEXT_REALMODE, DS:_TEXT_REALMODE + +;---------------------------------------------------------------------------- +; +; Procedure: _ModuleEntryPoint +; +; Input: None +; +; Output: None +; +; Destroys: Assume all registers +; +; Description: +; +; Transition to non-paged flat-model protected mode from a +; hard-coded GDT that provides exactly two descriptors. +; This is a bare bones transition to protected mode only +; used for a while in PEI and possibly DXE. +; +; After enabling protected mode, a far jump is executed to +; transfer to PEI using the newly loaded GDT. +; +; Return: None +; +; MMX Usage: +; MM0 = BIST State +; MM5 = Save time-stamp counter value high32bit +; MM6 = Save time-stamp counter value low32bit. +; +;---------------------------------------------------------------------------- + +align 4 +_ModuleEntryPoint PROC NEAR C PUBLIC + fninit ; clear any pending Floating point exceptions + ; + ; Store the BIST value in mm0 + ; + movd mm0, eax + cli + + ; + ; Check INIT# is asserted by port 0xCF9 + ; + mov dx, 0CF9h + in al, dx + cmp al, 04h + jnz NotWarmStart + + ; + ; @note Issue warm reset, since if CPU only reset is issued not all MSRs are restored to their defaults + ; + mov dx, 0CF9h + mov al, 06h + out dx, al + +NotWarmStart: + + ; + ; Save time-stamp counter value + ; rdtsc load 64bit time-stamp counter to EDX:EAX + ; + rdtsc + movd mm5, edx + movd mm6, eax + + ; + ; Load the GDT table in GdtDesc + ; + mov esi, OFFSET GdtDesc + DB 66h + lgdt fword ptr cs:[si] + + ; + ; Transition to 16 bit protected mode + ; + mov eax, cr0 ; Get control register 0 + or eax, 00000003h ; Set PE bit (bit #0) & MP bit (bit #1) + mov cr0, eax ; Activate protected mode + + mov eax, cr4 ; Get control register 4 + or eax, 00000600h ; Set OSFXSR bit (bit #9) & OSXMMEXCPT bit (bit #10) + mov cr4, eax + + ; + ; Now we're in 16 bit protected mode + ; Set up the selectors for 32 bit protected mode entry + ; + mov ax, SYS_DATA_SEL + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov ss, ax + + ; + ; Transition to Flat 32 bit protected mode + ; The jump to a far pointer causes the transition to 32 bit mode + ; + mov esi, offset ProtectedModeEntryLinearAddress + jmp fword ptr cs:[si] + +_ModuleEntryPoint ENDP +_TEXT_REALMODE ENDS + +_TEXT_PROTECTED_MODE SEGMENT PARA PUBLIC USE32 'CODE' + ASSUME CS:_TEXT_PROTECTED_MODE, DS:_TEXT_PROTECTED_MODE + +;---------------------------------------------------------------------------- +; +; Procedure: ProtectedModeEntryPoint +; +; Input: None +; +; Output: None +; +; Destroys: Assume all registers +; +; Description: +; +; This function handles: +; Call two basic APIs from FSP binary +; Initializes stack with some early data (BIST, PEI entry, etc) +; +; Return: None +; +;---------------------------------------------------------------------------- + +align 4 +ProtectedModeEntryPoint PROC NEAR PUBLIC + + ; + ; Early board hooks + ; + mov esp, BoardBeforeTempRamInitRet + jmp BoardBeforeTempRamInit + +BoardBeforeTempRamInitRet: + + ; Find the fsp info header + mov edi, PcdGet32 (PcdFsptBaseAddress) + + mov eax, dword ptr [edi + FVH_SIGINATURE_OFFSET] + cmp eax, FVH_SIGINATURE_VALID_VALUE + jnz FspHeaderNotFound + + xor eax, eax + mov ax, word ptr [edi + FVH_EXTHEADER_OFFSET_OFFSET] + cmp ax, 0 + jnz FspFvExtHeaderExist + + xor eax, eax + mov ax, word ptr [edi + FVH_HEADER_LENGTH_OFFSET] ; Bypass Fv Header + add edi, eax + jmp FspCheckFfsHeader + +FspFvExtHeaderExist: + add edi, eax + mov eax, dword ptr [edi + FVH_EXTHEADER_SIZE_OFFSET] ; Bypass Ext Fv Header + add edi, eax + + ; Round up to 8 byte alignment + mov eax, edi + and al, 07h + jz FspCheckFfsHeader + + and edi, 0FFFFFFF8h + add edi, 08h + +FspCheckFfsHeader: + ; Check the ffs guid + mov eax, dword ptr [edi] + cmp eax, FSP_HEADER_GUID_DWORD1 + jnz FspHeaderNotFound + + mov eax, dword ptr [edi + 4] + cmp eax, FSP_HEADER_GUID_DWORD2 + jnz FspHeaderNotFound + + mov eax, dword ptr [edi + 8] + cmp eax, FSP_HEADER_GUID_DWORD3 + jnz FspHeaderNotFound + + mov eax, dword ptr [edi + 0Ch] + cmp eax, FSP_HEADER_GUID_DWORD4 + jnz FspHeaderNotFound + + add edi, FFS_HEADER_SIZE_VALUE ; Bypass the ffs header + + ; Check the section type as raw section + mov al, byte ptr [edi + SECTION_HEADER_TYPE_OFFSET] + cmp al, 019h + jnz FspHeaderNotFound + + add edi, RAW_SECTION_HEADER_SIZE_VALUE ; Bypass the section header + jmp FspHeaderFound + +FspHeaderNotFound: + jmp $ + +FspHeaderFound: + ; Get the fsp TempRamInit Api address + mov eax, dword ptr [edi + FSP_HEADER_IMAGEBASE_OFFSET] + add eax, dword ptr [edi + FSP_HEADER_TEMPRAMINIT_OFFSET] + + ; Setup the hardcode stack + mov esp, OFFSET TempRamInitStack + + ; Call the fsp TempRamInit Api + jmp eax + +TempRamInitDone: + cmp eax, 8000000Eh ;Check if EFI_NOT_FOUND returned. Error code for Microcode Update not found. + je CallSecFspInit ;If microcode not found, don't hang, but continue. + + cmp eax, 0 ;Check if EFI_SUCCESS retuned. + jnz FspApiFailed + + ; ECX: start of range + ; EDX: end of range +CallSecFspInit: + sub edx, PcdGet32 (PcdFspTemporaryRamSize) ; TemporaryRam for FSP + xor eax, eax + mov esp, edx + + ; Align the stack at DWORD + add esp, 3 + and esp, 0FFFFFFFCh + + push edx + push ecx + push eax ; zero - no hob list yet + call CallPeiCoreEntryPoint + +FspApiFailed: + jmp $ + +align 10h +TempRamInitStack: + DD OFFSET TempRamInitDone + DD OFFSET FsptUpdDataPtr ; TempRamInitParams + +ProtectedModeEntryPoint ENDP + +; +; ROM-based Global-Descriptor Table for the Tiano PEI Phase +; +align 16 +PUBLIC BootGdtTable + +; +; GDT[0]: 0x00: Null entry, never used. +; +NULL_SEL EQU $ - GDT_BASE ; Selector [0] +GDT_BASE: +BootGdtTable DD 0 + DD 0 +; +; Linear data segment descriptor +; +LINEAR_SEL EQU $ - GDT_BASE ; Selector [0x8] + DW 0FFFFh ; limit 0xFFFFF + DW 0 ; base 0 + DB 0 + DB 092h ; present, ring 0, data, expand-up, writable + DB 0CFh ; page-granular, 32-bit + DB 0 +; +; Linear code segment descriptor +; +LINEAR_CODE_SEL EQU $ - GDT_BASE ; Selector [0x10] + DW 0FFFFh ; limit 0xFFFFF + DW 0 ; base 0 + DB 0 + DB 09Bh ; present, ring 0, data, expand-up, not-writable + DB 0CFh ; page-granular, 32-bit + DB 0 +; +; System data segment descriptor +; +SYS_DATA_SEL EQU $ - GDT_BASE ; Selector [0x18] + DW 0FFFFh ; limit 0xFFFFF + DW 0 ; base 0 + DB 0 + DB 093h ; present, ring 0, data, expand-up, not-writable + DB 0CFh ; page-granular, 32-bit + DB 0 + +; +; System code segment descriptor +; +SYS_CODE_SEL EQU $ - GDT_BASE ; Selector [0x20] + DW 0FFFFh ; limit 0xFFFFF + DW 0 ; base 0 + DB 0 + DB 09Ah ; present, ring 0, data, expand-up, writable + DB 0CFh ; page-granular, 32-bit + DB 0 +; +; Spare segment descriptor +; +SYS16_CODE_SEL EQU $ - GDT_BASE ; Selector [0x28] + DW 0FFFFh ; limit 0xFFFFF + DW 0 ; base 0 + DB 0Eh ; Changed from F000 to E000. + DB 09Bh ; present, ring 0, code, expand-up, writable + DB 00h ; byte-granular, 16-bit + DB 0 +; +; Spare segment descriptor +; +SYS16_DATA_SEL EQU $ - GDT_BASE ; Selector [0x30] + DW 0FFFFh ; limit 0xFFFF + DW 0 ; base 0 + DB 0 + DB 093h ; present, ring 0, data, expand-up, not-writable + DB 00h ; byte-granular, 16-bit + DB 0 + +; +; Spare segment descriptor +; +SPARE5_SEL EQU $ - GDT_BASE ; Selector [0x38] + DW 0 ; limit 0 + DW 0 ; base 0 + DB 0 + DB 0 ; present, ring 0, data, expand-up, writable + DB 0 ; page-granular, 32-bit + DB 0 +GDT_SIZE EQU $ - BootGdtTable ; Size, in bytes + +; +; GDT Descriptor +; +GdtDesc: ; GDT descriptor + DW GDT_SIZE - 1 ; GDT limit + DD OFFSET BootGdtTable ; GDT base address + + +ProtectedModeEntryLinearAddress LABEL FWORD +ProtectedModeEntryLinearOffset LABEL DWORD + DD OFFSET ProtectedModeEntryPoint ; Offset of our 32 bit code + DW LINEAR_CODE_SEL + +_TEXT_PROTECTED_MODE ENDS +END diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Stack.S b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Stack.S new file mode 100644 index 0000000000..e0eb80ad9a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Stack.S @@ -0,0 +1,73 @@ +## @file +# Switch the stack from temporary memory to permenent memory. +# +# 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. +# +## + +#------------------------------------------------------------------------------ +# VOID +# EFIAPI +# SecSwitchStack ( +# UINT32 TemporaryMemoryBase, +# UINT32 PermanentMemoryBase +# ) +#------------------------------------------------------------------------------ +ASM_GLOBAL ASM_PFX (SecSwitchStack) +ASM_PFX(SecSwitchStack): + # + # Save standard registers so they can be used to change stack + # + pushl %eax + pushl %ebx + pushl %ecx + pushl %edx + + # + # !!CAUTION!! this function address's is pushed into stack after + # migration of whole temporary memory, so need save it to permanent + # memory at first! + # + movl 20(%esp), %ebx # Save the first parameter + movl 24(%esp), %ecx # Save the second parameter + + # + # Save this function's return address into permanent memory at first. + # Then, Fixup the esp point to permanent memory + # + movl %esp, %eax + subl %ebx, %eax + addl %ecx, %eax + movl 0(%esp), %edx # copy pushed register's value to permanent memory + movl %edx, 0(%eax) + movl 4(%esp), %edx + movl %edx, 4(%eax) + movl 8(%esp), %edx + movl %edx, 8(%eax) + movl 12(%esp), %edx + movl %edx, 12(%eax) + movl 16(%esp), %edx # Update this function's return address into permanent memory + movl %edx, 16(%eax) + movl %eax, %esp # From now, esp is pointed to permanent memory + + # + # Fixup the ebp point to permanent memory + # + movl %ebp, %eax + subl %ebx, %eax + addl %ecx, %eax + movl %eax, %ebp # From now, ebp is pointed to permanent memory + + popl %edx + popl %ecx + popl %ebx + popl %eax + ret + diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Stack.asm b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Stack.asm new file mode 100644 index 0000000000..27ae218e63 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/Ia32/Stack.asm @@ -0,0 +1,79 @@ +;; @file +; Switch the stack from temporary memory to permenent memory. +; +; 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. +; +;; + + .586p + .model flat,C + .code + +;------------------------------------------------------------------------------ +; VOID +; EFIAPI +; SecSwitchStack ( +; UINT32 TemporaryMemoryBase, +; UINT32 PermanentMemoryBase +; ); +;------------------------------------------------------------------------------ +SecSwitchStack PROC + ; + ; Save three register: eax, ebx, ecx + ; + push eax + push ebx + push ecx + push edx + + ; + ; !!CAUTION!! this function address's is pushed into stack after + ; migration of whole temporary memory, so need save it to permanent + ; memory at first! + ; + + mov ebx, [esp + 20] ; Save the first parameter + mov ecx, [esp + 24] ; Save the second parameter + + ; + ; Save this function's return address into permanent memory at first. + ; Then, Fixup the esp point to permanent memory + ; + mov eax, esp + sub eax, ebx + add eax, ecx + mov edx, dword ptr [esp] ; copy pushed register's value to permanent memory + mov dword ptr [eax], edx + mov edx, dword ptr [esp + 4] + mov dword ptr [eax + 4], edx + mov edx, dword ptr [esp + 8] + mov dword ptr [eax + 8], edx + mov edx, dword ptr [esp + 12] + mov dword ptr [eax + 12], edx + mov edx, dword ptr [esp + 16] ; Update this function's return address into permanent memory + mov dword ptr [eax + 16], edx + mov esp, eax ; From now, esp is pointed to permanent memory + + ; + ; Fixup the ebp point to permanent memory + ; + mov eax, ebp + sub eax, ebx + add eax, ecx + mov ebp, eax ; From now, ebp is pointed to permanent memory + + pop edx + pop ecx + pop ebx + pop eax + ret +SecSwitchStack ENDP + + END diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/PlatformInit.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/PlatformInit.c new file mode 100644 index 0000000000..ac1ebcebae --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/PlatformInit.c @@ -0,0 +1,51 @@ +/** @file + Provide platform init function. + +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 + +/** + Platform initialization. + + @param[in] FspHobList HobList produced by FSP. + @param[in] StartOfRange Start of temporary RAM. + @param[in] EndOfRange End of temporary RAM. +**/ +VOID +EFIAPI +PlatformInit ( + IN VOID *FspHobList, + IN VOID *StartOfRange, + IN VOID *EndOfRange + ) +{ + // + // Platform initialization + // Enable Serial port here + // + SerialPortInitialize (); + + DEBUG ((DEBUG_INFO, "PrintPeiCoreEntryPointParam in PlatformInit\n")); + DEBUG ((DEBUG_INFO, "FspHobList - 0x%x\n", FspHobList)); + DEBUG ((DEBUG_INFO, "StartOfRange - 0x%x\n", StartOfRange)); + DEBUG ((DEBUG_INFO, "EndOfRange - 0x%x\n", EndOfRange)); + + BoardAfterTempRamInit (); + + TestPointTempMemoryInitDone (StartOfRange, EndOfRange); +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf new file mode 100644 index 0000000000..84bfef1016 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf @@ -0,0 +1,103 @@ +## @file +# Provide FSP wrapper platform sec related function. +# +# 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 which 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. +# +## + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SecFspWrapperPlatformSecLib + FILE_GUID = 4E1C4F95-90EA-47de-9ACC-B8920189A1F5 + MODULE_TYPE = SEC + VERSION_STRING = 1.0 + LIBRARY_CLASS = PlatformSecLib + + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +################################################################################ +# +# Sources Section - list of files that are required for the build to succeed. +# +################################################################################ + +[Sources] + FspWrapperPlatformSecLib.c + SecRamInitData.c + SecPlatformInformation.c + SecGetPerformance.c + SecTempRamDone.c + PlatformInit.c + +[Sources.IA32] + Ia32/SecEntry.asm + Ia32/PeiCoreEntry.asm + Ia32/Stack.asm + Ia32/Fsp.h + Ia32/SecEntry.S + Ia32/PeiCoreEntry.S + Ia32/Stack.S + +################################################################################ +# +# Package Dependency Section - list of Package files that are required for +# this module. +# +################################################################################ + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + IntelFsp2Pkg/IntelFsp2Pkg.dec + IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[LibraryClasses] + LocalApicLib + SerialPortLib + FspWrapperPlatformLib + FspWrapperApiLib + BoardInitLib + SecBoardInitLib + TestPointCheckLib + +[Ppis] + gEfiSecPlatformInformationPpiGuid ## CONSUMES + gPeiSecPerformancePpiGuid ## CONSUMES + gTopOfTemporaryRamPpiGuid ## PRODUCES + gEfiPeiFirmwareVolumeInfoPpiGuid ## PRODUCES + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdPeiTemporaryRamStackSize ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFsptBaseAddress ## CONSUMES + gIntelFsp2PkgTokenSpaceGuid.PcdFspTemporaryRamSize ## CONSUMES + +[FixedPcd] + gIntelFsp2WrapperTokenSpaceGuid.PcdCpuMicrocodePatchAddress ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFlashMicrocodeOffset ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFlashCodeCacheAddress ## CONSUMES + gIntelFsp2WrapperTokenSpaceGuid.PcdFlashCodeCacheSize ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery2Base + gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery2Size + gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery3Base + gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery3Size diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecGetPerformance.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecGetPerformance.c new file mode 100644 index 0000000000..7d06b4e985 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecGetPerformance.c @@ -0,0 +1,95 @@ +/** @file + Sample to provide SecGetPerformance function. + +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 + +/** + This interface conveys performance information out of the Security (SEC) phase into PEI. + + This service is published by the SEC phase. The SEC phase handoff has an optional + EFI_PEI_PPI_DESCRIPTOR list as its final argument when control is passed from SEC into the + PEI Foundation. As such, if the platform supports collecting performance data in SEC, + this information is encapsulated into the data structure abstracted by this service. + This information is collected for the boot-strap processor (BSP) on IA-32. + + @param[in] PeiServices The pointer to the PEI Services Table. + @param[in] This The pointer to this instance of the PEI_SEC_PERFORMANCE_PPI. + @param[out] Performance The pointer to performance data collected in SEC phase. + + @retval EFI_SUCCESS The data was successfully returned. + +**/ +EFI_STATUS +EFIAPI +SecGetPerformance ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN PEI_SEC_PERFORMANCE_PPI *This, + OUT FIRMWARE_SEC_PERFORMANCE *Performance + ) +{ + UINT32 Size; + UINT32 Count; + UINT32 TopOfTemporaryRam; + UINT64 Ticker; + VOID *TopOfTemporaryRamPpi; + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "SecGetPerformance\n")); + + Status = (*PeiServices)->LocatePpi ( + PeiServices, + &gTopOfTemporaryRamPpiGuid, + 0, + NULL, + (VOID **) &TopOfTemporaryRamPpi + ); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + // + // |--------------| <- TopOfTemporaryRam - BL + // | List Ptr | + // |--------------| + // | BL RAM Start | + // |--------------| + // | BL RAM End | + // |--------------| + // |Number of BSPs| + // |--------------| + // | BIST | + // |--------------| + // | .... | + // |--------------| + // | TSC[63:32] | + // |--------------| + // | TSC[31:00] | + // |--------------| + // + TopOfTemporaryRam = (UINT32)(UINTN)TopOfTemporaryRamPpi - sizeof(UINT32); + TopOfTemporaryRam -= sizeof(UINT32) * 2; + Count = *(UINT32 *) (UINTN) (TopOfTemporaryRam - sizeof (UINT32)); + Size = Count * sizeof (UINT32); + + Ticker = *(UINT64 *) (UINTN) (TopOfTemporaryRam - sizeof (UINT32) - Size - sizeof (UINT32) * 2); + Performance->ResetEnd = GetTimeInNanoSecond (Ticker); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecPlatformInformation.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecPlatformInformation.c new file mode 100644 index 0000000000..3b8189fadd --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecPlatformInformation.c @@ -0,0 +1,84 @@ +/** @file + Provide SecPlatformInformation function. + +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 + +/** + This interface conveys state information out of the Security (SEC) phase into PEI. + + @param[in] PeiServices Pointer to the PEI Services Table. + @param[in,out] StructureSize Pointer to the variable describing size of the input buffer. + @param[out] PlatformInformationRecord Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD. + + @retval EFI_SUCCESS The data was successfully returned. + @retval EFI_BUFFER_TOO_SMALL The buffer was too small. + +**/ +EFI_STATUS +EFIAPI +SecPlatformInformation ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN OUT UINT64 *StructureSize, + OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord + ) +{ + UINT32 *Bist; + UINT32 Size; + UINT32 Count; + UINT32 TopOfTemporaryRam; + VOID *TopOfTemporaryRamPpi; + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "SecPlatformInformation\n")); + + Status = (*PeiServices)->LocatePpi ( + PeiServices, + &gTopOfTemporaryRamPpiGuid, + 0, + NULL, + (VOID **) &TopOfTemporaryRamPpi + ); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + // + // The entries of BIST information, together with the number of them, + // reside in the bottom of stack, left untouched by normal stack operation. + // This routine copies the BIST information to the buffer pointed by + // PlatformInformationRecord for output. + // + TopOfTemporaryRam = (UINT32)(UINTN)TopOfTemporaryRamPpi - sizeof (UINT32); + TopOfTemporaryRam -= sizeof(UINT32) * 2; + Count = *((UINT32 *)(UINTN) (TopOfTemporaryRam - sizeof (UINT32))); + Size = Count * sizeof (IA32_HANDOFF_STATUS); + + if ((*StructureSize) < (UINT64) Size) { + *StructureSize = Size; + return EFI_BUFFER_TOO_SMALL; + } + + *StructureSize = Size; + Bist = (UINT32 *) (TopOfTemporaryRam - sizeof (UINT32) - Size); + + CopyMem (PlatformInformationRecord, Bist, Size); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecRamInitData.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecRamInitData.c new file mode 100644 index 0000000000..485f198db4 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecRamInitData.c @@ -0,0 +1,42 @@ +/** @file + Provide TempRamInitParams data. + +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 "FsptCoreUpd.h" + +typedef struct { + FSP_UPD_HEADER FspUpdHeader; + FSPT_CORE_UPD FsptCoreUpd; +} FSPT_UPD_CORE_DATA; + +GLOBAL_REMOVE_IF_UNREFERENCED CONST FSPT_UPD_CORE_DATA FsptUpdDataPtr = { + { + 0x4450555F54505346, + 0x00, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + } + }, + { + ((UINT32)FixedPcdGet64 (PcdCpuMicrocodePatchAddress) + FixedPcdGet32 (PcdFlashMicrocodeOffset)), + ((UINT32)FixedPcdGet64 (PcdCpuMicrocodePatchRegionSize) - FixedPcdGet32 (PcdFlashMicrocodeOffset)), + 0, // Set CodeRegionBase as 0, so that caching will be 4GB-(CodeRegionSize > LLCSize ? LLCSize : CodeRegionSize) will be used. + FixedPcdGet32 (PcdFlashCodeCacheSize), + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + } + } +}; + diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecTempRamDone.c b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecTempRamDone.c new file mode 100644 index 0000000000..98bec31013 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecTempRamDone.c @@ -0,0 +1,53 @@ +/** @file + Provide SecTemporaryRamDone function. + +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 + +/** +This interface disables temporary memory in SEC Phase. +**/ +VOID +EFIAPI +SecPlatformDisableTemporaryMemory ( + VOID + ) +{ + EFI_STATUS Status; + VOID *TempRamExitParam; + + DEBUG((DEBUG_INFO, "SecPlatformDisableTemporaryMemory enter\n")); + + Status = BoardInitBeforeTempRamExit (); + ASSERT_EFI_ERROR (Status); + + TempRamExitParam = UpdateTempRamExitParam (); + Status = CallTempRamExit (TempRamExitParam); + DEBUG((DEBUG_INFO, "TempRamExit status: 0x%x\n", Status)); + ASSERT_EFI_ERROR(Status); + + Status = BoardInitAfterTempRamExit (); + ASSERT_EFI_ERROR (Status); + + return ; +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.c b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.c new file mode 100644 index 0000000000..a142206141 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.c @@ -0,0 +1,139 @@ +/** @file + This is the driver that locates the MemoryConfigurationData HOB, if it + exists, and saves the data to nvRAM. + +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 + +/** + This is the standard EFI driver point that detects whether there is a + MemoryConfigurationData HOB and, if so, saves its data to nvRAM. + + @param[in] ImageHandle Handle for the image of this driver + @param[in] SystemTable Pointer to the EFI System Table + + @retval EFI_UNSUPPORTED +**/ +EFI_STATUS +EFIAPI +SaveMemoryConfigEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + VOID *HobList; + EFI_HOB_GUID_TYPE *GuidHob; + VOID *HobData; + VOID *VariableData; + UINTN DataSize; + UINTN BufferSize; + EDKII_VARIABLE_LOCK_PROTOCOL *VariableLock; + + DataSize = 0; + VariableData = NULL; + GuidHob = NULL; + HobList = NULL; + HobData = NULL; + + // + // Get the HOB list. If it is not present, then ASSERT. + // + HobList = GetHobList (); + ASSERT (HobList != NULL); + + // + // Search for the Memory Configuration GUID HOB. If it is not present, then + // there's nothing we can do. It may not exist on the update path. + // + GuidHob = GetNextGuidHob (&gFspNonVolatileStorageHobGuid, HobList); + if (GuidHob != NULL) { + HobData = GET_GUID_HOB_DATA (GuidHob); + DataSize = GET_GUID_HOB_DATA_SIZE(GuidHob); + if (DataSize > 0) { + // + // Use the HOB to save Memory Configuration Data + // + BufferSize = DataSize; + VariableData = AllocatePool (BufferSize); + if (VariableData == NULL) { + return EFI_UNSUPPORTED; + } + Status = gRT->GetVariable ( + L"MemoryConfig", + &gFspNonVolatileStorageHobGuid, + NULL, + &BufferSize, + VariableData + ); + + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (VariableData); + VariableData = AllocatePool (BufferSize); + if (VariableData == NULL) { + return EFI_UNSUPPORTED; + } + + Status = gRT->GetVariable ( + L"MemoryConfig", + &gFspNonVolatileStorageHobGuid, + NULL, + &BufferSize, + VariableData + ); + } + + if ( (EFI_ERROR(Status)) || BufferSize != DataSize || 0 != CompareMem (HobData, VariableData, DataSize)) { + Status = gRT->SetVariable ( + L"MemoryConfig", + &gFspNonVolatileStorageHobGuid, + (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS), + DataSize, + HobData + ); + ASSERT_EFI_ERROR (Status); + + DEBUG((DEBUG_INFO, "Restored Size is 0x%x\n", DataSize)); + } + + // + // Mark MemoryConfig to read-only if the Variable Lock protocol exists + // + Status = gBS->LocateProtocol(&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLock); + if (!EFI_ERROR(Status)) { + Status = VariableLock->RequestToLock(VariableLock, L"MemoryConfig", &gFspNonVolatileStorageHobGuid); + ASSERT_EFI_ERROR(Status); + } + + (gBS->FreePool)(VariableData); + } else { + DEBUG((DEBUG_INFO, "Memory save size is %d\n", DataSize)); + } + } else { + DEBUG((DEBUG_ERROR, "Memory S3 Data HOB was not found\n")); + } + + // + // This driver does not produce any protocol services, so always unload it. + // + return EFI_UNSUPPORTED; +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf new file mode 100644 index 0000000000..03f50cf2c8 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf @@ -0,0 +1,52 @@ +### @file +# Component information file for SaveMemoryConfig module +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = SaveMemoryConfig + FILE_GUID = E0ECBEC9-B193-4351-A488-36A655F22F9F + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + ENTRY_POINT = SaveMemoryConfigEntryPoint + +[LibraryClasses] + UefiDriverEntryPoint + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + HobLib + DebugLib + MemoryAllocationLib + BaseMemoryLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + IntelFsp2Pkg/IntelFsp2Pkg.dec + +[Sources] + SaveMemoryConfig.c + +[Protocols] + gEfiVariableArchProtocolGuid ## CONSUMES + gEfiVariableWriteArchProtocolGuid ## CONSUMES + gEdkiiVariableLockProtocolGuid + +[Guids] + gFspNonVolatileStorageHobGuid ## CONSUMES + +[Depex] + gEfiVariableArchProtocolGuid AND + gEfiVariableWriteArchProtocolGuid AND + gEfiResetArchProtocolGuid \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/ExternalDeviceDmaProtection.c b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/ExternalDeviceDmaProtection.c new file mode 100644 index 0000000000..197813fe66 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/ExternalDeviceDmaProtection.c @@ -0,0 +1,53 @@ +/** @file + This file contains sample for setting external DMA protection bit + in sample IBV HSTI structure. Actual test implementation is not present + in this sample driver. + +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 "HstiIbvPlatformDxe.h" + +/** + This function sets the verified bit for ExternalDeviceDmaProtection. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckExternalDeviceDmaProtection ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + if ((mFeatureImplemented[2] & HSTI_BYTE2_EXTERNAL_DEVICE_DMA_PROTECTION) == 0) { + return ; + } + Result = TRUE; + + DEBUG ((EFI_D_INFO, " External Device DMA Protection \n")); + + // + // ALL PASS + // + if (Result) { + Status = HstiLibSetFeaturesVerified ( + Role, + NULL, + 2, + HSTI_BYTE2_EXTERNAL_DEVICE_DMA_PROTECTION + ); + ASSERT_EFI_ERROR (Status); + } + + + return ; +} diff --git a/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/FirmwareTrustConfigurationCryptoStrength.c b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/FirmwareTrustConfigurationCryptoStrength.c new file mode 100644 index 0000000000..6e2f5f4c10 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/FirmwareTrustConfigurationCryptoStrength.c @@ -0,0 +1,52 @@ +/** @file + This file contains sample test for setting Continuous Crypto strength + bit in sample IBV HSTI structure. Actual test implementation is not present + in this sample driver. + +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 "HstiIbvPlatformDxe.h" + +/** + This function sets the verified bit for FirmwareTrustContinuationCryptoStrength. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckFirmwareTrustContinuationCryptoStrength ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + if ((mFeatureImplemented[2] & HSTI_BYTE2_FIRMWARE_TRUSTED_CONTINUATION_CRYPTO_STRENGTH) == 0) { + return ; + } + + Result = TRUE; + DEBUG ((EFI_D_INFO, " Firmware Trust Continuation Crypto Strength\n")); + + // + // ALL PASS + // + if (Result) { + Status = HstiLibSetFeaturesVerified ( + Role, + NULL, + 2, + HSTI_BYTE2_FIRMWARE_TRUSTED_CONTINUATION_CRYPTO_STRENGTH + ); + ASSERT_EFI_ERROR (Status); + } + + return ; +} diff --git a/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/FirmwareVersionRollbackProtection.c b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/FirmwareVersionRollbackProtection.c new file mode 100644 index 0000000000..a22836c8a5 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/FirmwareVersionRollbackProtection.c @@ -0,0 +1,53 @@ +/** @file + This file contains sample for setting external DMA protection bit + in sample IBV HSTI structure. Actual test implementation is not present + in this sample driver. + +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 "HstiIbvPlatformDxe.h" + +/** + Sets the verified bit for FirmwareVersionRollbackProtection. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckFirmwareVersionRollbackProtection ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + if ((mFeatureImplemented[2] & HSTI_BYTE2_FIRMWARE_VERSION_ROLLBACK_PROTECTION) == 0) { + return ; + } + + Result = TRUE; + + DEBUG ((EFI_D_INFO, " Firmware Version Rollback Protection\n")); + + // + // ALL PASS + // + if (Result) { + Status = HstiLibSetFeaturesVerified ( + Role, + NULL, + 2, + HSTI_BYTE2_FIRMWARE_VERSION_ROLLBACK_PROTECTION + ); + ASSERT_EFI_ERROR (Status); + } + + return ; +} diff --git a/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.c b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.c new file mode 100644 index 0000000000..02af6dbbe7 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.c @@ -0,0 +1,259 @@ +/** @file + This file contains sample DXE driver for publishing IBV HSTI. + This driver does not actually implement the test, but merely + publishes the IBV role HSTI structure indicating all tests pass + +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 "HstiIbvPlatformDxe.h" + +ADAPTER_INFO_PLATFORM_SECURITY_STRUCT mHstiStruct = { + PLATFORM_SECURITY_VERSION_VNEXTCS, + PLATFORM_SECURITY_ROLE_PLATFORM_IBV, + {HSTI_IMPLEMENTATION_ID_PLATFORM}, + HSTI_SECURITY_FEATURE_SIZE, + {0}, // SecurityFeaturesRequired + {0}, // SecurityFeaturesImplemented + {0}, // SecurityFeaturesVerified + 0, +}; + +UINT8 mFeatureImplemented[HSTI_SECURITY_FEATURE_SIZE]; + +/** + Initialize HSTI feature data +**/ +VOID +InitData ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + + ASSERT (PcdGetSize(PcdHstiIbvPlatformFeature) == sizeof(mFeatureImplemented)); + CopyMem (mFeatureImplemented, PcdGetPtr(PcdHstiIbvPlatformFeature), sizeof(mFeatureImplemented)); + + mHstiStruct.Role = Role; + CopyMem (mHstiStruct.SecurityFeaturesImplemented, mFeatureImplemented, sizeof(mFeatureImplemented)); + Status = HstiLibSetTable ( + &mHstiStruct, + sizeof(mHstiStruct) + ); + if (EFI_ERROR (Status)) { + if (Status != EFI_ALREADY_STARTED) { + ASSERT_EFI_ERROR (Status); + } + } +} + +/** + Concatenate error string. + + @param[in] ErrorCodeString - Error Code + @param[in] ErrorCategoryString - Error Category + @param[in] ErrorString - Error Text + + @retval CHAR16 - Concatenated string. +**/ +CHAR16 * +EFIAPI +BuildHstiErrorString ( + IN CHAR16 *ErrorCodeString, + IN CHAR16 *ErrorCategoryString, + IN CHAR16 *ErrorString + ) +{ + UINTN Offset; + UINTN StringSize; + CHAR16 *ErrorStringOut; + + ErrorStringOut = NULL; + Offset = 0; + + StringSize = StrSize (HSTI_ERROR) + StrSize(ErrorCodeString) + StrSize(HSTI_PLATFORM_SECURITY_SPECIFICATION) + StrSize(ErrorCategoryString) + StrSize(ErrorString); + ErrorStringOut = AllocatePool (StringSize); + ASSERT (ErrorStringOut != NULL); + if (ErrorStringOut != NULL) { + CopyMem (ErrorStringOut, HSTI_ERROR, StrSize (HSTI_ERROR)-1); + Offset += StrLen (HSTI_ERROR); + + CopyMem (ErrorStringOut + Offset, ErrorCodeString, StrSize(ErrorCodeString)-1); + Offset += StrLen(ErrorCodeString); + + CopyMem (ErrorStringOut + Offset, HSTI_PLATFORM_SECURITY_SPECIFICATION, StrSize(HSTI_PLATFORM_SECURITY_SPECIFICATION)-1); + Offset += StrLen(HSTI_PLATFORM_SECURITY_SPECIFICATION); + + CopyMem (ErrorStringOut + Offset, ErrorCategoryString, StrSize(ErrorCategoryString)-1); + Offset += StrLen(ErrorCategoryString); + + CopyMem (ErrorStringOut + Offset, ErrorString, StrSize(ErrorString)); + Offset += StrLen(ErrorString); + } + return ErrorStringOut; +} + +/** + Update HSTI feature data +**/ +VOID +UpdateData ( + IN UINT32 Role + ) +{ + DEBUG ((EFI_D_INFO, "2.0 Firmware Trust Continuation Crypto Strength\n")); + CheckFirmwareTrustContinuationCryptoStrength (Role); + + DEBUG ((EFI_D_INFO, "2.1 No Test Key Verification\n")); + CheckNoTestKeyVerification (Role); + + DEBUG ((EFI_D_INFO, "2.2 Firmware Version Rollback Protection\n")); + CheckFirmwareVersionRollbackProtection (Role); + + DEBUG ((EFI_D_INFO, "2.3 SecureBoot Bypass Checking\n")); + CheckSecureBootBypass (Role); + + DEBUG ((EFI_D_INFO, "2.4 External Device DMA Protection\n")); + CheckExternalDeviceDmaProtection (Role); + + DEBUG ((EFI_D_INFO, "2.5 MOR Support\n")); + CheckMorSupport (Role); +} + +/** + Dump HSTI info to serial + + @param[in] HstiData - Pointer to HSTI data +**/ +VOID +DumpHsti ( + IN VOID *HstiData + ) +{ + ADAPTER_INFO_PLATFORM_SECURITY *Hsti; + UINT8 *SecurityFeatures; + CHAR16 *ErrorString; + UINTN Index; + CHAR16 ErrorChar; + + Hsti = HstiData; + DEBUG ((EFI_D_INFO, "HSTI\n")); + DEBUG ((EFI_D_INFO, " Version - 0x%08x\n", Hsti->Version)); + DEBUG ((EFI_D_INFO, " Role - 0x%08x\n", Hsti->Role)); + DEBUG ((EFI_D_INFO, " ImplementationID - %S\n", Hsti->ImplementationID)); + DEBUG ((EFI_D_INFO, " SecurityFeaturesSize - 0x%08x\n", Hsti->SecurityFeaturesSize)); + + SecurityFeatures = (UINT8 *)(Hsti + 1); + DEBUG ((EFI_D_INFO, " SecurityFeaturesRequired - ")); + for (Index = 0; Index < Hsti->SecurityFeaturesSize; Index++) { + DEBUG ((EFI_D_INFO, "%02x ", SecurityFeatures[Index])); + } + DEBUG ((EFI_D_INFO, "\n")); + + SecurityFeatures = (UINT8 *)(SecurityFeatures + Hsti->SecurityFeaturesSize); + DEBUG ((EFI_D_INFO, " SecurityFeaturesImplemented - ")); + for (Index = 0; Index < Hsti->SecurityFeaturesSize; Index++) { + DEBUG ((EFI_D_INFO, "%02x ", SecurityFeatures[Index])); + } + DEBUG ((EFI_D_INFO, "\n")); + + SecurityFeatures = (UINT8 *)(SecurityFeatures + Hsti->SecurityFeaturesSize); + DEBUG ((EFI_D_INFO, " SecurityFeaturesVerified - ")); + for (Index = 0; Index < Hsti->SecurityFeaturesSize; Index++) { + DEBUG ((EFI_D_INFO, "%02x ", SecurityFeatures[Index])); + } + DEBUG ((EFI_D_INFO, "\n")); + + ErrorString = (CHAR16 *)(SecurityFeatures + Hsti->SecurityFeaturesSize); + DEBUG ((EFI_D_INFO, " ErrorString - \"")); + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + for (; ErrorChar != 0;) { + DEBUG ((EFI_D_INFO, "%c", ErrorChar)); + ErrorString++; + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + } + DEBUG ((EFI_D_INFO, "\"\n")); +} + +/** + Retrieve HSTI Table from AIP +**/ +VOID +DumpData ( + IN UINT32 Role + ) +{ + VOID *Hsti; + UINTN HstiSize; + EFI_STATUS Status; + + Status = HstiLibGetTable (Role, NULL, &Hsti, &HstiSize); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "HSTI (Role - 0x%08x) not found!\n", Role)); + return ; + } + + DumpHsti (Hsti); + + FreePool (Hsti); +} + +/** + Handler to gather and publish HSTI results on ReadyToBootEvent + + @param[in] Event Event whose notification function is being invoked + @param[in] Context Pointer to the notification function's context +**/ +VOID +EFIAPI +OnReadyToBoot ( + EFI_EVENT Event, + VOID *Context + ) +{ + UpdateData (PLATFORM_SECURITY_ROLE_PLATFORM_IBV); + DumpData (PLATFORM_SECURITY_ROLE_PLATFORM_IBV); + + if (Event != NULL) { + gBS->CloseEvent (Event); + } +} + +/** + The driver's entry point. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry point. +**/ +EFI_STATUS +EFIAPI +HstiPlatformDxeEntrypoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT Event; + + InitData (PLATFORM_SECURITY_ROLE_PLATFORM_IBV); + + Status = EfiCreateEventReadyToBootEx ( + TPL_NOTIFY, + OnReadyToBoot, + NULL, + &Event + ); + + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.h b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.h new file mode 100644 index 0000000000..1e32229895 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.h @@ -0,0 +1,121 @@ +/** @file + This file contains sample DXE driver definitions for testing + and publishing IBV HSTI + +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. + +**/ + +#ifndef _HSTI_IBV_PLATFORM_DXE_H_ +#define _HSTI_IBV_PLATFORM_DXE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#pragma pack(1) +typedef struct { + UINT32 Version; + UINT32 Role; + CHAR16 ImplementationID[256]; + UINT32 SecurityFeaturesSize; + UINT8 SecurityFeaturesRequired[HSTI_SECURITY_FEATURE_SIZE]; + UINT8 SecurityFeaturesImplemented[HSTI_SECURITY_FEATURE_SIZE]; + UINT8 SecurityFeaturesVerified[HSTI_SECURITY_FEATURE_SIZE]; + CHAR16 End; +} ADAPTER_INFO_PLATFORM_SECURITY_STRUCT; +#pragma pack() + +extern UINT8 mFeatureImplemented[HSTI_SECURITY_FEATURE_SIZE]; + +/** + Concatenate error string. + + @param[in] ErrorCodeString - Error Code + @param[in] ErrorCategoryString - Error Category + @param[in] ErrorString - Error Text + + @retval CHAR16 - Concatenated string. +**/ +CHAR16 * +EFIAPI +BuildHstiErrorString ( + IN CHAR16 *ErrorCodeString, + IN CHAR16 *ErrorCategoryString, + IN CHAR16 *ErrorString + ); + +/** + This function sets the verified bit for FirmwareTrustContinuationCryptoStrength. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckFirmwareTrustContinuationCryptoStrength ( + IN UINT32 Role + ); + +/** + Sets the verified bit for NoTestKeyVerification. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckNoTestKeyVerification ( + IN UINT32 Role + ); + +/** + Sets the verified bit for FirmwareVersionRollbackProtection. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckFirmwareVersionRollbackProtection ( + IN UINT32 Role + ); + +/** + Sets verified bit for SecureBootBypass bit + Actual test implementation is not present in this sample function. +**/ +VOID +CheckSecureBootBypass ( + IN UINT32 Role + ); + +/** + This function sets the verified bit for ExternalDeviceDmaProtection. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckExternalDeviceDmaProtection ( + IN UINT32 Role + ); + +/** + Sets the verified bit for MorSupport. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckMorSupport ( + IN UINT32 Role + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.inf b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.inf new file mode 100644 index 0000000000..1fa93b050d --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.inf @@ -0,0 +1,53 @@ +### @file +# Component description file for Hsti IBV Driver +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = HstiPlatformDxe + FILE_GUID = 00B46EC9-2712-486B-A6A4-E2933581C28B + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = HstiPlatformDxeEntrypoint + +[Sources] + HstiIbvPlatformDxe.c + FirmwareTrustConfigurationCryptoStrength.c + NoTestKeyVerification.c + FirmwareVersionRollbackProtection.c + SecureBootBypass.c + ExternalDeviceDmaProtection.c + MorSupport.c + +[Packages] + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + BaseLib + UefiLib + BaseMemoryLib + MemoryAllocationLib + DebugLib + UefiBootServicesTableLib + HstiLib + +[Pcd] + gPlatformModuleTokenSpaceGuid.PcdHstiIbvPlatformFeature + +[Protocols] + +[Depex] + TRUE diff --git a/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/MorSupport.c b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/MorSupport.c new file mode 100644 index 0000000000..9a1e8a0385 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/MorSupport.c @@ -0,0 +1,54 @@ +/** @file + This file contains sample for setting MOR support bit + in sample IBV HSTI structure. Actual test implementation is not present + in this sample driver. + +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 "HstiIbvPlatformDxe.h" + +/** + Sets the verified bit for MorSupport. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckMorSupport ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + if ((mFeatureImplemented[2] & HSTI_BYTE2_MOR_SUPPORT) == 0) { + return ; + } + + Result = TRUE; + + DEBUG ((EFI_D_INFO, " MOR Strength\n")); + + // + // ALL PASS + // + if (Result) { + Status = HstiLibSetFeaturesVerified ( + Role, + NULL, + 2, + HSTI_BYTE2_MOR_SUPPORT + ); + ASSERT_EFI_ERROR (Status); + } + + + return ; +} diff --git a/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/NoTestKeyVerification.c b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/NoTestKeyVerification.c new file mode 100644 index 0000000000..6f03495572 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/NoTestKeyVerification.c @@ -0,0 +1,55 @@ +/** @file + This file contains sample for setting no test key bit + in sample IBV HSTI structure. Actual test implementation is not present + in this sample driver. + +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 "HstiIbvPlatformDxe.h" + +/** + Sets the verified bit for NoTestKeyVerification. + Actual test implementation is not present in this sample function. +**/ +VOID +CheckNoTestKeyVerification ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + if ((mFeatureImplemented[2] & HSTI_BYTE2_NO_TEST_KEY_VERIFICATION) == 0) { + return ; + } + + Result = TRUE; + DEBUG ((EFI_D_INFO, " No Test Key Verification \n")); + + // + // Get db and check Microsoft Test Key + // + + // + // ALL PASS + // + if (Result) { + Status = HstiLibSetFeaturesVerified ( + Role, + NULL, + 2, + HSTI_BYTE2_NO_TEST_KEY_VERIFICATION + ); + ASSERT_EFI_ERROR (Status); + } + +} diff --git a/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/SecureBootBypass.c b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/SecureBootBypass.c new file mode 100644 index 0000000000..472ec42673 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Hsti/HstiIbvPlatformDxe/SecureBootBypass.c @@ -0,0 +1,51 @@ +/** @file + This file contains sample for setting secureboot bypass bit + in sample IBV HSTI structure. Actual test implementation is not present + in this sample driver. + +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 "HstiIbvPlatformDxe.h" + +/** + Sets verified bit for SecureBootBypass bit + Actual test implementation is not present in this sample function. +**/ +VOID +CheckSecureBootBypass ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + if ((mFeatureImplemented[2] & HSTI_BYTE2_SECUREBOOT_BYPASS_CHECKING) == 0) { + return ; + } + + Result = TRUE; + DEBUG ((EFI_D_INFO, " Secure Boot Bypass\n")); + + // + // ALL PASS + // + if (Result) { + Status = HstiLibSetFeaturesVerified ( + Role, + NULL, + 2, + HSTI_BYTE2_SECUREBOOT_BYPASS_CHECKING + ); + ASSERT_EFI_ERROR (Status); + } + +} diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc new file mode 100644 index 0000000000..6446898102 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc @@ -0,0 +1,142 @@ +## @file +# Platform description. +# +# 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 which 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. +# +## + + # + # Generic EDKII Lib + # + +[LibraryClasses.common] + # + # Entry point + # + PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf + PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf + DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf + SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf + PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf + + # + # Basic + # + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf + + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf + PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + BasePciLibPciExpress|MdePkg/Library/BasePciLibPciExpress/BasePciLibPciExpress.inf +# PciLib|MdePkg/Library/BasePciLibPciExpress/BasePciLibPciExpress.inf + PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf + PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf + CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf + PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf + SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf + # + # UEFI & PI + # + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf + UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + + UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf + PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf + PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf + UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf + + # + # Framework + # + S3BootScriptLib|MdePkg/Library/BaseS3BootScriptLibNull/BaseS3BootScriptLibNull.inf + S3IoLib|MdePkg/Library/BaseS3IoLib/BaseS3IoLib.inf + S3PciLib|MdePkg/Library/BaseS3PciLib/BaseS3PciLib.inf + + # + # Generic Modules + # + UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf + + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf + CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf + + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf + SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf + SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf + SmmCorePlatformHookLib|MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformHookLibNull.inf + IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf + + PostCodeLib|MdePkg/Library/BasePostCodeLibPort80/BasePostCodeLibPort80.inf + + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf + CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf + + # + # CPU + # + MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf + LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf + SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf + + # + # Platform + # + TimerLib|PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf + + # + # Misc + # +!if $(TARGET) == RELEASE + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!else + DebugLib|MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf +!endif + + PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf + + TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf + VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf + PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf + AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf + +!if gPlatformModuleTokenSpaceGuid.PcdUefiSecureBootEnable == TRUE + AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf +!endif + + # + # CryptLib + # + IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf + + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + + Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLibDTpm.inf + Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.inf + Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf + Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeInclude.dsc b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeInclude.dsc new file mode 100644 index 0000000000..38315a4e95 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeInclude.dsc @@ -0,0 +1,142 @@ +## @file +# Platform description. +# +# 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 which 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. +# +## + + + # + # Generic EDKII Driver + # + MdeModulePkg/Core/Dxe/DxeMain.inf { + + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf + } + MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { + + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + + MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf + MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf + + UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf + PcAtChipsetPkg/8259InterruptControllerDxe/8259.inf + MdeModulePkg/Universal/Metronome/Metronome.inf + MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf + PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf + MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf + +!if gPlatformModuleTokenSpaceGuid.PcdBootToShellOnly == FALSE + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf { + + NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf + NULL|MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf + } +!else + MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf +!endif + + MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf + + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf + MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.inf + MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf { + +!if gPlatformModuleTokenSpaceGuid.PcdUefiSecureBootEnable == TRUE + NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf +!endif +!if gPlatformModuleTokenSpaceGuid.PcdTpm2Enable == TRUE + NULL|SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.inf +!endif + } + + MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + + UefiCpuPkg/CpuDxe/CpuDxe.inf + + MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf + PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf + + MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf + MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf + + MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.inf + MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf + MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf + MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf + MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf + MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf + MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf + MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf + MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf + + MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf + MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf + MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf + FatBinPkg/EnhancedFatDxe/Fat.inf + + MdeModulePkg/Universal/Console/GraphicsOutputDxe/GraphicsOutputDxe.inf + MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf + + MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf + MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf + + MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + + MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf + + MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf + MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf + + MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf + + MdeModulePkg/Application/UiApp/UiApp.inf + MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf + +!if gPlatformModuleTokenSpaceGuid.PcdBootToShellOnly == FALSE + MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf + MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf + + MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf + MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf + + UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf + + UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf + MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.inf +!endif + +!if gPlatformModuleTokenSpaceGuid.PcdBootToShellOnly == FALSE + MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf + MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf + MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf + MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf +!endif + +!if gPlatformModuleTokenSpaceGuid.PcdUefiSecureBootEnable == TRUE + SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf +!endif + +!if gPlatformModuleTokenSpaceGuid.PcdTpm2Enable == TRUE + SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf + SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf { + + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } + SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf + SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf +!endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc new file mode 100644 index 0000000000..cd83e72877 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc @@ -0,0 +1,96 @@ +## @file +# Platform description. +# +# 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 which 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. +# +## + + + # + # Generic EDKII Lib + # + + # + # DXE phase common + # +[LibraryClasses.common.DXE_CORE,LibraryClasses.common.DXE_SMM_DRIVER,LibraryClasses.common.SMM_CORE,LibraryClasses.common.DXE_DRIVER,LibraryClasses.common.DXE_RUNTIME_DRIVER,LibraryClasses.common.UEFI_DRIVER,LibraryClasses.common.UEFI_APPLICATION] + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf + ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf + + HstiLib|MdePkg/Library/DxeHstiLib/DxeHstiLib.inf + + LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf + + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf + + MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf + TimerLib|PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf + + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf + +[LibraryClasses.common.DXE_CORE] + HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf + MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + + PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf + +!if $(TARGET) == DEBUG + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!endif + +[LibraryClasses.common.DXE_DRIVER] + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf + +[LibraryClasses.common.DXE_SMM_DRIVER] + SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf + MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf + LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf + SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf + PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf + + SmmCpuPlatformHookLib|UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.inf + + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf + +[LibraryClasses.common.SMM_CORE] + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + MemoryAllocationLib|MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.inf + SmmServicesTableLib|MdeModulePkg/Library/PiSmmCoreSmmServicesTableLib/PiSmmCoreSmmServicesTableLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf + SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf + PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf +!if $(TARGET) == DEBUG + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!endif + +[LibraryClasses.common.DXE_RUNTIME_DRIVER] + ReportStatusCodeLib|MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf + +[LibraryClasses.common.UEFI_DRIVER] + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf + +[LibraryClasses.common.UEFI_APPLICATION] + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc b/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc new file mode 100644 index 0000000000..e2c07aeb3f --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc @@ -0,0 +1,58 @@ +## @file +# Platform description. +# +# 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 which 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. +# +## + + # + # Generic EDKII Driver + # + + # + # FSP wrapper SEC Core + # + UefiCpuPkg/SecCore/SecCore.inf { + + #PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + } + + MdeModulePkg/Core/Pei/PeiMain.inf + + MdeModulePkg/Universal/PCD/Pei/Pcd.inf { + + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf + MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf + + UefiCpuPkg/CpuIoPei/CpuIoPei.inf + + MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf + + MdeModulePkg/Universal/Variable/Pei/VariablePei.inf + + MdeModulePkg/Universal/PcatSingleSegmentPciCfg2Pei/PcatSingleSegmentPciCfg2Pei.inf + + MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf { + + NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf + } + +!if gPlatformModuleTokenSpaceGuid.PcdTpm2Enable == TRUE + SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf + SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { + + NULL|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf + NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.inf + } +!endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc b/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc new file mode 100644 index 0000000000..2ad6983cb6 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc @@ -0,0 +1,56 @@ +## @file +# Platform description. +# +# 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 which 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. +# +## + + # + # Generic EDKII Lib + # + + # + # PEI phase common + # + +[LibraryClasses.common.SEC,LibraryClasses.common.PEI_CORE,LibraryClasses.common.PEIM] + S3BootScriptLib|MdePkg/Library/BaseS3BootScriptLibNull/BaseS3BootScriptLibNull.inf + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf + ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf + LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf + + PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf + TimerLib|PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf + +[LibraryClasses.common.SEC] + ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf +!if $(TARGET) == DEBUG + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!endif + +[LibraryClasses.common.PEI_CORE] + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf +!if $(TARGET) == DEBUG + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!endif + +[LibraryClasses.common.PEIM] + CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf + + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf + + Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.inf + HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.inf + Tcg2PhysicalPresenceLib|SecurityPkg/Library/PeiTcg2PhysicalPresenceLib/PeiTcg2PhysicalPresenceLib.inf diff --git a/Platform/Intel/MinPlatformPkg/Include/Fdf/CoreDxeInclude.fdf b/Platform/Intel/MinPlatformPkg/Include/Fdf/CoreDxeInclude.fdf new file mode 100644 index 0000000000..7aab06f7ad --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Fdf/CoreDxeInclude.fdf @@ -0,0 +1,111 @@ +## @file +# FDF file of Platform. +# +# 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 which 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. +# +## + +INF MdeModulePkg/Core/Dxe/DxeMain.inf + +INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf +INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf +INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf + +INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf +INF PcAtChipsetPkg/8259InterruptControllerDxe/8259.inf +INF MdeModulePkg/Universal/Metronome/Metronome.inf +INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf +INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf +INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf + +!if gPlatformModuleTokenSpaceGuid.PcdBootToShellOnly == FALSE +INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf +INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf +INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf +!else +INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf +!endif + +INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf + +INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +INF MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.inf +INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf +INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + +INF UefiCpuPkg/CpuDxe/CpuDxe.inf + +INF MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf +INF PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf + +INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf +INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf + +INF MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.inf +INF MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf +INF MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf + +INF MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf +INF MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf +INF MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf +INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf +INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf +INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf + +INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf +INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf +INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf +INF FatBinPkg/EnhancedFatDxe/Fat.inf + +INF MdeModulePkg/Universal/Console/GraphicsOutputDxe/GraphicsOutputDxe.inf +INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf + +INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf +INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf + +INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + +INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf + +INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf +INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf + +INF RuleOverride = UI MdeModulePkg/Application/UiApp/UiApp.inf +INF MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf + +!if gPlatformModuleTokenSpaceGuid.PcdBootToShellOnly == FALSE +INF MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf +INF MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf +INF MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf +INF MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf +INF UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +INF UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf +INF MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.inf +!endif + +!if gPlatformModuleTokenSpaceGuid.PcdBootToShellOnly == FALSE +INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf +INF MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf +INF MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf +INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf +!endif + +!if gPlatformModuleTokenSpaceGuid.PcdUefiSecureBootEnable == TRUE +INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf +!endif + +!if gPlatformModuleTokenSpaceGuid.PcdTpm2Enable == TRUE +INF SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf +INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf +INF SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf +INF SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf +!endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiBfvInclude.fdf b/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiBfvInclude.fdf new file mode 100644 index 0000000000..ef9463228a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiBfvInclude.fdf @@ -0,0 +1,18 @@ +## @file +# FDF file of Platform. +# +# 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 which 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. +# +## + +INF UefiCpuPkg/SecCore/SecCore.inf +INF MdeModulePkg/Core/Pei/PeiMain.inf + diff --git a/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiPostMemInclude.fdf b/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiPostMemInclude.fdf new file mode 100644 index 0000000000..013c10146b --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiPostMemInclude.fdf @@ -0,0 +1,14 @@ +## @file +# FDF file of Platform. +# +# 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 which 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. +# +## diff --git a/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiPreMemInclude.fdf b/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiPreMemInclude.fdf new file mode 100644 index 0000000000..3acdcc5269 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePeiPreMemInclude.fdf @@ -0,0 +1,32 @@ +## @file +# FDF file of Platform. +# +# 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 which 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. +# +## + +INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf +INF MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf +INF MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf + +INF UefiCpuPkg/CpuIoPei/CpuIoPei.inf + +INF MdeModulePkg/Universal/PcatSingleSegmentPciCfg2Pei/PcatSingleSegmentPciCfg2Pei.inf +INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf +INF MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf + +INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf + +!if gPlatformModuleTokenSpaceGuid.PcdTpm2Enable == TRUE +INF SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf +INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf +!endif + diff --git a/Platform/Intel/MinPlatformPkg/Include/Fdf/RuleInclude.fdf b/Platform/Intel/MinPlatformPkg/Include/Fdf/RuleInclude.fdf new file mode 100644 index 0000000000..e341829526 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Fdf/RuleInclude.fdf @@ -0,0 +1,303 @@ +## @file +# FDF file of Platform. +# +# 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 which 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. +# +## + +[Rule.Common.SEC] + FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED { + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + PE32 PE32 Align = 16 $(INF_OUTPUT)/$(MODULE_NAME).efi + RAW BIN Align = 16 |.com + } + +[Rule.Common.SEC.BINARY] + FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED { + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + PE32 PE32 Align = 16 $(INF_OUTPUT)/$(MODULE_NAME).efi + RAW BIN Align = 16 |.com + } + +[Rule.Common.PEI_CORE] + FILE PEI_CORE = $(NAMED_GUID) { + PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.PEIM] + FILE PEIM = $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.PEIM.BINARY] + FILE PEIM = $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional |.depex + PE32 PE32 Align = Auto |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.USER_DEFINED.APINIT] + + FILE RAW = $(NAMED_GUID) Fixed Align=4K { + RAW SEC_BIN |.com + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.USER_DEFINED.LEGACY16] + FILE FREEFORM = $(NAMED_GUID) { + RAW BIN |.com + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_CORE] + FILE DXE_CORE = $(NAMED_GUID) { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_DRIVER.BINARY] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional |.depex + PE32 PE32 |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.UEFI_DRIVER] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.UEFI_DRIVER.BINARY] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional |.depex + PE32 PE32 |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_DRIVER] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_DRIVER.BINARY] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional |.depex + PE32 PE32 |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_DRIVER.DRIVER_ACPITABLE] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + RAW ACPI Optional |.acpi + RAW ASL Optional |.aml + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_RUNTIME_DRIVER] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + RAW ACPI Optional |.acpi + RAW ASL Optional |.aml + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_RUNTIME_DRIVER.BINARY] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional |.depex + PE32 PE32 |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_SMM_DRIVER] + FILE SMM = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_SMM_DRIVER.BINARY] + FILE SMM = $(NAMED_GUID) { + SMM_DEPEX SMM_DEPEX Optional |.depex + PE32 PE32 |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.DXE_SMM_DRIVER.DRIVER_ACPITABLE] + FILE SMM = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + RAW ACPI Optional |.acpi + RAW ASL Optional |.aml + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.SMM_CORE] + FILE SMM_CORE = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.UEFI_APPLICATION] + FILE APPLICATION = $(NAMED_GUID) { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.UEFI_APPLICATION.BINARY] + FILE APPLICATION = $(NAMED_GUID) { + PE32 PE32 |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.UEFI_APPLICATION.UI] + FILE APPLICATION = $(NAMED_GUID) { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="Enter Setup" + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.USER_DEFINED] + FILE FREEFORM = $(NAMED_GUID) { + UI STRING="$(MODULE_NAME)" Optional + RAW BIN |.bin + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.USER_DEFINED.ACPITABLE] + FILE FREEFORM = $(NAMED_GUID) { + RAW ACPI Optional |.acpi + RAW ASL Optional |.aml + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +# +# FFS layout for R8 component type +# +[Rule.Common.PE32_PEIM] + FILE PEIM = $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.BS_DRIVER] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.RT_DRIVER] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.APPLICATION] + FILE APPLICATION = $(NAMED_GUID) { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.ACPITABLE] + FILE FREEFORM = $(NAMED_GUID) { + RAW ACPI Optional |.acpi + RAW ASL Optional |.aml + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.PE32_PEIM.Align32K] + FILE PEIM = $(NAMED_GUID) Align=32K { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.PE32_PEIM.Align64K] + FILE PEIM = $(NAMED_GUID) Align=64K { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 Align = Auto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.PE32_PEIM.LzmaCompress] + FILE PEIM = $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + } + +[Rule.Common.PEIM.LzmaCompress] + FILE PEIM = $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + } + +[Rule.Common.PEIM.LzmaCompressBinary] + FILE PEIM = $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional |.depex + COMPRESS PI_STD { + PE32 PE32 |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + } + diff --git a/Platform/Intel/MinPlatformPkg/Include/Guid/SmramMemoryReserve.h b/Platform/Intel/MinPlatformPkg/Include/Guid/SmramMemoryReserve.h new file mode 100644 index 0000000000..04589cf040 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Guid/SmramMemoryReserve.h @@ -0,0 +1,60 @@ +/** @file + Definition of GUIDed HOB for reserving SMRAM regions. + + This file defines: + * the GUID used to identify the GUID HOB for reserving SMRAM regions. + * the data structure of SMRAM descriptor to describe SMRAM candidate regions + * values of state of SMRAM candidate regions + * the GUID specific data structure of HOB for reserving SMRAM regions. + This GUIDed HOB can be used to convey the existence of the T-SEG reservation and H-SEG usage + +Copyright (c) 2007 - 2010, 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. + + @par Revision Reference: + GUIDs defined in SmmCis spec version 0.9. + +**/ + +#ifndef _EFI_SMM_PEI_SMRAM_MEMORY_RESERVE_H_ +#define _EFI_SMM_PEI_SMRAM_MEMORY_RESERVE_H_ + +#define EFI_SMM_PEI_SMRAM_MEMORY_RESERVE \ + { \ + 0x6dadf1d1, 0xd4cc, 0x4910, {0xbb, 0x6e, 0x82, 0xb1, 0xfd, 0x80, 0xff, 0x3d } \ + } + +/** +* GUID specific data structure of HOB for reserving SMRAM regions. +* +* Inconsistent with specification here: +* EFI_HOB_SMRAM_DESCRIPTOR_BLOCK has been changed to EFI_SMRAM_HOB_DESCRIPTOR_BLOCK. +* This inconsistency is kept in code in order for backward compatibility. +**/ +typedef struct { + /// + /// Designates the number of possible regions in the system + /// that can be usable for SMRAM. + /// + /// Inconsistent with specification here: + /// In Framework SMM CIS 0.91 specification, it defines the field type as UINTN. + /// However, HOBs are supposed to be CPU neutral, so UINT32 should be used instead. + /// + UINT32 NumberOfSmmReservedRegions; + /// + /// Used throughout this protocol to describe the candidate + /// regions for SMRAM that are supported by this platform. + /// + EFI_SMRAM_DESCRIPTOR Descriptor[1]; +} EFI_SMRAM_HOB_DESCRIPTOR_BLOCK; + +extern EFI_GUID gEfiSmmPeiSmramMemoryReserveGuid; + +#endif + diff --git a/Platform/Intel/MinPlatformPkg/Include/HstiIbvFeatureBit.h b/Platform/Intel/MinPlatformPkg/Include/HstiIbvFeatureBit.h new file mode 100644 index 0000000000..e833b36559 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/HstiIbvFeatureBit.h @@ -0,0 +1,60 @@ +/** @file + This file contains various definitions for IBV HSTI implementation + including error string definitions + +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. + +**/ + +#ifndef __HSTI_IBV_FEATURE_BIT_H__ +#define __HSTI_IBV_FEATURE_BIT_H__ + +#define HSTI_IMPLEMENTATION_ID_PLATFORM L"Intel MinPlatform" + +#define HSTI_SECURITY_FEATURE_SIZE 3 + +#define HSTI_ERROR L"Error " +#define HSTI_PLATFORM_SECURITY_SPECIFICATION L" Platform Security Specification" + +#define HSTI_FIRMWARE_TRUSTED_CONTINUATION_CRYPTO_STRENGTH L" - Firmware Trust Continuation Crypto Strength - " +#define HSTI_NO_TEST_KEY_VERIFICATION L" - No Test Key Verification - " +#define HSTI_FIRMWARE_VERSION_ROLLBACK_PROTECTION L" - Firmware Version Rollback Protection - " +#define HSTI_SECUREBOOT_BYPASS_CHECKING L" - SecureBoot Bypass Checking - " +#define HSTI_EXTERNAL_DEVICE_DMA_PROTECTION L" - External Device DMA Protection - " +#define HSTI_MOR_SUPPORT L" - MOR Support - " + +#define HSTI_BYTE2_FIRMWARE_TRUSTED_CONTINUATION_CRYPTO_STRENGTH BIT0 +#define HSTI_BYTE2_FIRMWARE_TRUSTED_CONTINUATION_CRYPTO_STRENGTH_ERROR_CODE_1 L"0x00100001" +#define HSTI_BYTE2_FIRMWARE_TRUSTED_CONTINUATION_CRYPTO_STRENGTH_ERROR_STRING_1 L"SHA1\r\n" + +#define HSTI_BYTE2_NO_TEST_KEY_VERIFICATION BIT1 +#define HSTI_BYTE2_NO_TEST_KEY_VERIFICATION_ERROR_CODE_1 L"0x00110001" +#define HSTI_BYTE2_NO_TEST_KEY_VERIFICATION_ERROR_STRING_1 L"fail\r\n" + +#define HSTI_BYTE2_FIRMWARE_VERSION_ROLLBACK_PROTECTION BIT2 +#define HSTI_BYTE2_FIRMWARE_VERSION_ROLLBACK_PROTECTION_ERROR_CODE_1 L"0x00120001" +#define HSTI_BYTE2_FIRMWARE_VERSION_ROLLBACK_PROTECTION_ERROR_STRING_1 L"fail\r\n" + +#define HSTI_BYTE2_SECUREBOOT_BYPASS_CHECKING BIT3 +#define HSTI_BYTE2_SECUREBOOT_BYPASS_CHECKING_ERROR_CODE_1 L"0x00130001" +#define HSTI_BYTE2_SECUREBOOT_BYPASS_CHECKING_ERROR_STRING_1 L"fail\r\n" + + +#define HSTI_BYTE2_EXTERNAL_DEVICE_DMA_PROTECTION BIT4 +#define HSTI_BYTE2_EXTERNAL_DEVICE_DMA_PROTECTION_ERROR_CODE_1 L"0x00140001" +#define HSTI_BYTE2_EXTERNAL_DEVICE_DMA_PROTECTION_ERROR_STRING_1 L"unsupported\r\n" + + +#define HSTI_BYTE2_MOR_SUPPORT BIT5 +#define HSTI_BYTE2_MOR_SUPPORT_ERROR_CODE_1 L"0x00150001" +#define HSTI_BYTE2_MOR_SUPPORT_ERROR_STRING_1 L"unsupported\r\n" + + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/AslUpdateLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/AslUpdateLib.h new file mode 100644 index 0000000000..dc76e33557 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/AslUpdateLib.h @@ -0,0 +1,146 @@ +/** @file + ASL dynamic update library definitions. + This library provides dymanic update to various ASL structures. + There may be different libraries for different environments (PEI, BS, RT, SMM). + Make sure you meet the requirements for the library (protocol dependencies, use + restrictions, etc). + +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. + +**/ + +#ifndef _ASL_UPDATE_LIB_H_ +#define _ASL_UPDATE_LIB_H_ + +// +// Include files +// +#include +#include +#include + +// +// AML parsing definitions +// +#define AML_RESRC_TEMP_END_TAG 0x0079 + +// +// ASL PSS package structure layout +// +#pragma pack (1) +typedef struct { + UINT8 NameOp; // 12h ;First opcode is a NameOp. + UINT8 PackageLead; // 20h ;First opcode is a NameOp. + UINT8 NumEntries; // 06h ;First opcode is a NameOp. + UINT8 DwordPrefix1; // 0Ch + UINT32 CoreFrequency; // 00h + UINT8 DwordPrefix2; // 0Ch + UINT32 Power; // 00h + UINT8 DwordPrefix3; // 0Ch + UINT32 TransLatency; // 00h + UINT8 DwordPrefix4; // 0Ch + UINT32 BmLatency; // 00h + UINT8 DwordPrefix5; // 0Ch + UINT32 Control; // 00h + UINT8 DwordPrefix6; // 0Ch + UINT32 Status; // 00h +} PSS_PACKAGE_LAYOUT; +#pragma pack() + +/** + Initialize the ASL update library state. + This must be called prior to invoking other library functions. + + + @retval EFI_SUCCESS The function completed successfully. +**/ +EFI_STATUS +InitializeAslUpdateLib ( + VOID + ); + +/** + This procedure will update immediate value assigned to a Name + + @param[in] AslSignature The signature of Operation Region that we want to update. + @param[in] Buffer source of data to be written over original aml + @param[in] Length length of data to be overwritten + + @retval EFI_SUCCESS The function completed successfully. +**/ +EFI_STATUS +UpdateNameAslCode( + IN UINT32 AslSignature, + IN VOID *Buffer, + IN UINTN Length + ); + +/** + This function uses the ACPI support protocol to locate an ACPI table using the . + It is really only useful for finding tables that only have a single instance, + e.g. FADT, FACS, MADT, etc. It is not good for locating SSDT, etc. + Matches are determined by finding the table with ACPI table that has + a matching signature and version. + + @param[in] Signature Pointer to an ASCII string containing the Signature to match + @param[in, out] Table Updated with a pointer to the table + @param[in, out] Handle AcpiSupport protocol table handle for the table found + @param[in, out] Version On input, the version of the table desired, + on output, the versions the table belongs to + @see AcpiSupport protocol for details + + @retval EFI_SUCCESS The function completed successfully. +**/ +EFI_STATUS +LocateAcpiTableBySignature ( + IN UINT32 Signature, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle + ); + +/** + This function uses the ACPI support protocol to locate an ACPI SSDT table. + The table is located by searching for a matching OEM Table ID field. + Partial match searches are supported via the TableIdSize parameter. + + @param[in] TableId Pointer to an ASCII string containing the OEM Table ID from the ACPI table header + @param[in] TableIdSize Length of the TableId to match. Table ID are 8 bytes long, this function + will consider it a match if the first TableIdSize bytes match + @param[in, out] Table Updated with a pointer to the table + @param[in, out] Handle AcpiSupport protocol table handle for the table found + @param[in, out] Version See AcpiSupport protocol, GetAcpiTable function for use + + @retval EFI_SUCCESS The function completed successfully. +**/ +EFI_STATUS +LocateAcpiTableByOemTableId ( + IN UINT8 *TableId, + IN UINT8 TableIdSize, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle + ); + +/** + This function calculates and updates an UINT8 checksum. + + @param[in] Buffer Pointer to buffer to checksum + @param[in] Size Number of bytes to checksum + @param[in] ChecksumOffset Offset to place the checksum result in + + @retval EFI_SUCCESS The function completed successfully. +**/ +EFI_STATUS +AcpiChecksum ( + IN VOID *Buffer, + IN UINTN Size, + IN UINTN ChecksumOffset + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/BoardAcpiEnableLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/BoardAcpiEnableLib.h new file mode 100644 index 0000000000..48de84cfed --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/BoardAcpiEnableLib.h @@ -0,0 +1,33 @@ +/** @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. + +**/ + +#ifndef _BOARD_ACPI_ENABLE_LIB_H_ +#define _BOARD_ACPI_ENABLE_LIB_H_ + +#include +#include +#include + +EFI_STATUS +EFIAPI +BoardEnableAcpi ( + IN BOOLEAN EnableSci + ); + +EFI_STATUS +EFIAPI +BoardDisableAcpi ( + IN BOOLEAN DisableSci + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/BoardAcpiTableLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/BoardAcpiTableLib.h new file mode 100644 index 0000000000..d001393654 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/BoardAcpiTableLib.h @@ -0,0 +1,28 @@ +/** @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. + +**/ + +#ifndef _BOARD_ACPI_TABLE_LIB_H_ +#define _BOARD_ACPI_TABLE_LIB_H_ + +#include +#include +#include + +EFI_STATUS +EFIAPI +BoardUpdateAcpiTable ( + IN OUT EFI_ACPI_COMMON_HEADER *Table, + IN OUT EFI_ACPI_TABLE_VERSION *Version + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/BoardInitLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/BoardInitLib.h new file mode 100644 index 0000000000..db366e387a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/BoardInitLib.h @@ -0,0 +1,92 @@ +/** @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. + +**/ + +#ifndef _BOARD_INIT_LIB_H_ +#define _BOARD_INIT_LIB_H_ + +#include +#include + +EFI_STATUS +EFIAPI +BoardDetect ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardDebugInit ( + VOID + ); + +EFI_BOOT_MODE +EFIAPI +BoardBootModeDetect ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardInitBeforeMemoryInit ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardInitAfterMemoryInit ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardInitBeforeTempRamExit ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardInitAfterTempRamExit ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardInitBeforeSiliconInit ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardInitAfterSiliconInit ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardInitAfterPciEnumeration ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardInitReadyToBoot ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardInitEndOfFirmware ( + VOID + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/FspPolicyInitLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/FspPolicyInitLib.h new file mode 100644 index 0000000000..40330e0113 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/FspPolicyInitLib.h @@ -0,0 +1,30 @@ +/** @file + Function prototype of FspPolicyInitLib. + +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. + +**/ + +#ifndef _FSP_POLICY_INIT_LIB_H_ +#define _FSP_POLICY_INIT_LIB_H_ + +VOID +EFIAPI +FspmPolicyInit ( + IN OUT VOID *FspmUpd + ); + +VOID +EFIAPI +FspsPolicyInit ( + IN OUT VOID *FspsUpd + ); + +#endif // _FSP_POLICY_INIT_LIB_H_ diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/FspPolicyUpdateLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/FspPolicyUpdateLib.h new file mode 100644 index 0000000000..977c4b2052 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/FspPolicyUpdateLib.h @@ -0,0 +1,30 @@ +/** @file + Function prototype of FspPolicyUpdateLib. + +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. + +**/ + +#ifndef _FSP_POLICY_UPDATE_LIB_H_ +#define _FSP_POLICY_UPDATE_LIB_H_ + +VOID +EFIAPI +FspmPolicyUpdate ( + IN OUT VOID *FspmUpd + ); + +VOID +EFIAPI +FspsPolicyUpdate ( + IN OUT VOID *FspsUpd + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/HobVariableLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/HobVariableLib.h new file mode 100644 index 0000000000..8b5e1dc858 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/HobVariableLib.h @@ -0,0 +1,111 @@ +/**@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. + +**/ + +#ifndef _HOB_VARIABLE_LIB_H_ +#define _HOB_VARIABLE_LIB_H_ + +/** + This function finds the default data and create GUID hob for it. + + @retval EFI_SUCCESS The matched default data is found. + @retval EFI_NOT_FOUND The matched default data is not found. + @retval EFI_OUT_OF_RESOURCES No enough resource to create HOB. + +**/ +EFI_STATUS +EFIAPI +CreateVariableHob ( + VOID + ); + +/** + This function finds the matched default data and create GUID hob for it. + + @param StoreId Specifies the type of defaults to retrieve. + @param SkuId Specifies the platform board of defaults to retrieve. + + @retval EFI_SUCCESS The matched default data is found. + @retval EFI_NOT_FOUND The matched default data is not found. + @retval EFI_OUT_OF_RESOURCES No enough resource to create HOB. + +**/ +EFI_STATUS +EFIAPI +CreateDefaultVariableHob ( + IN UINT16 StoreId, + IN UINT16 SkuId + ); + +/** + Get variable from default variable HOB. + + @param[in] VariableName A Null-terminated string that is the name of the vendor's + variable. + @param[in] VendorGuid A unique identifier for the vendor. + @param[out] Attributes If not NULL, a pointer to the memory location to return the + attributes bitmask for the variable. + @param[in, out] DataSize On input, the size in bytes of the return Data buffer. + On output the size of data returned in Data. + @param[out] Data The buffer to return the contents of the variable. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is NULL. + +**/ +EFI_STATUS +EFIAPI +GetVariableFromHob ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes, OPTIONAL + IN OUT UINTN *DataSize, + OUT VOID *Data + ); + +/** + Set variable to default variable HOB. + + @param[in] VariableName A Null-terminated string that is the name of the vendor's + variable. + @param[in] VendorGuid A unique identifier for the vendor. + @param[in] Attributes If not NULL, a pointer to the memory location to set the + attributes bitmask for the variable. + @param[in] DataSize On input, the size in bytes of the return Data buffer. + On output the size of data returned in Data. + @param[in] Data The buffer to return the contents of the variable. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER Attributes is not NULL, but attributes value is 0. + @retval EFI_INVALID_PARAMETER DataSize is not equal to the variable data size. + @retval EFI_INVALID_PARAMETER The DataSize is equal to the variable data size, but Data is NULL. + +**/ +EFI_STATUS +EFIAPI +SetVariableToHob ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + IN UINT32 *Attributes, OPTIONAL + IN UINTN DataSize, + IN VOID *Data + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardAcpiSupportLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardAcpiSupportLib.h new file mode 100644 index 0000000000..15087428e8 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardAcpiSupportLib.h @@ -0,0 +1,60 @@ +/** @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. + +**/ + +#ifndef _MULTI_BOARD_ACPI_SUPPORT_LIB_H_ +#define _MULTI_BOARD_ACPI_SUPPORT_LIB_H_ + +#include +#include + +typedef +EFI_STATUS +(EFIAPI *BOARD_ENABLE_ACPI) ( + IN BOOLEAN EnableSci + ); + +typedef +EFI_STATUS +(EFIAPI *BOARD_DISABLE_ACPI) ( + IN BOOLEAN DisableSci + ); + +typedef struct { + BOARD_ENABLE_ACPI BoardEnableAcpi; + BOARD_DISABLE_ACPI BoardDisableAcpi; +} BOARD_ACPI_ENABLE_FUNC; + +typedef +EFI_STATUS +(EFIAPI *BOARD_UPDATE_ACPI_TABLE) ( + IN OUT EFI_ACPI_COMMON_HEADER *Table, + IN OUT EFI_ACPI_TABLE_VERSION *Version + ); + +typedef struct { + BOARD_UPDATE_ACPI_TABLE BoardUpdateAcpiTable; +} BOARD_ACPI_TABLE_FUNC; + +EFI_STATUS +EFIAPI +RegisterBoardAcpiEnableFunc ( + IN BOARD_ACPI_ENABLE_FUNC *BoardAcpiEnableFunc + ); + +EFI_STATUS +EFIAPI +RegisterBoardAcpiTableFunc ( + IN BOARD_ACPI_TABLE_FUNC *BoardAcpiTableFunc + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h new file mode 100644 index 0000000000..c4c36216fe --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h @@ -0,0 +1,85 @@ +/** @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. + +**/ + +#ifndef _MULTI_BOARD_INIT_SUPPORT_LIB_H_ +#define _MULTI_BOARD_INIT_SUPPORT_LIB_H_ + +#include + +typedef +EFI_STATUS +(EFIAPI *BOARD_DETECT) ( + VOID + ); + +typedef +EFI_STATUS +(EFIAPI *BOARD_INIT) ( + VOID + ); + +typedef +EFI_BOOT_MODE +(EFIAPI *BOARD_BOOT_MODE_DETECT) ( + VOID + ); + +typedef struct { + BOARD_DETECT BoardDetect; +} BOARD_DETECT_FUNC; + +typedef struct { + BOARD_INIT BoardDebugInit; + BOARD_BOOT_MODE_DETECT BoardBootModeDetect; + BOARD_INIT BoardInitBeforeMemoryInit; + BOARD_INIT BoardInitAfterMemoryInit; + BOARD_INIT BoardInitBeforeTempRamExit; + BOARD_INIT BoardInitAfterTempRamExit; +} BOARD_PRE_MEM_INIT_FUNC; + +typedef struct { + BOARD_INIT BoardInitBeforeSiliconInit; + BOARD_INIT BoardInitAfterSiliconInit; +} BOARD_POST_MEM_INIT_FUNC; + +typedef struct { + BOARD_INIT BoardInitAfterPciEnumeration; + BOARD_INIT BoardInitReadyToBoot; + BOARD_INIT BoardInitEndOfFirmware; +} BOARD_NOTIFICATION_INIT_FUNC; + +EFI_STATUS +EFIAPI +RegisterBoardDetect ( + IN BOARD_DETECT_FUNC *BoardDetect + ); + +EFI_STATUS +EFIAPI +RegisterBoardPreMemInit ( + IN BOARD_PRE_MEM_INIT_FUNC *BoardPreMemInit + ); + +EFI_STATUS +EFIAPI +RegisterBoardPostMemInit ( + IN BOARD_POST_MEM_INIT_FUNC *BoardPostMemInit + ); + +EFI_STATUS +EFIAPI +RegisterBoardNotificationInit ( + IN BOARD_NOTIFICATION_INIT_FUNC *BoardNotificationInit + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/PeiLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/PeiLib.h new file mode 100644 index 0000000000..8889f97d59 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/PeiLib.h @@ -0,0 +1,85 @@ +/** @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. + +**/ + +#ifndef _PEI_LIB_H_ +#define _PEI_LIB_H_ + +#include + +/** + Returns the status whether get the variable success. The function retrieves + variable through the ReadOnlyVariable2 PPI GetVariable(). + + If the *Size is 0, the returned buffer is allocated using AllocatePool(). + The caller is responsible for freeing this buffer with FreePool(). + + If the *Size is non-0, this function just uses caller allocated *Value. + + @param[in] Name The pointer to a Null-terminated Unicode string. + @param[in] Guid The pointer to an EFI_GUID structure + @param[out] Value The buffer point saved the variable info. + @param[out] Size The buffer size of the variable. + + @return EFI_OUT_OF_RESOURCES Allocate buffer failed. + @return EFI_SUCCESS Find the specified variable. + @return Others Errors Return errors from call to gRT->GetVariable. + +**/ +EFI_STATUS +EFIAPI +PeiGetVariable ( + IN CONST CHAR16 *Name, + IN CONST EFI_GUID *Guid, + OUT VOID **Value, + OUT UINTN *Size + ); + +/** + Finds the file in any FV and gets file Address and Size + + @param[in] NameGuid File GUID + @param[out] Address Pointer to the File Address + @param[out] Size Pointer to File Size + + @retval EFI_SUCCESS Successfull in reading the file from any FV +**/ +EFI_STATUS +EFIAPI +PeiGetFfsFromAnyFv ( + IN CONST EFI_GUID *NameGuid, + OUT VOID **Address, + OUT UINTN *Size + ); + +/** + Finds the section in any FV and gets section Address and Size + + @param[in] NameGuid File GUID + @param[in] SectionType The SectionType of Section to be found + @param[in] SectionInstance The Instance of Section to be found + @param[out] Address Pointer to the section Address + @param[out] Size Pointer to section Size + + @retval EFI_SUCCESS Successfull in reading the section from any FV +**/ +EFI_STATUS +EFIAPI +PeiGetSectionFromAnyFv ( + IN CONST EFI_GUID *NameGuid, + IN EFI_SECTION_TYPE SectionType, + IN UINTN SectionInstance, + OUT VOID **Address, + OUT UINTN *Size + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/SecBoardInitLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/SecBoardInitLib.h new file mode 100644 index 0000000000..9142b14335 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/SecBoardInitLib.h @@ -0,0 +1,38 @@ +/** @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. + +**/ + +#ifndef _SEC_BOARD_INIT_LIB_H_ +#define _SEC_BOARD_INIT_LIB_H_ + +#include +#include + +/** + This is stackless function in 32bit. + + return address - ESP. + All other registers can be used. +**/ +VOID +EFIAPI +BoardBeforeTempRamInit ( + VOID + ); + +EFI_STATUS +EFIAPI +BoardAfterTempRamInit ( + VOID + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/SpiFlashCommonLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/SpiFlashCommonLib.h new file mode 100644 index 0000000000..12dfaeb440 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/SpiFlashCommonLib.h @@ -0,0 +1,104 @@ +/** @file + The header file includes the common header files, defines + internal structure and functions used by SpiFlashCommonLib. + +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. + +**/ + +#ifndef __SPI_FLASH_COMMON_LIB_H__ +#define __SPI_FLASH_COMMON_LIB_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define SECTOR_SIZE_4KB 0x1000 // Common 4kBytes sector size +/** + Enable block protection on the Serial Flash device. + + @retval EFI_SUCCESS Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +SpiFlashLock ( + VOID + ); + +/** + Read NumBytes bytes of data from the address specified by + PAddress into Buffer. + + @param[in] Address The starting physical address of the read. + @param[in,out] NumBytes On input, the number of bytes to read. On output, the number + of bytes actually read. + @param[out] Buffer The destination data buffer for the read. + + @retval EFI_SUCCESS Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +SpiFlashRead ( + IN UINTN Address, + IN OUT UINT32 *NumBytes, + OUT UINT8 *Buffer + ); + +/** + Write NumBytes bytes of data from Buffer to the address specified by + PAddresss. + + @param[in] Address The starting physical address of the write. + @param[in,out] NumBytes On input, the number of bytes to write. On output, + the actual number of bytes written. + @param[in] Buffer The source data buffer for the write. + + @retval EFI_SUCCESS Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +SpiFlashWrite ( + IN UINTN Address, + IN OUT UINT32 *NumBytes, + IN UINT8 *Buffer + ); + +/** + Erase the block starting at Address. + + @param[in] Address The starting physical address of the block to be erased. + This library assume that caller garantee that the PAddress + is at the starting address of this block. + @param[in] NumBytes On input, the number of bytes of the logical block to be erased. + On output, the actual number of bytes erased. + + @retval EFI_SUCCESS. Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +SpiFlashBlockErase ( + IN UINTN Address, + IN UINTN *NumBytes + ); + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/TestPointCheckLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/TestPointCheckLib.h new file mode 100644 index 0000000000..7caea0a53e --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/TestPointCheckLib.h @@ -0,0 +1,219 @@ +/** @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. + +**/ + +#ifndef _TEST_POINT_CHECK_LIB_H_ +#define _TEST_POINT_CHECK_LIB_H_ + +#include +#include + +// +// Below is Test Point Hook Point. +// + +EFI_STATUS +EFIAPI +TestPointTempMemoryInitDone ( + IN VOID *TempRamStart, + IN VOID *TempRamEnd + ); + +EFI_STATUS +EFIAPI +TestPointDebugInitDone ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointMemoryDiscovered ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointEndOfPei ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointPciEnumerationDone ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointEndOfDxe ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointDxeSmmReadyToLock ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointReadyToBoot ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointExitBootServices ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointSmmEndOfDxe ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointSmmReadyToLock ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointSmmReadyToBoot ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointSmmExitBootServices ( + VOID + ); + +// +// Below is detail definition for MinPlatform implementation +// + +#define TEST_POINT_IMPLEMENTATION_ID_PLATFORM L"Intel MinPlatform TestPoint" + +#define TEST_POINT_FEATURE_SIZE 4 + +#define TEST_POINT_ERROR L"Error " +#define TEST_POINT_PLATFORM_TEST_POINT L" Platform TestPoint" + +// Byte 0 - SEC +#define TEST_POINT_TEMP_MEMORY_INIT_DONE L" - Temp Memory Init Done - " + +#define TEST_POINT_BYTE0_TEMP_INIT_DONE BIT0 +#define TEST_POINT_BYTE0_TEMP_MEMORY_INIT_DONE_ERROR_CODE_1 L"0x00000001" +#define TEST_POINT_BYTE0_TEMP_MEMORY_INIT_DONE_ERROR_STRING_1 L"Invalid Temp Ram\r\n" + +// Byte 1 - PEI +#define TEST_POINT_DEBUG_INIT_DONE L" - Debug Init Done - " +#define TEST_POINT_MEMORY_DISCOVERED L" - Memory Discovered - " +#define TEST_POINT_END_OF_PEI L" - End Of PEI - " + +#define TEST_POINT_BYTE1_DEBUG_INIT_DONE BIT0 +#define TEST_POINT_BYTE1_MEMORY_DISCOVERED BIT1 +#define TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_CODE_1 L"0x01010001" +#define TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_STRING_1 L"Invalid Memory Resource\r\n" +#define TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_CODE_2 L"0x01010002" +#define TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_STRING_2 L"Invalid MTRR Setting\r\n" +#define TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_CODE_3 L"0x01010002" +#define TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_STRING_3 L"Invalid SMRAM Resource\r\n" +#define TEST_POINT_BYTE1_END_OF_PEI BIT2 +#define TEST_POINT_BYTE1_END_OF_PEI_ERROR_CODE_1 L"0x01020001" +#define TEST_POINT_BYTE1_END_OF_PEI_ERROR_STRING_1 L"Invalid System Resource\r\n" +#define TEST_POINT_BYTE1_END_OF_PEI_ERROR_CODE_2 L"0x01020002" +#define TEST_POINT_BYTE1_END_OF_PEI_ERROR_STRING_2 L"Invalid MTRR Setting\r\n" +#define TEST_POINT_BYTE1_END_OF_PEI_ERROR_CODE_3 L"0x01010003" +#define TEST_POINT_BYTE1_END_OF_PEI_ERROR_STRING_3 L"Invalid FV Information\r\n" + +// Byte 2 - DXE +#define TEST_POINT_PCI_ENUMERATION_DONE L" - PCI Enumeration Done - " +#define TEST_POINT_END_OF_DXE L" - End Of DXE - " +#define TEST_POINT_DXE_SMM_READY_TO_LOCK L" - DXE SMM Ready To Lock - " +#define TEST_POINT_READY_TO_BOOT L" - Ready To Boot - " +#define TEST_POINT_EXIT_BOOT_SERVICES L" - Exit Boot Services - " + +#define TEST_POINT_BYTE2_PCI_ENUMERATION_DONE BIT0 +#define TEST_POINT_BYTE2_PCI_ENUMERATION_DONE_ERROR_CODE_1 L"0x02010001" +#define TEST_POINT_BYTE2_PCI_ENUMERATION_DONE_ERROR_STRING_1 L"Invalid PCI Resource\r\n" +#define TEST_POINT_BYTE2_END_OF_DXE BIT1 +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_CODE_1 L"0x02020001" +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_STRING_1 L"Invalid PCI OROM\r\n" +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_CODE_2 L"0x02020002" +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_STRING_2 L"Invalid Memory Map\r\n" +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_CODE_3 L"0x02020003" +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_STRING_3 L"Invalid GCD Map\r\n" +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_CODE_4 L"0x02020004" +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_STRING_4 L"Invalid Console Variable\r\n" +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_CODE_5 L"0x02020005" +#define TEST_POINT_BYTE2_END_OF_DXE_ERROR_STRING_5 L"Invalid Boot Variable\r\n" +#define TEST_POINT_BYTE2_DXE_SMM_READY_TO_LOCK BIT2 +#define TEST_POINT_BYTE2_DXE_SMM_READY_TO_LOCK_ERROR_CODE_1 L"0x02040001" +#define TEST_POINT_BYTE2_DXE_SMM_READY_TO_LOCK_ERROR_STRING_1 L"Invalid SMRAM Information\r\n" +#define TEST_POINT_BYTE2_READY_TO_BOOT BIT3 +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_1 L"0x02080001" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_1 L"Invalid Device\r\n" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_2 L"0x02080002" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_2 L"Invalid Memory Type Information\r\n" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_3 L"0x02080003" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_3 L"Invalid UEFI Variable\r\n" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_4 L"0x02080004" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_4 L"Invalid Memory Attribute Table\r\n" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_5 L"0x02080005" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_5 L"Invalid ACPI Table\r\n" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_6 L"0x02080006" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_6 L"Invalid WSMT Table\r\n" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_7 L"0x02080007" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_7 L"Invalid DMAR Table\r\n" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_8 L"0x02080008" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_8 L"Invalid HSTI\r\n" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_9 L"0x02080009" +#define TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_9 L"Invalid ESRT\r\n" +#define TEST_POINT_BYTE2_EXIT_BOOT_SERVICES BIT4 + +// Byte 3 - SMM +#define TEST_POINT_SMM_END_OF_DXE L" - SMM End Of DXE - " +#define TEST_POINT_SMM_READY_TO_LOCK L" - SMM Ready To Lock - " +#define TEST_POINT_SMM_READY_TO_BOOT L" - SMM Ready To Boot - " +#define TEST_POINT_SMM_EXIT_BOOT_SERVICES L" - SMM Exit Boot Services - " + +#define TEST_POINT_BYTE3_SMM_END_OF_DXE BIT0 +#define TEST_POINT_BYTE3_SMM_END_OF_DXE_ERROR_CODE_1 L"0x03010001" +#define TEST_POINT_BYTE3_SMM_END_OF_DXE_ERROR_STRING_1 L"Invalid SMM Image\r\n" +#define TEST_POINT_BYTE3_SMM_READY_TO_LOCK BIT1 +#define TEST_POINT_BYTE2_SMM_READY_TO_LOCK_ERROR_CODE_1 L"0x03020001" +#define TEST_POINT_BYTE2_SMM_READY_TO_LOCK_ERROR_STRING_1 L"Invalid SMM Memory Attribute Table\r\n" +#define TEST_POINT_BYTE2_SMM_READY_TO_LOCK_ERROR_CODE_2 L"0x03020002" +#define TEST_POINT_BYTE2_SMM_READY_TO_LOCK_ERROR_STRING_2 L"Invalid SMRR\r\n" +#define TEST_POINT_BYTE3_SMM_READY_TO_BOOT BIT2 +#define TEST_POINT_BYTE3_SMM_EXIT_BOOT_SERVICES BIT3 + +#pragma pack (1) + +typedef struct { + UINT32 Version; + UINT32 Role; + CHAR16 ImplementationID[256]; + UINT32 FeaturesSize; + UINT8 FeaturesRequired[TEST_POINT_FEATURE_SIZE]; + UINT8 FeaturesImplemented[TEST_POINT_FEATURE_SIZE]; + UINT8 FeaturesVerified[TEST_POINT_FEATURE_SIZE]; + CHAR16 End; +} ADAPTER_INFO_PLATFORM_TEST_POINT_STRUCT; + +#pragma pack () + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/TestPointLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/TestPointLib.h new file mode 100644 index 0000000000..49d5f84cb0 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/TestPointLib.h @@ -0,0 +1,225 @@ +/** @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. + +**/ + +#ifndef _TEST_POINT_LIB_H_ +#define _TEST_POINT_LIB_H_ + +#include +#include + +// +// Below is Test Point report definition. +// + +// +// We reuse HSTI stype definition. +// ADAPTER_INFO_PLATFORM_TEST_POINT is similar to ADAPTER_INFO_PLATFORM_SECURITY. +// + +#define PLATFORM_TEST_POINT_VERSION 0x00000001 + +#define PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE 0x00000001 +#define PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV 0x00000002 +#define PLATFORM_TEST_POINT_ROLE_IMPLEMENTOR_OEM 0x00000003 +#define PLATFORM_TEST_POINT_ROLE_IMPLEMENTOR_ODM 0x00000004 + +typedef struct { + UINT32 Version; + UINT32 Role; + CHAR16 ImplementationID[256]; + UINT32 FeaturesSize; +//UINT8 FeaturesRequired[]; +//UINT8 FeaturesImplemented[]; +//UINT8 FeaturesVerified[]; +//CHAR16 ErrorString[]; +} ADAPTER_INFO_PLATFORM_TEST_POINT; + +// +// Below is test point report library +// + +/** + Publish TestPoint table in AIP protocol. + + One system should have only one PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE. + + If the Role is NOT PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE, + FeaturesRequired field will be ignored. + + @param TestPoint TestPoint data + @param TestPointSize TestPoint size + + @retval EFI_SUCCESS The TestPoint data is published in AIP protocol. + @retval EFI_ALREADY_STARTED There is already TestPoint table with Role and ImplementationID published in system. + @retval EFI_VOLUME_CORRUPTED The input TestPoint data is invalid. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish TestPoint data in AIP protocol. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetTable ( + IN VOID *TestPoint, + IN UINTN TestPointSize + ); + +/** + Search TestPoint table in AIP protocol, and return the data. + This API will return the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param TestPoint TestPoint data. This buffer is allocated by callee, and it + is the responsibility of the caller to free it after + using it. + @param TestPointSize TestPoint size + + @retval EFI_SUCCESS The TestPoint data in AIP protocol is returned. + @retval EFI_NOT_FOUND There is not TestPoint table with the Role and ImplementationID published in system. +**/ +EFI_STATUS +EFIAPI +TestPointLibGetTable ( + IN UINT32 Role, + IN CHAR16 *ImplementationID OPTIONAL, + OUT VOID **TestPoint, + OUT UINTN *TestPointSize + ); + +/** + Set FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 BitMask + ); + +/** + Clear FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +EFIAPI +TestPointLibClearFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 BitMask + ); + +/** + Append ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +EFIAPI +TestPointLibAppendErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString + ); + +/** + Set a new ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString + ); + +// +// TEST POINT SMM Communication command +// +#define SMI_HANDLER_TEST_POINT_COMMAND_GET_INFO 0x1 +#define SMI_HANDLER_TEST_POINT_COMMAND_GET_DATA_BY_OFFSET 0x2 + +typedef struct { + UINT32 Command; + UINT32 DataLength; + UINT64 ReturnStatus; +} SMI_HANDLER_TEST_POINT_PARAMETER_HEADER; + +typedef struct { + SMI_HANDLER_TEST_POINT_PARAMETER_HEADER Header; + UINT64 DataSize; +} SMI_HANDLER_TEST_POINT_PARAMETER_GET_INFO; + +typedef struct { + SMI_HANDLER_TEST_POINT_PARAMETER_HEADER Header; + // + // On input, data buffer size. + // On output, actual data buffer size copied. + // + UINT64 DataSize; + PHYSICAL_ADDRESS DataBuffer; + // + // On input, data buffer offset to copy. + // On output, next time data buffer offset to copy. + // + UINT64 DataOffset; +} SMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET; + +extern EFI_GUID gAdapterInfoPlatformTestPointGuid; + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/Fce.h b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/Fce.h new file mode 100644 index 0000000000..a9010a2763 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/Fce.h @@ -0,0 +1,48 @@ +/**@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. + +**/ + +#ifndef __FCE_H__ +#define __FCE_H__ + +extern EFI_GUID gDefaultDataFileGuid; +extern EFI_GUID gDefaultDataOptSizeFileGuid; + +#pragma pack(1) + +typedef struct { + UINT16 DefaultId; + UINT16 BoardId; +} DEFAULT_INFO; + +typedef struct { + UINT16 Offset; + UINT8 Value; +} DATA_DELTA; + +typedef struct { + // + // HeaderSize includes HeaderSize fields and DefaultInfo arrays + // + UINT16 HeaderSize; + // + // DefaultInfo arrays those have the same default setting. + // + DEFAULT_INFO DefaultInfo[1]; + // + // Default data is stored as variable storage or the array of DATA_DELTA. + // +} DEFAULT_DATA; + +#pragma pack() + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/InternalCommonLib.c b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/InternalCommonLib.c new file mode 100644 index 0000000000..cb7f928426 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/InternalCommonLib.c @@ -0,0 +1,634 @@ +/**@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 "Variable.h" +#include "Fce.h" + +/** + + Gets the pointer to the first variable header in given variable store area. + + @param VarStoreHeader Pointer to the Variable Store Header. + + @return Pointer to the first variable header + +**/ +STATIC +AUTHENTICATED_VARIABLE_HEADER * +GetStartPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) +{ + // + // The end of variable store + // + return (AUTHENTICATED_VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1); +} + + +/** + This code gets the pointer to the last variable memory pointer byte. + + @param VarStoreHeader Pointer to the Variable Store Header. + + @return AUTHENTICATED_VARIABLE_HEADER* pointer to last unavailable Variable Header. + +**/ +STATIC +AUTHENTICATED_VARIABLE_HEADER * +GetEndPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) +{ + // + // The end of variable store + // + return (AUTHENTICATED_VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size); +} + + +/** + This code checks if variable header is valid or not. + + @param Variable Pointer to the Variable Header. + + @retval TRUE Variable header is valid. + @retval FALSE Variable header is not valid. + +**/ +STATIC +BOOLEAN +IsValidVariableHeader ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable + ) +{ + if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) { + return FALSE; + } + + return TRUE; +} + +/** + This code gets the size of name of variable. + + @param Variable Pointer to the Variable Header. + @param AuthFlag Authenticated variable flag. + + @return Size of variable in bytes in type UINTN. + +**/ +STATIC +UINTN +NameSizeOfVariable ( + IN AUTHENTICATED_VARIABLE_HEADER *AuthVariable, + IN BOOLEAN AuthFlag + ) +{ + VARIABLE_HEADER *Variable; + + Variable = (VARIABLE_HEADER *) AuthVariable; + if (AuthFlag) { + if (AuthVariable->State == (UINT8) (-1) || + AuthVariable->DataSize == (UINT32) (-1) || + AuthVariable->NameSize == (UINT32) (-1) || + AuthVariable->Attributes == (UINT32) (-1)) { + return 0; + } + return (UINTN) AuthVariable->NameSize; + } else { + if (Variable->State == (UINT8) (-1) || + Variable->DataSize == (UINT32) (-1) || + Variable->NameSize == (UINT32) (-1) || + Variable->Attributes == (UINT32) (-1)) { + return 0; + } + return (UINTN) Variable->NameSize; + } +} + + +/** + This code gets the size of data of variable. + + @param Variable Pointer to the Variable Header. + @param AuthFlag Authenticated variable flag. + + @return Size of variable in bytes in type UINTN. + +**/ +STATIC +UINTN +DataSizeOfVariable ( + IN AUTHENTICATED_VARIABLE_HEADER *AuthVariable, + IN BOOLEAN AuthFlag + ) +{ + VARIABLE_HEADER *Variable; + + Variable = (VARIABLE_HEADER *) AuthVariable; + if (AuthFlag) { + if (AuthVariable->State == (UINT8) (-1) || + AuthVariable->DataSize == (UINT32) (-1) || + AuthVariable->NameSize == (UINT32) (-1) || + AuthVariable->Attributes == (UINT32) (-1)) { + return 0; + } + return (UINTN) AuthVariable->DataSize; + } else { + if (Variable->State == (UINT8) (-1) || + Variable->DataSize == (UINT32) (-1) || + Variable->NameSize == (UINT32) (-1) || + Variable->Attributes == (UINT32) (-1)) { + return 0; + } + return (UINTN) Variable->DataSize; + } +} + +/** + This code gets the size of variable header. + + @param AuthFlag Authenticated variable flag. + + @return Size of variable header in bytes in type UINTN. + +**/ +UINTN +GetVariableHeaderSize ( + IN BOOLEAN AuthFlag + ) +{ + UINTN Value; + + if (AuthFlag) { + Value = sizeof (AUTHENTICATED_VARIABLE_HEADER); + } else { + Value = sizeof (VARIABLE_HEADER); + } + + return Value; +} + + +/** + This code gets the pointer to the variable name. + + @param Variable Pointer to the Variable Header. + @param AuthFlag Authenticated variable flag. + + @return A CHAR16* pointer to Variable Name. + +**/ +STATIC +CHAR16 * +GetVariableNamePtr ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFlag + ) +{ + return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize (AuthFlag)); +} + + +/** + This code gets the pointer to the variable guid. + + @param Variable Pointer to the Variable Header. + @param AuthFlag Authenticated variable flag. + + @return A EFI_GUID* pointer to Vendor Guid. + +**/ +EFI_GUID * +GetVendorGuidPtr ( + IN AUTHENTICATED_VARIABLE_HEADER *AuthVariable, + IN BOOLEAN AuthFlag + ) +{ + VARIABLE_HEADER *Variable; + + Variable = (VARIABLE_HEADER *) AuthVariable; + if (AuthFlag) { + return &AuthVariable->VendorGuid; + } else { + return &Variable->VendorGuid; + } +} + + +/** + This code gets the pointer to the variable data. + + @param Variable Pointer to the Variable Header. + @param AuthFlag Authenticated variable flag. + + @return A UINT8* pointer to Variable Data. + +**/ +STATIC +UINT8 * +GetVariableDataPtr ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFlag + ) +{ + UINTN Value; + + // + // Be careful about pad size for alignment + // + Value = (UINTN) GetVariableNamePtr (Variable, AuthFlag); + Value += NameSizeOfVariable (Variable, AuthFlag); + Value += GET_PAD_SIZE (NameSizeOfVariable (Variable, AuthFlag)); + + return (UINT8 *) Value; +} + + +/** + This code gets the pointer to the next variable header. + + @param Variable Pointer to the Variable Header. + @param AuthFlag Authenticated variable flag. + + @return A AUTHENTICATED_VARIABLE_HEADER* pointer to next variable header. + +**/ +STATIC +AUTHENTICATED_VARIABLE_HEADER * +GetNextVariablePtr ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFlag + ) +{ + UINTN Value; + + if (!IsValidVariableHeader (Variable)) { + return NULL; + } + + Value = (UINTN) GetVariableDataPtr (Variable, AuthFlag); + Value += DataSizeOfVariable (Variable, AuthFlag); + Value += GET_PAD_SIZE (DataSizeOfVariable (Variable, AuthFlag)); + + // + // Be careful about pad size for alignment + // + return (AUTHENTICATED_VARIABLE_HEADER *) HEADER_ALIGN (Value); +} + +EFI_STATUS +EFIAPI +BuildDefaultDataHobForRecoveryVariable ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +/*++ + +Routine Description: + + Convert Authenticated variable to normal variable data. + +Arguments: + + PeiServices General purpose services available to every PEIM. + NotifyDescriptor Notify that this module published. + Ppi PPI that was installed. + +Returns: + + EFI_SUCCESS The function completed successfully. + +--*/ +{ + EFI_HOB_GUID_TYPE *GuidHob; + VARIABLE_STORE_HEADER *AuthVarStoreHeader; + VARIABLE_STORE_HEADER *VarStoreHeader; + UINT32 VarStoreSize; + AUTHENTICATED_VARIABLE_HEADER *AuthStartPtr; + AUTHENTICATED_VARIABLE_HEADER *AuthEndPtr; + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; + VARIABLE_HEADER *Variable; + UINT8 *AuthVariablePtr; + UINT8 *VariablePtr; + + GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); + AuthVarStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob); + // + // Go through AuthVarStore to calculate the required size for normal varstore. + // + VarStoreSize = sizeof (VARIABLE_STORE_HEADER); + AuthStartPtr = GetStartPointer (AuthVarStoreHeader); + AuthEndPtr = GetEndPointer (AuthVarStoreHeader); + AuthVariable = AuthStartPtr; + while ((AuthVariable < AuthEndPtr) && IsValidVariableHeader (AuthVariable)) { + if (AuthVariable->State == VAR_ADDED) { + VarStoreSize = HEADER_ALIGN (VarStoreSize); + VarStoreSize += sizeof (VARIABLE_HEADER); + VarStoreSize += AuthVariable->NameSize + GET_PAD_SIZE (AuthVariable->NameSize); + VarStoreSize += AuthVariable->DataSize + GET_PAD_SIZE (AuthVariable->DataSize); + } + AuthVariable = GetNextVariablePtr (AuthVariable, TRUE); + } + + // + // Create HOB data for normal variable storage. + // Allocate more data for header alignment. + // + VarStoreSize = VarStoreSize + HEADER_ALIGNMENT - 1; + VarStoreHeader = (VARIABLE_STORE_HEADER *) BuildGuidHob (&gEfiVariableGuid, VarStoreSize); + ASSERT (VarStoreHeader != NULL); + if (VarStoreHeader == NULL) { + return EFI_OUT_OF_RESOURCES; + } + CopyGuid (&VarStoreHeader->Signature, &gEfiVariableGuid); + VarStoreHeader->Format = AuthVarStoreHeader->Format; + VarStoreHeader->State = AuthVarStoreHeader->State; + + // + // Copy variable data from AuthVarStore to NormalVarStore + // + AuthVariable = AuthStartPtr; + VariablePtr = (UINT8 *) (VarStoreHeader + 1); + while ((AuthVariable < AuthEndPtr) && IsValidVariableHeader (AuthVariable)) { + if (AuthVariable->State == VAR_ADDED) { + Variable = (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VariablePtr); + // + // Copy variable header + // + Variable->StartId = AuthVariable->StartId; + Variable->State = AuthVariable->State; + Variable->Reserved = AuthVariable->Reserved; + Variable->Attributes = AuthVariable->Attributes; + Variable->NameSize = AuthVariable->NameSize; + Variable->DataSize = AuthVariable->DataSize; + CopyGuid (&Variable->VendorGuid, &AuthVariable->VendorGuid); + // + // Copy variable Name and Data + // + VariablePtr = (UINT8 *) (Variable + 1); + AuthVariablePtr = (UINT8 *) (AuthVariable + 1); + CopyMem (VariablePtr, AuthVariablePtr, Variable->NameSize); + VariablePtr = VariablePtr + Variable->NameSize + GET_PAD_SIZE (Variable->NameSize); + AuthVariablePtr = AuthVariablePtr + AuthVariable->NameSize + GET_PAD_SIZE (AuthVariable->NameSize); + CopyMem (VariablePtr, AuthVariablePtr, Variable->DataSize); + VariablePtr = VariablePtr + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize); + } + AuthVariable = GetNextVariablePtr (AuthVariable, TRUE); + } + + // + // Update Variable Storage Size + // + VarStoreHeader->Size = (UINT32) ((UINTN) VariablePtr - (UINTN) VarStoreHeader); + + return EFI_SUCCESS; +} + +EFI_PEI_NOTIFY_DESCRIPTOR mMemoryNotifyList = { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiMemoryDiscoveredPpiGuid, + BuildDefaultDataHobForRecoveryVariable +}; + +/** + Find variable from default variable HOB. + + @param[in] VariableName A Null-terminated string that is the name of the vendor's + variable. + @param[in] VendorGuid A unique identifier for the vendor. + @param[out] AuthFlag Pointer to output Authenticated variable flag. + + @return Pointer to variable header, NULL if not found. + +**/ +AUTHENTICATED_VARIABLE_HEADER * +FindVariableFromHob ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT BOOLEAN *AuthFlag + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + VARIABLE_STORE_HEADER *VariableStoreHeader; + AUTHENTICATED_VARIABLE_HEADER *StartPtr; + AUTHENTICATED_VARIABLE_HEADER *EndPtr; + AUTHENTICATED_VARIABLE_HEADER *CurrPtr; + VOID *Point; + + VariableStoreHeader = NULL; + + GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); + if (GuidHob != NULL) { + VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob); + *AuthFlag = TRUE; + } else { + GuidHob = GetFirstGuidHob (&gEfiVariableGuid); + if (GuidHob != NULL) { + VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob); + *AuthFlag = FALSE; + } + } + ASSERT (VariableStoreHeader != NULL); + if (VariableStoreHeader == NULL) { + return NULL; + } + + StartPtr = GetStartPointer (VariableStoreHeader); + EndPtr = GetEndPointer (VariableStoreHeader); + for ( CurrPtr = StartPtr + ; (CurrPtr < EndPtr) && IsValidVariableHeader (CurrPtr) + ; CurrPtr = GetNextVariablePtr (CurrPtr, *AuthFlag) + ) { + if (CurrPtr->State == VAR_ADDED) { + if (CompareGuid (VendorGuid, GetVendorGuidPtr (CurrPtr, *AuthFlag))) { + Point = (VOID *) GetVariableNamePtr (CurrPtr, *AuthFlag); + + ASSERT (NameSizeOfVariable (CurrPtr, *AuthFlag) != 0); + if (CompareMem (VariableName, Point, NameSizeOfVariable (CurrPtr, *AuthFlag)) == 0) { + return CurrPtr; + } + } + } + } + + return NULL; +} + +/** + Get variable from default variable HOB. + + @param[in] VariableName A Null-terminated string that is the name of the vendor's + variable. + @param[in] VendorGuid A unique identifier for the vendor. + @param[out] Attributes If not NULL, a pointer to the memory location to return the + attributes bitmask for the variable. + @param[in, out] DataSize On input, the size in bytes of the return Data buffer. + On output the size of data returned in Data. + @param[out] Data The buffer to return the contents of the variable. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is NULL. + +**/ +EFI_STATUS +EFIAPI +GetVariableFromHob ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes, OPTIONAL + IN OUT UINTN *DataSize, + OUT VOID *Data + ) +{ + BOOLEAN AuthFlag; + AUTHENTICATED_VARIABLE_HEADER *Variable; + UINTN VarDataSize; + + if ((VariableName == NULL) || (VendorGuid == NULL) || (DataSize == NULL)) { + return EFI_INVALID_PARAMETER; + } + + Variable = FindVariableFromHob (VariableName, VendorGuid, &AuthFlag); + if (Variable == NULL) { + return EFI_NOT_FOUND; + } + + // + // Get data size + // + VarDataSize = DataSizeOfVariable (Variable, AuthFlag); + if (*DataSize >= VarDataSize) { + if (Data == NULL) { + return EFI_INVALID_PARAMETER; + } + + CopyMem (Data, GetVariableDataPtr (Variable, AuthFlag), VarDataSize); + + if (Attributes != NULL) { + *Attributes = Variable->Attributes; + } + + *DataSize = VarDataSize; + return EFI_SUCCESS; + } else { + *DataSize = VarDataSize; + return EFI_BUFFER_TOO_SMALL; + } +} + +/** + Set variable to default variable HOB. + + @param[in] VariableName A Null-terminated string that is the name of the vendor's + variable. + @param[in] VendorGuid A unique identifier for the vendor. + @param[in] Attributes If not NULL, a pointer to the memory location to set the + attributes bitmask for the variable. + @param[in] DataSize On input, the size in bytes of the return Data buffer. + On output the size of data returned in Data. + @param[in] Data The buffer to return the contents of the variable. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER Attributes is not NULL, but attributes value is 0. + @retval EFI_INVALID_PARAMETER DataSize is not equal to the variable data size. + @retval EFI_INVALID_PARAMETER The DataSize is equal to the variable data size, but Data is NULL. + +**/ +EFI_STATUS +EFIAPI +SetVariableToHob ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + IN UINT32 *Attributes, OPTIONAL + IN UINTN DataSize, + IN VOID *Data + ) +{ + BOOLEAN AuthFlag; + AUTHENTICATED_VARIABLE_HEADER *Variable; + UINTN VarDataSize; + + if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) { + return EFI_INVALID_PARAMETER; + } + + Variable = FindVariableFromHob (VariableName, VendorGuid, &AuthFlag); + if (Variable == NULL) { + return EFI_NOT_FOUND; + } + + // + // Get data size + // + VarDataSize = DataSizeOfVariable (Variable, AuthFlag); + if (DataSize == VarDataSize) { + if (Data == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (Attributes != NULL) { + if (*Attributes == 0) { + return EFI_INVALID_PARAMETER; + } + Variable->Attributes = *Attributes; + } + + CopyMem (GetVariableDataPtr (Variable, AuthFlag), Data, VarDataSize); + + return EFI_SUCCESS; + } else { + return EFI_INVALID_PARAMETER; + } +} + +/** + This function finds the matched data and create GUID hob for it. + + @retval EFI_SUCCESS The matched default data is found. + @retval EFI_NOT_FOUND The matched default data is not found. + @retval EFI_OUT_OF_RESOURCES No enough resource to create HOB. + +**/ +EFI_STATUS +EFIAPI +CreateVariableHob ( + VOID + ) +{ + UINT16 StoreId; + UINT16 SkuId; + + StoreId = EFI_HII_DEFAULT_CLASS_STANDARD; // BUGBUG: Should get from PCD + SkuId = (UINT16)LibPcdGetSku (); + return CreateDefaultVariableHob (StoreId, SkuId); +} \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFce.c b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFce.c new file mode 100644 index 0000000000..ecad77ec8a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFce.c @@ -0,0 +1,467 @@ +/** @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 "Variable.h" +#include "Fce.h" + +/** + + Gets the pointer to the first variable header in given variable store area. + + @param VarStoreHeader Pointer to the Variable Store Header. + + @return Pointer to the first variable header + +**/ +STATIC +AUTHENTICATED_VARIABLE_HEADER * +GetStartPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) +{ + // + // The end of variable store + // + return (AUTHENTICATED_VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1); +} + + +/** + This code gets the pointer to the last variable memory pointer byte. + + @param VarStoreHeader Pointer to the Variable Store Header. + + @return AUTHENTICATED_VARIABLE_HEADER* pointer to last unavailable Variable Header. + +**/ +STATIC +AUTHENTICATED_VARIABLE_HEADER * +GetEndPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) +{ + // + // The end of variable store + // + return (AUTHENTICATED_VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size); +} + + +/** + This code checks if variable header is valid or not. + + @param Variable Pointer to the Variable Header. + + @retval TRUE Variable header is valid. + @retval FALSE Variable header is not valid. + +**/ +STATIC +BOOLEAN +IsValidVariableHeader ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable + ) +{ + if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) { + return FALSE; + } + + return TRUE; +} + + +/** + This code gets the size of name of variable. + + @param Variable Pointer to the Variable Header. + + @return Size of variable in bytes in type UINTN. + +**/ +STATIC +UINTN +NameSizeOfVariable ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable + ) +{ + if (Variable->State == (UINT8) (-1) || + Variable->DataSize == (UINT32) (-1) || + Variable->NameSize == (UINT32) (-1) || + Variable->Attributes == (UINT32) (-1)) { + return 0; + } + return (UINTN) Variable->NameSize; +} + + +/** + This code gets the size of data of variable. + + @param Variable Pointer to the Variable Header. + + @return Size of variable in bytes in type UINTN. + +**/ +STATIC +UINTN +DataSizeOfVariable ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable + ) +{ + if (Variable->State == (UINT8) (-1) || + Variable->DataSize == (UINT32) (-1) || + Variable->NameSize == (UINT32) (-1) || + Variable->Attributes == (UINT32) (-1)) { + return 0; + } + return (UINTN) Variable->DataSize; +} + +/** + This code gets the pointer to the variable name. + + @param Variable Pointer to the Variable Header. + + @return A CHAR16* pointer to Variable Name. + +**/ +STATIC +CHAR16 * +GetVariableNamePtr ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable + ) +{ + + return (CHAR16 *) (Variable + 1); +} + + +/** + This code gets the pointer to the variable data. + + @param Variable Pointer to the Variable Header. + + @return A UINT8* pointer to Variable Data. + +**/ +STATIC +UINT8 * +GetVariableDataPtr ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable + ) +{ + UINTN Value; + + // + // Be careful about pad size for alignment + // + Value = (UINTN) GetVariableNamePtr (Variable); + Value += NameSizeOfVariable (Variable); + Value += GET_PAD_SIZE (NameSizeOfVariable (Variable)); + + return (UINT8 *) Value; +} + + +/** + This code gets the pointer to the next variable header. + + @param Variable Pointer to the Variable Header. + + @return A AUTHENTICATED_VARIABLE_HEADER* pointer to next variable header. + +**/ +STATIC +AUTHENTICATED_VARIABLE_HEADER * +GetNextVariablePtr ( + IN AUTHENTICATED_VARIABLE_HEADER *Variable + ) +{ + UINTN Value; + + if (!IsValidVariableHeader (Variable)) { + return NULL; + } + + Value = (UINTN) GetVariableDataPtr (Variable); + Value += DataSizeOfVariable (Variable); + Value += GET_PAD_SIZE (DataSizeOfVariable (Variable)); + + // + // Be careful about pad size for alignment + // + return (AUTHENTICATED_VARIABLE_HEADER *) HEADER_ALIGN (Value); +} + +EFI_STATUS +EFIAPI +BuildDefaultDataHobForRecoveryVariable ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +/*++ + +Routine Description: + + Convert Authenticated variable to normal variable data. + +Arguments: + + PeiServices General purpose services available to every PEIM. + NotifyDescriptor Notify that this module published. + Ppi PPI that was installed. + +Returns: + + EFI_SUCCESS The function completed successfully. + +--*/ +{ + EFI_HOB_GUID_TYPE *GuidHob; + VARIABLE_STORE_HEADER *AuthVarStoreHeader; + VARIABLE_STORE_HEADER *VarStoreHeader; + UINT32 VarStoreSize; + AUTHENTICATED_VARIABLE_HEADER *AuthStartPtr; + AUTHENTICATED_VARIABLE_HEADER *AuthEndPtr; + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; + VARIABLE_HEADER *Variable; + UINT8 *AuthVariablePtr; + UINT8 *VariablePtr; + + GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); + AuthVarStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob); + // + // Go through AuthVarStore to calculate the required size for normal varstore. + // + VarStoreSize = sizeof (VARIABLE_STORE_HEADER); + AuthStartPtr = GetStartPointer (AuthVarStoreHeader); + AuthEndPtr = GetEndPointer (AuthVarStoreHeader); + AuthVariable = AuthStartPtr; + while ((AuthVariable < AuthEndPtr) && IsValidVariableHeader (AuthVariable)) { + if (AuthVariable->State == VAR_ADDED) { + VarStoreSize = HEADER_ALIGN (VarStoreSize); + VarStoreSize += sizeof (VARIABLE_HEADER); + VarStoreSize += AuthVariable->NameSize + GET_PAD_SIZE (AuthVariable->NameSize); + VarStoreSize += AuthVariable->DataSize + GET_PAD_SIZE (AuthVariable->DataSize); + } + AuthVariable = GetNextVariablePtr (AuthVariable); + } + + // + // Create HOB data for normal variable storage. + // Allocate more data for header alignment. + // + VarStoreSize = VarStoreSize + HEADER_ALIGNMENT - 1; + VarStoreHeader = (VARIABLE_STORE_HEADER *) BuildGuidHob (&gEfiVariableGuid, VarStoreSize); + ASSERT (VarStoreHeader != NULL); + CopyGuid (&VarStoreHeader->Signature, &gEfiVariableGuid); + VarStoreHeader->Format = AuthVarStoreHeader->Format; + VarStoreHeader->State = AuthVarStoreHeader->State; + + // + // Copy variable data from AuthVarStore to NormalVarStore + // + AuthVariable = AuthStartPtr; + VariablePtr = (UINT8 *) (VarStoreHeader + 1); + while ((AuthVariable < AuthEndPtr) && IsValidVariableHeader (AuthVariable)) { + if (AuthVariable->State == VAR_ADDED) { + Variable = (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VariablePtr); + // + // Copy variable header + // + Variable->StartId = AuthVariable->StartId; + Variable->State = AuthVariable->State; + Variable->Reserved = AuthVariable->Reserved; + Variable->Attributes = AuthVariable->Attributes; + Variable->NameSize = AuthVariable->NameSize; + Variable->DataSize = AuthVariable->DataSize; + CopyGuid (&Variable->VendorGuid, &AuthVariable->VendorGuid); + // + // Copy variable Name and Data + // + VariablePtr = (UINT8 *) (Variable + 1); + AuthVariablePtr = (UINT8 *) (AuthVariable + 1); + CopyMem (VariablePtr, AuthVariablePtr, Variable->NameSize); + VariablePtr = VariablePtr + Variable->NameSize + GET_PAD_SIZE (Variable->NameSize); + AuthVariablePtr = AuthVariablePtr + AuthVariable->NameSize + GET_PAD_SIZE (AuthVariable->NameSize); + CopyMem (VariablePtr, AuthVariablePtr, Variable->DataSize); + VariablePtr = VariablePtr + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize); + } + AuthVariable = GetNextVariablePtr (AuthVariable); + } + + // + // Update Variable Storage Size + // + VarStoreHeader->Size = (UINT32) ((UINTN) VariablePtr - (UINTN) VarStoreHeader); + + return EFI_SUCCESS; +} + +static EFI_PEI_NOTIFY_DESCRIPTOR mMemoryNotifyList = { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiMemoryDiscoveredPpiGuid, + BuildDefaultDataHobForRecoveryVariable +}; + +/** + This function finds the matched default data and create GUID hob for it. + + @param StoreId Specifies the type of defaults to retrieve. + @param SkuId Specifies the platform board of defaults to retrieve. + + @retval EFI_SUCCESS The matched default data is found. + @retval EFI_NOT_FOUND The matched default data is not found. + @retval EFI_OUT_OF_RESOURCES No enough resource to create HOB. + +**/ +EFI_STATUS +EFIAPI +CreateDefaultVariableHob ( + IN UINT16 StoreId, + IN UINT16 SkuId + ) +{ + UINTN FvInstance; + EFI_FIRMWARE_VOLUME_HEADER *FvHeader; + EFI_FFS_FILE_HEADER *FfsHeader; + UINT32 FileSize; + EFI_COMMON_SECTION_HEADER *Section; + UINT32 SectionLength; + EFI_STATUS Status; + BOOLEAN DefaultFileIsFound; + DEFAULT_DATA *DefaultData; + DEFAULT_INFO *DefaultInfo; + VARIABLE_STORE_HEADER *VarStoreHeader; + VARIABLE_STORE_HEADER *VarStoreHeaderHob; + UINT8 *VarHobPtr; + UINT8 *VarPtr; + UINT32 VarDataOffset; + UINT32 VarHobDataOffset; + EFI_BOOT_MODE BootMode; + CONST EFI_PEI_SERVICES **PeiServices; + + // + // Get PeiService pointer + // + PeiServices = GetPeiServicesTablePointer (); + + // + // Find the FFS file that stores all default data. + // + DefaultFileIsFound = FALSE; + FvInstance = 0; + FfsHeader = NULL; + while (((*PeiServices)->FfsFindNextVolume (PeiServices, FvInstance, &FvHeader) == EFI_SUCCESS) && + (!DefaultFileIsFound)) { + FfsHeader = NULL; + while ((*PeiServices)->FfsFindNextFile (PeiServices, EFI_FV_FILETYPE_FREEFORM, FvHeader, &FfsHeader) == EFI_SUCCESS) { + if (CompareGuid ((EFI_GUID *) FfsHeader, &gDefaultDataFileGuid)) { + DefaultFileIsFound = TRUE; + break; + } + } + FvInstance ++; + } + + // + // FFS file is not found. + // + if (!DefaultFileIsFound) { + return EFI_NOT_FOUND; + } + + // + // Find the matched default data for the input default ID and plat ID. + // + VarStoreHeader = NULL; + Section = (EFI_COMMON_SECTION_HEADER *)(FfsHeader + 1); + FileSize = *(UINT32 *)(FfsHeader->Size) & 0x00FFFFFF; + while (((UINTN) Section < (UINTN) FfsHeader + FileSize) && (VarStoreHeader == NULL)) { + DefaultData = (DEFAULT_DATA *) (Section + 1); + DefaultInfo = &(DefaultData->DefaultInfo[0]); + while ((UINTN) DefaultInfo < (UINTN) DefaultData + DefaultData->HeaderSize) { + if (DefaultInfo->DefaultId == StoreId && DefaultInfo->BoardId == SkuId) { + VarStoreHeader = (VARIABLE_STORE_HEADER *) ((UINT8 *) DefaultData + DefaultData->HeaderSize); + break; + } + DefaultInfo ++; + } + // + // Size is 24 bits wide so mask upper 8 bits. + // SectionLength is adjusted it is 4 byte aligned. + // Go to the next section + // + SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF; + SectionLength = (SectionLength + 3) & (~3); + ASSERT (SectionLength != 0); + Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength); + } + // + // Matched default data is not found. + // + if (VarStoreHeader == NULL) { + return EFI_NOT_FOUND; + } + + // + // Create HOB to store default data so that Variable driver can use it. + // Allocate more data for header alignment. + // + VarStoreHeaderHob = (VARIABLE_STORE_HEADER *) BuildGuidHob (&VarStoreHeader->Signature, VarStoreHeader->Size + HEADER_ALIGNMENT - 1); + if (VarStoreHeaderHob == NULL) { + // + // No enough hob resource. + // + return EFI_OUT_OF_RESOURCES; + } + + // + // Copy variable storage header. + // + CopyMem (VarStoreHeaderHob, VarStoreHeader, sizeof (VARIABLE_STORE_HEADER)); + // + // Copy variable data. + // + VarPtr = (UINT8 *) HEADER_ALIGN ((UINTN) (VarStoreHeader + 1)); + VarDataOffset = (UINT32) ((UINTN) VarPtr - (UINTN) VarStoreHeader); + VarHobPtr = (UINT8 *) HEADER_ALIGN ((UINTN) (VarStoreHeaderHob + 1)); + VarHobDataOffset = (UINT32) ((UINTN) VarHobPtr - (UINTN) VarStoreHeaderHob); + CopyMem (VarHobPtr, VarPtr, VarStoreHeader->Size - VarDataOffset); + // + // Update variable size. + // + VarStoreHeaderHob->Size = VarStoreHeader->Size - VarDataOffset + VarHobDataOffset; + + // + // On recovery boot mode, emulation variable driver will be used. + // But, Emulation variable only knows normal variable data format. + // So, if the default variable data format is authenticated, it needs to be converted to normal data. + // + Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode); + if (BootMode == BOOT_IN_RECOVERY_MODE && + CompareGuid (&VarStoreHeader->Signature, &gEfiAuthenticatedVariableGuid)) { + Status = (**PeiServices).NotifyPpi (PeiServices, &mMemoryNotifyList); + ASSERT_EFI_ERROR (Status); + } + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFce.inf b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFce.inf new file mode 100644 index 0000000000..66526b3fbd --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFce.inf @@ -0,0 +1,54 @@ +### @file +# Module define variable layout and access method for common +# circumstance. +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = PeiHobVariableLibFce + FILE_GUID = 5196F8AE-7C88-4DA8-83D4-21725AB4CF9B + VERSION_STRING = 1.0 + MODULE_TYPE = PEIM + LIBRARY_CLASS = HobVariableLib|PEIM +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF +# + +[LibraryClasses] + BaseMemoryLib + PeiServicesTablePointerLib + HobLib + DebugLib + PcdLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[Sources] + PeiHobVariableLibFce.c + InternalCommonLib.c + +[Ppis] + gEfiPeiMemoryDiscoveredPpiGuid ## NOTIFY + +[Guids] + gEfiVariableGuid ## SOMETIMES_PRODUCES ## HOB + gEfiAuthenticatedVariableGuid ## SOMETIMES_CONSUMES ## HOB + gDefaultDataFileGuid ## SOMETIMES_CONSUMES ## FV + diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFceOptSize.c b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFceOptSize.c new file mode 100644 index 0000000000..cd93898d25 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFceOptSize.c @@ -0,0 +1,206 @@ +/** @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 "Variable.h" +#include "Fce.h" + +extern EFI_PEI_NOTIFY_DESCRIPTOR mMemoryNotifyList; + +/** + This function finds the matched default data and create GUID hob for it. + + @param StoreId Specifies the type of defaults to retrieve. + @param SkuId Specifies the platform board of defaults to retrieve. + + @retval EFI_SUCCESS The matched default data is found. + @retval EFI_NOT_FOUND The matched default data is not found. + @retval EFI_OUT_OF_RESOURCES No enough resource to create HOB. + +**/ +EFI_STATUS +EFIAPI +CreateDefaultVariableHob ( + IN UINT16 StoreId, + IN UINT16 SkuId + ) +{ + UINTN FvInstance; + EFI_FIRMWARE_VOLUME_HEADER *FvHeader; + EFI_FFS_FILE_HEADER *FfsHeader; + UINT32 FileSize; + EFI_COMMON_SECTION_HEADER *Section; + UINT32 SectionLength; + EFI_STATUS Status; + BOOLEAN DefaultSettingIsFound; + DEFAULT_DATA *DefaultData; + DEFAULT_INFO *DefaultInfo; + VARIABLE_STORE_HEADER *VarStoreHeader; + VARIABLE_STORE_HEADER *VarStoreHeaderHob; + UINT8 *VarHobPtr; + UINT8 *VarPtr; + UINT32 VarDataOffset; + UINT32 VarHobDataOffset; + EFI_BOOT_MODE BootMode; + BOOLEAN IsFirstSection; + DATA_DELTA *DataDelta; + UINTN DataDeltaSize; + UINTN Index; + CONST EFI_PEI_SERVICES **PeiServices; + + // + // Get PeiService pointer + // + PeiServices = GetPeiServicesTablePointer (); + + // + // Find the FFS file that stores all default data. + // + DefaultSettingIsFound = FALSE; + FvInstance = 0; + FfsHeader = NULL; + while (((*PeiServices)->FfsFindNextVolume (PeiServices, FvInstance, (VOID **) &FvHeader) == EFI_SUCCESS) && + (!DefaultSettingIsFound)) { + FfsHeader = NULL; + while ((*PeiServices)->FfsFindNextFile (PeiServices, EFI_FV_FILETYPE_FREEFORM, FvHeader, (VOID **) &FfsHeader) == EFI_SUCCESS) { + if (CompareGuid ((EFI_GUID *) FfsHeader, &gDefaultDataOptSizeFileGuid)) { + DefaultSettingIsFound = TRUE; + break; + } + } + FvInstance ++; + } + + // + // FFS file is not found. + // + if (!DefaultSettingIsFound) { + return EFI_NOT_FOUND; + } + + // + // Find the matched default data for the input default ID and plat ID. + // + DefaultSettingIsFound = FALSE; + VarStoreHeaderHob = NULL; + VarHobPtr = NULL; + DataDelta = NULL; + DataDeltaSize = 0; + IsFirstSection = TRUE; + VarStoreHeader = NULL; + Section = (EFI_COMMON_SECTION_HEADER *)(FfsHeader + 1); + FileSize = *(UINT32 *)(FfsHeader->Size) & 0x00FFFFFF; + while (((UINTN) Section < (UINTN) FfsHeader + FileSize) && !DefaultSettingIsFound) { + DefaultData = (DEFAULT_DATA *) (Section + 1); + DefaultInfo = &(DefaultData->DefaultInfo[0]); + SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF; + + if (IsFirstSection) { + // + // Create HOB to store default data so that Variable driver can use it. + // Allocate more data for header alignment. + // + VarStoreHeader = (VARIABLE_STORE_HEADER *) ((UINT8 *) DefaultData + DefaultData->HeaderSize); + VarStoreHeaderHob = (VARIABLE_STORE_HEADER *) BuildGuidHob (&VarStoreHeader->Signature, VarStoreHeader->Size + HEADER_ALIGNMENT - 1); + if (VarStoreHeaderHob == NULL) { + // + // No enough hob resource. + // + return EFI_OUT_OF_RESOURCES; + } + + // + // Copy variable storage header. + // + CopyMem (VarStoreHeaderHob, VarStoreHeader, sizeof (VARIABLE_STORE_HEADER)); + // + // Copy variable data. + // + VarPtr = (UINT8 *) HEADER_ALIGN ((UINTN) (VarStoreHeader + 1)); + VarDataOffset = (UINT32) ((UINTN) VarPtr - (UINTN) VarStoreHeader); + VarHobPtr = (UINT8 *) HEADER_ALIGN ((UINTN) (VarStoreHeaderHob + 1)); + VarHobDataOffset = (UINT32) ((UINTN) VarHobPtr - (UINTN) VarStoreHeaderHob); + CopyMem (VarHobPtr, VarPtr, VarStoreHeader->Size - VarDataOffset); + // + // Update variable size. + // + VarStoreHeaderHob->Size = VarStoreHeader->Size - VarDataOffset + VarHobDataOffset; + + // + // Update Delta Data + // + VarHobPtr = (UINT8 *) VarStoreHeaderHob - VarDataOffset + VarHobDataOffset; + } else { + // + // Apply delta setting + // + DataDelta = (DATA_DELTA *) ((UINT8 *) DefaultData + DefaultData->HeaderSize); + DataDeltaSize = SectionLength - sizeof (EFI_COMMON_SECTION_HEADER) - DefaultData->HeaderSize; + for (Index = 0; Index < DataDeltaSize / sizeof (DATA_DELTA); Index ++) { + *((UINT8 *) VarHobPtr + DataDelta[Index].Offset) = DataDelta[Index].Value; + } + } + + // + // Find the matched DefaultId and BoardId + // + while ((UINTN) DefaultInfo < (UINTN) DefaultData + DefaultData->HeaderSize) { + if (DefaultInfo->DefaultId == StoreId && DefaultInfo->BoardId == SkuId) { + DefaultSettingIsFound = TRUE; + break; + } + DefaultInfo ++; + } + // + // Size is 24 bits wide so mask upper 8 bits. + // SectionLength is adjusted it is 4 byte aligned. + // Go to the next section + // + SectionLength = (SectionLength + 3) & (~3); + ASSERT (SectionLength != 0); + Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength); + IsFirstSection = FALSE; + } + // + // Matched default data is not found. + // + if (!DefaultSettingIsFound) { + // + // Change created HOB type to be unused. + // + if (VarStoreHeaderHob != NULL) { + ((EFI_HOB_GUID_TYPE *)((UINT8 *) VarStoreHeaderHob - sizeof (EFI_HOB_GUID_TYPE)))->Header.HobType = EFI_HOB_TYPE_UNUSED; + } + return EFI_NOT_FOUND; + } + + // + // On recovery boot mode, emulation variable driver will be used. + // But, Emulation variable only knows normal variable data format. + // So, if the default variable data format is authenticated, it needs to be converted to normal data. + // + Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode); + if (BootMode == BOOT_IN_RECOVERY_MODE && + CompareGuid (&VarStoreHeader->Signature, &gEfiAuthenticatedVariableGuid)) { + Status = (**PeiServices).NotifyPpi (PeiServices, &mMemoryNotifyList); + ASSERT_EFI_ERROR (Status); + } + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFceOptSize.inf b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFceOptSize.inf new file mode 100644 index 0000000000..9f6d60622d --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFceOptSize.inf @@ -0,0 +1,53 @@ +### @file +# Finds the matched default data and creates GUID hob for it. +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = PeiHobVariableLibFceOptSize + FILE_GUID = AD8F6AF5-F94C-44A2-AE7A-A4CDC22BDC6C + VERSION_STRING = 1.0 + MODULE_TYPE = PEIM + LIBRARY_CLASS = HobVariableLib|PEIM +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF +# + +[LibraryClasses] + BaseMemoryLib + PeiServicesTablePointerLib + HobLib + DebugLib + PcdLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[Sources] + PeiHobVariableLibFceOptSize.c + InternalCommonLib.c + +[Ppis] + gEfiPeiMemoryDiscoveredPpiGuid ## NOTIFY + +[Guids] + gEfiVariableGuid ## SOMETIMES_PRODUCES ## HOB + gEfiAuthenticatedVariableGuid ## SOMETIMES_CONSUMES ## HOB + gDefaultDataOptSizeFileGuid ## SOMETIMES_CONSUMES ## FV + diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/Variable.h b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/Variable.h new file mode 100644 index 0000000000..fa9fb0292c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiHobVariableLibFce/Variable.h @@ -0,0 +1,178 @@ +/**@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. + +**/ + +#ifndef __VARIABLE_H__ +#define __VARIABLE_H__ + +extern EFI_GUID gEfiVariableGuid; +extern EFI_GUID gEfiAuthenticatedVariableGuid; + +/// +/// Alignment of variable name and data, according to the architecture: +/// * For IA-32 and Intel(R) 64 architectures: 1. +/// * For IA-64 architecture: 8. +/// +#if defined (MDE_CPU_IPF) +#define ALIGNMENT 8 +#else +#define ALIGNMENT 1 +#endif + +// +// GET_PAD_SIZE calculates the miminal pad bytes needed to make the current pad size satisfy the alignment requirement. +// +#if (ALIGNMENT == 1) +#define GET_PAD_SIZE(a) (0) +#else +#define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1)) +#endif + +/// +/// Alignment of Variable Data Header in Variable Store region. +/// +#define HEADER_ALIGNMENT 4 +#define HEADER_ALIGN(Header) (((UINTN) (Header) + HEADER_ALIGNMENT - 1) & (~(HEADER_ALIGNMENT - 1))) + +/// +/// Status of Variable Store Region. +/// +typedef enum { + EfiRaw, + EfiValid, + EfiInvalid, + EfiUnknown +} VARIABLE_STORE_STATUS; + +#pragma pack(1) + +/// +/// Variable Store Header Format and State. +/// +#define VARIABLE_STORE_FORMATTED 0x5a +#define VARIABLE_STORE_HEALTHY 0xfe + +/// +/// Variable Store region header. +/// +typedef struct { + /// + /// Variable store region signature. + /// + EFI_GUID Signature; + /// + /// Size of entire variable store, + /// including size of variable store header but not including the size of FvHeader. + /// + UINT32 Size; + /// + /// Variable region format state. + /// + UINT8 Format; + /// + /// Variable region healthy state. + /// + UINT8 State; + UINT16 Reserved; + UINT32 Reserved1; +} VARIABLE_STORE_HEADER; + +/// +/// Variable data start flag. +/// +#define VARIABLE_DATA 0x55AA + +/// +/// Variable State flags. +/// +#define VAR_IN_DELETED_TRANSITION 0xfe ///< Variable is in obsolete transition. +#define VAR_DELETED 0xfd ///< Variable is obsolete. +#define VAR_HEADER_VALID_ONLY 0x7f ///< Variable header has been valid. +#define VAR_ADDED 0x3f ///< Variable has been completely added. + +/// +/// Single Variable Data Header Structure. +/// +typedef struct { + /// + /// Variable Data Start Flag. + /// + UINT16 StartId; + /// + /// Variable State defined above. + /// + UINT8 State; + UINT8 Reserved; + /// + /// Attributes of variable defined in UEFI specification. + /// + UINT32 Attributes; + /// + /// Size of variable null-terminated Unicode string name. + /// + UINT32 NameSize; + /// + /// Size of the variable data without this header. + /// + UINT32 DataSize; + /// + /// A unique identifier for the vendor that produces and consumes this varaible. + /// + EFI_GUID VendorGuid; +} VARIABLE_HEADER; + +/// +/// Single Variable Data Header Structure for Auth variable. +/// +typedef struct { + /// + /// Variable Data Start Flag. + /// + UINT16 StartId; + /// + /// Variable State defined above. + /// + UINT8 State; + UINT8 Reserved; + /// + /// Attributes of variable defined in UEFI specification. + /// + UINT32 Attributes; + /// + /// Associated monotonic count value against replay attack. + /// + UINT64 MonotonicCount; + /// + /// Associated TimeStamp value against replay attack. + /// + EFI_TIME TimeStamp; + /// + /// Index of associated public key in database. + /// + UINT32 PubKeyIndex; + /// + /// Size of variable null-terminated Unicode string name. + /// + UINT32 NameSize; + /// + /// Size of the variable data without this header. + /// + UINT32 DataSize; + /// + /// A unique identifier for the vendor that produces and consumes this varaible. + /// + EFI_GUID VendorGuid; +} AUTHENTICATED_VARIABLE_HEADER; + +#pragma pack() + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c b/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c new file mode 100644 index 0000000000..96bf91c408 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c @@ -0,0 +1,293 @@ +/** @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 + +/** + Returns the status whether get the variable success. The function retrieves + variable through the ReadOnlyVariable2 PPI GetVariable(). The + returned buffer is allocated using AllocatePool(). The caller is responsible + for freeing this buffer with FreePool(). + + If Name is NULL, then ASSERT(). + If Guid is NULL, then ASSERT(). + If Value is NULL, then ASSERT(). + + @param[in] Name The pointer to a Null-terminated Unicode string. + @param[in] Guid The pointer to an EFI_GUID structure + @param[out] Value The buffer point saved the variable info. + @param[out] Size The buffer size of the variable. + + @return EFI_OUT_OF_RESOURCES Allocate buffer failed. + @return EFI_SUCCESS Find the specified variable. + @return Others Errors Return errors from call to gRT->GetVariable. + +**/ +EFI_STATUS +EFIAPI +PeiGetVariable ( + IN CONST CHAR16 *Name, + IN CONST EFI_GUID *Guid, + OUT VOID **Value, + OUT UINTN *Size OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariableServices; + UINTN VariableSize; + VOID *VariableData; + + ASSERT (Name != NULL); + ASSERT (Guid != NULL); + ASSERT (Value != NULL); + + Status = PeiServicesLocatePpi ( + &gEfiPeiReadOnlyVariable2PpiGuid, + 0, + NULL, + &VariableServices + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR(Status)) { + return EFI_NOT_READY; + } + + VariableSize = 0; + VariableData = NULL; + Status = VariableServices->GetVariable ( + VariableServices, + Name, + Guid, + NULL, + &VariableSize, + VariableData + ); + if (Status != EFI_BUFFER_TOO_SMALL) { + return Status; + } + + if ((Size == NULL) || (*Size == 0) || (*Value == NULL)) { + VariableData = AllocatePool (VariableSize); + ASSERT (VariableData != NULL); + if (VariableData == NULL) { + return EFI_OUT_OF_RESOURCES; + } + } else { + if (*Size < VariableSize) { + return EFI_BUFFER_TOO_SMALL; + } + VariableData = *Value; + } + + Status = VariableServices->GetVariable ( + VariableServices, + Name, + Guid, + NULL, + &VariableSize, + VariableData + ); + if (EFI_ERROR (Status)) { + FreePool (VariableData); + VariableData = NULL; + VariableSize = 0; + } + + *Value = VariableData; + if (Size != NULL) { + *Size = VariableSize; + } + return Status; +} + +EFI_PEI_FILE_HANDLE +InternalGetFfsHandleFromAnyFv ( + IN CONST EFI_GUID *NameGuid + ) +{ + EFI_STATUS Status; + UINTN FvInstance; + EFI_PEI_FV_HANDLE FvHandle; + EFI_PEI_FILE_HANDLE FfsHandle; + + FvInstance = 0; + FvHandle = NULL; + FfsHandle = NULL; + while (TRUE) { + Status = PeiServicesFfsFindNextVolume (FvInstance, &FvHandle); + if (EFI_ERROR(Status)) { + break; + } + Status = PeiServicesFfsFindFileByName (NameGuid, FvHandle, &FfsHandle); + if (Status == EFI_SUCCESS) { + break; + } + FfsHandle = NULL; + FvInstance ++; + } + + return FfsHandle; +} + +/** + Finds the file in any FV and gets file Address and Size + + @param[in] NameGuid File GUID + @param[out] Address Pointer to the File Address + @param[out] Size Pointer to File Size + + @retval EFI_SUCCESS Successfull in reading the file from any FV +**/ +EFI_STATUS +EFIAPI +PeiGetFfsFromAnyFv ( + IN CONST EFI_GUID *NameGuid, + OUT VOID **Address, + OUT UINTN *Size + ) +{ + EFI_STATUS Status; + EFI_FV_FILE_INFO FvFileInfo; + EFI_PEI_FILE_HANDLE FfsHandle; + + FfsHandle = InternalGetFfsHandleFromAnyFv (NameGuid); + if (FfsHandle == NULL) { + return EFI_NOT_FOUND; + } + + // + // Need get size + // + Status = PeiServicesFfsGetFileInfo (FfsHandle, &FvFileInfo); + if (EFI_ERROR(Status)) { + return EFI_NOT_FOUND; + } + *Address = FvFileInfo.Buffer; + *Size = FvFileInfo.BufferSize; + + return Status; +} + +/** + Get Section buffer pointer by SectionType and SectionInstance. + + @param[in] SectionBuffer The buffer of section + @param[in] SectionBufferSize The size of SectionBuffer in bytes + @param[in] SectionType The SectionType of Section to be found + @param[in] SectionInstance The Instance of Section to be found + @param[out] OutSectionBuffer The section found, including SECTION_HEADER + @param[out] OutSectionSize The size of section found, including SECTION_HEADER + + @retval EFI_SUCCESS Successfull in reading the section from FV +**/ +EFI_STATUS +InternalGetSectionByType ( + IN VOID *SectionBuffer, + IN UINTN SectionBufferSize, + IN EFI_SECTION_TYPE SectionType, + IN UINTN SectionInstance, + OUT VOID **OutSectionBuffer, + OUT UINTN *OutSectionSize + ) +{ + EFI_COMMON_SECTION_HEADER *SectionHeader; + UINTN SectionSize; + UINTN Instance; + + // + // Find Section + // + SectionHeader = SectionBuffer; + + Instance = 0; + while ((UINTN)SectionHeader < (UINTN)SectionBuffer + SectionBufferSize) { + if (IS_SECTION2(SectionHeader)) { + SectionSize = SECTION2_SIZE(SectionHeader); + } else { + SectionSize = SECTION_SIZE(SectionHeader); + } + + if (SectionHeader->Type == SectionType) { + if (Instance == SectionInstance) { + *OutSectionBuffer = (UINT8 *)SectionHeader; + *OutSectionSize = SectionSize; + return EFI_SUCCESS; + } else { + Instance++; + } + } else { + // + // Skip other section type + // + } + + // + // Next Section + // + SectionHeader = (EFI_COMMON_SECTION_HEADER *)((UINTN)SectionHeader + ALIGN_VALUE(SectionSize, 4)); + } + + return EFI_NOT_FOUND; +} + +/** + Finds the section in any FV and gets section Address and Size + + @param[in] NameGuid File GUID + @param[in] SectionType The SectionType of Section to be found + @param[in] SectionInstance The Instance of Section to be found + @param[out] Address Pointer to the section Address + @param[out] Size Pointer to section Size + + @retval EFI_SUCCESS Successfull in reading the section from any FV +**/ +EFI_STATUS +EFIAPI +PeiGetSectionFromAnyFv ( + IN CONST EFI_GUID *NameGuid, + IN EFI_SECTION_TYPE SectionType, + IN UINTN SectionInstance, + OUT VOID **Address, + OUT UINTN *Size + ) +{ + EFI_STATUS Status; + EFI_COMMON_SECTION_HEADER *Section; + VOID *FileBuffer; + UINTN FileBufferSize; + + Status = PeiGetFfsFromAnyFv (NameGuid, &FileBuffer, &FileBufferSize); + if (EFI_ERROR(Status)) { + return Status; + } + + Status = InternalGetSectionByType (FileBuffer, FileBufferSize, SectionType, SectionInstance, Address, Size); + if (EFI_ERROR(Status)) { + return Status; + } + Section = *Address; + if (IS_SECTION2(Section)) { + ASSERT(SECTION2_SIZE(Section) > 0x00FFFFFF); + *Size = SECTION2_SIZE(Section) - sizeof (EFI_COMMON_SECTION_HEADER2); + *Address = (UINT8 *)*Address + sizeof (EFI_COMMON_SECTION_HEADER2); + } else { + *Size = SECTION_SIZE(Section) - sizeof (EFI_COMMON_SECTION_HEADER); + *Address = (UINT8 *)*Address + sizeof (EFI_COMMON_SECTION_HEADER); + } + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf b/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf new file mode 100644 index 0000000000..2ad74bf058 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf @@ -0,0 +1,37 @@ +## @file +# Component information file for Board Init Test Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiLib + FILE_GUID = 657A478B-16B9-4B6D-9C41-BEF86197BDF4 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = PeiLib + +[LibraryClasses] + BaseLib + PeiServicesLib + MemoryAllocationLib + DebugLib + +[Packages] + MdePkg/MdePkg.dec + +[Sources] + PeiLib.c + +[Ppis] + gEfiPeiReadOnlyVariable2PpiGuid ## CONSUMES diff --git a/Platform/Intel/MinPlatformPkg/License.txt b/Platform/Intel/MinPlatformPkg/License.txt new file mode 100644 index 0000000000..3bb2e6d1ea --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/License.txt @@ -0,0 +1,25 @@ +Copyright (c) 2017, Intel Corporation. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec new file mode 100644 index 0000000000..e7091e9926 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec @@ -0,0 +1,224 @@ +## @file +# Module describe the entire platform configuration. +# +# The DEC files are used by the utilities that parse DSC and +# INF files to generate AutoGen.c and AutoGen.h files +# for the build infrastructure. +# +# 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 which 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. +# +## + + +[Defines] +DEC_SPECIFICATION = 0x00010017 +PACKAGE_NAME = MinPlatformPkg +PACKAGE_VERSION = 0.1 +PACKAGE_GUID = 463B3B00-0D18-4a5f-90C0-D5B851D2574B + + +[Includes] +Include + +[Guids] +gPlatformModuleTokenSpaceGuid = {0x69d13bf0, 0xaf91, 0x4d96, {0xaa, 0x9f, 0x21, 0x84, 0xc5, 0xce, 0x3b, 0xc0}} + +gAdapterInfoPlatformTestPointGuid = {0x5381e3ea, 0xb77, 0x4580, {0xad, 0xdf, 0xa9, 0x1c, 0x8, 0x3b, 0xf2, 0x97}} + +gBoardDetectGuid = {0x1792429d, 0x9d94, 0x4e08, {0xa0, 0x99, 0x73, 0xa2, 0x86, 0xae, 0xb4, 0x35}} +gBoardPreMemInitGuid = {0x191dcfcf, 0xe16e, 0x43bb, {0x9b, 0xc3, 0x6e, 0xee, 0x6f, 0xab, 0x3a, 0x27}} +gBoardPostMemInitGuid = {0xa0e933ea, 0xa69, 0x47fb, {0xb2, 0xab, 0xa1, 0x6f, 0x71, 0x2d, 0x6f, 0x58}} +gBoardNotificationInitGuid = {0x78dbcabf, 0xc544, 0x4e6f, {0xaf, 0x3a, 0x71, 0x17, 0xd9, 0x42, 0x4e, 0xd1}} + +gBoardAcpiTableGuid = {0xd70e9f57, 0x69f, 0x4bef, {0x96, 0xc0, 0x84, 0x74, 0xf4, 0xa2, 0x5f, 0x3a}} +gBoardAcpiEnableGuid = {0x9727b610, 0xf645, 0x4429, {0x89, 0x21, 0x2c, 0x2b, 0x58, 0xdc, 0xbb, 0xa}} + +## +## IntelFrameworkPkg +## +gEfiSmmPeiSmramMemoryReserveGuid = {0x6dadf1d1, 0xd4cc, 0x4910, {0xbb, 0x6e, 0x82, 0xb1, 0xfd, 0x80, 0xff, 0x3d}} + +gIntelPeiGraphicsVbtGuid = {0x4ad46122, 0xffeb, 0x4a52, {0xbf, 0xb0, 0x51, 0x8c, 0xfc, 0xa0, 0x2d, 0xb0}} +gTianoLogoGuid = {0x7BB28B99, 0x61BB, 0x11D5, {0x9A, 0x5D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D}} + +gDefaultDataFileGuid = { 0x1ae42876, 0x008f, 0x4161, { 0xb2, 0xb7, 0x1c, 0x0d, 0x15, 0xc5, 0xef, 0x43 }} +gDefaultDataOptSizeFileGuid = { 0x003e7b41, 0x98a2, 0x4be2, { 0xb2, 0x7a, 0x6c, 0x30, 0xc7, 0x65, 0x52, 0x25 }} + +[LibraryClasses] + +PeiLib|Include/Library/PeiLib.h + +AslUpdateLib|Include/Library/AslUpdateLib.h +BoardAcpiEnableLib|Include/Library/BoardAcpiEnableLib.h +BoardAcpiTableLib|Include/Library/BoardAcpiTableLib.h + +FspPolicyInitLib|Include/Library/FspPolicyInitLib.h +FspPolicyUpdateLib|Include/Library/FspPolicyUpdateLib.h + +SpiFlashCommonLib|Include/Library/SpiFlashCommonLib.h + +BoardInitLib|Include/Library/BoardInitLib.h +MultiBoardInitSupportLib|Include/Library/MultiBoardInitSupportLib.h +SecBoardInitLib|Include/Library/SecBoardInitLib.h + +TestPointLib|Include/Library/TestPointLib.h +TestPointCheckLib|Include/Library/TestPointCheckLib.h + +[PcdsFixedAtBuild] + +## +## The Flash relevant PCD are ineffective and will be patched basing on FDF definitions during build. +## Set all of them to 0 here to prevent from confusion. +## +gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress|0xFF800000|UINT32|0x10000001 +gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize|0x00800000|UINT32|0x10000002 +gPlatformModuleTokenSpaceGuid.PcdFlashMicrocodeFvBase|0xFFE60000|UINT32|0x30000004 +gPlatformModuleTokenSpaceGuid.PcdFlashMicrocodeFvSize|0x000A0000|UINT32|0x30000005 +gPlatformModuleTokenSpaceGuid.PcdFlashMicrocodeFvOffset|0x00660000|UINT32|0x30000006 + +gPlatformModuleTokenSpaceGuid.PcdFlashFvRecoveryBase|0x00000000|UINT32|0x20000001 +gPlatformModuleTokenSpaceGuid.PcdFlashFvRecoverySize|0x00000000|UINT32|0x20000002 +gPlatformModuleTokenSpaceGuid.PcdFlashFvRecoveryOffset|0x00000000|UINT32|0x20000003 +gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery2Base|0x00000000|UINT32|0x20000004 +gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery2Size|0x00000000|UINT32|0x20000005 +gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery2Offset|0x00000000|UINT32|0x20000006 +gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery3Base|0x00000000|UINT32|0x20000007 +gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery3Size|0x00000000|UINT32|0x20000008 +gPlatformModuleTokenSpaceGuid.PcdFlashFvRecovery3Offset|0x00000000|UINT32|0x20000009 +gPlatformModuleTokenSpaceGuid.PcdFlashFvMainBase|0x00000000|UINT32|0x2000000A +gPlatformModuleTokenSpaceGuid.PcdFlashFvMainSize|0x00000000|UINT32|0x2000000B +gPlatformModuleTokenSpaceGuid.PcdFlashFvMainOffset|0x00000000|UINT32|0x2000000C +gPlatformModuleTokenSpaceGuid.PcdFlashFvMain2Base|0x00000000|UINT32|0x2000000D +gPlatformModuleTokenSpaceGuid.PcdFlashFvMain2Size|0x00000000|UINT32|0x2000000E +gPlatformModuleTokenSpaceGuid.PcdFlashFvMain2Offset|0x00000000|UINT32|0x2000000F +gPlatformModuleTokenSpaceGuid.PcdFlashFvFspWrapperBase|0x00000000|UINT32|0x20000013 +gPlatformModuleTokenSpaceGuid.PcdFlashFvFspWrapperSize|0x00000000|UINT32|0x20000014 +gPlatformModuleTokenSpaceGuid.PcdFlashNvStorageBase|0x00000000|UINT32|0x20000015 +gPlatformModuleTokenSpaceGuid.PcdFlashNvStorageSize|0x00000000|UINT32|0x20000016 +gPlatformModuleTokenSpaceGuid.PcdFlashNvStorageOffset|0x00000000|UINT32|0x20000017 +gPlatformModuleTokenSpaceGuid.PcdFlashNvStorageVariableOffset|0x00000000|UINT32|0x20000018 +gPlatformModuleTokenSpaceGuid.PcdFlashNvStorageFtwSpareOffset|0x00000000|UINT32|0x20000019 +gPlatformModuleTokenSpaceGuid.PcdFlashNvStorageFtwWorkingOffset|0x00000000|UINT32|0x2000001A +gPlatformModuleTokenSpaceGuid.PcdFlashFvFspmtBase|0x00000000|UINT32|0x20000021 +gPlatformModuleTokenSpaceGuid.PcdFlashFvFspmtSize|0x00000000|UINT32|0x20000022 +gPlatformModuleTokenSpaceGuid.PcdFlashFvFspmtOffset|0x00000000|UINT32|0x20000023 +gPlatformModuleTokenSpaceGuid.PcdFlashFvFspsBase|0x00000000|UINT32|0x20000024 +gPlatformModuleTokenSpaceGuid.PcdFlashFvFspsSize|0x00000000|UINT32|0x20000025 +gPlatformModuleTokenSpaceGuid.PcdFlashFvFspsOffset|0x00000000|UINT32|0x20000026 + +gPlatformModuleTokenSpaceGuid.PcdFspMaxUpdSize|0x00000000|UINT32|0x80000000 +gPlatformModuleTokenSpaceGuid.PcdFspReservedSizeOnStackTop|0x00000040|UINT32|0x80000001 +gPlatformModuleTokenSpaceGuid.PcdPeiPhaseStackTop|0x00000000|UINT32|0x80000002 + +gPlatformModuleTokenSpaceGuid.PcdApicLocalAddress|0xFEE00000|UINT64|0x9000000B +gPlatformModuleTokenSpaceGuid.PcdApicLocalMmioSize|0x1000|UINT32|0x9000000C + +gPlatformModuleTokenSpaceGuid.PcdApicIoAddress|0xFEC00000|UINT64|0x9000000D +gPlatformModuleTokenSpaceGuid.PcdApicIoMmioSize|0x1000|UINT32|0x9000000E + +gPlatformModuleTokenSpaceGuid.PcdAcpiEnableSwSmi|0xF0|UINT8|0x90000012 +gPlatformModuleTokenSpaceGuid.PcdAcpiDisableSwSmi|0xF1|UINT8|0x90000013 + +gPlatformModuleTokenSpaceGuid.PcdApicIoIdPch|0x02|UINT8|0x9000001E + +gPlatformModuleTokenSpaceGuid.PcdPlatformEfiAcpiReclaimMemorySize|0x65|UINT32|0x20000500 +gPlatformModuleTokenSpaceGuid.PcdPlatformEfiAcpiNvsMemorySize|0x30|UINT32|0x20000501 +gPlatformModuleTokenSpaceGuid.PcdPlatformEfiReservedMemorySize|0x402|UINT32|0x20000502 +gPlatformModuleTokenSpaceGuid.PcdPlatformEfiRtDataMemorySize|0x4b|UINT32|0x20000503 +gPlatformModuleTokenSpaceGuid.PcdPlatformEfiRtCodeMemorySize|0x25|UINT32|0x20000504 + +gPlatformModuleTokenSpaceGuid.PcdFspTemporaryRamSize|0x1000|UINT32|0x10001003 + +# +# The PCDs are used to control the Windows SMM Security Mitigations Table - Protection Flags +# +# BIT0: If set, expresses that for all synchronous SMM entries,SMM will validate that input and output buffers lie entirely within the expected fixed memory regions. +# BIT1: If set, expresses that for all synchronous SMM entries, SMM will validate that input and output pointers embedded within the fixed communication buffer only refer to address ranges \ +# that lie entirely within the expected fixed memory regions. +# BIT2: Firmware setting this bit is an indication that it will not allow reconfiguration of system resources via non-architectural mechanisms. +# BIT3-31: Reserved +# +gPlatformModuleTokenSpaceGuid.PcdWsmtProtectionFlags|0|UINT32|0x10001006 + +gPlatformModuleTokenSpaceGuid.PcdPreferredPmProfile|0x0|UINT8|0x00100205 + +# +# See HstiIbvFeatureBit.h for the definition +# +# #define HSTI_BYTE_ BIT +# +# It means BYTE BIT is for feature . +# +gPlatformModuleTokenSpaceGuid.PcdHstiIbvPlatformFeature|{0x00, 0x00, 0x00}|VOID*|0x00100301 + +# +# See TestPointCheckLib.h for the definition +# +# #define TEST_POINT_BYTE_ BIT +# +# It means BYTE BIT is for feature . +# +gPlatformModuleTokenSpaceGuid.PcdTestPointIbvPlatformFeature|{0x00, 0x07, 0x0F, 0x03}|VOID*|0x00100302 + +[PcdsDynamic] + +[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] + + ## + ## Allocate 56 KB [0x2000..0xFFFF] of I/O space for Pci Devices + ## If PcdPciReservedMemLimit =0 Pci Reserved default MMIO Limit is PciExpressBase else use PcdPciReservedMemLimit . + ## + gPlatformModuleTokenSpaceGuid.PcdPciReservedIobase |0x2000 |UINT16|0x40010041 + gPlatformModuleTokenSpaceGuid.PcdPciReservedIoLimit |0xFFFF |UINT16|0x40010042 + gPlatformModuleTokenSpaceGuid.PcdPciReservedMemBase |0x90000000 |UINT32|0x40010043 + gPlatformModuleTokenSpaceGuid.PcdPciReservedMemLimit |0x00000000 |UINT32|0x40010044 + gPlatformModuleTokenSpaceGuid.PcdPciReservedMemAbove4GBBase |0xFFFFFFFFFFFFFFFF |UINT64|0x40010045 + gPlatformModuleTokenSpaceGuid.PcdPciReservedMemAbove4GBLimit |0x0000000000000000 |UINT64|0x40010046 + gPlatformModuleTokenSpaceGuid.PcdPciReservedPMemBase |0xFFFFFFFF |UINT32|0x40010047 + gPlatformModuleTokenSpaceGuid.PcdPciReservedPMemLimit |0x00000000 |UINT32|0x40010048 + gPlatformModuleTokenSpaceGuid.PcdPciReservedPMemAbove4GBBase |0xFFFFFFFFFFFFFFFF |UINT64|0x40010049 + gPlatformModuleTokenSpaceGuid.PcdPciReservedPMemAbove4GBLimit|0x0000000000000000 |UINT64|0x4001004A + gPlatformModuleTokenSpaceGuid.PcdPciDmaAbove4G |FALSE|BOOLEAN|0x4001004B + gPlatformModuleTokenSpaceGuid.PcdPciNoExtendedConfigSpace |FALSE|BOOLEAN|0x4001004C + gPlatformModuleTokenSpaceGuid.PcdPciResourceAssigned |FALSE|BOOLEAN|0x4001004D + + gPlatformModuleTokenSpaceGuid.PcdLowPowerS0Idle|0|UINT8|0x40000006 + gPlatformModuleTokenSpaceGuid.PcdTenSecondPowerButtonEnable|0|UINT8|0x40000008 + gPlatformModuleTokenSpaceGuid.PcdPciExpNative|0|UINT8|0x40000004 + gPlatformModuleTokenSpaceGuid.PcdNativeAspmEnable|1|UINT8|0x40000005 + + gPlatformModuleTokenSpaceGuid.PcdAcpiPm1AEventBlockAddress|0x1800|UINT16|0x00010035 + gPlatformModuleTokenSpaceGuid.PcdAcpiPm1BEventBlockAddress|0x0000|UINT16|0x00010036 + gPlatformModuleTokenSpaceGuid.PcdAcpiPm1AControlBlockAddress|0x1804|UINT16|0x0001037 + gPlatformModuleTokenSpaceGuid.PcdAcpiPm1BControlBlockAddress|0x0000|UINT16|0x00010038 + gPlatformModuleTokenSpaceGuid.PcdAcpiPm2ControlBlockAddress|0x1850|UINT16|0x00010039 + gPlatformModuleTokenSpaceGuid.PcdAcpiPmTimerBlockAddress|0x1808|UINT16|0x0001003A + gPlatformModuleTokenSpaceGuid.PcdAcpiGpe0BlockAddress|0x1880|UINT16|0x0001003B + gPlatformModuleTokenSpaceGuid.PcdAcpiGpe1BlockAddress|0x0000|UINT16|0x0001003C + + gPlatformModuleTokenSpaceGuid.PcdPciExpressRegionLength|0x10000000|UINT32|0x0010004 + gPlatformModuleTokenSpaceGuid.PcdFspCpuPeiApWakeupBufferAddr|0x9f000|UINT32|0x30000008 + +[PcdsFeatureFlag] + # + # Stage 1 - enable debug (system deadloop after debug init) + # Stage 2 - mem init (system deadloop after mem init) + # Stage 3 - boot to shell only + # Stage 4 - boot to OS + # Stage 5 - boot to OS with security boot enabled + # + gPlatformModuleTokenSpaceGuid.PcdBootStage|4|UINT8|0xF00000A0 + + gPlatformModuleTokenSpaceGuid.PcdStopAfterDebugInit |FALSE|BOOLEAN|0xF00000A1 + gPlatformModuleTokenSpaceGuid.PcdStopAfterMemInit |FALSE|BOOLEAN|0xF00000A2 + gPlatformModuleTokenSpaceGuid.PcdBootToShellOnly |FALSE|BOOLEAN|0xF00000A3 + gPlatformModuleTokenSpaceGuid.PcdUefiSecureBootEnable|FALSE|BOOLEAN|0xF00000A4 + gPlatformModuleTokenSpaceGuid.PcdTpm2Enable |FALSE|BOOLEAN|0xF00000A5 diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc new file mode 100644 index 0000000000..949cf159a4 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc @@ -0,0 +1,180 @@ +## @file +# Platform description. +# +# 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 which 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. +# +## + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + PLATFORM_NAME = MinPlatformPkg + PLATFORM_GUID = 8FE55D15-3ABF-4175-8169-74B87E5CD175 + PLATFORM_VERSION = 0.1 + DSC_SPECIFICATION = 0x00010005 + OUTPUT_DIRECTORY = Build/MinPlatformPkg + SUPPORTED_ARCHITECTURES = IA32|X64 + BUILD_TARGETS = DEBUG|RELEASE + SKUID_IDENTIFIER = DEFAULT + +################################################################################ +# +# SKU Identification section - list of all SKU IDs supported by this +# Platform. +# +################################################################################ +[SkuIds] + 0|DEFAULT # The entry: 0|DEFAULT is reserved and always required. + +################################################################################ +# +# Pcd Section - list of all EDK II PCD Entries defined by this Platform +# +################################################################################ + +[PcdsFeatureFlag] + # configuration + gPlatformModuleTokenSpaceGuid.PcdBootToShellOnly|FALSE + gPlatformModuleTokenSpaceGuid.PcdUefiSecureBootEnable|FALSE + gPlatformModuleTokenSpaceGuid.PcdTpm2Enable|FALSE + +################################################################################ +# +# Library Class section - list of all Library Classes needed by this Platform. +# +################################################################################ + +!include MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc +!include MinPlatformPkg/Include/Dsc/CorePeiLib.dsc +!include MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc + +[LibraryClasses.common] + # + # Platform + # + PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf + PciHostBridgeLib|MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.inf + PlatformBootManagerLib|MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf + AslUpdateLib|MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.inf + + # + # Misc + # + FspWrapperApiLib|IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/BaseFspWrapperApiLib.inf + FspWrapperApiTestLib|IntelFsp2WrapperPkg/Library/PeiFspWrapperApiTestLib/PeiFspWrapperApiTestLib.inf + FspWrapperHobProcessLib|MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.inf + PlatformSecLib|MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf + + FspWrapperPlatformLib|MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.inf + + BoardInitLib|MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLibNull.inf + BoardAcpiTableLib|MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLibNull.inf + BoardAcpiEnableLib|MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLibNull.inf + TestPointCheckLib|MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.inf + +[LibraryClasses.common.SEC] + TestPointCheckLib|MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.inf + +[LibraryClasses.common.PEIM] + # + # PEI phase common + # + FspWrapperPlatformResetLib|MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.inf + TestPointCheckLib|MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf + TestPointLib|MinPlatformPkg/Test/Library/TestPointLib/PeiTestPointLib.inf + +[LibraryClasses.common.DXE_DRIVER] + # + # DXE phase common + # + FspWrapperPlatformLib|MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.inf + TestPointCheckLib|MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf + TestPointLib|MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointLib.inf + +[LibraryClasses.common.DXE_SMM_DRIVER] + SpiFlashCommonLib|MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.inf + TestPointCheckLib|MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.inf + TestPointLib|MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointLib.inf + +################################################################################################### +# +# Components Section - list of the modules and components that will be processed by compilation +# tools and the EDK II tools to generate PE32/PE32+/Coff image files. +# +# Note: The EDK II DSC file is not used to specify how compiled binary images get placed +# into firmware volume images. This section is just a list of modules to compile from +# source into UEFI-compliant binaries. +# It is the FDF file that contains information on combining binary files into firmware +# volume images, whose concept is beyond UEFI and is described in PI specification. +# Binary modules do not need to be listed in this section, as they should be +# specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi), +# Logo (Logo.bmp), and etc. +# There may also be modules listed in this section that are not required in the FDF file, +# When a module listed here is excluded from FDF file, then UEFI-compliant binary will be +# generated for it, but the binary will not be put into any firmware volume. +# +################################################################################################### + +[Components] + + MinPlatformPkg/Library/PeiLib/PeiLib.inf + MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFce.inf + MinPlatformPkg/Library/PeiHobVariableLibFce/PeiHobVariableLibFceOptSize.inf + + MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf + MinPlatformPkg/Acpi/AcpiSmm/AcpiSmm.inf + MinPlatformPkg/Acpi/Library/DxeAslUpdateLib/DxeAslUpdateLib.inf + MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiEnableLibNull.inf + MinPlatformPkg/Acpi/Library/BoardAcpiLibNull/BoardAcpiTableLibNull.inf + MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/DxeMultiBoardAcpiSupportLib.inf + MinPlatformPkg/Acpi/Library/MultiBoardAcpiSupportLib/SmmMultiBoardAcpiSupportLib.inf + + MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf + + MinPlatformPkg/Flash/SpiFvbService/SpiFvbServiceSmm.inf + MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/SpiFlashCommonLibNull.inf + + MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf + MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.inf + MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf + MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.inf + MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformResetLib/DxeFspWrapperPlatformResetLib.inf + MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformResetLib/PeiFspWrapperPlatformResetLib.inf + + MinPlatformPkg/Hsti/HstiIbvPlatformDxe/HstiIbvPlatformDxe.inf + + MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.inf + + MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPreMem.inf + MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPostMem.inf + MinPlatformPkg/PlatformInit/PlatformInitDxe/PlatformInitDxe.inf + MinPlatformPkg/PlatformInit/PlatformInitSmm/PlatformInitSmm.inf + MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/SecBoardInitLibNull.inf + MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLibNull.inf + MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.inf + MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.inf + + MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.inf + MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.inf + MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf + MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf + MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointLib.inf + MinPlatformPkg/Test/Library/TestPointLib/PeiTestPointLib.inf + MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointLib.inf + MinPlatformPkg/Test/TestPointDumpApp/TestPointDumpApp.inf + +!if gPlatformModuleTokenSpaceGuid.PcdTpm2Enable == TRUE + MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf + MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf +!endif diff --git a/Platform/Intel/MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.c b/Platform/Intel/MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.c new file mode 100644 index 0000000000..557ac2a5b3 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.c @@ -0,0 +1,166 @@ +/** @file + SA PciHostBridge Library + +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 + +GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] = { + L"Mem", L"I/O", L"Bus" +}; +ACPI_HID_DEVICE_PATH mRootBridgeDeviceNode = { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) + } + }, + EISA_PNP_ID (0x0A03), + 0 +}; + +PCI_ROOT_BRIDGE mRootBridge = { + 0, + EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO | + EFI_PCI_ATTRIBUTE_IDE_PRIMARY_IO | + EFI_PCI_ATTRIBUTE_ISA_IO | + EFI_PCI_ATTRIBUTE_ISA_IO_16 | + EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO | + EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16 | + EFI_PCI_ATTRIBUTE_VGA_MEMORY | + EFI_PCI_ATTRIBUTE_VGA_IO | + EFI_PCI_ATTRIBUTE_VGA_IO_16, // Supports; + 0, // Attributes; + FALSE, // DmaAbove4G; + FALSE, // NoExtendedConfigSpace; + FALSE, // ResourceAssigned; + EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM, // AllocationAttributes + { 0, 255 }, // Bus + { 0, 0 }, // Io - to be fixed later + { 0, 0 }, // Mem - to be fixed later + { 0, 0 }, // MemAbove4G - to be fixed later + { 0, 0 }, // PMem - COMBINE_MEM_PMEM indicating no PMem and PMemAbove4GB + { 0, 0 }, // PMemAbove4G + NULL // DevicePath; +}; + +PCI_ROOT_BRIDGE * +EFIAPI +PciHostBridgeGetRootBridges ( + UINTN *Count + ) +{ + mRootBridge.Mem.Base = PcdGet32 (PcdPciReservedMemBase); + if (PcdGet32(PcdPciReservedMemLimit) != 0) { + mRootBridge.Mem.Limit = PcdGet32 (PcdPciReservedMemLimit); + } else { + mRootBridge.Mem.Limit = (UINT32)PcdGet64 (PcdPciExpressBaseAddress); + } + + mRootBridge.MemAbove4G.Base = PcdGet64 (PcdPciReservedMemAbove4GBBase); + mRootBridge.MemAbove4G.Limit = PcdGet64 (PcdPciReservedMemAbove4GBLimit); + + mRootBridge.PMem.Base = PcdGet32 (PcdPciReservedPMemBase); + mRootBridge.PMem.Limit = PcdGet32 (PcdPciReservedPMemLimit); + mRootBridge.PMemAbove4G.Base = PcdGet64 (PcdPciReservedPMemAbove4GBBase); + mRootBridge.PMemAbove4G.Limit = PcdGet64 (PcdPciReservedPMemAbove4GBLimit); + + if (mRootBridge.MemAbove4G.Base < mRootBridge.MemAbove4G.Limit) { + mRootBridge.AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE; + } + + mRootBridge.Io.Base = PcdGet16 (PcdPciReservedIobase); + mRootBridge.Io.Limit = PcdGet16 (PcdPciReservedIoLimit); + + mRootBridge.DmaAbove4G = PcdGetBool (PcdPciDmaAbove4G); + mRootBridge.NoExtendedConfigSpace = PcdGetBool (PcdPciNoExtendedConfigSpace); + mRootBridge.ResourceAssigned = PcdGetBool (PcdPciResourceAssigned); + + mRootBridge.DevicePath = AppendDevicePathNode (NULL, &mRootBridgeDeviceNode.Header); + *Count = 1; + return &mRootBridge; +} + +VOID +EFIAPI +PciHostBridgeFreeRootBridges ( + PCI_ROOT_BRIDGE *Bridges, + UINTN Count + ) +{ + ASSERT (Count == 1); + FreePool (Bridges->DevicePath); +} + +/** + Inform the platform that the resource conflict happens. + + @param HostBridgeHandle Handle of the Host Bridge. + @param Configuration Pointer to PCI I/O and PCI memory resource descriptors. + The Configuration contains the resources for all the + root bridges. The resource for each root bridge is + terminated with END descriptor and an additional END + is appended indicating the end of the whole resources. + The resource descriptor field values follow the description + in EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL.SubmitResources(). +**/ + +VOID +EFIAPI +PciHostBridgeResourceConflict ( + EFI_HANDLE HostBridgeHandle, + VOID *Configuration + ) +{ + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; + UINTN RootBridgeIndex; + DEBUG ((EFI_D_ERROR, "PciHostBridge: Resource conflict happens!\n")); + + RootBridgeIndex = 0; + Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration; + while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) { + DEBUG ((EFI_D_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++)); + for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) { + ASSERT (Descriptor->ResType < + sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr) / sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr[0]) + ); + DEBUG ((EFI_D_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n", + mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType], Descriptor->AddrLen, Descriptor->AddrRangeMax)); + if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) { + DEBUG ((EFI_D_ERROR, " Granularity/SpecificFlag = %ld / %02x%s\n", + Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag, + ((Descriptor->SpecificFlag & EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE) != 0) ? L" (Prefetchable)" : L"" + )); + } + } + // + // Skip the END descriptor for root bridge + // + ASSERT (Descriptor->Desc == ACPI_END_TAG_DESCRIPTOR); + Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) ((EFI_ACPI_END_TAG_DESCRIPTOR *) Descriptor + 1); + } + + ASSERT (FALSE); +} diff --git a/Platform/Intel/MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.inf b/Platform/Intel/MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.inf new file mode 100644 index 0000000000..631de8e6b6 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Pci/Library/PciHostBridgeLibSimple/PciHostBridgeLibSimple.inf @@ -0,0 +1,59 @@ +## @file +# Component description file for the SA PciHostBridge library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PciHostBridgeLibSimple + FILE_GUID = F24CC210-DAD9-44E1-9F7E-B1CE05D22A36 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = PciHostBridgeLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources] + PciHostBridgeLibSimple.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[LibraryClasses] + DebugLib + DevicePathLib + BaseMemoryLib + BaseLib + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress + gPlatformModuleTokenSpaceGuid.PcdPciReservedIobase + gPlatformModuleTokenSpaceGuid.PcdPciReservedIoLimit + gPlatformModuleTokenSpaceGuid.PcdPciReservedMemBase + gPlatformModuleTokenSpaceGuid.PcdPciReservedMemLimit + gPlatformModuleTokenSpaceGuid.PcdPciReservedMemAbove4GBBase + gPlatformModuleTokenSpaceGuid.PcdPciReservedMemAbove4GBLimit + gPlatformModuleTokenSpaceGuid.PcdPciReservedPMemBase + gPlatformModuleTokenSpaceGuid.PcdPciReservedPMemLimit + gPlatformModuleTokenSpaceGuid.PcdPciReservedPMemAbove4GBBase + gPlatformModuleTokenSpaceGuid.PcdPciReservedPMemAbove4GBLimit + gPlatformModuleTokenSpaceGuid.PcdPciDmaAbove4G + gPlatformModuleTokenSpaceGuid.PcdPciNoExtendedConfigSpace + gPlatformModuleTokenSpaceGuid.PcdPciResourceAssigned + diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLib.c new file mode 100644 index 0000000000..f680fc27ce --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLib.c @@ -0,0 +1,124 @@ +/** @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 + +EFI_STATUS +EFIAPI +BoardDetect ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardDebugInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_BOOT_MODE +EFIAPI +BoardBootModeDetect ( + VOID + ) +{ + return BOOT_WITH_FULL_CONFIGURATION; +} + +EFI_STATUS +EFIAPI +BoardInitBeforeMemoryInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitAfterMemoryInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitBeforeTempRamExit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitAfterTempRamExit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitBeforeSiliconInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitAfterSiliconInit ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitAfterPciEnumeration ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitReadyToBoot ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitEndOfFirmware ( + VOID + ) +{ + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLibNull.inf b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLibNull.inf new file mode 100644 index 0000000000..65a445b0f7 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/BoardInitLibNull/BoardInitLibNull.inf @@ -0,0 +1,36 @@ +## @file +# Component information file for Board Init Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BoardInitLib + FILE_GUID = 71B4AEBA-6CBA-442F-912E-E1851B21F106 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = BoardInitLib + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + +[Sources] + BoardInitLib.c + +[Pcd] diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeBoardInitLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeBoardInitLib.c new file mode 100644 index 0000000000..13c623c640 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeBoardInitLib.c @@ -0,0 +1,84 @@ +/** @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 + +EFI_STATUS +EFIAPI +BoardInitAfterPciEnumeration ( + VOID + ) +{ + BOARD_NOTIFICATION_INIT_FUNC *BoardNotificationInit; + EFI_STATUS Status; + + Status = gBS->LocateProtocol ( + &gBoardNotificationInitGuid, + NULL, + (VOID **)&BoardNotificationInit + ); + if (!EFI_ERROR(Status)) { + if (BoardNotificationInit->BoardInitAfterPciEnumeration != NULL) { + return BoardNotificationInit->BoardInitAfterPciEnumeration (); + } + } + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitReadyToBoot ( + VOID + ) +{ + BOARD_NOTIFICATION_INIT_FUNC *BoardNotificationInit; + EFI_STATUS Status; + + Status = gBS->LocateProtocol ( + &gBoardNotificationInitGuid, + NULL, + (VOID **)&BoardNotificationInit + ); + if (!EFI_ERROR(Status)) { + if (BoardNotificationInit->BoardInitReadyToBoot != NULL) { + return BoardNotificationInit->BoardInitReadyToBoot (); + } + } + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitEndOfFirmware ( + VOID + ) +{ + BOARD_NOTIFICATION_INIT_FUNC *BoardNotificationInit; + EFI_STATUS Status; + + Status = gBS->LocateProtocol ( + &gBoardNotificationInitGuid, + NULL, + (VOID **)&BoardNotificationInit + ); + if (!EFI_ERROR(Status)) { + if (BoardNotificationInit->BoardInitEndOfFirmware != NULL) { + return BoardNotificationInit->BoardInitEndOfFirmware (); + } + } + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c new file mode 100644 index 0000000000..f7a4c5b5a1 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c @@ -0,0 +1,39 @@ +/** @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 + +EFI_STATUS +EFIAPI +RegisterBoardNotificationInit ( + IN BOARD_NOTIFICATION_INIT_FUNC *BoardNotificationInit + ) +{ + EFI_HANDLE Handle; + EFI_STATUS Status; + + Handle = NULL; + Status = gBS->InstallProtocolInterface ( + &Handle, + &gBoardNotificationInitGuid, + EFI_NATIVE_INTERFACE, + BoardNotificationInit + ); + ASSERT_EFI_ERROR(Status); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.inf b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.inf new file mode 100644 index 0000000000..188c98db0a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.inf @@ -0,0 +1,42 @@ +## @file +# Component information file for Board Init Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeMultiBoardInitSupportLib + FILE_GUID = 4790240A-F86D-4E91-BA4C-7E24B9AC393B + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = MultiBoardInitSupportLib + LIBRARY_CLASS = BoardInitLib + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + UefiBootServicesTableLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + +[Sources] + DxeMultiBoardInitSupportLib.c + DxeBoardInitLib.c + +[Guids] + gBoardNotificationInitGuid + +[Pcd] diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiBoardInitLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiBoardInitLib.c new file mode 100644 index 0000000000..9bfe1551fb --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiBoardInitLib.c @@ -0,0 +1,229 @@ +/** @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 + +EFI_STATUS +EFIAPI +BoardDetect ( + VOID + ) +{ + BOARD_DETECT_FUNC *BoardDetectFunc; + UINTN Index; + EFI_STATUS Status; + + for (Index = 0; ; Index++) { + Status = PeiServicesLocatePpi( + &gBoardDetectGuid, + Index, + NULL, + (VOID **)&BoardDetectFunc + ); + if (EFI_ERROR(Status)) { + break; + } + if (BoardDetectFunc->BoardDetect != NULL) { + BoardDetectFunc->BoardDetect (); + } + } + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardDebugInit ( + VOID + ) +{ + BOARD_PRE_MEM_INIT_FUNC *BoardPreMemInit; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi( + &gBoardPreMemInitGuid, + 0, + NULL, + (VOID **)&BoardPreMemInit + ); + if (!EFI_ERROR(Status)) { + if (BoardPreMemInit->BoardDebugInit != NULL) { + return BoardPreMemInit->BoardDebugInit (); + } + } + return EFI_SUCCESS; +} + +EFI_BOOT_MODE +EFIAPI +BoardBootModeDetect ( + VOID + ) +{ + BOARD_PRE_MEM_INIT_FUNC *BoardPreMemInit; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi( + &gBoardPreMemInitGuid, + 0, + NULL, + (VOID **)&BoardPreMemInit + ); + if (!EFI_ERROR(Status)) { + if (BoardPreMemInit->BoardBootModeDetect != NULL) { + return BoardPreMemInit->BoardBootModeDetect (); + } + } + return BOOT_WITH_FULL_CONFIGURATION; +} + +EFI_STATUS +EFIAPI +BoardInitBeforeMemoryInit ( + VOID + ) +{ + BOARD_PRE_MEM_INIT_FUNC *BoardPreMemInit; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi( + &gBoardPreMemInitGuid, + 0, + NULL, + (VOID **)&BoardPreMemInit + ); + if (!EFI_ERROR(Status)) { + if (BoardPreMemInit->BoardInitBeforeMemoryInit != NULL) { + return BoardPreMemInit->BoardInitBeforeMemoryInit (); + } + } + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitAfterMemoryInit ( + VOID + ) +{ + BOARD_PRE_MEM_INIT_FUNC *BoardPreMemInit; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi( + &gBoardPreMemInitGuid, + 0, + NULL, + (VOID **)&BoardPreMemInit + ); + if (!EFI_ERROR(Status)) { + if (BoardPreMemInit->BoardInitAfterMemoryInit != NULL) { + return BoardPreMemInit->BoardInitAfterMemoryInit (); + } + } + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitBeforeTempRamExit ( + VOID + ) +{ + BOARD_PRE_MEM_INIT_FUNC *BoardPreMemInit; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi( + &gBoardPreMemInitGuid, + 0, + NULL, + (VOID **)&BoardPreMemInit + ); + if (!EFI_ERROR(Status)) { + if (BoardPreMemInit->BoardInitBeforeTempRamExit != NULL) { + return BoardPreMemInit->BoardInitBeforeTempRamExit (); + } + } + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitAfterTempRamExit ( + VOID + ) +{ + BOARD_PRE_MEM_INIT_FUNC *BoardPreMemInit; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi( + &gBoardPreMemInitGuid, + 0, + NULL, + (VOID **)&BoardPreMemInit + ); + if (!EFI_ERROR(Status)) { + if (BoardPreMemInit->BoardInitAfterTempRamExit != NULL) { + return BoardPreMemInit->BoardInitAfterTempRamExit (); + } + } + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitBeforeSiliconInit ( + VOID + ) +{ + BOARD_POST_MEM_INIT_FUNC *BoardPostMemInit; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi( + &gBoardPostMemInitGuid, + 0, + NULL, + (VOID **)&BoardPostMemInit + ); + if (!EFI_ERROR(Status)) { + if (BoardPostMemInit->BoardInitBeforeSiliconInit != NULL) { + return BoardPostMemInit->BoardInitBeforeSiliconInit (); + } + } + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +BoardInitAfterSiliconInit ( + VOID + ) +{ + BOARD_POST_MEM_INIT_FUNC *BoardPostMemInit; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi( + &gBoardPostMemInitGuid, + 0, + NULL, + (VOID **)&BoardPostMemInit + ); + if (!EFI_ERROR(Status)) { + if (BoardPostMemInit->BoardInitAfterSiliconInit != NULL) { + return BoardPostMemInit->BoardInitAfterSiliconInit (); + } + } + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c new file mode 100644 index 0000000000..2056782181 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c @@ -0,0 +1,82 @@ +/** @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 + +EFI_STATUS +EFIAPI +RegisterBoardDetect ( + IN BOARD_DETECT_FUNC *BoardDetect + ) +{ + EFI_STATUS Status; + EFI_PEI_PPI_DESCRIPTOR *PpiListBoardDetect; + + PpiListBoardDetect = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR)); + ASSERT (PpiListBoardDetect != NULL); + + PpiListBoardDetect->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST); + PpiListBoardDetect->Guid = &gBoardDetectGuid; + PpiListBoardDetect->Ppi = BoardDetect; + + Status = PeiServicesInstallPpi (PpiListBoardDetect); + ASSERT_EFI_ERROR(Status); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +RegisterBoardPreMemInit ( + IN BOARD_PRE_MEM_INIT_FUNC *BoardPreMemInit + ) +{ + EFI_STATUS Status; + EFI_PEI_PPI_DESCRIPTOR *PpiListBoardInitPreMem; + + PpiListBoardInitPreMem = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR)); + ASSERT (PpiListBoardInitPreMem != NULL); + + PpiListBoardInitPreMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST); + PpiListBoardInitPreMem->Guid = &gBoardPreMemInitGuid; + PpiListBoardInitPreMem->Ppi = BoardPreMemInit; + + Status = PeiServicesInstallPpi (PpiListBoardInitPreMem); + ASSERT_EFI_ERROR(Status); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +RegisterBoardPostMemInit ( + IN BOARD_POST_MEM_INIT_FUNC *BoardPostMemInit + ) +{ + EFI_STATUS Status; + EFI_PEI_PPI_DESCRIPTOR *PpiListBoardInitPostMem; + + PpiListBoardInitPostMem = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR)); + ASSERT (PpiListBoardInitPostMem != NULL); + + PpiListBoardInitPostMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST); + PpiListBoardInitPostMem->Guid = &gBoardPostMemInitGuid; + PpiListBoardInitPostMem->Ppi = BoardPostMemInit; + + Status = PeiServicesInstallPpi (PpiListBoardInitPostMem); + ASSERT_EFI_ERROR(Status); + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.inf b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.inf new file mode 100644 index 0000000000..de769bf504 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.inf @@ -0,0 +1,44 @@ +## @file +# Component information file for Board Init Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiMultiBoardInitSupportLib + FILE_GUID = E0238683-D3FD-4D97-8874-37C6157E2906 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = MultiBoardInitSupportLib + LIBRARY_CLASS = BoardInitLib + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + +[Sources] + PeiMultiBoardInitSupportLib.c + PeiBoardInitLib.c + +[Guids] + gBoardDetectGuid + gBoardPreMemInitGuid + gBoardPostMemInitGuid + gBoardNotificationInitGuid + +[Pcd] diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/Ia32/SecBoardInit.nasm b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/Ia32/SecBoardInit.nasm new file mode 100644 index 0000000000..71bf82933b --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/Ia32/SecBoardInit.nasm @@ -0,0 +1,32 @@ +; +; This file contains an 'Intel Peripheral Driver' and is +; licensed for Intel CPUs and chipsets under the terms of your +; license agreement with Intel or your vendor. This file may +; be modified by the user, subject to additional terms of the +; license agreement +;; @file +; This is the code that goes from real-mode to protected mode. +; It consumes the reset vector, calls TempRamInit API from FSP binary. +; +; 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. +; +;; + +SECTION .text + +global ASM_PFX(BoardBeforeTempRamInit) +ASM_PFX(BoardBeforeTempRamInit): + ; + ; This hook is called before FSP TempRamInit API call + ; ESI, EDI need to be preserved + ; ESP contains return address + ; + jmp esp + diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/SecBoardInitLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/SecBoardInitLib.c new file mode 100644 index 0000000000..990e9c9b3a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/SecBoardInitLib.c @@ -0,0 +1,25 @@ +/** @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 + +EFI_STATUS +EFIAPI +BoardAfterTempRamInit ( + VOID + ) +{ + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/SecBoardInitLibNull.inf b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/SecBoardInitLibNull.inf new file mode 100644 index 0000000000..186814925a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/SecBoardInitLibNull/SecBoardInitLibNull.inf @@ -0,0 +1,40 @@ +## @file +# Component information file for SEC Board Init Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SecBoardInitLibNull + FILE_GUID = B9DC6910-67E0-4FCE-A1A4-675115E71455 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = SecBoardInitLib + +[Sources.IA32] + Ia32/SecBoardInit.nasm + +[Sources] + SecBoardInitLib.c + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + IntelFsp2Pkg/IntelFsp2Pkg.dec + +[LibraryClasses] + BaseLib + +[Guids] + +[Pcd] diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitDxe/PlatformInitDxe.c b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitDxe/PlatformInitDxe.c new file mode 100644 index 0000000000..c8eca1c613 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitDxe/PlatformInitDxe.c @@ -0,0 +1,400 @@ +/** @file + This driver will register two callbacks to call fsp's notifies. + + Copyright (c) 2014 - 2016, 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 + which 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 +PlatformInitUnRegisterRscHandler ( + VOID + ); + +/** + PciEnumerationComplete Protocol notification event handler. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +OnPciEnumerationComplete ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + VOID *Interface; + + // + // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration. + // Just return if it is not found. + // + Status = gBS->LocateProtocol ( + &gEfiPciEnumerationCompleteProtocolGuid, + NULL, + &Interface + ); + if (EFI_ERROR (Status)) { + return ; + } + + Status = BoardInitAfterPciEnumeration (); + ASSERT_EFI_ERROR(Status); + + TestPointPciEnumerationDone (); +} + +/** + This stage is notified when system exists platform manufacture authentication. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context, which is + always zero in current implementation. + +**/ +VOID +EFIAPI +OnEndOfDxe ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + gBS->CloseEvent (Event); + + TestPointEndOfDxe (); +} + +/** + SmmReadyToLock Protocol notification event handler. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +OnDxeSmmReadyToLock ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + VOID *Interface; + + // + // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration. + // Just return if it is not found. + // + Status = gBS->LocateProtocol ( + &gEfiDxeSmmReadyToLockProtocolGuid, + NULL, + &Interface + ); + if (EFI_ERROR (Status)) { + return ; + } + + TestPointDxeSmmReadyToLock (); +} + +/** + Notification function of EVT_GROUP_READY_TO_BOOT event group. + + This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group. + When the Boot Manager is about to load and execute a boot option, it reclaims variable + storage if free size is below the threshold. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. + +**/ +VOID +EFIAPI +OnReadyToBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + gBS->CloseEvent (Event); + + Status = BoardInitReadyToBoot (); + ASSERT_EFI_ERROR(Status); +} + +/** + This stage is notified just before the firmware/Preboot environment transfers + management of all system resources to the OS or next level execution environment. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context, which is + always zero in current implementation. + +**/ +VOID +EFIAPI +OnEndOfFirmware ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + gBS->CloseEvent (Event); + + PlatformInitUnRegisterRscHandler (); + + Status = BoardInitEndOfFirmware (); + ASSERT_EFI_ERROR(Status); + + TestPointExitBootServices (); +} + +/** + Main entry for the FSP DXE module. + + This routine registers two callbacks to call fsp's notifies. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +BoardNotificationInitEntryPoint ( + VOID + ) +{ + EFI_STATUS Status; + EFI_EVENT ReadyToBootEvent; + VOID *Registration; + EFI_EVENT ProtocolNotifyEvent; + EFI_EVENT ExitBootServicesEvent; + EFI_EVENT EndOfDxeEvent; + VOID *SmmReadyToLockRegistration; + EFI_EVENT SmmReadyToLockEvent; + + ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent ( + &gEfiPciEnumerationCompleteProtocolGuid, + TPL_CALLBACK, + OnPciEnumerationComplete, + NULL, + &Registration + ); + ASSERT (ProtocolNotifyEvent != NULL); + + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + OnEndOfDxe, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &EndOfDxeEvent + ); + ASSERT_EFI_ERROR (Status); + + SmmReadyToLockEvent = EfiCreateProtocolNotifyEvent ( + &gEfiDxeSmmReadyToLockProtocolGuid, + TPL_CALLBACK, + OnDxeSmmReadyToLock, + NULL, + &SmmReadyToLockRegistration + ); + + Status = EfiCreateEventReadyToBootEx ( + TPL_CALLBACK, + OnReadyToBoot, + NULL, + &ReadyToBootEvent + ); + ASSERT_EFI_ERROR (Status); + + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + OnEndOfFirmware, + NULL, + &gEfiEventExitBootServicesGuid, + &ExitBootServicesEvent + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +EFI_EVENT mRscNotifyEvent = NULL; +EFI_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL; + +/** + Report status code listener + for OsLoaderLoadImageStart and OsLoaderStartImageStart. + + @param[in] CodeType Indicates the type of status code being reported. + @param[in] Value Describes the current status of a hardware or software entity. + This included information about the class and subclass that is used to + classify the entity as well as an operation. + @param[in] Instance The enumeration of a hardware or software entity within + the system. Valid instance numbers start with 1. + @param[in] CallerId This optional parameter may be used to identify the caller. + This parameter allows the status code driver to apply different rules to + different callers. + @param[in] Data This optional parameter may be used to pass additional data. + + @retval EFI_SUCCESS Status code is what we expected. + @retval EFI_UNSUPPORTED Status code not supported. + +**/ +EFI_STATUS +EFIAPI +PlatformInitStatusCodeListener ( + IN EFI_STATUS_CODE_TYPE CodeType, + IN EFI_STATUS_CODE_VALUE Value, + IN UINT32 Instance, + IN EFI_GUID *CallerId, + IN EFI_STATUS_CODE_DATA *Data + ) +{ + EFI_STATUS Status; + + // + // Check whether status code is what we are interested in. + // + if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) { + return EFI_UNSUPPORTED; + } + + Status = EFI_SUCCESS; + if (Value == (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)) { + TestPointReadyToBoot (); + } else if (Value == PcdGet32 (PcdProgressCodeOsLoaderLoad)) { + } else if (Value == PcdGet32 (PcdProgressCodeOsLoaderStart)) { + } else if (Value == (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)) { + PlatformInitUnRegisterRscHandler (); + } else if (Value == (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_LEGACY_BOOT_EVENT)) { + } else { + // + // Ignore else progress code. + // + Status = EFI_UNSUPPORTED; + } + + return Status; +} + +/** + RscHandler Protocol notification event handler. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +OnRscHandlerInstalled ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + Status = gBS->LocateProtocol ( + &gEfiRscHandlerProtocolGuid, + NULL, + &mRscHandlerProtocol + ); + if (EFI_ERROR (Status)) { + return ; + } + + // + // Register report status code listener for OS Loader load and start. + // + Status = mRscHandlerProtocol->Register (PlatformInitStatusCodeListener, TPL_HIGH_LEVEL); + ASSERT_EFI_ERROR (Status); + + gBS->CloseEvent (mRscNotifyEvent); + mRscNotifyEvent = NULL; +} + +EFI_STATUS +PlatformInitRegisterRscHandler ( + VOID + ) +{ + VOID *Registration; + + mRscNotifyEvent = EfiCreateProtocolNotifyEvent ( + &gEfiRscHandlerProtocolGuid, + TPL_CALLBACK, + OnRscHandlerInstalled, + NULL, + &Registration + ); + ASSERT (mRscNotifyEvent != NULL); + + return EFI_SUCCESS; +} + +EFI_STATUS +PlatformInitUnRegisterRscHandler ( + VOID + ) +{ + if (mRscHandlerProtocol != NULL) { + mRscHandlerProtocol->Unregister (PlatformInitStatusCodeListener); + mRscHandlerProtocol = NULL; + } + if (mRscNotifyEvent != NULL) { + gBS->CloseEvent (mRscNotifyEvent); + mRscNotifyEvent = NULL; + } + return EFI_SUCCESS; +} + +/** + Initialize DXE Platform. + + @param[in] ImageHandle Image handle of this driver. + @param[in] SystemTable Global system service table. + + @retval EFI_SUCCESS Initialization complete. + @exception EFI_UNSUPPORTED The chipset is unsupported by this driver. + @retval EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver. + @retval EFI_DEVICE_ERROR Device error, driver exits abnormally. +**/ +EFI_STATUS +EFIAPI +PlatformInitDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + PlatformInitRegisterRscHandler (); + BoardNotificationInitEntryPoint (); + + return EFI_SUCCESS; +} \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitDxe/PlatformInitDxe.inf b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitDxe/PlatformInitDxe.inf new file mode 100644 index 0000000000..e64d62c756 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitDxe/PlatformInitDxe.inf @@ -0,0 +1,60 @@ +### @file +# Module Information file for the PlatformInit DXE driver. +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = PlatformInitDxe + FILE_GUID = CA84408A-0929-4F11-BFED-18C7D9576C6B + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + ENTRY_POINT = PlatformInitDxeEntryPoint + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DxeServicesTableLib + MemoryAllocationLib + PcdLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + UefiRuntimeServicesTableLib + BoardInitLib + TestPointCheckLib + +[Packages] + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + PlatformInitDxe.c + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad + gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart + +[Protocols] + gEfiPciEnumerationCompleteProtocolGuid + gEfiDxeSmmReadyToLockProtocolGuid + gEfiRscHandlerProtocolGuid + +[Guids] + gEfiEventExitBootServicesGuid + gEfiEndOfDxeEventGroupGuid + +[Depex] + TRUE diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPostMem.c b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPostMem.c new file mode 100644 index 0000000000..e8c3485186 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPostMem.c @@ -0,0 +1,228 @@ +/** @file + Source code file for Platform Init PEI module + +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 +EFIAPI +PlatformInitEndOfPei ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ); + +static EFI_PEI_NOTIFY_DESCRIPTOR mEndOfPeiNotifyList = { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiEndOfPeiSignalPpiGuid, + (EFI_PEIM_NOTIFY_ENTRY_POINT) PlatformInitEndOfPei +}; + +/** + Update MTRR setting and set write back as default memory attribute. + + @retval EFI_SUCCESS The function completes successfully. + @retval Others Some error occurs. +**/ +EFI_STATUS +EFIAPI +SetCacheMtrrAfterEndOfPei ( + VOID + ) +{ + EFI_STATUS Status; + MTRR_SETTINGS MtrrSetting; + EFI_PEI_HOB_POINTERS Hob; + UINT64 MemoryBase; + UINT64 MemoryLength; + UINT64 Power2Length; + EFI_BOOT_MODE BootMode; + UINTN Index; + UINT64 SmramSize; + UINT64 SmramBase; + EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; + Status = PeiServicesGetBootMode (&BootMode); + ASSERT_EFI_ERROR (Status); + + if (BootMode == BOOT_ON_S3_RESUME) { + return EFI_SUCCESS; + } + // + // Clear the CAR Settings + // + ZeroMem(&MtrrSetting, sizeof(MTRR_SETTINGS)); + + // + // Default Cachable attribute will be set to WB to support large memory size/hot plug memory + // + MtrrSetting.MtrrDefType &= ~((UINT64)(0xFF)); + MtrrSetting.MtrrDefType |= (UINT64) CacheWriteBack; + + // + // Set fixed cache for memory range below 1MB + // + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + 0x0, + 0xA0000, + CacheWriteBack + ); + ASSERT_EFI_ERROR (Status); + + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + 0xA0000, + 0x20000, + CacheUncacheable + ); + ASSERT_EFI_ERROR (Status); + + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + 0xC0000, + 0x40000, + CacheWriteProtected + ); + ASSERT_EFI_ERROR ( Status); + + // + // PI SMM IPL can't set SMRAM to WB because at that time CPU ARCH protocol is not available. + // Set cacheability of SMRAM to WB here to improve SMRAM initialization performance. + // + SmramSize = 0; + SmramBase = 0; + Status = PeiServicesGetHobList ((VOID **) &Hob.Raw); + while (!END_OF_HOB_LIST (Hob)) { + if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) { + if (CompareGuid (&Hob.Guid->Name, &gEfiSmmPeiSmramMemoryReserveGuid)) { + SmramHobDescriptorBlock = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *) (Hob.Guid + 1); + for (Index = 0; Index < SmramHobDescriptorBlock->NumberOfSmmReservedRegions; Index++) { + if (SmramHobDescriptorBlock->Descriptor[Index].PhysicalStart > 0x100000) { + SmramSize += SmramHobDescriptorBlock->Descriptor[Index].PhysicalSize; + if (SmramBase == 0 || SmramBase > SmramHobDescriptorBlock->Descriptor[Index].CpuStart) { + SmramBase = SmramHobDescriptorBlock->Descriptor[Index].CpuStart; + } + } + } + break; + } + } + Hob.Raw = GET_NEXT_HOB (Hob); + } + + // + // Set non system memory as UC + // + MemoryBase = 0x100000000; + + // + // Add IED size to set whole SMRAM as WB to save MTRR count + // + MemoryLength = MemoryBase - (SmramBase + SmramSize); + while (MemoryLength != 0) { + Power2Length = GetPowerOfTwo64 (MemoryLength); + MemoryBase -= Power2Length; + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + MemoryBase, + Power2Length, + CacheUncacheable + ); + ASSERT_EFI_ERROR (Status); + MemoryLength -= Power2Length; + } + + // + // Update MTRR setting from MTRR buffer + // + MtrrSetAllMtrrs (&MtrrSetting); + + return Status; +} + +/** + This function handles PlatformInit task at the end of PEI + + @param[in] PeiServices Pointer to PEI Services Table. + @param[in] NotifyDesc Pointer to the descriptor for the Notification event that + caused this function to execute. + @param[in] Ppi Pointer to the PPI data associated with this function. + + @retval EFI_SUCCESS The function completes successfully + @retval others +**/ +EFI_STATUS +EFIAPI +PlatformInitEndOfPei ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + EFI_STATUS Status; + + Status = BoardInitAfterSiliconInit (); + ASSERT_EFI_ERROR (Status); + + Status = SetCacheMtrrAfterEndOfPei (); + ASSERT_EFI_ERROR (Status); + + TestPointEndOfPei (); + + return Status; +} + + +/** + Platform Init PEI module entry point + + @param[in] FileHandle Not used. + @param[in] PeiServices General purpose services available to every PEIM. + + @retval EFI_SUCCESS The function completes successfully + @retval EFI_OUT_OF_RESOURCES Insufficient resources to create database +**/ +EFI_STATUS +EFIAPI +PlatformInitPostMemEntryPoint ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + + Status = BoardInitBeforeSiliconInit (); + ASSERT_EFI_ERROR (Status); + + // + // Performing PlatformInitEndOfPei after EndOfPei PPI produced + // + Status = PeiServicesNotifyPpi (&mEndOfPeiNotifyList); + + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPostMem.inf b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPostMem.inf new file mode 100644 index 0000000000..264a9b23b9 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPostMem.inf @@ -0,0 +1,59 @@ +### @file +# Component information file for the Platform Init PEI module. +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = PlatformInitPostMem + FILE_GUID = 59ADD62D-A1C0-44C5-A90F-A1168770468C + VERSION_STRING = 1.0 + MODULE_TYPE = PEIM + ENTRY_POINT = PlatformInitPostMemEntryPoint + +[LibraryClasses] + PeimEntryPoint + DebugLib + IoLib + MemoryAllocationLib + BaseMemoryLib + HobLib + PeiServicesLib + MtrrLib + BoardInitLib + TestPointCheckLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Sources] + PlatformInitPostMem.c + +[Pcd] + +[Ppis] + gEfiEndOfPeiSignalPpiGuid ## CONSUMES + gEfiPeiReadOnlyVariable2PpiGuid + +[Protocols] + +[Guids] + gEfiSmmPeiSmramMemoryReserveGuid ## CONSUMES + +[Depex] + gEfiPeiMemoryDiscoveredPpiGuid + +[FixedPcd] diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPreMem.c b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPreMem.c new file mode 100644 index 0000000000..10561513fe --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPreMem.c @@ -0,0 +1,507 @@ +/** @file + Source code file for Platform Init Pre-Memory PEI module + +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 +#include +#include +#include +#include +#include +#include + +EFI_STATUS +EFIAPI +PlatformInitPreMem ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ); + +EFI_STATUS +EFIAPI +MemoryDiscoveredPpiNotifyCallback ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ); + +static EFI_PEI_NOTIFY_DESCRIPTOR mPreMemNotifyList = { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiReadOnlyVariable2PpiGuid, + (EFI_PEIM_NOTIFY_ENTRY_POINT) PlatformInitPreMem +}; + +static EFI_PEI_NOTIFY_DESCRIPTOR mMemDiscoveredNotifyList = { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiMemoryDiscoveredPpiGuid, + (EFI_PEIM_NOTIFY_ENTRY_POINT) MemoryDiscoveredPpiNotifyCallback +}; + +GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mPpiListRecoveryBootMode = { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiBootInRecoveryModePpiGuid, + NULL +}; + +GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mPpiBootMode = { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiMasterBootModePpiGuid, + NULL +}; + +/// +/// Memory Reserved should be between 125% to 150% of the Current required memory +/// otherwise BdsMisc.c would do a reset to make it 125% to avoid s4 resume issues. +/// +GLOBAL_REMOVE_IF_UNREFERENCED EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = { + { EfiACPIReclaimMemory, FixedPcdGet32 (PcdPlatformEfiAcpiReclaimMemorySize) }, // ASL + { EfiACPIMemoryNVS, FixedPcdGet32 (PcdPlatformEfiAcpiNvsMemorySize) }, // ACPI NVS (including S3 related) + { EfiReservedMemoryType, FixedPcdGet32 (PcdPlatformEfiReservedMemorySize) }, // BIOS Reserved (including S3 related) + { EfiRuntimeServicesData, FixedPcdGet32 (PcdPlatformEfiRtDataMemorySize) }, // Runtime Service Data + { EfiRuntimeServicesCode, FixedPcdGet32 (PcdPlatformEfiRtCodeMemorySize) }, // Runtime Service Code + { EfiMaxMemoryType, 0 } +}; + +VOID +BuildMemoryTypeInformation ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariableServices; + UINTN DataSize; + EFI_MEMORY_TYPE_INFORMATION MemoryData[EfiMaxMemoryType + 1]; + + // + // Locate system configuration variable + // + Status = PeiServicesLocatePpi( + &gEfiPeiReadOnlyVariable2PpiGuid, // GUID + 0, // INSTANCE + NULL, // EFI_PEI_PPI_DESCRIPTOR + (VOID **) &VariableServices // PPI + ); + ASSERT_EFI_ERROR(Status); + + DataSize = sizeof (MemoryData); + Status = VariableServices->GetVariable ( + VariableServices, + EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME, + &gEfiMemoryTypeInformationGuid, + NULL, + &DataSize, + &MemoryData + ); + if (EFI_ERROR(Status)) { + DataSize = sizeof (mDefaultMemoryTypeInformation); + CopyMem(MemoryData, mDefaultMemoryTypeInformation, DataSize); + } + + /// + /// Build the GUID'd HOB for DXE + /// + BuildGuidDataHob ( + &gEfiMemoryTypeInformationGuid, + MemoryData, + DataSize + ); +} + +/** + Set Cache Mtrr. +**/ +VOID +SetCacheMtrr ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PEI_HOB_POINTERS Hob; + MTRR_SETTINGS MtrrSetting; + UINT64 MemoryBase; + UINT64 MemoryLength; + UINT64 LowMemoryLength; + UINT64 HighMemoryLength; + EFI_BOOT_MODE BootMode; + EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute; + UINT64 CacheMemoryLength; + + /// + /// Reset all MTRR setting. + /// + ZeroMem(&MtrrSetting, sizeof(MTRR_SETTINGS)); + + /// + /// Cache the Flash area as WP to boost performance + /// + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + (UINTN) FixedPcdGet32 (PcdFlashAreaBaseAddress), + (UINTN) FixedPcdGet32 (PcdFlashAreaSize), + CacheWriteProtected + ); + ASSERT_EFI_ERROR (Status); + + /// + /// Update MTRR setting from MTRR buffer for Flash Region to be WP to boost performance + /// + MtrrSetAllMtrrs (&MtrrSetting); + + /// + /// Set low to 1 MB. Since 1MB cacheability will always be set + /// until override by CSM. + /// Initialize high memory to 0. + /// + LowMemoryLength = 0x100000; + HighMemoryLength = 0; + ResourceAttribute = ( + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE + ); + + Status = PeiServicesGetBootMode (&BootMode); + ASSERT_EFI_ERROR (Status); + + if (BootMode != BOOT_ON_S3_RESUME) { + ResourceAttribute |= EFI_RESOURCE_ATTRIBUTE_TESTED; + } + + Status = PeiServicesGetHobList ((VOID **) &Hob.Raw); + while (!END_OF_HOB_LIST (Hob)) { + if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { + if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) || + ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_RESERVED) && + (Hob.ResourceDescriptor->ResourceAttribute == ResourceAttribute)) + ) { + if (Hob.ResourceDescriptor->PhysicalStart >= 0x100000000ULL) { + HighMemoryLength += Hob.ResourceDescriptor->ResourceLength; + } else if (Hob.ResourceDescriptor->PhysicalStart >= 0x100000) { + LowMemoryLength += Hob.ResourceDescriptor->ResourceLength; + } + } + } + + Hob.Raw = GET_NEXT_HOB (Hob); + } + + DEBUG ((DEBUG_INFO, "Memory Length (Below 4GB) = %lx.\n", LowMemoryLength)); + DEBUG ((DEBUG_INFO, "Memory Length (Above 4GB) = %lx.\n", HighMemoryLength)); + + /// + /// Assume size of main memory is multiple of 256MB + /// + MemoryLength = (LowMemoryLength + 0xFFFFFFF) & 0xF0000000; + MemoryBase = 0; + + CacheMemoryLength = MemoryLength; + /// + /// Programming MTRRs to avoid override SPI region with UC when MAX TOLUD Length >= 3.5GB + /// + if (MemoryLength > 0xDC000000) { + CacheMemoryLength = 0xC0000000; + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + MemoryBase, + CacheMemoryLength, + CacheWriteBack + ); + ASSERT_EFI_ERROR (Status); + + MemoryBase = 0xC0000000; + CacheMemoryLength = MemoryLength - 0xC0000000; + if (MemoryLength > 0xE0000000) { + CacheMemoryLength = 0x20000000; + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + MemoryBase, + CacheMemoryLength, + CacheWriteBack + ); + ASSERT_EFI_ERROR (Status); + + MemoryBase = 0xE0000000; + CacheMemoryLength = MemoryLength - 0xE0000000; + } + } + + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + MemoryBase, + CacheMemoryLength, + CacheWriteBack + ); + ASSERT_EFI_ERROR (Status); + + if (LowMemoryLength != MemoryLength) { + MemoryBase = LowMemoryLength; + MemoryLength -= LowMemoryLength; + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + MemoryBase, + MemoryLength, + CacheUncacheable + ); + ASSERT_EFI_ERROR (Status); + } + + /// + /// VGA-MMIO - 0xA0000 to 0xC0000 to be UC + /// + Status = MtrrSetMemoryAttributeInMtrrSettings ( + &MtrrSetting, + 0xA0000, + 0x20000, + CacheUncacheable + ); + ASSERT_EFI_ERROR (Status); + + /// + /// Update MTRR setting from MTRR buffer + /// + MtrrSetAllMtrrs (&MtrrSetting); + + return ; +} + +VOID +ReportCpuHob ( + VOID + ) +{ + UINT8 PhysicalAddressBits; + UINT32 RegEax; + + AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL); + if (RegEax >= 0x80000008) { + AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL); + PhysicalAddressBits = (UINT8) RegEax; + } else { + PhysicalAddressBits = 36; + } + + /// + /// Create a CPU hand-off information + /// + BuildCpuHob (PhysicalAddressBits, 16); +} + +VOID +ReportFv ( + VOID + ) +{ + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + + Status = PeiServicesGetBootMode (&BootMode); + ASSERT_EFI_ERROR (Status); + + /// + /// Build HOB for DXE + /// + if (BootMode == BOOT_IN_RECOVERY_MODE) { + /// + /// Prepare the recovery service + /// + } else { + + PeiServicesInstallFvInfo2Ppi ( + &(((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FixedPcdGet32 (PcdFlashFvMainBase))->FileSystemGuid), + (VOID *) (UINTN) FixedPcdGet32 (PcdFlashFvMainBase), + FixedPcdGet32 (PcdFlashFvMainSize), + NULL, + NULL, + 0 + ); + } + + // + // Report resource HOB for flash FV + // + BuildResourceDescriptorHob ( + EFI_RESOURCE_MEMORY_MAPPED_IO, + (EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE), + (UINTN) FixedPcdGet32 (PcdFlashAreaBaseAddress), + (UINTN) FixedPcdGet32 (PcdFlashAreaSize) + ); + BuildMemoryAllocationHob ( + (UINTN) FixedPcdGet32 (PcdFlashAreaBaseAddress), + (UINTN) FixedPcdGet32 (PcdFlashAreaSize), + EfiMemoryMappedIO + ); + + BuildFvHob ( + (UINTN) FixedPcdGet32 (PcdFlashAreaBaseAddress), + (UINTN) FixedPcdGet32 (PcdFlashAreaSize) + ); +} + +/** + Install Firmware Volume Hob's once there is main memory + + @param[in] PeiServices General purpose services available to every PEIM. + @param[in] NotifyDescriptor Notify that this module published. + @param[in] Ppi PPI that was installed. + + @retval EFI_SUCCESS The function completed successfully. +**/ +EFI_STATUS +EFIAPI +MemoryDiscoveredPpiNotifyCallback ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + + Status = BoardInitAfterMemoryInit (); + ASSERT_EFI_ERROR (Status); + + Status = PeiServicesGetBootMode (&BootMode); + ASSERT_EFI_ERROR (Status); + + SetCacheMtrr (); + + ReportCpuHob (); + + /// + /// If S3 resume, then we are done + /// + if (BootMode == BOOT_ON_S3_RESUME) { + return EFI_SUCCESS; + } + + ReportFv (); + + TestPointMemoryDiscovered (); + + if (PcdGetBool (PcdStopAfterMemInit)) { + CpuDeadLoop (); + } + + return Status; +} + + +/** + This function handles PlatformInit task after PeiReadOnlyVariable2 PPI produced + + @param[in] PeiServices Pointer to PEI Services Table. + @param[in] NotifyDesc Pointer to the descriptor for the Notification event that + caused this function to execute. + @param[in] Ppi Pointer to the PPI data associated with this function. + + @retval EFI_SUCCESS The function completes successfully + @retval others +**/ +EFI_STATUS +EFIAPI +PlatformInitPreMem ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + + // + // Start board detection + // + BoardDetect (); + + BoardDebugInit (); + + TestPointDebugInitDone (); + + if (PcdGetBool (PcdStopAfterDebugInit)) { + CpuDeadLoop (); + } + + BootMode = BoardBootModeDetect (); + Status = PeiServicesSetBootMode (BootMode); + ASSERT_EFI_ERROR (Status); + if (BootMode == BOOT_IN_RECOVERY_MODE) { + Status = PeiServicesInstallPpi (&mPpiListRecoveryBootMode); + } + /// + /// Signal possible dependent modules that there has been a + /// final boot mode determination, it is used to build BIST + /// Hob for Dxe use. + /// + Status = PeiServicesInstallPpi (&mPpiBootMode); + ASSERT_EFI_ERROR (Status); + + BuildMemoryTypeInformation (); + + Status = BoardInitBeforeMemoryInit (); + ASSERT_EFI_ERROR (Status); + + return Status; +} + + +/** + Platform Init before memory PEI module entry point + + @param[in] FileHandle Not used. + @param[in] PeiServices General purpose services available to every PEIM. + + @retval EFI_SUCCESS The function completes successfully + @retval EFI_OUT_OF_RESOURCES Insufficient resources to create database +**/ +EFI_STATUS +EFIAPI +PlatformInitPreMemEntryPoint ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + + /// + /// Performing PlatformInitPreMem after PeiReadOnlyVariable2 PPI produced + /// + Status = PeiServicesNotifyPpi (&mPreMemNotifyList); + + /// + /// After code reorangized, memorycallback will run because the PPI is already + /// installed when code run to here, it is supposed that the InstallEfiMemory is + /// done before. + /// + Status = PeiServicesNotifyPpi (&mMemDiscoveredNotifyList); + + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPreMem.inf b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPreMem.inf new file mode 100644 index 0000000000..82c503814b --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitPei/PlatformInitPreMem.inf @@ -0,0 +1,71 @@ +### @file +# Component information file for the Platform Init Pre-Memory PEI module. +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = PlatformInitPreMem + FILE_GUID = EEEE611D-F78F-4FB9-B868-55907F169280 + VERSION_STRING = 1.0 + MODULE_TYPE = PEIM + ENTRY_POINT = PlatformInitPreMemEntryPoint + +[LibraryClasses] + PeimEntryPoint + DebugLib + IoLib + MemoryAllocationLib + BaseMemoryLib + HobLib + PeiServicesLib + MtrrLib + TimerLib + BoardInitLib + TestPointCheckLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Pcd] + gPlatformModuleTokenSpaceGuid.PcdFlashAreaBaseAddress ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdFlashAreaSize ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdFlashFvMainBase ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdFlashFvMainSize ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdStopAfterDebugInit + gPlatformModuleTokenSpaceGuid.PcdStopAfterMemInit + +[FixedPcd] + gPlatformModuleTokenSpaceGuid.PcdPlatformEfiAcpiReclaimMemorySize ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdPlatformEfiAcpiNvsMemorySize ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdPlatformEfiReservedMemorySize ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdPlatformEfiRtDataMemorySize ## CONSUMES + gPlatformModuleTokenSpaceGuid.PcdPlatformEfiRtCodeMemorySize ## CONSUMES + +[Sources] + PlatformInitPreMem.c + +[Ppis] + gEfiPeiMemoryDiscoveredPpiGuid + gEfiPeiMasterBootModePpiGuid ## PRODUCES + gEfiPeiBootInRecoveryModePpiGuid ## PRODUCES + gEfiPeiReadOnlyVariable2PpiGuid + +[Guids] + gEfiMemoryTypeInformationGuid + +[Depex] + TRUE diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitSmm/PlatformInitSmm.c b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitSmm/PlatformInitSmm.c new file mode 100644 index 0000000000..c4d3f52436 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitSmm/PlatformInitSmm.c @@ -0,0 +1,168 @@ +/** @file + This driver will register two callbacks to call fsp's notifies. + + Copyright (c) 2014 - 2016, 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 + which 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 + +/** + SMM End Of Dxe event notification handler. + + @param[in] Protocol Points to the protocol's unique identifier. + @param[in] Interface Points to the interface instance. + @param[in] Handle The handle on which the interface was installed. + + @retval EFI_SUCCESS Notification handler runs successfully. +**/ +EFI_STATUS +EFIAPI +SmmEndOfDxeEventNotify ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + TestPointSmmEndOfDxe (); + return EFI_SUCCESS; +} + +/** + SMM Ready To Lock event notification handler. + + @param[in] Protocol Points to the protocol's unique identifier. + @param[in] Interface Points to the interface instance. + @param[in] Handle The handle on which the interface was installed. + + @retval EFI_SUCCESS Notification handler runs successfully. +**/ +EFI_STATUS +EFIAPI +SmmReadyToLockEventNotify ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + TestPointSmmReadyToLock (); + return EFI_SUCCESS; +} + +/** + SMM Ready To Boot event notification handler. + + @param[in] Protocol Points to the protocol's unique identifier. + @param[in] Interface Points to the interface instance. + @param[in] Handle The handle on which the interface was installed. + + @retval EFI_SUCCESS Notification handler runs successfully. +**/ +EFI_STATUS +EFIAPI +SmmReadyToBootEventNotify ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + TestPointSmmReadyToBoot (); + return EFI_SUCCESS; +} + +/** + SMM Exit Boot Services event notification handler. + + @param[in] Protocol Points to the protocol's unique identifier. + @param[in] Interface Points to the interface instance. + @param[in] Handle The handle on which the interface was installed. + + @retval EFI_SUCCESS Notification handler runs successfully. +**/ +EFI_STATUS +EFIAPI +SmmExitBootServicesEventNotify ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + TestPointSmmExitBootServices (); + return EFI_SUCCESS; +} + +/** + Initialize SMM Platform. + + @param[in] ImageHandle Image handle of this driver. + @param[in] SystemTable Global system service table. + + @retval EFI_SUCCESS Initialization complete. + @exception EFI_UNSUPPORTED The chipset is unsupported by this driver. + @retval EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver. + @retval EFI_DEVICE_ERROR Device error, driver exits abnormally. +**/ +EFI_STATUS +EFIAPI +PlatformInitSmmEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + VOID *SmmEndOfDxeRegistration; + VOID *SmmReadyToLockRegistration; + VOID *SmmReadyToBootRegistration; + VOID *SmmExitBootServicesRegistration; + + Status = gSmst->SmmRegisterProtocolNotify ( + &gEfiSmmEndOfDxeProtocolGuid, + SmmEndOfDxeEventNotify, + &SmmEndOfDxeRegistration + ); + ASSERT_EFI_ERROR (Status); + + Status = gSmst->SmmRegisterProtocolNotify ( + &gEfiSmmReadyToLockProtocolGuid, + SmmReadyToLockEventNotify, + &SmmReadyToLockRegistration + ); + ASSERT_EFI_ERROR (Status); + + Status = gSmst->SmmRegisterProtocolNotify ( + &gEdkiiSmmReadyToBootProtocolGuid, + SmmReadyToBootEventNotify, + &SmmReadyToBootRegistration + ); + ASSERT_EFI_ERROR (Status); + + Status = gSmst->SmmRegisterProtocolNotify ( + &gEdkiiSmmExitBootServicesProtocolGuid, + SmmExitBootServicesEventNotify, + &SmmExitBootServicesRegistration + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitSmm/PlatformInitSmm.inf b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitSmm/PlatformInitSmm.inf new file mode 100644 index 0000000000..d845a63467 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/PlatformInitSmm/PlatformInitSmm.inf @@ -0,0 +1,52 @@ +### @file +# Module Information file for the PlatformInit DXE driver. +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = PlatformInitSmm + FILE_GUID = EE447DFD-7B3A-4F39-80FC-ED02BB20F6A0 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_SMM_DRIVER + PI_SPECIFICATION_VERSION = 1.10 + ENTRY_POINT = PlatformInitSmmEntryPoint + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DxeServicesTableLib + MemoryAllocationLib + PcdLib + SmmServicesTableLib + UefiDriverEntryPoint + BoardInitLib + TestPointCheckLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[Sources] + PlatformInitSmm.c + +[Protocols] + gEfiSmmReadyToLockProtocolGuid + gEfiSmmEndOfDxeProtocolGuid + gEdkiiSmmReadyToBootProtocolGuid + gEdkiiSmmExitBootServicesProtocolGuid + +[Depex] + TRUE diff --git a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.c b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.c new file mode 100644 index 0000000000..d33c651a91 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.c @@ -0,0 +1,218 @@ +/** @file + Platform specific TPM2 component. + +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 + +#define MAX_NEW_AUTHORIZATION_SIZE SHA512_DIGEST_SIZE + +/** + Generate high-quality entropy source through RDRAND. + + @param[in] Length Size of the buffer, in bytes, to fill with. + @param[out] Entropy Pointer to the buffer to store the entropy data. + + @retval EFI_SUCCESS Entropy generation succeeded. + @retval EFI_NOT_READY Failed to request random data. + +**/ +EFI_STATUS +EFIAPI +RdRandGenerateEntropy ( + IN UINTN Length, + OUT UINT8 *Entropy + ) +{ + EFI_STATUS Status; + UINTN BlockCount; + UINT64 Seed[2]; + UINT8 *Ptr; + + Status = EFI_NOT_READY; + BlockCount = Length / 64; + Ptr = (UINT8 *)Entropy; + + // + // Generate high-quality seed for DRBG Entropy + // + while (BlockCount > 0) { + Status = GetRandomNumber128(Seed); + if (EFI_ERROR(Status)) { + return Status; + } + CopyMem(Ptr, Seed, 64); + + BlockCount--; + Ptr = Ptr + 64; + } + + // + // Populate the remained data as request. + // + Status = GetRandomNumber128(Seed); + if (EFI_ERROR(Status)) { + return Status; + } + CopyMem(Ptr, Seed, (Length % 64)); + + return Status; +} + +/** + Set PlatformAuth to random value. +**/ +VOID +RandomizePlatformAuth ( + VOID + ) +{ + EFI_STATUS Status; + UINT16 AuthSize; + TPML_PCR_SELECTION Pcrs; + UINT32 Index; + UINT8 *Rand; + UINTN RandSize; + TPM2B_AUTH NewPlatformAuth; + + // + // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth being null + // + ZeroMem(&Pcrs, sizeof(TPML_PCR_SELECTION)); + AuthSize = MAX_NEW_AUTHORIZATION_SIZE; + + Status = Tpm2GetCapabilityPcrs(&Pcrs); + if (EFI_ERROR(Status)) { + DEBUG((EFI_D_ERROR, "Tpm2GetCapabilityPcrs fail!\n")); + } else { + for (Index = 0; Index < Pcrs.count; Index++) { + switch (Pcrs.pcrSelections[Index].hash) { + case TPM_ALG_SHA1: + AuthSize = SHA1_DIGEST_SIZE; + break; + case TPM_ALG_SHA256: + AuthSize = SHA256_DIGEST_SIZE; + break; + case TPM_ALG_SHA384: + AuthSize = SHA384_DIGEST_SIZE; + break; + case TPM_ALG_SHA512: + AuthSize = SHA512_DIGEST_SIZE; + break; + case TPM_ALG_SM3_256: + AuthSize = SM3_256_DIGEST_SIZE; + break; + } + } + } + + ZeroMem(NewPlatformAuth.buffer, AuthSize); + NewPlatformAuth.size = AuthSize; + + // + // Allocate one buffer to store random data. + // + RandSize = MAX_NEW_AUTHORIZATION_SIZE; + Rand = AllocatePool(RandSize); + + RdRandGenerateEntropy(RandSize, Rand); + CopyMem(NewPlatformAuth.buffer, Rand, AuthSize); + + FreePool(Rand); + + // + // Send Tpm2HierarchyChangeAuth command with the new Auth value + // + Status = Tpm2HierarchyChangeAuth(TPM_RH_PLATFORM, NULL, &NewPlatformAuth); + DEBUG((DEBUG_INFO, "Tpm2HierarchyChangeAuth Result: - %r\n", Status)); + ZeroMem(NewPlatformAuth.buffer, AuthSize); + ZeroMem(Rand, RandSize); +} + +/** + This is the Event call back function to notify the Library the system is entering + run time phase. + + @param Event Pointer to this event + @param Context Event hanlder private data + **/ +VOID +EFIAPI +ReadyToLockEventCallBack ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + VOID *Interface; + + // + // Try to locate it because EfiCreateProtocolNotifyEvent will trigger it once when registration. + // Just return if it is not found. + // + Status = gBS->LocateProtocol ( + &gEfiDxeSmmReadyToLockProtocolGuid, + NULL, + &Interface + ); + if (EFI_ERROR (Status)) { + return ; + } + + // + // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth being null + // + RandomizePlatformAuth(); + + gBS->CloseEvent (Event); +} + +/** + The driver's entry point. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry point. +**/ +EFI_STATUS +EFIAPI +Tcg2PlatformDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + VOID *Registration; + EFI_EVENT Event; + + Event = EfiCreateProtocolNotifyEvent ( + &gEfiDxeSmmReadyToLockProtocolGuid, + TPL_CALLBACK, + ReadyToLockEventCallBack, + NULL, + &Registration + ); + ASSERT (Event != NULL); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf new file mode 100644 index 0000000000..f5b083b1fb --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf @@ -0,0 +1,56 @@ +### @file +# Platform specific TPM2 component. +# +# 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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = Tcg2PlatformDxe + FILE_GUID = 5CAB08D5-AD8F-4d8b-B828-D17A8D9FE977 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + ENTRY_POINT = Tcg2PlatformDxeEntryPoint +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF +# + +[LibraryClasses] + MemoryAllocationLib + BaseLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiRuntimeServicesTableLib + BaseMemoryLib + DebugLib + Tpm2CommandLib + Tpm2DeviceLib + RngLib + UefiLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SecurityPkg/SecurityPkg.dec + CryptoPkg/CryptoPkg.dec + +[Sources] + Tcg2PlatformDxe.c + +[Protocols] + gEfiDxeSmmReadyToLockProtocolGuid ## SOMETIMES_CONSUMES ## NOTIFY + +[Depex] + gEfiTcg2ProtocolGuid + diff --git a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c new file mode 100644 index 0000000000..b05da87ab6 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.c @@ -0,0 +1,233 @@ +/** @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 + +#define MAX_NEW_AUTHORIZATION_SIZE SHA512_DIGEST_SIZE + +/** + Generate high-quality entropy source through RDRAND. + + @param[in] Length Size of the buffer, in bytes, to fill with. + @param[out] Entropy Pointer to the buffer to store the entropy data. + + @retval EFI_SUCCESS Entropy generation succeeded. + @retval EFI_NOT_READY Failed to request random data. + +**/ +EFI_STATUS +EFIAPI +RdRandGenerateEntropy ( + IN UINTN Length, + OUT UINT8 *Entropy + ) +{ + EFI_STATUS Status; + UINTN BlockCount; + UINT64 Seed[2]; + UINT8 *Ptr; + + Status = EFI_NOT_READY; + BlockCount = Length / 64; + Ptr = (UINT8 *)Entropy; + + // + // Generate high-quality seed for DRBG Entropy + // + while (BlockCount > 0) { + Status = GetRandomNumber128(Seed); + if (EFI_ERROR(Status)) { + return Status; + } + CopyMem(Ptr, Seed, 64); + + BlockCount--; + Ptr = Ptr + 64; + } + + // + // Populate the remained data as request. + // + Status = GetRandomNumber128(Seed); + if (EFI_ERROR(Status)) { + return Status; + } + CopyMem(Ptr, Seed, (Length % 64)); + + return Status; +} + +/** + Set PlatformAuth to random value. +**/ +VOID +RandomizePlatformAuth ( + VOID + ) +{ + EFI_STATUS Status; + UINT16 AuthSize; + TPML_PCR_SELECTION Pcrs; + UINT32 Index; + UINT8 *Rand; + UINTN RandSize; + TPM2B_AUTH NewPlatformAuth; + + // + // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth being null + // + ZeroMem(&Pcrs, sizeof(TPML_PCR_SELECTION)); + AuthSize = MAX_NEW_AUTHORIZATION_SIZE; + + Status = Tpm2GetCapabilityPcrs(&Pcrs); + if (EFI_ERROR(Status)) { + DEBUG((EFI_D_ERROR, "Tpm2GetCapabilityPcrs fail!\n")); + } else { + for (Index = 0; Index < Pcrs.count; Index++) { + switch (Pcrs.pcrSelections[Index].hash) { + case TPM_ALG_SHA1: + AuthSize = SHA1_DIGEST_SIZE; + break; + case TPM_ALG_SHA256: + AuthSize = SHA256_DIGEST_SIZE; + break; + case TPM_ALG_SHA384: + AuthSize = SHA384_DIGEST_SIZE; + break; + case TPM_ALG_SHA512: + AuthSize = SHA512_DIGEST_SIZE; + break; + case TPM_ALG_SM3_256: + AuthSize = SM3_256_DIGEST_SIZE; + break; + } + } + } + + ZeroMem(NewPlatformAuth.buffer, AuthSize); + NewPlatformAuth.size = AuthSize; + + // + // Allocate one buffer to store random data. + // + RandSize = MAX_NEW_AUTHORIZATION_SIZE; + Rand = AllocatePool(RandSize); + + RdRandGenerateEntropy(RandSize, Rand); + CopyMem(NewPlatformAuth.buffer, Rand, AuthSize); + + FreePool(Rand); + + // + // Send Tpm2HierarchyChangeAuth command with the new Auth value + // + Status = Tpm2HierarchyChangeAuth(TPM_RH_PLATFORM, NULL, &NewPlatformAuth); + DEBUG((DEBUG_INFO, "Tpm2HierarchyChangeAuth Result: - %r\n", Status)); + ZeroMem(NewPlatformAuth.buffer, AuthSize); + ZeroMem(Rand, RandSize); +} + +/** + This function handles PlatformInit task at the end of PEI + + @param[in] PeiServices Pointer to PEI Services Table. + @param[in] NotifyDesc Pointer to the descriptor for the Notification event that + caused this function to execute. + @param[in] Ppi Pointer to the PPI data associated with this function. + + @retval EFI_SUCCESS The function completes successfully + @retval others +**/ +EFI_STATUS +EFIAPI +PlatformInitEndOfPei ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + VOID *TcgEventLog; + + // + // Try to get TcgEventLog in S3 to see if S3 error is reported. + // + TcgEventLog = GetFirstGuidHob(&gTcgEventEntryHobGuid); + if (TcgEventLog == NULL) { + TcgEventLog = GetFirstGuidHob(&gTcgEvent2EntryHobGuid); + } + + if (TcgEventLog == NULL) { + // + // no S3 error reported + // + return EFI_SUCCESS; + } + + // + // If there is S3 error on TPM_SU_STATE and success on TPM_SU_CLEAR, + // Send Tpm2HierarchyChange Auth with random value to avoid PlatformAuth being null + // + RandomizePlatformAuth(); + + return EFI_SUCCESS; +} + +static EFI_PEI_NOTIFY_DESCRIPTOR mEndOfPeiNotifyList = { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiEndOfPeiSignalPpiGuid, + (EFI_PEIM_NOTIFY_ENTRY_POINT)PlatformInitEndOfPei +}; + +/** + Main entry + + @param[in] FileHandle Handle of the file being invoked. + @param[in] PeiServices Pointer to PEI Services table. + + @retval EFI_SUCCESS Install function successfully. + +**/ +EFI_STATUS +EFIAPI +Tcg2PlatformPeiEntryPoint ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + + Status = PeiServicesGetBootMode (&BootMode); + ASSERT_EFI_ERROR(Status); + + if (BootMode != BOOT_ON_S3_RESUME) { + return EFI_SUCCESS; + } + + // + // Performing PlatformInitEndOfPei after EndOfPei PPI produced + // + Status = PeiServicesNotifyPpi (&mEndOfPeiNotifyList); + + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf new file mode 100644 index 0000000000..43b8e835f0 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tcg/Tcg2PlatformPei/Tcg2PlatformPei.inf @@ -0,0 +1,56 @@ +### @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 which 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. +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = Tcg2PlatformPei + FILE_GUID = 47727552-A54B-4A84-8CC1-BFF23E239636 + VERSION_STRING = 1.0 + MODULE_TYPE = PEIM + ENTRY_POINT = Tcg2PlatformPeiEntryPoint + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[LibraryClasses] + PcdLib + BaseMemoryLib + MemoryAllocationLib + PeiServicesLib + PeimEntryPoint + DebugLib + Tpm2DeviceLib + Tpm2CommandLib + RngLib + +[Packages] + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec + +[Sources] + Tcg2PlatformPei.c + +[Guids] + gTcgEventEntryHobGuid + gTcgEvent2EntryHobGuid + +[Ppis] + gEfiEndOfPeiSignalPpiGuid + +[Depex] + gEfiTpmDeviceSelectedGuid + diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpi.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpi.c new file mode 100644 index 0000000000..c5c79ac40d --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpi.c @@ -0,0 +1,340 @@ +/** @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 + +BOOLEAN mDmarFound = FALSE; +BOOLEAN mWsmtFound = FALSE; + +EFI_STATUS +DumpAcpiMadt ( + IN EFI_ACPI_4_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt + ); + +EFI_STATUS +DumpAcpiMcfg ( + IN EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER *Mcfg + ); + +EFI_STATUS +DumpAcpiHpet ( + IN EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_HEADER *Hpet + ); + +EFI_STATUS +DumpAcpiDmar ( + IN EFI_ACPI_DMAR_HEADER *Dmar + ); + +EFI_STATUS +DumpAcpiWsmt ( + IN EFI_ACPI_WSMT_TABLE *Wsmt + ); + +VOID +DumpCharArray ( + IN CHAR8 *Ch, + IN UINTN Size + ) +{ + UINTN Index; + + for (Index = 0; Index < Size; Index++) { + DEBUG ((DEBUG_INFO, "%c", Ch[Index])); + } +} + +VOID +DumpAcpiTableHeader ( + IN EFI_ACPI_DESCRIPTION_HEADER *Table + ) +{ + DEBUG ((DEBUG_INFO, " ")); + DumpCharArray ((CHAR8 *)&Table->Signature, sizeof(Table->Signature)); + DEBUG ((DEBUG_INFO, " : (0x%016lx) 0x%02x \'", Table, Table->Revision)); + DumpCharArray (Table->OemId, sizeof(Table->OemId)); + DEBUG ((DEBUG_INFO, "\' \'")); + DumpCharArray ((CHAR8 *)&Table->OemTableId, sizeof(Table->OemTableId)); + DEBUG ((DEBUG_INFO, "\' 0x%08x \'", Table->OemRevision)); + DumpCharArray ((CHAR8 *)&Table->CreatorId, sizeof(Table->CreatorId)); + DEBUG ((DEBUG_INFO, "\' 0x%08x |\n", Table->CreatorRevision)); +} + +EFI_STATUS +DumpAcpiFadt ( + IN EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt + ) +{ + DumpAcpiTableHeader (&Fadt->Header); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " SCI=0x%04x", Fadt->SciInt)); + DEBUG ((DEBUG_INFO, " SMI=0x%08x", Fadt->SmiCmd)); + DEBUG ((DEBUG_INFO, " AcpiEnable=0x%02x", Fadt->AcpiEnable)); + DEBUG ((DEBUG_INFO, " AcpiDisable=0x%02x", Fadt->AcpiDisable)); + DEBUG ((DEBUG_INFO, "\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +DumpAcpiFacs ( + IN EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs + ) +{ + DEBUG ((DEBUG_INFO, " ")); + DumpCharArray ((CHAR8 *)&Facs->Signature, sizeof(Facs->Signature)); + DEBUG ((DEBUG_INFO, " : (0x%016lx) 0x%02x\n", Facs, Facs->Version)); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " HardwareSignature=%08x\n", Facs->HardwareSignature)); + return EFI_SUCCESS; +} + +EFI_STATUS +DumpAcpiTable ( + IN EFI_ACPI_DESCRIPTION_HEADER *Table + ) +{ + EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt; + EFI_STATUS Status; + + if (Table == NULL) { + return EFI_INVALID_PARAMETER; + } + + switch (Table->Signature) { + case EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE: + Fadt = (EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE *)Table; + Status = DumpAcpiFadt (Fadt); + if (Fadt->Header.Revision >= EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) { + if (Fadt->XFirmwareCtrl != 0) { + DumpAcpiFacs ((EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Fadt->XFirmwareCtrl); + } else { + DumpAcpiFacs ((EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Fadt->FirmwareCtrl); + } + if (Fadt->XDsdt != 0) { + DumpAcpiTable ((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Fadt->XDsdt); + } else { + DumpAcpiTable ((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Fadt->Dsdt); + } + } else { + DumpAcpiFacs ((EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Fadt->FirmwareCtrl); + DumpAcpiTable ((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Fadt->Dsdt); + } + return Status; + case EFI_ACPI_4_0_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE: + Status = DumpAcpiMadt ((EFI_ACPI_4_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *)Table); + return Status; + case EFI_ACPI_2_0_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_SIGNATURE: + Status = DumpAcpiMcfg ((EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER *)Table); + return Status; + case EFI_ACPI_3_0_HIGH_PRECISION_EVENT_TIMER_TABLE_SIGNATURE: + Status = DumpAcpiHpet ((EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_HEADER *)Table); + return Status; + case EFI_ACPI_4_0_DMA_REMAPPING_TABLE_SIGNATURE: + Status = DumpAcpiDmar ((EFI_ACPI_DMAR_HEADER *)Table); + mDmarFound = TRUE; + return Status; + case EFI_ACPI_WINDOWS_SMM_SECURITY_MITIGATION_TABLE_SIGNATURE: + Status = DumpAcpiWsmt ((EFI_ACPI_WSMT_TABLE *)Table); + mWsmtFound = TRUE; + return Status; + default: + break; + } + DumpAcpiTableHeader (Table); + return EFI_SUCCESS; +} + +EFI_STATUS +DumpAcpiRsdt ( + IN EFI_ACPI_DESCRIPTION_HEADER *Rsdt + ) +{ + EFI_STATUS Status; + UINTN Index; + UINT32 EntryCount; + UINT32 *EntryPtr; + EFI_ACPI_DESCRIPTION_HEADER *Table; + BOOLEAN Result; + + if (Rsdt == NULL) { + return EFI_INVALID_PARAMETER; + } + + EntryCount = (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof(UINT32); + EntryPtr = (UINT32 *)(Rsdt + 1); + Result = TRUE; + for (Index = 0; Index < EntryCount; Index ++, EntryPtr ++) { + Table = (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)(*EntryPtr)); + Status = DumpAcpiTable (Table); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + } + if (!Result) { + return EFI_INVALID_PARAMETER; + } + return EFI_SUCCESS; +} + +EFI_STATUS +DumpAcpiXsdt ( + IN EFI_ACPI_DESCRIPTION_HEADER *Xsdt + ) +{ + EFI_STATUS Status; + UINTN Index; + UINT32 EntryCount; + UINT64 EntryPtr; + UINTN BasePtr; + EFI_ACPI_DESCRIPTION_HEADER *Table; + BOOLEAN Result; + + if (Xsdt == NULL) { + return EFI_INVALID_PARAMETER; + } + + EntryCount = (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof(UINT64); + + BasePtr = (UINTN)(Xsdt + 1); + Result = TRUE; + for (Index = 0; Index < EntryCount; Index ++) { + CopyMem (&EntryPtr, (VOID *)(BasePtr + Index * sizeof(UINT64)), sizeof(UINT64)); + Table = (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)(EntryPtr)); + Status = DumpAcpiTable (Table); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + } + if (!Result) { + return EFI_INVALID_PARAMETER; + } + return EFI_SUCCESS; +} + +EFI_STATUS +DumpAcpiRsdp ( + IN EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp + ) +{ + EFI_STATUS Status; + EFI_ACPI_DESCRIPTION_HEADER *Rsdt; + EFI_ACPI_DESCRIPTION_HEADER *Xsdt; + + DumpCharArray ((CHAR8 *)&Rsdp->Signature, sizeof(Rsdp->Signature)); + DEBUG ((DEBUG_INFO, ": (0x%016lx) 0x%02x \'", Rsdp, Rsdp->Revision)); + DumpCharArray (Rsdp->OemId, sizeof(Rsdp->OemId)); + DEBUG ((DEBUG_INFO, "\'\n")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " RSDT=0x%08x XSDT=0x%016lx\n", Rsdp->RsdtAddress, Rsdp->XsdtAddress)); + + if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION) { + DumpAcpiTable ((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress); + } + DumpAcpiTable ((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress); + + // + // Search XSDT + // + if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION) { + Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN) Rsdp->XsdtAddress; + Status = DumpAcpiXsdt (Xsdt); + } else { + // + // Search RSDT + // + Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN) Rsdp->RsdtAddress; + Status = DumpAcpiRsdt (Rsdt); + } + + return Status; +} + +EFI_STATUS +DumpAcpiWithGuid ( + IN EFI_GUID *AcpiTableGuid + ) +{ + VOID *Rsdp; + EFI_STATUS Status; + + Status = EfiGetSystemConfigurationTable (AcpiTableGuid, &Rsdp); + if (EFI_ERROR(Status)) { + return EFI_NOT_FOUND; + } + + Status = DumpAcpiRsdp (Rsdp); + + return Status; +} + +EFI_STATUS +TestPointDumpAcpi ( + VOID + ) +{ + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpAcpi - Enter\n")); + + DEBUG ((DEBUG_INFO, "AcpiTable :\n")); + DEBUG ((DEBUG_INFO, " Table Address Rev OemId OemTableId OemRev Creat CreatorRev\n")); + Status = DumpAcpiWithGuid (&gEfiAcpi20TableGuid); + if (Status == EFI_NOT_FOUND) { + Status = DumpAcpiWithGuid (&gEfiAcpi10TableGuid); + } + + DEBUG ((DEBUG_INFO, "==== TestPointDumpAcpi - Exit\n")); + + if (EFI_ERROR(Status)) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_5 TEST_POINT_READY_TO_BOOT TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_5 + ); + } + + if (!mWsmtFound) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_6 TEST_POINT_READY_TO_BOOT TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_6 + ); + Status = EFI_INVALID_PARAMETER; + } + if (!mDmarFound) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_7 TEST_POINT_READY_TO_BOOT TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_7 + ); + Status = EFI_INVALID_PARAMETER; + } + + if (!mDmarFound) { + Status = EFI_INVALID_PARAMETER; + } + + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiDmar.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiDmar.c new file mode 100644 index 0000000000..7277389a23 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiDmar.c @@ -0,0 +1,210 @@ +/** @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 + +VOID +DumpCharArray ( + IN CHAR8 *Ch, + IN UINTN Size + ); + +VOID +DumpAcpiTableHeader ( + IN EFI_ACPI_DESCRIPTION_HEADER *Table + ); + +CHAR8 *mDmarTypeString[] = { + "DRHD ", + "RMRR ", + "ATSR ", + "RHSA ", + "ANDD ", +}; + +CHAR8 mUnknownStr[11]; + +CHAR8 * +ShortNameOfDmarType( + IN UINT16 Type + ) +{ + if (Type < sizeof(mDmarTypeString) / sizeof(mDmarTypeString[0])) { + return mDmarTypeString[Type]; + } else { + AsciiSPrint(mUnknownStr, sizeof(mUnknownStr), "[%04x]", Type); + return mUnknownStr; + } +} + +CHAR8 *mDmarDeviceTypeString[] = { + "[00]", + "PCI", + "P2P", + "IOAPIC", + "HPET", + "ACPI", +}; + +CHAR8 * +ShortNameOfDmarDeviceType( + IN UINT8 Type + ) +{ + if (Type < sizeof(mDmarDeviceTypeString) / sizeof(mDmarDeviceTypeString[0])) { + return mDmarDeviceTypeString[Type]; + } else { + AsciiSPrint(mUnknownStr, sizeof(mUnknownStr), "[%02x]", Type); + return mUnknownStr; + } +} + +VOID +DumpDmarDeviceScope ( + IN EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *DmarDeviceScope, + IN UINTN Size + ) +{ + EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *Device; + EFI_ACPI_DMAR_PCI_PATH *PciPathScope; + EFI_ACPI_DMAR_PCI_PATH *PciPath; + UINTN PciPathSize; + + Device = DmarDeviceScope; + while ((UINTN)Device < (UINTN)DmarDeviceScope + Size) { + DEBUG ((DEBUG_INFO, " (")); + DEBUG ((DEBUG_INFO, ShortNameOfDmarDeviceType(Device->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", Device->Type)); + DEBUG ((DEBUG_INFO, " EnumId=0x%02x", Device->EnumerationId)); + DEBUG ((DEBUG_INFO, " Bus=0x%02x", Device->StartBusNumber)); + + PciPathScope = (EFI_ACPI_DMAR_PCI_PATH *)(DmarDeviceScope + 1); + PciPathSize = Device->Length - sizeof(EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER); + PciPath = PciPathScope; + while ((UINTN)PciPath < (UINTN)PciPathScope + PciPathSize) { + DEBUG ((DEBUG_INFO, " Pci=0x%02x/0x%02x", PciPath->Device, PciPath->Function)); + PciPath ++; + } + + DEBUG ((DEBUG_INFO, ")")); + Device = (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)((UINTN)Device + Device->Length); + } +} + +EFI_STATUS +DumpAcpiDmar ( + IN EFI_ACPI_DMAR_HEADER *Dmar + ) +{ + EFI_ACPI_DMAR_STRUCTURE_HEADER *DmarStructHeader; + INTN DmarLen; + EFI_ACPI_DMAR_DRHD_HEADER *Drhd; + EFI_ACPI_DMAR_RMRR_HEADER *Rmrr; + EFI_ACPI_DMAR_ATSR_HEADER *Atsr; + EFI_ACPI_DMAR_RHSA_HEADER *Rhsa; + EFI_ACPI_DMAR_ANDD_HEADER *Andd; + + DumpAcpiTableHeader (&Dmar->Header); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " HostAddressWidth=0x%02x Flags=0x%02x\n", Dmar->HostAddressWidth, Dmar->Flags)); + + // + // 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; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfDmarType(DmarStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%04x]", DmarStructHeader->Type)); + DEBUG ((DEBUG_INFO, " Flags=0x%02x", Drhd->Flags)); + DEBUG ((DEBUG_INFO, " Segment=0x%04x", Drhd->SegmentNumber)); + DEBUG ((DEBUG_INFO, " Register=0x%016lx", Drhd->RegisterBaseAddress)); + if ((Drhd->Flags & EFI_ACPI_DMAR_DRHD_FLAGS_INCLUDE_PCI_ALL) != 0) { + DEBUG ((DEBUG_INFO, " (INCLUDE_PCI_ALL)")); + } else { + DumpDmarDeviceScope ((EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)(Drhd + 1), Drhd->Header.Length - sizeof(EFI_ACPI_DMAR_DRHD_HEADER)); + } + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_DMAR_TYPE_RMRR: + Rmrr = (EFI_ACPI_DMAR_RMRR_HEADER *)DmarStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfDmarType(DmarStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%04x]", DmarStructHeader->Type)); + DEBUG ((DEBUG_INFO, " Segment=0x%04x", Rmrr->SegmentNumber)); + DEBUG ((DEBUG_INFO, " Reserved=(0x%016lx-0x%016lx)", Rmrr->ReservedMemoryRegionBaseAddress, Rmrr->ReservedMemoryRegionLimitAddress)); + DumpDmarDeviceScope ((EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)(Rmrr + 1), Rmrr->Header.Length - sizeof(EFI_ACPI_DMAR_RMRR_HEADER)); + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_DMAR_TYPE_ATSR: + Atsr = (EFI_ACPI_DMAR_ATSR_HEADER *)DmarStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfDmarType(DmarStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%04x]", DmarStructHeader->Type)); + DEBUG ((DEBUG_INFO, " Flags=0x%02x", Atsr->Flags)); + DEBUG ((DEBUG_INFO, " Segment=0x%04x", Atsr->SegmentNumber)); + if ((Atsr->Flags & EFI_ACPI_DMAR_ATSR_FLAGS_ALL_PORTS) != 0) { + DEBUG ((DEBUG_INFO, " (ALL_PORTS)")); + } else { + DumpDmarDeviceScope ((EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)(Atsr + 1), Atsr->Header.Length - sizeof(EFI_ACPI_DMAR_ATSR_HEADER)); + } + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_DMAR_TYPE_RHSA: + Rhsa = (EFI_ACPI_DMAR_RHSA_HEADER *)DmarStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfDmarType(DmarStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%04x]", DmarStructHeader->Type)); + DEBUG ((DEBUG_INFO, " Register=0x%016lx", Rhsa->RegisterBaseAddress)); + DEBUG ((DEBUG_INFO, " ProximityDomain=0x%08x", Rhsa->ProximityDomain)); + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_DMAR_TYPE_ANDD: + Andd = (EFI_ACPI_DMAR_ANDD_HEADER *)DmarStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfDmarType(DmarStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%04x]", DmarStructHeader->Type)); + DEBUG ((DEBUG_INFO, " DeviceNumber=0x%02x", Andd->AcpiDeviceNumber)); + DEBUG ((DEBUG_INFO, " ObjectName=%a", Andd + 1)); + DEBUG ((DEBUG_INFO, "\n")); + break; + default: + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfDmarType(DmarStructHeader->Type))); + DEBUG ((DEBUG_INFO, "\n")); + break; + } + DmarStructHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)DmarStructHeader + DmarStructHeader->Length); + DmarLen -= DmarStructHeader->Length; + } + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiHpet.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiHpet.c new file mode 100644 index 0000000000..4eba26ca8f --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiHpet.c @@ -0,0 +1,52 @@ +/** @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 + +VOID +DumpCharArray ( + IN CHAR8 *Ch, + IN UINTN Size + ); + +VOID +DumpAcpiTableHeader ( + IN EFI_ACPI_DESCRIPTION_HEADER *Table + ); + +EFI_STATUS +DumpAcpiHpet ( + IN EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_HEADER *Hpet + ) +{ + DumpAcpiTableHeader (&Hpet->Header); + + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " Timer :")); + DEBUG ((DEBUG_INFO, " BlockId=0x%08x", Hpet->EventTimerBlockId)); + DEBUG ((DEBUG_INFO, " BaseAddress=0x%016lx", Hpet->BaseAddressLower32Bit.Address)); + DEBUG ((DEBUG_INFO, " HpetNumber=0x%08x", Hpet->HpetNumber)); + DEBUG ((DEBUG_INFO, " MinClockTick=0x%04x", Hpet->MainCounterMinimumClockTickInPeriodicMode)); + DEBUG ((DEBUG_INFO, " PageProtection=0x%02x", Hpet->PageProtectionAndOemAttribute)); + DEBUG ((DEBUG_INFO, "\n")); + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiMadt.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiMadt.c new file mode 100644 index 0000000000..9da138daad --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiMadt.c @@ -0,0 +1,241 @@ +/** @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 + +VOID +DumpCharArray ( + IN CHAR8 *Ch, + IN UINTN Size + ); + +VOID +DumpAcpiTableHeader ( + IN EFI_ACPI_DESCRIPTION_HEADER *Table + ); + +typedef struct { + UINT8 Type; + UINT8 Length; +} APIC_STRUCT_HEADER; + +CHAR8 *mMadtTypeString[] = { + "APIC ", + "IO_APIC ", + "INT_SRC_OR", + "NNI_SRC ", + "APIC_NMI ", + "APIC_OR ", + "IO_SAPIC ", + "SAPIC ", + "PL_INT_SRC", + "X2APIC ", + "X2APIC_NMI", +}; + +CHAR8 mUnknownStr[11]; + +CHAR8 * +ShortNameOfMadtType( + IN UINT8 Type + ) +{ + if (Type < sizeof(mMadtTypeString) / sizeof(mMadtTypeString[0])) { + return mMadtTypeString[Type]; + } else { + AsciiSPrint(mUnknownStr, sizeof(mUnknownStr), "[%02x] ", Type); + return mUnknownStr; + } +} + +EFI_STATUS +DumpAcpiMadt ( + IN EFI_ACPI_4_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt + ) +{ + APIC_STRUCT_HEADER *ApicStructHeader; + INTN MadtLen; + EFI_ACPI_4_0_PROCESSOR_LOCAL_APIC_STRUCTURE *ProcessorLocalApic; + EFI_ACPI_4_0_IO_APIC_STRUCTURE *IOApic; + EFI_ACPI_4_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE *InterruptSourceOverride; + EFI_ACPI_4_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE *NonMaskableInterruptSource; + EFI_ACPI_4_0_LOCAL_APIC_NMI_STRUCTURE *LocalApicNMI; + EFI_ACPI_4_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE *LocalApicAddressOverride; + EFI_ACPI_4_0_IO_SAPIC_STRUCTURE *IOSapic; + EFI_ACPI_4_0_PROCESSOR_LOCAL_SAPIC_STRUCTURE *ProcessorLocalSapic; + EFI_ACPI_4_0_PLATFORM_INTERRUPT_SOURCES_STRUCTURE *PlatformInterruptSource; + EFI_ACPI_4_0_PROCESSOR_LOCAL_X2APIC_STRUCTURE *ProcessorLocalX2Apic; + EFI_ACPI_4_0_LOCAL_X2APIC_NMI_STRUCTURE *LocalX2ApicNmi; + + DumpAcpiTableHeader (&Madt->Header); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " LocalApicAddress=0x%08x\n", Madt->LocalApicAddress)); + + // + // Sub table + // + MadtLen = Madt->Header.Length - sizeof(EFI_ACPI_4_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER); + ApicStructHeader = (APIC_STRUCT_HEADER *)(Madt + 1); + while (MadtLen > 0) { + switch (ApicStructHeader->Type) { + case EFI_ACPI_4_0_PROCESSOR_LOCAL_APIC: + ProcessorLocalApic = (EFI_ACPI_4_0_PROCESSOR_LOCAL_APIC_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " ID=0x%02x", ProcessorLocalApic->AcpiProcessorId)); + DEBUG ((DEBUG_INFO, " ApicId=0x%02x", ProcessorLocalApic->ApicId)); + if ((ProcessorLocalApic->Flags & EFI_ACPI_4_0_LOCAL_APIC_ENABLED) != 0) { + DEBUG ((DEBUG_INFO, " (Enabled)")); + } + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_IO_APIC: + IOApic = (EFI_ACPI_4_0_IO_APIC_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " IoApicId=0x%02x", IOApic->IoApicId)); + DEBUG ((DEBUG_INFO, " Address=0x%08x", IOApic->IoApicAddress)); + DEBUG ((DEBUG_INFO, " InterruptBase=0x%08x", IOApic->GlobalSystemInterruptBase)); + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_INTERRUPT_SOURCE_OVERRIDE: + InterruptSourceOverride = (EFI_ACPI_4_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " Bus=0x%02x", InterruptSourceOverride->Bus)); + DEBUG ((DEBUG_INFO, " Source=0x%02x", InterruptSourceOverride->Source)); + DEBUG ((DEBUG_INFO, " Interrupt=0x%08x", InterruptSourceOverride->GlobalSystemInterrupt)); + DEBUG ((DEBUG_INFO, " Flags=0x%04x", InterruptSourceOverride->Flags)); + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_NON_MASKABLE_INTERRUPT_SOURCE: + NonMaskableInterruptSource = (EFI_ACPI_4_0_NON_MASKABLE_INTERRUPT_SOURCE_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " Interrupt=0x%08x", NonMaskableInterruptSource->GlobalSystemInterrupt)); + DEBUG ((DEBUG_INFO, " Flags=0x%04x", NonMaskableInterruptSource->Flags)); + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_LOCAL_APIC_NMI: + LocalApicNMI = (EFI_ACPI_4_0_LOCAL_APIC_NMI_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " ID=0x%02x", LocalApicNMI->AcpiProcessorId)); + DEBUG ((DEBUG_INFO, " Lint=0x%02x", LocalApicNMI->LocalApicLint)); + DEBUG ((DEBUG_INFO, " Flags=0x%04x", LocalApicNMI->Flags)); + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_LOCAL_APIC_ADDRESS_OVERRIDE: + LocalApicAddressOverride = (EFI_ACPI_4_0_LOCAL_APIC_ADDRESS_OVERRIDE_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " LocalApicAddress=0x%016lx", LocalApicAddressOverride->LocalApicAddress)); + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_IO_SAPIC: + IOSapic = (EFI_ACPI_4_0_IO_SAPIC_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " IoApicId=0x%02x", IOSapic->IoApicId)); + DEBUG ((DEBUG_INFO, " InterruptBase=0x%08x", IOSapic->GlobalSystemInterruptBase)); + DEBUG ((DEBUG_INFO, " IoSapicAddress=0x%016lx", IOSapic->IoSapicAddress)); + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_LOCAL_SAPIC: + ProcessorLocalSapic = (EFI_ACPI_4_0_PROCESSOR_LOCAL_SAPIC_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " ID=0x%02x", ProcessorLocalSapic->AcpiProcessorId)); + DEBUG ((DEBUG_INFO, " LocalSapicId=0x%02x", ProcessorLocalSapic->LocalSapicId)); + DEBUG ((DEBUG_INFO, " LocalSapicEid=0x%02x", ProcessorLocalSapic->LocalSapicEid)); + DEBUG ((DEBUG_INFO, " UID=0x%08x", ProcessorLocalSapic->ACPIProcessorUIDValue)); + if ((ProcessorLocalSapic->Flags & EFI_ACPI_5_0_LOCAL_APIC_ENABLED) != 0) { + DEBUG ((DEBUG_INFO, " (Enabled)")); + } + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_PLATFORM_INTERRUPT_SOURCES: + PlatformInterruptSource = (EFI_ACPI_4_0_PLATFORM_INTERRUPT_SOURCES_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " Type=0x%02x", PlatformInterruptSource->InterruptType)); + DEBUG ((DEBUG_INFO, " ID=0x%02x", PlatformInterruptSource->ProcessorId)); + DEBUG ((DEBUG_INFO, " EID=0x%02x", PlatformInterruptSource->ProcessorEid)); + DEBUG ((DEBUG_INFO, " IoSapicVector=0x%02x", PlatformInterruptSource->IoSapicVector)); + DEBUG ((DEBUG_INFO, " Interrupt=0x%08x", PlatformInterruptSource->GlobalSystemInterrupt)); + DEBUG ((DEBUG_INFO, " SourceFlags=0x%08x", PlatformInterruptSource->PlatformInterruptSourceFlags)); + DEBUG ((DEBUG_INFO, " Flags=0x%04x", PlatformInterruptSource->Flags)); + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_PROCESSOR_LOCAL_X2APIC: + ProcessorLocalX2Apic = (EFI_ACPI_4_0_PROCESSOR_LOCAL_X2APIC_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " X2ApicId=0x%08x", ProcessorLocalX2Apic->X2ApicId)); + DEBUG ((DEBUG_INFO, " UID=0x%08x", ProcessorLocalX2Apic->AcpiProcessorUid)); + if ((ProcessorLocalX2Apic->Flags & EFI_ACPI_5_0_LOCAL_APIC_ENABLED) != 0) { + DEBUG ((DEBUG_INFO, " (Enabled)")); + } + DEBUG ((DEBUG_INFO, "\n")); + break; + case EFI_ACPI_4_0_LOCAL_X2APIC_NMI: + LocalX2ApicNmi = (EFI_ACPI_4_0_LOCAL_X2APIC_NMI_STRUCTURE *)ApicStructHeader; + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, ": [0x%02x]", ApicStructHeader->Type)); + DEBUG ((DEBUG_INFO, " UID=0x%08x", LocalX2ApicNmi->AcpiProcessorUid)); + DEBUG ((DEBUG_INFO, " Lint=0x%02x", LocalX2ApicNmi->LocalX2ApicLint)); + DEBUG ((DEBUG_INFO, " Flags=0x%04x", LocalX2ApicNmi->Flags)); + DEBUG ((DEBUG_INFO, "\n")); + break; + default: + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, ShortNameOfMadtType(ApicStructHeader->Type))); + DEBUG ((DEBUG_INFO, "\n")); + break; + } + ApicStructHeader = (APIC_STRUCT_HEADER *)((UINT8 *)ApicStructHeader + ApicStructHeader->Length); + MadtLen -= ApicStructHeader->Length; + } + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiMcfg.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiMcfg.c new file mode 100644 index 0000000000..097a688004 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiMcfg.c @@ -0,0 +1,63 @@ +/** @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 + +VOID +DumpCharArray ( + IN CHAR8 *Ch, + IN UINTN Size + ); + +VOID +DumpAcpiTableHeader ( + IN EFI_ACPI_DESCRIPTION_HEADER *Table + ); + +EFI_STATUS +DumpAcpiMcfg ( + IN EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER *Mcfg + ) +{ + EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE *Struct; + UINTN Count; + UINTN Index; + + DumpAcpiTableHeader (&Mcfg->Header); + + Count = Mcfg->Header.Length - sizeof(EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER); + Count = Count / sizeof(EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE); + Struct = (VOID *)(Mcfg + 1); + for (Index = 0; Index < Count; Index++) { + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " Segment :")); + DEBUG ((DEBUG_INFO, " BaseAddress=0x%016lx", Struct->BaseAddress)); + DEBUG ((DEBUG_INFO, " Seg=0x%04x Bus=(0x%02x-0x%02x)", + Struct->PciSegmentGroupNumber, + Struct->StartBusNumber, + Struct->EndBusNumber + )); + DEBUG ((DEBUG_INFO, "\n")); + Struct++; + } + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiWsmt.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiWsmt.c new file mode 100644 index 0000000000..001b1d4357 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpAcpiWsmt.c @@ -0,0 +1,45 @@ +/** @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 + +VOID +DumpCharArray ( + IN CHAR8 *Ch, + IN UINTN Size + ); + +VOID +DumpAcpiTableHeader ( + IN EFI_ACPI_DESCRIPTION_HEADER *Table + ); + +EFI_STATUS +DumpAcpiWsmt ( + IN EFI_ACPI_WSMT_TABLE *Wsmt + ) +{ + DumpAcpiTableHeader (&Wsmt->Header); + DEBUG ((DEBUG_INFO, " ")); + DEBUG ((DEBUG_INFO, " ProtectionFlags=0x%08x\n", Wsmt->ProtectionFlags)); + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpBootVariable.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpBootVariable.c new file mode 100644 index 0000000000..763960cf5a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpBootVariable.c @@ -0,0 +1,195 @@ +/** @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 + +CHAR16 *mLoadOptionVariableList[] = { + L"Boot", + L"Driver", + L"SysPrep", +}; + +CHAR16 *mPlatformRecoveryOptionVariableList[] = { + L"PlatformRecovery", // does not have PlatformRecoveryOrder +}; + +CHAR16 *mOsRecoveryOptionVariableList[] = { + L"OsRecovery", // VariableGuid in OsRecoveryOrder +}; + +CHAR16 *mKeyOptionVariableList[] = { + L"Key", // does not have KeyOrder +}; + +VOID +DumpLoadOption ( + IN CHAR16 *OptionName, + IN EFI_LOAD_OPTION *LoadOption, + IN UINTN Size + ) +{ + CHAR16 *Str; + CHAR16 *Description; + EFI_DEVICE_PATH_PROTOCOL *FilePathList; + + if (LoadOption == NULL) { + DEBUG ((DEBUG_INFO, "%s: \n", OptionName)); + return ; + } + + Description = (CHAR16 *)(LoadOption + 1); + + FilePathList = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)Description + StrSize (Description)); + + DEBUG ((DEBUG_INFO, "%s: [0x%08x] \"%s\"", OptionName, LoadOption->Attributes, Description)); + Str = ConvertDevicePathToText(FilePathList, TRUE, TRUE); + DEBUG ((DEBUG_INFO, " %s\n", Str)); + if (Str != NULL) { + FreePool (Str); + } +} + +VOID +DumpKeyOption ( + IN CHAR16 *OptionName, + IN EFI_KEY_OPTION *KeyOption, + IN UINTN Size + ) +{ + UINTN Index; + EFI_INPUT_KEY *Keys; + + Keys = (EFI_INPUT_KEY *)(KeyOption + 1); + + DEBUG ((DEBUG_INFO, "%s: [Boot%04x] 0x%08x", OptionName, KeyOption->BootOption, KeyOption->KeyData.PackedValue)); + for (Index = 0; Index < KeyOption->KeyData.Options.InputKeyCount; Index++) { + DEBUG ((DEBUG_INFO, " (%04x/%04x)", Keys[Index].ScanCode, Keys[Index].UnicodeChar)); + } + DEBUG ((DEBUG_INFO, "\n")); +} + +VOID +DumpLoadOptionVariable ( + VOID + ) +{ + UINT16 *BootOrder; + UINTN OrderSize; + VOID *Variable; + UINTN ListIndex; + UINTN Size; + UINTN Index; + EFI_STATUS Status; + CHAR16 BootOptionName[sizeof(L"PlatformRecovery####")]; + CHAR16 BootOrderName[sizeof(L"PlatformRecoveryOrder")]; + + for (ListIndex = 0; ListIndex < sizeof(mLoadOptionVariableList)/sizeof(mLoadOptionVariableList[0]); ListIndex++) { + UnicodeSPrint (BootOrderName, sizeof(BootOrderName), L"%sOrder", mLoadOptionVariableList[ListIndex]); + Status = GetVariable2 (BootOrderName, &gEfiGlobalVariableGuid, &BootOrder, &OrderSize); + if (EFI_ERROR(Status)) { + continue; + } + for (Index = 0; Index < OrderSize/sizeof(CHAR16); Index++) { + UnicodeSPrint (BootOptionName, sizeof(BootOptionName), L"%s%04x", mLoadOptionVariableList[ListIndex], BootOrder[Index]); + Status = GetVariable2 (BootOptionName, &gEfiGlobalVariableGuid, &Variable, &Size); + if (!EFI_ERROR(Status)) { + DumpLoadOption (BootOptionName, Variable, Size); + } else { + DumpLoadOption (BootOptionName, NULL, 0); + } + } + } +} + +VOID +DumpPlatformRecoveryOptionVariable ( + VOID + ) +{ + VOID *Variable; + UINTN ListIndex; + UINTN Size; + UINTN Index; + EFI_STATUS Status; + CHAR16 PlatformRecoveryOptionName[sizeof(L"PlatformRecovery####")]; + + for (ListIndex = 0; ListIndex < sizeof(mPlatformRecoveryOptionVariableList)/sizeof(mPlatformRecoveryOptionVariableList[0]); ListIndex++) { + for (Index = 0; ; Index++) { + UnicodeSPrint (PlatformRecoveryOptionName, sizeof(PlatformRecoveryOptionName), L"%s%04x", mPlatformRecoveryOptionVariableList[ListIndex], Index); + Status = GetVariable2 (PlatformRecoveryOptionName, &gEfiGlobalVariableGuid, &Variable, &Size); + if (!EFI_ERROR(Status)) { + DumpLoadOption (PlatformRecoveryOptionName, Variable, Size); + } else { + break; + } + } + } +} + +VOID +DumpOsRecoveryOptionVariable ( + VOID + ) +{ +} + +VOID +DumpKeyOptionVariable ( + VOID + ) +{ + VOID *Variable; + UINTN ListIndex; + UINTN Size; + UINTN Index; + EFI_STATUS Status; + CHAR16 KeyOptionName[sizeof(L"Key####")]; + + for (ListIndex = 0; ListIndex < sizeof(mKeyOptionVariableList)/sizeof(mKeyOptionVariableList[0]); ListIndex++) { + for (Index = 0; ; Index++) { + UnicodeSPrint (KeyOptionName, sizeof(KeyOptionName), L"%s%04x", mKeyOptionVariableList[ListIndex], Index); + Status = GetVariable2 (KeyOptionName, &gEfiGlobalVariableGuid, &Variable, &Size); + if (!EFI_ERROR(Status)) { + DumpKeyOption (KeyOptionName, Variable, Size); + } else { + break; + } + } + } +} + +EFI_STATUS +TestPointDumpBootVariable ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "==== TestPointDumpBootVariable - Enter\n")); + + DumpLoadOptionVariable (); + DumpPlatformRecoveryOptionVariable (); + DumpOsRecoveryOptionVariable (); + DumpKeyOptionVariable (); + + DEBUG ((DEBUG_INFO, "==== TestPointDumpBootVariable - Exit\n")); + + // Check - TBD + return EFI_SUCCESS; +} \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpConsoleVariable.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpConsoleVariable.c new file mode 100644 index 0000000000..b78235a73f --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpConsoleVariable.c @@ -0,0 +1,69 @@ +/** @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 + +CHAR16 *mConsoleVariableList[] = { + L"ConIn", + L"ConInDev", + L"ConOut", + L"ConOutDev", + L"ErrOut", + L"ErrOutDev", +}; + +VOID +DumpDevicePath ( + IN CHAR16 *Name, + IN EFI_DEVICE_PATH *DevicePath, + IN UINTN Size + ) +{ + CHAR16 *Str; + + Str = ConvertDevicePathToText(DevicePath, TRUE, TRUE); + DEBUG ((DEBUG_INFO, "%s: %s\n", Name, Str)); + if (Str != NULL) { + FreePool (Str); + } +} + +EFI_STATUS +TestPointDumpConsoleVariable ( + VOID + ) +{ + VOID *Variable; + UINTN Size; + UINTN Index; + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpConsoleVariable - Enter\n")); + for (Index = 0; Index < sizeof(mConsoleVariableList)/sizeof(mConsoleVariableList[0]); Index++) { + Status = GetVariable2 (mConsoleVariableList[Index], &gEfiGlobalVariableGuid, &Variable, &Size); + if (!EFI_ERROR(Status)) { + DumpDevicePath (mConsoleVariableList[Index], Variable, Size); + } + } + DEBUG ((DEBUG_INFO, "==== TestPointDumpConsoleVariable - Exit\n")); + + // Check - TBD + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpDevicePath.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpDevicePath.c new file mode 100644 index 0000000000..eff049591e --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpDevicePath.c @@ -0,0 +1,78 @@ +/** @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 +TestPointDumpDevicePath ( + VOID + ) +{ + UINTN Index; + EFI_HANDLE *HandleBuf; + UINTN HandleCount; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_STATUS Status; + CHAR16 *Str; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpDevicePath - Enter\n")); + HandleBuf = NULL; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiDevicePathProtocolGuid, + NULL, + &HandleCount, + &HandleBuf + ); + if (EFI_ERROR (Status)) { + goto Done ; + } + + DEBUG ((DEBUG_INFO, "DeviceList:\n")); + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol ( + HandleBuf[Index], + &gEfiDevicePathProtocolGuid, + (VOID**)&DevicePath + ); + if (EFI_ERROR (Status)) { + continue; + } + Str = ConvertDevicePathToText(DevicePath, TRUE, TRUE); + DEBUG ((DEBUG_INFO, " %s\n", Str)); + if (Str != NULL) { + FreePool (Str); + } + } + +Done: + if (HandleBuf != NULL) { + FreePool (HandleBuf); + } + + DEBUG ((DEBUG_INFO, "==== TestPointDumpDevicePath - Enter\n")); + + // Check - TBD + return EFI_SUCCESS; +} \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpEsrt.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpEsrt.c new file mode 100644 index 0000000000..48c1eaa3a3 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpEsrt.c @@ -0,0 +1,120 @@ +/** @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 + +CHAR8 *mFwTypeString[] = { + " Unknown ", + " System ", + " Device ", + " Driver ", +}; + +CHAR8 *mLastAttemptStatusString[] = { + "Success", + "Error: Unsuccessful", + "Error: Insufficient Resources", + "Error: Incorrect Version", + "Error: Invalid Format", + "Error: Auth Error", + "Error: Power Event AC", + "Error: Power Event Battery", +}; + +CHAR8 mUnknownStr[11]; + +CHAR8 * +FwTypeToString( + IN UINT32 FwType + ) +{ + if (FwType < sizeof(mFwTypeString) / sizeof(mFwTypeString[0])) { + return mFwTypeString[FwType]; + } else { + AsciiSPrint(mUnknownStr, sizeof(mUnknownStr), "[%08x]", FwType); + return mUnknownStr; + } +} + +CHAR8 * +LastAttemptStatusToString( + IN UINT32 LastAttemptStatus + ) +{ + if (LastAttemptStatus < sizeof(mLastAttemptStatusString) / sizeof(mLastAttemptStatusString[0])) { + return mLastAttemptStatusString[LastAttemptStatus]; + } else { + return "Error: Unknown"; + } +} + +VOID +DumpEsrt ( + IN EFI_SYSTEM_RESOURCE_TABLE *Esrt + ) +{ + UINTN Index; + EFI_SYSTEM_RESOURCE_ENTRY *EsrtEntry; + + DEBUG ((DEBUG_INFO, "ESRT Table:")); + DEBUG ((DEBUG_INFO, " Count=0x%x", Esrt->FwResourceCount)); + DEBUG ((DEBUG_INFO, " CountMax=0x%x", Esrt->FwResourceCountMax)); + DEBUG ((DEBUG_INFO, " Version=0x%lx\n", Esrt->FwResourceVersion)); + + DEBUG ((DEBUG_INFO, " FwClass FwType Version LowestVer Flags AttemptVer Attempt\n")); +//DEBUG ((DEBUG_INFO, " 00000000-0000-0000-0000-000000000000 [00000000] 0x00000000 0x00000000 0x00000000 0x00000000 Success\n")); + EsrtEntry = (VOID *)(Esrt + 1); + for (Index = 0; Index < Esrt->FwResourceCount; Index++) { + DEBUG ((DEBUG_INFO, " %g ", &EsrtEntry->FwClass)); + DEBUG ((DEBUG_INFO, FwTypeToString(EsrtEntry->FwType))); + DEBUG ((DEBUG_INFO, " 0x%08x", EsrtEntry->FwVersion)); + DEBUG ((DEBUG_INFO, " 0x%08x", EsrtEntry->LowestSupportedFwVersion)); + DEBUG ((DEBUG_INFO, " 0x%08x", EsrtEntry->CapsuleFlags)); + DEBUG ((DEBUG_INFO, " 0x%08x ", EsrtEntry->LastAttemptVersion)); + DEBUG ((DEBUG_INFO, LastAttemptStatusToString(EsrtEntry->LastAttemptStatus))); + DEBUG ((DEBUG_INFO, "\n")); + EsrtEntry++; + } +} + +EFI_STATUS +TestPointDumpEsrt ( + VOID + ) +{ + EFI_STATUS Status; + EFI_SYSTEM_RESOURCE_TABLE *Esrt; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpEsrt - Enter\n")); + Status = EfiGetSystemConfigurationTable (&gEfiSystemResourceTableGuid, (VOID **)&Esrt); + if (!EFI_ERROR(Status)) { + DumpEsrt(Esrt); + } else { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_9 TEST_POINT_READY_TO_BOOT TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_9 + ); + } + DEBUG ((DEBUG_INFO, "==== TestPointDumpEsrt - Exit\n")); + + return Status; +} \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpGcd.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpGcd.c new file mode 100644 index 0000000000..46fde33ab1 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpGcd.c @@ -0,0 +1,230 @@ +/** @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 + +CHAR8 *mGcdMemoryTypeShortName[] = { + " NE ", + " RSVD", + " SYS ", + " MMIO", + " PERS", + " RELI", +}; + +CHAR8 mUnknownStr[11]; + +CHAR8 * +ShortNameOfGcdMemoryType( + IN UINT32 Type + ) +{ + if (Type < sizeof(mGcdMemoryTypeShortName) / sizeof(mGcdMemoryTypeShortName[0])) { + return mGcdMemoryTypeShortName[Type]; + } else { + return " ???? "; + } +} + +CHAR8 *mGcdIoTypeShortName[] = { + " NE ", + " RSVD", + " SYS ", +}; + +CHAR8 * +ShortNameOfGcdIoType( + IN UINT32 Type + ) +{ + if (Type < sizeof(mGcdIoTypeShortName) / sizeof(mGcdIoTypeShortName[0])) { + return mGcdIoTypeShortName[Type]; + } else { + return " ???? "; + } +} + +VOID +PrintBitMask ( + IN UINT64 Bit, + IN UINT64 Capabilities, + IN UINT64 Attributes + ) +{ + if ((Capabilities & Bit) != 0) { + if ((Attributes & Bit) != 0) { + DEBUG ((DEBUG_INFO, "1")); + } else { + DEBUG ((DEBUG_INFO, "0")); + } + } else { + DEBUG ((DEBUG_INFO, "-")); + } +} + +VOID +PrintMemoryDescriptorHeader ( + VOID + ) +{ + if (sizeof(UINT64) == sizeof(UINTN)) { + DEBUG ((DEBUG_INFO, " U \n")); + DEBUG ((DEBUG_INFO, " RRMNXRWCWWWU \n")); + DEBUG ((DEBUG_INFO, "Base Address End Address Type TORVPPPEBTCC Image Device \n")); + DEBUG ((DEBUG_INFO, "================ ================ ==== ============ ================ ================\n")); + } else { + DEBUG ((DEBUG_INFO, " U \n")); + DEBUG ((DEBUG_INFO, " RRMNXRWCWWWU \n")); + DEBUG ((DEBUG_INFO, "Base Address End Address Type TORVPPPEBTCC Image Device \n")); + DEBUG ((DEBUG_INFO, "================ ================ ==== ============ ======== ========\n")); + } +} + +VOID +PrintMemoryDescriptor ( + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemoryDescriptor + ) +{ + DEBUG ((DEBUG_INFO, + "%016lx-%016lx", + MemoryDescriptor->BaseAddress, + MemoryDescriptor->BaseAddress + MemoryDescriptor->Length - 1 + )); + + DEBUG ((DEBUG_INFO, ShortNameOfGcdMemoryType(MemoryDescriptor->GcdMemoryType))); + DEBUG ((DEBUG_INFO, " ")); + + if (MemoryDescriptor->GcdMemoryType != EfiGcdMemoryTypeNonExistent) { + PrintBitMask (EFI_MEMORY_RUNTIME, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_RO, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_MORE_RELIABLE, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_NV, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_XP, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_RP, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_WP, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_UCE, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_WB, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_WT, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_WC, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + PrintBitMask (EFI_MEMORY_UC, MemoryDescriptor->Capabilities, MemoryDescriptor->Attributes); + } else { + DEBUG ((DEBUG_INFO, " ")); + } + + if (sizeof(UINT64) == sizeof(UINTN)) { + if (MemoryDescriptor->ImageHandle != NULL) { + DEBUG ((DEBUG_INFO, " %016lx", (UINT64)(UINTN)MemoryDescriptor->ImageHandle)); + if (MemoryDescriptor->DeviceHandle != NULL) { + DEBUG ((DEBUG_INFO, " %016lx", (UINT64)(UINTN)MemoryDescriptor->ImageHandle)); + } + } + } else { + if (MemoryDescriptor->ImageHandle != NULL) { + DEBUG ((DEBUG_INFO, " %08x", MemoryDescriptor->ImageHandle)); + if (MemoryDescriptor->DeviceHandle != NULL) { + DEBUG ((DEBUG_INFO, " %08x", MemoryDescriptor->ImageHandle)); + } + } + } + + DEBUG ((DEBUG_INFO, "\n")); +} + +VOID +PrintIoDescriptorHeader ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Base Address End Address Type Image Device \n")); + DEBUG ((DEBUG_INFO, "================ ================ ==== ======== ========\n")); +} + +VOID +PrintIoDescriptor ( + EFI_GCD_IO_SPACE_DESCRIPTOR *IoDescriptor + ) +{ + DEBUG ((DEBUG_INFO, + "%016lx-%016lx", + IoDescriptor->BaseAddress, + IoDescriptor->BaseAddress + IoDescriptor->Length - 1 + )); + + DEBUG ((DEBUG_INFO, ShortNameOfGcdIoType (IoDescriptor->GcdIoType))); + + if (IoDescriptor->ImageHandle != NULL) { + DEBUG ((DEBUG_INFO, " %08x", IoDescriptor->ImageHandle)); + if (IoDescriptor->DeviceHandle != NULL) { + DEBUG ((DEBUG_INFO, " %08x", IoDescriptor->ImageHandle)); + } + } + + DEBUG ((DEBUG_INFO, "\n")); +} + +EFI_STATUS +TestPointDumpGcd ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemoryMap; + EFI_GCD_IO_SPACE_DESCRIPTOR *IoMap; + UINTN NumberOfDescriptors; + UINTN Index; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpGcd - Enter\n")); + DEBUG ((DEBUG_INFO, "GCD MEM:\n")); + NumberOfDescriptors = 0; + MemoryMap = NULL; + Status = gDS->GetMemorySpaceMap ( + &NumberOfDescriptors, + &MemoryMap + ); + if (!EFI_ERROR (Status)) { + PrintMemoryDescriptorHeader (); + for (Index = 0; Index < NumberOfDescriptors; Index++) { + PrintMemoryDescriptor (&MemoryMap[Index]); + } + } else { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_END_OF_DXE_ERROR_CODE_3 TEST_POINT_END_OF_DXE TEST_POINT_BYTE2_END_OF_DXE_ERROR_STRING_3 + ); + goto Done; + } + + DEBUG ((DEBUG_INFO, "GCD IO:\n")); + NumberOfDescriptors = 0; + IoMap = NULL; + Status = gDS->GetIoSpaceMap ( + &NumberOfDescriptors, + &IoMap + ); + if (!EFI_ERROR (Status)) { + PrintIoDescriptorHeader (); + for (Index = 0; Index < NumberOfDescriptors; Index++) { + PrintIoDescriptor (&IoMap[Index]); + } + } + +Done: + DEBUG ((DEBUG_INFO, "==== TestPointDumpGcd - Exit\n")); + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpHsti.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpHsti.c new file mode 100644 index 0000000000..826a0b1ba4 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpHsti.c @@ -0,0 +1,123 @@ +/** @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 + +/** + Dump HSTI info + + @param[in] HstiData - Pointer to HSTI data +**/ +VOID +DumpHsti ( + IN VOID *HstiData + ) +{ + ADAPTER_INFO_PLATFORM_SECURITY *Hsti; + UINT8 *SecurityFeatures; + CHAR16 *ErrorString; + UINTN Index; + CHAR16 ErrorChar; + + Hsti = HstiData; + DEBUG ((DEBUG_INFO, "HSTI\n")); + DEBUG ((DEBUG_INFO, " Version - 0x%08x\n", Hsti->Version)); + DEBUG ((DEBUG_INFO, " Role - 0x%08x\n", Hsti->Role)); + DEBUG ((DEBUG_INFO, " ImplementationID - %S\n", Hsti->ImplementationID)); + DEBUG ((DEBUG_INFO, " SecurityFeaturesSize - 0x%08x\n", Hsti->SecurityFeaturesSize)); + + SecurityFeatures = (UINT8 *) (Hsti + 1); + DEBUG ((DEBUG_INFO, " SecurityFeaturesRequired - ")); + for (Index = 0; Index < Hsti->SecurityFeaturesSize; Index++) { + DEBUG ((DEBUG_INFO, "%02x ", SecurityFeatures[Index])); + } + DEBUG ((DEBUG_INFO, "\n")); + + SecurityFeatures = (UINT8 *) (SecurityFeatures + Hsti->SecurityFeaturesSize); + DEBUG ((DEBUG_INFO, " SecurityFeaturesImplemented - ")); + for (Index = 0; Index < Hsti->SecurityFeaturesSize; Index++) { + DEBUG ((DEBUG_INFO, "%02x ", SecurityFeatures[Index])); + } + DEBUG ((DEBUG_INFO, "\n")); + + SecurityFeatures = (UINT8 *) (SecurityFeatures + Hsti->SecurityFeaturesSize); + DEBUG ((DEBUG_INFO, " SecurityFeaturesVerified - ")); + for (Index = 0; Index < Hsti->SecurityFeaturesSize; Index++) { + DEBUG ((DEBUG_INFO, "%02x ", SecurityFeatures[Index])); + } + DEBUG ((DEBUG_INFO, "\n")); + + ErrorString = (CHAR16 *) (SecurityFeatures + Hsti->SecurityFeaturesSize); + DEBUG ((DEBUG_INFO, " ErrorString - \"")); + CopyMem (&ErrorChar, ErrorString, sizeof (ErrorChar)); + for (; ErrorChar != 0;) { + DEBUG ((DEBUG_INFO, "%c", ErrorChar)); + ErrorString++; + CopyMem (&ErrorChar, ErrorString, sizeof (ErrorChar)); + } + DEBUG ((DEBUG_INFO, "\"\n")); +} + +UINT32 mRole[] = { + PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE, + PLATFORM_SECURITY_ROLE_PLATFORM_IBV, + PLATFORM_SECURITY_ROLE_IMPLEMENTOR_OEM, + PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM, +}; + +EFI_STATUS +TestPointDumpHsti ( + VOID + ) +{ + VOID *Hsti; + UINTN HstiSize; + EFI_STATUS Status; + UINTN Index; + BOOLEAN Result; + + Result = TRUE; + DEBUG ((DEBUG_INFO, "==== TestPointDumpHsti - Enter\n")); + for (Index = 0; Index < sizeof(mRole)/sizeof(mRole[0]); Index++) { + Status = HstiLibGetTable (mRole[Index], NULL, &Hsti, &HstiSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "HSTI (Role - 0x%08x) not found!\n", mRole[Index])); + if (mRole[Index] <= PLATFORM_SECURITY_ROLE_PLATFORM_IBV) { + Result = FALSE; + } + continue; + } + DumpHsti (Hsti); + FreePool (Hsti); + } + DEBUG ((DEBUG_INFO, "==== TestPointDumpHsti - Exit\n")); + + if (!Result) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_8 TEST_POINT_READY_TO_BOOT TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_8 + ); + return EFI_NOT_FOUND; + } + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpLoadedImage.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpLoadedImage.c new file mode 100644 index 0000000000..8b717e08ed --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpLoadedImage.c @@ -0,0 +1,203 @@ +/** @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 + +BOOLEAN +IsRuntimeImage ( + IN VOID *Pe32Data + ) +{ + EFI_IMAGE_DOS_HEADER *DosHdr; + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; + UINT16 Magic; + UINT16 Subsystem; + + ASSERT (Pe32Data != NULL); + + DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data; + if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) { + // + // DOS image header is present, so read the PE header after the DOS image header. + // + Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff)); + } else { + // + // DOS image header is not present, so PE header is at the image base. + // + Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data; + } + + if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) { + // + // NOTE: We use Machine field to identify PE32/PE32+, instead of Magic. + // It is due to backward-compatibility, for some system might + // generate PE32+ image with PE32 Magic. + // + switch (Hdr.Pe32->FileHeader.Machine) { + case IMAGE_FILE_MACHINE_I386: + // + // Assume PE32 image with IA32 Machine field. + // + Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC; + break; + case IMAGE_FILE_MACHINE_X64: + case IMAGE_FILE_MACHINE_IA64: + // + // Assume PE32+ image with x64 or IA64 Machine field + // + Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; + break; + default: + // + // For unknow Machine field, use Magic in optional Header + // + Magic = Hdr.Pe32->OptionalHeader.Magic; + } + + if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + Subsystem = Hdr.Pe32->OptionalHeader.Subsystem; + } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + Subsystem = Hdr.Pe32Plus->OptionalHeader.Subsystem; + } + if (Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) { + return TRUE; + } + } + + return FALSE; +} + +VOID +DumpLoadedImage ( + IN UINTN Index, + IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, + IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath + ) +{ + CHAR16 *Str; + CHAR8 *PdbPointer; + + DEBUG ((DEBUG_INFO, "[0x%04x]:", Index)); + if (IsRuntimeImage (LoadedImage->ImageBase)) { + DEBUG ((DEBUG_INFO, " (RT)")); + } else { + DEBUG ((DEBUG_INFO, " ")); + } + DEBUG ((DEBUG_INFO, " 0x%016lx-0x%016lx", (UINT64)(UINTN)LoadedImage->ImageBase, LoadedImage->ImageSize)); + + if (LoadedImageDevicePath != NULL) { + Str = ConvertDevicePathToText(LoadedImageDevicePath, TRUE, TRUE); + DEBUG ((DEBUG_INFO, " LoadedImageDevicePath=%s", Str)); + if (Str != NULL) { + FreePool (Str); + } + } else { + if (LoadedImage->FilePath != NULL) { + Str = ConvertDevicePathToText(LoadedImage->FilePath, TRUE, TRUE); + DEBUG ((DEBUG_INFO, " FilePath=%s", Str)); + if (Str != NULL) { + FreePool (Str); + } + } + + if (DevicePath != NULL) { + Str = ConvertDevicePathToText(DevicePath, TRUE, TRUE); + DEBUG ((DEBUG_INFO, " DevicePath=%s", Str)); + if (Str != NULL) { + FreePool (Str); + } + } + } + + PdbPointer = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase); + if (PdbPointer != NULL) { + DEBUG ((DEBUG_INFO, " (pdb - %a)", PdbPointer)); + } + + DEBUG ((DEBUG_INFO, "\n")); +} + +EFI_STATUS +TestPointDumpLoadedImage ( + VOID + ) +{ + EFI_STATUS Status; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + UINTN Index; + EFI_HANDLE *HandleBuf; + UINTN HandleCount; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpLoadedImage - Enter\n")); + HandleBuf = NULL; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiLoadedImageProtocolGuid, + NULL, + &HandleCount, + &HandleBuf + ); + if (EFI_ERROR (Status)) { + goto Done ; + } + + DEBUG ((DEBUG_INFO, "LoadedImage (%d):\n", HandleCount)); + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol ( + HandleBuf[Index], + &gEfiLoadedImageProtocolGuid, + (VOID **)&LoadedImage + ); + if (EFI_ERROR(Status)) { + continue; + } + + Status = gBS->HandleProtocol (LoadedImage->DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath); + if (EFI_ERROR(Status)) { + DevicePath = NULL; + } + + Status = gBS->HandleProtocol (HandleBuf[Index], &gEfiLoadedImageDevicePathProtocolGuid, (VOID **)&LoadedImageDevicePath); + if (EFI_ERROR(Status)) { + LoadedImageDevicePath = NULL; + } + + DumpLoadedImage (Index, LoadedImage, DevicePath, LoadedImageDevicePath); + } + +Done: + + if (HandleBuf != NULL) { + FreePool (HandleBuf); + } + + DEBUG ((DEBUG_INFO, "==== TestPointDumpLoadedImage - Exit\n")); + + // Check - TBD + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemAttribute.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemAttribute.c new file mode 100644 index 0000000000..57a86963f2 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemAttribute.c @@ -0,0 +1,89 @@ +/** @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 + +CHAR8 * +ShortNameOfMemoryType( + IN UINT32 Type + ); + +VOID +DumpMemoryAttributesTable ( + IN EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable + ) +{ + UINTN Index; + EFI_MEMORY_DESCRIPTOR *Entry; + UINT64 Pages[EfiMaxMemoryType]; + + ZeroMem (Pages, sizeof(Pages)); + + DEBUG ((DEBUG_INFO, "MemoryAttributesTable:")); + DEBUG ((DEBUG_INFO, " Version=0x%x", MemoryAttributesTable->Version)); + DEBUG ((DEBUG_INFO, " Count=0x%x", MemoryAttributesTable->NumberOfEntries)); + DEBUG ((DEBUG_INFO, " DescriptorSize=0x%x\n", MemoryAttributesTable->DescriptorSize)); + Entry = (EFI_MEMORY_DESCRIPTOR *)(MemoryAttributesTable + 1); + DEBUG ((DEBUG_INFO, "Type Start End # Pages Attributes\n")); + for (Index = 0; Index < MemoryAttributesTable->NumberOfEntries; Index++) { + DEBUG ((DEBUG_INFO, ShortNameOfMemoryType(Entry->Type))); + DEBUG ((DEBUG_INFO, " %016LX-%016LX %016LX %016LX\n", + Entry->PhysicalStart, + Entry->PhysicalStart+MultU64x64 (SIZE_4KB,Entry->NumberOfPages) - 1, + Entry->NumberOfPages, + Entry->Attribute + )); + if (Entry->Type < EfiMaxMemoryType) { + Pages[Entry->Type] += Entry->NumberOfPages; + } + Entry = NEXT_MEMORY_DESCRIPTOR (Entry, MemoryAttributesTable->DescriptorSize); + } + + DEBUG ((DEBUG_INFO, "\n")); + DEBUG ((DEBUG_INFO, " RT_Code : %14ld Pages (%ld Bytes)\n", Pages[EfiRuntimeServicesCode], MultU64x64(SIZE_4KB, Pages[EfiRuntimeServicesCode]))); + DEBUG ((DEBUG_INFO, " RT_Data : %14ld Pages (%ld Bytes)\n", Pages[EfiRuntimeServicesData], MultU64x64(SIZE_4KB, Pages[EfiRuntimeServicesData]))); + DEBUG ((DEBUG_INFO, " -------------- \n")); +} + +EFI_STATUS +TestPointDumpMemAttribute ( + VOID + ) +{ + EFI_STATUS Status; + VOID *MemoryAttributesTable; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpMemAttribute - Enter\n")); + Status = EfiGetSystemConfigurationTable (&gEfiMemoryAttributesTableGuid, &MemoryAttributesTable); + if (!EFI_ERROR (Status)) { + DumpMemoryAttributesTable(MemoryAttributesTable); + } else { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_4 TEST_POINT_READY_TO_BOOT TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_4 + ); + } + DEBUG ((DEBUG_INFO, "==== TestPointDumpMemAttribute - Exit\n")); + + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemMap.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemMap.c new file mode 100644 index 0000000000..6d59c7773c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemMap.c @@ -0,0 +1,219 @@ +/** @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 + +CHAR8 *mMemoryTypeShortName[] = { + "Reserved ", + "LoaderCode", + "LoaderData", + "BS_Code ", + "BS_Data ", + "RT_Code ", + "RT_Data ", + "Available ", + "Unusable ", + "ACPI_Recl ", + "ACPI_NVS ", + "MMIO ", + "MMIO_Port ", + "PalCode ", + "Persistent", +}; + +CHAR8 mUnknownStr[11]; + +CHAR8 * +ShortNameOfMemoryType( + IN UINT32 Type + ) +{ + if (Type < sizeof(mMemoryTypeShortName) / sizeof(mMemoryTypeShortName[0])) { + return mMemoryTypeShortName[Type]; + } else { + AsciiSPrint(mUnknownStr, sizeof(mUnknownStr), "[%08x]", Type); + return mUnknownStr; + } +} + + +/** + Dump memory map. + + @param MemoryMap A pointer to the buffer in which firmware places + the current memory map. + @param MemoryMapSize Size, in bytes, of the MemoryMap buffer. + @param DescriptorSize Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR. +**/ +VOID +DumpMemoryMap ( + IN EFI_MEMORY_DESCRIPTOR *MemoryMap, + IN UINTN MemoryMapSize, + IN UINTN DescriptorSize + ) +{ + EFI_MEMORY_DESCRIPTOR *Entry; + UINTN NumberOfEntries; + UINTN Index; + UINT64 Pages[EfiMaxMemoryType]; + + ZeroMem (Pages, sizeof(Pages)); + + DEBUG ((EFI_D_INFO, "MemoryMap:\n")); + + Entry = MemoryMap; + NumberOfEntries = MemoryMapSize / DescriptorSize; + DEBUG ((DEBUG_INFO, "Type Start End # Pages Attributes\n")); + for (Index = 0; Index < NumberOfEntries; Index++) { + DEBUG ((DEBUG_INFO, ShortNameOfMemoryType(Entry->Type))); + DEBUG ((DEBUG_INFO, " %016LX-%016LX %016LX %016LX\n", + Entry->PhysicalStart, + Entry->PhysicalStart+MultU64x64 (SIZE_4KB,Entry->NumberOfPages) - 1, + Entry->NumberOfPages, + Entry->Attribute + )); + if (Entry->Type < EfiMaxMemoryType) { + Pages[Entry->Type] += Entry->NumberOfPages; + } + Entry = NEXT_MEMORY_DESCRIPTOR (Entry, DescriptorSize); + } + + DEBUG ((DEBUG_INFO, "\n")); + DEBUG ((DEBUG_INFO, " Reserved : %14ld Pages (%ld Bytes)\n", Pages[EfiReservedMemoryType], MultU64x64(SIZE_4KB, Pages[EfiReservedMemoryType]))); + DEBUG ((DEBUG_INFO, " LoaderCode: %14ld Pages (%ld Bytes)\n", Pages[EfiLoaderCode], MultU64x64(SIZE_4KB, Pages[EfiLoaderCode]))); + DEBUG ((DEBUG_INFO, " LoaderData: %14ld Pages (%ld Bytes)\n", Pages[EfiLoaderData], MultU64x64(SIZE_4KB, Pages[EfiLoaderData]))); + DEBUG ((DEBUG_INFO, " BS_Code : %14ld Pages (%ld Bytes)\n", Pages[EfiBootServicesCode], MultU64x64(SIZE_4KB, Pages[EfiBootServicesCode]))); + DEBUG ((DEBUG_INFO, " BS_Data : %14ld Pages (%ld Bytes)\n", Pages[EfiBootServicesData], MultU64x64(SIZE_4KB, Pages[EfiBootServicesData]))); + DEBUG ((DEBUG_INFO, " RT_Code : %14ld Pages (%ld Bytes)\n", Pages[EfiRuntimeServicesCode], MultU64x64(SIZE_4KB, Pages[EfiRuntimeServicesCode]))); + DEBUG ((DEBUG_INFO, " RT_Data : %14ld Pages (%ld Bytes)\n", Pages[EfiRuntimeServicesData], MultU64x64(SIZE_4KB, Pages[EfiRuntimeServicesData]))); + DEBUG ((DEBUG_INFO, " ACPI_Recl : %14ld Pages (%ld Bytes)\n", Pages[EfiACPIReclaimMemory], MultU64x64(SIZE_4KB, Pages[EfiACPIReclaimMemory]))); + DEBUG ((DEBUG_INFO, " ACPI_NVS : %14ld Pages (%ld Bytes)\n", Pages[EfiACPIMemoryNVS], MultU64x64(SIZE_4KB, Pages[EfiACPIMemoryNVS]))); + DEBUG ((DEBUG_INFO, " MMIO : %14ld Pages (%ld Bytes)\n", Pages[EfiMemoryMappedIO], MultU64x64(SIZE_4KB, Pages[EfiMemoryMappedIO]))); + DEBUG ((DEBUG_INFO, " MMIO_Port : %14ld Pages (%ld Bytes)\n", Pages[EfiMemoryMappedIOPortSpace], MultU64x64(SIZE_4KB, Pages[EfiMemoryMappedIOPortSpace]))); + DEBUG ((DEBUG_INFO, " PalCode : %14ld Pages (%ld Bytes)\n", Pages[EfiPalCode], MultU64x64(SIZE_4KB, Pages[EfiPalCode]))); + DEBUG ((DEBUG_INFO, " Available : %14ld Pages (%ld Bytes)\n", Pages[EfiConventionalMemory], MultU64x64(SIZE_4KB, Pages[EfiConventionalMemory]))); + DEBUG ((DEBUG_INFO, " Persistent: %14ld Pages (%ld Bytes)\n", Pages[EfiPersistentMemory], MultU64x64(SIZE_4KB, Pages[EfiPersistentMemory]))); + DEBUG ((DEBUG_INFO, " -------------- \n")); +} + +BOOLEAN +IsGoodMemoryMap ( + IN EFI_MEMORY_DESCRIPTOR *MemoryMap, + IN UINTN MemoryMapSize, + IN UINTN DescriptorSize + ) +{ + EFI_MEMORY_DESCRIPTOR *Entry; + UINTN NumberOfEntries; + UINTN Index; + UINT64 EntryCount[EfiMaxMemoryType]; + + ZeroMem (EntryCount, sizeof(EntryCount)); + + Entry = MemoryMap; + NumberOfEntries = MemoryMapSize / DescriptorSize; + for (Index = 0; Index < NumberOfEntries; Index++) { + if (Entry->Type < EfiMaxMemoryType) { + EntryCount[Entry->Type] ++; + } + Entry = NEXT_MEMORY_DESCRIPTOR (Entry, DescriptorSize); + } + if ((EntryCount[EfiRuntimeServicesCode] > 1) || + (EntryCount[EfiRuntimeServicesData] > 1) || + (EntryCount[EfiACPIReclaimMemory] > 1) || + (EntryCount[EfiACPIMemoryNVS] > 1) ) { + return FALSE; + } else { + return TRUE; + } +} + +EFI_STATUS +TestPointDumpMemMap ( + VOID + ) +{ + EFI_STATUS Status; + UINTN MapKey; + UINT32 DescriptorVersion; + EFI_MEMORY_DESCRIPTOR *MemoryMap; + UINTN UefiMemoryMapSize; + UINTN UefiDescriptorSize; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpMemMap - Enter\n")); + UefiMemoryMapSize = 0; + MemoryMap = NULL; + Status = gBS->GetMemoryMap ( + &UefiMemoryMapSize, + MemoryMap, + &MapKey, + &UefiDescriptorSize, + &DescriptorVersion + ); + ASSERT (Status == EFI_BUFFER_TOO_SMALL); + + do { + Status = gBS->AllocatePool (EfiBootServicesData, UefiMemoryMapSize, (VOID **)&MemoryMap); + ASSERT (MemoryMap != NULL); + if (MemoryMap == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done ; + } + + Status = gBS->GetMemoryMap ( + &UefiMemoryMapSize, + MemoryMap, + &MapKey, + &UefiDescriptorSize, + &DescriptorVersion + ); + if (EFI_ERROR (Status)) { + gBS->FreePool (MemoryMap); + MemoryMap = NULL; + } + } while (Status == EFI_BUFFER_TOO_SMALL); + + if (MemoryMap == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done ; + } + + DumpMemoryMap (MemoryMap, UefiMemoryMapSize, UefiDescriptorSize); + + Result = IsGoodMemoryMap (MemoryMap, UefiMemoryMapSize, UefiDescriptorSize); + if (!Result) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_END_OF_DXE_ERROR_CODE_2 TEST_POINT_END_OF_DXE TEST_POINT_BYTE2_END_OF_DXE_ERROR_STRING_2 + ); + Status = EFI_INVALID_PARAMETER; + } else { + Status = EFI_SUCCESS; + } + + gBS->FreePool (MemoryMap); + +Done: + DEBUG ((DEBUG_INFO, "==== TestPointDumpMemMap - Exit\n")); + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemoryTypeInformation.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemoryTypeInformation.c new file mode 100644 index 0000000000..b25404a564 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpMemoryTypeInformation.c @@ -0,0 +1,158 @@ +/** @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 + +CHAR8 * +ShortNameOfMemoryType( + IN UINT32 Type + ); + +VOID +DumpMemoryTypeInfoSummary ( + IN EFI_MEMORY_TYPE_INFORMATION *CurrentMemoryTypeInformation, + IN EFI_MEMORY_TYPE_INFORMATION *PreviousMemoryTypeInformation + ) +{ + UINTN Index; + UINTN Index1; + EFI_BOOT_MODE BootMode; + UINT32 Previous; + UINT32 Current; + UINT32 Next; + BOOLEAN MemoryTypeInformationModified; + + MemoryTypeInformationModified = FALSE; + BootMode = GetBootModeHob(); + + // + // Use a heuristic to adjust the Memory Type Information for the next boot + // + DEBUG ((DEBUG_INFO, "\n")); + DEBUG ((DEBUG_INFO, " (HOB) (ConfTabl) (Var) \n")); + DEBUG ((DEBUG_INFO, " Memory Previous Current Next \n")); + DEBUG ((DEBUG_INFO, " Type Pages Pages Pages \n")); + DEBUG ((DEBUG_INFO, "========== ======== ======== ========\n")); + + for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) { + + for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) { + if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) { + break; + } + } + if (CurrentMemoryTypeInformation[Index1].Type == EfiMaxMemoryType) { + continue; + } + + // + // Previous is the number of pages pre-allocated + // Current is the number of pages actually needed + // + Previous = PreviousMemoryTypeInformation[Index].NumberOfPages; + Current = CurrentMemoryTypeInformation[Index1].NumberOfPages; + Next = Previous; + + // + // Inconsistent Memory Reserved across bootings may lead to S4 fail + // Write next varible to 125% * current when the pre-allocated memory is: + // 1. More than 150% of needed memory and boot mode is BOOT_WITH_DEFAULT_SETTING + // 2. Less than the needed memory + // + if ((Current + (Current >> 1)) < Previous) { + if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) { + Next = Current + (Current >> 2); + } + } else if (Current > Previous) { + Next = Current + (Current >> 2); + } + if (Next > 0 && Next < 4) { + Next = 4; + } + + if (Next != Previous) { + PreviousMemoryTypeInformation[Index].NumberOfPages = Next; + MemoryTypeInformationModified = TRUE; + } + + DEBUG ((DEBUG_INFO, ShortNameOfMemoryType(PreviousMemoryTypeInformation[Index].Type))); + DEBUG ((DEBUG_INFO, " %08x %08x %08x\n", Previous, Current, Next)); + } + DEBUG ((DEBUG_INFO, "\n")); + + if (MemoryTypeInformationModified) { + DEBUG ((DEBUG_INFO, "MemoryTypeInformation - Modified. RESET Needed!\n")); + } else { + DEBUG ((DEBUG_INFO, "MemoryTypeInformation - Unmodified.\n")); + } + DEBUG ((DEBUG_INFO, "\n")); +} + +EFI_STATUS +TestPointDumpMemoryTypeInformation ( + VOID + ) +{ + EFI_STATUS Status; + EFI_HOB_GUID_TYPE *GuidHob; + VOID *CurrentMemoryTypeInformation; + VOID *PreviousMemoryTypeInformation; + VOID *VariableMemoryTypeInformation; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpMemoryTypeInformation - Enter\n")); + CurrentMemoryTypeInformation = NULL; + PreviousMemoryTypeInformation = NULL; + + Status = EfiGetSystemConfigurationTable (&gEfiMemoryTypeInformationGuid, &CurrentMemoryTypeInformation); + if (EFI_ERROR(Status)) { + goto Done; + } + + GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid); + if (GuidHob != NULL) { + PreviousMemoryTypeInformation = GET_GUID_HOB_DATA(GuidHob); + } else { + Status = EFI_NOT_FOUND; + goto Done; + } + + GetVariable2 ( + EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME, + &gEfiMemoryTypeInformationGuid, + &VariableMemoryTypeInformation, + NULL + ); + + if ((CurrentMemoryTypeInformation != NULL) && (PreviousMemoryTypeInformation != NULL)) { + DumpMemoryTypeInfoSummary(CurrentMemoryTypeInformation, PreviousMemoryTypeInformation); + } + DEBUG ((DEBUG_INFO, "==== TestPointDumpMemoryTypeInformation - Exit\n")); + +Done: + if (EFI_ERROR(Status)) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_CODE_2 TEST_POINT_READY_TO_BOOT TEST_POINT_BYTE2_READY_TO_BOOT_ERROR_STRING_2 + ); + } + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpPci.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpPci.c new file mode 100644 index 0000000000..b1d0ff331c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpPci.c @@ -0,0 +1,384 @@ +/** @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 + +#pragma pack(1) + +// +// Data region after PCI configuration header(for cardbus bridge) +// +typedef struct { + UINT16 SubVendorId; // Subsystem Vendor ID + UINT16 SubSystemId; // Subsystem ID + UINT32 LegacyBase; // Optional 16-Bit PC Card Legacy + // Mode Base Address + // + UINT32 Data[46]; +} PCI_CARDBUS_DATA; + +typedef union { + PCI_DEVICE_HEADER_TYPE_REGION Device; + PCI_BRIDGE_CONTROL_REGISTER Bridge; + PCI_CARDBUS_CONTROL_REGISTER CardBus; +} NON_COMMON_UNION; + +typedef struct { + PCI_DEVICE_INDEPENDENT_REGION Common; + NON_COMMON_UNION NonCommon; + UINT32 Data[48]; +} PCI_CONFIG_SPACE; + +#pragma pack() + +VOID +DumpPciDevice ( + IN UINT8 Bus, + IN UINT8 Device, + IN UINT8 Function, + IN PCI_TYPE00 *PciData + ) +{ +//DEBUG ((DEBUG_INFO, " 00/00/00 : [0000][0000] [00|00|00] 00000000 00000000 00000000 00000000 00000000 00000000 0000\n")); + DEBUG ((DEBUG_INFO, " %02x/%02x/%02x :", + Bus, + Device, + Function + )); + DEBUG ((DEBUG_INFO, " [%04x][%04x]", + PciData->Hdr.VendorId, + PciData->Hdr.DeviceId + )); + DEBUG ((DEBUG_INFO, " [%02x|%02x|%02x]", + PciData->Hdr.ClassCode[2], + PciData->Hdr.ClassCode[1], + PciData->Hdr.ClassCode[0] + )); + DEBUG ((DEBUG_INFO, " %08x %08x %08x %08x %08x %08x", + PciData->Device.Bar[0], + PciData->Device.Bar[1], + PciData->Device.Bar[2], + PciData->Device.Bar[3], + PciData->Device.Bar[4], + PciData->Device.Bar[6] + )); + DEBUG ((DEBUG_INFO, " %04x\n", + PciData->Hdr.Command + )); +} + +VOID +DumpPciBridge ( + IN UINT8 Bus, + IN UINT8 Device, + IN UINT8 Function, + IN PCI_TYPE01 *PciData + ) +{ +//DEBUG ((DEBUG_INFO, " 00/00/00*: [0000][0000] [00|00|00] 00000000 00000000 [00|00|00] [00:00] [0000:0000] [0000:0000] [00000000:00000000] [0000:0000] 0000 0000\n")); + DEBUG ((DEBUG_INFO, " %02x/%02x/%02x*:", + Bus, + Device, + Function + )); + DEBUG ((DEBUG_INFO, " [%04x][%04x]", + PciData->Hdr.VendorId, + PciData->Hdr.DeviceId + )); + DEBUG ((DEBUG_INFO, " [%02x|%02x|%02x]", + PciData->Hdr.ClassCode[2], + PciData->Hdr.ClassCode[1], + PciData->Hdr.ClassCode[0] + )); + DEBUG ((DEBUG_INFO, " %08x %08x", + PciData->Bridge.Bar[0], + PciData->Bridge.Bar[1] + )); + DEBUG ((DEBUG_INFO, " [%02x|%02x|%02x]", + PciData->Bridge.PrimaryBus, + PciData->Bridge.SecondaryBus, + PciData->Bridge.SubordinateBus + )); + DEBUG ((DEBUG_INFO, " [00:00] [0000:0000] [0000:0000]", + PciData->Bridge.IoBase, + PciData->Bridge.IoLimit, + PciData->Bridge.MemoryBase, + PciData->Bridge.MemoryLimit, + PciData->Bridge.PrefetchableMemoryBase, + PciData->Bridge.PrefetchableMemoryLimit + )); + DEBUG ((DEBUG_INFO, " [00000000:00000000] [0000:0000]", + PciData->Bridge.PrefetchableBaseUpper32, + PciData->Bridge.PrefetchableLimitUpper32, + PciData->Bridge.IoBaseUpper16, + PciData->Bridge.IoLimitUpper16 + )); + DEBUG ((DEBUG_INFO, " %04x ", + PciData->Bridge.BridgeControl + )); + DEBUG ((DEBUG_INFO, " %04x\n", + PciData->Hdr.Command + )); +} + +/** + This function gets the protocol interface from the given handle, and + obtains its address space descriptors. + + @param[in] Handle The PCI_ROOT_BRIDIGE_IO_PROTOCOL handle. + @param[out] IoDev Handle used to access configuration space of PCI device. + @param[out] Descriptors Points to the address space descriptors. + + @retval EFI_SUCCESS The command completed successfully +**/ +EFI_STATUS +PciGetProtocolAndResource ( + IN EFI_HANDLE Handle, + OUT EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **IoDev, + OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors + ) +{ + EFI_STATUS Status; + + // + // Get inferface from protocol + // + Status = gBS->HandleProtocol ( + Handle, + &gEfiPciRootBridgeIoProtocolGuid, + (VOID**)IoDev + ); + + if (EFI_ERROR (Status)) { + return Status; + } + // + // Call Configuration() to get address space descriptors + // + Status = (*IoDev)->Configuration (*IoDev, (VOID**)Descriptors); + if (Status == EFI_UNSUPPORTED) { + *Descriptors = NULL; + return EFI_SUCCESS; + + } else { + return Status; + } +} + +/** + This function get the next bus range of given address space descriptors. + It also moves the pointer backward a node, to get prepared to be called + again. + + @param[in, out] Descriptors Points to current position of a serial of address space + descriptors. + @param[out] MinBus The lower range of bus number. + @param[out] MaxBus The upper range of bus number. + @param[out] IsEnd Meet end of the serial of descriptors. + + @retval EFI_SUCCESS The command completed successfully. +**/ +EFI_STATUS +PciGetNextBusRange ( + IN OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR **Descriptors, + OUT UINT16 *MinBus, + OUT UINT16 *MaxBus, + OUT BOOLEAN *IsEnd + ) +{ + *IsEnd = FALSE; + + // + // When *Descriptors is NULL, Configuration() is not implemented, so assume + // range is 0~PCI_MAX_BUS + // + if ((*Descriptors) == NULL) { + *MinBus = 0; + *MaxBus = PCI_MAX_BUS; + return EFI_SUCCESS; + } + // + // *Descriptors points to one or more address space descriptors, which + // ends with a end tagged descriptor. Examine each of the descriptors, + // if a bus typed one is found and its bus range covers bus, this handle + // is the handle we are looking for. + // + + while ((*Descriptors)->Desc != ACPI_END_TAG_DESCRIPTOR) { + if ((*Descriptors)->ResType == ACPI_ADDRESS_SPACE_TYPE_BUS) { + *MinBus = (UINT16) (*Descriptors)->AddrRangeMin; + *MaxBus = (UINT16) (*Descriptors)->AddrRangeMax; + (*Descriptors)++; + return (EFI_SUCCESS); + } + + (*Descriptors)++; + } + + if ((*Descriptors)->Desc == ACPI_END_TAG_DESCRIPTOR) { + *IsEnd = TRUE; + } + + return EFI_SUCCESS; +} + +EFI_STATUS +TestPointDumpPci ( + VOID + ) +{ + UINT16 Bus; + UINT16 Device; + UINT16 Func; + UINT64 Address; + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoDev; + EFI_STATUS Status; + PCI_TYPE00 PciData; + UINTN Index; + EFI_HANDLE *HandleBuf; + UINTN HandleCount; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors; + UINT16 MinBus; + UINT16 MaxBus; + BOOLEAN IsEnd; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpPci - Enter\n")); + HandleBuf = NULL; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciRootBridgeIoProtocolGuid, + NULL, + &HandleCount, + &HandleBuf + ); + if (EFI_ERROR (Status)) { + goto Done ; + } + + DEBUG ((DEBUG_INFO, " B D F* VID DID Class[CSP] Bar0 Bar1 Bus[PSS] Io[BL] Memory[BL]")); + DEBUG ((DEBUG_INFO, " PMemory[BL] PMemoryU[BL] IoU[BL] BriCtl Command\n")); + + DEBUG ((DEBUG_INFO, " B D F VID DID Class[CSP] Bar0 Bar1 Bar2 Bar3 Bar4 Bar5 Command\n")); + + for (Index = 0; Index < HandleCount; Index++) { + Status = PciGetProtocolAndResource ( + HandleBuf[Index], + &IoDev, + &Descriptors + ); + while (TRUE) { + Status = PciGetNextBusRange (&Descriptors, &MinBus, &MaxBus, &IsEnd); + if (EFI_ERROR (Status)) { + goto Done; + } + + if (IsEnd) { + break; + } + + for (Bus = MinBus; Bus <= MaxBus; Bus++) { + // + // For each devices, enumerate all functions it contains + // + for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) { + // + // For each function, read its configuration space and print summary + // + for (Func = 0; Func <= PCI_MAX_FUNC; Func++) { + Address = EFI_PCI_ADDRESS (Bus, Device, Func, 0); + IoDev->Pci.Read ( + IoDev, + EfiPciWidthUint16, + Address, + 1, + &PciData.Hdr.VendorId + ); + + // + // If VendorId = 0xffff, there does not exist a device at this + // location. For each device, if there is any function on it, + // there must be 1 function at Function 0. So if Func = 0, there + // will be no more functions in the same device, so we can break + // loop to deal with the next device. + // + if (PciData.Hdr.VendorId == 0xffff && Func == 0) { + break; + } + + if (PciData.Hdr.VendorId != 0xffff) { + IoDev->Pci.Read ( + IoDev, + EfiPciWidthUint32, + Address, + sizeof (PciData) / sizeof (UINT32), + &PciData + ); + + if (IS_PCI_BRIDGE(&PciData)) { + // Bridge + DumpPciBridge ((UINT8)Bus, (UINT8)Device, (UINT8)Func, (PCI_TYPE01 *)&PciData); + } else if (IS_CARDBUS_BRIDGE(&PciData)) { + // CardBus Bridge + } else { + // Device + DumpPciDevice ((UINT8)Bus, (UINT8)Device, (UINT8)Func, &PciData); + } + + // + // If this is not a multi-function device, we can leave the loop + // to deal with the next device. + // + if (Func == 0 && ((PciData.Hdr.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00)) { + break; + } + } + } + } + } + // + // If Descriptor is NULL, Configuration() returns EFI_UNSUPPRORED, + // we assume the bus range is 0~PCI_MAX_BUS. After enumerated all + // devices on all bus, we can leave loop. + // + if (Descriptors == NULL) { + break; + } + } + } + +Done: + if (HandleBuf != NULL) { + FreePool (HandleBuf); + } + + DEBUG ((DEBUG_INFO, "==== TestPointDumpPci - Exit\n")); + + if (EFI_ERROR(Status)) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_PCI_ENUMERATION_DONE_ERROR_CODE_1 TEST_POINT_PCI_ENUMERATION_DONE TEST_POINT_BYTE2_PCI_ENUMERATION_DONE_ERROR_STRING_1 + ); + } + + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpSmmInfo.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpSmmInfo.c new file mode 100644 index 0000000000..0934038208 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpSmmInfo.c @@ -0,0 +1,80 @@ +/** @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 + +VOID +DumpSmramDescriptor ( + IN UINTN NumberOfSmmReservedRegions, + IN EFI_SMRAM_DESCRIPTOR *Descriptor + ); + +VOID +DumpSmramInfo ( + VOID + ) +{ +} + +EFI_STATUS +TestPointDumpSmmInfo ( + VOID + ) +{ + EFI_STATUS Status; + EFI_SMM_ACCESS2_PROTOCOL *SmmAccess; + UINTN Size; + EFI_SMRAM_DESCRIPTOR *SmramRanges; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmmInfo - Enter\n")); + + Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess); + if (EFI_ERROR (Status)) { + goto Done ; + } + + Size = 0; + Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL); + ASSERT (Status == EFI_BUFFER_TOO_SMALL); + + SmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocateZeroPool (Size); + ASSERT (SmramRanges != NULL); + + Status = SmmAccess->GetCapabilities (SmmAccess, &Size, SmramRanges); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INFO, "SMRAM Info\n")); + DumpSmramDescriptor (Size / sizeof (EFI_SMRAM_DESCRIPTOR), SmramRanges); + + FreePool (SmramRanges); + +Done: + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmmInfo - Exit\n")); + + if (EFI_ERROR(Status)) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_DXE_SMM_READY_TO_LOCK_ERROR_CODE_1 TEST_POINT_DXE_SMM_READY_TO_LOCK TEST_POINT_BYTE2_DXE_SMM_READY_TO_LOCK_ERROR_STRING_1 + ); + } + + return Status; +} \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpVariable.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpVariable.c new file mode 100644 index 0000000000..4512a2385d --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeDumpVariable.c @@ -0,0 +1,173 @@ +/** @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 + +#define INIT_NAME_BUFFER_SIZE 128 + +CHAR8 *mAttributeShortName[] = { + "NV", + "BS", + "RT", + "HR", + "AU", + "AT", + "AP", +}; + +VOID +DumpVarAttrName ( + IN UINT32 Attributes + ) +{ + UINTN Index; + BOOLEAN IsFirst; + + IsFirst = TRUE; + DEBUG ((DEBUG_INFO, "(")); + for (Index = 0; Index < sizeof(mAttributeShortName)/sizeof(mAttributeShortName[0]); Index++) { + if ((Attributes & (1 << Index)) != 0) { + if (!IsFirst) { + DEBUG ((DEBUG_INFO, "|")); + } + DEBUG ((DEBUG_INFO, mAttributeShortName[Index])); + if (IsFirst) { + IsFirst = FALSE; + } + } + } + DEBUG ((DEBUG_INFO, ")")); +} + +VOID +DumpVarProperty ( + IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty + ) +{ + if ((VariableProperty->Property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY) != 0) { + DEBUG ((DEBUG_INFO, " (RO)")); + } +} + +EFI_STATUS +TestPointDumpVariable ( + VOID + ) +{ + CHAR16 *VariableName; + UINTN NameSize; + UINTN NameBufferSize; + EFI_STATUS Status; + EFI_GUID Guid; + UINTN VarSize; + UINT32 Attributes; + VOID *VarData; + EDKII_VAR_CHECK_PROTOCOL *VarCheck; + VAR_CHECK_VARIABLE_PROPERTY VariableProperty; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpVariable - Enter\n")); + + Status = gBS->LocateProtocol (&gEdkiiVarCheckProtocolGuid, NULL, (VOID **)&VarCheck); + DEBUG ((DEBUG_INFO, "VarCheck - %r\n", Status)); + + Status = EFI_SUCCESS; + DEBUG ((DEBUG_INFO, "Variable List:\n")); + NameBufferSize = INIT_NAME_BUFFER_SIZE; + VariableName = AllocateZeroPool(NameBufferSize); + if (VariableName == NULL) { + goto Done ; + } + *VariableName = CHAR_NULL; + + while (!EFI_ERROR(Status)) { + // + // Get Name/Guid + // + NameSize = NameBufferSize; + Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid); + if (Status == EFI_NOT_FOUND){ + Status = EFI_SUCCESS; + break; + } else if (Status == EFI_BUFFER_TOO_SMALL) { + NameBufferSize = NameSize > NameBufferSize * 2 ? NameSize : NameBufferSize * 2; + if (VariableName != NULL) { + FreePool (VariableName); + } + VariableName = AllocateZeroPool(NameBufferSize); + if (VariableName == NULL) { + Status = EFI_OUT_OF_RESOURCES; + break; + } + NameSize = NameBufferSize; + Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid); + } + + if (EFI_ERROR(Status)) { + break; + } + + // + // Get Attributes/Size + // + VarSize = 0; + Attributes = 0; + Status = gRT->GetVariable(VariableName, &Guid, &Attributes, &VarSize, NULL); + if (Status == EFI_BUFFER_TOO_SMALL){ + VarData = AllocateZeroPool (VarSize); + if (VarData == NULL) { + goto Done; + } + Status = gRT->GetVariable(VariableName, &Guid, &Attributes, &VarSize, VarData); + if (!EFI_ERROR(Status)) { + DEBUG ((DEBUG_INFO, + " Name=L\"%s\" Guid=%g Size=0x%x Attr=0x%x ", + VariableName, + &Guid, + VarSize, + Attributes + )); + DumpVarAttrName (Attributes); + + if (VarCheck != NULL) { + Status = VarCheck->VariablePropertyGet (VariableName, &Guid, &VariableProperty); + if (!EFI_ERROR(Status)) { + DumpVarProperty (&VariableProperty); + } + } + + DEBUG ((DEBUG_INFO, "\n")); + FreePool (VarData); + Status = EFI_SUCCESS; + } + } + } + + if (VariableName != NULL) { + FreePool (VariableName); + } + +Done: + DEBUG ((DEBUG_INFO, "==== TestPointDumpVariable - Exit\n")); + + // Check - TBD + return EFI_SUCCESS; +} \ 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 new file mode 100644 index 0000000000..f7801bf4b2 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.c @@ -0,0 +1,335 @@ +/** @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 + +EFI_STATUS +TestPointDumpGcd ( + VOID + ); + +EFI_STATUS +TestPointDumpMemMap ( + VOID + ); + +EFI_STATUS +TestPointDumpMemAttribute ( + VOID + ); + +EFI_STATUS +TestPointDumpPci ( + VOID + ); + +EFI_STATUS +TestPointDumpConsoleVariable ( + VOID + ); + +EFI_STATUS +TestPointDumpBootVariable ( + VOID + ); + +EFI_STATUS +TestPointDumpDevicePath ( + VOID + ); + +EFI_STATUS +TestPointDumpMemoryTypeInformation ( + VOID + ); + +EFI_STATUS +TestPointDumpAcpi ( + VOID + ); + +EFI_STATUS +TestPointDumpHsti ( + VOID + ); + +EFI_STATUS +TestPointDumpVariable ( + VOID + ); + +EFI_STATUS +TestPointDumpEsrt ( + VOID + ); + +EFI_STATUS +TestPointDumpSmmInfo ( + VOID + ); + +EFI_STATUS +TestPointDumpLoadedImage ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointPciEnumerationDone ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "======== TestPointPciEnumerationDone - Enter\n")); + + Result = TRUE; + Status = TestPointDumpPci (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 2, + TEST_POINT_BYTE2_PCI_ENUMERATION_DONE + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointPciEnumerationDone - Exit\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointEndOfDxe ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "======== TestPointEndOfDxe - Enter\n")); + + Result = TRUE; + Status = TestPointDumpLoadedImage (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpMemMap (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpGcd (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpConsoleVariable (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpBootVariable (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 2, + TEST_POINT_BYTE2_END_OF_DXE + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointEndOfDxe - Exit\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointDxeSmmReadyToLock ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "======== TestPointDxeSmmReadyToLock - Enter\n")); + + Result = TRUE; + Status = TestPointDumpSmmInfo (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 2, + TEST_POINT_BYTE2_DXE_SMM_READY_TO_LOCK + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointDxeSmmReadyToLock - Exit\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointReadyToBoot ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "======== TestPointReadyToBoot - Enter\n")); + + Result = TRUE; + Status = TestPointDumpLoadedImage (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpMemMap (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpGcd (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpDevicePath (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpConsoleVariable (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpBootVariable (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpMemoryTypeInformation (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpVariable (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + Status = TestPointDumpMemAttribute (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpAcpi (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpEsrt (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpHsti (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 2, + TEST_POINT_BYTE2_READY_TO_BOOT + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointReadyToBoot - Exit\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointExitBootServices ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "======== TestPointExitBootServices - Enter\n")); + + DEBUG ((DEBUG_INFO, "======== TestPointExitBootServices - Exit\n")); + + return EFI_SUCCESS; +} + +GLOBAL_REMOVE_IF_UNREFERENCED ADAPTER_INFO_PLATFORM_TEST_POINT_STRUCT mTestPointStruct = { + PLATFORM_TEST_POINT_VERSION, + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + {TEST_POINT_IMPLEMENTATION_ID_PLATFORM}, + TEST_POINT_FEATURE_SIZE, + {0}, // FeaturesRequired + {0}, // FeaturesImplemented + {0}, // FeaturesVerified + 0, +}; + +GLOBAL_REMOVE_IF_UNREFERENCED UINT8 mFeatureImplemented[TEST_POINT_FEATURE_SIZE]; + +/** + Initialize feature data +**/ +VOID +InitData ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + + ASSERT (PcdGetSize(PcdTestPointIbvPlatformFeature) == sizeof(mFeatureImplemented)); + CopyMem (mFeatureImplemented, PcdGetPtr(PcdTestPointIbvPlatformFeature), sizeof(mFeatureImplemented)); + + mTestPointStruct.Role = Role; + CopyMem (mTestPointStruct.FeaturesImplemented, mFeatureImplemented, sizeof(mFeatureImplemented)); + Status = TestPointLibSetTable ( + &mTestPointStruct, + sizeof(mTestPointStruct) + ); + if (EFI_ERROR (Status)) { + if (Status != EFI_ALREADY_STARTED) { + ASSERT_EFI_ERROR (Status); + } + } +} + +EFI_STATUS +EFIAPI +DxeTestPointCheckLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + InitData (PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf new file mode 100644 index 0000000000..beec4a2193 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf @@ -0,0 +1,86 @@ +## @file +# Component information file for Board Init Test Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeTestPointCheckLib + FILE_GUID = 74A1F91F-AD11-49C5-96B8-A579F4AA65F1 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = TestPointCheckLib + CONSTRUCTOR = DxeTestPointCheckLibConstructor + +[LibraryClasses] + BaseLib + DebugLib + DxeServicesTableLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + UefiLib + PrintLib + DevicePathLib + HobLib + PeCoffGetEntryPointLib + HstiLib + TestPointLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + DxeTestPointCheckLib.c + DxeDumpGcd.c + DxeDumpMemMap.c + DxeDumpMemAttribute.c + DxeDumpPci.c + DxeDumpConsoleVariable.c + DxeDumpBootVariable.c + DxeDumpVariable.c + DxeDumpDevicePath.c + DxeDumpMemoryTypeInformation.c + DxeDumpAcpi.c + DxeDumpAcpiMadt.c + DxeDumpAcpiMcfg.c + DxeDumpAcpiHpet.c + DxeDumpAcpiDmar.c + DxeDumpAcpiWsmt.c + DxeDumpHsti.c + DxeDumpEsrt.c + DxeDumpLoadedImage.c + DxeDumpSmmInfo.c + PeiDumpSmramHob.c + +[Guids] + gEfiMemoryAttributesTableGuid + gEfiGlobalVariableGuid + gEfiAcpi20TableGuid + gEfiAcpi10TableGuid + gEfiMemoryTypeInformationGuid + gEfiSystemResourceTableGuid + gEfiSmmPeiSmramMemoryReserveGuid + +[Protocols] + gEfiPciIoProtocolGuid + gEfiPciRootBridgeIoProtocolGuid + gEfiSmmAccess2ProtocolGuid + gEdkiiVarCheckProtocolGuid + gEfiLoadedImageProtocolGuid + gEfiLoadedImageDevicePathProtocolGuid + gEfiDevicePathProtocolGuid + +[Pcd] + gPlatformModuleTokenSpaceGuid.PcdTestPointIbvPlatformFeature \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpFvInfo.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpFvInfo.c new file mode 100644 index 0000000000..c32c03b2c7 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpFvInfo.c @@ -0,0 +1,118 @@ +/** @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 + +EFI_STATUS +TestPointDumpFvInfo ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PEI_PPI_DESCRIPTOR *Descriptor; + EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *FvInfo; + EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI *FvInfo2; + UINTN Index; + UINTN Index2; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpFvInfo - Enter\n")); + DEBUG ((DEBUG_INFO, "FV Info PPI\n")); + for (Index = 0; ; Index++) { + Status = PeiServicesLocatePpi ( + &gEfiPeiFirmwareVolumeInfoPpiGuid, + Index, + &Descriptor, + (VOID **)&FvInfo + ); + if (EFI_ERROR (Status)) { + break; + } + DEBUG ((DEBUG_INFO, + " BA=%08x L=%08x Format={%g}", + (UINT32)(UINTN)FvInfo->FvInfo, + FvInfo->FvInfoSize, + &FvInfo->FvFormat, + FvInfo->ParentFvName, + FvInfo->ParentFileName + )); + if (FvInfo->ParentFvName != NULL) { + DEBUG ((DEBUG_INFO, + " ParentFv={%g}", + FvInfo->ParentFvName + )); + } + if (FvInfo->ParentFileName != NULL) { + DEBUG ((DEBUG_INFO, + " ParentFileName={%g}", + FvInfo->ParentFileName + )); + } + DEBUG ((DEBUG_INFO, "\n")); + } + + DEBUG ((DEBUG_INFO, "FV Info2 PPI\n")); + for (Index2 = 0; ; Index2++) { + Status = PeiServicesLocatePpi ( + &gEfiPeiFirmwareVolumeInfo2PpiGuid, + Index2, + &Descriptor, + (VOID **)&FvInfo2 + ); + if (EFI_ERROR (Status)) { + break; + } + DEBUG ((DEBUG_INFO, + " BA=%08x L=%08x Format={%g}", + (UINT32)(UINTN)FvInfo2->FvInfo, + FvInfo2->FvInfoSize, + &FvInfo2->FvFormat, + FvInfo2->ParentFvName, + FvInfo2->ParentFileName, + FvInfo2->AuthenticationStatus + )); + if (FvInfo2->ParentFvName != NULL) { + DEBUG ((DEBUG_INFO, + " ParentFv={%g}", + FvInfo2->ParentFvName + )); + } + if (FvInfo2->ParentFileName != NULL) { + DEBUG ((DEBUG_INFO, + " ParentFileName={%g}", + FvInfo2->ParentFileName + )); + } + DEBUG ((DEBUG_INFO, + " Auth=%08x\n", + FvInfo2->AuthenticationStatus + )); + } + DEBUG ((DEBUG_INFO, "==== TestPointDumpFvInfo - Exit\n")); + + if ((Index == 0) && (Index2 == 0)) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE1_END_OF_PEI_ERROR_CODE_3 TEST_POINT_END_OF_PEI TEST_POINT_BYTE1_END_OF_PEI_ERROR_STRING_3 + ); + return EFI_INVALID_PARAMETER; + } + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpHob.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpHob.c new file mode 100644 index 0000000000..9ef96936c0 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpHob.c @@ -0,0 +1,377 @@ +/** @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 + +#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \ + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \ + EFI_RESOURCE_ATTRIBUTE_TESTED | \ + EFI_RESOURCE_ATTRIBUTE_16_BIT_IO | \ + EFI_RESOURCE_ATTRIBUTE_32_BIT_IO | \ + EFI_RESOURCE_ATTRIBUTE_64_BIT_IO \ + ) + +#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED) + +#define INITIALIZED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED) + +#define PRESENT_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT) + +CHAR8 *mMemoryTypeShortName[] = { + "Reserved", + "LoaderCode", + "LoaderData", + "BS_Code", + "BS_Data", + "RT_Code", + "RT_Data", + "Available", + "Unusable", + "ACPI_Recl", + "ACPI_NVS", + "MMIO", + "MMIO_Port", + "PalCode", + "Persistent", +}; + +CHAR8 *mResourceTypeShortName[] = { + "Mem", + "MMIO", + "I/O", + "FD", + "MM Port I/O", + "Reserved Mem", + "Reserved I/O", +}; + +CHAR8 mUnknownStr[11]; + +CHAR8 * +ShortNameOfMemoryType ( + IN UINT32 Type + ) +{ + if (Type < sizeof(mMemoryTypeShortName) / sizeof(mMemoryTypeShortName[0])) { + return mMemoryTypeShortName[Type]; + } else { + AsciiSPrint(mUnknownStr, sizeof(mUnknownStr), "%08x", Type); + return mUnknownStr; + } +} + +CHAR8 * +ShortNameOfResourceType ( + IN UINT32 Type + ) +{ + if (Type < sizeof(mResourceTypeShortName) / sizeof(mResourceTypeShortName[0])) { + return mResourceTypeShortName[Type]; + } else { + AsciiSPrint(mUnknownStr, sizeof(mUnknownStr), "%08x", Type); + return mUnknownStr; + } +} + +EFI_STATUS +DumpPhitHob ( + IN VOID *HobList + ) +{ + EFI_HOB_HANDOFF_INFO_TABLE *PhitHob; + + PhitHob = HobList; + ASSERT(GET_HOB_TYPE(HobList) == EFI_HOB_TYPE_HANDOFF); + DEBUG ((DEBUG_INFO, "PHIT HOB\n")); + DEBUG ((DEBUG_INFO, " PhitHob - 0x%x\n", PhitHob)); + DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", PhitHob->BootMode)); + DEBUG ((DEBUG_INFO, " EfiMemoryTop - 0x%016lx\n", PhitHob->EfiMemoryTop)); + DEBUG ((DEBUG_INFO, " EfiMemoryBottom - 0x%016lx\n", PhitHob->EfiMemoryBottom)); + DEBUG ((DEBUG_INFO, " EfiFreeMemoryTop - 0x%016lx\n", PhitHob->EfiFreeMemoryTop)); + DEBUG ((DEBUG_INFO, " EfiFreeMemoryBottom - 0x%016lx\n", PhitHob->EfiFreeMemoryBottom)); + DEBUG ((DEBUG_INFO, " EfiEndOfHobList - 0x%lx\n", PhitHob->EfiEndOfHobList)); + + return EFI_SUCCESS; +} + +EFI_STATUS +DumpCpuHob ( + IN VOID *HobList + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_CPU *CpuHob; + + DEBUG ((DEBUG_INFO, "CPU HOBs\n")); + for (Hob.Raw = HobList; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) { + if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_CPU) { + CpuHob = Hob.Cpu; + DEBUG ((DEBUG_INFO, + " SizeOfMemorySpace=%x SizeOfIoSpace=%x\n", + CpuHob->SizeOfMemorySpace, + CpuHob->SizeOfIoSpace + )); + } + } + + return EFI_SUCCESS; +} + +EFI_STATUS +DumpResourceHob ( + IN VOID *HobList + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + + DEBUG ((DEBUG_INFO, "Resource Descriptor HOBs\n")); + for (Hob.Raw = HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + + if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { + + ResourceHob = Hob.ResourceDescriptor; + + DEBUG ((DEBUG_INFO, + " BA=%016lx L=%016lx Attr=%08x ", + ResourceHob->PhysicalStart, + ResourceHob->ResourceLength, + ResourceHob->ResourceAttribute + )); + + DEBUG ((DEBUG_INFO, ShortNameOfResourceType(ResourceHob->ResourceType))); + switch (ResourceHob->ResourceType) { + case EFI_RESOURCE_SYSTEM_MEMORY: + if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) != 0) { + DEBUG ((DEBUG_INFO, " (Persistent)")); + } else if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) != 0) { + DEBUG ((DEBUG_INFO, " (MoreReliable)")); + } else if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == TESTED_MEMORY_ATTRIBUTES) { + DEBUG ((DEBUG_INFO, " (Tested)")); + } else if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == INITIALIZED_MEMORY_ATTRIBUTES) { + DEBUG ((DEBUG_INFO, " (Init)")); + } else if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == PRESENT_MEMORY_ATTRIBUTES) { + DEBUG ((DEBUG_INFO, " (Present)")); + } else { + DEBUG ((DEBUG_INFO, " (Unknown)")); + } + break; + default: + break; + } + DEBUG ((DEBUG_INFO, "\n")); + } + } + + return EFI_SUCCESS; +} + +EFI_STATUS +DumpFvHob ( + IN VOID *HobList + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob; + EFI_HOB_FIRMWARE_VOLUME2 *FirmwareVolume2Hob; + BOOLEAN Found; + + Found = FALSE; + DEBUG ((DEBUG_INFO, "FV HOBs\n")); + for (Hob.Raw = HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) { + + FirmwareVolumeHob = Hob.FirmwareVolume; + + DEBUG ((DEBUG_INFO, + " BA=%016lx L=%016lx\n", + FirmwareVolumeHob->BaseAddress, + FirmwareVolumeHob->Length + )); + Found = TRUE; + } + } + + DEBUG ((DEBUG_INFO, "FV2 HOBs\n")); + for (Hob.Raw = HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) { + + FirmwareVolume2Hob = Hob.FirmwareVolume2; + + DEBUG ((DEBUG_INFO, + " BA=%016lx L=%016lx Fv={%g} File={%g}\n", + FirmwareVolume2Hob->BaseAddress, + FirmwareVolume2Hob->Length, + &FirmwareVolume2Hob->FvName, + &FirmwareVolume2Hob->FileName + )); + Found = TRUE; + } + } + + if (!Found) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE1_END_OF_PEI_ERROR_CODE_3 TEST_POINT_END_OF_PEI TEST_POINT_BYTE1_END_OF_PEI_ERROR_STRING_3 + ); + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +EFI_STATUS +DumpMemoryAllocationHob ( + IN VOID *HobList + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_MEMORY_ALLOCATION *MemoryHob; + + DEBUG ((DEBUG_INFO, "Memory Allocation HOBs\n")); + for (Hob.Raw = HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) { + + MemoryHob = Hob.MemoryAllocation; + + DEBUG ((DEBUG_INFO, + " BA=%016lx L=%016lx ", + MemoryHob->AllocDescriptor.MemoryBaseAddress, + MemoryHob->AllocDescriptor.MemoryLength + )); + DEBUG ((DEBUG_INFO, ShortNameOfMemoryType(MemoryHob->AllocDescriptor.MemoryType))); + if (!IsZeroGuid(&MemoryHob->AllocDescriptor.Name)) { + if (CompareGuid(&gEfiHobMemoryAllocStackGuid, &MemoryHob->AllocDescriptor.Name)) { + DEBUG ((DEBUG_INFO, + " {Stack}", + &MemoryHob->AllocDescriptor.Name + )); + } else if (CompareGuid(&gEfiHobMemoryAllocBspStoreGuid, &MemoryHob->AllocDescriptor.Name)) { + DEBUG ((DEBUG_INFO, + " {BspStore}", + &MemoryHob->AllocDescriptor.Name + )); + } else if (CompareGuid(&gEfiHobMemoryAllocModuleGuid, &MemoryHob->AllocDescriptor.Name)) { + DEBUG ((DEBUG_INFO, + " {Module=%g,Entry=0x%lx}", + &((EFI_HOB_MEMORY_ALLOCATION_MODULE *)MemoryHob)->ModuleName, + ((EFI_HOB_MEMORY_ALLOCATION_MODULE *)MemoryHob)->EntryPoint + )); + } else { + DEBUG ((DEBUG_INFO, + " {%g}", + &MemoryHob->AllocDescriptor.Name + )); + } + } + DEBUG ((DEBUG_INFO, "\n")); + } + } + + return EFI_SUCCESS; +} + +EFI_STATUS +DumpGuidHob ( + IN VOID *HobList + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_GUID_TYPE *GuidHob; + + DEBUG ((DEBUG_INFO, "GUID HOBs\n")); + for (Hob.Raw = HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_GUID_EXTENSION) { + + GuidHob = Hob.Guid; + + DEBUG ((DEBUG_INFO, + " GUID=%g DataSize=0x%x\n", + &GuidHob->Name, + GET_GUID_HOB_DATA_SIZE(GuidHob) + )); + } + } + + return EFI_SUCCESS; +} + +EFI_STATUS +TestPointDumpHob ( + IN BOOLEAN PhitHobOnly + ) +{ + VOID *HobList; + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpHob - Enter\n")); + // + // Get Hob list + // + HobList = GetHobList (); + + Result = TRUE; + + Status = DumpPhitHob (HobList); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (PhitHobOnly) { + goto Done ; + } + + Status = DumpCpuHob (HobList); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + Status = DumpResourceHob (HobList); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + Status = DumpFvHob (HobList); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + Status = DumpMemoryAllocationHob (HobList); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + Status = DumpGuidHob (HobList); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + +Done: + DEBUG ((DEBUG_INFO, "==== TestPointDumpHob - Exit\n")); + + if (!Result) { + return EFI_INVALID_PARAMETER; + } + return EFI_SUCCESS; +} + diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpMtrr.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpMtrr.c new file mode 100644 index 0000000000..e50e10b0d5 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpMtrr.c @@ -0,0 +1,77 @@ +/** @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 + +EFI_STATUS +TestPointDumpMtrr ( + IN BOOLEAN IsForDxe + ) +{ + MTRR_SETTINGS LocalMtrrs; + MTRR_SETTINGS *Mtrrs; + UINTN Index; + UINTN VariableMtrrCount; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpMtrr - Enter\n")); + + MtrrGetAllMtrrs (&LocalMtrrs); + Mtrrs = &LocalMtrrs; + DEBUG ((DEBUG_INFO, "MTRR Default Type: %016lx\n", Mtrrs->MtrrDefType)); + for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) { + DEBUG ((DEBUG_INFO, "Fixed MTRR[%02d] : %016lx\n", Index, Mtrrs->Fixed.Mtrr[Index])); + } + + VariableMtrrCount = GetVariableMtrrCount (); + for (Index = 0; Index < VariableMtrrCount; Index++) { + DEBUG ((DEBUG_INFO, "Variable MTRR[%02d]: Base=%016lx Mask=%016lx\n", + Index, + Mtrrs->Variables.Mtrr[Index].Base, + Mtrrs->Variables.Mtrr[Index].Mask + )); + } + DEBUG ((DEBUG_INFO, "\n")); + DEBUG ((DEBUG_INFO, "==== TestPointDumpMtrr - Exit\n")); + + // Check - TBD + if (IsForDxe) { + Result = TRUE; + } else { + Result = TRUE; + } + + if (!Result) { + if (IsForDxe) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_CODE_2 TEST_POINT_END_OF_PEI TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_STRING_2 + ); + } else { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE, + NULL, + TEST_POINT_BYTE1_END_OF_PEI_ERROR_CODE_2 TEST_POINT_MEMORY_DISCOVERED TEST_POINT_BYTE1_END_OF_PEI_ERROR_STRING_2 + ); + } + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpSmramHob.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpSmramHob.c new file mode 100644 index 0000000000..a8e2f91679 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiDumpSmramHob.c @@ -0,0 +1,95 @@ +/** @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 + +CHAR8 *mSmramStateName[] = { + "Open", + "Closed", + "Locked", + "Cacheable", + "Allocated", + "NeedTest", + "NeedEccInit", +}; + +VOID +DumpSmramDescriptor ( + IN UINTN NumberOfSmmReservedRegions, + IN EFI_SMRAM_DESCRIPTOR *Descriptor + ) +{ + UINTN Index; + UINTN BitIndex; + + for (Index = 0; Index < NumberOfSmmReservedRegions; Index++) { + DEBUG ((DEBUG_INFO, + " BA=%016lx (A=%016lx) L=%016lx State=%016lx", + Descriptor[Index].PhysicalStart, + Descriptor[Index].CpuStart, + Descriptor[Index].PhysicalSize, + Descriptor[Index].RegionState + )); + DEBUG ((DEBUG_INFO, " (")); + for (BitIndex = 0; BitIndex < sizeof(mSmramStateName)/sizeof(mSmramStateName[0]); BitIndex++) { + if ((Descriptor[Index].RegionState & LShiftU64 (1, BitIndex)) != 0) { + DEBUG ((DEBUG_INFO, mSmramStateName[BitIndex])); + DEBUG ((DEBUG_INFO, ",")); + } + } + DEBUG ((DEBUG_INFO, ")\n")); + } +} + +EFI_STATUS +TestPointDumpSmramHob ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; + BOOLEAN Found; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmramHob - Enter\n")); + Hob.Raw = GetHobList (); + DEBUG ((DEBUG_INFO, "SMRAM HOB\n")); + while (!END_OF_HOB_LIST (Hob)) { + if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) { + if (CompareGuid (&Hob.Guid->Name, &gEfiSmmPeiSmramMemoryReserveGuid)) { + SmramHobDescriptorBlock = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *) (Hob.Guid + 1); + DumpSmramDescriptor (SmramHobDescriptorBlock->NumberOfSmmReservedRegions, SmramHobDescriptorBlock->Descriptor); + Found = TRUE; + break; + } + } + Hob.Raw = GET_NEXT_HOB (Hob); + } + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmramHob - Exit\n")); + + if (!Found) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_CODE_3 TEST_POINT_MEMORY_DISCOVERED TEST_POINT_BYTE1_MEMORY_DISCOVERED_ERROR_STRING_3 + ); + return EFI_INVALID_PARAMETER; + } + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.c new file mode 100644 index 0000000000..754771eafd --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.c @@ -0,0 +1,204 @@ +/** @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 + +EFI_STATUS +TestPointDumpMtrr ( + IN BOOLEAN IsForDxe + ); + +EFI_STATUS +TestPointDumpHob ( + IN BOOLEAN PhitHobOnly + ); + +EFI_STATUS +TestPointDumpFvInfo ( + VOID + ); + +EFI_STATUS +TestPointDumpSmramHob ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointDebugInitDone ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "======== TestPointDebugInitDone - Enter\n")); + DEBUG ((DEBUG_INFO, "!!! DebugInitialized !!!\n")); + + Result = TRUE; + Status = TestPointDumpHob (TRUE); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 1, + TEST_POINT_BYTE1_DEBUG_INIT_DONE + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointDebugInitDone - Exit\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointMemoryDiscovered ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "======== TestPointMemoryDiscovered - Enter\n")); + Result = TRUE; + Status = TestPointDumpMtrr (FALSE); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpHob (FALSE); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpFvInfo (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpSmramHob (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 1, + TEST_POINT_BYTE1_MEMORY_DISCOVERED + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointMemoryDiscovered - Exit\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointEndOfPei ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "======== TestPointEndOfPei - Enter\n")); + Result = TRUE; + Status = TestPointDumpMtrr (TRUE); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpHob (FALSE); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpFvInfo (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpSmramHob (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 1, + TEST_POINT_BYTE1_END_OF_PEI + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointEndOfPei - Exit\n")); + return EFI_SUCCESS; +} + +GLOBAL_REMOVE_IF_UNREFERENCED ADAPTER_INFO_PLATFORM_TEST_POINT_STRUCT mTestPointStruct = { + PLATFORM_TEST_POINT_VERSION, + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + {TEST_POINT_IMPLEMENTATION_ID_PLATFORM}, + TEST_POINT_FEATURE_SIZE, + {0}, // FeaturesRequired + {0}, // FeaturesImplemented + {0}, // FeaturesVerified + 0, +}; + +/** + Initialize feature data +**/ +VOID +InitData ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + UINT8 FeatureImplemented[TEST_POINT_FEATURE_SIZE]; + ADAPTER_INFO_PLATFORM_TEST_POINT_STRUCT TestPointStruct; + + ASSERT (PcdGetSize(PcdTestPointIbvPlatformFeature) == sizeof(FeatureImplemented)); + CopyMem (FeatureImplemented, PcdGetPtr(PcdTestPointIbvPlatformFeature), sizeof(FeatureImplemented)); + + CopyMem (&TestPointStruct, &mTestPointStruct, sizeof(TestPointStruct)); + TestPointStruct.Role = Role; + CopyMem (TestPointStruct.FeaturesImplemented, FeatureImplemented, sizeof(FeatureImplemented)); + Status = TestPointLibSetTable ( + &TestPointStruct, + sizeof(TestPointStruct) + ); + if (EFI_ERROR (Status)) { + if (Status != EFI_ALREADY_STARTED) { + ASSERT_EFI_ERROR (Status); + } + } +} + +EFI_STATUS +EFIAPI +PeiTestPointCheckLibConstructor ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + InitData (PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf new file mode 100644 index 0000000000..11b4ce6756 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiTestPointCheckLib.inf @@ -0,0 +1,58 @@ +## @file +# Component information file for Board Init Test Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiTestPointCheckLib + FILE_GUID = 2EBA7FD0-1AAC-4DCC-B42A-C12905A61133 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = TestPointCheckLib + CONSTRUCTOR = PeiTestPointCheckLibConstructor + +[LibraryClasses] + BaseLib + DebugLib + BaseMemoryLib + MtrrLib + HobLib + PrintLib + PeiServicesLib + TestPointLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Sources] + PeiTestPointCheckLib.c + PeiDumpMtrr.c + PeiDumpHob.c + PeiDumpFvInfo.c + PeiDumpSmramHob.c + +[Pcd] + gPlatformModuleTokenSpaceGuid.PcdTestPointIbvPlatformFeature + +[Guids] + gEfiHobMemoryAllocStackGuid + gEfiHobMemoryAllocBspStoreGuid + gEfiHobMemoryAllocModuleGuid + gEfiSmmPeiSmramMemoryReserveGuid + +[Ppis] + gEfiPeiFirmwareVolumeInfoPpiGuid + gEfiPeiFirmwareVolumeInfo2PpiGuid \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecDumpCpuInfo.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecDumpCpuInfo.c new file mode 100644 index 0000000000..9ec3044353 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecDumpCpuInfo.c @@ -0,0 +1,39 @@ +/** @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 + +VOID +TestPointDumpCpuInfo ( + VOID + ) +{ + UINT32 RegEax; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpCpuInfo - Enter\n")); + + DEBUG((DEBUG_INFO, "CPU info\n")); + AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, NULL); + DEBUG((DEBUG_INFO, " CPUID = 0x%08x\n", RegEax)); + + DEBUG((DEBUG_INFO, " Microcode ID (0x%08x) = 0x%016lx\n", MSR_IA32_BIOS_SIGN_ID, AsmReadMsr64 (MSR_IA32_BIOS_SIGN_ID))); + DEBUG((DEBUG_INFO, " Platform ID (0x%08x) = 0x%016lx\n", MSR_IA32_PLATFORM_ID, AsmReadMsr64 (MSR_IA32_PLATFORM_ID))); + //DEBUG((DEBUG_INFO, " PLATFORM_INFO (0x%08x) = 0x%016lx\n", MSR_NEHALEM_PLATFORM_INFO, AsmReadMsr64 (MSR_NEHALEM_PLATFORM_INFO))); + + DEBUG ((DEBUG_INFO, "==== TestPointDumpCpuInfo - Exit\n")); +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.c new file mode 100644 index 0000000000..8d10a255e1 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.c @@ -0,0 +1,40 @@ +/** @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 + +VOID +TestPointDumpCpuInfo ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointTempMemoryInitDone ( + IN VOID *TempRamStart, + IN VOID *TempRamEnd + ) +{ + DEBUG ((DEBUG_INFO, "======== TestPointTempMemoryInitDone - Enter\n")); + + DEBUG ((DEBUG_INFO, "TempRamStart - 0x%08x\n", TempRamStart)); + DEBUG ((DEBUG_INFO, "TempRamEnd - 0x%08x\n", TempRamEnd)); + + TestPointDumpCpuInfo (); + + DEBUG ((DEBUG_INFO, "======== TestPointTempMemoryInitDone - Exit\n")); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.inf new file mode 100644 index 0000000000..c7445d9222 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SecTestPointCheckLib.inf @@ -0,0 +1,37 @@ +## @file +# Component information file for Board Init Test Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SecTestPointCheckLib + FILE_GUID = 1BC3BD18-CDB3-4475-95B1-B2A5F4F026E3 + MODULE_TYPE = SEC + VERSION_STRING = 1.0 + LIBRARY_CLASS = TestPointCheckLib + +[LibraryClasses] + BaseLib + DebugLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Sources] + SecTestPointCheckLib.c + SecDumpCpuInfo.c + +[Pcd] diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpLoadedImage.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpLoadedImage.c new file mode 100644 index 0000000000..63b20edc6a --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpLoadedImage.c @@ -0,0 +1,111 @@ +/** @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 + +VOID +DumpLoadedImage ( + IN UINTN Index, + IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, + IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath + ); + +EFI_STATUS +TestPointDumpSmmLoadedImage ( + VOID + ) +{ + EFI_STATUS Status; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + UINTN Index; + UINTN HandleBufSize; + EFI_HANDLE *HandleBuf; + UINTN HandleCount; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmmLoadedImage - Enter\n")); + HandleBuf = NULL; + HandleBufSize = 0; + Status = gSmst->SmmLocateHandle ( + ByProtocol, + &gEfiLoadedImageProtocolGuid, + NULL, + &HandleBufSize, + HandleBuf + ); + if (Status != EFI_BUFFER_TOO_SMALL) { + goto Done ; + } + HandleBuf = AllocateZeroPool (HandleBufSize); + if (HandleBuf == NULL) { + goto Done ; + } + Status = gSmst->SmmLocateHandle ( + ByProtocol, + &gEfiLoadedImageProtocolGuid, + NULL, + &HandleBufSize, + HandleBuf + ); + if (EFI_ERROR (Status)) { + goto Done ; + } + HandleCount = HandleBufSize / sizeof(EFI_HANDLE); + + DEBUG ((DEBUG_INFO, "SmmLoadedImage (%d):\n", HandleCount)); + for (Index = 0; Index < HandleCount; Index++) { + Status = gSmst->SmmHandleProtocol ( + HandleBuf[Index], + &gEfiLoadedImageProtocolGuid, + (VOID **)&LoadedImage + ); + if (EFI_ERROR(Status)) { + continue; + } + + Status = gSmst->SmmHandleProtocol (LoadedImage->DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath); + if (EFI_ERROR(Status)) { + DevicePath = NULL; + } + + Status = gSmst->SmmHandleProtocol (HandleBuf[Index], &gEfiLoadedImageDevicePathProtocolGuid, (VOID **)&LoadedImageDevicePath); + if (EFI_ERROR(Status)) { + LoadedImageDevicePath = NULL; + } + + DumpLoadedImage (Index, LoadedImage, DevicePath, LoadedImageDevicePath); + } + +Done: + + if (HandleBuf != NULL) { + FreePool (HandleBuf); + } + + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmmLoadedImage - Exit\n")); + + // Check - TBD + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpMemAttribute.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpMemAttribute.c new file mode 100644 index 0000000000..bf7008c160 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpMemAttribute.c @@ -0,0 +1,86 @@ +/** @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 + +VOID +DumpMemoryAttributesTable ( + IN EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable + ); + +/** + Retrieves a pointer to the system configuration table from the SMM System Table + based on a specified GUID. + + @param[in] TableGuid The pointer to table's GUID type. + @param[out] Table The pointer to the table associated with TableGuid in the EFI System Table. + + @retval EFI_SUCCESS A configuration table matching TableGuid was found. + @retval EFI_NOT_FOUND A configuration table matching TableGuid could not be found. + +**/ +EFI_STATUS +EFIAPI +SmmGetSystemConfigurationTable ( + IN EFI_GUID *TableGuid, + OUT VOID **Table + ) +{ + UINTN Index; + + ASSERT (TableGuid != NULL); + ASSERT (Table != NULL); + + *Table = NULL; + for (Index = 0; Index < gSmst->NumberOfTableEntries; Index++) { + if (CompareGuid (TableGuid, &(gSmst->SmmConfigurationTable[Index].VendorGuid))) { + *Table = gSmst->SmmConfigurationTable[Index].VendorTable; + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +EFI_STATUS +TestPointDumpSmmMemAttribute ( + VOID + ) +{ + EFI_STATUS Status; + VOID *MemoryAttributesTable; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmmMemAttribute - Enter\n")); + Status = SmmGetSystemConfigurationTable (&gEdkiiPiSmmMemoryAttributesTableGuid, (VOID **)&MemoryAttributesTable); + if (!EFI_ERROR (Status)) { + DumpMemoryAttributesTable((EFI_MEMORY_ATTRIBUTES_TABLE *)MemoryAttributesTable); + } else { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_SMM_READY_TO_LOCK_ERROR_CODE_1 TEST_POINT_SMM_READY_TO_LOCK TEST_POINT_BYTE2_SMM_READY_TO_LOCK_ERROR_STRING_1 + ); + } + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmmMemAttribute - Exit\n")); + + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpSmrr.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpSmrr.c new file mode 100644 index 0000000000..f10db06574 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmDumpSmrr.c @@ -0,0 +1,125 @@ +/** @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 + +// +// Machine Specific Registers (MSRs) +// +#define SMM_FEATURES_LIB_IA32_MTRR_CAP 0x0FE +#define SMM_FEATURES_LIB_IA32_SMRR_PHYSBASE 0x1F2 +#define SMM_FEATURES_LIB_IA32_SMRR_PHYSMASK 0x1F3 +#define SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE 0x0A0 +#define SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSMASK 0x0A1 + +BOOLEAN mSmrrSupported = FALSE; +// +// Set default value to assume IA-32 Architectural MSRs are used +// +UINT32 mSmrrPhysBaseMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSBASE; +UINT32 mSmrrPhysMaskMsr = SMM_FEATURES_LIB_IA32_SMRR_PHYSMASK; + +EFI_STATUS +TestPointDumpSmrr ( + VOID + ) +{ + UINT64 SmrrBase; + UINT64 SmrrMask; + + UINT32 RegEax; + UINT32 RegEdx; + UINTN FamilyId; + UINTN ModelId; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmrr - Enter\n")); + + // + // Retrieve CPU Family and Model + // + AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, &RegEdx); + FamilyId = (RegEax >> 8) & 0xf; + ModelId = (RegEax >> 4) & 0xf; + if (FamilyId == 0x06 || FamilyId == 0x0f) { + ModelId = ModelId | ((RegEax >> 12) & 0xf0); + } + + // + // Check CPUID(CPUID_VERSION_INFO).EDX[12] for MTRR capability + // + if ((RegEdx & BIT12) != 0) { + // + // Check MTRR_CAP MSR bit 11 for SMRR support + // + if ((AsmReadMsr64 (SMM_FEATURES_LIB_IA32_MTRR_CAP) & BIT11) != 0) { + mSmrrSupported = TRUE; + } + } + + // + // Intel(R) 64 and IA-32 Architectures Software Developer's Manual + // Volume 3C, Section 35.3 MSRs in the Intel(R) Atom(TM) Processor Family + // + // If CPU Family/Model is 06_1CH, 06_26H, 06_27H, 06_35H or 06_36H, then + // SMRR Physical Base and SMM Physical Mask MSRs are not available. + // + if (FamilyId == 0x06) { + if (ModelId == 0x1C || ModelId == 0x26 || ModelId == 0x27 || ModelId == 0x35 || ModelId == 0x36) { + mSmrrSupported = FALSE; + } + } + + // + // Intel(R) 64 and IA-32 Architectures Software Developer's Manual + // Volume 3C, Section 35.2 MSRs in the Intel(R) Core(TM) 2 Processor Family + // + // If CPU Family/Model is 06_0F or 06_17, then use Intel(R) Core(TM) 2 + // Processor Family MSRs + // + if (FamilyId == 0x06) { + if (ModelId == 0x17 || ModelId == 0x0f) { + mSmrrPhysBaseMsr = SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE; + mSmrrPhysMaskMsr = SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSMASK; + } + } + + if (mSmrrSupported) { + SmrrBase = AsmReadMsr64 (mSmrrPhysBaseMsr); + SmrrMask = AsmReadMsr64 (mSmrrPhysMaskMsr); + DEBUG ((DEBUG_INFO, "SMRR : Base=%016lx Make=%016lx\n", SmrrBase, SmrrMask)); + } + + DEBUG ((DEBUG_INFO, "==== TestPointDumpSmrr - Exit\n")); + + // Check - TBD + Result = TRUE; + + if (!Result) { + TestPointLibAppendErrorString ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + TEST_POINT_BYTE2_SMM_READY_TO_LOCK_ERROR_CODE_2 TEST_POINT_SMM_READY_TO_LOCK TEST_POINT_BYTE2_SMM_READY_TO_LOCK_ERROR_STRING_2 + ); + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.c new file mode 100644 index 0000000000..e99fefa386 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.c @@ -0,0 +1,172 @@ +/** @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 + +EFI_STATUS +TestPointDumpSmrr ( + VOID + ); + +EFI_STATUS +TestPointDumpSmmLoadedImage ( + VOID + ); + +EFI_STATUS +TestPointDumpSmmMemAttribute ( + VOID + ); + +EFI_STATUS +EFIAPI +TestPointSmmEndOfDxe ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "======== TestPointSmmEndOfDxe - Enter\n")); + + Result = TRUE; + Status = TestPointDumpSmmLoadedImage (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 3, + TEST_POINT_BYTE3_SMM_END_OF_DXE + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointSmmEndOfDxe - Exit\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointSmmReadyToLock ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN Result; + + DEBUG ((DEBUG_INFO, "======== TestPointSmmReadyToLock - Enter\n")); + + Result = TRUE; + Status = TestPointDumpSmrr (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + Status = TestPointDumpSmmMemAttribute (); + if (EFI_ERROR(Status)) { + Result = FALSE; + } + + if (Result) { + TestPointLibSetFeaturesVerified ( + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + NULL, + 3, + TEST_POINT_BYTE3_SMM_READY_TO_LOCK + ); + } + + DEBUG ((DEBUG_INFO, "======== TestPointSmmReadyToLock - Exit\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointSmmReadyToBoot ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "======== TestPointSmmReadyToBoot - Enter\n")); + + DEBUG ((DEBUG_INFO, "======== TestPointSmmReadyToBoot - Exit\n")); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointSmmExitBootServices ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "======== TestPointSmmExitBootServices - Enter\n")); + + DEBUG ((DEBUG_INFO, "======== TestPointSmmExitBootServices - Exit\n")); + return EFI_SUCCESS; +} + +GLOBAL_REMOVE_IF_UNREFERENCED ADAPTER_INFO_PLATFORM_TEST_POINT_STRUCT mTestPointStruct = { + PLATFORM_TEST_POINT_VERSION, + PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV, + {TEST_POINT_IMPLEMENTATION_ID_PLATFORM}, + TEST_POINT_FEATURE_SIZE, + {0}, // FeaturesRequired + {0}, // FeaturesImplemented + {0}, // FeaturesVerified + 0, +}; + +GLOBAL_REMOVE_IF_UNREFERENCED UINT8 mFeatureImplemented[TEST_POINT_FEATURE_SIZE]; + +/** + Initialize feature data +**/ +VOID +InitData ( + IN UINT32 Role + ) +{ + EFI_STATUS Status; + + ASSERT (PcdGetSize(PcdTestPointIbvPlatformFeature) == sizeof(mFeatureImplemented)); + CopyMem (mFeatureImplemented, PcdGetPtr(PcdTestPointIbvPlatformFeature), sizeof(mFeatureImplemented)); + + mTestPointStruct.Role = Role; + CopyMem (mTestPointStruct.FeaturesImplemented, mFeatureImplemented, sizeof(mFeatureImplemented)); + Status = TestPointLibSetTable ( + &mTestPointStruct, + sizeof(mTestPointStruct) + ); + if (EFI_ERROR (Status)) { + if (Status != EFI_ALREADY_STARTED) { + ASSERT_EFI_ERROR (Status); + } + } +} + +EFI_STATUS +EFIAPI +SmmTestPointCheckLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + InitData (PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.inf new file mode 100644 index 0000000000..f17c96cecb --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.inf @@ -0,0 +1,59 @@ +## @file +# Component information file for Board Init Test Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SmmTestPointCheckLib + FILE_GUID = 74A1F91F-AD11-49C5-96B8-A579F4AA65F1 + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = TestPointCheckLib + CONSTRUCTOR = SmmTestPointCheckLibConstructor + +[LibraryClasses] + BaseLib + DebugLib + SmmServicesTableLib + MemoryAllocationLib + DevicePathLib + PeCoffGetEntryPointLib + TestPointLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Sources] + SmmTestPointCheckLib.c + SmmDumpMemAttribute.c + DxeDumpMemAttribute.c + DxeDumpMemMap.c + SmmDumpLoadedImage.c + DxeDumpLoadedImage.c + SmmDumpSmrr.c + +[Pcd] + gPlatformModuleTokenSpaceGuid.PcdTestPointIbvPlatformFeature + +[Guids] + gEdkiiPiSmmMemoryAttributesTableGuid + gEfiMemoryAttributesTableGuid + +[Protocols] + gEfiLoadedImageProtocolGuid + gEfiLoadedImageDevicePathProtocolGuid + gEfiDevicePathProtocolGuid diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.c new file mode 100644 index 0000000000..db932318b7 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.c @@ -0,0 +1,133 @@ +/** @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 + +EFI_STATUS +EFIAPI +TestPointTempMemoryInitDone ( + IN VOID *TempRamStart, + IN VOID *TempRamEnd + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointDebugInitDone ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointMemoryDiscovered ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointEndOfPei ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointPciEnumerationDone ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointEndOfDxe ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointDxeSmmReadyToLock ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointReadyToBoots ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointExitBootServices ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointSmmEndOfDxe ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointSmmReadyToLock ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointSmmReadyToBoot ( + VOID + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +TestPointSmmExitBootServices ( + VOID + ) +{ + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.inf new file mode 100644 index 0000000000..9801c2d68f --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLibNull/TestPointCheckLibNull.inf @@ -0,0 +1,32 @@ +## @file +# Component information file for Board Init Test Library +# +# 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 which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = TestPointCheckLibNull + FILE_GUID = 657A478B-16B9-4B6D-9C41-BEF86197BDF4 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = TestPointCheckLib + +[LibraryClasses] + BaseLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + +[Sources] + TestPointCheckLibNull.c diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPoint.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPoint.c new file mode 100644 index 0000000000..40474cd4f2 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPoint.c @@ -0,0 +1,611 @@ +/** @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 + which 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 "DxeTestPoint.h" + +/** + Find TestPoint table in AIP protocol, and return the data. + This API will return the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param TestPointData TestPoint data. This buffer is allocated by callee, and it + is the responsibility of the caller to free it after + using it. + @param TestPointSize TestPoint size + + @return Aip The AIP protocol having this TestPoint. + @return NULL There is not TestPoint table with the Role and ImplementationID published in system. +**/ +VOID * +InternalTestPointFindAip ( + IN UINT32 Role, + IN CHAR16 *ImplementationID OPTIONAL, + OUT VOID **TestPointData OPTIONAL, + OUT UINTN *TestPointSize OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + UINTN NoHandles; + EFI_HANDLE *Handles; + UINTN Index; + EFI_GUID *InfoTypesBuffer; + UINTN InfoTypesBufferCount; + UINTN InfoTypesIndex; + EFI_ADAPTER_INFORMATION_PROTOCOL *AipCandidate; + VOID *InformationBlock; + UINTN InformationBlockSize; + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiAdapterInformationProtocolGuid, + NULL, + &NoHandles, + &Handles + ); + if (EFI_ERROR (Status)) { + return NULL; + } + + TestPoint = NULL; + Aip = NULL; + InformationBlock = NULL; + InformationBlockSize = 0; + for (Index = 0; Index < NoHandles; Index++) { + Status = gBS->HandleProtocol ( + Handles[Index], + &gEfiAdapterInformationProtocolGuid, + (VOID **)&Aip + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Check AIP + // + Status = Aip->GetSupportedTypes ( + Aip, + &InfoTypesBuffer, + &InfoTypesBufferCount + ); + if (EFI_ERROR (Status)) { + continue; + } + + AipCandidate = NULL; + for (InfoTypesIndex = 0; InfoTypesIndex < InfoTypesBufferCount; InfoTypesIndex++) { + if (CompareGuid (&InfoTypesBuffer[InfoTypesIndex], &gAdapterInfoPlatformTestPointGuid)) { + AipCandidate = Aip; + break; + } + } + FreePool (InfoTypesBuffer); + + if (AipCandidate == NULL) { + continue; + } + + // + // Check Role + // + Aip = AipCandidate; + Status = Aip->GetInformation ( + Aip, + &gAdapterInfoPlatformTestPointGuid, + &InformationBlock, + &InformationBlockSize + ); + if (EFI_ERROR (Status)) { + continue; + } + + TestPoint = InformationBlock; + if ((TestPoint->Role == Role) && + ((ImplementationID == NULL) || (StrCmp (ImplementationID, TestPoint->ImplementationID) == 0))) { + break; + } else { + TestPoint = NULL; + FreePool (InformationBlock); + continue; + } + } + FreePool (Handles); + + if (TestPoint == NULL) { + return NULL; + } + + if (TestPointData != NULL) { + *TestPointData = InformationBlock; + } + if (TestPointSize != NULL) { + *TestPointSize = InformationBlockSize; + } + return Aip; +} + +/** + Return if input TestPoint data is valid. + + @param TestPointData TestPoint data + @param TestPointSize TestPoint size + + @retval TRUE TestPoint data is valid. + @retval FALSE TestPoint data is not valid. +**/ +BOOLEAN +InternalTestPointIsValidTable ( + IN VOID *TestPointData, + IN UINTN TestPointSize + ) +{ + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN Index; + CHAR16 *ErrorString; + CHAR16 ErrorChar; + UINTN ErrorStringSize; + UINTN ErrorStringLength; + + TestPoint = TestPointData; + + // + // basic check for header + // + if (TestPointData == NULL) { + DEBUG ((EFI_D_ERROR, "TestPointData == NULL\n")); + return FALSE; + } + if (TestPointSize < sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)) { + DEBUG ((EFI_D_ERROR, "TestPointSize < sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)\n")); + return FALSE; + } + if (((TestPointSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)) / 3) < TestPoint->FeaturesSize) { + DEBUG ((EFI_D_ERROR, "((TestPointSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)) / 3) < FeaturesSize\n")); + return FALSE; + } + + // + // Check Version + // + if (TestPoint->Version != PLATFORM_TEST_POINT_VERSION) { + DEBUG ((EFI_D_ERROR, "Version != PLATFORM_TEST_POINT_VERSION\n")); + return FALSE; + } + + // + // Check Role + // + if ((TestPoint->Role < PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE) || + (TestPoint->Role > PLATFORM_TEST_POINT_ROLE_IMPLEMENTOR_ODM)) { + DEBUG ((EFI_D_ERROR, "Role < PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE ||\n")); + DEBUG ((EFI_D_ERROR, "Role > PLATFORM_TEST_POINT_ROLE_IMPLEMENTOR_ODM\n")); + return FALSE; + } + + // + // Check ImplementationID + // + for (Index = 0; Index < sizeof(TestPoint->ImplementationID)/sizeof(TestPoint->ImplementationID[0]); Index++) { + if (TestPoint->ImplementationID[Index] == 0) { + break; + } + } + if (Index == sizeof(TestPoint->ImplementationID)/sizeof(TestPoint->ImplementationID[0])) { + DEBUG ((EFI_D_ERROR, "ImplementationID is no NUL CHAR\n")); + return FALSE; + } + + ErrorStringSize = TestPointSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) - TestPoint->FeaturesSize * 3; + ErrorString = (CHAR16 *)((UINTN)TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) - TestPoint->FeaturesSize * 3); + + // + // basic check for ErrorString + // + if (ErrorStringSize == 0) { + DEBUG ((EFI_D_ERROR, "ErrorStringSize == 0\n")); + return FALSE; + } + if ((ErrorStringSize & BIT0) != 0) { + DEBUG ((EFI_D_ERROR, "(ErrorStringSize & BIT0) != 0\n")); + return FALSE; + } + + // + // ErrorString might not be CHAR16 aligned. + // + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + for (ErrorStringLength = 0; (ErrorChar != 0) && (ErrorStringLength < (ErrorStringSize/2)); ErrorStringLength++) { + ErrorString++; + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + } + + // + // check the length of ErrorString + // + if (ErrorChar != 0) { + DEBUG ((EFI_D_ERROR, "ErrorString has no NUL CHAR\n")); + return FALSE; + } + if (ErrorStringLength == (ErrorStringSize/2)) { + DEBUG ((EFI_D_ERROR, "ErrorString Length incorrect\n")); + return FALSE; + } + + return TRUE; +} + +/** + Publish TestPoint table in AIP protocol. + + One system should have only one PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE. + + If the Role is NOT PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE, + FeaturesRequired field will be ignored. + + @param TestPoint TestPoint data + @param TestPointSize TestPoint size + + @retval EFI_SUCCESS The TestPoint data is published in AIP protocol. + @retval EFI_ALREADY_STARTED There is already TestPoint table with Role and ImplementationID published in system. + @retval EFI_VOLUME_CORRUPTED The input TestPoint data is invalid. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish TestPoint data in AIP protocol. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetTable ( + IN VOID *TestPoint, + IN UINTN TestPointSize + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + TEST_POINT_AIP_PRIVATE_DATA *TestPointAip; + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + UINT32 Role; + CHAR16 *ImplementationID; + UINT32 FeaturesSize; + UINT8 *FeaturesRequired; + + if (!InternalTestPointIsValidTable (TestPoint, TestPointSize)) { + return EFI_VOLUME_CORRUPTED; + } + + Role = ((ADAPTER_INFO_PLATFORM_TEST_POINT *)TestPoint)->Role; + ImplementationID = ((ADAPTER_INFO_PLATFORM_TEST_POINT *)TestPoint)->ImplementationID; + Aip = InternalTestPointFindAip (Role, ImplementationID, NULL, NULL); + if (Aip != NULL) { + return EFI_ALREADY_STARTED; + } + + TestPointAip = AllocateZeroPool (sizeof(TEST_POINT_AIP_PRIVATE_DATA)); + if (TestPointAip == NULL) { + return EFI_OUT_OF_RESOURCES; + } + TestPointAip->TestPoint = AllocateCopyPool (TestPointSize, TestPoint); + if (TestPointAip->TestPoint == NULL) { + FreePool (TestPointAip); + return EFI_OUT_OF_RESOURCES; + } + if (Role != PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE) { + FeaturesRequired = (UINT8 *)TestPointAip->TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT); + FeaturesSize = ((ADAPTER_INFO_PLATFORM_TEST_POINT *)TestPoint)->FeaturesSize; + ZeroMem (FeaturesRequired, FeaturesSize); + } + + TestPointAip->Signature = TEST_POINT_AIP_PRIVATE_SIGNATURE; + CopyMem (&TestPointAip->Aip, &mAdapterInformationProtocol, sizeof(EFI_ADAPTER_INFORMATION_PROTOCOL)); + TestPointAip->TestPointSize = TestPointSize; + TestPointAip->TestPointMaxSize = TestPointSize; + + Handle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces ( + &Handle, + &gEfiAdapterInformationProtocolGuid, + &TestPointAip->Aip, + NULL + ); + if (EFI_ERROR (Status)) { + FreePool (TestPointAip->TestPoint); + FreePool (TestPointAip); + } + + return Status; +} + +/** + Search TestPoint table in AIP protocol, and return the data. + This API will return the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param TestPoint TestPoint data. This buffer is allocated by callee, and it + is the responsibility of the caller to free it after + using it. + @param TestPointSize TestPoint size + + @retval EFI_SUCCESS The TestPoint data in AIP protocol is returned. + @retval EFI_NOT_FOUND There is not TestPoint table with the Role and ImplementationID published in system. +**/ +EFI_STATUS +EFIAPI +TestPointLibGetTable ( + IN UINT32 Role, + IN CHAR16 *ImplementationID OPTIONAL, + OUT VOID **TestPoint, + OUT UINTN *TestPointSize + ) +{ + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + + Aip = InternalTestPointFindAip (Role, ImplementationID, TestPoint, TestPointSize); + if (Aip == NULL) { + return EFI_NOT_FOUND; + } + return EFI_SUCCESS; +} + +/** + Record FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + @param Set TRUE means to set the FeaturesVerified bit. + FALSE means to clear the FeaturesVerified bit. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +InternalTestPointRecordFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 Bit, + IN BOOLEAN Set + ) +{ + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN TestPointSize; + UINT8 *FeaturesVerified; + EFI_STATUS Status; + + Aip = InternalTestPointFindAip (Role, ImplementationID, (VOID **)&TestPoint, &TestPointSize); + if (Aip == NULL) { + return EFI_NOT_STARTED; + } + + if (ByteIndex >= TestPoint->FeaturesSize) { + return EFI_UNSUPPORTED; + } + + FeaturesVerified = (UINT8 *)((UINTN)TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + TestPoint->FeaturesSize * 2); + + if (Set) { + FeaturesVerified[ByteIndex] = (UINT8)(FeaturesVerified[ByteIndex] | (Bit)); + } else { + FeaturesVerified[ByteIndex] = (UINT8)(FeaturesVerified[ByteIndex] & (~Bit)); + } + + Status = Aip->SetInformation ( + Aip, + &gAdapterInfoPlatformTestPointGuid, + TestPoint, + TestPointSize + ); + return Status; +} + +/** + Set FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 BitMask + ) +{ + return InternalTestPointRecordFeaturesVerified ( + Role, + ImplementationID, + ByteIndex, + BitMask, + TRUE + ); +} + +/** + Clear FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +EFIAPI +TestPointLibClearFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 BitMask + ) +{ + return InternalTestPointRecordFeaturesVerified ( + Role, + ImplementationID, + ByteIndex, + BitMask, + FALSE + ); +} + +/** + Record ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + @param Append TRUE means to append the ErrorString to TestPoint table. + FALSE means to set the ErrorString in TestPoint table. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is published in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +InternalTestPointRecordErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString, + IN BOOLEAN Append + ) +{ + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN TestPointSize; + UINTN StringSize; + VOID *NewTestPoint; + UINTN NewTestPointSize; + UINTN Offset; + EFI_STATUS Status; + + Aip = InternalTestPointFindAip (Role, ImplementationID, (VOID **)&TestPoint, &TestPointSize); + if (Aip == NULL) { + return EFI_NOT_STARTED; + } + + if (Append) { + Offset = TestPointSize - sizeof(CHAR16); + } else { + Offset = sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + TestPoint->FeaturesSize * 3; + } + StringSize = StrSize (ErrorString); + + NewTestPointSize = Offset + StringSize; + NewTestPoint = AllocatePool (NewTestPointSize); + if (NewTestPoint == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem (NewTestPoint, TestPoint, Offset); + CopyMem ((UINT8 *)NewTestPoint + Offset, ErrorString, StringSize); + + Status = Aip->SetInformation ( + Aip, + &gAdapterInfoPlatformTestPointGuid, + NewTestPoint, + NewTestPointSize + ); + return Status; +} + +/** + Append ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +EFIAPI +TestPointLibAppendErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString + ) +{ + DEBUG ((DEBUG_ERROR, "TestPointLibAppendErrorString - (0x%x) %s\n", Role, ErrorString)); + return InternalTestPointRecordErrorString ( + Role, + ImplementationID, + ErrorString, + TRUE + ); +} + +/** + Set a new ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString + ) +{ + DEBUG ((DEBUG_ERROR, "TestPointLibSetErrorString - %s\n", ErrorString)); + return InternalTestPointRecordErrorString ( + Role, + ImplementationID, + ErrorString, + FALSE + ); +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPoint.h b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPoint.h new file mode 100644 index 0000000000..e152f95a13 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPoint.h @@ -0,0 +1,61 @@ +/** @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 + which 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. + +**/ + +#ifndef _DXE_TEST_POINT_DXE_H_ +#define _DXE_TEST_POINT_DXE_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define TEST_POINT_AIP_PRIVATE_SIGNATURE SIGNATURE_32('T', 'S', 'P', 'T') + +typedef struct { + UINT32 Signature; + EFI_ADAPTER_INFORMATION_PROTOCOL Aip; + VOID *TestPoint; + UINTN TestPointSize; + UINTN TestPointMaxSize; +} TEST_POINT_AIP_PRIVATE_DATA; + +#define TEST_POINT_AIP_PRIVATE_DATA_FROM_THIS(a) \ + CR (a, \ + TEST_POINT_AIP_PRIVATE_DATA, \ + Aip, \ + TEST_POINT_AIP_PRIVATE_SIGNATURE \ + ) + +extern EFI_ADAPTER_INFORMATION_PROTOCOL mAdapterInformationProtocol; + +/** + Return if input TestPoint data is valid. + + @param TestPointData TestPoint data + @param TestPointSize TestPoint size + + @retval TRUE TestPoint data is valid. + @retval FALSE TestPoint data is not valid. +**/ +BOOLEAN +InternalTestPointIsValidTable ( + IN VOID *TestPointData, + IN UINTN TestPointSize + ); + +#endif \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointAip.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointAip.c new file mode 100644 index 0000000000..2e807932f8 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointAip.c @@ -0,0 +1,175 @@ +/** @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 + which 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 "DxeTestPoint.h" + +/** + Returns the current state information for the adapter. + + This function returns information of type InformationType from the adapter. + If an adapter does not support the requested informational type, then + EFI_UNSUPPORTED is returned. + + @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance. + @param[in] InformationType A pointer to an EFI_GUID that defines the contents of InformationBlock. + @param[out] InformationBlock The service returns a pointer to the buffer with the InformationBlock + structure which contains details about the data specific to InformationType. + @param[out] InformationBlockSize The driver returns the size of the InformationBlock in bytes. + + @retval EFI_SUCCESS The InformationType information was retrieved. + @retval EFI_UNSUPPORTED The InformationType is not known. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_INVALID_PARAMETER InformationBlock is NULL. + @retval EFI_INVALID_PARAMETER InformationBlockSize is NULL. + +**/ +EFI_STATUS +EFIAPI +TestPointAipGetInfo ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + IN EFI_GUID *InformationType, + OUT VOID **InformationBlock, + OUT UINTN *InformationBlockSize + ) +{ + TEST_POINT_AIP_PRIVATE_DATA *TestPointAip; + + if ((This == NULL) || (InformationBlock == NULL) || (InformationBlockSize == NULL)) { + return EFI_INVALID_PARAMETER; + } + if (!CompareGuid (InformationType, &gAdapterInfoPlatformTestPointGuid)) { + return EFI_UNSUPPORTED; + } + + TestPointAip = TEST_POINT_AIP_PRIVATE_DATA_FROM_THIS(This); + + *InformationBlock = AllocateCopyPool (TestPointAip->TestPointSize, TestPointAip->TestPoint); + if (*InformationBlock == NULL) { + return EFI_OUT_OF_RESOURCES; + } + *InformationBlockSize = TestPointAip->TestPointSize; + return EFI_SUCCESS; +} + +/** + Sets state information for an adapter. + + This function sends information of type InformationType for an adapter. + If an adapter does not support the requested information type, then EFI_UNSUPPORTED + is returned. + + @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance. + @param[in] InformationType A pointer to an EFI_GUID that defines the contents of InformationBlock. + @param[in] InformationBlock A pointer to the InformationBlock structure which contains details + about the data specific to InformationType. + @param[in] InformationBlockSize The size of the InformationBlock in bytes. + + @retval EFI_SUCCESS The information was received and interpreted successfully. + @retval EFI_UNSUPPORTED The InformationType is not known. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_INVALID_PARAMETER InformationBlock is NULL. + @retval EFI_WRITE_PROTECTED The InformationType cannot be modified using EFI_ADAPTER_INFO_SET_INFO(). + +**/ +EFI_STATUS +EFIAPI +TestPointAipSetInfo ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN VOID *InformationBlock, + IN UINTN InformationBlockSize + ) +{ + TEST_POINT_AIP_PRIVATE_DATA *TestPointAip; + VOID *NewTestPoint; + + if ((This == NULL) || (InformationBlock == NULL)) { + return EFI_INVALID_PARAMETER; + } + if (!CompareGuid (InformationType, &gAdapterInfoPlatformTestPointGuid)) { + return EFI_UNSUPPORTED; + } + + if (!InternalTestPointIsValidTable (InformationBlock, InformationBlockSize)) { + return EFI_VOLUME_CORRUPTED; + } + + TestPointAip = TEST_POINT_AIP_PRIVATE_DATA_FROM_THIS(This); + + if (InformationBlockSize > TestPointAip->TestPointMaxSize) { + NewTestPoint = AllocateZeroPool (InformationBlockSize); + if (NewTestPoint == NULL) { + return EFI_OUT_OF_RESOURCES; + } + FreePool (TestPointAip->TestPoint); + TestPointAip->TestPoint = NewTestPoint; + TestPointAip->TestPointSize = 0; + TestPointAip->TestPointMaxSize = InformationBlockSize; + } + + CopyMem (TestPointAip->TestPoint, InformationBlock, InformationBlockSize); + TestPointAip->TestPointSize = InformationBlockSize; + return EFI_SUCCESS; +} + +/** + Get a list of supported information types for this instance of the protocol. + + This function returns a list of InformationType GUIDs that are supported on an + adapter with this instance of EFI_ADAPTER_INFORMATION_PROTOCOL. The list is returned + in InfoTypesBuffer, and the number of GUID pointers in InfoTypesBuffer is returned in + InfoTypesBufferCount. + + @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance. + @param[out] InfoTypesBuffer A pointer to the array of InformationType GUIDs that are supported + by This. + @param[out] InfoTypesBufferCount A pointer to the number of GUIDs present in InfoTypesBuffer. + + @retval EFI_SUCCESS The list of information type GUIDs that are supported on this adapter was + returned in InfoTypesBuffer. The number of information type GUIDs was + returned in InfoTypesBufferCount. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_INVALID_PARAMETER InfoTypesBuffer is NULL. + @retval EFI_INVALID_PARAMETER InfoTypesBufferCount is NULL. + @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the results. + +**/ +EFI_STATUS +EFIAPI +TestPointAipGetSupportedTypes ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + OUT EFI_GUID **InfoTypesBuffer, + OUT UINTN *InfoTypesBufferCount + ) +{ + if ((This == NULL) || (InfoTypesBuffer == NULL) || (InfoTypesBufferCount == NULL)) { + return EFI_INVALID_PARAMETER; + } + + *InfoTypesBuffer = AllocateCopyPool (sizeof(gAdapterInfoPlatformTestPointGuid), &gAdapterInfoPlatformTestPointGuid); + if (*InfoTypesBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + *InfoTypesBufferCount = 1; + + return EFI_SUCCESS; +} + +EFI_ADAPTER_INFORMATION_PROTOCOL mAdapterInformationProtocol = { + TestPointAipGetInfo, + TestPointAipSetInfo, + TestPointAipGetSupportedTypes, +}; diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointLib.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointLib.inf new file mode 100644 index 0000000000..5c394645d7 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointLib.inf @@ -0,0 +1,48 @@ +## @file +# DXE instance of TestPoint Library. +# +# 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 +# which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeTestPointLib + FILE_GUID = 9FDFABCE-7931-462F-8EDF-8C43AD58169C + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = TestPointLib + +[Sources] + DxeTestPointAip.c + DxeTestPoint.c + DxeTestPoint.h + +[Packages] + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + MemoryAllocationLib + DebugLib + UefiBootServicesTableLib + +[Guids] +## SOMETIMES_PRODUCES ## GUID +## SOMETIMES_CONSUMES ## GUID + gAdapterInfoPlatformTestPointGuid + +[Protocols] +## SOMETIMES_PRODUCES +## SOMETIMES_CONSUMES + gEfiAdapterInformationProtocolGuid + diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPoint.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPoint.c new file mode 100644 index 0000000000..f648e589b7 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPoint.c @@ -0,0 +1,541 @@ +/** @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 + which 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 "PeiTestPoint.h" + +UINTN +InternalGetTestPointInfoSize ( + IN ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint, + IN UINTN MaxSize + ) +{ + CHAR16 *ErrorString; + UINTN ErrorStringLength; + UINTN ErrorStringMaxSize; + CHAR16 ErrorChar; + + ErrorString = (CHAR16 *)((UINTN)TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + 3 * TestPoint->FeaturesSize); + + ErrorStringMaxSize = MaxSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) - TestPoint->FeaturesSize * 3; + // + // ErrorString might not be CHAR16 aligned. + // + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + for (ErrorStringLength = 0; (ErrorChar != 0) && (ErrorStringLength < (ErrorStringMaxSize/2)); ErrorStringLength++) { + ErrorString++; + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + } + + return sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + 3 * TestPoint->FeaturesSize + (ErrorStringLength + 1) * sizeof(CHAR16); +} + +/** + Find TestPoint table in AIP protocol, and return the data. + This API will return the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param TestPointData TestPoint data. This buffer is allocated by callee, and it + is the responsibility of the caller to free it after + using it. + @param TestPointSize TestPoint size + + @return Status +**/ +EFI_STATUS +InternalTestPointFindAip ( + IN UINT32 Role, + IN CHAR16 *ImplementationID OPTIONAL, + OUT VOID **TestPointData OPTIONAL, + OUT UINTN *TestPointSize OPTIONAL, + OUT UINTN *TestPointMaxSize OPTIONAL + ) +{ + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN Size; + UINTN MaxSize; + EFI_PEI_HOB_POINTERS Hob; + + Hob.Raw = GetHobList (); + while (TRUE) { + Hob.Raw = GetNextGuidHob (&gAdapterInfoPlatformTestPointGuid, Hob.Raw); + if (Hob.Raw == NULL) { + return EFI_NOT_FOUND; + } + TestPoint = GET_GUID_HOB_DATA (Hob); + MaxSize = GET_GUID_HOB_DATA_SIZE (Hob); + Size = InternalGetTestPointInfoSize (TestPoint, MaxSize); + + if ((TestPoint->Role == Role) && + ((ImplementationID == NULL) || (StrCmp (ImplementationID, TestPoint->ImplementationID) == 0))) { + break; + } + Hob.Raw = GET_NEXT_HOB (Hob); + if (Hob.Raw == NULL) { + return EFI_NOT_FOUND; + } + } + + if (TestPointData != NULL) { + *TestPointData = TestPoint; + } + if (TestPointSize != NULL) { + *TestPointSize = Size; + } + if (TestPointMaxSize != NULL) { + *TestPointMaxSize = MaxSize; + } + return EFI_SUCCESS; +} + +/** + Return if input TestPoint data is valid. + + @param TestPointData TestPoint data + @param TestPointSize TestPoint size + + @retval TRUE TestPoint data is valid. + @retval FALSE TestPoint data is not valid. +**/ +BOOLEAN +InternalTestPointIsValidTable ( + IN VOID *TestPointData, + IN UINTN TestPointSize + ) +{ + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN Index; + CHAR16 *ErrorString; + CHAR16 ErrorChar; + UINTN ErrorStringSize; + UINTN ErrorStringLength; + + TestPoint = TestPointData; + + // + // basic check for header + // + if (TestPointData == NULL) { + DEBUG ((EFI_D_ERROR, "TestPointData == NULL\n")); + return FALSE; + } + if (TestPointSize < sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)) { + DEBUG ((EFI_D_ERROR, "TestPointSize < sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)\n")); + return FALSE; + } + if (((TestPointSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)) / 3) < TestPoint->FeaturesSize) { + DEBUG ((EFI_D_ERROR, "((TestPointSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)) / 3) < FeaturesSize\n")); + return FALSE; + } + + // + // Check Version + // + if (TestPoint->Version != PLATFORM_TEST_POINT_VERSION) { + DEBUG ((EFI_D_ERROR, "Version != PLATFORM_TEST_POINT_VERSION\n")); + return FALSE; + } + + // + // Check Role + // + if ((TestPoint->Role < PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE) || + (TestPoint->Role > PLATFORM_TEST_POINT_ROLE_IMPLEMENTOR_ODM)) { + DEBUG ((EFI_D_ERROR, "Role < PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE ||\n")); + DEBUG ((EFI_D_ERROR, "Role > PLATFORM_TEST_POINT_ROLE_IMPLEMENTOR_ODM\n")); + return FALSE; + } + + // + // Check ImplementationID + // + for (Index = 0; Index < sizeof(TestPoint->ImplementationID)/sizeof(TestPoint->ImplementationID[0]); Index++) { + if (TestPoint->ImplementationID[Index] == 0) { + break; + } + } + if (Index == sizeof(TestPoint->ImplementationID)/sizeof(TestPoint->ImplementationID[0])) { + DEBUG ((EFI_D_ERROR, "ImplementationID is no NUL CHAR\n")); + return FALSE; + } + + ErrorStringSize = TestPointSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) - TestPoint->FeaturesSize * 3; + ErrorString = (CHAR16 *)((UINTN)TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) - TestPoint->FeaturesSize * 3); + + // + // basic check for ErrorString + // + if (ErrorStringSize == 0) { + DEBUG ((EFI_D_ERROR, "ErrorStringSize == 0\n")); + return FALSE; + } + if ((ErrorStringSize & BIT0) != 0) { + DEBUG ((EFI_D_ERROR, "(ErrorStringSize & BIT0) != 0\n")); + return FALSE; + } + + // + // ErrorString might not be CHAR16 aligned. + // + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + for (ErrorStringLength = 0; (ErrorChar != 0) && (ErrorStringLength < (ErrorStringSize/2)); ErrorStringLength++) { + ErrorString++; + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + } + + // + // check the length of ErrorString + // + if (ErrorChar != 0) { + DEBUG ((EFI_D_ERROR, "ErrorString has no NUL CHAR\n")); + return FALSE; + } + if (ErrorStringLength == (ErrorStringSize/2)) { + DEBUG ((EFI_D_ERROR, "ErrorString Length incorrect\n")); + return FALSE; + } + + return TRUE; +} + +/** + Publish TestPoint table in hob. + + One system should have only one PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE. + + If the Role is NOT PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE, + FeaturesRequired field will be ignored. + + @param TestPoint TestPoint data + @param TestPointSize TestPoint size + + @retval EFI_SUCCESS The TestPoint data is published in hob. + @retval EFI_ALREADY_STARTED There is already TestPoint table with Role and ImplementationID published in system. + @retval EFI_VOLUME_CORRUPTED The input TestPoint data is invalid. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish TestPoint data in hob. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetTable ( + IN VOID *TestPoint, + IN UINTN TestPointSize + ) +{ + VOID *NewTestPoint; + EFI_STATUS Status; + UINT32 Role; + CHAR16 *ImplementationID; + UINT32 FeaturesSize; + UINT8 *FeaturesRequired; + + if (!InternalTestPointIsValidTable (TestPoint, TestPointSize)) { + return EFI_VOLUME_CORRUPTED; + } + + Role = ((ADAPTER_INFO_PLATFORM_TEST_POINT *)TestPoint)->Role; + ImplementationID = ((ADAPTER_INFO_PLATFORM_TEST_POINT *)TestPoint)->ImplementationID; + Status = InternalTestPointFindAip (Role, ImplementationID, NULL, NULL, NULL); + if (!EFI_ERROR(Status)) { + return EFI_ALREADY_STARTED; + } + + NewTestPoint = BuildGuidHob (&gAdapterInfoPlatformTestPointGuid, TestPointSize); + if (NewTestPoint == NULL) { + return EFI_OUT_OF_RESOURCES; + } + if (Role != PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE) { + FeaturesRequired = (UINT8 *)TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT); + FeaturesSize = ((ADAPTER_INFO_PLATFORM_TEST_POINT *)TestPoint)->FeaturesSize; + ZeroMem (FeaturesRequired, FeaturesSize); + } + + CopyMem (NewTestPoint, TestPoint, TestPointSize); + + return EFI_SUCCESS; +} + +/** + Search TestPoint table in hob, and return the data. + This API will return the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param TestPoint TestPoint data. + @param TestPointSize TestPoint size + + @retval EFI_SUCCESS The TestPoint data in hob is returned. + @retval EFI_NOT_FOUND There is not TestPoint table with the Role and ImplementationID published in system. +**/ +EFI_STATUS +EFIAPI +TestPointLibGetTable ( + IN UINT32 Role, + IN CHAR16 *ImplementationID OPTIONAL, + OUT VOID **TestPoint, + OUT UINTN *TestPointSize + ) +{ + EFI_STATUS Status; + + Status = InternalTestPointFindAip (Role, ImplementationID, TestPoint, TestPointSize, NULL); + return Status; +} + +/** + Record FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + @param Set TRUE means to set the FeaturesVerified bit. + FALSE means to clear the FeaturesVerified bit. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +InternalTestPointRecordFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 Bit, + IN BOOLEAN Set + ) +{ + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN TestPointSize; + UINT8 *FeaturesVerified; + EFI_STATUS Status; + + Status = InternalTestPointFindAip (Role, ImplementationID, (VOID **)&TestPoint, &TestPointSize, NULL); + if (EFI_ERROR(Status)) { + return EFI_NOT_STARTED; + } + + if (ByteIndex >= TestPoint->FeaturesSize) { + return EFI_UNSUPPORTED; + } + + FeaturesVerified = (UINT8 *)((UINTN)TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + TestPoint->FeaturesSize * 2); + + if (Set) { + FeaturesVerified[ByteIndex] = (UINT8)(FeaturesVerified[ByteIndex] | (Bit)); + } else { + FeaturesVerified[ByteIndex] = (UINT8)(FeaturesVerified[ByteIndex] & (~Bit)); + } + + return EFI_SUCCESS; +} + +/** + Set FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in hob. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 BitMask + ) +{ + return InternalTestPointRecordFeaturesVerified ( + Role, + ImplementationID, + ByteIndex, + BitMask, + TRUE + ); +} + +/** + Clear FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in hob. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +EFIAPI +TestPointLibClearFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 BitMask + ) +{ + return InternalTestPointRecordFeaturesVerified ( + Role, + ImplementationID, + ByteIndex, + BitMask, + FALSE + ); +} + +/** + Record ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + @param Append TRUE means to append the ErrorString to TestPoint table. + FALSE means to set the ErrorString in TestPoint table. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is published in hob. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +InternalTestPointRecordErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString, + IN BOOLEAN Append + ) +{ + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN TestPointSize; + UINTN StringSize; + VOID *NewTestPoint; + UINTN NewTestPointSize; + UINTN Offset; + EFI_STATUS Status; + UINTN TestPointMaxSize; + EFI_HOB_GUID_TYPE *GuidHob; + + Status = InternalTestPointFindAip (Role, ImplementationID, (VOID **)&TestPoint, &TestPointSize, &TestPointMaxSize); + if (EFI_ERROR(Status)) { + return EFI_NOT_STARTED; + } + + if (Append) { + Offset = TestPointSize - sizeof(CHAR16); + } else { + Offset = sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + TestPoint->FeaturesSize * 3; + } + StringSize = StrSize (ErrorString); + + NewTestPointSize = Offset + StringSize; + if (NewTestPointSize > TestPointMaxSize) { + NewTestPoint = BuildGuidHob (&gAdapterInfoPlatformTestPointGuid, NewTestPointSize); + if (NewTestPoint == NULL) { + return EFI_OUT_OF_RESOURCES; + } + CopyMem (NewTestPoint, TestPoint, TestPointSize); + + // remove old data + GuidHob = (VOID *)((UINT8 *)TestPoint - sizeof (EFI_HOB_GUID_TYPE)); + ZeroMem (&GuidHob->Name, sizeof(GuidHob->Name)); + + TestPoint = NewTestPoint; + } + + CopyMem ((UINT8 *)TestPoint + Offset, ErrorString, StringSize); + + return Status; +} + +/** + Append ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is updated in hob. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +EFIAPI +TestPointLibAppendErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString + ) +{ + DEBUG ((DEBUG_ERROR, "TestPointLibAppendErrorString - (0x%x) %s\n", Role, ErrorString)); + return InternalTestPointRecordErrorString ( + Role, + ImplementationID, + ErrorString, + TRUE + ); +} + +/** + Set a new ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is updated in hob. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString + ) +{ + DEBUG ((DEBUG_ERROR, "TestPointLibSetErrorString - %s\n", ErrorString)); + return InternalTestPointRecordErrorString ( + Role, + ImplementationID, + ErrorString, + FALSE + ); +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPoint.h b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPoint.h new file mode 100644 index 0000000000..c2aa72e0ee --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPoint.h @@ -0,0 +1,44 @@ +/** @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 + which 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. + +**/ + +#ifndef _PEI_TEST_POINT_DXE_H_ +#define _PEI_TEST_POINT_DXE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/** + Return if input TestPoint data is valid. + + @param TestPointData TestPoint data + @param TestPointSize TestPoint size + + @retval TRUE TestPoint data is valid. + @retval FALSE TestPoint data is not valid. +**/ +BOOLEAN +InternalTestPointIsValidTable ( + IN VOID *TestPointData, + IN UINTN TestPointSize + ); + +#endif \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPointLib.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPointLib.inf new file mode 100644 index 0000000000..7fa2a471b4 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/PeiTestPointLib.inf @@ -0,0 +1,44 @@ +## @file +# PEI instance of TestPoint Library. +# +# 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 +# which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiTestPointLib + FILE_GUID = 9FDFABCE-7931-462F-8EDF-8C43AD58169C + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = TestPointLib + +[Sources] + PeiTestPoint.c + PeiTestPoint.h + +[Packages] + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + MemoryAllocationLib + DebugLib + PeiServicesLib + HobLib + +[Guids] +## SOMETIMES_PRODUCES ## GUID +## SOMETIMES_CONSUMES ## GUID + gAdapterInfoPlatformTestPointGuid + + diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPoint.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPoint.c new file mode 100644 index 0000000000..746d0308da --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPoint.c @@ -0,0 +1,634 @@ +/** @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 + which 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 "SmmTestPoint.h" + +/** + Find TestPoint table in AIP protocol, and return the data. + This API will return the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param TestPointData TestPoint data. This buffer is allocated by callee, and it + is the responsibility of the caller to free it after + using it. + @param TestPointSize TestPoint size + + @return Aip The AIP protocol having this TestPoint. + @return NULL There is not TestPoint table with the Role and ImplementationID published in system. +**/ +VOID * +InternalTestPointFindAip ( + IN UINT32 Role, + IN CHAR16 *ImplementationID OPTIONAL, + OUT VOID **TestPointData OPTIONAL, + OUT UINTN *TestPointSize OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + UINTN HandleBufSize; + UINTN NoHandles; + EFI_HANDLE *Handles; + UINTN Index; + EFI_GUID *InfoTypesBuffer; + UINTN InfoTypesBufferCount; + UINTN InfoTypesIndex; + EFI_ADAPTER_INFORMATION_PROTOCOL *AipCandidate; + VOID *InformationBlock; + UINTN InformationBlockSize; + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + + HandleBufSize = 0; + Handles = NULL; + Status = gSmst->SmmLocateHandle ( + ByProtocol, + &gEfiAdapterInformationProtocolGuid, + NULL, + &HandleBufSize, + Handles + ); + if (Status != EFI_BUFFER_TOO_SMALL) { + return NULL ; + } + Handles = AllocateZeroPool (HandleBufSize); + if (Handles == NULL) { + return NULL; + } + + Status = gSmst->SmmLocateHandle ( + ByProtocol, + &gEfiAdapterInformationProtocolGuid, + NULL, + &HandleBufSize, + Handles + ); + if (EFI_ERROR (Status)) { + return NULL; + } + NoHandles = HandleBufSize / sizeof(EFI_HANDLE); + + TestPoint = NULL; + Aip = NULL; + InformationBlock = NULL; + InformationBlockSize = 0; + for (Index = 0; Index < NoHandles; Index++) { + Status = gSmst->SmmHandleProtocol ( + Handles[Index], + &gEfiAdapterInformationProtocolGuid, + (VOID **)&Aip + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Check AIP + // + Status = Aip->GetSupportedTypes ( + Aip, + &InfoTypesBuffer, + &InfoTypesBufferCount + ); + if (EFI_ERROR (Status)) { + continue; + } + + AipCandidate = NULL; + for (InfoTypesIndex = 0; InfoTypesIndex < InfoTypesBufferCount; InfoTypesIndex++) { + if (CompareGuid (&InfoTypesBuffer[InfoTypesIndex], &gAdapterInfoPlatformTestPointGuid)) { + AipCandidate = Aip; + break; + } + } + FreePool (InfoTypesBuffer); + + if (AipCandidate == NULL) { + continue; + } + + // + // Check Role + // + Aip = AipCandidate; + Status = Aip->GetInformation ( + Aip, + &gAdapterInfoPlatformTestPointGuid, + &InformationBlock, + &InformationBlockSize + ); + if (EFI_ERROR (Status)) { + continue; + } + + TestPoint = InformationBlock; + if ((TestPoint->Role == Role) && + ((ImplementationID == NULL) || (StrCmp (ImplementationID, TestPoint->ImplementationID) == 0))) { + break; + } else { + TestPoint = NULL; + FreePool (InformationBlock); + continue; + } + } + FreePool (Handles); + + if (TestPoint == NULL) { + return NULL; + } + + if (TestPointData != NULL) { + *TestPointData = InformationBlock; + } + if (TestPointSize != NULL) { + *TestPointSize = InformationBlockSize; + } + return Aip; +} + +/** + Return if input TestPoint data is valid. + + @param TestPointData TestPoint data + @param TestPointSize TestPoint size + + @retval TRUE TestPoint data is valid. + @retval FALSE TestPoint data is not valid. +**/ +BOOLEAN +InternalTestPointIsValidTable ( + IN VOID *TestPointData, + IN UINTN TestPointSize + ) +{ + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN Index; + CHAR16 *ErrorString; + CHAR16 ErrorChar; + UINTN ErrorStringSize; + UINTN ErrorStringLength; + + TestPoint = TestPointData; + + // + // basic check for header + // + if (TestPointData == NULL) { + DEBUG ((EFI_D_ERROR, "TestPointData == NULL\n")); + return FALSE; + } + if (TestPointSize < sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)) { + DEBUG ((EFI_D_ERROR, "TestPointSize < sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)\n")); + return FALSE; + } + if (((TestPointSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)) / 3) < TestPoint->FeaturesSize) { + DEBUG ((EFI_D_ERROR, "((TestPointSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT)) / 3) < FeaturesSize\n")); + return FALSE; + } + + // + // Check Version + // + if (TestPoint->Version != PLATFORM_TEST_POINT_VERSION) { + DEBUG ((EFI_D_ERROR, "Version != PLATFORM_TEST_POINT_VERSION\n")); + return FALSE; + } + + // + // Check Role + // + if ((TestPoint->Role < PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE) || + (TestPoint->Role > PLATFORM_TEST_POINT_ROLE_IMPLEMENTOR_ODM)) { + DEBUG ((EFI_D_ERROR, "Role < PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE ||\n")); + DEBUG ((EFI_D_ERROR, "Role > PLATFORM_TEST_POINT_ROLE_IMPLEMENTOR_ODM\n")); + return FALSE; + } + + // + // Check ImplementationID + // + for (Index = 0; Index < sizeof(TestPoint->ImplementationID)/sizeof(TestPoint->ImplementationID[0]); Index++) { + if (TestPoint->ImplementationID[Index] == 0) { + break; + } + } + if (Index == sizeof(TestPoint->ImplementationID)/sizeof(TestPoint->ImplementationID[0])) { + DEBUG ((EFI_D_ERROR, "ImplementationID is no NUL CHAR\n")); + return FALSE; + } + + ErrorStringSize = TestPointSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) - TestPoint->FeaturesSize * 3; + ErrorString = (CHAR16 *)((UINTN)TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) - TestPoint->FeaturesSize * 3); + + // + // basic check for ErrorString + // + if (ErrorStringSize == 0) { + DEBUG ((EFI_D_ERROR, "ErrorStringSize == 0\n")); + return FALSE; + } + if ((ErrorStringSize & BIT0) != 0) { + DEBUG ((EFI_D_ERROR, "(ErrorStringSize & BIT0) != 0\n")); + return FALSE; + } + + // + // ErrorString might not be CHAR16 aligned. + // + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + for (ErrorStringLength = 0; (ErrorChar != 0) && (ErrorStringLength < (ErrorStringSize/2)); ErrorStringLength++) { + ErrorString++; + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + } + + // + // check the length of ErrorString + // + if (ErrorChar != 0) { + DEBUG ((EFI_D_ERROR, "ErrorString has no NUL CHAR\n")); + return FALSE; + } + if (ErrorStringLength == (ErrorStringSize/2)) { + DEBUG ((EFI_D_ERROR, "ErrorString Length incorrect\n")); + return FALSE; + } + + return TRUE; +} + +/** + Publish TestPoint table in AIP protocol. + + One system should have only one PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE. + + If the Role is NOT PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE, + FeaturesRequired field will be ignored. + + @param TestPoint TestPoint data + @param TestPointSize TestPoint size + + @retval EFI_SUCCESS The TestPoint data is published in AIP protocol. + @retval EFI_ALREADY_STARTED There is already TestPoint table with Role and ImplementationID published in system. + @retval EFI_VOLUME_CORRUPTED The input TestPoint data is invalid. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish TestPoint data in AIP protocol. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetTable ( + IN VOID *TestPoint, + IN UINTN TestPointSize + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + TEST_POINT_AIP_PRIVATE_DATA *TestPointAip; + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + UINT32 Role; + CHAR16 *ImplementationID; + UINT32 FeaturesSize; + UINT8 *FeaturesRequired; + + if (!InternalTestPointIsValidTable (TestPoint, TestPointSize)) { + return EFI_VOLUME_CORRUPTED; + } + + Role = ((ADAPTER_INFO_PLATFORM_TEST_POINT *)TestPoint)->Role; + ImplementationID = ((ADAPTER_INFO_PLATFORM_TEST_POINT *)TestPoint)->ImplementationID; + Aip = InternalTestPointFindAip (Role, ImplementationID, NULL, NULL); + if (Aip != NULL) { + return EFI_ALREADY_STARTED; + } + + TestPointAip = AllocateZeroPool (sizeof(TEST_POINT_AIP_PRIVATE_DATA)); + if (TestPointAip == NULL) { + return EFI_OUT_OF_RESOURCES; + } + TestPointAip->TestPoint = AllocateCopyPool (TestPointSize, TestPoint); + if (TestPointAip->TestPoint == NULL) { + FreePool (TestPointAip); + return EFI_OUT_OF_RESOURCES; + } + if (Role != PLATFORM_TEST_POINT_ROLE_PLATFORM_REFERENCE) { + FeaturesRequired = (UINT8 *)TestPointAip->TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT); + FeaturesSize = ((ADAPTER_INFO_PLATFORM_TEST_POINT *)TestPoint)->FeaturesSize; + ZeroMem (FeaturesRequired, FeaturesSize); + } + + TestPointAip->Signature = TEST_POINT_AIP_PRIVATE_SIGNATURE; + CopyMem (&TestPointAip->Aip, &mAdapterInformationProtocol, sizeof(EFI_ADAPTER_INFORMATION_PROTOCOL)); + TestPointAip->TestPointSize = TestPointSize; + TestPointAip->TestPointMaxSize = TestPointSize; + + Handle = NULL; + Status = gSmst->SmmInstallProtocolInterface ( + &Handle, + &gEfiAdapterInformationProtocolGuid, + EFI_NATIVE_INTERFACE, + &TestPointAip->Aip + ); + if (EFI_ERROR (Status)) { + FreePool (TestPointAip->TestPoint); + FreePool (TestPointAip); + } + + if (!EFI_ERROR(Status)) { + RegisterSmmTestPointSmiHandler (); + } + + return Status; +} + +/** + Search TestPoint table in AIP protocol, and return the data. + This API will return the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param TestPoint TestPoint data. This buffer is allocated by callee, and it + is the responsibility of the caller to free it after + using it. + @param TestPointSize TestPoint size + + @retval EFI_SUCCESS The TestPoint data in AIP protocol is returned. + @retval EFI_NOT_FOUND There is not TestPoint table with the Role and ImplementationID published in system. +**/ +EFI_STATUS +EFIAPI +TestPointLibGetTable ( + IN UINT32 Role, + IN CHAR16 *ImplementationID OPTIONAL, + OUT VOID **TestPoint, + OUT UINTN *TestPointSize + ) +{ + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + + Aip = InternalTestPointFindAip (Role, ImplementationID, TestPoint, TestPointSize); + if (Aip == NULL) { + return EFI_NOT_FOUND; + } + return EFI_SUCCESS; +} + +/** + Record FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + @param Set TRUE means to set the FeaturesVerified bit. + FALSE means to clear the FeaturesVerified bit. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +InternalTestPointRecordFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 Bit, + IN BOOLEAN Set + ) +{ + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN TestPointSize; + UINT8 *FeaturesVerified; + EFI_STATUS Status; + + Aip = InternalTestPointFindAip (Role, ImplementationID, (VOID **)&TestPoint, &TestPointSize); + if (Aip == NULL) { + return EFI_NOT_STARTED; + } + + if (ByteIndex >= TestPoint->FeaturesSize) { + return EFI_UNSUPPORTED; + } + + FeaturesVerified = (UINT8 *)((UINTN)TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + TestPoint->FeaturesSize * 2); + + if (Set) { + FeaturesVerified[ByteIndex] = (UINT8)(FeaturesVerified[ByteIndex] | (Bit)); + } else { + FeaturesVerified[ByteIndex] = (UINT8)(FeaturesVerified[ByteIndex] & (~Bit)); + } + + Status = Aip->SetInformation ( + Aip, + &gAdapterInfoPlatformTestPointGuid, + TestPoint, + TestPointSize + ); + return Status; +} + +/** + Set FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 BitMask + ) +{ + return InternalTestPointRecordFeaturesVerified ( + Role, + ImplementationID, + ByteIndex, + BitMask, + TRUE + ); +} + +/** + Clear FeaturesVerified in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ByteIndex Byte index of FeaturesVerified of TestPoint data. + @param BitMask Bit mask of FeaturesVerified of TestPoint data. + + @retval EFI_SUCCESS The FeaturesVerified of TestPoint data updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_UNSUPPORTED The ByteIndex is invalid. +**/ +EFI_STATUS +EFIAPI +TestPointLibClearFeaturesVerified ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN UINT32 ByteIndex, + IN UINT8 BitMask + ) +{ + return InternalTestPointRecordFeaturesVerified ( + Role, + ImplementationID, + ByteIndex, + BitMask, + FALSE + ); +} + +/** + Record ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + @param Append TRUE means to append the ErrorString to TestPoint table. + FALSE means to set the ErrorString in TestPoint table. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is published in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +InternalTestPointRecordErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString, + IN BOOLEAN Append + ) +{ + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN TestPointSize; + UINTN StringSize; + VOID *NewTestPoint; + UINTN NewTestPointSize; + UINTN Offset; + EFI_STATUS Status; + + Aip = InternalTestPointFindAip (Role, ImplementationID, (VOID **)&TestPoint, &TestPointSize); + if (Aip == NULL) { + return EFI_NOT_STARTED; + } + + if (Append) { + Offset = TestPointSize - sizeof(CHAR16); + } else { + Offset = sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + TestPoint->FeaturesSize * 3; + } + StringSize = StrSize (ErrorString); + + NewTestPointSize = Offset + StringSize; + NewTestPoint = AllocatePool (NewTestPointSize); + if (NewTestPoint == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem (NewTestPoint, TestPoint, Offset); + CopyMem ((UINT8 *)NewTestPoint + Offset, ErrorString, StringSize); + + Status = Aip->SetInformation ( + Aip, + &gAdapterInfoPlatformTestPointGuid, + NewTestPoint, + NewTestPointSize + ); + return Status; +} + +/** + Append ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +EFIAPI +TestPointLibAppendErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString + ) +{ + DEBUG ((DEBUG_ERROR, "TestPointLibAppendErrorString - (0x%x) %s\n", Role, ErrorString)); + return InternalTestPointRecordErrorString ( + Role, + ImplementationID, + ErrorString, + TRUE + ); +} + +/** + Set a new ErrorString in published TestPoint table. + This API will update the TestPoint table with indicated Role and ImplementationID, + NULL ImplementationID means to find the first TestPoint table with indicated Role. + + @param Role Role of TestPoint data. + @param ImplementationID ImplementationID of TestPoint data. + NULL means find the first one match Role. + @param ErrorString ErrorString of TestPoint data. + + @retval EFI_SUCCESS The ErrorString of TestPoint data is updated in AIP protocol. + @retval EFI_NOT_STARTED There is not TestPoint table with the Role and ImplementationID published in system. + @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString. +**/ +EFI_STATUS +EFIAPI +TestPointLibSetErrorString ( + IN UINT32 Role, + IN CHAR16 *ImplementationID, OPTIONAL + IN CHAR16 *ErrorString + ) +{ + DEBUG ((DEBUG_ERROR, "TestPointLibSetErrorString - %s\n", ErrorString)); + return InternalTestPointRecordErrorString ( + Role, + ImplementationID, + ErrorString, + FALSE + ); +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPoint.h b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPoint.h new file mode 100644 index 0000000000..4a7429f569 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPoint.h @@ -0,0 +1,71 @@ +/** @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 + which 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. + +**/ + +#ifndef _SMM_TEST_POINT_DXE_H_ +#define _SMM_TEST_POINT_DXE_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define TEST_POINT_AIP_PRIVATE_SIGNATURE SIGNATURE_32('T', 'S', 'P', 'T') + +typedef struct { + UINT32 Signature; + EFI_ADAPTER_INFORMATION_PROTOCOL Aip; + VOID *TestPoint; + UINTN TestPointSize; + UINTN TestPointMaxSize; +} TEST_POINT_AIP_PRIVATE_DATA; + +#define TEST_POINT_AIP_PRIVATE_DATA_FROM_THIS(a) \ + CR (a, \ + TEST_POINT_AIP_PRIVATE_DATA, \ + Aip, \ + TEST_POINT_AIP_PRIVATE_SIGNATURE \ + ) + +extern EFI_ADAPTER_INFORMATION_PROTOCOL mAdapterInformationProtocol; + +/** + Return if input TestPoint data is valid. + + @param TestPointData TestPoint data + @param TestPointSize TestPoint size + + @retval TRUE TestPoint data is valid. + @retval FALSE TestPoint data is not valid. +**/ +BOOLEAN +InternalTestPointIsValidTable ( + IN VOID *TestPointData, + IN UINTN TestPointSize + ); + +/** + Register SMM TestPoint handler. +**/ +VOID +RegisterSmmTestPointSmiHandler ( + VOID + ); + +#endif \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointAip.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointAip.c new file mode 100644 index 0000000000..11aea2c91f --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointAip.c @@ -0,0 +1,175 @@ +/** @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 + which 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 "SmmTestPoint.h" + +/** + Returns the current state information for the adapter. + + This function returns information of type InformationType from the adapter. + If an adapter does not support the requested informational type, then + EFI_UNSUPPORTED is returned. + + @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance. + @param[in] InformationType A pointer to an EFI_GUID that defines the contents of InformationBlock. + @param[out] InformationBlock The service returns a pointer to the buffer with the InformationBlock + structure which contains details about the data specific to InformationType. + @param[out] InformationBlockSize The driver returns the size of the InformationBlock in bytes. + + @retval EFI_SUCCESS The InformationType information was retrieved. + @retval EFI_UNSUPPORTED The InformationType is not known. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_INVALID_PARAMETER InformationBlock is NULL. + @retval EFI_INVALID_PARAMETER InformationBlockSize is NULL. + +**/ +EFI_STATUS +EFIAPI +TestPointAipGetInfo ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + IN EFI_GUID *InformationType, + OUT VOID **InformationBlock, + OUT UINTN *InformationBlockSize + ) +{ + TEST_POINT_AIP_PRIVATE_DATA *TestPointAip; + + if ((This == NULL) || (InformationBlock == NULL) || (InformationBlockSize == NULL)) { + return EFI_INVALID_PARAMETER; + } + if (!CompareGuid (InformationType, &gAdapterInfoPlatformTestPointGuid)) { + return EFI_UNSUPPORTED; + } + + TestPointAip = TEST_POINT_AIP_PRIVATE_DATA_FROM_THIS(This); + + *InformationBlock = AllocateCopyPool (TestPointAip->TestPointSize, TestPointAip->TestPoint); + if (*InformationBlock == NULL) { + return EFI_OUT_OF_RESOURCES; + } + *InformationBlockSize = TestPointAip->TestPointSize; + return EFI_SUCCESS; +} + +/** + Sets state information for an adapter. + + This function sends information of type InformationType for an adapter. + If an adapter does not support the requested information type, then EFI_UNSUPPORTED + is returned. + + @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance. + @param[in] InformationType A pointer to an EFI_GUID that defines the contents of InformationBlock. + @param[in] InformationBlock A pointer to the InformationBlock structure which contains details + about the data specific to InformationType. + @param[in] InformationBlockSize The size of the InformationBlock in bytes. + + @retval EFI_SUCCESS The information was received and interpreted successfully. + @retval EFI_UNSUPPORTED The InformationType is not known. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_INVALID_PARAMETER InformationBlock is NULL. + @retval EFI_WRITE_PROTECTED The InformationType cannot be modified using EFI_ADAPTER_INFO_SET_INFO(). + +**/ +EFI_STATUS +EFIAPI +TestPointAipSetInfo ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN VOID *InformationBlock, + IN UINTN InformationBlockSize + ) +{ + TEST_POINT_AIP_PRIVATE_DATA *TestPointAip; + VOID *NewTestPoint; + + if ((This == NULL) || (InformationBlock == NULL)) { + return EFI_INVALID_PARAMETER; + } + if (!CompareGuid (InformationType, &gAdapterInfoPlatformTestPointGuid)) { + return EFI_UNSUPPORTED; + } + + if (!InternalTestPointIsValidTable (InformationBlock, InformationBlockSize)) { + return EFI_VOLUME_CORRUPTED; + } + + TestPointAip = TEST_POINT_AIP_PRIVATE_DATA_FROM_THIS(This); + + if (InformationBlockSize > TestPointAip->TestPointMaxSize) { + NewTestPoint = AllocateZeroPool (InformationBlockSize); + if (NewTestPoint == NULL) { + return EFI_OUT_OF_RESOURCES; + } + FreePool (TestPointAip->TestPoint); + TestPointAip->TestPoint = NewTestPoint; + TestPointAip->TestPointSize = 0; + TestPointAip->TestPointMaxSize = InformationBlockSize; + } + + CopyMem (TestPointAip->TestPoint, InformationBlock, InformationBlockSize); + TestPointAip->TestPointSize = InformationBlockSize; + return EFI_SUCCESS; +} + +/** + Get a list of supported information types for this instance of the protocol. + + This function returns a list of InformationType GUIDs that are supported on an + adapter with this instance of EFI_ADAPTER_INFORMATION_PROTOCOL. The list is returned + in InfoTypesBuffer, and the number of GUID pointers in InfoTypesBuffer is returned in + InfoTypesBufferCount. + + @param[in] This A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance. + @param[out] InfoTypesBuffer A pointer to the array of InformationType GUIDs that are supported + by This. + @param[out] InfoTypesBufferCount A pointer to the number of GUIDs present in InfoTypesBuffer. + + @retval EFI_SUCCESS The list of information type GUIDs that are supported on this adapter was + returned in InfoTypesBuffer. The number of information type GUIDs was + returned in InfoTypesBufferCount. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_INVALID_PARAMETER InfoTypesBuffer is NULL. + @retval EFI_INVALID_PARAMETER InfoTypesBufferCount is NULL. + @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the results. + +**/ +EFI_STATUS +EFIAPI +TestPointAipGetSupportedTypes ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + OUT EFI_GUID **InfoTypesBuffer, + OUT UINTN *InfoTypesBufferCount + ) +{ + if ((This == NULL) || (InfoTypesBuffer == NULL) || (InfoTypesBufferCount == NULL)) { + return EFI_INVALID_PARAMETER; + } + + *InfoTypesBuffer = AllocateCopyPool (sizeof(gAdapterInfoPlatformTestPointGuid), &gAdapterInfoPlatformTestPointGuid); + if (*InfoTypesBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + *InfoTypesBufferCount = 1; + + return EFI_SUCCESS; +} + +EFI_ADAPTER_INFORMATION_PROTOCOL mAdapterInformationProtocol = { + TestPointAipGetInfo, + TestPointAipSetInfo, + TestPointAipGetSupportedTypes, +}; diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointCommunication.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointCommunication.c new file mode 100644 index 0000000000..e6fb7bea0e --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointCommunication.c @@ -0,0 +1,379 @@ +/** @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 + which 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 "SmmTestPoint.h" + +EFI_STATUS +GetAllSmmTestPointData ( + IN OUT UINTN *DataSize, + IN OUT VOID *Data + ) +{ + EFI_STATUS Status; + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + UINTN NoHandles; + EFI_HANDLE *Handles; + UINTN HandleBufSize; + UINTN Index; + EFI_GUID *InfoTypesBuffer; + UINTN InfoTypesBufferCount; + UINTN InfoTypesIndex; + EFI_ADAPTER_INFORMATION_PROTOCOL *AipCandidate; + VOID *InformationBlock; + UINTN InformationBlockSize; + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN TotalSize; + EFI_STATUS RetStatus; + + TotalSize = 0; + + Handles = NULL; + HandleBufSize = 0; + Status = gSmst->SmmLocateHandle ( + ByProtocol, + &gEfiAdapterInformationProtocolGuid, + NULL, + &HandleBufSize, + Handles + ); + if (Status != EFI_BUFFER_TOO_SMALL) { + RetStatus = EFI_NOT_FOUND; + goto Done ; + } + Handles = AllocateZeroPool (HandleBufSize); + if (Handles == NULL) { + RetStatus = EFI_OUT_OF_RESOURCES; + goto Done ; + } + Status = gSmst->SmmLocateHandle ( + ByProtocol, + &gEfiAdapterInformationProtocolGuid, + NULL, + &HandleBufSize, + Handles + ); + if (EFI_ERROR (Status)) { + RetStatus = Status; + goto Done ; + } + NoHandles = HandleBufSize / sizeof(EFI_HANDLE); + + RetStatus = EFI_SUCCESS; + + TestPoint = NULL; + Aip = NULL; + InformationBlock = NULL; + InformationBlockSize = 0; + for (Index = 0; Index < NoHandles; Index++) { + Status = gSmst->SmmHandleProtocol ( + Handles[Index], + &gEfiAdapterInformationProtocolGuid, + (VOID **)&Aip + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Check AIP + // + Status = Aip->GetSupportedTypes ( + Aip, + &InfoTypesBuffer, + &InfoTypesBufferCount + ); + if (EFI_ERROR (Status)) { + continue; + } + + AipCandidate = NULL; + for (InfoTypesIndex = 0; InfoTypesIndex < InfoTypesBufferCount; InfoTypesIndex++) { + if (CompareGuid (&InfoTypesBuffer[InfoTypesIndex], &gAdapterInfoPlatformTestPointGuid)) { + AipCandidate = Aip; + break; + } + } + FreePool (InfoTypesBuffer); + + if (AipCandidate == NULL) { + continue; + } + + // + // Check Role + // + Aip = AipCandidate; + Status = Aip->GetInformation ( + Aip, + &gAdapterInfoPlatformTestPointGuid, + &InformationBlock, + &InformationBlockSize + ); + if (EFI_ERROR (Status)) { + continue; + } + + if ((Data != NULL) && (TotalSize + InformationBlockSize <= *DataSize)) { + CopyMem ((UINT8 *)Data + TotalSize, InformationBlock, InformationBlockSize); + } else { + RetStatus = EFI_BUFFER_TOO_SMALL; + } + TotalSize += InformationBlockSize; + + FreePool (InformationBlock); + } + +Done: + + *DataSize = TotalSize; + + if (Handles != NULL) { + FreePool (Handles); + } + + return RetStatus; +} + +/** + SMM test point SMI handler to get info. + + @param SmiHandlerTestPointParameterGetInfo The parameter of SMM test point SMI handler get info. + +**/ +VOID +SmmTestPointSmiHandlerGetInfo ( + IN SMI_HANDLER_TEST_POINT_PARAMETER_GET_INFO *SmiHandlerTestPointParameterGetInfo + ) +{ + UINTN DataSize; + EFI_STATUS Status; + + DataSize = 0; + Status = GetAllSmmTestPointData (&DataSize, NULL); + if (Status == EFI_BUFFER_TOO_SMALL) { + SmiHandlerTestPointParameterGetInfo->DataSize = DataSize; + SmiHandlerTestPointParameterGetInfo->Header.ReturnStatus = 0; + } else { + SmiHandlerTestPointParameterGetInfo->DataSize = 0; + SmiHandlerTestPointParameterGetInfo->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_NOT_FOUND; + } +} + +/** + Copy SMM Test Point data. + + @param DataBuffer The buffer to hold SMM Test Point data. + @param DataSize On input, data buffer size. + On output, actual data buffer size copied. + @param DataOffset On input, data buffer offset to copy. + On output, next time data buffer offset to copy. + +**/ +VOID +SmiHandlerTestPointCopyData ( + IN VOID *InputData, + IN UINTN InputDataSize, + OUT VOID *DataBuffer, + IN OUT UINT64 *DataSize, + IN OUT UINT64 *DataOffset + ) +{ + if (*DataOffset >= InputDataSize) { + *DataOffset = InputDataSize; + return; + } + if (InputDataSize - *DataOffset < *DataSize) { + *DataSize = InputDataSize - *DataOffset; + } + + CopyMem( + DataBuffer, + (UINT8 *)InputData + *DataOffset, + (UINTN)*DataSize + ); + *DataOffset = *DataOffset + *DataSize; +} + +/** + SMM test point SMI handler to get data by offset. + + @param SmiHandlerTestPointParameterGetDataByOffset The parameter of SMM test point SMI handler get data by offset. + +**/ +VOID +SmmTestPointSmiHandlerGetDataByOffset ( + IN SMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *SmiHandlerTestPointParameterGetDataByOffset + ) +{ + SMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET SmiHandlerTestPointGetDataByOffset; + VOID *Data; + UINTN DataSize; + EFI_STATUS Status; + + Data = NULL; + + CopyMem ( + &SmiHandlerTestPointGetDataByOffset, + SmiHandlerTestPointParameterGetDataByOffset, + sizeof(SmiHandlerTestPointGetDataByOffset) + ); + + // + // Sanity check + // + if (!SmmIsBufferOutsideSmmValid((UINTN)SmiHandlerTestPointGetDataByOffset.DataBuffer, (UINTN)SmiHandlerTestPointGetDataByOffset.DataSize)) { + DEBUG((DEBUG_ERROR, "SmmTestPointSmiHandlerGetDataByOffset: SmmTestPoint get data in SMRAM or overflow!\n")); + SmiHandlerTestPointParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_ACCESS_DENIED; + goto Done; + } + + DataSize = 0; + Status = GetAllSmmTestPointData (&DataSize, NULL); + if (Status != EFI_BUFFER_TOO_SMALL) { + SmiHandlerTestPointParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_NOT_FOUND; + goto Done; + } + Data = AllocatePool (DataSize); + if (Data == NULL) { + SmiHandlerTestPointParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_OUT_OF_RESOURCES; + goto Done; + } + Status = GetAllSmmTestPointData (&DataSize, Data); + if (EFI_ERROR(Status)) { + SmiHandlerTestPointParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)Status; + goto Done; + } + + SmiHandlerTestPointCopyData ( + Data, + DataSize, + (VOID *)(UINTN)SmiHandlerTestPointGetDataByOffset.DataBuffer, + &SmiHandlerTestPointGetDataByOffset.DataSize, + &SmiHandlerTestPointGetDataByOffset.DataOffset + ); + + CopyMem ( + SmiHandlerTestPointParameterGetDataByOffset, + &SmiHandlerTestPointGetDataByOffset, + sizeof(SmiHandlerTestPointGetDataByOffset) + ); + + SmiHandlerTestPointParameterGetDataByOffset->Header.ReturnStatus = 0; + +Done: + if (Data != NULL) { + FreePool (Data); + } +} + +/** + Dispatch function for a Software SMI handler. + + Caution: This function may receive untrusted input. + Communicate buffer and buffer size are external input, so this function will do basic validation. + + @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister(). + @param Context Points to an optional handler context which was specified when the + handler was registered. + @param CommBuffer A pointer to a collection of data in memory that will + be conveyed from a non-SMM environment into an SMM environment. + @param CommBufferSize The size of the CommBuffer. + + @retval EFI_SUCCESS Command is handled successfully. +**/ +EFI_STATUS +EFIAPI +SmmTestPointSmiHandler ( + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL + ) +{ + SMI_HANDLER_TEST_POINT_PARAMETER_HEADER *SmiHandlerTestPointParameterHeader; + UINTN TempCommBufferSize; + + DEBUG((DEBUG_ERROR, "SmmTestPointSmiHandler Enter\n")); + + // + // If input is invalid, stop processing this SMI + // + if (CommBuffer == NULL || CommBufferSize == NULL) { + return EFI_SUCCESS; + } + + TempCommBufferSize = *CommBufferSize; + + if (TempCommBufferSize < sizeof(SMI_HANDLER_TEST_POINT_PARAMETER_HEADER)) { + DEBUG((DEBUG_ERROR, "SmmTestPointSmiHandler: SMM communication buffer size invalid!\n")); + return EFI_SUCCESS; + } + + if (!SmmIsBufferOutsideSmmValid((UINTN)CommBuffer, TempCommBufferSize)) { + DEBUG((DEBUG_ERROR, "SmmTestPointSmiHandler: SMM communication buffer in SMRAM or overflow!\n")); + return EFI_SUCCESS; + } + + SmiHandlerTestPointParameterHeader = (SMI_HANDLER_TEST_POINT_PARAMETER_HEADER *)((UINTN)CommBuffer); + SmiHandlerTestPointParameterHeader->ReturnStatus = (UINT64)-1; + + switch (SmiHandlerTestPointParameterHeader->Command) { + case SMI_HANDLER_TEST_POINT_COMMAND_GET_INFO: + DEBUG((DEBUG_ERROR, "SmiHandlerTestPointHandlerGetInfo\n")); + if (TempCommBufferSize != sizeof(SMI_HANDLER_TEST_POINT_PARAMETER_GET_INFO)) { + DEBUG((DEBUG_ERROR, "SmmTestPointSmiHandler: SMM communication buffer size invalid!\n")); + return EFI_SUCCESS; + } + SmmTestPointSmiHandlerGetInfo((SMI_HANDLER_TEST_POINT_PARAMETER_GET_INFO *)(UINTN)CommBuffer); + break; + case SMI_HANDLER_TEST_POINT_COMMAND_GET_DATA_BY_OFFSET: + DEBUG((DEBUG_ERROR, "SmiHandlerTestPointHandlerGetDataByOffset\n")); + if (TempCommBufferSize != sizeof(SMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET)) { + DEBUG((DEBUG_ERROR, "SmmTestPointSmiHandler: SMM communication buffer size invalid!\n")); + return EFI_SUCCESS; + } + SmmTestPointSmiHandlerGetDataByOffset((SMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *)(UINTN)CommBuffer); + break; + default: + break; + } + + DEBUG((DEBUG_ERROR, "SmmTestPointSmiHandler Exit\n")); + + return EFI_SUCCESS; +} + +/** + Register SMM TestPoint handler. +**/ +VOID +RegisterSmmTestPointSmiHandler ( + VOID + ) +{ + EFI_HANDLE DispatchHandle; + EFI_STATUS Status; + STATIC BOOLEAN Registered = FALSE; + + if (Registered) { + return ; + } + + Status = gSmst->SmiHandlerRegister ( + SmmTestPointSmiHandler, + &gAdapterInfoPlatformTestPointGuid, + &DispatchHandle + ); + ASSERT_EFI_ERROR (Status); + Registered = TRUE; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointLib.inf b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointLib.inf new file mode 100644 index 0000000000..4a03657d4f --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointLib/SmmTestPointLib.inf @@ -0,0 +1,50 @@ +## @file +# SMM instance of TestPoint Library. +# +# 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 +# which 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SmmTestPointLib + FILE_GUID = 221290AE-AB4C-4FE1-B4C3-43A43BE13645 + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = TestPointLib + +[Sources] + SmmTestPointCommunication.c + SmmTestPointAip.c + SmmTestPoint.c + SmmTestPoint.h + +[Packages] + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + MemoryAllocationLib + DebugLib + SmmServicesTableLib + SmmMemLib + +[Guids] +## SOMETIMES_PRODUCES ## GUID +## SOMETIMES_CONSUMES ## GUID + gAdapterInfoPlatformTestPointGuid + +[Protocols] +## SOMETIMES_PRODUCES +## SOMETIMES_CONSUMES + gEfiAdapterInformationProtocolGuid + diff --git a/Platform/Intel/MinPlatformPkg/Test/TestPointDumpApp/TestPointDump.c b/Platform/Intel/MinPlatformPkg/Test/TestPointDumpApp/TestPointDump.c new file mode 100644 index 0000000000..e35ae95222 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/TestPointDumpApp/TestPointDump.c @@ -0,0 +1,412 @@ +/** @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 +which 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 + +VOID +DumpTestPoint ( + IN VOID *TestPointData + ) +{ + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINT8 *Features; + CHAR16 *ErrorString; + UINTN Index; + CHAR16 ErrorChar; + + TestPoint = TestPointData; + Print (L"TestPoint\n"); + Print (L" Version - 0x%08x\n", TestPoint->Version); + Print (L" Role - 0x%08x\n", TestPoint->Role); + Print (L" ImplementationID - %S\n", TestPoint->ImplementationID); + Print (L" FeaturesSize - 0x%08x\n", TestPoint->FeaturesSize); + + Features = (UINT8 *)(TestPoint + 1); + Print (L" FeaturesRequired - "); + for (Index = 0; Index < TestPoint->FeaturesSize; Index++) { + Print (L"%02x ", Features[Index]); + } + Print (L"\n"); + + Features = (UINT8 *)(Features + TestPoint->FeaturesSize); + Print (L" FeaturesImplemented - "); + for (Index = 0; Index < TestPoint->FeaturesSize; Index++) { + Print (L"%02x ", Features[Index]); + } + Print (L"\n"); + + Features = (UINT8 *)(Features + TestPoint->FeaturesSize); + Print (L" FeaturesVerified - "); + for (Index = 0; Index < TestPoint->FeaturesSize; Index++) { + Print (L"%02x ", Features[Index]); + } + Print (L"\n"); + + ErrorString = (CHAR16 *)(Features + TestPoint->FeaturesSize); + Print (L" ErrorString - \""); + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + for (; ErrorChar != 0;) { + if (ErrorChar == L'\r') { + Print (L"\\r"); + } else if (ErrorChar == L'\n') { + Print (L"\\n"); + } else { + Print (L"%c", ErrorChar); + } + ErrorString++; + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + } + Print (L"\"\n"); +} + +VOID +DumpTestPointDataPei ( + IN UINT32 Role OPTIONAL, + IN CHAR16 *ImplementationID OPTIONAL + ) +{ + EFI_PEI_HOB_POINTERS Hob; + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + + Hob.Raw = GetHobList (); + while (TRUE) { + Hob.Raw = GetNextGuidHob (&gAdapterInfoPlatformTestPointGuid, Hob.Raw); + if (Hob.Raw == NULL) { + return ; + } + TestPoint = GET_GUID_HOB_DATA (Hob); + + if ((Role == 0) || + ((TestPoint->Role == Role) && + ((ImplementationID == NULL) || (StrCmp (ImplementationID, TestPoint->ImplementationID) == 0)))) { + DumpTestPoint (TestPoint); + } + Hob.Raw = GET_NEXT_HOB (Hob); + if (Hob.Raw == NULL) { + return ; + } + } +} + +VOID +DumpTestPointDataDxe ( + IN UINT32 Role OPTIONAL, + IN CHAR16 *ImplementationID OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + UINTN NoHandles; + EFI_HANDLE *Handles; + UINTN Index; + EFI_GUID *InfoTypesBuffer; + UINTN InfoTypesBufferCount; + UINTN InfoTypesIndex; + EFI_ADAPTER_INFORMATION_PROTOCOL *AipCandidate; + VOID *InformationBlock; + UINTN InformationBlockSize; + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiAdapterInformationProtocolGuid, + NULL, + &NoHandles, + &Handles + ); + if (EFI_ERROR (Status)) { + return ; + } + + TestPoint = NULL; + Aip = NULL; + InformationBlock = NULL; + InformationBlockSize = 0; + for (Index = 0; Index < NoHandles; Index++) { + Status = gBS->HandleProtocol ( + Handles[Index], + &gEfiAdapterInformationProtocolGuid, + (VOID **)&Aip + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Check AIP + // + Status = Aip->GetSupportedTypes ( + Aip, + &InfoTypesBuffer, + &InfoTypesBufferCount + ); + if (EFI_ERROR (Status)) { + continue; + } + + AipCandidate = NULL; + for (InfoTypesIndex = 0; InfoTypesIndex < InfoTypesBufferCount; InfoTypesIndex++) { + if (CompareGuid (&InfoTypesBuffer[InfoTypesIndex], &gAdapterInfoPlatformTestPointGuid)) { + AipCandidate = Aip; + break; + } + } + FreePool (InfoTypesBuffer); + + if (AipCandidate == NULL) { + continue; + } + + // + // Check Role + // + Aip = AipCandidate; + Status = Aip->GetInformation ( + Aip, + &gAdapterInfoPlatformTestPointGuid, + &InformationBlock, + &InformationBlockSize + ); + if (EFI_ERROR (Status)) { + continue; + } + + TestPoint = InformationBlock; + + if ((Role == 0) || + ((TestPoint->Role == Role) && + ((ImplementationID == NULL) || (StrCmp (ImplementationID, TestPoint->ImplementationID) == 0)))) { + DumpTestPoint (TestPoint); + } + FreePool (InformationBlock); + } + FreePool (Handles); +} + +UINTN mSmmTestPointDatabaseSize; +VOID *mSmmTestPointDatabase; + +VOID +GetTestPointDataSmm ( + VOID + ) +{ + EFI_STATUS Status; + UINTN CommSize; + UINT8 *CommBuffer; + EFI_SMM_COMMUNICATE_HEADER *CommHeader; + SMI_HANDLER_TEST_POINT_PARAMETER_GET_INFO *CommGetInfo; + SMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *CommGetData; + EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; + UINTN MinimalSizeNeeded; + EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable; + UINT32 Index; + EFI_MEMORY_DESCRIPTOR *Entry; + VOID *Buffer; + UINTN Size; + UINTN Offset; + + Status = gBS->LocateProtocol(&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **)&SmmCommunication); + if (EFI_ERROR(Status)) { + Print(L"SmiHandlerTestPoint: Locate SmmCommunication protocol - %r\n", Status); + return ; + } + + MinimalSizeNeeded = EFI_PAGE_SIZE; + + Status = EfiGetSystemConfigurationTable( + &gEdkiiPiSmmCommunicationRegionTableGuid, + (VOID **)&PiSmmCommunicationRegionTable + ); + if (EFI_ERROR(Status)) { + Print(L"SmiHandlerTestPoint: Get PiSmmCommunicationRegionTable - %r\n", Status); + return ; + } + ASSERT(PiSmmCommunicationRegionTable != NULL); + Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1); + Size = 0; + for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) { + if (Entry->Type == EfiConventionalMemory) { + Size = EFI_PAGES_TO_SIZE((UINTN)Entry->NumberOfPages); + if (Size >= MinimalSizeNeeded) { + break; + } + } + Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize); + } + ASSERT(Index < PiSmmCommunicationRegionTable->NumberOfEntries); + CommBuffer = (UINT8 *)(UINTN)Entry->PhysicalStart; + + // + // Get Size + // + CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; + CopyMem(&CommHeader->HeaderGuid, &gAdapterInfoPlatformTestPointGuid, sizeof(gAdapterInfoPlatformTestPointGuid)); + CommHeader->MessageLength = sizeof(SMI_HANDLER_TEST_POINT_PARAMETER_GET_INFO); + + CommGetInfo = (SMI_HANDLER_TEST_POINT_PARAMETER_GET_INFO *)&CommBuffer[OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data)]; + CommGetInfo->Header.Command = SMI_HANDLER_TEST_POINT_COMMAND_GET_INFO; + CommGetInfo->Header.DataLength = sizeof(*CommGetInfo); + CommGetInfo->Header.ReturnStatus = (UINT64)-1; + CommGetInfo->DataSize = 0; + + CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLength; + Status = SmmCommunication->Communicate(SmmCommunication, CommBuffer, &CommSize); + if (EFI_ERROR(Status)) { + Print(L"SmiHandlerTestPoint: SmmCommunication - %r\n", Status); + return ; + } + + if (CommGetInfo->Header.ReturnStatus != 0) { + Print(L"SmiHandlerTestPoint: GetInfo - 0x%0x\n", CommGetInfo->Header.ReturnStatus); + return ; + } + + mSmmTestPointDatabaseSize = (UINTN)CommGetInfo->DataSize; + + // + // Get Data + // + mSmmTestPointDatabase = AllocateZeroPool(mSmmTestPointDatabaseSize); + if (mSmmTestPointDatabase == NULL) { + Status = EFI_OUT_OF_RESOURCES; + Print(L"SmiHandlerTestPoint: AllocateZeroPool (0x%x) for dump buffer - %r\n", mSmmTestPointDatabaseSize, Status); + return ; + } + + CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; + CopyMem(&CommHeader->HeaderGuid, &gAdapterInfoPlatformTestPointGuid, sizeof(gAdapterInfoPlatformTestPointGuid)); + CommHeader->MessageLength = sizeof(SMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET); + + CommGetData = (SMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *)&CommBuffer[OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data)]; + CommGetData->Header.Command = SMI_HANDLER_TEST_POINT_COMMAND_GET_DATA_BY_OFFSET; + CommGetData->Header.DataLength = sizeof(*CommGetData); + CommGetData->Header.ReturnStatus = (UINT64)-1; + + CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLength; + Buffer = (UINT8 *)CommHeader + CommSize; + Size -= CommSize; + + CommGetData->DataBuffer = (PHYSICAL_ADDRESS)(UINTN)Buffer; + CommGetData->DataOffset = 0; + while (CommGetData->DataOffset < mSmmTestPointDatabaseSize) { + Offset = (UINTN)CommGetData->DataOffset; + if (Size <= (mSmmTestPointDatabaseSize - CommGetData->DataOffset)) { + CommGetData->DataSize = (UINT64)Size; + } else { + CommGetData->DataSize = (UINT64)(mSmmTestPointDatabaseSize - CommGetData->DataOffset); + } + Status = SmmCommunication->Communicate(SmmCommunication, CommBuffer, &CommSize); + ASSERT_EFI_ERROR(Status); + + if (CommGetData->Header.ReturnStatus != 0) { + FreePool(mSmmTestPointDatabase); + mSmmTestPointDatabase = NULL; + Print(L"SmiHandlerTestPoint: GetData - 0x%x\n", CommGetData->Header.ReturnStatus); + return ; + } + CopyMem((UINT8 *)mSmmTestPointDatabase + Offset, (VOID *)(UINTN)CommGetData->DataBuffer, (UINTN)CommGetData->DataSize); + } + + DEBUG ((DEBUG_INFO, "SmmTestPointDatabaseSize - 0x%x\n", mSmmTestPointDatabaseSize)); + + return ; +} + +UINTN +GetTestPointInfoSize ( + IN ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint, + IN UINTN MaxSize + ) +{ + CHAR16 *ErrorString; + UINTN ErrorStringLength; + UINTN ErrorStringMaxSize; + CHAR16 ErrorChar; + + ErrorString = (CHAR16 *)((UINTN)TestPoint + sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + 3 * TestPoint->FeaturesSize); + + ErrorStringMaxSize = MaxSize - sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) - TestPoint->FeaturesSize * 3; + // + // ErrorString might not be CHAR16 aligned. + // + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + for (ErrorStringLength = 0; (ErrorChar != 0) && (ErrorStringLength < (ErrorStringMaxSize/2)); ErrorStringLength++) { + ErrorString++; + CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar)); + } + + return sizeof(ADAPTER_INFO_PLATFORM_TEST_POINT) + 3 * TestPoint->FeaturesSize + (ErrorStringLength + 1) * sizeof(CHAR16); +} + +VOID +DumpTestPointDataSmm ( + IN UINT32 Role OPTIONAL, + IN CHAR16 *ImplementationID OPTIONAL + ) +{ + ADAPTER_INFO_PLATFORM_TEST_POINT *TestPoint; + UINTN Size; + + GetTestPointDataSmm (); + + if (mSmmTestPointDatabaseSize == 0) { + return ; + } + if (mSmmTestPointDatabase == NULL) { + return ; + } + + TestPoint = mSmmTestPointDatabase; + while ((UINTN)TestPoint < (UINTN)mSmmTestPointDatabase + mSmmTestPointDatabaseSize) { + if ((Role == 0) || + ((TestPoint->Role == Role) && + ((ImplementationID == NULL) || (StrCmp (ImplementationID, TestPoint->ImplementationID) == 0)))) { + DumpTestPoint (TestPoint); + } + + // + // Next + // + Size = GetTestPointInfoSize (TestPoint, (UINTN)mSmmTestPointDatabase + mSmmTestPointDatabaseSize - (UINTN)TestPoint); + TestPoint = (ADAPTER_INFO_PLATFORM_TEST_POINT *)((UINTN)TestPoint + Size); + } +} + +EFI_STATUS +EFIAPI +TestPointDumpAppEntrypoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + Print(L"TestPoint PEI:\n"); + DumpTestPointDataPei (0, NULL); + Print(L"TestPoint DXE:\n"); + DumpTestPointDataDxe (0, NULL); + Print(L"TestPoint SMM:\n"); + DumpTestPointDataSmm (0, NULL); + + return EFI_SUCCESS; +} diff --git a/Platform/Intel/MinPlatformPkg/Test/TestPointDumpApp/TestPointDumpApp.inf b/Platform/Intel/MinPlatformPkg/Test/TestPointDumpApp/TestPointDumpApp.inf new file mode 100644 index 0000000000..73ca073fe2 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Test/TestPointDumpApp/TestPointDumpApp.inf @@ -0,0 +1,49 @@ +## @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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = TestPointDumpApp + FILE_GUID = C19F7B48-9D41-4975-A9CC-BC42B4DC3732 + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = TestPointDumpAppEntrypoint + +[Sources] + TestPointDump.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[LibraryClasses] + UefiApplicationEntryPoint + BaseLib + BaseMemoryLib + MemoryAllocationLib + DebugLib + UefiBootServicesTableLib + UefiLib + HobLib + +[Guids] + gAdapterInfoPlatformTestPointGuid + gEdkiiPiSmmCommunicationRegionTableGuid + +[Protocols] + gEfiAdapterInformationProtocolGuid + gEfiSmmCommunicationProtocolGuid + +[Depex] + TRUE \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Tools/Fsp/PatchFspBinFvsBaseAddress.py b/Platform/Intel/MinPlatformPkg/Tools/Fsp/PatchFspBinFvsBaseAddress.py new file mode 100644 index 0000000000..63d2f88946 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tools/Fsp/PatchFspBinFvsBaseAddress.py @@ -0,0 +1,116 @@ +## @ PatchFspBinBaseAddress.py +# +# 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. +# +## + +import os +import re +import sys +import struct +from datetime import date + +fspSBaseAddress = 0 +fspMBaseAddress = 0 +fspTBaseAddress = 0 + +def GetFspBaseAddress (binfile): + offset = 0; + for index in range(1,4): + attribute = readDataFromFile(binfile, offset+0xB7, 1) >> 4 + if attribute == 0x3: + global fspSBaseAddress + fspSBaseAddress = readDataFromFile(binfile, offset+0xB0, 4) + if attribute == 0x2: + global fspMBaseAddress + fspMBaseAddress = readDataFromFile(binfile, offset+0xB0, 4) + if attribute == 0x1: + global fspTBaseAddress + fspTBaseAddress = readDataFromFile(binfile, offset+0xB0, 4) + offset += readDataFromFile(binfile, offset+0xAC, 4) + return 0 + +# +# Read data from file +# +# param [in] binfile Binary file +# param [in] offset Offset +# param [in] len Length +# +# retval value Value +# +def readDataFromFile (binfile, offset, len=1): + fd = open(binfile, "rb") + fsize = os.path.getsize(binfile) + offval = offset & 0xFFFFFFFF + if (offval & 0x80000000): + offval = fsize - (0xFFFFFFFF - offval + 1) + fd.seek(offval) + bytearray = [ord(b) for b in fd.read(len)] + value = 0 + idx = len - 1 + while idx >= 0: + value = value << 8 | bytearray[idx] + idx = idx - 1 + fd.close() + return value + +def updateFspFvsBase (binfile, TargetFile): + ext_file = str(os.path.splitext(TargetFile)[-1]).lower() + if not os.path.exists(binfile): + print "WARNING! " + str(binfile) + " is not found." + return 1 + if not os.path.exists(TargetFile): + print "WARNING! " + str(TargetFile) + " is not found." + return 1 + + GetFspBaseAddress(binfile) + + if ext_file == ".dsc": + DscFile = open(TargetFile, "r") + DscLines = DscFile.readlines() + DscFile.close() + DscContent = [] + + for line in DscLines: + DscContent.append(line) + DscFile = open(TargetFile,"w") + + for index in range(len(DscContent)): + DscLine = DscContent[index] + Match = re.match("([_a-zA-Z0-9]+).Pcd(Fspt|Fspm|Fsps)BaseAddress",DscLine) + if Match: + DscLine = Match.group(1) + ".Pcd" + Match.group(2) + "BaseAddress|0x" + if Match.group(2) == 'Fspt': + BaseAddrStr = str(hex(fspTBaseAddress)[2:]).zfill(8).upper().rstrip('L') + elif Match.group(2) == 'Fspm': + BaseAddrStr = str(hex(fspMBaseAddress)[2:]).zfill(8).upper().rstrip('L') + elif Match.group(2) == 'Fsps': + BaseAddrStr = str(hex(fspSBaseAddress)[2:]).zfill(8).upper().rstrip('L') + DscLine = DscLine + BaseAddrStr + "\n" + DscFile.writelines(DscLine) + DscFile.close() + return 0 + +def Main(): + # + # Parse the options and args + # + if len(sys.argv) != 3: + print "error" + return 1 + ret = updateFspFvsBase (sys.argv[1], sys.argv[2]) + + if ret != 0: + return 1 + return 0 + +if __name__ == '__main__': + sys.exit(Main()) diff --git a/Platform/Intel/MinPlatformPkg/Tools/Fsp/RebaseAndPatchFspBinBaseAddress.py b/Platform/Intel/MinPlatformPkg/Tools/Fsp/RebaseAndPatchFspBinBaseAddress.py new file mode 100644 index 0000000000..b9d627a1d2 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tools/Fsp/RebaseAndPatchFspBinBaseAddress.py @@ -0,0 +1,121 @@ +## @ RebaseAndPatchFspBinBaseAddress.py +# +# 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. +# +## +import os +import sys +import re +import subprocess + +if len(sys.argv) != 6: + print "RebaseAndPatchFspBinBaseAddress.py - Error in number of arguments received" + print "Usage - RebaseAndPatchFspBinBaseAddress.py " + exit(1) + +flashMapName = sys.argv[1] +fspBinPath = sys.argv[2] +fspBinFile = sys.argv[3] +targetDscFile = sys.argv[4] +fvOffset = long(sys.argv[5], 16) +fspBinFileRebased = "Fsp_Rebased.fd" + +# +# Make sure argument passed or valid +# +if not os.path.exists(flashMapName): + print "WARNING! " + str(flashMapName) + " is not found." + exit(1) +fspBinFilePath = fspBinPath + "\\" + fspBinFile +if not os.path.exists(fspBinFilePath): + print "WARNING! " + str(fspBinFilePath) + " is not found." + exit(1) +if not os.path.exists(targetDscFile): + print "WARNING! " + str(targetDscFile) + " is not found." + exit(1) +ext_file = str(os.path.splitext(targetDscFile)[-1]).lower() +if ext_file != ".dsc": + print "WARNING! " + str(targetDscFile) + " is not a dsc file" + exit(1) + +# +# Get the FSP-S / FSP-M-T FV Base Address from Flash Map +# +file = open (flashMapName, "r") +data = file.read () + +# Get the Flash Base Address +flashBase = long(data.split("FLASH_BASE")[1].split("=")[1].split()[0], 16) + +# Based on Build Target, select the section in the FlashMap file +flashmap = data + +# Get FSP-S & FSP-M-T offset & calculate the base +for line in flashmap.split("\n"): + if "PcdFlashFvFspsOffset" in line: + fspSBaseOffset = long(line.split("=")[1].split()[0], 16) + if "PcdFlashFvFspmtOffset" in line: + fspMBaseOffset = long(line.split("=")[1].split()[0], 16) +file.close() + +# +# Get FSP-M Size, in order to calculate the FSP-T Base. Used SplitFspBin.py script +# to dump the header, and get the ImageSize in FSP-M section +# +Process = subprocess.Popen("python edk2\IntelFsp2Pkg\Tools\SplitFspBin.py info -f" + fspBinFilePath, stdout=subprocess.PIPE) +Output = Process.communicate()[0] +FsptInfo = Output.rsplit("FSP_M", 1); +for line in FsptInfo[1].split("\n"): + if "ImageSize" in line: + fspMSize = long(line.split("=")[1], 16) + break + +# Calculate FSP-S/M/T base address, to which re-base has to be done +fspSBaseAddress = flashBase + fspSBaseOffset + fvOffset +fspMBaseAddress = flashBase + fspMBaseOffset +fspTBaseAddress = flashBase + fspMBaseOffset + fspMSize + +# +# Re-base FSP bin file to new address and save it as fspBinFileRebased using SplitFspBin.py +# +rebaseArguments = fspBinFilePath + " -c s m t -b " + str(hex(fspSBaseAddress).rstrip("L")) + " " + str(hex(fspMBaseAddress).rstrip("L")) + " " + str(hex(fspTBaseAddress).rstrip("L")) + " -o" + fspBinPath + " -n " + fspBinFileRebased +os.system("python edk2\IntelFsp2Pkg\Tools\SplitFspBin.py rebase -f" + rebaseArguments) + +# +# Split FSP bin to FSP-S/M/T segments +# +splitArguments = fspBinPath +"\\" + fspBinFileRebased + " -o " + fspBinPath + " -n Fsp_Rebased.fd" +os.system("python edk2\IntelFsp2Pkg\Tools\SplitFspBin.py split -f" + splitArguments) + +# +# Patch dsc file with the re-based FSP-S/M/T address, so internally build will use the same. +# +DscFile = open(targetDscFile, "r") +DscLines = DscFile.readlines() +DscFile.close() +DscContent = [] +for line in DscLines: + DscContent.append(line) +DscFile = open(targetDscFile,"w") +for index in range(len(DscContent)): + DscLine = DscContent[index] + Match = re.match("([\s_a-zA-Z0-9]+).Pcd(Fspt|Fspm|Fsps)BaseAddress",DscLine) + if Match: + DscLine = Match.group(1) + ".Pcd" + Match.group(2) + "BaseAddress|0x" + if Match.group(2) == 'Fspt': + BaseAddrStr = str(hex(fspTBaseAddress)[2:]).zfill(8).upper().rstrip('L') + elif Match.group(2) == 'Fspm': + BaseAddrStr = str(hex(fspMBaseAddress)[2:]).zfill(8).upper().rstrip('L') + elif Match.group(2) == 'Fsps': + BaseAddrStr = str(hex(fspSBaseAddress)[2:]).zfill(8).upper().rstrip('L') + DscLine = DscLine + BaseAddrStr + "\n" + DscFile.writelines(DscLine) +DscFile.close() +exit(0) diff --git a/Platform/Intel/MinPlatformPkg/Tools/Fsp/pad.bin b/Platform/Intel/MinPlatformPkg/Tools/Fsp/pad.bin new file mode 100644 index 0000000000..146420f3a6 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tools/Fsp/pad.bin @@ -0,0 +1 @@ +ÿÿÿÿÿÿÿÿÿÿÿÿ \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Tools/Help/CheckCodeBase.py b/Platform/Intel/MinPlatformPkg/Tools/Help/CheckCodeBase.py new file mode 100644 index 0000000000..f97de4f522 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Tools/Help/CheckCodeBase.py @@ -0,0 +1,795 @@ +## @ CheckCodeBase.py +# +# 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. +# +## + +import os +import re +import sys +import time +import shutil + +class FileChecker: + def __init__(self): + # sourceRoot == WORKSPACE + # sourceRoot != PACKAGES_PATH + self.sourceRoot = "" + self.includeCoreList = ["\\CryptoPkg\\", "\\FatBinPkg\\", "\\FatPkg\\", "\\IntelFrameworkModulePkg\\", "\\IntelFrameworkPkg\\", "\\IntelFsp2Pkg\\", "\\IntelFsp2WrapperPkg\\", "\\IntelFspPkg\\", "\\IntelFspWrapperPkg\\", "\\IntelSiliconPkg\\", "\\MdeModulePkg\\", "\\MdePkg\\", "\\NetworkPkg\\", "\\PcAtChipsetPkg\\", "\\PerformancePkg\\", "\\SecurityPkg\\", "\\ShellBinPkg\\", "\\ShellPkg\\", "\\SignedCapsulePkg\\", "\\SourceLevelDebugPkg\\", "\\UefiCpuPkg\\"] + self.includeList = self.includeCoreList + self.excluseCoreList = ["\\BaseTools\\", "\\Conf\\", "\\Tools\\", "\\Build\\", "\\tool\\", "\\.svn", "\\.git", "\\Override\\", "\\SampleCode\\", "\\openssl"] + self.excluseList = self.excluseCoreList + self.usedModuleList = [] + self.usedLibraryList = [] + self.makefileList = [] + self.usedIncludeFileList = [] + self.usedModuleFileList = [] + self.usedLibraryFileList = [] + self.usedFileList = [] + self.usedPackageList = [] + self.allModuleList = [] + self.allLibraryList = [] + self.allDirList = [] + self.allIncludeFileList = [] + self.allModuleFileList = [] + self.allLibraryFileList = [] + self.allFileList = [] + self.allPackageList = [] + self.unusedModuleList = [] + self.unusedLibraryList = [] + self.unusedIncludeFileList = [] + self.unusedModuleFileList = [] + self.unusedLibraryFileList = [] + self.unusedFileList = [] + self.unusedPackageList = [] + self.unusedPackageFileList = [] + + def CheckFile(self, file): + if os.path.isfile(file): + return file.decode('gbk') + else: + return "" + + def CheckDir(self, file): + if os.path.isdir(file): + return file.decode('gbk') + else: + return "" + + def IsIncludeFile(self, file): + if (cmp (file[-2:], ".h") == 0) and (file.find ("Pkg\\Include") != -1): + return True + else: + return False + + def IsLibraryFile(self, file): + if (file.find ("Pkg\\Library") != -1): + return True + else: + return False + + def CheckIncludeFile(self, file): + if self.IsIncludeFile(file) and (self.IsInExclusiveList(file) == False): + return file.decode('gbk') + else: + return "" + + def GetModulePathFromMakefile (self, file): + makefile = open (file, "r") + data = makefile.read () + for line in data.split("\n"): + # MODULE_DIR = c:\home\edkiigit\edk2\MdeModulePkg\Library\BaseSerialPortLib16550 + if "MODULE_DIR =" in line: + moduleDir = line.split(" = ")[1] + # BUILD_DIR = c:\home\edkiigit\Build\KabylakeOpenBoardPkg\KabylakeRvp3\DEBUG_VS2015x86 + if "BUILD_DIR =" in line: + buildDir = line.split(" = ")[1] + makefile.close() + + # record sourceRoot = c:\home\Edk-II + self.sourceRoot = buildDir.split("\\Build\\")[0] + + if (self.IsInExclusiveList(moduleDir) == False): + self.AddPackageList(moduleDir, self.usedPackageList) + + return moduleDir + + def AddPackageList(self, file, packageList): + packageName = file.split("Pkg") + packagePath = packageName[0] + "Pkg" + if packagePath not in packageList: + packageList.append(packagePath) + + def IsInPackageList(self, file): + for package in self.usedPackageList: + if file.find(package) != -1: + return True + return False + + def CheckUsedModule(self, file): + if (cmp (file[-8:], "Makefile") == 0) and (self.IsLibraryFile(file) == False): + finalDir = self.GetModulePathFromMakefile(file) + if self.IsInExclusiveList(finalDir): + return "" + return finalDir.decode('gbk') + else: + return "" + + def CheckUsedLibrary(self, file): + if (cmp (file[-8:], "Makefile") == 0) and self.IsLibraryFile(file): + finalDir = self.GetModulePathFromMakefile(file) + if self.IsInExclusiveList(finalDir): + return "" + return finalDir.decode('gbk') + else: + return "" + + def CheckMakefile(self, file): + if cmp (file[-8:], "Makefile") == 0: + finalDir = self.GetModulePathFromMakefile(file) + if self.IsInExclusiveList(finalDir): + return "" + return file.decode('gbk') + else: + return "" + + def ParseMakefile(self, fileName): + try : + file = open(fileName) + except Exception: + print "fail to open " + fileName + return + try: + while 1: + line = file.readline() + if not line: + break + if cmp (line[0], "#") == 0: + continue + newline = line[:-1] + + #print "check - (" + newline + ")" + headFile = "" + #COMMON_DEPS = $(WORKSPACE)\MdePkg\Include\Protocol\DebugSupport.h \ + # $(WORKSPACE)\MdePkg\Include\Ppi\PciCfg2.h \ + #$(OUTPUT_DIR)\X64\Semaphore.obj : $(WORKSPACE)\UefiCpuPkg\Include\Library\MtrrLib.h + #MatchString = "[\w\\\s\=\:\.\(\)\$]*\$\(WORKSPACE\)([\\\w]*\.h)[\\w\s]*" + MatchString1 = "(COMMON_DEPS = | |\$\(OUTPUT_DIR\)[\\\\\w]*.obj : )\$\(WORKSPACE\)\\\\([\\\\\w]*\.h)" + match1 = re.match(MatchString1, newline) + if match1 is not None: + #print "match1 - " + newline + #print "0 - " + match1.group(0) + #print "1 - " + match1.group(1) + #print "2 - " + match1.group(2) + headFile = match1.group(2) + + if (cmp (headFile, "") != 0) and self.IsIncludeFile(headFile): + finalPath = os.path.join (self.sourceRoot, headFile) + if (self.IsInExclusiveList(finalPath) == False) and (finalPath not in self.usedIncludeFileList): + self.usedIncludeFileList.append(finalPath) + self.AddPackageList (finalPath, self.usedPackageList) + + finally: + file.close() + + return + + def IsInIncludeList(self, file): + for list in self.includeList: + result = file.find(list); + if (result != -1): + return True + return False + + def IsInExclusiveList(self, file): + if self.IsInIncludeList(file) == False: + return True + for list in self.excluseList: + result = file.find(list); + if (result != -1): + return True + for list in self.excluseList: + full_file = file + "\\" + result = full_file.find(list); + if (result != -1): + return True + return False + + def IsFinalDir(self, file): + for s in os.listdir(file): + newFile=os.path.join(file,s) + if cmp (newFile[-4:], ".inf") == 0: + return True + return False + + def IsInUsedModuleList(self, file): + if file in self.usedModuleList: + return True + else: + return False + + def IsInUsedLibraryList(self, file): + if file in self.usedLibraryList: + return True + else: + return False + + def IsUsedModule(self, file): + for used in self.usedModuleList: + final = used + "\\" + result = file.find(final); + if (result != -1): + return True + return False + + def IsUsedLibrary(self, file): + for used in self.usedLibraryList: + final = used + "\\" + result = file.find(final); + if (result != -1): + return True + return False + + def IsUnusedModule(self, file): + for unused in self.unusedModuleList: + final = unused + "\\" + result = file.find(final); + if (result != -1): + return True + return False + + def IsUnusedLibrary(self, file): + for unused in self.unusedLibraryList: + final = unused + "\\" + result = file.find(final); + if (result != -1): + return True + return False + + def IsUnusedPackage(self, file): + for unused in self.unusedPackageList: + final = unused + "\\" + result = file.find(final); + if (result != -1): + return True + return False + + def CheckUnusedModule(self, file): + if os.path.isdir(file): + if (self.IsInExclusiveList(file) == False) and self.IsFinalDir(file) and (self.IsInUsedModuleList(file) == False) and (self.IsLibraryFile(file) == False): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckUnusedLibrary(self, file): + if os.path.isdir(file): + if (self.IsInExclusiveList(file) == False) and self.IsFinalDir(file) and (self.IsInUsedLibraryList(file) == False) and self.IsLibraryFile(file): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckAllModule(self, file): + if os.path.isdir(file): + if (self.IsInExclusiveList(file) == False) and self.IsFinalDir(file) and (self.IsLibraryFile(file) == False): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckAllLibrary(self, file): + if os.path.isdir(file): + if (self.IsInExclusiveList(file) == False) and self.IsFinalDir(file) and self.IsLibraryFile(file): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckAllDir(self, file): + if os.path.isdir(file): + if (self.IsInExclusiveList(file) == False): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckAllModuleFile(self, file): + if os.path.isfile(file): + if (self.IsInExclusiveList(file) == False) and (self.IsUsedModule(file) or self.IsUnusedModule(file)) and (self.IsLibraryFile(file) == False): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckAllLibraryFile(self, file): + if os.path.isfile(file): + if (self.IsInExclusiveList(file) == False) and (self.IsUsedLibrary(file) or self.IsUnusedLibrary(file)) and self.IsLibraryFile(file): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckAllFile(self, file): + if os.path.isfile(file): + if (self.IsInExclusiveList(file) == False): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckUsedModuleFile(self, file): + if os.path.isfile(file): + if (self.IsInExclusiveList(file) == False) and self.IsUsedModule(file): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckUsedLibraryFile(self, file): + if os.path.isfile(file): + if (self.IsInExclusiveList(file) == False) and self.IsUsedLibrary(file): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckUnusedModuleFile(self, file): + if os.path.isfile(file): + if (self.IsInExclusiveList(file) == False) and self.IsUnusedModule(file): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckUnusedLibraryFile(self, file): + if os.path.isfile(file): + if (self.IsInExclusiveList(file) == False) and self.IsUnusedLibrary(file): + return file.decode('gbk') + else: + return "" + else: + return "" + + def CheckUnusedPackageFile(self, file): + if os.path.isfile(file): + if (self.IsInExclusiveList(file) == False) and self.IsUnusedPackage(file): + return file.decode('gbk') + else: + return "" + else: + return "" + + def GetFileList(self, dir, fileList, checkFunc): + newDir = dir + AppendName = checkFunc (dir) + if cmp (AppendName, "") != 0: + #print "AppendName = " + AppendName + if AppendName not in fileList: + fileList.append(AppendName) + if os.path.isdir(dir): + for sub in os.listdir(dir): + newDir = os.path.join(dir,sub) + self.GetFileList(newDir, fileList, checkFunc) + return fileList + + def DeleteEmptyDir(self, dir): + if os.path.exists(dir) == False: + return + if os.path.isdir(dir): + for sub in os.listdir(dir): + newDir = os.path.join(dir,sub) + if (os.path.isdir(newDir) == True): + self.DeleteEmptyDir(newDir) + if not os.listdir(dir): + print "deleting empty " + dir + os.rmdir(dir) + + def DeleteEmptyDirList(self, fileList): + for file in fileList: + self.DeleteEmptyDir(file) + + def DeleteUnusedFile(self, fileList): + for file in fileList: + if os.path.exists(file) == False: + continue + print "deleting " + file + try : + if os.path.isdir(file): + shutil.rmtree(file) + if os.path.isfile(file): + os.remove(file) + except : + print "deleting error (" + file + ")" + + def PrintFileTime(self, file): + statinfo = os.stat(file) + strucatime = time.localtime(statinfo.st_atime) + print "atime: " + str(statinfo.st_atime) + " (" + str(strucatime.tm_year) + "." + str(strucatime.tm_mon) + "." + str(strucatime.tm_mday) + " " + str(strucatime.tm_hour) + ":" + str(strucatime.tm_min) + ":" + str(strucatime.tm_sec) + ")" + strucctime = time.localtime(statinfo.st_ctime) + print "ctime: " + str(statinfo.st_ctime) + " (" + str(strucctime.tm_year) + "." + str(strucctime.tm_mon) + "." + str(strucctime.tm_mday) + " " + str(strucctime.tm_hour) + ":" + str(strucctime.tm_min) + ":" + str(strucctime.tm_sec) + ")" + strucmtime = time.localtime(statinfo.st_mtime) + print "mtime: " + str(statinfo.st_mtime) + " (" + str(strucmtime.tm_year) + "." + str(strucmtime.tm_mon) + "." + str(strucmtime.tm_mday) + " " + str(strucmtime.tm_hour) + ":" + str(strucmtime.tm_min) + ":" + str(strucmtime.tm_sec) + ")" + + def TouchFileTime(self, file): + #currentTime = time.time() + #os.utime(file, (currentTime, currentTime)) + os.utime(file, None) + + def TouchFileListTime(self, fileList): + for file in fileList: + self.TouchFileTime(file) + + def PrintFileList(self, fileList): + for file in fileList: + print file + print " Count - " + str(len(fileList)) + + def SortFileList(self, fileList): + fileList.sort() + + def PrintFileListTime(self, fileList): + for file in fileList: + print file + self.PrintFileTime(file) + + def GetUsedModuleList(self): + if (len(self.usedModuleList) == 0): + self.usedModuleList = self.GetFileList(sys.argv[1], [], self.CheckUsedModule) + self.SortFileList(self.usedModuleList) + + def GetUsedLibraryList(self): + if (len(self.usedLibraryList) == 0): + self.usedLibraryList = self.GetFileList(sys.argv[1], [], self.CheckUsedLibrary) + self.SortFileList(self.usedLibraryList) + + def GetMakefileList(self): + if (len(self.makefileList) == 0): + self.GetUsedModuleList() + self.makefileList = self.GetFileList(sys.argv[1], [], self.CheckMakefile) + + def GetUsedIncludeFileList(self): + if (len(self.usedIncludeFileList) == 0): + self.GetMakefileList() + + #print "\nMakefile:" + #fileChecker.PrintFileList (fileChecker.makefileList) + + for file in self.makefileList: + self.ParseMakefile(file) + self.SortFileList(self.usedIncludeFileList) + + def GetUsedModuleFileList(self): + if (len(self.usedModuleFileList) == 0): + self.GetUsedModuleList() + + self.usedModuleFileList = self.GetFileList(self.sourceRoot, [], self.CheckUsedModuleFile) + self.SortFileList(self.usedModuleFileList) + + def GetUsedLibraryFileList(self): + if (len(self.usedLibraryFileList) == 0): + self.GetUsedLibraryList() + + self.usedLibraryFileList = self.GetFileList(self.sourceRoot, [], self.CheckUsedLibraryFile) + self.SortFileList(self.usedLibraryFileList) + + def GetUsedFileList(self): + if (len(self.usedFileList) == 0): + self.GetAllFileList() + self.GetUnusedFileList() + + self.usedFileList = [] + for file in self.allFileList: + if (file not in self.unusedFileList) and self.IsInPackageList(file): + self.usedFileList.append(file) + + self.SortFileList(self.usedFileList) + + def GetUsedPackageList(self): + self.GetUsedModuleList() + self.GetUsedLibraryList() + self.GetUsedIncludeFileList() + self.SortFileList(self.usedPackageList) + + def GetAllModuleList(self): + if (len(self.allModuleList) == 0): + self.GetUsedModuleList() + + self.allModuleList = self.GetFileList(self.sourceRoot, [], self.CheckAllModule) + self.SortFileList(self.allModuleList) + + def GetAllLibraryList(self): + if (len(self.allLibraryList) == 0): + self.GetUsedLibraryList() + + self.allLibraryList = self.GetFileList(self.sourceRoot, [], self.CheckAllLibrary) + self.SortFileList(self.allLibraryList) + + def GetAllIncludeFileList(self): + if (len(self.allIncludeFileList) == 0): + self.GetUsedModuleList() + + self.allIncludeFileList = self.GetFileList(self.sourceRoot, [], self.CheckIncludeFile) + self.SortFileList(self.allIncludeFileList) + + def GetAllModuleFileList(self): + if (len(self.allFileList) == 0): + self.GetUsedModuleList() + self.GetUnusedModuleList() + + self.allModuleFileList = self.GetFileList(self.sourceRoot, [], self.CheckAllModuleFile) + self.SortFileList(self.allModuleFileList) + + def GetAllLibraryFileList(self): + if (len(self.allFileList) == 0): + self.GetUsedLibraryList() + self.GetUnusedLibraryList() + + self.allLibraryFileList = self.GetFileList(self.sourceRoot, [], self.CheckAllLibraryFile) + self.SortFileList(self.allLibraryFileList) + + def GetAllFileList(self): + if (len(self.allFileList) == 0): + self.GetUsedModuleList() + + self.allFileList = self.GetFileList(self.sourceRoot, [], self.CheckAllFile) + self.SortFileList(self.allFileList) + + def GetAllPackageList(self): + if (len(self.allPackageList) == 0): + self.GetAllFileList() + prefixLength = len(self.sourceRoot) + for file in self.allFileList: + finalPath = os.path.join (self.sourceRoot, file[prefixLength + 1:]) + self.AddPackageList(finalPath, self.allPackageList) + self.SortFileList(self.allPackageList) + + def GetUnusedModuleList(self): + if (len(self.unusedModuleList) == 0): + self.GetUsedModuleList() + + self.unusedModuleList = self.GetFileList(self.sourceRoot, [], self.CheckUnusedModule) + + def GetUnusedLibraryList(self): + if (len(self.unusedLibraryList) == 0): + self.GetUsedLibraryList() + + self.unusedLibraryList = self.GetFileList(self.sourceRoot, [], self.CheckUnusedLibrary) + + def GetUnusedIncludeFileList(self): + if (len(self.unusedIncludeFileList) == 0): + self.GetUsedIncludeFileList() + self.GetAllIncludeFileList() + + self.unusedIncludeFileList = [] + for file in self.allIncludeFileList: + if file not in self.usedIncludeFileList: + self.unusedIncludeFileList.append(file) + + self.SortFileList(self.unusedIncludeFileList) + + def GetUnusedModuleFileList(self): + if (len(self.unusedModuleFileList) == 0): + self.GetUnusedModuleList () + + self.unusedModuleFileList = self.GetFileList(self.sourceRoot, [], self.CheckUnusedModuleFile) + self.SortFileList(self.unusedModuleFileList) + + def GetUnusedLibraryFileList(self): + if (len(self.unusedLibraryFileList) == 0): + self.GetUnusedLibraryList () + + self.unusedLibraryFileList = self.GetFileList(self.sourceRoot, [], self.CheckUnusedLibraryFile) + self.SortFileList(self.unusedLibraryFileList) + + def GetUnusedFileList(self): + if (len(self.unusedFileList) == 0): + self.GetUnusedIncludeFileList() + self.GetUnusedModuleFileList() + self.GetUnusedLibraryFileList() + + self.GetUnusedPackageList() + self.unusedPackageFileList = self.GetFileList(self.sourceRoot, [], self.CheckUnusedPackageFile) + + self.unusedFileList = [] + self.unusedFileList.extend(self.unusedIncludeFileList) + self.unusedFileList.extend(self.unusedModuleFileList) + self.unusedFileList.extend(self.unusedLibraryFileList) + + for file in self.unusedPackageFileList: + if file not in self.unusedFileList: + self.unusedFileList.append(file) + + self.SortFileList(self.unusedFileList) + + def GetUnusedPackageList(self): + if (len(self.unusedPackageList) == 0): + self.GetUsedPackageList() + self.GetAllPackageList() + + for package in self.allPackageList: + if package not in self.usedPackageList: + self.unusedPackageList.append(package) + self.SortFileList(self.unusedPackageList) + +# +# Print out the usage +# +def usage(): + print "Usage: \n\tCheckCodeBase used|unused|all" + print " used - used library, modules, include file, library files, module files, all used files" + print " unused - unused library, modules, include file, library files, module files, all unused files" + print " all - all library, modules, include file, library files, module files, all files" + print " library : the directory of a library" + print " module : the directory of a driver" + print " include file : the header files in include directory" + print " library file : all files in a library directory" + print " module file : all files in a driver directory" + print " all file : all files in project, including any other metadata files or batch files" + #print "Usage: \n\tCheckCodeBase time|touch" + print "For Example: \n\tCheckCodeBase Build\KabylakeOpenBoardPkg\KabylakeRvp3\DEBUG_VS2015x86 used" + +def main(): + global FileChecker + + fileChecker = FileChecker() + + if len(sys.argv) < 3: + usage() + return 1 + + if cmp (sys.argv[2], "used") == 0: + fileChecker.GetUsedModuleList () + print "\n Used Module List:" + fileChecker.PrintFileList (fileChecker.usedModuleList) + + fileChecker.GetUsedLibraryList () + print "\n Used Library List:" + fileChecker.PrintFileList (fileChecker.usedLibraryList) + + fileChecker.GetUsedIncludeFileList() + print "\n Used Include File List:" + fileChecker.PrintFileList (fileChecker.usedIncludeFileList) + + fileChecker.GetUsedModuleFileList() + print "\n Used Module File List:" + fileChecker.PrintFileList (fileChecker.usedModuleFileList) + + fileChecker.GetUsedLibraryFileList() + print "\n Used Library File List:" + fileChecker.PrintFileList (fileChecker.usedLibraryFileList) + + fileChecker.GetUsedFileList() + print "\n All Used File List:" + fileChecker.PrintFileList (fileChecker.usedFileList) + + fileChecker.GetUsedPackageList() + print "\n Used Package List:" + fileChecker.PrintFileList (fileChecker.usedPackageList) + + print "\n ==== Used Module Summary ====" + print " Module Count - " + str(len(fileChecker.usedModuleList)) + print " Library Count - " + str(len(fileChecker.usedLibraryList)) + print " Include File Count - " + str(len(fileChecker.usedIncludeFileList)) + print " Module File Count - " + str(len(fileChecker.usedModuleFileList)) + print " Library File Count - " + str(len(fileChecker.usedLibraryFileList)) + print " All File Count - " + str(len(fileChecker.usedFileList)) + + elif cmp (sys.argv[2], "all") == 0: + fileChecker.GetAllModuleList() + print "\n All Module List:" + fileChecker.PrintFileList (fileChecker.allModuleList) + + fileChecker.GetAllLibraryList() + print "\n All Library List:" + fileChecker.PrintFileList (fileChecker.allLibraryList) + + fileChecker.GetAllIncludeFileList() + print "\n All Include File List:" + fileChecker.PrintFileList (fileChecker.allIncludeFileList) + + fileChecker.GetAllModuleFileList() + print "\n All Module File List:" + fileChecker.PrintFileList (fileChecker.allModuleFileList) + + fileChecker.GetAllLibraryFileList() + print "\n All Library File List:" + fileChecker.PrintFileList (fileChecker.allLibraryFileList) + + fileChecker.GetAllFileList() + print "\n All File List:" + fileChecker.PrintFileList (fileChecker.allFileList) + + fileChecker.GetAllPackageList() + print "\n All Package List:" + fileChecker.PrintFileList (fileChecker.allPackageList) + + print "\n ==== All Module Summary ====" + print " Module Count - " + str(len(fileChecker.allModuleList)) + print " Library Count - " + str(len(fileChecker.allLibraryList)) + print " Include File Count - " + str(len(fileChecker.allIncludeFileList)) + print " Module File Count - " + str(len(fileChecker.allModuleFileList)) + print " Library File Count - " + str(len(fileChecker.allLibraryFileList)) + print " All File Count - " + str(len(fileChecker.allFileList)) + + elif cmp (sys.argv[2], "unused") == 0: + fileChecker.GetUnusedModuleList() + print "\n Unused Module List:" + fileChecker.PrintFileList (fileChecker.unusedModuleList) + + fileChecker.GetUnusedLibraryList() + print "\n Unused Library List:" + fileChecker.PrintFileList (fileChecker.unusedLibraryList) + + fileChecker.GetUnusedIncludeFileList() + print "\n Unused Include List:" + fileChecker.PrintFileList (fileChecker.unusedIncludeFileList) + + fileChecker.GetUnusedModuleFileList() + print "\n Unused Module File List:" + fileChecker.PrintFileList (fileChecker.unusedModuleFileList) + + fileChecker.GetUnusedLibraryFileList() + print "\n Unused Library File List:" + fileChecker.PrintFileList (fileChecker.unusedLibraryFileList) + + fileChecker.GetUnusedFileList() + print "\n Unused File List:" + fileChecker.PrintFileList (fileChecker.unusedFileList) + + fileChecker.GetUnusedPackageList() + print "\n Unused Package List:" + fileChecker.PrintFileList (fileChecker.unusedPackageList) + + print "\n ==== Unused Module Summary ====" + print " Module Count - " + str(len(fileChecker.unusedModuleList)) + print " Library Count - " + str(len(fileChecker.unusedLibraryList)) + print " Include File Count - " + str(len(fileChecker.unusedIncludeFileList)) + print " Module File Count - " + str(len(fileChecker.unusedModuleFileList)) + print " Library File Count - " + str(len(fileChecker.unusedLibraryFileList)) + print " All File Count - " + str(len(fileChecker.unusedFileList)) + + elif cmp (sys.argv[2], "delete_unused") == 0: + fileChecker.GetUnusedModuleList() + fileChecker.GetUnusedLibraryList() + fileChecker.GetUnusedIncludeFileList() + fileChecker.GetUnusedPackageList() + + fileChecker.DeleteUnusedFile(fileChecker.unusedPackageList) + fileChecker.DeleteUnusedFile(fileChecker.unusedModuleList) + fileChecker.DeleteUnusedFile(fileChecker.unusedLibraryList) + fileChecker.DeleteUnusedFile(fileChecker.unusedIncludeFileList) + + fileChecker.allDirList = fileChecker.GetFileList(fileChecker.sourceRoot, [], fileChecker.CheckAllDir) + fileChecker.DeleteEmptyDirList(fileChecker.allDirList) + + elif cmp (sys.argv[2], "time") == 0: + fileChecker.allDirList = fileChecker.GetFileList(sys.argv[1], [], fileChecker.CheckFile) + fileChecker.PrintFileListTime(fileChecker.allDirList) + + elif cmp (sys.argv[2], "touch") == 0: + fileChecker.allDirList = fileChecker.GetFileList(sys.argv[1], [], fileChecker.CheckFile) + fileChecker.TouchFileListTime(fileChecker.allDirList) + else: + print "Unknown - " + sys.argv[2] + +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3