OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
VariableDxe.c File Reference
#include "Variable.h"
#include <Protocol/VariablePolicy.h>
#include <Library/VariablePolicyLib.h>

Go to the source code of this file.

Functions

EFI_STATUS EFIAPI ProtocolIsVariablePolicyEnabled (OUT BOOLEAN *State)
 
VOID EFIAPI RecordSecureBootPolicyVarData (VOID)
 
BOOLEAN AtRuntime (VOID)
 
EFI_LOCK * InitializeLock (IN OUT EFI_LOCK *Lock, IN EFI_TPL Priority)
 
VOID AcquireLockOnlyAtBootTime (IN EFI_LOCK *Lock)
 
VOID ReleaseLockOnlyAtBootTime (IN EFI_LOCK *Lock)
 
EFI_STATUS GetFtwProtocol (OUT VOID **FtwProtocol)
 
EFI_STATUS GetFvbByHandle (IN EFI_HANDLE FvBlockHandle, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock)
 
EFI_STATUS GetFvbCountAndBuffer (OUT UINTN *NumberHandles, OUT EFI_HANDLE **Buffer)
 
VOID EFIAPI VariableClassAddressChangeEvent (IN EFI_EVENT Event, IN VOID *Context)
 
VOID EFIAPI OnReadyToBoot (EFI_EVENT Event, VOID *Context)
 
VOID EFIAPI OnEndOfDxe (EFI_EVENT Event, VOID *Context)
 
VOID VariableWriteServiceInitializeDxe (VOID)
 
VOID EFIAPI FtwNotificationEvent (IN EFI_EVENT Event, IN VOID *Context)
 
STATIC EFI_STATUS EFIAPI MapCreateEventEx (IN UINT32 Type, IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, IN CONST VOID *NotifyContext OPTIONAL, IN CONST EFI_GUID *EventGroup OPTIONAL, OUT EFI_EVENT *Event)
 
STATIC VOID SaveAcpiGlobalVariable (IN EFI_SYSTEM_TABLE *SystemTable)
 
STATIC VOID RestoreAcpiGlobalVariable (IN EFI_SYSTEM_TABLE *SystemTable)
 
EFI_STATUS EFIAPI VariableServiceInitialize (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

EFI_HANDLE mHandle = NULL
 
EFI_EVENT mVirtualAddressChangeEvent = NULL
 
VOID * mFtwRegistration = NULL
 
VOID *** mVarCheckAddressPointer = NULL
 
UINTN mVarCheckAddressPointerCount = 0
 
EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock }
 
EDKII_VARIABLE_POLICY_PROTOCOL mVariablePolicyProtocol
 
EDKII_VAR_CHECK_PROTOCOL mVarCheck
 
STATIC EFI_GUID mAcpiGlobalVariableGuid
 
STATIC VOID * mAcpiGlobalVariable = NULL
 
STATIC UINT32 mAcpiGlobalVariableAttributes
 

Detailed Description

Implement all four UEFI Runtime Variable services for the nonvolatile and volatile storage space and install variable architecture protocol.

Modified to work with UEFI1.1 for Apple firmware, and for immediate install.

Copyright (C) 2013, Red Hat, Inc. Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
Copyright (c) Microsoft Corporation.
Additional modifications Copyright (c) 2022 Mike Beaton SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file VariableDxe.c.

Function Documentation

◆ AcquireLockOnlyAtBootTime()

VOID AcquireLockOnlyAtBootTime ( IN EFI_LOCK * Lock)

Acquires lock only at boot time. Simply returns at runtime.

This is a temperary function that will be removed when EfiAcquireLock() in UefiLib can handle the call in UEFI Runtimer driver in RT phase. It calls EfiAcquireLock() at boot time, and simply returns at runtime.

Parameters
LockA pointer to the lock to acquire.

Definition at line 122 of file VariableDxe.c.

◆ AtRuntime()

BOOLEAN AtRuntime ( VOID )

Return TRUE if ExitBootServices () has been called.

Return values
TRUEIf ExitBootServices () has been called.

Definition at line 77 of file VariableDxe.c.

◆ FtwNotificationEvent()

VOID EFIAPI FtwNotificationEvent ( IN EFI_EVENT Event,
IN VOID * Context )

Fault Tolerant Write protocol notification event handler.

Non-Volatile variable write may needs FTW protocol to reclaim when writting variable.

Parameters
[in]EventEvent whose notification function is being invoked.
[in]ContextPointer to the notification function's context.

Definition at line 428 of file VariableDxe.c.

◆ GetFtwProtocol()

EFI_STATUS GetFtwProtocol ( OUT VOID ** FtwProtocol)

Retrieve the Fault Tolerent Write protocol interface.

Parameters
[out]FtwProtocolThe interface of Ftw protocol
Return values
EFI_SUCCESSThe FTW protocol instance was found and returned in FtwProtocol.
EFI_NOT_FOUNDThe FTW protocol instance was not found.
EFI_INVALID_PARAMETERSarProtocol is NULL.

Definition at line 164 of file VariableDxe.c.

◆ GetFvbByHandle()

EFI_STATUS GetFvbByHandle ( IN EFI_HANDLE FvBlockHandle,
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL ** FvBlock )

Retrieve the FVB protocol interface by HANDLE.

Parameters
[in]FvBlockHandleThe handle of FVB protocol that provides services for reading, writing, and erasing the target block.
[out]FvBlockThe interface of FVB protocol
Return values
EFI_SUCCESSThe interface information for the specified protocol was returned.
EFI_UNSUPPORTEDThe device does not support the FVB protocol.
EFI_INVALID_PARAMETERFvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.

Definition at line 194 of file VariableDxe.c.

◆ GetFvbCountAndBuffer()

EFI_STATUS GetFvbCountAndBuffer ( OUT UINTN * NumberHandles,
OUT EFI_HANDLE ** Buffer )

Function returns an array of handles that support the FVB protocol in a buffer allocated from pool.

Parameters
[out]NumberHandlesThe number of handles returned in Buffer.
[out]BufferA pointer to the buffer to return the requested array of handles that support FVB protocol.
Return values
EFI_SUCCESSThe array of handles was returned in Buffer, and the number of handles in Buffer was returned in NumberHandles.
EFI_NOT_FOUNDNo FVB handle was found.
EFI_OUT_OF_RESOURCESThere is not enough pool memory to store the matching results.
EFI_INVALID_PARAMETERNumberHandles is NULL or Buffer is NULL.

Definition at line 225 of file VariableDxe.c.

◆ InitializeLock()

EFI_LOCK * InitializeLock ( IN OUT EFI_LOCK * Lock,
IN EFI_TPL Priority )

Initializes a basic mutual exclusion lock.

This function initializes a basic mutual exclusion lock to the released state and returns the lock. Each lock provides mutual exclusion access at its task priority level. Since there is no preemption or multiprocessor support in EFI, acquiring the lock only consists of raising to the locks TPL. If Lock is NULL, then ASSERT(). If Priority is not a valid TPL value, then ASSERT().

Parameters
LockA pointer to the lock data structure to initialize.
PriorityEFI TPL is associated with the lock.
Returns
The lock.

Definition at line 101 of file VariableDxe.c.

◆ MapCreateEventEx()

STATIC EFI_STATUS EFIAPI MapCreateEventEx ( IN UINT32 Type,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
IN CONST VOID *NotifyContext OPTIONAL,
IN CONST EFI_GUID *EventGroup OPTIONAL,
OUT EFI_EVENT * Event )

Definition at line 534 of file VariableDxe.c.

◆ OnEndOfDxe()

VOID EFIAPI OnEndOfDxe ( EFI_EVENT Event,
VOID * Context )

Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.

This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.

Parameters
EventEvent whose notification function is being invoked.
ContextPointer to the notification function's context.

Definition at line 357 of file VariableDxe.c.

◆ OnReadyToBoot()

VOID EFIAPI OnReadyToBoot ( EFI_EVENT Event,
VOID * Context )

Notification function of EVT_GROUP_READY_TO_BOOT event group.

This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group. When the Boot Manager is about to load and execute a boot option, it reclaims variable storage if free size is below the threshold.

Parameters
EventEvent whose notification function is being invoked.
ContextPointer to the notification function's context.

Definition at line 311 of file VariableDxe.c.

◆ ProtocolIsVariablePolicyEnabled()

EFI_STATUS EFIAPI ProtocolIsVariablePolicyEnabled ( OUT BOOLEAN * State)

This API function returns whether or not the policy engine is currently being enforced.

Parameters
[out]StatePointer to a return value for whether the policy enforcement is currently enabled.
Return values
EFI_SUCCESS
OthersAn error has prevented this command from completing.

Definition at line 523 of file VariableDxe.c.

◆ RecordSecureBootPolicyVarData()

VOID EFIAPI RecordSecureBootPolicyVarData ( VOID )

Some Secure Boot Policy Variable may update following other variable changes(SecureBoot follows PK change, etc). Record their initial State when variable write service is ready.

Definition at line 321 of file Measurement.c.

◆ ReleaseLockOnlyAtBootTime()

VOID ReleaseLockOnlyAtBootTime ( IN EFI_LOCK * Lock)

Releases lock only at boot time. Simply returns at runtime.

This is a temperary function which will be removed when EfiReleaseLock() in UefiLib can handle the call in UEFI Runtimer driver in RT phase. It calls EfiReleaseLock() at boot time and simply returns at runtime.

Parameters
LockA pointer to the lock to release.

Definition at line 144 of file VariableDxe.c.

◆ RestoreAcpiGlobalVariable()

STATIC VOID RestoreAcpiGlobalVariable ( IN EFI_SYSTEM_TABLE * SystemTable)

Definition at line 608 of file VariableDxe.c.

◆ SaveAcpiGlobalVariable()

STATIC VOID SaveAcpiGlobalVariable ( IN EFI_SYSTEM_TABLE * SystemTable)

Definition at line 569 of file VariableDxe.c.

◆ VariableClassAddressChangeEvent()

VOID EFIAPI VariableClassAddressChangeEvent ( IN EFI_EVENT Event,
IN VOID * Context )

Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.

This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event. It convers pointer to new virtual address.

Parameters
EventEvent whose notification function is being invoked.
ContextPointer to the notification function's context.

Definition at line 257 of file VariableDxe.c.

◆ VariableServiceInitialize()

EFI_STATUS EFIAPI VariableServiceInitialize ( IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE * SystemTable )

Variable Driver main entry point. The Variable driver places the 4 EFI runtime services in the EFI System Table and installs arch protocols for variable read and write services being available. It also registers a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.

Parameters
[in]ImageHandleThe firmware allocated handle for the EFI image.
[in]SystemTableA pointer to the EFI System Table.
Return values
EFI_SUCCESSVariable service successfully initialized.

Definition at line 645 of file VariableDxe.c.

◆ VariableWriteServiceInitializeDxe()

VOID VariableWriteServiceInitializeDxe ( VOID )

Initializes variable write service for DXE.

Definition at line 386 of file VariableDxe.c.

Variable Documentation

◆ mAcpiGlobalVariable

STATIC VOID* mAcpiGlobalVariable = NULL

Definition at line 54 of file VariableDxe.c.

◆ mAcpiGlobalVariableAttributes

STATIC UINT32 mAcpiGlobalVariableAttributes

Definition at line 58 of file VariableDxe.c.

◆ mAcpiGlobalVariableGuid

STATIC EFI_GUID mAcpiGlobalVariableGuid
Initial value:
= {
0xAF9FFD67, 0xEC10, 0x488A, { 0x9D, 0xFC, 0x6C, 0xBF, 0x5E, 0xE2, 0x2C, 0x2E }
}

Definition at line 48 of file VariableDxe.c.

◆ mFtwRegistration

VOID* mFtwRegistration = NULL

Definition at line 30 of file VariableDxe.c.

◆ mHandle

EFI_HANDLE mHandle = NULL

Definition at line 28 of file VariableDxe.c.

◆ mVarCheck

EDKII_VAR_CHECK_PROTOCOL mVarCheck
Initial value:
= {
}
EFI_STATUS EFIAPI VarCheckVariablePropertySet(IN CHAR16 *Name, IN EFI_GUID *Guid, IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)
Definition VarCheck.c:59
EFI_STATUS EFIAPI VarCheckRegisterSetVariableCheckHandler(IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler)
Definition VarCheck.c:29
EFI_STATUS EFIAPI VarCheckVariablePropertyGet(IN CHAR16 *Name, IN EFI_GUID *Guid, OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)
Definition VarCheck.c:88

Definition at line 42 of file VariableDxe.c.

◆ mVarCheckAddressPointer

VOID*** mVarCheckAddressPointer = NULL

Definition at line 31 of file VariableDxe.c.

◆ mVarCheckAddressPointerCount

UINTN mVarCheckAddressPointerCount = 0

Definition at line 32 of file VariableDxe.c.

◆ mVariableLock

EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock = { VariableLockRequestToLock }

Definition at line 33 of file VariableDxe.c.

◆ mVariablePolicyProtocol

EDKII_VARIABLE_POLICY_PROTOCOL mVariablePolicyProtocol
Initial value:
= {
EDKII_VARIABLE_POLICY_PROTOCOL_REVISION,
DisableVariablePolicy,
RegisterVariablePolicy,
DumpVariablePolicy,
LockVariablePolicy
}
EFI_STATUS EFIAPI ProtocolIsVariablePolicyEnabled(OUT BOOLEAN *State)

Definition at line 34 of file VariableDxe.c.

◆ mVirtualAddressChangeEvent

EFI_EVENT mVirtualAddressChangeEvent = NULL

Definition at line 29 of file VariableDxe.c.