diff --git a/IpmiFeaturePkg/Include/Guid/PlatformPowerRestorePolicy.h b/IpmiFeaturePkg/Include/Guid/PlatformPowerRestorePolicy.h new file mode 100644 index 0000000..777c937 --- /dev/null +++ b/IpmiFeaturePkg/Include/Guid/PlatformPowerRestorePolicy.h @@ -0,0 +1,32 @@ +/** @file PlatformPowerRestorePolicy.h + + Platform Power Restore Policy Definition + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef PLATFORM_POWER_RESTORE_POLICY_H_ +#define PLATFORM_POWER_RESTORE_POLICY_H_ + +#define PLATFORM_POWER_RESTORE_POLICY_GUID {0x85bcbff7, 0x8f9d, 0x4997, {0xac, 0x46, 0x5b, 0x36, 0x70, 0x0b, 0x0b, 0x85}} + +// +// Power Restore Policy definition from IPMI Spec. +// +typedef enum { + PowerRestorePolicyPowerOff = 0x00, + PowerRestorePolicyLastState = 0x01, + PowerRestorePolicyPowerOn = 0x02, + PowerRestorePolicyNoChange = 0x03, +} PLATFORM_POWER_RESTORE_POLICY_TYPE; + +#pragma pack(1) + +typedef struct _PLATFORM_POWER_RESTORE_POLICY { + PLATFORM_POWER_RESTORE_POLICY_TYPE PolicyValue; +} PLATFORM_POWER_RESTORE_POLICY; + +#pragma pack() + +#endif //#ifdef PLATFORM_POWER_RESTORE_POLICY_H_ diff --git a/IpmiFeaturePkg/Include/Library/PlatformPowerRestorePolicyConfigurationLib.h b/IpmiFeaturePkg/Include/Library/PlatformPowerRestorePolicyConfigurationLib.h deleted file mode 100644 index 87a1d4d..0000000 --- a/IpmiFeaturePkg/Include/Library/PlatformPowerRestorePolicyConfigurationLib.h +++ /dev/null @@ -1,35 +0,0 @@ -/** @file PlatformPowerRestorePolicyConfigurationLib.h - - Platform Power Restore Policy Configuration Library interface - - Copyright (c) Microsoft Corporation. - SPDX-License-Identifier: BSD-2-Clause-Patent -**/ - -#ifndef PLATFORM_POWER_RESTORE_POLICY_CONFIGURATION_LIB_H_ -#define PLATFORM_POWER_RESTORE_POLICY_CONFIGURATION_LIB_H_ - -// -// Power Restore Policy definition from IPMI Spec. -// -#define POWER_RESTORE_POLICY_POWER_OFF 0x00 -#define POWER_RESTORE_POLICY_LAST_STATE 0x01 -#define POWER_RESTORE_POLICY_POWER_ON 0x02 -#define POWER_RESTORE_POLICY_NO_CHANGE 0x03 // "Set Power Restore Policy" -#define POWER_RESTORE_POLICY_UNKNOWN 0x03 // "Get Chassis Status" - -/** - Get PowerRestorePolicy - - @param[out] PowerRestorePolicy The PowerRestorePolicy setting of the platform - - @retval EFI_INVALID_PARAMETER The input parameter is invalid. - @retval EFI_SUCCESS Get PowerRestorePolicy successfully. -**/ -EFI_STATUS -EFIAPI -GetPowerRestorePolicy ( - OUT UINT8 *PowerRestorePolicy - ); - -#endif //#ifdef PLATFORM_POWER_RESTORE_POLICY_CONFIGURATION_LIB_H_ diff --git a/IpmiFeaturePkg/IpmiFeaturePkg.dec b/IpmiFeaturePkg/IpmiFeaturePkg.dec index 0340fe8..283d140 100644 --- a/IpmiFeaturePkg/IpmiFeaturePkg.dec +++ b/IpmiFeaturePkg/IpmiFeaturePkg.dec @@ -31,12 +31,12 @@ IpmiWatchdogLib|Include/Library/IpmiWatchdogLib.h IpmiBootOptionLib|Include/Library/IpmiBootOptionLib.h PlatformCmosClearLib|Include/Library/PlatformCmosClearLib.h - PlatformPowerRestorePolicyConfigurationLib|Include/Library/PlatformPowerRestorePolicyConfigurationLib.h [Guids] gIpmiFeaturePkgTokenSpaceGuid = {0xc05283f6, 0xd6a8, 0x48f3, {0x9b, 0x59, 0xfb, 0xca, 0x71, 0x32, 0x0f, 0x12}} gIpmiBmcHobGuid = {0x3d133ac1, 0x8565, 0x4a08, {0xac, 0x50, 0x9d, 0xff, 0x55, 0x29, 0xac, 0x12}} gIpmiWatchdogPolicyGuid = {0x6b53a598, 0x4ff5, 0x43c5, {0x81, 0x83, 0x74, 0xd0, 0xe6, 0x34, 0xcd, 0x66}} + gPlatformPowerRestorePolicyGuid = {0x85bcbff7, 0x8f9d, 0x4997, {0xac, 0x46, 0x5b, 0x36, 0x70, 0x0b, 0x0b, 0x85}} [Ppis] gPeiIpmiTransportPpiGuid = {0x7bf5fecc, 0xc5b5, 0x4b25, {0x81, 0x1b, 0xb4, 0xb5, 0xb, 0x28, 0x79, 0xf7}} diff --git a/IpmiFeaturePkg/IpmiFeaturePkg.dsc b/IpmiFeaturePkg/IpmiFeaturePkg.dsc index cc581df..b1c0df4 100644 --- a/IpmiFeaturePkg/IpmiFeaturePkg.dsc +++ b/IpmiFeaturePkg/IpmiFeaturePkg.dsc @@ -54,7 +54,6 @@ IpmiTransportLib|IpmiFeaturePkg/Library/IpmiTransportLibNull/IpmiTransportLibNull.inf IpmiPlatformLib|IpmiFeaturePkg/Library/IpmiPlatformLibNull/IpmiPlatformLibNull.inf PlatformCmosClearLib|IpmiFeaturePkg/Library/PlatformCmosClearLibNull/PlatformCmosClearLibNull.inf - PlatformPowerRestorePolicyConfigurationLib|IpmiFeaturePkg/Library/PlatformPowerRestorePolicyConfigurationLibNull/PlatformPowerRestorePolicyConfigurationLibNull.inf [LibraryClasses.common.PEI_CORE,LibraryClasses.common.PEIM] ####################################### @@ -112,7 +111,7 @@ IpmiFeaturePkg/Library/IpmiBootOptionLib/IpmiBootOptionLib.inf IpmiFeaturePkg/IpmiCmosClear/IpmiCmosClear.inf IpmiFeaturePkg/Library/PlatformCmosClearLibNull/PlatformCmosClearLibNull.inf - IpmiFeaturePkg/Library/PlatformPowerRestorePolicyConfigurationLibNull/PlatformPowerRestorePolicyConfigurationLibNull.inf + IpmiFeaturePkg/PlatformPowerRestorePolicyDefault/PlatformPowerRestorePolicyDefault.inf # Transport Libraries IpmiFeaturePkg/Library/IpmiTransportLibNull/IpmiTransportLibNull.inf diff --git a/IpmiFeaturePkg/IpmiPowerRestorePolicy/IpmiPowerRestorePolicy.c b/IpmiFeaturePkg/IpmiPowerRestorePolicy/IpmiPowerRestorePolicy.c index 0eabc49..986015a 100644 --- a/IpmiFeaturePkg/IpmiPowerRestorePolicy/IpmiPowerRestorePolicy.c +++ b/IpmiFeaturePkg/IpmiPowerRestorePolicy/IpmiPowerRestorePolicy.c @@ -10,7 +10,10 @@ #include #include #include -#include +#include +#include + +#define POWER_RESTORE_POLICY_UNKNOWN 0x03 // "Get Chassis Status" /** Configure Power Restore Policy via IPMI @@ -31,9 +34,10 @@ IpmiPowerRestorePolicyEntry ( EFI_STATUS Status; IPMI_GET_CHASSIS_STATUS_RESPONSE ChassisStatusRespData; UINT8 CurrentPowerRestorePolicy; - UINT8 PlatformPowerRestorePolicy; + PLATFORM_POWER_RESTORE_POLICY PlatformPowerRestorePolicy; IPMI_SET_POWER_RESTORE_POLICY_REQUEST SetRestorePolicyRequest; IPMI_SET_POWER_RESTORE_POLICY_RESPONSE SetRestorePolicyResponse; + UINT16 PolicySize = sizeof (PLATFORM_POWER_RESTORE_POLICY); // // Get current power restore policy setting @@ -52,16 +56,15 @@ IpmiPowerRestorePolicyEntry ( // // Get platform power restore policy setting // - Status = GetPowerRestorePolicy (&PlatformPowerRestorePolicy); - + Status = GetPolicy (&gPlatformPowerRestorePolicyGuid, NULL, &PlatformPowerRestorePolicy, &PolicySize); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "[%a] - GetPowerRestorePolicy: %r\n", __FUNCTION__, Status)); + DEBUG ((DEBUG_ERROR, "%a: Failed to get platform power restore policy! %r\n", __FUNCTION__, Status)); return Status; } DEBUG ((DEBUG_VERBOSE, "[%a] - PlatformPowerRestorePolicy: 0x%x\n", __FUNCTION__, PlatformPowerRestorePolicy)); - if ( PlatformPowerRestorePolicy == CurrentPowerRestorePolicy) { + if ( PlatformPowerRestorePolicy.PolicyValue == CurrentPowerRestorePolicy) { // Just return if CurrentPowerRestorePolicy the same with PlatformPowerRestorePolicy DEBUG ((DEBUG_VERBOSE, "[%a] - Current Power Restore Policy is consistent with platform setting\n", __FUNCTION__)); return EFI_SUCCESS; @@ -70,8 +73,8 @@ IpmiPowerRestorePolicyEntry ( // // If platform setting is not POWER_RESTORE_POLICY_NO_CHANGE, then configure the power restore policy based on PlatformPowerRestorePolicy // - if (PlatformPowerRestorePolicy != POWER_RESTORE_POLICY_NO_CHANGE) { - SetRestorePolicyRequest.PowerRestorePolicy.Bits.PowerRestorePolicy = PlatformPowerRestorePolicy; + if (PlatformPowerRestorePolicy.PolicyValue != PowerRestorePolicyNoChange) { + SetRestorePolicyRequest.PowerRestorePolicy.Bits.PowerRestorePolicy = (UINT8)PlatformPowerRestorePolicy.PolicyValue; SetRestorePolicyRequest.PowerRestorePolicy.Bits.Reserved = 0; Status = IpmiSetPowerRestorePolicy (&SetRestorePolicyRequest, &SetRestorePolicyResponse); if (EFI_ERROR (Status)) { diff --git a/IpmiFeaturePkg/IpmiPowerRestorePolicy/IpmiPowerRestorePolicy.inf b/IpmiFeaturePkg/IpmiPowerRestorePolicy/IpmiPowerRestorePolicy.inf index 70c6f3b..07be157 100644 --- a/IpmiFeaturePkg/IpmiPowerRestorePolicy/IpmiPowerRestorePolicy.inf +++ b/IpmiFeaturePkg/IpmiPowerRestorePolicy/IpmiPowerRestorePolicy.inf @@ -22,14 +22,19 @@ MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec IpmiFeaturePkg/IpmiFeaturePkg.dec + PolicyServicePkg/PolicyServicePkg.dec [LibraryClasses] PeimEntryPoint DebugLib BaseLib IpmiCommandLib - PlatformPowerRestorePolicyConfigurationLib + PolicyLib + +[Guids] + gPlatformPowerRestorePolicyGuid [Depex] - gPeiIpmiTransportPpiGuid + gPeiIpmiTransportPpiGuid AND + gPlatformPowerRestorePolicyGuid diff --git a/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/MockApi.c b/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/MockApi.c index 46a23dd..d05dcf1 100644 --- a/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/MockApi.c +++ b/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/MockApi.c @@ -20,22 +20,38 @@ #include #include #include -#include +#include +#include /** - @brief Mock this api locally in the test Get the Platform Power Restore Policy Setting Value object - - @param[out] PowerRestorePolicy - @retval EFI_STATUS -**/ + * @brief Mock version of GetPolicy + * + */ EFI_STATUS EFIAPI -GetPowerRestorePolicy ( - OUT UINT8 *PowerRestorePolicy +GetPolicy ( + IN CONST EFI_GUID *PolicyGuid, + OUT UINT64 *Attributes OPTIONAL, + OUT VOID *Policy, + IN OUT UINT16 *PolicySize ) { - *PowerRestorePolicy = mock_type (UINT8); - return mock_type (UINTN); + EFI_STATUS Status; + + // Check that this is the right guid being used + check_expected_ptr (PolicyGuid); + + Status = mock_type (EFI_STATUS); + + if (!EFI_ERROR (Status)) { + // Set Attributes, Policy and PolicySize + *PolicySize = (UINT16)mock (); + if (Policy != NULL) { + CopyMem ((VOID *)Policy, (VOID *)mock (), *PolicySize); + } + } + + return Status; } EFI_STATUS diff --git a/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/TestIpmiPowerRestorePolicyHost.c b/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/TestIpmiPowerRestorePolicyHost.c index 07953dc..26b2841 100644 --- a/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/TestIpmiPowerRestorePolicyHost.c +++ b/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/TestIpmiPowerRestorePolicyHost.c @@ -24,20 +24,11 @@ #include #include #include -#include +#include #define UNIT_TEST_NAME "TestIpmiPowerRestorePolicyHost" #define UNIT_TEST_VERSION "1.0" -// -// Power Restore Policy configuration. -// -#define POWER_RESTORE_POLICY_POWER_OFF 0x00 -#define POWER_RESTORE_POLICY_LAST_STATE 0x01 -#define POWER_RESTORE_POLICY_POWER_ON 0x02 -#define POWER_RESTORE_POLICY_NO_CHANGE 0x03 // "Set Power Restore Policy" -#define POWER_RESTORE_POLICY_UNKNOWN 0x03 // "Get Chassis Status" - /// /// Global variables used in unit tests /// @@ -74,11 +65,11 @@ TestNoUpdateToBmcWhenLocalInvalid ( ); // IpmiGetChassisStatus returns current power state, restore power policy is bits [6:5] in current power state - will_return (IpmiGetChassisStatus, POWER_RESTORE_POLICY_POWER_ON << 5); + will_return (IpmiGetChassisStatus, PowerRestorePolicyPowerOn << 5); will_return (IpmiGetChassisStatus, EFI_DEVICE_ERROR); - will_return (GetPowerRestorePolicy, POWER_RESTORE_POLICY_POWER_ON); - will_return (GetPowerRestorePolicy, EFI_DEVICE_ERROR); // fail to retrieve local value will prevent update + expect_value (GetPolicy, PolicyGuid, &gPlatformPowerRestorePolicyGuid); + will_return (GetPolicy, EFI_DEVICE_ERROR); // fail to retrieve local value will prevent update // Would be nice to explicitly check that a function isn't called, test framework does not allow a value of zero // However, not specifying an expected value will fail if it is called. @@ -110,8 +101,11 @@ TestNoUpdateToBmcWhenInSync ( IN UNIT_TEST_CONTEXT Context ) { - EFI_PEI_FILE_HANDLE FileHandle; - EFI_PEI_SERVICES *PeiServices; + EFI_PEI_FILE_HANDLE FileHandle; + EFI_PEI_SERVICES *PeiServices; + PLATFORM_POWER_RESTORE_POLICY RestorePolicy; + + RestorePolicy.PolicyValue = PowerRestorePolicyPowerOff; ZeroMem ( &FileHandle, @@ -123,11 +117,13 @@ TestNoUpdateToBmcWhenInSync ( // expect_function_calls (IpmiSetPowerRestorePolicy, 0); // IpmiGetChassisStatus returns current power state, restore power policy is bits [6:5] in current power state - will_return (IpmiGetChassisStatus, POWER_RESTORE_POLICY_POWER_OFF << 5); + will_return (IpmiGetChassisStatus, PowerRestorePolicyPowerOff << 5); will_return (IpmiGetChassisStatus, EFI_SUCCESS); - will_return (GetPowerRestorePolicy, POWER_RESTORE_POLICY_POWER_OFF); - will_return (GetPowerRestorePolicy, EFI_SUCCESS); // fail to retrieve local value will prevent update + expect_value (GetPolicy, PolicyGuid, &gPlatformPowerRestorePolicyGuid); + will_return (GetPolicy, EFI_SUCCESS); + will_return (GetPolicy, sizeof (RestorePolicy)); + will_return (GetPolicy, &RestorePolicy); EFI_STATUS status = IpmiPowerRestorePolicyEntry ( FileHandle, @@ -136,11 +132,14 @@ TestNoUpdateToBmcWhenInSync ( UT_ASSERT_EQUAL (status, EFI_SUCCESS); - will_return (IpmiGetChassisStatus, POWER_RESTORE_POLICY_LAST_STATE << 5); + will_return (IpmiGetChassisStatus, PowerRestorePolicyLastState << 5); will_return (IpmiGetChassisStatus, EFI_SUCCESS); - will_return (GetPowerRestorePolicy, POWER_RESTORE_POLICY_LAST_STATE); - will_return (GetPowerRestorePolicy, EFI_SUCCESS); // fail to retrieve local value will prevent update + RestorePolicy.PolicyValue = PowerRestorePolicyLastState; + expect_value (GetPolicy, PolicyGuid, &gPlatformPowerRestorePolicyGuid); + will_return (GetPolicy, EFI_SUCCESS); + will_return (GetPolicy, sizeof (RestorePolicy)); + will_return (GetPolicy, &RestorePolicy); status = IpmiPowerRestorePolicyEntry ( FileHandle, @@ -167,8 +166,11 @@ TestNoUpdateToBmcWhenLocalValueIsNoChange ( IN UNIT_TEST_CONTEXT Context ) { - EFI_PEI_FILE_HANDLE FileHandle; - EFI_PEI_SERVICES *PeiServices; + EFI_PEI_FILE_HANDLE FileHandle; + EFI_PEI_SERVICES *PeiServices; + PLATFORM_POWER_RESTORE_POLICY RestorePolicy; + + RestorePolicy.PolicyValue = PowerRestorePolicyNoChange; ZeroMem ( &FileHandle, @@ -180,11 +182,13 @@ TestNoUpdateToBmcWhenLocalValueIsNoChange ( // expect_function_calls (IpmiSetPowerRestorePolicy, 0); // IpmiGetChassisStatus returns current power state, restore power policy is bits [6:5] in current power state - will_return (IpmiGetChassisStatus, POWER_RESTORE_POLICY_POWER_OFF << 5); + will_return (IpmiGetChassisStatus, PowerRestorePolicyPowerOff << 5); will_return (IpmiGetChassisStatus, EFI_SUCCESS); - will_return (GetPowerRestorePolicy, POWER_RESTORE_POLICY_NO_CHANGE); - will_return (GetPowerRestorePolicy, EFI_SUCCESS); // fail to retrieve local value will prevent update + expect_value (GetPolicy, PolicyGuid, &gPlatformPowerRestorePolicyGuid); + will_return (GetPolicy, EFI_SUCCESS); + will_return (GetPolicy, sizeof (RestorePolicy)); + will_return (GetPolicy, &RestorePolicy); EFI_STATUS status = IpmiPowerRestorePolicyEntry ( FileHandle, @@ -211,8 +215,11 @@ TestFailReturnedIfBmcUpdateFails ( IN UNIT_TEST_CONTEXT Context ) { - EFI_PEI_FILE_HANDLE FileHandle; - EFI_PEI_SERVICES *PeiServices; + EFI_PEI_FILE_HANDLE FileHandle; + EFI_PEI_SERVICES *PeiServices; + PLATFORM_POWER_RESTORE_POLICY RestorePolicy; + + RestorePolicy.PolicyValue = PowerRestorePolicyPowerOn; ZeroMem ( &FileHandle, @@ -220,14 +227,16 @@ TestFailReturnedIfBmcUpdateFails ( ); // IpmiGetChassisStatus returns current power state, restore power policy is bits [6:5] in current power state - will_return (IpmiGetChassisStatus, POWER_RESTORE_POLICY_POWER_OFF << 5); + will_return (IpmiGetChassisStatus, PowerRestorePolicyPowerOff << 5); will_return (IpmiGetChassisStatus, EFI_SUCCESS); - will_return (GetPowerRestorePolicy, POWER_RESTORE_POLICY_POWER_ON); - will_return (GetPowerRestorePolicy, EFI_SUCCESS); // fail to retrieve local value will prevent update + expect_value (GetPolicy, PolicyGuid, &gPlatformPowerRestorePolicyGuid); + will_return (GetPolicy, EFI_SUCCESS); + will_return (GetPolicy, sizeof (RestorePolicy)); + will_return (GetPolicy, &RestorePolicy); expect_function_calls (IpmiSetPowerRestorePolicy, 1); - expect_value (IpmiSetPowerRestorePolicy, ChassisControlRequest->PowerRestorePolicy.Uint8, POWER_RESTORE_POLICY_POWER_ON); + expect_value (IpmiSetPowerRestorePolicy, ChassisControlRequest->PowerRestorePolicy.Uint8, PowerRestorePolicyPowerOn); will_return (IpmiSetPowerRestorePolicy, 0); // completion code success will_return (IpmiSetPowerRestorePolicy, EFI_INVALID_PARAMETER); // @@ -240,14 +249,17 @@ TestFailReturnedIfBmcUpdateFails ( UT_ASSERT_EQUAL (status, EFI_INVALID_PARAMETER); // test that if IpmiSetPowerRestorePolicy returns success, but completion code is not, then will also fail - will_return (IpmiGetChassisStatus, POWER_RESTORE_POLICY_POWER_ON << 5); + will_return (IpmiGetChassisStatus, PowerRestorePolicyPowerOn << 5); will_return (IpmiGetChassisStatus, EFI_SUCCESS); - will_return (GetPowerRestorePolicy, POWER_RESTORE_POLICY_POWER_OFF); - will_return (GetPowerRestorePolicy, EFI_SUCCESS); // fail to retrieve local value will prevent update + RestorePolicy.PolicyValue = PowerRestorePolicyPowerOff; + expect_value (GetPolicy, PolicyGuid, &gPlatformPowerRestorePolicyGuid); + will_return (GetPolicy, EFI_SUCCESS); + will_return (GetPolicy, sizeof (RestorePolicy)); + will_return (GetPolicy, &RestorePolicy); expect_function_calls (IpmiSetPowerRestorePolicy, 1); - expect_value (IpmiSetPowerRestorePolicy, ChassisControlRequest->PowerRestorePolicy.Uint8, POWER_RESTORE_POLICY_POWER_OFF); + expect_value (IpmiSetPowerRestorePolicy, ChassisControlRequest->PowerRestorePolicy.Uint8, PowerRestorePolicyPowerOff); will_return (IpmiSetPowerRestorePolicy, 2); // completion code fail will_return (IpmiSetPowerRestorePolicy, EFI_SUCCESS); // fail to retrieve local value will prevent update @@ -277,8 +289,11 @@ TestValidBmcUpdate ( IN UNIT_TEST_CONTEXT Context ) { - EFI_PEI_FILE_HANDLE FileHandle; - EFI_PEI_SERVICES *PeiServices; + EFI_PEI_FILE_HANDLE FileHandle; + EFI_PEI_SERVICES *PeiServices; + PLATFORM_POWER_RESTORE_POLICY RestorePolicy; + + RestorePolicy.PolicyValue = PowerRestorePolicyPowerOff; ZeroMem ( &FileHandle, @@ -286,14 +301,16 @@ TestValidBmcUpdate ( ); // test that if IpmiSetPowerRestorePolicy returns success, but completion code is not, then will also fail - will_return (IpmiGetChassisStatus, POWER_RESTORE_POLICY_POWER_ON << 5); + will_return (IpmiGetChassisStatus, PowerRestorePolicyPowerOn << 5); will_return (IpmiGetChassisStatus, EFI_SUCCESS); - will_return (GetPowerRestorePolicy, POWER_RESTORE_POLICY_POWER_OFF); - will_return (GetPowerRestorePolicy, EFI_SUCCESS); // fail to retrieve local value will prevent update + expect_value (GetPolicy, PolicyGuid, &gPlatformPowerRestorePolicyGuid); + will_return (GetPolicy, EFI_SUCCESS); + will_return (GetPolicy, sizeof (RestorePolicy)); + will_return (GetPolicy, &RestorePolicy); expect_function_calls (IpmiSetPowerRestorePolicy, 1); - expect_value (IpmiSetPowerRestorePolicy, ChassisControlRequest->PowerRestorePolicy.Uint8, POWER_RESTORE_POLICY_POWER_OFF); + expect_value (IpmiSetPowerRestorePolicy, ChassisControlRequest->PowerRestorePolicy.Uint8, PowerRestorePolicyPowerOff); will_return (IpmiSetPowerRestorePolicy, 0); // completion code success will_return (IpmiSetPowerRestorePolicy, EFI_SUCCESS); // fail to retrieve local value will prevent update diff --git a/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/TestIpmiPowerRestorePolicyHost.inf b/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/TestIpmiPowerRestorePolicyHost.inf index ff560a7..a7f0bad 100644 --- a/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/TestIpmiPowerRestorePolicyHost.inf +++ b/IpmiFeaturePkg/IpmiPowerRestorePolicy/UnitTest/TestIpmiPowerRestorePolicyHost.inf @@ -23,7 +23,10 @@ VERSION_STRING = 1.0 MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + PolicyServicePkg/PolicyServicePkg.dec +[Guids] + gPlatformPowerRestorePolicyGuid [LibraryClasses] BaseLib diff --git a/IpmiFeaturePkg/Library/PlatformPowerRestorePolicyConfigurationLibNull/PlatformPowerRestorePolicyConfigurationLibNull.c b/IpmiFeaturePkg/Library/PlatformPowerRestorePolicyConfigurationLibNull/PlatformPowerRestorePolicyConfigurationLibNull.c deleted file mode 100644 index ea4829a..0000000 --- a/IpmiFeaturePkg/Library/PlatformPowerRestorePolicyConfigurationLibNull/PlatformPowerRestorePolicyConfigurationLibNull.c +++ /dev/null @@ -1,31 +0,0 @@ -/** @file PlatformPowerRestorePolicyConfigurationLibNull.c - - Copyright (c) Microsoft Corporation. - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ -#include -#include - -/** - Get PowerRestorePolicy - - @param[out] PowerRestorePolicy The PowerRestorePolicy setting of the platform - - @retval EFI_INVALID_PARAMETER The input parameter is invalid. - @retval EFI_SUCCESS Get PowerRestorePolicy successfully. -**/ -EFI_STATUS -EFIAPI -GetPowerRestorePolicy ( - OUT UINT8 *PowerRestorePolicy - ) -{ - if (PowerRestorePolicy == NULL) { - return EFI_INVALID_PARAMETER; - } - - *PowerRestorePolicy = POWER_RESTORE_POLICY_NO_CHANGE; - - return EFI_SUCCESS; -} diff --git a/IpmiFeaturePkg/Library/PlatformPowerRestorePolicyConfigurationLibNull/PlatformPowerRestorePolicyConfigurationLibNull.inf b/IpmiFeaturePkg/Library/PlatformPowerRestorePolicyConfigurationLibNull/PlatformPowerRestorePolicyConfigurationLibNull.inf deleted file mode 100644 index a9a9628..0000000 --- a/IpmiFeaturePkg/Library/PlatformPowerRestorePolicyConfigurationLibNull/PlatformPowerRestorePolicyConfigurationLibNull.inf +++ /dev/null @@ -1,32 +0,0 @@ -## @file PlatformPowerRestorePolicyConfigurationLibNull.inf -# -# Copyright (c) Microsoft Corporation. -# SPDX-License-Identifier: BSD-2-Clause-Patent -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PlatformPowerRestorePolicyConfigurationLibNull - FILE_GUID = 3D4E325A-0A2D-4BE7-8238-4FDC714CB903 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = PlatformPowerRestorePolicyConfigurationLib -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 AARCH64 -# - -[Sources] - PlatformPowerRestorePolicyConfigurationLibNull.c - -[Packages] - MdePkg/MdePkg.dec - IpmiFeaturePkg/IpmiFeaturePkg.dec - -[LibraryClasses] - -[Guids] - -[Depex] diff --git a/IpmiFeaturePkg/PlatformPowerRestorePolicyDefault/PlatformPowerRestorePolicyDefault.c b/IpmiFeaturePkg/PlatformPowerRestorePolicyDefault/PlatformPowerRestorePolicyDefault.c new file mode 100644 index 0000000..83226ea --- /dev/null +++ b/IpmiFeaturePkg/PlatformPowerRestorePolicyDefault/PlatformPowerRestorePolicyDefault.c @@ -0,0 +1,45 @@ +/** @file PlatformPowerRestorePolicyDefault.c + + This driver provides default implementation of platform power restore policy. + Platform can choose to either use this policy or produce policy in their platform code. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + Produce the default implementation of platform power restore policy. + + @param[in] FileHandle Handle of the file + @param[in] PeiServices List of possible PEI Services. + + @return EFI_SUCCESS Power Restore Policy is configured to expected setting successfully. + @return Others Failed to configure Power Restore Policy +**/ +EFI_STATUS +EFIAPI +PlatformPowerRestorePolicyDefaultEntry ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + PLATFORM_POWER_RESTORE_POLICY PlatformPowerRestorePolicy; + EFI_STATUS Status; + + // + // Set PlatformConfigPolicy + // + PlatformPowerRestorePolicy.PolicyValue = PowerRestorePolicyNoChange; + + Status = SetPolicy (&gPlatformPowerRestorePolicyGuid, POLICY_ATTRIBUTE_FINALIZED, &PlatformPowerRestorePolicy, sizeof (PLATFORM_POWER_RESTORE_POLICY)); + ASSERT (Status == EFI_SUCCESS); + + return EFI_SUCCESS; +} diff --git a/IpmiFeaturePkg/PlatformPowerRestorePolicyDefault/PlatformPowerRestorePolicyDefault.inf b/IpmiFeaturePkg/PlatformPowerRestorePolicyDefault/PlatformPowerRestorePolicyDefault.inf new file mode 100644 index 0000000..8a78a01 --- /dev/null +++ b/IpmiFeaturePkg/PlatformPowerRestorePolicyDefault/PlatformPowerRestorePolicyDefault.inf @@ -0,0 +1,37 @@ +## @file PlatformPowerRestorePolicyDefault.inf +# +# This driver provides default implementation of platform power restore policy. +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PlatformPowerRestorePolicyDefault + FILE_GUID = D723D6B8-D34A-4AB6-94E5-49F6F6EC79A0 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + ENTRY_POINT = PlatformPowerRestorePolicyDefaultEntry + +[Sources] + PlatformPowerRestorePolicyDefault.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + IpmiFeaturePkg/IpmiFeaturePkg.dec + PolicyServicePkg/PolicyServicePkg.dec + +[LibraryClasses] + PeimEntryPoint + DebugLib + BaseLib + PolicyLib + +[Guids] + gPlatformPowerRestorePolicyGuid + +[Depex] + gPeiPolicyPpiGuid