2016-05-13 07:00:53 +02:00
|
|
|
/** @file
|
|
|
|
This will be invoked only once. It will call FspMemoryInit API,
|
|
|
|
register TemporaryRamDonePpi to call TempRamExit API, and register MemoryDiscoveredPpi
|
|
|
|
notify to call FspSiliconInit API.
|
|
|
|
|
2022-04-15 10:37:41 +02:00
|
|
|
Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:04:06 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2016-05-13 07:00:53 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <PiPei.h>
|
|
|
|
|
|
|
|
#include <Library/PeimEntryPoint.h>
|
|
|
|
#include <Library/PeiServicesLib.h>
|
|
|
|
#include <Library/PeiServicesTablePointerLib.h>
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/MemoryAllocationLib.h>
|
|
|
|
#include <Library/HobLib.h>
|
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
#include <Library/TimerLib.h>
|
|
|
|
#include <Library/PerformanceLib.h>
|
|
|
|
#include <Library/FspWrapperPlatformLib.h>
|
|
|
|
#include <Library/FspWrapperHobProcessLib.h>
|
2022-08-10 02:35:50 +02:00
|
|
|
#include <Library/FspWrapperMultiPhaseProcessLib.h>
|
2016-05-13 07:00:53 +02:00
|
|
|
#include <Library/FspWrapperApiLib.h>
|
2020-08-18 08:26:14 +02:00
|
|
|
#include <Library/FspMeasurementLib.h>
|
2016-05-13 07:00:53 +02:00
|
|
|
|
|
|
|
#include <Ppi/FspSiliconInitDone.h>
|
|
|
|
#include <Ppi/EndOfPeiPhase.h>
|
|
|
|
#include <Ppi/MemoryDiscovered.h>
|
|
|
|
#include <Ppi/SecPlatformInformation.h>
|
2020-08-18 08:26:14 +02:00
|
|
|
#include <Ppi/Tcg.h>
|
|
|
|
#include <Ppi/FirmwareVolumeInfoMeasurementExcluded.h>
|
2016-05-13 07:00:53 +02:00
|
|
|
#include <Library/FspWrapperApiTestLib.h>
|
|
|
|
#include <FspEas.h>
|
2016-10-21 07:49:24 +02:00
|
|
|
#include <FspStatusCode.h>
|
2022-08-10 02:35:50 +02:00
|
|
|
#include <FspGlobalData.h>
|
|
|
|
#include <Library/FspCommonLib.h>
|
2016-05-13 07:00:53 +02:00
|
|
|
|
|
|
|
extern EFI_GUID gFspHobGuid;
|
|
|
|
|
2021-12-16 09:10:20 +01:00
|
|
|
/**
|
|
|
|
Get the FSP M UPD Data address
|
|
|
|
|
|
|
|
@return FSP-M UPD Data Address
|
|
|
|
**/
|
|
|
|
UINTN
|
|
|
|
GetFspmUpdDataAddress (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (PcdGet64 (PcdFspmUpdDataAddress64) != 0) {
|
2022-07-19 06:08:31 +02:00
|
|
|
return (UINTN)PcdGet64 (PcdFspmUpdDataAddress64);
|
2021-12-16 09:10:20 +01:00
|
|
|
} else {
|
2022-07-19 06:08:31 +02:00
|
|
|
return (UINTN)PcdGet32 (PcdFspmUpdDataAddress);
|
2021-12-16 09:10:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 07:00:53 +02:00
|
|
|
/**
|
|
|
|
Call FspMemoryInit API.
|
|
|
|
|
|
|
|
@return Status returned by FspMemoryInit API.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
PeiFspMemoryInit (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
FSP_INFO_HEADER *FspmHeaderPtr;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT64 TimeStampCounterStart;
|
|
|
|
VOID *FspHobListPtr;
|
|
|
|
VOID *HobData;
|
2022-04-15 10:37:41 +02:00
|
|
|
VOID *FspmUpdDataPtr;
|
2016-05-13 07:00:53 +02:00
|
|
|
UINTN *SourceData;
|
|
|
|
|
|
|
|
DEBUG ((DEBUG_INFO, "PeiFspMemoryInit enter\n"));
|
|
|
|
|
|
|
|
FspHobListPtr = NULL;
|
2017-11-23 03:22:45 +01:00
|
|
|
FspmUpdDataPtr = NULL;
|
2016-05-13 07:00:53 +02:00
|
|
|
|
2018-11-22 02:44:28 +01:00
|
|
|
FspmHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress));
|
2016-06-30 03:13:24 +02:00
|
|
|
DEBUG ((DEBUG_INFO, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr));
|
|
|
|
if (FspmHeaderPtr == NULL) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2021-12-16 09:10:20 +01:00
|
|
|
if ((GetFspmUpdDataAddress () == 0) && (FspmHeaderPtr->CfgRegionSize != 0) && (FspmHeaderPtr->CfgRegionOffset != 0)) {
|
2017-11-23 03:22:45 +01:00
|
|
|
//
|
|
|
|
// Copy default FSP-M UPD data from Flash
|
|
|
|
//
|
2022-04-15 10:37:41 +02:00
|
|
|
FspmUpdDataPtr = AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);
|
2017-11-23 03:22:45 +01:00
|
|
|
ASSERT (FspmUpdDataPtr != NULL);
|
|
|
|
SourceData = (UINTN *)((UINTN)FspmHeaderPtr->ImageBase + (UINTN)FspmHeaderPtr->CfgRegionOffset);
|
|
|
|
CopyMem (FspmUpdDataPtr, SourceData, (UINTN)FspmHeaderPtr->CfgRegionSize);
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// External UPD is ready, get the buffer from PCD pointer.
|
|
|
|
//
|
2022-07-19 06:08:31 +02:00
|
|
|
FspmUpdDataPtr = (VOID *)GetFspmUpdDataAddress ();
|
2017-11-23 03:22:45 +01:00
|
|
|
ASSERT (FspmUpdDataPtr != NULL);
|
|
|
|
}
|
2016-05-13 07:00:53 +02:00
|
|
|
|
2016-05-18 14:40:01 +02:00
|
|
|
DEBUG ((DEBUG_INFO, "UpdateFspmUpdData enter\n"));
|
2022-04-15 10:37:41 +02:00
|
|
|
UpdateFspmUpdData (FspmUpdDataPtr);
|
|
|
|
if (((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.Revision >= 3) {
|
|
|
|
DEBUG ((DEBUG_INFO, " StackBase - 0x%lx\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.StackBase));
|
|
|
|
DEBUG ((DEBUG_INFO, " StackSize - 0x%lx\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.StackSize));
|
|
|
|
DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.BootLoaderTolumSize));
|
|
|
|
DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", ((FSPM_UPD_COMMON_FSP24 *)FspmUpdDataPtr)->FspmArchUpd.BootMode));
|
|
|
|
} else {
|
|
|
|
DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.NvsBufferPtr));
|
|
|
|
DEBUG ((DEBUG_INFO, " StackBase - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.StackBase));
|
|
|
|
DEBUG ((DEBUG_INFO, " StackSize - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.StackSize));
|
|
|
|
DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.BootLoaderTolumSize));
|
|
|
|
DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", ((FSPM_UPD_COMMON *)FspmUpdDataPtr)->FspmArchUpd.BootMode));
|
|
|
|
}
|
2022-07-19 06:08:31 +02:00
|
|
|
|
2016-05-13 07:00:53 +02:00
|
|
|
DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", &FspHobListPtr));
|
|
|
|
|
|
|
|
TimeStampCounterStart = AsmReadTsc ();
|
|
|
|
Status = CallFspMemoryInit (FspmUpdDataPtr, &FspHobListPtr);
|
2016-06-17 04:38:09 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
|
|
|
|
//
|
|
|
|
if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
|
2022-08-10 02:35:50 +02:00
|
|
|
DEBUG ((DEBUG_INFO, "FspMemoryInitApi requested reset %r\n", Status));
|
2022-07-19 06:08:31 +02:00
|
|
|
CallFspWrapperResetSystem (Status);
|
2016-06-17 04:38:09 +02:00
|
|
|
}
|
|
|
|
|
2022-08-10 02:35:50 +02:00
|
|
|
if ((Status != FSP_STATUS_VARIABLE_REQUEST) && EFI_ERROR (Status)) {
|
2016-05-13 07:00:53 +02:00
|
|
|
DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspMemoryInitApi(), Status = %r\n", Status));
|
2022-08-10 02:35:50 +02:00
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG ((DEBUG_INFO, "FspMemoryInit status: %r\n", Status));
|
|
|
|
if (Status == FSP_STATUS_VARIABLE_REQUEST) {
|
|
|
|
//
|
|
|
|
// call to Variable request handler
|
|
|
|
//
|
|
|
|
FspWrapperVariableRequestHandler (&FspHobListPtr, FspMultiPhaseMemInitApiIndex);
|
2016-05-13 07:00:53 +02:00
|
|
|
}
|
|
|
|
|
2022-08-10 02:35:50 +02:00
|
|
|
//
|
|
|
|
// See if MultiPhase process is required or not
|
|
|
|
//
|
|
|
|
FspWrapperMultiPhaseHandler (&FspHobListPtr, FspMultiPhaseMemInitApiIndex); // FspM MultiPhase
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create hobs after memory initialization and not in temp RAM. Hence passing the recorded timestamp here
|
|
|
|
//
|
|
|
|
PERF_START_EX (&gFspApiPerformanceGuid, "EventRec", NULL, TimeStampCounterStart, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
|
|
|
|
PERF_END_EX (&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
|
|
|
|
DEBUG ((DEBUG_INFO, "Total time spent executing FspMemoryInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));
|
2016-05-13 07:00:53 +02:00
|
|
|
|
|
|
|
Status = TestFspMemoryInitApiOutput (FspmUpdDataPtr, &FspHobListPtr);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((DEBUG_ERROR, "ERROR - TestFspMemoryInitApiOutput () fail, Status = %r\n", Status));
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG ((DEBUG_INFO, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr));
|
|
|
|
ASSERT (FspHobListPtr != NULL);
|
|
|
|
|
|
|
|
PostFspmHobProcess (FspHobListPtr);
|
|
|
|
|
|
|
|
//
|
|
|
|
// FspHobList is not complete at this moment.
|
|
|
|
// Save FspHobList pointer to hob, so that it can be got later
|
|
|
|
//
|
|
|
|
HobData = BuildGuidHob (
|
|
|
|
&gFspHobGuid,
|
|
|
|
sizeof (VOID *)
|
|
|
|
);
|
|
|
|
ASSERT (HobData != NULL);
|
|
|
|
CopyMem (HobData, &FspHobListPtr, sizeof (FspHobListPtr));
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Do FSP initialization.
|
|
|
|
|
|
|
|
@return FSP initialization status.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FspmWrapperInit (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2020-08-18 08:26:14 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PEI_FIRMWARE_VOLUME_INFO_MEASUREMENT_EXCLUDED_PPI *MeasurementExcludedFvPpi;
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR *MeasurementExcludedPpiList;
|
2021-12-05 23:54:00 +01:00
|
|
|
|
2020-08-18 08:26:14 +02:00
|
|
|
MeasurementExcludedFvPpi = AllocatePool (sizeof (*MeasurementExcludedFvPpi));
|
|
|
|
ASSERT (MeasurementExcludedFvPpi != NULL);
|
|
|
|
MeasurementExcludedFvPpi->Count = 1;
|
|
|
|
MeasurementExcludedFvPpi->Fv[0].FvBase = PcdGet32 (PcdFspmBaseAddress);
|
|
|
|
MeasurementExcludedFvPpi->Fv[0].FvLength = ((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FvLength;
|
2021-12-05 23:54:00 +01:00
|
|
|
|
2020-08-18 08:26:14 +02:00
|
|
|
MeasurementExcludedPpiList = AllocatePool (sizeof (*MeasurementExcludedPpiList));
|
|
|
|
ASSERT (MeasurementExcludedPpiList != NULL);
|
|
|
|
MeasurementExcludedPpiList->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
|
|
|
|
MeasurementExcludedPpiList->Guid = &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid;
|
|
|
|
MeasurementExcludedPpiList->Ppi = MeasurementExcludedFvPpi;
|
2016-05-13 07:00:53 +02:00
|
|
|
|
2018-11-22 02:44:28 +01:00
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
|
2018-11-22 03:51:21 +01:00
|
|
|
if (PcdGet8 (PcdFspModeSelection) == 1) {
|
2018-11-22 02:44:28 +01:00
|
|
|
Status = PeiFspMemoryInit ();
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
} else {
|
2020-08-18 08:26:14 +02:00
|
|
|
Status = PeiServicesInstallPpi (MeasurementExcludedPpiList);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2018-11-22 02:44:28 +01:00
|
|
|
PeiServicesInstallFvInfoPpi (
|
2023-05-22 08:13:06 +02:00
|
|
|
&((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FileSystemGuid,
|
2018-11-22 02:44:28 +01:00
|
|
|
(VOID *)(UINTN)PcdGet32 (PcdFspmBaseAddress),
|
|
|
|
(UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FvLength,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
2016-05-13 07:00:53 +02:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:26:14 +02:00
|
|
|
/**
|
|
|
|
This function is called after TCG installed PPI.
|
|
|
|
|
|
|
|
@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_STATUS Always return EFI_SUCCESS
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
TcgPpiNotify (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
|
|
|
|
IN VOID *Ppi
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_PEI_NOTIFY_DESCRIPTOR mTcgPpiNotifyDesc = {
|
|
|
|
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
|
|
|
&gEdkiiTcgPpiGuid,
|
|
|
|
TcgPpiNotify
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function is called after TCG installed PPI.
|
|
|
|
|
|
|
|
@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_STATUS Always return EFI_SUCCESS
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
TcgPpiNotify (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
|
|
|
|
IN VOID *Ppi
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 FspMeasureMask;
|
|
|
|
|
|
|
|
DEBUG ((DEBUG_INFO, "TcgPpiNotify FSPM\n"));
|
|
|
|
|
|
|
|
FspMeasureMask = PcdGet32 (PcdFspMeasurementConfig);
|
|
|
|
|
|
|
|
if ((FspMeasureMask & FSP_MEASURE_FSPT) != 0) {
|
|
|
|
MeasureFspFirmwareBlob (
|
|
|
|
0,
|
|
|
|
"FSPT",
|
|
|
|
PcdGet32 (PcdFsptBaseAddress),
|
|
|
|
(UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFsptBaseAddress))->FvLength
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((FspMeasureMask & FSP_MEASURE_FSPM) != 0) {
|
|
|
|
MeasureFspFirmwareBlob (
|
|
|
|
0,
|
|
|
|
"FSPM",
|
|
|
|
PcdGet32 (PcdFspmBaseAddress),
|
|
|
|
(UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspmBaseAddress))->FvLength
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-05-13 07:00:53 +02:00
|
|
|
/**
|
|
|
|
This is the entrypoint of PEIM
|
|
|
|
|
|
|
|
@param[in] FileHandle Handle of the file being invoked.
|
|
|
|
@param[in] PeiServices Describes the list of possible PEI Services.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS if it completed successfully.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FspmWrapperPeimEntryPoint (
|
|
|
|
IN EFI_PEI_FILE_HANDLE FileHandle,
|
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices
|
|
|
|
)
|
|
|
|
{
|
2020-08-18 08:26:14 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2016-05-13 07:00:53 +02:00
|
|
|
DEBUG ((DEBUG_INFO, "FspmWrapperPeimEntryPoint\n"));
|
|
|
|
|
2020-08-18 08:26:14 +02:00
|
|
|
Status = PeiServicesNotifyPpi (&mTcgPpiNotifyDesc);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2016-05-13 07:00:53 +02:00
|
|
|
FspmWrapperInit ();
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|