This driver implements Reset2, ResetFilter and ResetHandler PPIs.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
---
MdeModulePkg/MdeModulePkg.dec | 4 +
.../Universal/ResetSystemPei/ResetSystem.c | 355 +++++++++++++++++++++
.../Universal/ResetSystemPei/ResetSystem.h | 129 ++++++++
.../Universal/ResetSystemPei/ResetSystemPei.inf | 62 ++++
.../Universal/ResetSystemPei/ResetSystemPei.uni | 20 ++
.../ResetSystemPei/ResetSystemPeiExtra.uni | 20 ++
6 files changed, 590 insertions(+)
create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c
create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h
create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf
create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni
create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 1cc9bc8ea1..1b971d599f 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -1419,6 +1419,10 @@ [PcdsFixedAtBuild, PcdsPatchableInModule]
# @Prompt CapsuleMax value in capsule report variable.
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleMax|0xFFFF|UINT16|0x00000107
+ ## Indicates the allowable maximum number of Reset Filters or Reset Handlers in PEI phase.
+ # @Prompt Maximum Number of PEI Reset Filters or Reset Handlers.
+ gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies|0x10|UINT32|0x00000109
+
[PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
## This PCD defines the Console output row. The default value is 25 according to UEFI spec.
# This PCD could be set to 0 then console output would be at max column and max row.
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c
new file mode 100644
index 0000000000..720593de6a
--- /dev/null
+++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c
@@ -0,0 +1,355 @@
+/** @file
+ Implementation of Reset2, ResetFilter and ResetHandler PPIs.
+
+ Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+
+ 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 "ResetSystem.h"
+
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mResetTypeStr[] = {
+ L"Cold", L"Warm", L"Shutdown", L"PlatformSpecific"
+};
+
+EFI_PEI_RESET2_PPI mPpiReset2 = {
+ ResetSystem2
+};
+
+EFI_GUID *mProcessingOrder[] = {
+ &gEdkiiPlatformSpecificResetFilterPpiGuid,
+ &gEdkiiPlatformSpecificResetHandlerPpiGuid
+};
+
+RESET_FILTER_INSTANCE mResetFilter = {
+ {
+ RegisterResetNotify,
+ UnregisterResetNotify
+ },
+ &gEdkiiPlatformSpecificResetFilterPpiGuid
+};
+
+RESET_FILTER_INSTANCE mResetHandler = {
+ {
+ RegisterResetNotify,
+ UnregisterResetNotify
+ },
+ &gEdkiiPlatformSpecificResetHandlerPpiGuid
+};
+
+EFI_PEI_PPI_DESCRIPTOR mPpiListReset[] = {
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI,
+ &gEfiPeiReset2PpiGuid,
+ &mPpiReset2
+ },
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI,
+ &gEdkiiPlatformSpecificResetFilterPpiGuid,
+ &mResetFilter.ResetFilter
+ },
+ {
+ EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gEdkiiPlatformSpecificResetHandlerPpiGuid,
+ &mResetHandler.ResetFilter
+ }
+};
+
+/**
+ Register a notification function to be called when ResetSystem() is called.
+
+ The RegisterResetNotify() function registers a notification function that is called when
+ ResetSystem()is called and prior to completing the reset of the platform.
+ The registered functions must not perform a platform reset themselves. These
+ notifications are intended only for the notification of components which may need some
+ special-purpose maintenance prior to the platform resetting.
+ The list of registered reset notification functions are processed if ResetSystem()is called
+ before ExitBootServices(). The list of registered reset notification functions is ignored if
+ ResetSystem()is called after ExitBootServices().
+
+ @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.
+ @param[in] ResetFunction Points to the function to be called when a ResetSystem() is executed.
+
+ @retval EFI_SUCCESS The reset notification function was successfully registered.
+ @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to register the reset notification function.
+ @retval EFI_ALREADY_STARTED The reset notification function specified by ResetFunction has already been registered.
+
+**/
+EFI_STATUS
+EFIAPI
+RegisterResetNotify (
+ IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This,
+ IN EFI_RESET_SYSTEM ResetFunction
+ )
+{
+ RESET_FILTER_INSTANCE *ResetFilter;
+ RESET_FILTER_LIST *List;
+ VOID *Hob;
+ UINTN Index;
+
+ if (ResetFunction == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ResetFilter = (RESET_FILTER_INSTANCE *) This;
+ ASSERT (CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetFilterPpiGuid) ||
+ CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetHandlerPpiGuid)
+ );
+
+ Hob = GetFirstGuidHob (ResetFilter->Guid);
+ if (Hob == NULL) {
+ //
+ // When the GUIDed HOB doesn't exist, create it.
+ //
+ List = (RESET_FILTER_LIST *)BuildGuidHob (
+ ResetFilter->Guid,
+ sizeof (RESET_FILTER_LIST) + sizeof (EFI_RESET_SYSTEM) * PcdGet32 (PcdMaximumPeiResetNotifies)
+ );
+ if (List == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ List->Signature = RESET_FILTER_LIST_SIGNATURE;
+ List->Count = PcdGet32 (PcdMaximumPeiResetNotifies);
+ ZeroMem (List->ResetFilters, sizeof (EFI_RESET_SYSTEM) * List->Count);
+ List->ResetFilters[0] = ResetFunction;
+ return EFI_SUCCESS;
+ } else {
+ List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob);
+ ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE);
+ //
+ // Firstly check whether the ResetFunction is already registerred.
+ //
+ for (Index = 0; Index < List->Count; Index++) {
+ if (List->ResetFilters[Index] == ResetFunction) {
+ break;
+ }
+ }
+ if (Index != List->Count) {
+ return EFI_ALREADY_STARTED;
+ }
+
+ //
+ // Secondly find the first free slot.
+ //
+ for (Index = 0; Index < List->Count; Index++) {
+ if (List->ResetFilters[Index] == NULL) {
+ break;
+ }
+ }
+
+ if (Index == List->Count) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ List->ResetFilters[Index] = ResetFunction;
+ return EFI_SUCCESS;
+ }
+}
+
+/**
+ Unregister a notification function.
+
+ The UnregisterResetNotify() function removes the previously registered
+ notification using RegisterResetNotify().
+
+ @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.
+ @param[in] ResetFunction The pointer to the ResetFunction being unregistered.
+
+ @retval EFI_SUCCESS The reset notification function was unregistered.
+ @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
+ @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously
+ registered using RegisterResetNotify().
+
+**/
+EFI_STATUS
+EFIAPI
+UnregisterResetNotify (
+ IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This,
+ IN EFI_RESET_SYSTEM ResetFunction
+ )
+{
+
+ RESET_FILTER_INSTANCE *ResetFilter;
+ RESET_FILTER_LIST *List;
+ VOID *Hob;
+ UINTN Index;
+
+ if (ResetFunction == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ResetFilter = (RESET_FILTER_INSTANCE *)This;
+ ASSERT (CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetFilterPpiGuid) ||
+ CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetHandlerPpiGuid)
+ );
+
+ Hob = GetFirstGuidHob (ResetFilter->Guid);
+ if (Hob == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob);
+ ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE);
+ for (Index = 0; Index < List->Count; Index++) {
+ if (List->ResetFilters[Index] == ResetFunction) {
+ break;
+ }
+ }
+
+ if (Index == List->Count) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ List->ResetFilters[Index] = NULL;
+ return EFI_SUCCESS;
+}
+
+
+/**
+ The PEIM's entry point.
+
+ It initializes the Reset2, ResetFilter and ResetHandler PPIs.
+
+ @param[in] FileHandle Handle of the file being invoked.
+ @param[in] PeiServices Describes the list of possible PEI Services.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval EFI_ALREADY_STARTED The Reset2 PPI was already installed.
+ @retval others Status code returned from PeiServicesInstallPpi().
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeResetSystem (
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
+ )
+{
+ EFI_STATUS Status;
+ VOID *Ppi;
+
+ Status = PeiServicesLocatePpi (&gEfiPeiReset2PpiGuid, 0, NULL, (VOID **)&Ppi);
+ if (Status != EFI_NOT_FOUND) {
+ return EFI_ALREADY_STARTED;
+ }
+
+ PeiServicesInstallPpi (mPpiListReset);
+
+ return Status;
+}
+
+/**
+ Resets the entire platform.
+
+ @param[in] ResetType The type of reset to perform.
+ @param[in] ResetStatus The status code for the reset.
+ @param[in] DataSize The size, in bytes, of ResetData.
+ @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
+ EfiResetShutdown the data buffer starts with a Null-terminated
+ string, optionally followed by additional binary data.
+ The string is a description that the caller may use to further
+ indicate the reason for the system reset. ResetData is only
+ valid if ResetStatus is something other than EFI_SUCCESS
+ unless the ResetType is EfiResetPlatformSpecific
+ where a minimum amount of ResetData is always required.
+ For a ResetType of EfiResetPlatformSpecific the data buffer
+ also starts with a Null-terminated string that is followed
+ by an EFI_GUID that describes the specific type of reset to perform.
+**/
+VOID
+EFIAPI
+ResetSystem2 (
+ IN EFI_RESET_TYPE ResetType,
+ IN EFI_STATUS ResetStatus,
+ IN UINTN DataSize,
+ IN VOID *ResetData OPTIONAL
+ )
+{
+ VOID *Hob;
+ UINTN Index;
+ RESET_FILTER_LIST *List;
+ UINTN OrderIndex;
+ UINT8 RecursionDepth;
+ UINT8 *RecursionDepthPointer;
+
+ //
+ // The recursion depth is stored in GUIDed HOB using gEfiCallerIdGuid.
+ //
+ Hob = GetFirstGuidHob (&gEfiCallerIdGuid);
+ if (Hob == NULL) {
+ RecursionDepth = 0;
+ RecursionDepthPointer = BuildGuidDataHob (&gEfiCallerIdGuid, &RecursionDepth, sizeof (RecursionDepth));
+ } else {
+ RecursionDepthPointer = (UINT8 *)GET_GUID_HOB_DATA (Hob);
+ }
+ //
+ // Only do REPORT_STATUS_CODE() on first call to ResetSystem()
+ //
+ if (*RecursionDepthPointer == 0) {
+ //
+ // Indicate reset system runtime service is called.
+ //
+ REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM));
+ }
+
+ //
+ // Increase the call depth
+ //
+ (*RecursionDepthPointer)++;
+ DEBUG ((DEBUG_INFO, "PEI ResetSystem2: Reset call depth = %d.\n", *RecursionDepthPointer));
+
+ if (*RecursionDepthPointer <= MAX_RESET_NOTIFY_DEPTH) {
+ //
+ // Iteratively call Reset Filters and Reset Handlers.
+ //
+ for (OrderIndex = 0; OrderIndex < ARRAY_SIZE (mProcessingOrder); OrderIndex++) {
+ Hob = GetFirstGuidHob (mProcessingOrder[OrderIndex]);
+ if (Hob != NULL) {
+ List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob);
+ ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE);
+
+ for (Index = 0; Index < List->Count; Index++) {
+ if (List->ResetFilters[Index] != NULL) {
+ List->ResetFilters[Index] (ResetType, ResetStatus, DataSize, ResetData);
+ }
+ }
+ }
+ }
+ } else {
+ ASSERT (ResetType < ARRAY_SIZE (mResetTypeStr));
+ DEBUG ((DEBUG_ERROR, "PEI ResetSystem2: Maximum reset call depth is met. Use the current reset type: %s!\n", mResetTypeStr[ResetType]));
+ }
+
+ switch (ResetType) {
+ case EfiResetWarm:
+ ResetWarm ();
+ break;
+
+ case EfiResetCold:
+ ResetCold ();
+ break;
+
+ case EfiResetShutdown:
+ ResetShutdown ();
+ return ;
+
+ case EfiResetPlatformSpecific:
+ ResetPlatformSpecific (DataSize, ResetData);
+ return;
+
+ default:
+ return ;
+ }
+
+ //
+ // Given we should have reset getting here would be bad
+ //
+ ASSERT (FALSE);
+}
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h
new file mode 100644
index 0000000000..2fcc3592b6
--- /dev/null
+++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h
@@ -0,0 +1,129 @@
+/** @file
+
+ Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+
+ 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 _RESET_SYSTEM2_H_
+#define _RESET_SYSTEM2_H_
+
+
+#include <Uefi.h>
+#include <PiPei.h>
+
+#include <Ppi/Reset2.h>
+#include <Ppi/PlatformSpecificResetFilter.h>
+#include <Ppi/PlatformSpecificResetHandler.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/HobLib.h>
+#include <Library/ResetSystemLib.h>
+#include <Library/ReportStatusCodeLib.h>
+
+
+//
+// The maximum recurstion depth to ResetSystem() by reset notification handlers
+//
+#define MAX_RESET_NOTIFY_DEPTH 10
+
+//
+// Data to put in GUIDed HOB
+//
+typedef struct {
+ UINT32 Signature;
+ UINT32 Count;
+ EFI_RESET_SYSTEM ResetFilters[0]; // ResetFilters[PcdGet32 (PcdMaximumResetNotifies)]
+} RESET_FILTER_LIST;
+#define RESET_FILTER_LIST_SIGNATURE SIGNATURE_32('r', 's', 't', 'l')
+
+
+typedef struct {
+ EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI ResetFilter;
+ EFI_GUID *Guid;
+} RESET_FILTER_INSTANCE;
+
+/**
+ Resets the entire platform.
+
+ @param[in] ResetType The type of reset to perform.
+ @param[in] ResetStatus The status code for the reset.
+ @param[in] DataSize The size, in bytes, of ResetData.
+ @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
+ EfiResetShutdown the data buffer starts with a Null-terminated
+ string, optionally followed by additional binary data.
+ The string is a description that the caller may use to further
+ indicate the reason for the system reset. ResetData is only
+ valid if ResetStatus is something other than EFI_SUCCESS
+ unless the ResetType is EfiResetPlatformSpecific
+ where a minimum amount of ResetData is always required.
+ For a ResetType of EfiResetPlatformSpecific the data buffer
+ also starts with a Null-terminated string that is followed
+ by an EFI_GUID that describes the specific type of reset to perform.
+
+**/
+VOID
+EFIAPI
+ResetSystem2 (
+ IN EFI_RESET_TYPE ResetType,
+ IN EFI_STATUS ResetStatus,
+ IN UINTN DataSize,
+ IN VOID *ResetData OPTIONAL
+ );
+/**
+ Register a notification function to be called when ResetSystem() is called.
+
+ The RegisterResetNotify() function registers a notification function that is called when
+ ResetSystem()is called and prior to completing the reset of the platform.
+ The registered functions must not perform a platform reset themselves. These
+ notifications are intended only for the notification of components which may need some
+ special-purpose maintenance prior to the platform resetting.
+
+ @param[in] This A pointer to the EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI instance.
+ @param[in] ResetFunction Points to the function to be called when a ResetSystem() is executed.
+
+ @retval EFI_SUCCESS The reset notification function was successfully registered.
+ @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to register the reset notification function.
+ @retval EFI_ALREADY_STARTED The reset notification function specified by ResetFunction has already been registered.
+
+**/
+EFI_STATUS
+EFIAPI
+RegisterResetNotify (
+ IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This,
+ IN EFI_RESET_SYSTEM ResetFunction
+ );
+
+/**
+ Unregister a notification function.
+
+ The UnregisterResetNotify() function removes the previously registered
+ notification using RegisterResetNotify().
+
+ @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.
+ @param[in] ResetFunction The pointer to the ResetFunction being unregistered.
+
+ @retval EFI_SUCCESS The reset notification function was unregistered.
+ @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
+ @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously
+ registered using RegisterResetNotify().
+
+**/
+EFI_STATUS
+EFIAPI
+UnregisterResetNotify (
+ IN EFI_RESET_NOTIFICATION_PROTOCOL *This,
+ IN EFI_RESET_SYSTEM ResetFunction
+ );
+#endif
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf
new file mode 100644
index 0000000000..38fdd16ceb
--- /dev/null
+++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf
@@ -0,0 +1,62 @@
+## @file
+# This driver implements Reset2, ResetFilter and ResetHandler PPIs.
+#
+# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+#
+# 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 = ResetSystemPei
+ MODULE_UNI_FILE = ResetSystemPei.uni
+ FILE_GUID = 6141E486-7543-4F1A-A579-FF532ED78E75
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+
+ ENTRY_POINT = InitializeResetSystem
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ ResetSystem.h
+ ResetSystem.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ PeiServicesLib
+ HobLib
+ PeimEntryPoint
+ ResetSystemLib
+ ReportStatusCodeLib
+
+[Ppis]
+ gEfiPeiReset2PpiGuid ## PRODUCES
+ gEdkiiPlatformSpecificResetFilterPpiGuid ## PRODUCES
+ gEdkiiPlatformSpecificResetHandlerPpiGuid ## PRODUCES
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies
+
+[Depex]
+ TRUE
+
+[UserExtensions.TianoCore."ExtraFiles"]
+ ResetSystemPeiExtra.uni
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni
new file mode 100644
index 0000000000..6d2d650c37
--- /dev/null
+++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni
@@ -0,0 +1,20 @@
+// /** @file
+// This driver implements Reset2, ResetFilter and ResetHandler PPIs.
+//
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+//
+// 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.
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Implements Reset2, ResetFilter and ResetHandler PPIs"
+
+#string STR_MODULE_DESCRIPTION #language en-US "This driver implements Reset2, ResetFilter and ResetHandler PPIs."
+
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni
new file mode 100644
index 0000000000..2681afc707
--- /dev/null
+++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni
@@ -0,0 +1,20 @@
+// /** @file
+// ResetSystemPei Localized Strings and Content
+//
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+//
+// 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.
+//
+// **/
+
+#string STR_PROPERTIES_MODULE_NAME
+#language en-US
+"Reset System PEIM"
+
+
--
2.15.1.windows.2
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
On 2018/2/2 14:45, Ruiyu Ni wrote: > This driver implements Reset2, ResetFilter and ResetHandler PPIs. > > Cc: Liming Gao <liming.gao@intel.com> > Cc: Michael D Kinney <michael.d.kinney@intel.com> > Cc: Star Zeng <star.zeng@intel.com> > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Should ResetSystemPei be added in MdeModulePkg.dsc for build coverage? Same comment has been provided to ResetSystemRuntimeDxe. Should be (*RecursionDepthPointer < MAX_RESET_NOTIFY_DEPTH) instead of (*RecursionDepthPointer <= MAX_RESET_NOTIFY_DEPTH)> Thanks, Star > --- > MdeModulePkg/MdeModulePkg.dec | 4 + > .../Universal/ResetSystemPei/ResetSystem.c | 355 +++++++++++++++++++++ > .../Universal/ResetSystemPei/ResetSystem.h | 129 ++++++++ > .../Universal/ResetSystemPei/ResetSystemPei.inf | 62 ++++ > .../Universal/ResetSystemPei/ResetSystemPei.uni | 20 ++ > .../ResetSystemPei/ResetSystemPeiExtra.uni | 20 ++ > 6 files changed, 590 insertions(+) > create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c > create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h > create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf > create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni > create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni > > diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec > index 1cc9bc8ea1..1b971d599f 100644 > --- a/MdeModulePkg/MdeModulePkg.dec > +++ b/MdeModulePkg/MdeModulePkg.dec > @@ -1419,6 +1419,10 @@ [PcdsFixedAtBuild, PcdsPatchableInModule] > # @Prompt CapsuleMax value in capsule report variable. > gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleMax|0xFFFF|UINT16|0x00000107 > > + ## Indicates the allowable maximum number of Reset Filters or Reset Handlers in PEI phase. > + # @Prompt Maximum Number of PEI Reset Filters or Reset Handlers. > + gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies|0x10|UINT32|0x00000109 > + > [PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] > ## This PCD defines the Console output row. The default value is 25 according to UEFI spec. > # This PCD could be set to 0 then console output would be at max column and max row. > diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c > new file mode 100644 > index 0000000000..720593de6a > --- /dev/null > +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c > @@ -0,0 +1,355 @@ > +/** @file > + Implementation of Reset2, ResetFilter and ResetHandler PPIs. > + > + Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> > + > + 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 "ResetSystem.h" > + > +GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mResetTypeStr[] = { > + L"Cold", L"Warm", L"Shutdown", L"PlatformSpecific" > +}; > + > +EFI_PEI_RESET2_PPI mPpiReset2 = { > + ResetSystem2 > +}; > + > +EFI_GUID *mProcessingOrder[] = { > + &gEdkiiPlatformSpecificResetFilterPpiGuid, > + &gEdkiiPlatformSpecificResetHandlerPpiGuid > +}; > + > +RESET_FILTER_INSTANCE mResetFilter = { > + { > + RegisterResetNotify, > + UnregisterResetNotify > + }, > + &gEdkiiPlatformSpecificResetFilterPpiGuid > +}; > + > +RESET_FILTER_INSTANCE mResetHandler = { > + { > + RegisterResetNotify, > + UnregisterResetNotify > + }, > + &gEdkiiPlatformSpecificResetHandlerPpiGuid > +}; > + > +EFI_PEI_PPI_DESCRIPTOR mPpiListReset[] = { > + { > + EFI_PEI_PPI_DESCRIPTOR_PPI, > + &gEfiPeiReset2PpiGuid, > + &mPpiReset2 > + }, > + { > + EFI_PEI_PPI_DESCRIPTOR_PPI, > + &gEdkiiPlatformSpecificResetFilterPpiGuid, > + &mResetFilter.ResetFilter > + }, > + { > + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, > + &gEdkiiPlatformSpecificResetHandlerPpiGuid, > + &mResetHandler.ResetFilter > + } > +}; > + > +/** > + Register a notification function to be called when ResetSystem() is called. > + > + The RegisterResetNotify() function registers a notification function that is called when > + ResetSystem()is called and prior to completing the reset of the platform. > + The registered functions must not perform a platform reset themselves. These > + notifications are intended only for the notification of components which may need some > + special-purpose maintenance prior to the platform resetting. > + The list of registered reset notification functions are processed if ResetSystem()is called > + before ExitBootServices(). The list of registered reset notification functions is ignored if > + ResetSystem()is called after ExitBootServices(). > + > + @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance. > + @param[in] ResetFunction Points to the function to be called when a ResetSystem() is executed. > + > + @retval EFI_SUCCESS The reset notification function was successfully registered. > + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. > + @retval EFI_OUT_OF_RESOURCES There are not enough resources available to register the reset notification function. > + @retval EFI_ALREADY_STARTED The reset notification function specified by ResetFunction has already been registered. > + > +**/ > +EFI_STATUS > +EFIAPI > +RegisterResetNotify ( > + IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This, > + IN EFI_RESET_SYSTEM ResetFunction > + ) > +{ > + RESET_FILTER_INSTANCE *ResetFilter; > + RESET_FILTER_LIST *List; > + VOID *Hob; > + UINTN Index; > + > + if (ResetFunction == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + ResetFilter = (RESET_FILTER_INSTANCE *) This; > + ASSERT (CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetFilterPpiGuid) || > + CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetHandlerPpiGuid) > + ); > + > + Hob = GetFirstGuidHob (ResetFilter->Guid); > + if (Hob == NULL) { > + // > + // When the GUIDed HOB doesn't exist, create it. > + // > + List = (RESET_FILTER_LIST *)BuildGuidHob ( > + ResetFilter->Guid, > + sizeof (RESET_FILTER_LIST) + sizeof (EFI_RESET_SYSTEM) * PcdGet32 (PcdMaximumPeiResetNotifies) > + ); > + if (List == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + List->Signature = RESET_FILTER_LIST_SIGNATURE; > + List->Count = PcdGet32 (PcdMaximumPeiResetNotifies); > + ZeroMem (List->ResetFilters, sizeof (EFI_RESET_SYSTEM) * List->Count); > + List->ResetFilters[0] = ResetFunction; > + return EFI_SUCCESS; > + } else { > + List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob); > + ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE); > + // > + // Firstly check whether the ResetFunction is already registerred. > + // > + for (Index = 0; Index < List->Count; Index++) { > + if (List->ResetFilters[Index] == ResetFunction) { > + break; > + } > + } > + if (Index != List->Count) { > + return EFI_ALREADY_STARTED; > + } > + > + // > + // Secondly find the first free slot. > + // > + for (Index = 0; Index < List->Count; Index++) { > + if (List->ResetFilters[Index] == NULL) { > + break; > + } > + } > + > + if (Index == List->Count) { > + return EFI_OUT_OF_RESOURCES; > + } > + List->ResetFilters[Index] = ResetFunction; > + return EFI_SUCCESS; > + } > +} > + > +/** > + Unregister a notification function. > + > + The UnregisterResetNotify() function removes the previously registered > + notification using RegisterResetNotify(). > + > + @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance. > + @param[in] ResetFunction The pointer to the ResetFunction being unregistered. > + > + @retval EFI_SUCCESS The reset notification function was unregistered. > + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. > + @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously > + registered using RegisterResetNotify(). > + > +**/ > +EFI_STATUS > +EFIAPI > +UnregisterResetNotify ( > + IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This, > + IN EFI_RESET_SYSTEM ResetFunction > + ) > +{ > + > + RESET_FILTER_INSTANCE *ResetFilter; > + RESET_FILTER_LIST *List; > + VOID *Hob; > + UINTN Index; > + > + if (ResetFunction == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + ResetFilter = (RESET_FILTER_INSTANCE *)This; > + ASSERT (CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetFilterPpiGuid) || > + CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetHandlerPpiGuid) > + ); > + > + Hob = GetFirstGuidHob (ResetFilter->Guid); > + if (Hob == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob); > + ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE); > + for (Index = 0; Index < List->Count; Index++) { > + if (List->ResetFilters[Index] == ResetFunction) { > + break; > + } > + } > + > + if (Index == List->Count) { > + return EFI_INVALID_PARAMETER; > + } > + > + List->ResetFilters[Index] = NULL; > + return EFI_SUCCESS; > +} > + > + > +/** > + The PEIM's entry point. > + > + It initializes the Reset2, ResetFilter and ResetHandler PPIs. > + > + @param[in] FileHandle Handle of the file being invoked. > + @param[in] PeiServices Describes the list of possible PEI Services. > + > + @retval EFI_SUCCESS The entry point is executed successfully. > + @retval EFI_ALREADY_STARTED The Reset2 PPI was already installed. > + @retval others Status code returned from PeiServicesInstallPpi(). > + > +**/ > +EFI_STATUS > +EFIAPI > +InitializeResetSystem ( > + IN EFI_PEI_FILE_HANDLE FileHandle, > + IN CONST EFI_PEI_SERVICES **PeiServices > + ) > +{ > + EFI_STATUS Status; > + VOID *Ppi; > + > + Status = PeiServicesLocatePpi (&gEfiPeiReset2PpiGuid, 0, NULL, (VOID **)&Ppi); > + if (Status != EFI_NOT_FOUND) { > + return EFI_ALREADY_STARTED; > + } > + > + PeiServicesInstallPpi (mPpiListReset); > + > + return Status; > +} > + > +/** > + Resets the entire platform. > + > + @param[in] ResetType The type of reset to perform. > + @param[in] ResetStatus The status code for the reset. > + @param[in] DataSize The size, in bytes, of ResetData. > + @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or > + EfiResetShutdown the data buffer starts with a Null-terminated > + string, optionally followed by additional binary data. > + The string is a description that the caller may use to further > + indicate the reason for the system reset. ResetData is only > + valid if ResetStatus is something other than EFI_SUCCESS > + unless the ResetType is EfiResetPlatformSpecific > + where a minimum amount of ResetData is always required. > + For a ResetType of EfiResetPlatformSpecific the data buffer > + also starts with a Null-terminated string that is followed > + by an EFI_GUID that describes the specific type of reset to perform. > +**/ > +VOID > +EFIAPI > +ResetSystem2 ( > + IN EFI_RESET_TYPE ResetType, > + IN EFI_STATUS ResetStatus, > + IN UINTN DataSize, > + IN VOID *ResetData OPTIONAL > + ) > +{ > + VOID *Hob; > + UINTN Index; > + RESET_FILTER_LIST *List; > + UINTN OrderIndex; > + UINT8 RecursionDepth; > + UINT8 *RecursionDepthPointer; > + > + // > + // The recursion depth is stored in GUIDed HOB using gEfiCallerIdGuid. > + // > + Hob = GetFirstGuidHob (&gEfiCallerIdGuid); > + if (Hob == NULL) { > + RecursionDepth = 0; > + RecursionDepthPointer = BuildGuidDataHob (&gEfiCallerIdGuid, &RecursionDepth, sizeof (RecursionDepth)); > + } else { > + RecursionDepthPointer = (UINT8 *)GET_GUID_HOB_DATA (Hob); > + } > + // > + // Only do REPORT_STATUS_CODE() on first call to ResetSystem() > + // > + if (*RecursionDepthPointer == 0) { > + // > + // Indicate reset system runtime service is called. > + // > + REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM)); > + } > + > + // > + // Increase the call depth > + // > + (*RecursionDepthPointer)++; > + DEBUG ((DEBUG_INFO, "PEI ResetSystem2: Reset call depth = %d.\n", *RecursionDepthPointer)); > + > + if (*RecursionDepthPointer <= MAX_RESET_NOTIFY_DEPTH) { > + // > + // Iteratively call Reset Filters and Reset Handlers. > + // > + for (OrderIndex = 0; OrderIndex < ARRAY_SIZE (mProcessingOrder); OrderIndex++) { > + Hob = GetFirstGuidHob (mProcessingOrder[OrderIndex]); > + if (Hob != NULL) { > + List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob); > + ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE); > + > + for (Index = 0; Index < List->Count; Index++) { > + if (List->ResetFilters[Index] != NULL) { > + List->ResetFilters[Index] (ResetType, ResetStatus, DataSize, ResetData); > + } > + } > + } > + } > + } else { > + ASSERT (ResetType < ARRAY_SIZE (mResetTypeStr)); > + DEBUG ((DEBUG_ERROR, "PEI ResetSystem2: Maximum reset call depth is met. Use the current reset type: %s!\n", mResetTypeStr[ResetType])); > + } > + > + switch (ResetType) { > + case EfiResetWarm: > + ResetWarm (); > + break; > + > + case EfiResetCold: > + ResetCold (); > + break; > + > + case EfiResetShutdown: > + ResetShutdown (); > + return ; > + > + case EfiResetPlatformSpecific: > + ResetPlatformSpecific (DataSize, ResetData); > + return; > + > + default: > + return ; > + } > + > + // > + // Given we should have reset getting here would be bad > + // > + ASSERT (FALSE); > +} > diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h > new file mode 100644 > index 0000000000..2fcc3592b6 > --- /dev/null > +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h > @@ -0,0 +1,129 @@ > +/** @file > + > + Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> > + > + 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 _RESET_SYSTEM2_H_ > +#define _RESET_SYSTEM2_H_ > + > + > +#include <Uefi.h> > +#include <PiPei.h> > + > +#include <Ppi/Reset2.h> > +#include <Ppi/PlatformSpecificResetFilter.h> > +#include <Ppi/PlatformSpecificResetHandler.h> > + > +#include <Library/BaseLib.h> > +#include <Library/BaseMemoryLib.h> > +#include <Library/DebugLib.h> > +#include <Library/PeiServicesLib.h> > +#include <Library/HobLib.h> > +#include <Library/ResetSystemLib.h> > +#include <Library/ReportStatusCodeLib.h> > + > + > +// > +// The maximum recurstion depth to ResetSystem() by reset notification handlers > +// > +#define MAX_RESET_NOTIFY_DEPTH 10 > + > +// > +// Data to put in GUIDed HOB > +// > +typedef struct { > + UINT32 Signature; > + UINT32 Count; > + EFI_RESET_SYSTEM ResetFilters[0]; // ResetFilters[PcdGet32 (PcdMaximumResetNotifies)] > +} RESET_FILTER_LIST; > +#define RESET_FILTER_LIST_SIGNATURE SIGNATURE_32('r', 's', 't', 'l') > + > + > +typedef struct { > + EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI ResetFilter; > + EFI_GUID *Guid; > +} RESET_FILTER_INSTANCE; > + > +/** > + Resets the entire platform. > + > + @param[in] ResetType The type of reset to perform. > + @param[in] ResetStatus The status code for the reset. > + @param[in] DataSize The size, in bytes, of ResetData. > + @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or > + EfiResetShutdown the data buffer starts with a Null-terminated > + string, optionally followed by additional binary data. > + The string is a description that the caller may use to further > + indicate the reason for the system reset. ResetData is only > + valid if ResetStatus is something other than EFI_SUCCESS > + unless the ResetType is EfiResetPlatformSpecific > + where a minimum amount of ResetData is always required. > + For a ResetType of EfiResetPlatformSpecific the data buffer > + also starts with a Null-terminated string that is followed > + by an EFI_GUID that describes the specific type of reset to perform. > + > +**/ > +VOID > +EFIAPI > +ResetSystem2 ( > + IN EFI_RESET_TYPE ResetType, > + IN EFI_STATUS ResetStatus, > + IN UINTN DataSize, > + IN VOID *ResetData OPTIONAL > + ); > +/** > + Register a notification function to be called when ResetSystem() is called. > + > + The RegisterResetNotify() function registers a notification function that is called when > + ResetSystem()is called and prior to completing the reset of the platform. > + The registered functions must not perform a platform reset themselves. These > + notifications are intended only for the notification of components which may need some > + special-purpose maintenance prior to the platform resetting. > + > + @param[in] This A pointer to the EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI instance. > + @param[in] ResetFunction Points to the function to be called when a ResetSystem() is executed. > + > + @retval EFI_SUCCESS The reset notification function was successfully registered. > + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. > + @retval EFI_OUT_OF_RESOURCES There are not enough resources available to register the reset notification function. > + @retval EFI_ALREADY_STARTED The reset notification function specified by ResetFunction has already been registered. > + > +**/ > +EFI_STATUS > +EFIAPI > +RegisterResetNotify ( > + IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This, > + IN EFI_RESET_SYSTEM ResetFunction > + ); > + > +/** > + Unregister a notification function. > + > + The UnregisterResetNotify() function removes the previously registered > + notification using RegisterResetNotify(). > + > + @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance. > + @param[in] ResetFunction The pointer to the ResetFunction being unregistered. > + > + @retval EFI_SUCCESS The reset notification function was unregistered. > + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. > + @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously > + registered using RegisterResetNotify(). > + > +**/ > +EFI_STATUS > +EFIAPI > +UnregisterResetNotify ( > + IN EFI_RESET_NOTIFICATION_PROTOCOL *This, > + IN EFI_RESET_SYSTEM ResetFunction > + ); > +#endif > diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf > new file mode 100644 > index 0000000000..38fdd16ceb > --- /dev/null > +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf > @@ -0,0 +1,62 @@ > +## @file > +# This driver implements Reset2, ResetFilter and ResetHandler PPIs. > +# > +# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> > +# > +# 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 = ResetSystemPei > + MODULE_UNI_FILE = ResetSystemPei.uni > + FILE_GUID = 6141E486-7543-4F1A-A579-FF532ED78E75 > + MODULE_TYPE = PEIM > + VERSION_STRING = 1.0 > + > + ENTRY_POINT = InitializeResetSystem > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = IA32 X64 > +# > + > +[Sources] > + ResetSystem.h > + ResetSystem.c > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + > +[LibraryClasses] > + BaseLib > + BaseMemoryLib > + DebugLib > + PeiServicesLib > + HobLib > + PeimEntryPoint > + ResetSystemLib > + ReportStatusCodeLib > + > +[Ppis] > + gEfiPeiReset2PpiGuid ## PRODUCES > + gEdkiiPlatformSpecificResetFilterPpiGuid ## PRODUCES > + gEdkiiPlatformSpecificResetHandlerPpiGuid ## PRODUCES > + > +[Pcd] > + gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies > + > +[Depex] > + TRUE > + > +[UserExtensions.TianoCore."ExtraFiles"] > + ResetSystemPeiExtra.uni > diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni > new file mode 100644 > index 0000000000..6d2d650c37 > --- /dev/null > +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni > @@ -0,0 +1,20 @@ > +// /** @file > +// This driver implements Reset2, ResetFilter and ResetHandler PPIs. > +// > +// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> > +// > +// 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. > +// > +// **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "Implements Reset2, ResetFilter and ResetHandler PPIs" > + > +#string STR_MODULE_DESCRIPTION #language en-US "This driver implements Reset2, ResetFilter and ResetHandler PPIs." > + > diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni > new file mode 100644 > index 0000000000..2681afc707 > --- /dev/null > +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni > @@ -0,0 +1,20 @@ > +// /** @file > +// ResetSystemPei Localized Strings and Content > +// > +// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> > +// > +// 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. > +// > +// **/ > + > +#string STR_PROPERTIES_MODULE_NAME > +#language en-US > +"Reset System PEIM" > + > + > _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Sorry for the trivial comments. 1. A typo "recurstion" should be "recursion" is in ResetSystem.h for both ResetSystemPei and ResetSystemRuntimeDxe. 2. Should "RUNTIME/runtime/RS" be "PEI" in the comments and code like below? // // Indicate reset system runtime service is called. // REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM)); -> // // Indicate reset system PEI service is called. // REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_SERVICE | EFI_SW_PS_PC_RESET_SYSTEM)); 3. We need update MdeModulePkg.uni for the new PCD PcdMaximumPeiResetNotifies accordingly. Thanks, Star On 2018/2/7 20:35, Zeng, Star wrote: > On 2018/2/2 14:45, Ruiyu Ni wrote: >> This driver implements Reset2, ResetFilter and ResetHandler PPIs. >> >> Cc: Liming Gao <liming.gao@intel.com> >> Cc: Michael D Kinney <michael.d.kinney@intel.com> >> Cc: Star Zeng <star.zeng@intel.com> >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> > > Should ResetSystemPei be added in MdeModulePkg.dsc for build coverage? > > Same comment has been provided to ResetSystemRuntimeDxe. > Should be (*RecursionDepthPointer < MAX_RESET_NOTIFY_DEPTH) instead of > (*RecursionDepthPointer <= MAX_RESET_NOTIFY_DEPTH)> > > > Thanks, > Star > >> --- >> MdeModulePkg/MdeModulePkg.dec | 4 + >> .../Universal/ResetSystemPei/ResetSystem.c | 355 >> +++++++++++++++++++++ >> .../Universal/ResetSystemPei/ResetSystem.h | 129 ++++++++ >> .../Universal/ResetSystemPei/ResetSystemPei.inf | 62 ++++ >> .../Universal/ResetSystemPei/ResetSystemPei.uni | 20 ++ >> .../ResetSystemPei/ResetSystemPeiExtra.uni | 20 ++ >> 6 files changed, 590 insertions(+) >> create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c >> create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h >> create mode 100644 >> MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf >> create mode 100644 >> MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni >> create mode 100644 >> MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni >> >> diff --git a/MdeModulePkg/MdeModulePkg.dec >> b/MdeModulePkg/MdeModulePkg.dec >> index 1cc9bc8ea1..1b971d599f 100644 >> --- a/MdeModulePkg/MdeModulePkg.dec >> +++ b/MdeModulePkg/MdeModulePkg.dec >> @@ -1419,6 +1419,10 @@ [PcdsFixedAtBuild, PcdsPatchableInModule] >> # @Prompt CapsuleMax value in capsule report variable. >> gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleMax|0xFFFF|UINT16|0x00000107 >> + ## Indicates the allowable maximum number of Reset Filters or Reset >> Handlers in PEI phase. >> + # @Prompt Maximum Number of PEI Reset Filters or Reset Handlers. >> + >> gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies|0x10|UINT32|0x00000109 >> >> + >> [PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] >> ## This PCD defines the Console output row. The default value is >> 25 according to UEFI spec. >> # This PCD could be set to 0 then console output would be at max >> column and max row. >> diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c >> new file mode 100644 >> index 0000000000..720593de6a >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c >> @@ -0,0 +1,355 @@ >> +/** @file >> + Implementation of Reset2, ResetFilter and ResetHandler PPIs. >> + >> + Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> + >> + 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 "ResetSystem.h" >> + >> +GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mResetTypeStr[] = { >> + L"Cold", L"Warm", L"Shutdown", L"PlatformSpecific" >> +}; >> + >> +EFI_PEI_RESET2_PPI mPpiReset2 = { >> + ResetSystem2 >> +}; >> + >> +EFI_GUID *mProcessingOrder[] = { >> + &gEdkiiPlatformSpecificResetFilterPpiGuid, >> + &gEdkiiPlatformSpecificResetHandlerPpiGuid >> +}; >> + >> +RESET_FILTER_INSTANCE mResetFilter = { >> + { >> + RegisterResetNotify, >> + UnregisterResetNotify >> + }, >> + &gEdkiiPlatformSpecificResetFilterPpiGuid >> +}; >> + >> +RESET_FILTER_INSTANCE mResetHandler = { >> + { >> + RegisterResetNotify, >> + UnregisterResetNotify >> + }, >> + &gEdkiiPlatformSpecificResetHandlerPpiGuid >> +}; >> + >> +EFI_PEI_PPI_DESCRIPTOR mPpiListReset[] = { >> + { >> + EFI_PEI_PPI_DESCRIPTOR_PPI, >> + &gEfiPeiReset2PpiGuid, >> + &mPpiReset2 >> + }, >> + { >> + EFI_PEI_PPI_DESCRIPTOR_PPI, >> + &gEdkiiPlatformSpecificResetFilterPpiGuid, >> + &mResetFilter.ResetFilter >> + }, >> + { >> + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, >> + &gEdkiiPlatformSpecificResetHandlerPpiGuid, >> + &mResetHandler.ResetFilter >> + } >> +}; >> + >> +/** >> + Register a notification function to be called when ResetSystem() is >> called. >> + >> + The RegisterResetNotify() function registers a notification >> function that is called when >> + ResetSystem()is called and prior to completing the reset of the >> platform. >> + The registered functions must not perform a platform reset >> themselves. These >> + notifications are intended only for the notification of components >> which may need some >> + special-purpose maintenance prior to the platform resetting. >> + The list of registered reset notification functions are processed >> if ResetSystem()is called >> + before ExitBootServices(). The list of registered reset >> notification functions is ignored if >> + ResetSystem()is called after ExitBootServices(). >> + >> + @param[in] This A pointer to the >> EFI_RESET_NOTIFICATION_PROTOCOL instance. >> + @param[in] ResetFunction Points to the function to be called >> when a ResetSystem() is executed. >> + >> + @retval EFI_SUCCESS The reset notification function was >> successfully registered. >> + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. >> + @retval EFI_OUT_OF_RESOURCES There are not enough resources >> available to register the reset notification function. >> + @retval EFI_ALREADY_STARTED The reset notification function >> specified by ResetFunction has already been registered. >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +RegisterResetNotify ( >> + IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This, >> + IN EFI_RESET_SYSTEM ResetFunction >> + ) >> +{ >> + RESET_FILTER_INSTANCE *ResetFilter; >> + RESET_FILTER_LIST *List; >> + VOID *Hob; >> + UINTN Index; >> + >> + if (ResetFunction == NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + ResetFilter = (RESET_FILTER_INSTANCE *) This; >> + ASSERT (CompareGuid (ResetFilter->Guid, >> &gEdkiiPlatformSpecificResetFilterPpiGuid) || >> + CompareGuid (ResetFilter->Guid, >> &gEdkiiPlatformSpecificResetHandlerPpiGuid) >> + ); >> + >> + Hob = GetFirstGuidHob (ResetFilter->Guid); >> + if (Hob == NULL) { >> + // >> + // When the GUIDed HOB doesn't exist, create it. >> + // >> + List = (RESET_FILTER_LIST *)BuildGuidHob ( >> + ResetFilter->Guid, >> + sizeof (RESET_FILTER_LIST) + sizeof >> (EFI_RESET_SYSTEM) * PcdGet32 (PcdMaximumPeiResetNotifies) >> + ); >> + if (List == NULL) { >> + return EFI_OUT_OF_RESOURCES; >> + } >> + List->Signature = RESET_FILTER_LIST_SIGNATURE; >> + List->Count = PcdGet32 (PcdMaximumPeiResetNotifies); >> + ZeroMem (List->ResetFilters, sizeof (EFI_RESET_SYSTEM) * >> List->Count); >> + List->ResetFilters[0] = ResetFunction; >> + return EFI_SUCCESS; >> + } else { >> + List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob); >> + ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE); >> + // >> + // Firstly check whether the ResetFunction is already registerred. >> + // >> + for (Index = 0; Index < List->Count; Index++) { >> + if (List->ResetFilters[Index] == ResetFunction) { >> + break; >> + } >> + } >> + if (Index != List->Count) { >> + return EFI_ALREADY_STARTED; >> + } >> + >> + // >> + // Secondly find the first free slot. >> + // >> + for (Index = 0; Index < List->Count; Index++) { >> + if (List->ResetFilters[Index] == NULL) { >> + break; >> + } >> + } >> + >> + if (Index == List->Count) { >> + return EFI_OUT_OF_RESOURCES; >> + } >> + List->ResetFilters[Index] = ResetFunction; >> + return EFI_SUCCESS; >> + } >> +} >> + >> +/** >> + Unregister a notification function. >> + >> + The UnregisterResetNotify() function removes the previously registered >> + notification using RegisterResetNotify(). >> + >> + @param[in] This A pointer to the >> EFI_RESET_NOTIFICATION_PROTOCOL instance. >> + @param[in] ResetFunction The pointer to the ResetFunction >> being unregistered. >> + >> + @retval EFI_SUCCESS The reset notification function was >> unregistered. >> + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. >> + @retval EFI_INVALID_PARAMETER The reset notification function >> specified by ResetFunction was not previously >> + registered using RegisterResetNotify(). >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +UnregisterResetNotify ( >> + IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This, >> + IN EFI_RESET_SYSTEM ResetFunction >> + ) >> +{ >> + >> + RESET_FILTER_INSTANCE *ResetFilter; >> + RESET_FILTER_LIST *List; >> + VOID *Hob; >> + UINTN Index; >> + >> + if (ResetFunction == NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + ResetFilter = (RESET_FILTER_INSTANCE *)This; >> + ASSERT (CompareGuid (ResetFilter->Guid, >> &gEdkiiPlatformSpecificResetFilterPpiGuid) || >> + CompareGuid (ResetFilter->Guid, >> &gEdkiiPlatformSpecificResetHandlerPpiGuid) >> + ); >> + >> + Hob = GetFirstGuidHob (ResetFilter->Guid); >> + if (Hob == NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob); >> + ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE); >> + for (Index = 0; Index < List->Count; Index++) { >> + if (List->ResetFilters[Index] == ResetFunction) { >> + break; >> + } >> + } >> + >> + if (Index == List->Count) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + List->ResetFilters[Index] = NULL; >> + return EFI_SUCCESS; >> +} >> + >> + >> +/** >> + The PEIM's entry point. >> + >> + It initializes the Reset2, ResetFilter and ResetHandler PPIs. >> + >> + @param[in] FileHandle Handle of the file being invoked. >> + @param[in] PeiServices Describes the list of possible PEI Services. >> + >> + @retval EFI_SUCCESS The entry point is executed successfully. >> + @retval EFI_ALREADY_STARTED The Reset2 PPI was already installed. >> + @retval others Status code returned from >> PeiServicesInstallPpi(). >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +InitializeResetSystem ( >> + IN EFI_PEI_FILE_HANDLE FileHandle, >> + IN CONST EFI_PEI_SERVICES **PeiServices >> + ) >> +{ >> + EFI_STATUS Status; >> + VOID *Ppi; >> + >> + Status = PeiServicesLocatePpi (&gEfiPeiReset2PpiGuid, 0, NULL, >> (VOID **)&Ppi); >> + if (Status != EFI_NOT_FOUND) { >> + return EFI_ALREADY_STARTED; >> + } >> + >> + PeiServicesInstallPpi (mPpiListReset); >> + >> + return Status; >> +} >> + >> +/** >> + Resets the entire platform. >> + >> + @param[in] ResetType The type of reset to perform. >> + @param[in] ResetStatus The status code for the reset. >> + @param[in] DataSize The size, in bytes, of ResetData. >> + @param[in] ResetData For a ResetType of EfiResetCold, >> EfiResetWarm, or >> + EfiResetShutdown the data buffer >> starts with a Null-terminated >> + string, optionally followed by >> additional binary data. >> + The string is a description that the >> caller may use to further >> + indicate the reason for the system >> reset. ResetData is only >> + valid if ResetStatus is something >> other than EFI_SUCCESS >> + unless the ResetType is >> EfiResetPlatformSpecific >> + where a minimum amount of ResetData >> is always required. >> + For a ResetType of >> EfiResetPlatformSpecific the data buffer >> + also starts with a Null-terminated >> string that is followed >> + by an EFI_GUID that describes the >> specific type of reset to perform. >> +**/ >> +VOID >> +EFIAPI >> +ResetSystem2 ( >> + IN EFI_RESET_TYPE ResetType, >> + IN EFI_STATUS ResetStatus, >> + IN UINTN DataSize, >> + IN VOID *ResetData OPTIONAL >> + ) >> +{ >> + VOID *Hob; >> + UINTN Index; >> + RESET_FILTER_LIST *List; >> + UINTN OrderIndex; >> + UINT8 RecursionDepth; >> + UINT8 *RecursionDepthPointer; >> + >> + // >> + // The recursion depth is stored in GUIDed HOB using gEfiCallerIdGuid. >> + // >> + Hob = GetFirstGuidHob (&gEfiCallerIdGuid); >> + if (Hob == NULL) { >> + RecursionDepth = 0; >> + RecursionDepthPointer = BuildGuidDataHob (&gEfiCallerIdGuid, >> &RecursionDepth, sizeof (RecursionDepth)); >> + } else { >> + RecursionDepthPointer = (UINT8 *)GET_GUID_HOB_DATA (Hob); >> + } >> + // >> + // Only do REPORT_STATUS_CODE() on first call to ResetSystem() >> + // >> + if (*RecursionDepthPointer == 0) { >> + // >> + // Indicate reset system runtime service is called. >> + // >> + REPORT_STATUS_CODE (EFI_PROGRESS_CODE, >> (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM)); >> + } >> + >> + // >> + // Increase the call depth >> + // >> + (*RecursionDepthPointer)++; >> + DEBUG ((DEBUG_INFO, "PEI ResetSystem2: Reset call depth = %d.\n", >> *RecursionDepthPointer)); >> + >> + if (*RecursionDepthPointer <= MAX_RESET_NOTIFY_DEPTH) { >> + // >> + // Iteratively call Reset Filters and Reset Handlers. >> + // >> + for (OrderIndex = 0; OrderIndex < ARRAY_SIZE (mProcessingOrder); >> OrderIndex++) { >> + Hob = GetFirstGuidHob (mProcessingOrder[OrderIndex]); >> + if (Hob != NULL) { >> + List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob); >> + ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE); >> + >> + for (Index = 0; Index < List->Count; Index++) { >> + if (List->ResetFilters[Index] != NULL) { >> + List->ResetFilters[Index] (ResetType, ResetStatus, >> DataSize, ResetData); >> + } >> + } >> + } >> + } >> + } else { >> + ASSERT (ResetType < ARRAY_SIZE (mResetTypeStr)); >> + DEBUG ((DEBUG_ERROR, "PEI ResetSystem2: Maximum reset call depth >> is met. Use the current reset type: %s!\n", mResetTypeStr[ResetType])); >> + } >> + >> + switch (ResetType) { >> + case EfiResetWarm: >> + ResetWarm (); >> + break; >> + >> + case EfiResetCold: >> + ResetCold (); >> + break; >> + >> + case EfiResetShutdown: >> + ResetShutdown (); >> + return ; >> + >> + case EfiResetPlatformSpecific: >> + ResetPlatformSpecific (DataSize, ResetData); >> + return; >> + >> + default: >> + return ; >> + } >> + >> + // >> + // Given we should have reset getting here would be bad >> + // >> + ASSERT (FALSE); >> +} >> diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h >> new file mode 100644 >> index 0000000000..2fcc3592b6 >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h >> @@ -0,0 +1,129 @@ >> +/** @file >> + >> + Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> + >> + 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 _RESET_SYSTEM2_H_ >> +#define _RESET_SYSTEM2_H_ >> + >> + >> +#include <Uefi.h> >> +#include <PiPei.h> >> + >> +#include <Ppi/Reset2.h> >> +#include <Ppi/PlatformSpecificResetFilter.h> >> +#include <Ppi/PlatformSpecificResetHandler.h> >> + >> +#include <Library/BaseLib.h> >> +#include <Library/BaseMemoryLib.h> >> +#include <Library/DebugLib.h> >> +#include <Library/PeiServicesLib.h> >> +#include <Library/HobLib.h> >> +#include <Library/ResetSystemLib.h> >> +#include <Library/ReportStatusCodeLib.h> >> + >> + >> +// >> +// The maximum recurstion depth to ResetSystem() by reset >> notification handlers >> +// >> +#define MAX_RESET_NOTIFY_DEPTH 10 >> + >> +// >> +// Data to put in GUIDed HOB >> +// >> +typedef struct { >> + UINT32 Signature; >> + UINT32 Count; >> + EFI_RESET_SYSTEM ResetFilters[0]; // >> ResetFilters[PcdGet32 (PcdMaximumResetNotifies)] >> +} RESET_FILTER_LIST; >> +#define RESET_FILTER_LIST_SIGNATURE SIGNATURE_32('r', 's', 't', 'l') >> + >> + >> +typedef struct { >> + EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI ResetFilter; >> + EFI_GUID *Guid; >> +} RESET_FILTER_INSTANCE; >> + >> +/** >> + Resets the entire platform. >> + >> + @param[in] ResetType The type of reset to perform. >> + @param[in] ResetStatus The status code for the reset. >> + @param[in] DataSize The size, in bytes, of ResetData. >> + @param[in] ResetData For a ResetType of EfiResetCold, >> EfiResetWarm, or >> + EfiResetShutdown the data buffer >> starts with a Null-terminated >> + string, optionally followed by >> additional binary data. >> + The string is a description that the >> caller may use to further >> + indicate the reason for the system >> reset. ResetData is only >> + valid if ResetStatus is something >> other than EFI_SUCCESS >> + unless the ResetType is >> EfiResetPlatformSpecific >> + where a minimum amount of ResetData >> is always required. >> + For a ResetType of >> EfiResetPlatformSpecific the data buffer >> + also starts with a Null-terminated >> string that is followed >> + by an EFI_GUID that describes the >> specific type of reset to perform. >> + >> +**/ >> +VOID >> +EFIAPI >> +ResetSystem2 ( >> + IN EFI_RESET_TYPE ResetType, >> + IN EFI_STATUS ResetStatus, >> + IN UINTN DataSize, >> + IN VOID *ResetData OPTIONAL >> + ); >> +/** >> + Register a notification function to be called when ResetSystem() is >> called. >> + >> + The RegisterResetNotify() function registers a notification >> function that is called when >> + ResetSystem()is called and prior to completing the reset of the >> platform. >> + The registered functions must not perform a platform reset >> themselves. These >> + notifications are intended only for the notification of components >> which may need some >> + special-purpose maintenance prior to the platform resetting. >> + >> + @param[in] This A pointer to the >> EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI instance. >> + @param[in] ResetFunction Points to the function to be called >> when a ResetSystem() is executed. >> + >> + @retval EFI_SUCCESS The reset notification function was >> successfully registered. >> + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. >> + @retval EFI_OUT_OF_RESOURCES There are not enough resources >> available to register the reset notification function. >> + @retval EFI_ALREADY_STARTED The reset notification function >> specified by ResetFunction has already been registered. >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +RegisterResetNotify ( >> + IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This, >> + IN EFI_RESET_SYSTEM ResetFunction >> + ); >> + >> +/** >> + Unregister a notification function. >> + >> + The UnregisterResetNotify() function removes the previously registered >> + notification using RegisterResetNotify(). >> + >> + @param[in] This A pointer to the >> EFI_RESET_NOTIFICATION_PROTOCOL instance. >> + @param[in] ResetFunction The pointer to the ResetFunction >> being unregistered. >> + >> + @retval EFI_SUCCESS The reset notification function was >> unregistered. >> + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. >> + @retval EFI_INVALID_PARAMETER The reset notification function >> specified by ResetFunction was not previously >> + registered using RegisterResetNotify(). >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +UnregisterResetNotify ( >> + IN EFI_RESET_NOTIFICATION_PROTOCOL *This, >> + IN EFI_RESET_SYSTEM ResetFunction >> + ); >> +#endif >> diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf >> new file mode 100644 >> index 0000000000..38fdd16ceb >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf >> @@ -0,0 +1,62 @@ >> +## @file >> +# This driver implements Reset2, ResetFilter and ResetHandler PPIs. >> +# >> +# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> +# >> +# 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 = ResetSystemPei >> + MODULE_UNI_FILE = ResetSystemPei.uni >> + FILE_GUID = 6141E486-7543-4F1A-A579-FF532ED78E75 >> + MODULE_TYPE = PEIM >> + VERSION_STRING = 1.0 >> + >> + ENTRY_POINT = InitializeResetSystem >> + >> +# >> +# The following information is for reference only and not required by >> the build tools. >> +# >> +# VALID_ARCHITECTURES = IA32 X64 >> +# >> + >> +[Sources] >> + ResetSystem.h >> + ResetSystem.c >> + >> +[Packages] >> + MdePkg/MdePkg.dec >> + MdeModulePkg/MdeModulePkg.dec >> + >> +[LibraryClasses] >> + BaseLib >> + BaseMemoryLib >> + DebugLib >> + PeiServicesLib >> + HobLib >> + PeimEntryPoint >> + ResetSystemLib >> + ReportStatusCodeLib >> + >> +[Ppis] >> + gEfiPeiReset2PpiGuid ## PRODUCES >> + gEdkiiPlatformSpecificResetFilterPpiGuid ## PRODUCES >> + gEdkiiPlatformSpecificResetHandlerPpiGuid ## PRODUCES >> + >> +[Pcd] >> + gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies >> + >> +[Depex] >> + TRUE >> + >> +[UserExtensions.TianoCore."ExtraFiles"] >> + ResetSystemPeiExtra.uni >> diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni >> new file mode 100644 >> index 0000000000..6d2d650c37 >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni >> @@ -0,0 +1,20 @@ >> +// /** @file >> +// This driver implements Reset2, ResetFilter and ResetHandler PPIs. >> +// >> +// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> +// >> +// 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. >> +// >> +// **/ >> + >> + >> +#string STR_MODULE_ABSTRACT #language en-US "Implements >> Reset2, ResetFilter and ResetHandler PPIs" >> + >> +#string STR_MODULE_DESCRIPTION #language en-US "This driver >> implements Reset2, ResetFilter and ResetHandler PPIs." >> + >> diff --git >> a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni >> new file mode 100644 >> index 0000000000..2681afc707 >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni >> @@ -0,0 +1,20 @@ >> +// /** @file >> +// ResetSystemPei Localized Strings and Content >> +// >> +// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> +// >> +// 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. >> +// >> +// **/ >> + >> +#string STR_PROPERTIES_MODULE_NAME >> +#language en-US >> +"Reset System PEIM" >> + >> + >> _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
On 2/7/2018 8:35 PM, Zeng, Star wrote: > On 2018/2/2 14:45, Ruiyu Ni wrote: >> This driver implements Reset2, ResetFilter and ResetHandler PPIs. >> >> Cc: Liming Gao <liming.gao@intel.com> >> Cc: Michael D Kinney <michael.d.kinney@intel.com> >> Cc: Star Zeng <star.zeng@intel.com> >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> > > Should ResetSystemPei be added in MdeModulePkg.dsc for build coverage? Good catch. I just found I wrongly added this module in commit: * MdeModulePkg: Add ResetUtility librray class and BASE instance That commit happens before this one. I might introduce this bug when rebasing the patches. I will change that commit and this commit to make sure ResetSystemPei is added in this commit. > > Same comment has been provided to ResetSystemRuntimeDxe. > Should be (*RecursionDepthPointer < MAX_RESET_NOTIFY_DEPTH) instead of > (*RecursionDepthPointer <= MAX_RESET_NOTIFY_DEPTH)> As I just replied, "<=" is the intention actually. > > > Thanks, > Star > >> --- >> MdeModulePkg/MdeModulePkg.dec | 4 + >> .../Universal/ResetSystemPei/ResetSystem.c | 355 >> +++++++++++++++++++++ >> .../Universal/ResetSystemPei/ResetSystem.h | 129 ++++++++ >> .../Universal/ResetSystemPei/ResetSystemPei.inf | 62 ++++ >> .../Universal/ResetSystemPei/ResetSystemPei.uni | 20 ++ >> .../ResetSystemPei/ResetSystemPeiExtra.uni | 20 ++ >> 6 files changed, 590 insertions(+) >> create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c >> create mode 100644 MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h >> create mode 100644 >> MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf >> create mode 100644 >> MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni >> create mode 100644 >> MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni >> >> diff --git a/MdeModulePkg/MdeModulePkg.dec >> b/MdeModulePkg/MdeModulePkg.dec >> index 1cc9bc8ea1..1b971d599f 100644 >> --- a/MdeModulePkg/MdeModulePkg.dec >> +++ b/MdeModulePkg/MdeModulePkg.dec >> @@ -1419,6 +1419,10 @@ [PcdsFixedAtBuild, PcdsPatchableInModule] >> # @Prompt CapsuleMax value in capsule report variable. >> gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleMax|0xFFFF|UINT16|0x00000107 >> + ## Indicates the allowable maximum number of Reset Filters or Reset >> Handlers in PEI phase. >> + # @Prompt Maximum Number of PEI Reset Filters or Reset Handlers. >> + >> gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies|0x10|UINT32|0x00000109 >> >> + >> [PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] >> ## This PCD defines the Console output row. The default value is >> 25 according to UEFI spec. >> # This PCD could be set to 0 then console output would be at max >> column and max row. >> diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c >> new file mode 100644 >> index 0000000000..720593de6a >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c >> @@ -0,0 +1,355 @@ >> +/** @file >> + Implementation of Reset2, ResetFilter and ResetHandler PPIs. >> + >> + Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> + >> + 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 "ResetSystem.h" >> + >> +GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mResetTypeStr[] = { >> + L"Cold", L"Warm", L"Shutdown", L"PlatformSpecific" >> +}; >> + >> +EFI_PEI_RESET2_PPI mPpiReset2 = { >> + ResetSystem2 >> +}; >> + >> +EFI_GUID *mProcessingOrder[] = { >> + &gEdkiiPlatformSpecificResetFilterPpiGuid, >> + &gEdkiiPlatformSpecificResetHandlerPpiGuid >> +}; >> + >> +RESET_FILTER_INSTANCE mResetFilter = { >> + { >> + RegisterResetNotify, >> + UnregisterResetNotify >> + }, >> + &gEdkiiPlatformSpecificResetFilterPpiGuid >> +}; >> + >> +RESET_FILTER_INSTANCE mResetHandler = { >> + { >> + RegisterResetNotify, >> + UnregisterResetNotify >> + }, >> + &gEdkiiPlatformSpecificResetHandlerPpiGuid >> +}; >> + >> +EFI_PEI_PPI_DESCRIPTOR mPpiListReset[] = { >> + { >> + EFI_PEI_PPI_DESCRIPTOR_PPI, >> + &gEfiPeiReset2PpiGuid, >> + &mPpiReset2 >> + }, >> + { >> + EFI_PEI_PPI_DESCRIPTOR_PPI, >> + &gEdkiiPlatformSpecificResetFilterPpiGuid, >> + &mResetFilter.ResetFilter >> + }, >> + { >> + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, >> + &gEdkiiPlatformSpecificResetHandlerPpiGuid, >> + &mResetHandler.ResetFilter >> + } >> +}; >> + >> +/** >> + Register a notification function to be called when ResetSystem() is >> called. >> + >> + The RegisterResetNotify() function registers a notification >> function that is called when >> + ResetSystem()is called and prior to completing the reset of the >> platform. >> + The registered functions must not perform a platform reset >> themselves. These >> + notifications are intended only for the notification of components >> which may need some >> + special-purpose maintenance prior to the platform resetting. >> + The list of registered reset notification functions are processed >> if ResetSystem()is called >> + before ExitBootServices(). The list of registered reset >> notification functions is ignored if >> + ResetSystem()is called after ExitBootServices(). >> + >> + @param[in] This A pointer to the >> EFI_RESET_NOTIFICATION_PROTOCOL instance. >> + @param[in] ResetFunction Points to the function to be called >> when a ResetSystem() is executed. >> + >> + @retval EFI_SUCCESS The reset notification function was >> successfully registered. >> + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. >> + @retval EFI_OUT_OF_RESOURCES There are not enough resources >> available to register the reset notification function. >> + @retval EFI_ALREADY_STARTED The reset notification function >> specified by ResetFunction has already been registered. >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +RegisterResetNotify ( >> + IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This, >> + IN EFI_RESET_SYSTEM ResetFunction >> + ) >> +{ >> + RESET_FILTER_INSTANCE *ResetFilter; >> + RESET_FILTER_LIST *List; >> + VOID *Hob; >> + UINTN Index; >> + >> + if (ResetFunction == NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + ResetFilter = (RESET_FILTER_INSTANCE *) This; >> + ASSERT (CompareGuid (ResetFilter->Guid, >> &gEdkiiPlatformSpecificResetFilterPpiGuid) || >> + CompareGuid (ResetFilter->Guid, >> &gEdkiiPlatformSpecificResetHandlerPpiGuid) >> + ); >> + >> + Hob = GetFirstGuidHob (ResetFilter->Guid); >> + if (Hob == NULL) { >> + // >> + // When the GUIDed HOB doesn't exist, create it. >> + // >> + List = (RESET_FILTER_LIST *)BuildGuidHob ( >> + ResetFilter->Guid, >> + sizeof (RESET_FILTER_LIST) + sizeof >> (EFI_RESET_SYSTEM) * PcdGet32 (PcdMaximumPeiResetNotifies) >> + ); >> + if (List == NULL) { >> + return EFI_OUT_OF_RESOURCES; >> + } >> + List->Signature = RESET_FILTER_LIST_SIGNATURE; >> + List->Count = PcdGet32 (PcdMaximumPeiResetNotifies); >> + ZeroMem (List->ResetFilters, sizeof (EFI_RESET_SYSTEM) * >> List->Count); >> + List->ResetFilters[0] = ResetFunction; >> + return EFI_SUCCESS; >> + } else { >> + List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob); >> + ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE); >> + // >> + // Firstly check whether the ResetFunction is already registerred. >> + // >> + for (Index = 0; Index < List->Count; Index++) { >> + if (List->ResetFilters[Index] == ResetFunction) { >> + break; >> + } >> + } >> + if (Index != List->Count) { >> + return EFI_ALREADY_STARTED; >> + } >> + >> + // >> + // Secondly find the first free slot. >> + // >> + for (Index = 0; Index < List->Count; Index++) { >> + if (List->ResetFilters[Index] == NULL) { >> + break; >> + } >> + } >> + >> + if (Index == List->Count) { >> + return EFI_OUT_OF_RESOURCES; >> + } >> + List->ResetFilters[Index] = ResetFunction; >> + return EFI_SUCCESS; >> + } >> +} >> + >> +/** >> + Unregister a notification function. >> + >> + The UnregisterResetNotify() function removes the previously registered >> + notification using RegisterResetNotify(). >> + >> + @param[in] This A pointer to the >> EFI_RESET_NOTIFICATION_PROTOCOL instance. >> + @param[in] ResetFunction The pointer to the ResetFunction >> being unregistered. >> + >> + @retval EFI_SUCCESS The reset notification function was >> unregistered. >> + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. >> + @retval EFI_INVALID_PARAMETER The reset notification function >> specified by ResetFunction was not previously >> + registered using RegisterResetNotify(). >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +UnregisterResetNotify ( >> + IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This, >> + IN EFI_RESET_SYSTEM ResetFunction >> + ) >> +{ >> + >> + RESET_FILTER_INSTANCE *ResetFilter; >> + RESET_FILTER_LIST *List; >> + VOID *Hob; >> + UINTN Index; >> + >> + if (ResetFunction == NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + ResetFilter = (RESET_FILTER_INSTANCE *)This; >> + ASSERT (CompareGuid (ResetFilter->Guid, >> &gEdkiiPlatformSpecificResetFilterPpiGuid) || >> + CompareGuid (ResetFilter->Guid, >> &gEdkiiPlatformSpecificResetHandlerPpiGuid) >> + ); >> + >> + Hob = GetFirstGuidHob (ResetFilter->Guid); >> + if (Hob == NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob); >> + ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE); >> + for (Index = 0; Index < List->Count; Index++) { >> + if (List->ResetFilters[Index] == ResetFunction) { >> + break; >> + } >> + } >> + >> + if (Index == List->Count) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + List->ResetFilters[Index] = NULL; >> + return EFI_SUCCESS; >> +} >> + >> + >> +/** >> + The PEIM's entry point. >> + >> + It initializes the Reset2, ResetFilter and ResetHandler PPIs. >> + >> + @param[in] FileHandle Handle of the file being invoked. >> + @param[in] PeiServices Describes the list of possible PEI Services. >> + >> + @retval EFI_SUCCESS The entry point is executed successfully. >> + @retval EFI_ALREADY_STARTED The Reset2 PPI was already installed. >> + @retval others Status code returned from >> PeiServicesInstallPpi(). >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +InitializeResetSystem ( >> + IN EFI_PEI_FILE_HANDLE FileHandle, >> + IN CONST EFI_PEI_SERVICES **PeiServices >> + ) >> +{ >> + EFI_STATUS Status; >> + VOID *Ppi; >> + >> + Status = PeiServicesLocatePpi (&gEfiPeiReset2PpiGuid, 0, NULL, >> (VOID **)&Ppi); >> + if (Status != EFI_NOT_FOUND) { >> + return EFI_ALREADY_STARTED; >> + } >> + >> + PeiServicesInstallPpi (mPpiListReset); >> + >> + return Status; >> +} >> + >> +/** >> + Resets the entire platform. >> + >> + @param[in] ResetType The type of reset to perform. >> + @param[in] ResetStatus The status code for the reset. >> + @param[in] DataSize The size, in bytes, of ResetData. >> + @param[in] ResetData For a ResetType of EfiResetCold, >> EfiResetWarm, or >> + EfiResetShutdown the data buffer >> starts with a Null-terminated >> + string, optionally followed by >> additional binary data. >> + The string is a description that the >> caller may use to further >> + indicate the reason for the system >> reset. ResetData is only >> + valid if ResetStatus is something >> other than EFI_SUCCESS >> + unless the ResetType is >> EfiResetPlatformSpecific >> + where a minimum amount of ResetData >> is always required. >> + For a ResetType of >> EfiResetPlatformSpecific the data buffer >> + also starts with a Null-terminated >> string that is followed >> + by an EFI_GUID that describes the >> specific type of reset to perform. >> +**/ >> +VOID >> +EFIAPI >> +ResetSystem2 ( >> + IN EFI_RESET_TYPE ResetType, >> + IN EFI_STATUS ResetStatus, >> + IN UINTN DataSize, >> + IN VOID *ResetData OPTIONAL >> + ) >> +{ >> + VOID *Hob; >> + UINTN Index; >> + RESET_FILTER_LIST *List; >> + UINTN OrderIndex; >> + UINT8 RecursionDepth; >> + UINT8 *RecursionDepthPointer; >> + >> + // >> + // The recursion depth is stored in GUIDed HOB using gEfiCallerIdGuid. >> + // >> + Hob = GetFirstGuidHob (&gEfiCallerIdGuid); >> + if (Hob == NULL) { >> + RecursionDepth = 0; >> + RecursionDepthPointer = BuildGuidDataHob (&gEfiCallerIdGuid, >> &RecursionDepth, sizeof (RecursionDepth)); >> + } else { >> + RecursionDepthPointer = (UINT8 *)GET_GUID_HOB_DATA (Hob); >> + } >> + // >> + // Only do REPORT_STATUS_CODE() on first call to ResetSystem() >> + // >> + if (*RecursionDepthPointer == 0) { >> + // >> + // Indicate reset system runtime service is called. >> + // >> + REPORT_STATUS_CODE (EFI_PROGRESS_CODE, >> (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM)); >> + } >> + >> + // >> + // Increase the call depth >> + // >> + (*RecursionDepthPointer)++; >> + DEBUG ((DEBUG_INFO, "PEI ResetSystem2: Reset call depth = %d.\n", >> *RecursionDepthPointer)); >> + >> + if (*RecursionDepthPointer <= MAX_RESET_NOTIFY_DEPTH) { >> + // >> + // Iteratively call Reset Filters and Reset Handlers. >> + // >> + for (OrderIndex = 0; OrderIndex < ARRAY_SIZE (mProcessingOrder); >> OrderIndex++) { >> + Hob = GetFirstGuidHob (mProcessingOrder[OrderIndex]); >> + if (Hob != NULL) { >> + List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob); >> + ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE); >> + >> + for (Index = 0; Index < List->Count; Index++) { >> + if (List->ResetFilters[Index] != NULL) { >> + List->ResetFilters[Index] (ResetType, ResetStatus, >> DataSize, ResetData); >> + } >> + } >> + } >> + } >> + } else { >> + ASSERT (ResetType < ARRAY_SIZE (mResetTypeStr)); >> + DEBUG ((DEBUG_ERROR, "PEI ResetSystem2: Maximum reset call depth >> is met. Use the current reset type: %s!\n", mResetTypeStr[ResetType])); >> + } >> + >> + switch (ResetType) { >> + case EfiResetWarm: >> + ResetWarm (); >> + break; >> + >> + case EfiResetCold: >> + ResetCold (); >> + break; >> + >> + case EfiResetShutdown: >> + ResetShutdown (); >> + return ; >> + >> + case EfiResetPlatformSpecific: >> + ResetPlatformSpecific (DataSize, ResetData); >> + return; >> + >> + default: >> + return ; >> + } >> + >> + // >> + // Given we should have reset getting here would be bad >> + // >> + ASSERT (FALSE); >> +} >> diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h >> new file mode 100644 >> index 0000000000..2fcc3592b6 >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h >> @@ -0,0 +1,129 @@ >> +/** @file >> + >> + Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> + >> + 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 _RESET_SYSTEM2_H_ >> +#define _RESET_SYSTEM2_H_ >> + >> + >> +#include <Uefi.h> >> +#include <PiPei.h> >> + >> +#include <Ppi/Reset2.h> >> +#include <Ppi/PlatformSpecificResetFilter.h> >> +#include <Ppi/PlatformSpecificResetHandler.h> >> + >> +#include <Library/BaseLib.h> >> +#include <Library/BaseMemoryLib.h> >> +#include <Library/DebugLib.h> >> +#include <Library/PeiServicesLib.h> >> +#include <Library/HobLib.h> >> +#include <Library/ResetSystemLib.h> >> +#include <Library/ReportStatusCodeLib.h> >> + >> + >> +// >> +// The maximum recurstion depth to ResetSystem() by reset >> notification handlers >> +// >> +#define MAX_RESET_NOTIFY_DEPTH 10 >> + >> +// >> +// Data to put in GUIDed HOB >> +// >> +typedef struct { >> + UINT32 Signature; >> + UINT32 Count; >> + EFI_RESET_SYSTEM ResetFilters[0]; // >> ResetFilters[PcdGet32 (PcdMaximumResetNotifies)] >> +} RESET_FILTER_LIST; >> +#define RESET_FILTER_LIST_SIGNATURE SIGNATURE_32('r', 's', 't', 'l') >> + >> + >> +typedef struct { >> + EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI ResetFilter; >> + EFI_GUID *Guid; >> +} RESET_FILTER_INSTANCE; >> + >> +/** >> + Resets the entire platform. >> + >> + @param[in] ResetType The type of reset to perform. >> + @param[in] ResetStatus The status code for the reset. >> + @param[in] DataSize The size, in bytes, of ResetData. >> + @param[in] ResetData For a ResetType of EfiResetCold, >> EfiResetWarm, or >> + EfiResetShutdown the data buffer >> starts with a Null-terminated >> + string, optionally followed by >> additional binary data. >> + The string is a description that the >> caller may use to further >> + indicate the reason for the system >> reset. ResetData is only >> + valid if ResetStatus is something >> other than EFI_SUCCESS >> + unless the ResetType is >> EfiResetPlatformSpecific >> + where a minimum amount of ResetData >> is always required. >> + For a ResetType of >> EfiResetPlatformSpecific the data buffer >> + also starts with a Null-terminated >> string that is followed >> + by an EFI_GUID that describes the >> specific type of reset to perform. >> + >> +**/ >> +VOID >> +EFIAPI >> +ResetSystem2 ( >> + IN EFI_RESET_TYPE ResetType, >> + IN EFI_STATUS ResetStatus, >> + IN UINTN DataSize, >> + IN VOID *ResetData OPTIONAL >> + ); >> +/** >> + Register a notification function to be called when ResetSystem() is >> called. >> + >> + The RegisterResetNotify() function registers a notification >> function that is called when >> + ResetSystem()is called and prior to completing the reset of the >> platform. >> + The registered functions must not perform a platform reset >> themselves. These >> + notifications are intended only for the notification of components >> which may need some >> + special-purpose maintenance prior to the platform resetting. >> + >> + @param[in] This A pointer to the >> EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI instance. >> + @param[in] ResetFunction Points to the function to be called >> when a ResetSystem() is executed. >> + >> + @retval EFI_SUCCESS The reset notification function was >> successfully registered. >> + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. >> + @retval EFI_OUT_OF_RESOURCES There are not enough resources >> available to register the reset notification function. >> + @retval EFI_ALREADY_STARTED The reset notification function >> specified by ResetFunction has already been registered. >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +RegisterResetNotify ( >> + IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This, >> + IN EFI_RESET_SYSTEM ResetFunction >> + ); >> + >> +/** >> + Unregister a notification function. >> + >> + The UnregisterResetNotify() function removes the previously registered >> + notification using RegisterResetNotify(). >> + >> + @param[in] This A pointer to the >> EFI_RESET_NOTIFICATION_PROTOCOL instance. >> + @param[in] ResetFunction The pointer to the ResetFunction >> being unregistered. >> + >> + @retval EFI_SUCCESS The reset notification function was >> unregistered. >> + @retval EFI_INVALID_PARAMETER ResetFunction is NULL. >> + @retval EFI_INVALID_PARAMETER The reset notification function >> specified by ResetFunction was not previously >> + registered using RegisterResetNotify(). >> + >> +**/ >> +EFI_STATUS >> +EFIAPI >> +UnregisterResetNotify ( >> + IN EFI_RESET_NOTIFICATION_PROTOCOL *This, >> + IN EFI_RESET_SYSTEM ResetFunction >> + ); >> +#endif >> diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf >> new file mode 100644 >> index 0000000000..38fdd16ceb >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf >> @@ -0,0 +1,62 @@ >> +## @file >> +# This driver implements Reset2, ResetFilter and ResetHandler PPIs. >> +# >> +# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> +# >> +# 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 = ResetSystemPei >> + MODULE_UNI_FILE = ResetSystemPei.uni >> + FILE_GUID = 6141E486-7543-4F1A-A579-FF532ED78E75 >> + MODULE_TYPE = PEIM >> + VERSION_STRING = 1.0 >> + >> + ENTRY_POINT = InitializeResetSystem >> + >> +# >> +# The following information is for reference only and not required by >> the build tools. >> +# >> +# VALID_ARCHITECTURES = IA32 X64 >> +# >> + >> +[Sources] >> + ResetSystem.h >> + ResetSystem.c >> + >> +[Packages] >> + MdePkg/MdePkg.dec >> + MdeModulePkg/MdeModulePkg.dec >> + >> +[LibraryClasses] >> + BaseLib >> + BaseMemoryLib >> + DebugLib >> + PeiServicesLib >> + HobLib >> + PeimEntryPoint >> + ResetSystemLib >> + ReportStatusCodeLib >> + >> +[Ppis] >> + gEfiPeiReset2PpiGuid ## PRODUCES >> + gEdkiiPlatformSpecificResetFilterPpiGuid ## PRODUCES >> + gEdkiiPlatformSpecificResetHandlerPpiGuid ## PRODUCES >> + >> +[Pcd] >> + gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies >> + >> +[Depex] >> + TRUE >> + >> +[UserExtensions.TianoCore."ExtraFiles"] >> + ResetSystemPeiExtra.uni >> diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni >> new file mode 100644 >> index 0000000000..6d2d650c37 >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni >> @@ -0,0 +1,20 @@ >> +// /** @file >> +// This driver implements Reset2, ResetFilter and ResetHandler PPIs. >> +// >> +// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> +// >> +// 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. >> +// >> +// **/ >> + >> + >> +#string STR_MODULE_ABSTRACT #language en-US "Implements >> Reset2, ResetFilter and ResetHandler PPIs" >> + >> +#string STR_MODULE_DESCRIPTION #language en-US "This driver >> implements Reset2, ResetFilter and ResetHandler PPIs." >> + >> diff --git >> a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni >> b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni >> new file mode 100644 >> index 0000000000..2681afc707 >> --- /dev/null >> +++ b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni >> @@ -0,0 +1,20 @@ >> +// /** @file >> +// ResetSystemPei Localized Strings and Content >> +// >> +// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> >> +// >> +// 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. >> +// >> +// **/ >> + >> +#string STR_PROPERTIES_MODULE_NAME >> +#language en-US >> +"Reset System PEIM" >> + >> + >> > -- Thanks, Ray _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
© 2016 - 2024 Red Hat, Inc.