public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Leif Lindholm" <leif@nuviainc.com>
To: Nhi Pham <nhi@os.amperecomputing.com>
Cc: devel@edk2.groups.io, Quan Nguyen <quan@os.amperecomputing.com>,
	Thang Nguyen <thang@os.amperecomputing.com>,
	Chuong Tran <chuong@os.amperecomputing.com>,
	Phong Vo <phong@os.amperecomputing.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Nate DeSimone <nathaniel.l.desimone@intel.com>
Subject: Re: [edk2-platforms][PATCH v2 08/32] AmpereAltraPkg: Add BootProgress support
Date: Sat, 5 Jun 2021 00:27:53 +0100	[thread overview]
Message-ID: <20210604232753.pc5gu5ggitiyqfqo@leviathan> (raw)
In-Reply-To: <20210526100724.5359-10-nhi@os.amperecomputing.com>


On Wed, May 26, 2021 at 17:07:00 +0700, Nhi Pham wrote:
> 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>

This looks like something that would be a good target to commonalise
between platforms in the future. But for now:
Reviewed-by: Leif Lindholm <leif@nuviainc.com>

/
    Leif

> ---
>  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 9f19f495fad2..9f75da6f05ad 100755
> --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc
> +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc
> @@ -529,6 +529,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
> @@ -539,6 +540,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 100755
> --- 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
> 

  reply	other threads:[~2021-06-04 23:27 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-26 10:06 [edk2-platforms][PATCH v2 00/32] Add new Ampere Mt. Jade platform Nhi Pham
2021-05-26 10:06 ` [edk2-platforms][PATCH v2 01/32] Ampere: Initial support for Ampere Altra processor and " Nhi Pham
2021-06-04 23:04   ` Leif Lindholm
2021-06-09  4:50     ` Nhi Pham
2021-06-09 12:40       ` Leif Lindholm
2021-06-15 16:46     ` Nhi Pham
2021-05-26 10:06 ` [PATCH 1/1] UsbCdcNetDxe: Remove reading connection status in SNP GetStatus Nhi Pham
2021-05-26 10:23   ` [edk2-devel] " Nhi Pham
2021-05-26 10:06 ` [edk2-platforms][PATCH v2 02/32] AmpereAltraPkg: Add MmCommunication modules Nhi Pham
2021-06-04 23:05   ` Leif Lindholm
2021-05-26 10:06 ` [edk2-platforms][PATCH v2 03/32] AmperePlatformPkg: Implement FailSafe library Nhi Pham
2021-06-04 23:07   ` Leif Lindholm
2021-05-26 10:06 ` [edk2-platforms][PATCH v2 04/32] AmperePlatformPkg: Add FailSafe and WDT support Nhi Pham
2021-06-04 23:12   ` Leif Lindholm
2021-06-15 16:47     ` Nhi Pham
2021-05-26 10:06 ` [edk2-platforms][PATCH v2 05/32] AmpereAltraPkg: Add DwI2cLib library Nhi Pham
2021-06-04 23:21   ` Leif Lindholm
2021-06-15 16:47     ` Nhi Pham
2021-05-26 10:06 ` [edk2-platforms][PATCH v2 06/32] AmpereAltraPkg: Add DwGpioLib library Nhi Pham
2021-06-04 23:22   ` Leif Lindholm
2021-05-26 10:06 ` [edk2-platforms][PATCH v2 07/32] JadePkg: Implement RealTimeClockLib for PCF85063 Nhi Pham
2021-06-04 23:26   ` Leif Lindholm
2021-06-15 16:48     ` Nhi Pham
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 08/32] AmpereAltraPkg: Add BootProgress support Nhi Pham
2021-06-04 23:27   ` Leif Lindholm [this message]
2021-06-15 16:48     ` Nhi Pham
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 09/32] AmpereAltraPkg: Support non-volatile variables Nhi Pham
2021-06-04 23:36   ` Leif Lindholm
2021-06-15 16:48     ` Nhi Pham
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 10/32] AmpereSiliconPkg: Add PlatformManagerUiLib library instance Nhi Pham
2021-06-04 23:37   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 11/32] AmperePlatformPkg: Add AcpiPccLib to support ACPI PCCT Table Nhi Pham
2021-06-04 23:44   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 12/32] AmperePlatformPkg: Add AcpiHelperLib to update ACPI DSDT table Nhi Pham
2021-06-04 23:47   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 13/32] AmpereAltraPkg, JadePkg: Add ACPI support Nhi Pham
2021-06-04 23:50   ` Leif Lindholm
2021-06-15 16:49     ` Nhi Pham
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 14/32] AmpereAltraPkg: Add PcieCoreLib library instance Nhi Pham
2021-06-05  0:05   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 15/32] JadePkg: Add PcieBoardLib " Nhi Pham
2021-06-07 22:45   ` Leif Lindholm
2021-06-15 16:50     ` Nhi Pham
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 16/32] AmpereAltraPkg: Add PciHostBridge driver Nhi Pham
2021-06-08 22:26   ` Leif Lindholm
2021-06-09  5:29   ` Ard Biesheuvel
2021-06-15 15:54     ` Nhi Pham
2021-06-16 14:20       ` Ard Biesheuvel
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 17/32] JadePkg: Enable PCIe-related libraries and device drivers Nhi Pham
2021-06-07 22:51   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 18/32] JadePkg: Add ASpeed GOP driver Nhi Pham
2021-06-07 22:51   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 19/32] AmpereAltraPkg: Add Random Number Generator Support Nhi Pham
2021-06-08 11:13   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 20/32] JadePkg: Add SMBIOS tables support Nhi Pham
2021-06-07 23:00   ` Leif Lindholm
2021-06-15 16:51     ` Nhi Pham
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 21/32] AmpereAltraPkg: Add DebugInfoPei module Nhi Pham
2021-06-07 23:08   ` Leif Lindholm
2021-06-15 16:51     ` Nhi Pham
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 22/32] AmpereAltraPkg: Add platform info screen Nhi Pham
2021-06-07 23:10   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 23/32] AmpereAltraPkg: Add configuration screen for memory Nhi Pham
2021-06-07 23:14   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 24/32] AmpereAltraPkg: Add configuration screen for CPU Nhi Pham
2021-06-07 23:15   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 25/32] AmpereAltraPkg: Add configuration screen for ACPI Nhi Pham
2021-06-07 23:20   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 26/32] AmpereAltraPkg: Add configuration screen for RAS Nhi Pham
2021-06-07 23:22   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 27/32] AmpereAltraPkg: Add configuration screen for Watchdog timer Nhi Pham
2021-06-07 23:24   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 28/32] AmpereAltraPkg: Add configuration screen for Pcie Devices Nhi Pham
2021-06-07 23:34   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 29/32] JadePkg: Recover boot options when NVRAM cleared Nhi Pham
2021-06-07 23:46   ` Leif Lindholm
2021-06-15 16:52     ` Nhi Pham
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 30/32] AmpereSiliconPkg: Implement PlatformBootManagerLib for LinuxBoot Nhi Pham
2021-06-07 23:50   ` Leif Lindholm
2021-06-09 15:21     ` Nhi Pham
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 31/32] Platform/Ampere: Introduce the LinuxBootPkg Nhi Pham
2021-06-07 23:51   ` Leif Lindholm
2021-05-26 10:07 ` [edk2-platforms][PATCH v2 32/32] AmpereAltraPkg,JadePkg: Support LinuxBoot DSC/FDF build for Jade platform Nhi Pham
2021-06-07 23:58   ` Leif Lindholm
2021-06-09 15:20     ` Nhi Pham
2021-05-27 12:56 ` [edk2-platforms][PATCH v2 00/32] Add new Ampere Mt. " Leif Lindholm
2021-06-04 13:54 ` Leif Lindholm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210604232753.pc5gu5ggitiyqfqo@leviathan \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox