123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- /** @file
- Platform variable initialization PEIM.
- This PEIM determines whether to load variable defaults. Ordinarily, the
- decision is based on the boot mode, but an OEM hook is provided to override
- that. The appropriate HOBs and PCDs are created to signal DXE code to update
- the variable default values.
- @copyright
- Copyright 2012 - 2021 Intel Corporation. <BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
- **/
- #include "PlatformVariableInitPei.h"
- #include <Guid/PlatformVariableCommon.h>
- #include <Uefi/UefiInternalFormRepresentation.h>
- UINT16 BoardId = BOARD_ID_DEFAULT;
- EFI_PEI_PPI_DESCRIPTOR mPpiListPlatformVariableInit = {
- (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
- &gPlatformVariableInitPpiGuid,
- NULL
- };
- /**
- Apply platform variable defaults.
- Create HOBs and set PCDs to prompt the (re-)loading of variable defaults.
- Each step is attempted regardless of whether the previous steps succeeded.
- If multiple errors occur, only the last error code is returned.
- @param[in] Events Bitmap of events that occurred.
- @param[in] DefaultId Default store ID, STANDARD or MANUFACTURING.
- @retval EFI_SUCCESS All steps completed successfully.
- @retval EFI_OUT_OF_RESOURCES One of the HOBs could not be created.
- @retval EFI_NOT_FOUND The default data could not be found in FFS.
- **/
- EFI_STATUS
- ApplyPlatformVariableDefaults(
- IN UINT8 Events,
- IN UINT16 DefaultId
- )
- {
- VOID *Hob;
- EFI_STATUS Status;
- EFI_STATUS ReturnStatus;
- DEBUG((DEBUG_INFO, "Applying platform variable defaults:\n"));
- DEBUG((DEBUG_INFO, " Events = 0x%02x\n", Events));
- DEBUG((DEBUG_INFO, " DefaultId = 0x%04x\n", DefaultId));
- //
- // Assume success up front. This will be overwritten if errors occur.
- //
- ReturnStatus = EFI_SUCCESS;
- //
- // Send the bitmap of events to the platform variable DXE driver.
- //
- Hob = BuildGuidDataHob(&gPlatformVariableHobGuid, &Events, sizeof(Events));
- if (Hob == NULL) {
- DEBUG((DEBUG_ERROR, "Create platform var event HOB: %r!\n", EFI_OUT_OF_RESOURCES));
- ReturnStatus = EFI_OUT_OF_RESOURCES;
- }
- //
- // Locate variable default data in FFS and send it to the core variable DXE
- // driver to write.
- //
- Status = CreateDefaultVariableHob(DefaultId, BoardId);
- if (EFI_ERROR(Status)) {
- DEBUG((DEBUG_ERROR, "create default var HOB: %r!\n", Status));
- ReturnStatus = Status;
- }
- //
- // Set the PCD SKU ID.
- //
- LibPcdSetSku(BoardId);
- //
- // Set the PCD default store ID.
- //
- Status = PcdSet16S(PcdSetNvStoreDefaultId, DefaultId);
- if (EFI_ERROR(Status)) {
- DEBUG((DEBUG_ERROR, "setNVstore default ID PCD: %r!\n", Status));
- ReturnStatus = Status;
- }
- return ReturnStatus;
- }
- /**
- Perform the default variable initializations after variable service is ready.
- @param[in] PeiServices General purpose services available to every PEIM.
- @param[in] NotifyDescriptor Pointer to Notify PPI descriptor.
- @param[in] Interface Pointer to PPI.
- @retval EFI_SUCCESS Default setting is initialized into variable.
- @retval Other values Can't find the matched default setting.
- **/
- EFI_STATUS
- EFIAPI
- PlatformVariablePeiInit(
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
- IN VOID *Interface
- )
- {
- EFI_STATUS Status;
- UINT8 *SystemConfiguration;
- EFI_GUID *SystemConfigurationGuid;
- UINTN DataSize;
- EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariableServices;
- UINT8 Events;
- UINT16 DefaultId;
- BOOLEAN ApplyDefaults;
- SystemConfigurationGuid = PcdGetPtr(PcdSetupVariableGuid);
- Events = 0;
- DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;
- if (PlatformVariableHookForHobGeneration(Interface, &Events, &DefaultId)) {
- //
- // Use events bitmap and default ID returned by PlatformVariableHook.
- //
- ApplyDefaults = TRUE;
- }
- else {
- //
- // If the setup variable does not exist (yet), defaults should be applied.
- //
- VariableServices = (EFI_PEI_READ_ONLY_VARIABLE2_PPI *)Interface;
- SystemConfiguration = NULL;
- DataSize = 0;
- Status = VariableServices->GetVariable(
- VariableServices,
- PLATFORM_SETUP_VARIABLE_NAME,
- SystemConfigurationGuid,
- NULL,
- &DataSize,
- SystemConfiguration
- );
- //
- // Setup variable is not found. So, set the default setting.
- //
- if (Status == EFI_NOT_FOUND) {
- Events = NULL_VARIABLE_EVENT;
- DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;
- ApplyDefaults = TRUE;
- }
- else {
- ApplyDefaults = FALSE;
- }
- }
- if (ApplyDefaults) {
- Status = ApplyPlatformVariableDefaults(Events, DefaultId);
- }
- else {
- //
- // Normal case boot flow
- //
- Events = 0; // no events occurred
- BuildGuidDataHob (&gPlatformVariableHobGuid, &Events, sizeof (UINT8));
- //
- // Patch RP variable value with PC variable in the begining of PEI
- //
- Status = CreateRPVariableHob (EFI_HII_DEFAULT_CLASS_STANDARD, BoardId);
- }
- PeiServicesInstallPpi (&mPpiListPlatformVariableInit);
- return Status;
- }
- /**
- Variable Init BootMode CallBack
- Prepare Knob values based on boot mode
- Execute after discovering BootMode
- @param[in] PeiServices General purpose services available to every PEIM.
- @param[in] NotifyDescriptor Pointer to Notify PPI descriptor.
- @param[in] Interface Pointer to PPI.
- @retval EFI_SUCCESS Knob Values.
- @retval Other values
- **/
- EFI_STATUS
- EFIAPI
- VariableInitBootModeCallBack(
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
- IN VOID *Interface
- ) {
- EFI_BOOT_MODE BootMode;
- BOOLEAN ApplyDefaults;
- UINT8 Events;
- UINT16 DefaultId;
- EFI_STATUS Status;
- Events = 0;
- DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;
- ApplyDefaults = FALSE;
- //
- // Certain boot modes require defaults to be (re-)applied.
- //
- Status = PeiServicesGetBootMode(&BootMode);
- ASSERT_EFI_ERROR(Status);
- if (EFI_ERROR(Status)) {
- BootMode = BOOT_WITH_DEFAULT_SETTINGS;
- }
- if (BootMode == BOOT_WITH_MFG_MODE_SETTINGS) {
- Events = MFG_MODE_EVENT;
- DefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;
- ApplyDefaults = TRUE;
- }
- else if (BootMode == BOOT_IN_RECOVERY_MODE) {
- Events = RECOVERY_MODE_EVENT;
- DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;
- ApplyDefaults = TRUE;
- }
- else if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {
- Events = CMOS_CLEAR_EVENT;
- DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;
- ApplyDefaults = TRUE;
- }
- if (ApplyDefaults) {
- Status = ApplyPlatformVariableDefaults(Events, DefaultId);
- }
- return Status;
- }
- EFI_PEI_NOTIFY_DESCRIPTOR mVariableNotifyList[] = {
- {
- (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK),
- &gEfiPeiReadOnlyVariable2PpiGuid,
- PlatformVariablePeiInit
- },
- {
- (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
- &gUpdateBootModePpiGuid,
- VariableInitBootModeCallBack
- }
- };
- EFI_STATUS
- EFIAPI
- PlatformVariableInitPeiEntry (
- IN EFI_PEI_FILE_HANDLE FileHandle,
- IN CONST EFI_PEI_SERVICES **PeiServices
- )
- /*++
- --*/
- {
- EFI_STATUS Status;
- PlatformVariableHookForEntry();
- // Register notify to set default variable once variable service is ready.
- //
- Status = PeiServicesNotifyPpi(&mVariableNotifyList[0]);
- return Status;
- }
|