TianoCore EDK2 master
Loading...
Searching...
No Matches
VariableRuntimeCache.c
Go to the documentation of this file.
1
15#include "VariableParsing.h"
17
18extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;
20
30 VOID
31 )
32{
33 VARIABLE_RUNTIME_CACHE_CONTEXT *VariableRuntimeCacheContext;
34
35 VariableRuntimeCacheContext = &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext;
36
37 if ((VariableRuntimeCacheContext->VariableRuntimeNvCache.Store == NULL) ||
38 (VariableRuntimeCacheContext->VariableRuntimeVolatileCache.Store == NULL) ||
39 (VariableRuntimeCacheContext->PendingUpdate == NULL))
40 {
41 return EFI_UNSUPPORTED;
42 }
43
44 if (*(VariableRuntimeCacheContext->PendingUpdate)) {
45 if ((VariableRuntimeCacheContext->VariableRuntimeHobCache.Store != NULL) &&
46 (mVariableModuleGlobal->VariableGlobal.HobVariableBase > 0))
47 {
48 CopyMem (
49 (VOID *)(
50 ((UINT8 *)(UINTN)VariableRuntimeCacheContext->VariableRuntimeHobCache.Store) +
51 VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateOffset
52 ),
53 (VOID *)(
54 ((UINT8 *)(UINTN)mVariableModuleGlobal->VariableGlobal.HobVariableBase) +
55 VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateOffset
56 ),
57 VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateLength
58 );
59 VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateLength = 0;
60 VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateOffset = 0;
61 }
62
63 CopyMem (
64 (VOID *)(
65 ((UINT8 *)(UINTN)VariableRuntimeCacheContext->VariableRuntimeNvCache.Store) +
66 VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateOffset
67 ),
68 (VOID *)(
69 ((UINT8 *)(UINTN)mNvVariableCache) +
70 VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateOffset
71 ),
72 VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateLength
73 );
74 VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateLength = 0;
75 VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateOffset = 0;
76
77 CopyMem (
78 (VOID *)(
79 ((UINT8 *)(UINTN)VariableRuntimeCacheContext->VariableRuntimeVolatileCache.Store) +
80 VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset
81 ),
82 (VOID *)(
83 ((UINT8 *)(UINTN)mVariableModuleGlobal->VariableGlobal.VolatileVariableBase) +
84 VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset
85 ),
86 VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateLength
87 );
88 VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateLength = 0;
89 VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffset = 0;
90 *(VariableRuntimeCacheContext->PendingUpdate) = FALSE;
91 }
92
93 return EFI_SUCCESS;
94}
95
115 IN VARIABLE_RUNTIME_CACHE *VariableRuntimeCache,
116 IN UINTN Offset,
117 IN UINTN Length
118 )
119{
120 if (VariableRuntimeCache == NULL) {
121 return EFI_INVALID_PARAMETER;
122 } else if (VariableRuntimeCache->Store == NULL) {
123 // The runtime cache may not be active or allocated yet.
124 // In either case, return EFI_SUCCESS instead of EFI_NOT_AVAILABLE_YET.
125 return EFI_SUCCESS;
126 }
127
128 if ((mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.PendingUpdate == NULL) ||
129 (mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.ReadLock == NULL))
130 {
131 return EFI_UNSUPPORTED;
132 }
133
134 if (*(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.PendingUpdate) &&
135 (VariableRuntimeCache->PendingUpdateLength > 0))
136 {
137 VariableRuntimeCache->PendingUpdateLength =
138 (UINT32)(
139 MAX (
140 (UINTN)(VariableRuntimeCache->PendingUpdateOffset + VariableRuntimeCache->PendingUpdateLength),
141 Offset + Length
142 ) - MIN ((UINTN)VariableRuntimeCache->PendingUpdateOffset, Offset)
143 );
144 VariableRuntimeCache->PendingUpdateOffset =
145 (UINT32)MIN ((UINTN)VariableRuntimeCache->PendingUpdateOffset, Offset);
146 } else {
147 VariableRuntimeCache->PendingUpdateLength = (UINT32)Length;
148 VariableRuntimeCache->PendingUpdateOffset = (UINT32)Offset;
149 }
150
151 *(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.PendingUpdate) = TRUE;
152
153 if (*(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.ReadLock) == FALSE) {
155 }
156
157 return EFI_SUCCESS;
158}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define MIN(a, b)
Definition: Base.h:1007
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define MAX(a, b)
Definition: Base.h:992
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS FlushPendingRuntimeVariableCacheUpdates(VOID)
VARIABLE_STORE_HEADER * mNvVariableCache
Definition: Variable.c:39
EFI_STATUS SynchronizeRuntimeVariableCache(IN VARIABLE_RUNTIME_CACHE *VariableRuntimeCache, IN UINTN Offset, IN UINTN Length)