[PATCH v3 08/28] AmpereAltraPkg: Add BootProgress support


Nhi Pham
 

From: Quan Nguyen <quan@os.amperecomputing.com>

BootProgress will send 32-bit UEFI Status Code via doorbell to report
its progress status.
Currently support reporting Progress Status Code and Error Status Code
only. Other types of Status Code are ignored.

Cc: Thang Nguyen <thang@os.amperecomputing.com>
Cc: Chuong Tran <chuong@os.amperecomputing.com>
Cc: Phong Vo <phong@os.amperecomputing.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
---
Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc | 2 +
Platform/Ampere/JadePkg/Jade.fdf | 2 +
Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.inf | 51 +++++
Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.inf | 49 +++++
Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.c | 211 ++++++++++++++++++++
Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.c | 210 +++++++++++++++++++
Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.uni | 16 ++
Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.uni | 18 ++
8 files changed, 559 insertions(+)

diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc
index 5f7a56133777..bb144183164d 100644
--- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc
+++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc
@@ -537,6 +537,7 @@ [Components.common]
}
MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf
MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
+ Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.inf

#
# DXE Phase modules
@@ -547,6 +548,7 @@ [Components.common]
}
MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf
MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf
+ Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.inf

#
# PCD
diff --git a/Platform/Ampere/JadePkg/Jade.fdf b/Platform/Ampere/JadePkg/Jade.fdf
index 80a86d7c1156..1857296a8ea5 100644
--- a/Platform/Ampere/JadePkg/Jade.fdf
+++ b/Platform/Ampere/JadePkg/Jade.fdf
@@ -102,6 +102,7 @@ [FV.FVMAIN_COMPACT]
INF Silicon/Ampere/AmpereAltraPkg/Drivers/ATFHobPei/ATFHobPeim.inf
INF Silicon/Ampere/AmpereAltraPkg/Drivers/MemoryInitPeim/MemoryInitPeim.inf
INF Silicon/Ampere/AmpereAltraPkg/Drivers/MmCommunicationPei/MmCommunicationPei.inf
+ INF Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.inf
INF ArmPkg/Drivers/CpuPei/CpuPei.inf
INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
@@ -149,6 +150,7 @@ [FV.FvMain]
INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf
INF MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf
+ INF Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.inf

#
# PI DXE Drivers producing Architectural Protocols (EFI Services)
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.inf
new file mode 100644
index 000000000000..2211a213a6df
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.inf
@@ -0,0 +1,51 @@
+## @file
+# This module installs Boot Progress Dxe.
+#
+# This module registers report status code listener to report boot progress
+# to SMpro.
+#
+# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = BootProgressDxe
+ MODULE_UNI_FILE = BootProgressDxe.uni
+ FILE_GUID = 6E12F248-F0C1-11EA-B37C-9798918A2163
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = BootProgressDxeEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = AARCH64
+#
+
+[Sources]
+ BootProgressDxe.c
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec
+
+[LibraryClasses]
+ AmpereCpuLib
+ BaseLib
+ DebugLib
+ DxeServicesLib
+ SystemFirmwareInterfaceLib
+ UefiBootServicesTableLib
+ UefiDriverEntryPoint
+ UefiLib
+ UefiRuntimeServicesTableLib
+
+[Protocols]
+ gEfiRscHandlerProtocolGuid ## CONSUMES
+
+[Depex]
+ gEfiRscHandlerProtocolGuid
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.inf
new file mode 100644
index 000000000000..1dd0ec31ac37
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.inf
@@ -0,0 +1,49 @@
+## @file
+# Boot Progress Pei Module.
+#
+# Updates to SCP with Boot Progress information during boot.
+#
+# This module register report status code listener to collect boot progress
+# information and keep SCP posted.
+#
+# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = BootProgressPeim
+ MODULE_UNI_FILE = BootProgressPeim.uni
+ FILE_GUID = 2E8A3B3E-F26C-11EA-BDE5-6726AD8F88BD
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ ENTRY_POINT = BootProgressPeiEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = AARCH64
+#
+
+[Sources]
+ BootProgressPeim.c
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ PeiServicesLib
+ PeimEntryPoint
+ SystemFirmwareInterfaceLib
+
+[Ppis]
+ gEfiPeiRscHandlerPpiGuid ## CONSUMES
+
+[Depex]
+ gEfiPeiRscHandlerPpiGuid
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.c
new file mode 100644
index 000000000000..f87a4d53179f
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.c
@@ -0,0 +1,211 @@
+/** @file
+
+ This module installs Boot Progress Dxe that report boot progress to SMpro.
+
+ This module registers report status code listener to report boot progress
+ to SMpro.
+
+ Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiDxe.h>
+
+#include <Library/AmpereCpuLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DxeServicesLib.h>
+#include <Library/SystemFirmwareInterfaceLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Pi/PiStatusCode.h>
+#include <Protocol/ReportStatusCodeHandler.h>
+
+typedef struct {
+ UINT8 Byte;
+ EFI_STATUS_CODE_VALUE Value;
+} STATUS_CODE_TO_CHECKPOINT;
+
+enum BOOT_PROGRESS_STATE {
+ BOOT_NOTSTART = 0,
+ BOOT_START = 1,
+ BOOT_COMPLETE = 2,
+ BOOT_FAILED = 3,
+};
+
+UINT32 DxeProgressCode[] = {
+ (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT), // DXE Core is started
+ (EFI_COMPUTING_UNIT_CHIPSET | EFI_CHIPSET_PC_DXE_HB_INIT), // PCI host bridge initialization
+ (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT), // Boot Device Selection (BDS) phase is started 
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS), // Driver connecting is started
+ (EFI_IO_BUS_PCI | EFI_IOB_PC_INIT), // PCI Bus initialization is started
+ (EFI_IO_BUS_PCI | EFI_IOB_PCI_HPC_INIT), // PCI Bus Hot Plug Controller Initialization
+ (EFI_IO_BUS_PCI | EFI_IOB_PCI_BUS_ENUM), // PCI Bus Enumeration
+ (EFI_IO_BUS_PCI | EFI_IOB_PCI_RES_ALLOC), // PCI Bus Request Resources
+ (EFI_IO_BUS_PCI | EFI_IOB_PC_ENABLE), // PCI Bus Assign Resources
+ (EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_PC_INIT), // Console Output devices connect
+ (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_INIT), // Console input devices connect
+ (EFI_IO_BUS_LPC | EFI_IOB_PC_INIT), // Super IO Initialization
+ (EFI_IO_BUS_USB | EFI_IOB_PC_INIT), // USB initialization is started
+ (EFI_IO_BUS_USB | EFI_IOB_PC_RESET), // USB Reset
+ (EFI_IO_BUS_USB | EFI_IOB_PC_DETECT), // USB Detect
+ (EFI_IO_BUS_USB | EFI_IOB_PC_ENABLE), // USB Enable
+ (EFI_IO_BUS_SCSI | EFI_IOB_PC_INIT), // SCSI initialization is started
+ (EFI_IO_BUS_SCSI | EFI_IOB_PC_RESET), // SCSI Reset
+ (EFI_IO_BUS_SCSI | EFI_IOB_PC_DETECT), // SCSI Detect
+ (EFI_IO_BUS_SCSI | EFI_IOB_PC_ENABLE), // SCSI Enable
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_VERIFYING_PASSWORD), // Setup Verifying Password
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP), // Start of Setup
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_INPUT_WAIT), // Setup Input Wait
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT), // Ready To Boot event
+ (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES), // Exit Boot Services event
+ (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_SET_VIRTUAL_ADDRESS_MAP), // Runtime Set Virtual Address MAP Begin
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_VIRTUAL_ADDRESS_CHANGE_EVENT), // Runtime Set Virtual Address MAP End
+ (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM), // System Reset
+ (EFI_IO_BUS_USB | EFI_IOB_PC_HOTPLUG), // USB hot plug
+ (EFI_IO_BUS_PCI | EFI_IOB_PC_HOTPLUG), // PCI bus hot plug
+ 0 // Must ended by 0
+};
+
+UINT32 DxeErrorCode[] = {
+ (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_EC_NO_ARCH), // Some of the Architectural Protocols are not available
+ (EFI_IO_BUS_PCI | EFI_IOB_EC_RESOURCE_CONFLICT), // PCI resource allocation error. Out of Resources
+ (EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_NOT_DETECTED), // No Console Output Devices are found
+ (EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_NOT_DETECTED), // No Console Input Devices are found
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_INVALID_PASSWORD), // Invalid password
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR), // Error loading Boot Option (LoadImage returned error)
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED), // Boot Option is failed (StartImage returned error)
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UPDATE_FAIL), // Flash update is failed
+ (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_PS_EC_RESET_NOT_AVAILABLE), // Reset protocol is not available
+ 0 // Must end by 0
+};
+
+EFI_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;
+
+STATIC UINT8 mBootstate = BOOT_START;
+
+STATIC
+BOOLEAN
+StatusCodeFilter (
+ UINT32 *Map,
+ EFI_STATUS_CODE_VALUE Value
+ )
+{
+ UINTN Index = 0;
+
+ while (Map[Index] != 0) {
+ if (Map[Index] == Value) {
+ return TRUE;
+ }
+ Index++;
+ }
+ return FALSE;
+}
+
+/**
+ Report status code listener of Boot Progress Dxe.
+
+ @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
+BootProgressListenerDxe (
+ 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
+ )
+{
+ BOOLEAN IsProgress = FALSE;
+ BOOLEAN IsError = FALSE;
+
+ if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
+ IsProgress = StatusCodeFilter (DxeProgressCode, Value);
+ } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
+ IsError = StatusCodeFilter (DxeErrorCode, Value);
+ } else {
+ return EFI_SUCCESS;
+ }
+
+ if (!IsProgress && !IsError) {
+ return EFI_SUCCESS;
+ }
+
+ DEBUG ((
+ DEBUG_INFO,
+ "BootProgressDxe: CodeType=0x%X Value=0x%X Instance=0x%X CallerIdGuid=%g Data=%p\n",
+ CodeType,
+ Value,
+ Instance,
+ CallerId,
+ Data
+ ));
+
+ if (IsError) {
+ mBootstate = BOOT_FAILED;
+ } else if (Value == (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)) {
+ /* Set boot complete when reach to ReadyToBoot event */
+ mBootstate = BOOT_COMPLETE;
+ }
+
+ MailboxMsgSetBootProgress (0, mBootstate, Value);
+
+ if (Value == (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES) &&
+ mRscHandlerProtocol != NULL)
+ {
+ mRscHandlerProtocol->Unregister (BootProgressListenerDxe);
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+/**
+ The module Entry Point of the Firmware Performance Data Table DXE driver.
+
+ @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
+BootProgressDxeEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Get Report Status Code Handler Protocol.
+ //
+ Status = gBS->LocateProtocol (&gEfiRscHandlerProtocolGuid, NULL, (VOID **)&mRscHandlerProtocol);
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Register report status code listener for OS Loader load and start.
+ //
+ if (!EFI_ERROR (Status)) {
+ Status = mRscHandlerProtocol->Register (BootProgressListenerDxe, TPL_HIGH_LEVEL);
+ }
+ ASSERT_EFI_ERROR (Status);
+
+ return EFI_SUCCESS;
+}
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.c
new file mode 100644
index 000000000000..c677e27a00ce
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.c
@@ -0,0 +1,210 @@
+/** @file
+
+ This module installs Boot Progress Pei to report boot progress to SMpro.
+
+ This module registers report status code listener to report boot progress
+ to SMpro.
+
+ Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiPei.h>
+
+#include <Library/AmpereCpuLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/SystemFirmwareInterfaceLib.h>
+#include <Pi/PiStatusCode.h>
+#include <Ppi/ReportStatusCodeHandler.h>
+
+enum BOOT_PROGRESS_STATE {
+ BOOT_NOTSTART = 0,
+ BOOT_START = 1,
+ BOOT_COMPLETE = 2,
+ BOOT_FAILED = 3,
+};
+
+UINT32 PeiProgressStatusCode[] = {
+ // Regular boot
+ (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_PC_ENTRY_POINT), // PEI Core is started
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_PC_POWER_ON_INIT), // Pre-memory CPU initialization is started
+ (EFI_SOFTWARE_PEI_SERVICE | EFI_SW_PS_PC_INSTALL_PEI_MEMORY), // Memory Installed
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_PC_INIT_BEGIN), // CPU post-memory initialization is started
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_PC_CACHE_INIT), // CPU post-memory initialization. Cache initialization
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_PC_AP_INIT), // CPU post-memory initialization. Application Processor(s) (AP) initialization
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_PC_BSP_SELECT), // CPU post-memory initialization. Boot Strap Processor (BSP) selection
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_PC_SMM_INIT), // CPU post-memory initialization. System Management Mode (SMM) initialization
+ // DXE IPL is started
+ (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT), // DXE IPL is started
+ // DXE Core is started
+ (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT), // DXE Core is started
+ // Recovery
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_RECOVERY_AUTO), // Recovery condition triggered by firmware (Auto recovery)
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_RECOVERY_USER), // Recovery condition triggered by user (Forced recovery)
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_RECOVERY_BEGIN), // Recovery process started
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_CAPSULE_LOAD), // Recovery firmware image is found
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_CAPSULE_START), // Recovery firmware image is loaded
+ // S3
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_S3_BOOT_SCRIPT), // S3 Boot Script execution
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_OS_WAKE), // OS S3 wake vector call
+ 0 // Must end with 0
+};
+
+UINT32 PeiErrorStatusCode[] = {
+ // Regular boot
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_INVALID_TYPE), // Memory initialization error. Invalid memory type
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_INVALID_SPEED), // Memory initialization error. Incompatible memory speed
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_SPD_FAIL), // Memory initialization error. SPD reading has failed
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_INVALID_SIZE), // Memory initialization error. Invalid memory size
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_MISMATCH), // Memory initialization error. Memory modules do not match
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_NONE_DETECTED), // Memory initialization error. No usable memory detected
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_NONE_USEFUL), // Memory initialization error. No usable memory detected
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_EC_NON_SPECIFIC), // Unspecified memory initialization error.
+ (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_EC_MEMORY_NOT_INSTALLED), // Memory not installed
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_INVALID_TYPE), // Invalid CPU type
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_INVALID_SPEED), // Invalid CPU Speed
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_MISMATCH), // CPU mismatch
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_SELF_TEST), // CPU self test failed
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_CACHE), // possible CPU cache error
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_INTERNAL), // Internal CPU error
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_EC_NON_SPECIFIC), // Internal CPU error
+ (EFI_SOFTWARE_PEI_SERVICE | EFI_SW_PS_EC_RESET_NOT_AVAILABLE), // reset PPI is not available
+ // Recovery
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_RECOVERY_PPI_NOT_FOUND), // Recovery PPI is not available
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_NO_RECOVERY_CAPSULE), // Recovery capsule is not found
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_INVALID_CAPSULE_DESCRIPTOR), // Invalid recovery capsule
+ // S3 Resume
+ (EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_S3_RESUME_FAIL), // S3 Resume Failed
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_RESUME_PPI_NOT_FOUND), // S3 Resume PPI not found
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_BOOT_SCRIPT_ERROR), // S3 Resume Boot Script Error
+ (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_OS_WAKE_ERROR), // S3 OS Wake Error
+ 0
+};
+
+// Should always be BOOT_START when start
+STATIC UINT8 mBootstate = BOOT_START;
+
+STATIC
+BOOLEAN
+StatusCodeFilter (
+ UINT32 *Map,
+ EFI_STATUS_CODE_VALUE Value
+ )
+{
+ UINTN Index = 0;
+
+ while (Map[Index] != 0) {
+ if (Map[Index] == Value) {
+ return TRUE;
+ }
+ Index++;
+ }
+
+ return FALSE;
+}
+
+/**
+ Report status code listener for PEI. This is used to record the boot progress info
+ and report it to SMpro.
+
+ @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
+ @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
+BootProgressListenerPei (
+ 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
+ )
+{
+ BOOLEAN IsProgress = FALSE;
+ BOOLEAN IsError = FALSE;
+
+ if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
+ IsProgress = StatusCodeFilter (PeiProgressStatusCode, Value);
+ } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
+ IsError = StatusCodeFilter (PeiErrorStatusCode, Value);
+ } else {
+ return EFI_SUCCESS;
+ }
+
+ // No interested status found
+ if (!IsProgress && !IsError) {
+ return EFI_SUCCESS;
+ }
+
+ DEBUG ((
+ DEBUG_INFO,
+ "BootProgressPeim: CodeType=0x%X Value=0x%X Instance=0x%X CallerIdGuid=%g Data=%p\n",
+ CodeType,
+ Value,
+ Instance,
+ CallerId,
+ Data
+ ));
+
+ if (IsError) {
+ mBootstate = BOOT_FAILED;
+ }
+
+ MailboxMsgSetBootProgress (0, mBootstate, Value);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Main entry for Boot Progress PEIM.
+
+ This routine is to register report status code listener for Boot Progress PEIM.
+
+ @param[in] FileHandle Handle of the file being invoked.
+ @param[in] PeiServices Pointer to PEI Services table.
+
+ @retval EFI_SUCCESS Report status code listener is registered successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+BootProgressPeiEntryPoint (
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
+ )
+{
+ EFI_STATUS Status;
+ EFI_PEI_RSC_HANDLER_PPI *RscHandler;
+
+ Status = PeiServicesLocatePpi (
+ &gEfiPeiRscHandlerPpiGuid,
+ 0,
+ NULL,
+ (VOID **)&RscHandler
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ if (!EFI_ERROR (Status)) {
+ Status = RscHandler->Register (BootProgressListenerPei);
+ }
+ ASSERT_EFI_ERROR (Status);
+
+ return EFI_SUCCESS;
+}
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.uni b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.uni
new file mode 100644
index 000000000000..492e85404631
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressDxe/BootProgressDxe.uni
@@ -0,0 +1,16 @@
+//
+// This module installs Boot Progress Dxe that report boot progress to SMpro.
+//
+// This module registers report status code listener to report boot progress
+// for SMpro.
+//
+// Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Installs Boot Progress Driver"
+
+#string STR_MODULE_DESCRIPTION #language en-US "This module registers report status code listener to collect and report boot progress to SMpro."
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.uni b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.uni
new file mode 100644
index 000000000000..0371fc4f9a80
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.uni
@@ -0,0 +1,18 @@
+//
+// Boot Progress Pei Module.
+//
+// Updates to SCP with Boot Progress information during boot
+//
+// This module register report status code listener to collect boot progress
+// information and keep SCP posted.
+//
+// Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Boot Progress Pei Module."
+
+#string STR_MODULE_DESCRIPTION #language en-US "Updates SCP with boot progress information during boot. This module register report status code listener to collect boot progress information and post to SCP."
--
2.17.1