From ca071fd9e3c4822e0bd03c4f4dd46fdb9a855515 Mon Sep 17 00:00:00 2001 From: Stanley Chang Date: Tue, 22 Aug 2023 11:10:20 +0800 Subject: [PATCH] feat: [EHL] add EfiResetShutdown in ResetSystemLib The patch handles EfiResetShutdown. With the patch, one can test "reset off" under OS Loader. The patch also - fixes a wrong reference error in ResetSystemLib.inf. - add shutdown text in CmdReset.c Signed-off-by: Stanley Chang --- .../Library/ShellLib/CmdReset.c | 6 ++- .../Library/ResetSystemLib/ResetSystemLib.c | 45 +++++++++++++++++++ .../Library/ResetSystemLib/ResetSystemLib.inf | 2 +- .../ElkhartlakePkg/Include/Register/PmcRegs.h | 1 + 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/BootloaderCommonPkg/Library/ShellLib/CmdReset.c b/BootloaderCommonPkg/Library/ShellLib/CmdReset.c index 15315dfb..97c0c3a4 100644 --- a/BootloaderCommonPkg/Library/ShellLib/CmdReset.c +++ b/BootloaderCommonPkg/Library/ShellLib/CmdReset.c @@ -83,7 +83,11 @@ ShellCommandResetFunc ( FuncResetSystem = PlatformService->ResetSystem; } - ShellPrint (L"Resetting...\n"); + if (ResetType == EfiResetShutdown) { + ShellPrint (L"Start shutdowning...\n"); + } else { + ShellPrint (L"Resetting...\n"); + } FuncResetSystem (ResetType); return EFI_SUCCESS; diff --git a/Platform/ElkhartlakeBoardPkg/Library/ResetSystemLib/ResetSystemLib.c b/Platform/ElkhartlakeBoardPkg/Library/ResetSystemLib/ResetSystemLib.c index 2d75251b..09e9104e 100644 --- a/Platform/ElkhartlakeBoardPkg/Library/ResetSystemLib/ResetSystemLib.c +++ b/Platform/ElkhartlakeBoardPkg/Library/ResetSystemLib/ResetSystemLib.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -55,6 +56,46 @@ ResetWarm ( IoWrite8 ((UINTN) R_RST_CNT, V_RST_CNT_HARDRESET); } +/** + Calling this function causes the system to enter a power state equivalent + to the ACPI G2/S5 or G3 states. + + System shutdown should not return, if it returns, it means the system does + not support shut down reset. +**/ +VOID +ResetShutdown ( + VOID + ) +{ + UINT32 Data32; + /// + /// Firstly, GPE0_EN should be disabled to avoid any GPI waking up the system from S5 + /// + IoWrite32 (ACPI_BASE_ADDRESS + R_ACPI_IO_GPE0_EN_127_96, 0); + + /// + /// Secondly, PwrSts register must be cleared + /// + /// Write a "1" to bit[8] of power button status register at + /// (PM_BASE + PM1_STS_OFFSET) to clear this bit + /// + IoWrite16 (ACPI_BASE_ADDRESS + R_ACPI_IO_PM1_STS, B_ACPI_IO_PM1_STS_PWRBTN); + + /// + /// Finally, transform system into S5 sleep state + /// + Data32 = IoRead32 (ACPI_BASE_ADDRESS + R_ACPI_IO_PM1_CNT); + + Data32 = (UINT32) ((Data32 &~(B_ACPI_IO_PM1_CNT_SLP_TYP + B_ACPI_IO_PM1_CNT_SLP_EN)) | V_ACPI_IO_PM1_CNT_S5); + + IoWrite32 (ACPI_BASE_ADDRESS + R_ACPI_IO_PM1_CNT, Data32); + + Data32 = Data32 | B_ACPI_IO_PM1_CNT_SLP_EN; + + IoWrite32 (ACPI_BASE_ADDRESS + R_ACPI_IO_PM1_CNT, Data32); +} + /** Calling this function causes a PCH Global reset in addition to system-wide initialization. @@ -93,6 +134,10 @@ ResetSystem ( ResetCold (); break; + case EfiResetShutdown: + ResetShutdown (); + break; + case EfiResetPlatformSpecific: FspResetRequest = (EFI_STATUS)PcdGet32(PcdFspResetStatus); if (FspResetRequest == FSP_STATUS_RESET_REQUIRED_3) { diff --git a/Platform/ElkhartlakeBoardPkg/Library/ResetSystemLib/ResetSystemLib.inf b/Platform/ElkhartlakeBoardPkg/Library/ResetSystemLib/ResetSystemLib.inf index 6f5291d4..04e7f9a1 100644 --- a/Platform/ElkhartlakeBoardPkg/Library/ResetSystemLib/ResetSystemLib.inf +++ b/Platform/ElkhartlakeBoardPkg/Library/ResetSystemLib/ResetSystemLib.inf @@ -27,7 +27,7 @@ MdePkg/MdePkg.dec BootloaderCommonPkg/BootloaderCommonPkg.dec BootloaderCorePkg/BootloaderCorePkg.dec - Silicon/AlderlakePkg/AlderlakePkg.dec + Silicon/ElkhartlakePkg/ElkhartlakePkg.dec IntelFsp2Pkg/IntelFsp2Pkg.dec [LibraryClasses] diff --git a/Silicon/ElkhartlakePkg/Include/Register/PmcRegs.h b/Silicon/ElkhartlakePkg/Include/Register/PmcRegs.h index d4f77848..62176516 100644 --- a/Silicon/ElkhartlakePkg/Include/Register/PmcRegs.h +++ b/Silicon/ElkhartlakePkg/Include/Register/PmcRegs.h @@ -64,6 +64,7 @@ #define B_ACPI_IO_PM1_EN_PWRBTN BIT8 #define R_ACPI_IO_PM1_CNT 0x04 +#define B_ACPI_IO_PM1_CNT_SLP_EN BIT13 #define B_ACPI_IO_PM1_CNT_SLP_TYP (BIT12 | BIT11 | BIT10) #define V_ACPI_IO_PM1_CNT_S0 0 #define V_ACPI_IO_PM1_CNT_S3 (BIT12 | BIT10)