alder_lake_bios/Insyde/InsydeModulePkg/Universal/StatusCode/DdtStatusCodePei/DdtStatusCodePei.c

292 lines
9.2 KiB
C

/** @file
PEI Module for DDT Report Status Code
;******************************************************************************
;* Copyright (c) 2012 - 2017, Insyde Software Corp. All Rights Reserved.
;*
;* You may not reproduce, distribute, publish, display, perform, modify, adapt,
;* transmit, broadcast, present, recite, release, license or otherwise exploit
;* any part of this publication in any form, by any means, without the prior
;* written permission of Insyde Software Corporation.
;*
;******************************************************************************
*/
#include <Ppi/ReportStatusCodeHandler.h>
#include <Guid/StatusCodeDataTypeId.h>
#include <Guid/StatusCodeDataTypeDebug.h>
#include <Library/DebugLib.h>
#include <Library/PrintLib.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/HobLib.h>
#include <Library/PcdLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/BaseMemoryLib.h>
#include <Library/H2ODebugLib.h>
EFI_STATUS
EFIAPI
RscHandlerPpiNotifyCallback (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
IN VOID *Ppi
);
EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnRscHandlerPpiList = {
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiRscHandlerPpiGuid,
RscHandlerPpiNotifyCallback
};
/**
Convert status code value and extended data to readable ASCII string, send string to H2O DDT.
@param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
@param CodeType Indicates the type of status code being reported.
@param Value Describes the current status of a hardware or
software entity. This includes information about the class and
subclass that is used to classify the entity as well as an operation.
For progress codes, the operation is the current activity.
For error codes, it is the exception.For debug codes,it is not defined at this time.
@param Instance The enumeration of a hardware or software entity within
the system. A system may contain multiple entities that match a class/subclass
pairing. The instance differentiates between them. An instance of 0 indicates
that instance information is unavailable, not meaningful, or not relevant.
Valid instance numbers start with 1.
@param 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 Data This optional parameter may be used to pass additional data.
@retval EFI_SUCCESS Status code reported to H2O DDT successfully.
**/
EFI_STATUS
EFIAPI
DdtStatusCodeReportWorker (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN CONST EFI_GUID *CallerId,
IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
)
{
CHAR8 *Filename;
CHAR8 *Description;
CHAR8 *Format;
CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
UINT32 ErrorLevel;
UINT32 LineNumber;
UINTN CharCount;
BASE_LIST Marker;
CharCount = 0;
Buffer[0] = '\0';
if (Data != NULL &&
ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
//
// Print ASSERT() information into output buffer.
//
CharCount = AsciiSPrint (
Buffer,
sizeof (Buffer),
"\n\rPEI_ASSERT!: %a (%d): %a",
Filename,
LineNumber,
Description
);
} else if (Data != NULL &&
ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
//
// Print DEBUG() information into output buffer.
//
CharCount = AsciiBSPrint (
Buffer,
sizeof (Buffer),
Format,
Marker
);
} else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
//
// Print ERROR information into output buffer.
//
CharCount = AsciiSPrint (
Buffer,
sizeof (Buffer),
"ERROR: C%x:V%x I%x",
CodeType,
Value,
Instance
);
ASSERT(CharCount > 0);
if (CallerId != NULL) {
CharCount += AsciiSPrint (
&Buffer[CharCount],
(sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
" %g",
CallerId
);
}
if (Data != NULL) {
CharCount += AsciiSPrint (
&Buffer[CharCount],
(sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
" %x",
Data
);
}
} else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
if (FeaturePcdGet(PcdDdtStatusCodeReportsProgressCode)) {
//
// Print PROGRESS information into output buffer.
//
CharCount = AsciiSPrint (
Buffer,
sizeof (Buffer),
"PROGRESS CODE: V%x I%x",
Value,
Instance
);
}
} else if (Data != NULL &&
CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) &&
((EFI_STATUS_CODE_STRING_DATA *) Data)->StringType == EfiStringAscii) {
//
// EFI_STATUS_CODE_STRING_DATA
//
CharCount = AsciiSPrint (
Buffer,
sizeof (Buffer),
"%a",
((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii
);
} else {
//
// Code type is not defined.
//
CharCount = AsciiSPrint (
Buffer,
sizeof (Buffer),
"Undefined: C%x:V%x I%x",
CodeType,
Value,
Instance
);
}
//
// Call DDTPrint function to do print.
//
if (CharCount > 0) {
if (Buffer[CharCount - 2] == 0x0D && Buffer[CharCount - 1] == 0x0A) {
//
// Truncate the new line characters at the end of the line
// DDTPrint will add additional new line automatically
//
Buffer[CharCount - 2] = '\0';
Buffer[CharCount - 1] = '\0';
}
DDTPrint ((CHAR8 *) Buffer);
}
return EFI_SUCCESS;
}
/**
Notification service to be called when gEfiPeiRscHandlerPpiGuid is installed.
@param PeiServices Indirect reference to the PEI Services Table.
@param NotifyDescriptor Address of the notification descriptor data structure. Type
EFI_PEI_NOTIFY_DESCRIPTOR is defined above.
@param Ppi Address of the PPI that was installed.
@retval EFI_STATUS This function will install a PPI to PPI database. The status
code will be the code for (*PeiServices)->InstallPpi.
**/
EFI_STATUS
EFIAPI
RscHandlerPpiNotifyCallback (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
IN VOID *Ppi
)
{
EFI_STATUS Status;
EFI_PEI_RSC_HANDLER_PPI *RscHandlerPpi;
Status = PeiServicesLocatePpi (
&gEfiPeiRscHandlerPpiGuid,
0,
NULL,
(VOID **) &RscHandlerPpi
);
if (!EFI_ERROR(Status)) {
//
// Dispatch initialization request to sub-statuscode-devices.
//
if (FeaturePcdGet (PcdStatusCodeUseDdt)) {
Status = RscHandlerPpi->Register (DdtStatusCodeReportWorker);
}
}
ASSERT_EFI_ERROR (Status);
return Status;
}
/**
Entry point of DDT Status Code PEIM.
This function is the entry point of this Status Code PEIM.
It initializes supported status code devices according to PCD settings,
and installs Status Code PPI.
@param FileHandle Handle of the file being invoked.
@param PeiServices Describes the list of possible PEI Services.
@retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.
**/
EFI_STATUS
EFIAPI
DdtStatusCodePeiEntry (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
EFI_PEI_RSC_HANDLER_PPI *RscHandlerPpi;
Status = PeiServicesLocatePpi (
&gEfiPeiRscHandlerPpiGuid,
0,
NULL,
(VOID **) &RscHandlerPpi
);
if (EFI_ERROR(Status)) {
return (*PeiServices)->NotifyPpi (PeiServices, &mNotifyOnRscHandlerPpiList);
}
//
// Dispatch initialization request to sub-statuscode-devices.
//
if (FeaturePcdGet (PcdStatusCodeUseDdt)) {
Status = RscHandlerPpi->Register (DdtStatusCodeReportWorker);
}
ASSERT_EFI_ERROR (Status);
return Status;
}